Index: src/codec/SkJpegCodec.cpp |
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp |
index d2f7cdb0fa382db95a0e69c9ca9dea607a691f3b..7af0e51a8dfaf2b35d07b87d017a2dfbb7c8d624 100644 |
--- a/src/codec/SkJpegCodec.cpp |
+++ b/src/codec/SkJpegCodec.cpp |
@@ -535,7 +535,7 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
void* dst, size_t dstRowBytes, |
const Options& options, SkPMColor*, int*, |
int* rowsDecoded) { |
- if (options.fSubset) { |
+/* if (options.fSubset) { |
// Subsets are not supported. |
return kUnimplemented; |
} |
@@ -577,6 +577,102 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
} |
return kSuccess; |
+*/ |
+ |
+ this->initializeColorXform(dstInfo); |
+ |
+ // This will check is_yuv_supported(), so we don't need to here. |
+ SkYUVSizeInfo yuvInfo; |
+ if (!this->onQueryYUV8(&yuvInfo, nullptr)) { |
+ return fDecoderMgr->returnFailure("onQueryYUV8", kInvalidInput); |
+ } |
+ |
+ // Set the jump location for libjpeg errors |
+ if (setjmp(fDecoderMgr->getJmpBuf())) { |
+ return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
+ } |
+ |
+ // Get a pointer to the decompress info since we will use it quite frequently |
+ jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); |
+ |
+ dinfo->raw_data_out = TRUE; |
+ if (!jpeg_start_decompress(dinfo)) { |
+ return fDecoderMgr->returnFailure("startDecompress", kInvalidInput); |
+ } |
+ |
+ // Currently, we require that the Y plane dimensions match the image dimensions |
+ // and that the U and V planes are the same dimensions. |
+ SkASSERT(yuvInfo.fSizes[SkYUVSizeInfo::kU] == yuvInfo.fSizes[SkYUVSizeInfo::kV]); |
+ SkASSERT((uint32_t) yuvInfo.fSizes[SkYUVSizeInfo::kY].width() == dinfo->output_width && |
+ (uint32_t) yuvInfo.fSizes[SkYUVSizeInfo::kY].height() == dinfo->output_height); |
+ |
+ // Build a JSAMPIMAGE to handle output from libjpeg-turbo. A JSAMPIMAGE has |
+ // a 2-D array of pixels for each of the components (Y, U, V) in the image. |
+ // Cheat Sheet: |
+ // JSAMPIMAGE == JSAMPLEARRAY* == JSAMPROW** == JSAMPLE*** |
+ JSAMPARRAY yuv[3]; |
+ |
+ // Set aside enough space for pointers to rows of Y, U, and V. |
+ JSAMPROW rowptrs[2 * DCTSIZE + DCTSIZE + DCTSIZE]; |
+ yuv[0] = &rowptrs[0]; // Y rows (DCTSIZE or 2 * DCTSIZE) |
+ yuv[1] = &rowptrs[1 /******/* DCTSIZE]; // U rows (DCTSIZE) |
+ yuv[2] = &rowptrs[2 /*******/* DCTSIZE]; // V rows (DCTSIZE) |
+ |
+ // Initialize rowptrs. |
+ SkASSERT(yuvInfo.fWidthBytes[0] == yuvInfo.fWidthBytes[1] && yuvInfo.fWidthBytes[0] == yuvInfo.fWidthBytes[2]); |
+ SkAutoTMalloc<uint8_t> storage(3 * DCTSIZE * yuvInfo.fWidthBytes[0]); |
+ int numYRowsPerBlock = DCTSIZE * dinfo->comp_info[0].v_samp_factor; |
+ SkASSERT(DCTSIZE == numYRowsPerBlock); |
+ JSAMPLE* storagePtr = (JSAMPLE*) storage.get(); |
+ for (int i = 0; i < numYRowsPerBlock; i++) { |
+ rowptrs[i] = storagePtr; |
+ storagePtr += yuvInfo.fWidthBytes[0]; |
+ } |
+ for (int i = 0; i < numYRowsPerBlock; i++) { |
+ rowptrs[DCTSIZE + i] = storagePtr; |
+ storagePtr += yuvInfo.fWidthBytes[0]; |
+ } |
+ for (int i = 0; i < numYRowsPerBlock; i++) { |
+ rowptrs[DCTSIZE + DCTSIZE + i] = storagePtr; |
+ storagePtr += yuvInfo.fWidthBytes[0]; |
+ } |
+ |
+ uint32_t numRowsPerBlock = numYRowsPerBlock; |
+ |
+ // We intentionally round down here, as this first loop will only handle |
+ // full block rows. As a special case at the end, we will handle any |
+ // remaining rows that do not make up a full block. |
+ const int numIters = dinfo->output_height / numRowsPerBlock; |
+ for (int i = 0; i < numIters; i++) { |
+ JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
+ if (linesRead < numRowsPerBlock) { |
+ // FIXME: Handle incomplete YUV decodes without signalling an error. |
+ return kInvalidInput; |
+ } |
+ |
+ for (uint32_t j = 0; j < DCTSIZE; j++) { |
+ fColorXform->applyYUV(dst, yuv[0][j], yuv[1][j], yuv[2][j], dstInfo.width()); |
+ dst = SkTAddOffset<void>(dst, dstRowBytes); |
+ } |
+ } |
+ |
+ uint32_t remainingRows = dinfo->output_height - dinfo->output_scanline; |
+ SkASSERT(remainingRows == dinfo->output_height % numRowsPerBlock); |
+ SkASSERT(dinfo->output_scanline == numIters * numRowsPerBlock); |
+ if (remainingRows > 0) { |
+ JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
+ if (linesRead < remainingRows) { |
+ // FIXME: Handle incomplete YUV decodes without signalling an error. |
+ return kInvalidInput; |
+ } |
+ |
+ for (uint32_t j = 0; j < remainingRows; j++) { |
+ fColorXform->applyYUV(dst, yuv[0][j], yuv[1][j], yuv[2][j], dstInfo.width()); |
+ dst = SkTAddOffset<void>(dst, dstRowBytes); |
+ } |
+ } |
+ |
+ return kSuccess; |
} |
void SkJpegCodec::allocateStorage(const SkImageInfo& dstInfo) { |