byte* outBuf = null;
result r = E_SUCCESS;
+ SysTryCatch(NID_MEDIA, !setjmp(__pJmp), r = E_INVALID_DATA, E_INVALID_DATA,
+ "[E_INVALID_DATA] error jump");
+
// Set decoding option
if (__pDec->jpeg_color_space == JCS_GRAYSCALE)
{
__pDec->out_color_space = JCS_GRAYSCALE;
}
+ else if (__pDec->jpeg_color_space == JCS_YCCK) // YCCK
+ {
+ __pDec->out_color_space = JCS_YCCK;
+ }
else // YUV444
{
__pDec->out_color_space = JCS_YCbCr;
}
}
}
- else
+ else if (__pDec->output_components == 4) // YCCK. Need to handle CMYK also.
+ {
+ if (__isDecodeRegionEnabled == true)
+ {
+ buffSize = __decodingRectWidth * __decodingRectHeight * 3;
+ planarSize = (__decodingRectWidth * __decodingRectHeight);
+ length = buffSize;
+ int row_stride = __pDec->output_width * __pDec->output_components;
+ JSAMPARRAY buffer = (*__pDec->mem->alloc_sarray)((struct jpeg_common_struct *) __pDec, JPOOL_IMAGE, row_stride, 1);
+
+ pReturnBuf = new (std::nothrow) byte[buffSize];
+ SysTryCatch(NID_MEDIA, pReturnBuf != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+ "[E_OUT_OF_MEMORY] Could not allocate %d bytes for output.", buffSize);
+
+ memset(pReturnBuf, 0, buffSize);
+ outBuf = pReturnBuf;
+
+ while (__pDec->output_scanline < (__decodingRectY + __decodingRectHeight))
+ {
+ jpeg_read_scanlines(__pDec, buffer, 1);
+ if (h >= __decodingRectY)
+ {
+ outX = 0;
+ for (int x = __decodingRectX; x < __decodingRectX + __decodingRectWidth; x++)
+ {
+ JSAMPLE* p = buffer[0] + (__pDec->output_components * x);
+
+ // YCCK -> YUV444p
+ pReturnBuf[(__decodingRectWidth * outY) + outX] = 255 - p[0]; // Y
+ pReturnBuf[(__decodingRectWidth * outY) + planarSize + outX] = 255 - p[1]; // Cb
+ pReturnBuf[(__decodingRectWidth * outY) + (planarSize * 2) + outX] = 255 - p[2];// Cr
+ outX++;
+ }
+ outY++;
+ }
+ h++;
+ }
+ }
+ else
+ {
+ buffSize = __pDec->output_width * __pDec->output_height * 3;
+ planarSize = __pDec->output_width * __pDec->output_height;
+ length = buffSize;
+ int row_stride = __pDec->output_width * __pDec->output_components;
+ JSAMPARRAY buffer = (*__pDec->mem->alloc_sarray)((struct jpeg_common_struct *) __pDec, JPOOL_IMAGE, row_stride, 1);
+
+ pReturnBuf = new (std::nothrow) byte[buffSize];
+ SysTryCatch(NID_MEDIA, pReturnBuf != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+ "[E_OUT_OF_MEMORY] Could not allocate %d bytes for output.", buffSize);
+
+ memset(pReturnBuf, 0, buffSize);
+ outBuf = pReturnBuf;
+
+ while (__pDec->output_scanline < __pDec->output_height)
+ {
+ jpeg_read_scanlines(__pDec, buffer, 1);
+
+ for (unsigned int x = 0; x < __pDec->output_width; x++)
+ {
+ JSAMPLE* p = buffer[0] + (__pDec->output_components * x);
+
+ // YCCK -> YUV444p
+ pReturnBuf[(__pDec->output_width * h) + x] = 255 - p[0]; // Y
+ pReturnBuf[(__pDec->output_width * h) + planarSize + x] = 255 - p[1]; // Cb
+ pReturnBuf[(__pDec->output_width * h) + (planarSize * 2) + x] = 255 - p[2]; // Cr
+ }
+ h++;
+ }
+ }
+ }
+ else // (__pDec->output_components == 3) YUV444
{
if (__isDecodeRegionEnabled == true)
{