summaryrefslogtreecommitdiff
path: root/src/imageutils-macosx.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/imageutils-macosx.cc')
-rw-r--r--src/imageutils-macosx.cc60
1 files changed, 51 insertions, 9 deletions
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;
}
+
+
+
contact: Jan Huwald // Impressum