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 | | |