Ticket #50116: patch-ipelib-ipebitmap_unix.cpp.diff

File patch-ipelib-ipebitmap_unix.cpp.diff, 1.9 KB (added by m7.thon@…, 9 years ago)
  • ipelib/ipebitmap_unix.cpp

    old new  
    3232
    3333#include <png.h>
    3434
    35 #ifdef __APPLE__
    36 #include <CoreGraphics.h>
    37 #else
    3835#include <csetjmp>
    3936#include <jpeglib.h>
    40 #endif
    4137
    4238using namespace ipe;
    4339
    4440// --------------------------------------------------------------------
    4541
    46 #ifdef __APPLE__
    47 
    48 bool dctDecode(Buffer dctData, Buffer pixelData, int components)
    49 {
    50   CGDataProviderRef source =
    51     CGDataProviderCreateWithData(NULL, dctData.data(),
    52                                  dctData.size(), NULL);
    53   CGImageRef bitmap =
    54     CGImageCreateWithJPEGDataProvider(source, NULL, false,
    55                                       kCGRenderingIntentDefault);
    56 
    57   if (CGImageGetBitsPerComponent(bitmap) != 8)
    58     return false;
    59 
    60   int w = CGImageGetWidth(bitmap);
    61   int h = CGImageGetHeight(bitmap);
    62   int bytes = CGImageGetBitsPerPixel(bitmap) / 8;
    63   int stride = CGImageGetBytesPerRow(bitmap);
    64 
    65   CGBitmapInfo info = CGImageGetBitmapInfo(bitmap);
    66   // TODO: check for alpha channel, float pixel values, and byte order?
    67   ipeDebug("dctDecode: %d x %d x %d, stride %d, info %x",
    68            w, h, bytes, stride, info);
    69 
    70   // TODO: Is it necessary to copy the data?
    71   CFDataRef pixels = CGDataProviderCopyData(CGImageGetDataProvider(bitmap));
    72   const uchar *inRow = CFDataGetBytePtr(pixels);
    73 
    74   uchar *q = (uchar *) pixelData.data();
    75   for (int y = 0; y < h; ++y) {
    76     const uchar *p = inRow;
    77     for (int x = 0; x < w; ++x) {
    78       *q++ = p[0];
    79       *q++ = p[1];
    80       *q++ = p[2];
    81       p += bytes;
    82     }
    83     inRow += stride;
    84   }
    85   CFRelease(pixels);
    86   CGImageRelease(bitmap);
    87   CGDataProviderRelease(source);
    88   return true;
    89 }
    90 
    91 #else
    92 
    9342// Decode jpeg image using libjpeg API with error handling
    9443// Code contributed by Michael Thon, 2015.
    9544
     
    13988  jpeg_destroy_decompress(&cinfo);
    14089  return true;
    14190}
    142 #endif
    14391
    14492// --------------------------------------------------------------------
    14593