mirror of https://github.com/vitalif/openscad
undo experiment with object orientation
parent
e80d847e3d
commit
c116a0849c
|
@ -232,7 +232,6 @@ HEADERS += src/version_check.h \
|
|||
src/svg.h \
|
||||
\
|
||||
src/lodepng.h \
|
||||
src/OffscreenContext.h \
|
||||
src/OffscreenView.h \
|
||||
src/fbo.h \
|
||||
src/imageutils.h \
|
||||
|
@ -306,16 +305,16 @@ SOURCES += src/version_check.cc \
|
|||
src/mainwin.cc
|
||||
|
||||
unix:!macx {
|
||||
SOURCES += src/OffscreenContextGLX.cc
|
||||
SOURCES += src/imageutils-lodepng.cc
|
||||
SOURCES += src/OffscreenContextGLX.cc
|
||||
}
|
||||
macx {
|
||||
SOURCES += src/OffscreenContext.mm
|
||||
SOURCES += src/imageutils-macosx.cc
|
||||
SOURCES += src/OffscreenContextCGL.mm
|
||||
}
|
||||
win32* {
|
||||
SOURCES += src/OffscreenContextWGL.cc
|
||||
SOURCES += src/imageutils-lodepng.cc
|
||||
SOURCES += src/OffscreenContextWGL.cc
|
||||
}
|
||||
|
||||
opencsg {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef OFFSCREENCONTEXT_H_
|
||||
#define OFFSCREENCONTEXT_H_
|
||||
|
||||
#include <iostream> // for error output
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
struct OffscreenContext *create_offscreen_context(int w, int h);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <stdint.h>
|
||||
#endif
|
||||
#include "system-gl.h"
|
||||
#include <iostream>
|
||||
|
||||
class OffscreenView
|
||||
{
|
||||
|
@ -24,6 +25,7 @@ public:
|
|||
void setupOrtho(bool offset=false);
|
||||
void paintGL();
|
||||
bool save(const char *filename);
|
||||
bool save(std::ostream &output);
|
||||
std::string getInfo();
|
||||
|
||||
GLint shaderinfo[11];
|
||||
|
|
|
@ -17,6 +17,7 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output)
|
|||
csgInfo.glview = new OffscreenView(512,512);
|
||||
} catch (int error) {
|
||||
fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error);
|
||||
return;
|
||||
}
|
||||
CGALRenderer cgalRenderer(*root_N);
|
||||
|
||||
|
|
|
@ -1,35 +1,16 @@
|
|||
#include "imageutils.h"
|
||||
#include "lodepng.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool write_png(std::ostream &output, unsigned char *pixels, int width, int height)
|
||||
{
|
||||
//encoder.settings.zlibsettings.windowSize = 2048;
|
||||
//LodePNG_Text_add(&encoder.infoPng.text, "Comment", "Created with LodePNG");
|
||||
size_t dataout_size = -1;
|
||||
unsigned char *dataout = (unsigned char *)malloc(width*height*4);
|
||||
LodePNG_encode(&dataout, &dataout_size, pixels, width, height, LCT_RGBA, 8);
|
||||
output.write( dataout, dataout_size );;
|
||||
output.write( reinterpret_cast<const char*>(dataout), dataout_size );;
|
||||
free( dataout );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write_png(const char *filename, unsigned char *pixels, int width, int height)
|
||||
{
|
||||
//encoder.settings.zlibsettings.windowSize = 2048;
|
||||
//LodePNG_Text_add(&encoder.infoPng.text, "Comment", "Created with LodePNG");
|
||||
|
||||
size_t dataout_size = -1;
|
||||
unsigned char *dataout = (unsigned char *)malloc(width*height*4);
|
||||
LodePNG_encode(&dataout, &dataout_size, pixels, width, height, LCT_RGBA, 8);
|
||||
//LodePNG_saveFile(dataout, dataout_size, "blah2.png");
|
||||
|
||||
FILE *f = fopen(filename, "wb");
|
||||
if (!f) {
|
||||
free(dataout);
|
||||
return false;
|
||||
}
|
||||
|
||||
fwrite(dataout, 1, dataout_size, f);
|
||||
fclose(f);
|
||||
free(dataout);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,40 +1,34 @@
|
|||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <CGDataConsumer.h>
|
||||
#include <iostream>
|
||||
#include "imageutils.h"
|
||||
|
||||
CGDataConsumerCallbacks callbacks;
|
||||
CGDataConsumerCallbacks dc_callbacks;
|
||||
|
||||
size_t write_bytes_to_ostream (void *info,const void *buffer,size_t count)
|
||||
{
|
||||
assert( info );
|
||||
assert( info && buffer );
|
||||
std::ostream *output = (std::ostream *)info;
|
||||
output->write( (const char *) buffer, count );
|
||||
return count;
|
||||
size_t startpos = output->tellp();
|
||||
size_t endpos = startpos;
|
||||
try {
|
||||
output->write( reinterpret_cast<const char *>buffer, count );
|
||||
endpos = output->tellp();
|
||||
} catch (const std::ios_base::failure& e)
|
||||
std::cerr << "Error writing to ostream:" << e.what() << "\n";
|
||||
}
|
||||
return endpos-startpos;
|
||||
}
|
||||
|
||||
CGDataConsumerRef dataconsumer CGDataConsumerCreateWithOstream(std::ostream &output)
|
||||
{
|
||||
callbacks.putBytes = write_bytes_to_ostream;
|
||||
callbacks.releaseConsumer = NULL;
|
||||
CGDataConsumerRef dc = CGDataConsumerCreate ( (void *)output, &callbacks );
|
||||
dc_callbacks.putBytes = write_bytes_to_ostream;
|
||||
dc_callbacks.releaseConsumer = NULL; // ostream closed by caller of write_png
|
||||
CGDataConsumerRef dc = CGDataConsumerCreate ( (void *)(&output), &dc_callbacks );
|
||||
return dc;
|
||||
}
|
||||
|
||||
bool write_png(const char *filename, unsigned char *pixels, int width, int height)
|
||||
{
|
||||
assert( filename );
|
||||
std::stringstream dummy;
|
||||
write_png_base( filename, dummy, pixels, width, height );
|
||||
}
|
||||
|
||||
bool write_png(std::ostream &output, unsigned char *pixels, int width, int height)
|
||||
{
|
||||
write_png_base( NULL, output, pixels, width, height );
|
||||
}
|
||||
|
||||
bool write_png_base(const char *filename, std::ostream &output, unsigned char *pixels, int width, int height)
|
||||
{
|
||||
|
||||
size_t rowBytes = width * 4;
|
||||
// CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
|
@ -54,19 +48,18 @@ bool write_png_base(const char *filename, std::ostream &output, unsigned char *p
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( filename == NULL ) {
|
||||
CGDataConsumerRef dataconsumer = CGDataConsumerCreateWithOstream(output);
|
||||
} else {
|
||||
CFStringRef fname = CFStringCreateWithCString(kCFAllocatorDefault, filename, kCFStringEncodingUTF8);
|
||||
CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
|
||||
fname, kCFURLPOSIXPathStyle, false);
|
||||
if (!fileURL) {
|
||||
std::cerr << "Unable to create file URL ref.";
|
||||
return false;
|
||||
}
|
||||
CGDataConsumerRef dataconsumer = CGDataConsumerCreateWithOstream(output);
|
||||
/*
|
||||
CFStringRef fname = CFStringCreateWithCString(kCFAllocatorDefault, filename, kCFStringEncodingUTF8);
|
||||
CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
|
||||
fname, kCFURLPOSIXPathStyle, false);
|
||||
if (!fileURL) {
|
||||
std::cerr << "Unable to create file URL ref.";
|
||||
return false;
|
||||
}
|
||||
|
||||
CGDataConsumerRef dataconsumer = CGDataConsumerCreateWithURL(fileURL);
|
||||
}
|
||||
CGDataConsumerRef dataconsumer = CGDataConsumerCreateWithURL(fileURL);
|
||||
*/
|
||||
|
||||
CFIndex fileImageIndex = 1;
|
||||
CFMutableDictionaryRef fileDict = NULL;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "imageutils.h"
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
|
||||
void flip_image(const unsigned char *src, unsigned char *dst, size_t pixelsize, size_t width, size_t height)
|
||||
{
|
||||
|
@ -8,3 +9,16 @@ void flip_image(const unsigned char *src, unsigned char *dst, size_t pixelsize,
|
|||
memmove(dst + (height - i - 1) * rowBytes, src + i * rowBytes, rowBytes);
|
||||
}
|
||||
}
|
||||
|
||||
bool write_png(const char *filename, unsigned char *pixels, int width, int height) {
|
||||
std::ofstream fstream( filename );
|
||||
if (fstream.is_open()) {
|
||||
write_png( fstream, pixels, width, height );
|
||||
fstream.close();
|
||||
return true;
|
||||
} else {
|
||||
std::cerr << "Can't open file " << filename << " for export.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define IMAGEUTILS_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
bool write_png(const char *filename, unsigned char *pixels, int width, int height);
|
||||
bool write_png(std::ostream &output, unsigned char *pixels, int width, int height);
|
||||
|
|
Loading…
Reference in New Issue