summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-01-24 05:05:15 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-01-24 05:05:15 (GMT)
commite80d847e3d9249d22bf70f257df7b2130487b211 (patch)
treeb9a17f3f8b66da2c303907833ead5116f55300d4
parentd847039c96641f564d805c57824bad422d68ec0d (diff)
stubs to enable passing ostream to png-writing functions
-rw-r--r--src/export_png.cc8
-rw-r--r--src/imageutils-lodepng.cc10
-rw-r--r--src/imageutils-macosx.cc60
-rw-r--r--src/imageutils.h1
4 files changed, 66 insertions, 13 deletions
diff --git a/src/export_png.cc b/src/export_png.cc
index aa23ee7..16e2a69 100644
--- a/src/export_png.cc
+++ b/src/export_png.cc
@@ -38,12 +38,12 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output)
Vector3d camerapos = center - radius*2*cameradir;
output << center << "\n";
output << radius << "\n";
-/*
+
csgInfo.glview->setCamera(camerapos, center);
csgInfo.glview->setRenderer(&cgalRenderer);
- csgInfo.glview->paintGL();
- csgInfo.glview->save(outfile);
-*/
+ csgInfo.glview->paintGL();
+ csgInfo.glview->save("test.png");
+
output << "solid OpenSCAD_Model\n";
output << "endsolid OpenSCAD_Model\n";
}
diff --git a/src/imageutils-lodepng.cc b/src/imageutils-lodepng.cc
index c89ed7c..a74f107 100644
--- a/src/imageutils-lodepng.cc
+++ b/src/imageutils-lodepng.cc
@@ -2,6 +2,16 @@
#include <stdio.h>
#include <stdlib.h>
+bool write_png(std::ostream &output, unsigned char *pixels, int width, int height)
+{
+ 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 );;
+ free( dataout );
+ return true;
+}
+
bool write_png(const char *filename, unsigned char *pixels, int width, int height)
{
//encoder.settings.zlibsettings.windowSize = 2048;
diff --git a/src/imageutils-macosx.cc b/src/imageutils-macosx.cc
index 404052f..8074f3f 100644
--- a/src/imageutils-macosx.cc
+++ b/src/imageutils-macosx.cc
@@ -1,8 +1,40 @@
#include <ApplicationServices/ApplicationServices.h>
+#include <CGDataConsumer.h>
#include <iostream>
+CGDataConsumerCallbacks callbacks;
+
+size_t write_bytes_to_ostream (void *info,const void *buffer,size_t count)
+{
+ assert( info );
+ std::ostream *output = (std::ostream *)info;
+ output->write( (const char *) buffer, count );
+ return count;
+}
+
+CGDataConsumerRef dataconsumer CGDataConsumerCreateWithOstream(std::ostream &output)
+{
+ callbacks.putBytes = write_bytes_to_ostream;
+ callbacks.releaseConsumer = NULL;
+ CGDataConsumerRef dc = CGDataConsumerCreate ( (void *)output, &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();
@@ -22,15 +54,20 @@ bool write_png(const char *filename, unsigned char *pixels, int width, int heigh
return false;
}
- CFStringRef fname = CFStringCreateWithCString(kCFAllocatorDefault, filename, kCFStringEncodingUTF8);
- CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
+ 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;
- }
+ 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;
CFStringRef fileUTType = kUTTypePNG;
@@ -55,10 +92,15 @@ bool write_png(const char *filename, unsigned char *pixels, int width, int heigh
CFRelease(imageDest);
CFRelease(dataconsumer);
- CFRelease(fileURL);
- CFRelease(fname);
+ if ( filename ) {
+ CFRelease(fileURL);
+ CFRelease(fname);
+ }
CFRelease(imageProps);
CGColorSpaceRelease(colorSpace);
CGImageRelease(imageRef);
return true;
}
+
+
+
diff --git a/src/imageutils.h b/src/imageutils.h
index 72602a2..b8d1663 100644
--- a/src/imageutils.h
+++ b/src/imageutils.h
@@ -4,6 +4,7 @@
#include <stdlib.h>
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);
void flip_image(const unsigned char *src, unsigned char *dst, size_t pixelsize, size_t width, size_t height);
#endif
contact: Jan Huwald // Impressum