| Index: src/images/SkImageDecoder_libjpeg.cpp
|
| diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
|
| index 8e92dd874e18a3ccc64c27e54db9301c2653bf75..17e9aae14d632d3980a21b5ea64ae4d69717d8a0 100644
|
| --- a/src/images/SkImageDecoder_libjpeg.cpp
|
| +++ b/src/images/SkImageDecoder_libjpeg.cpp
|
| @@ -23,7 +23,11 @@
|
|
|
| #include <stdio.h>
|
| extern "C" {
|
| +#ifdef SK_BUILD_FOR_ANDROID
|
| + #include "manglejpeglib.h"
|
| +#else
|
| #include "jpeglib.h"
|
| +#endif
|
| #include "jerror.h"
|
| }
|
|
|
| @@ -113,7 +117,7 @@ public:
|
| // Like fHuffmanCreated, set to false before calling libjpeg
|
| // function to prevent potential infinite loop.
|
| fDecompressStarted = false;
|
| - jpeg_finish_decompress(&fCInfo);
|
| + jFinDecompress(&fCInfo);
|
| }
|
| if (fInfoInitialized) {
|
| this->destroyInfo();
|
| @@ -133,14 +137,14 @@ public:
|
| // Like fHuffmanCreated, set to false before calling libjpeg
|
| // function to prevent potential infinite loop.
|
| fInfoInitialized = false;
|
| - jpeg_destroy_decompress(&fCInfo);
|
| + jDestDecompress(&fCInfo);
|
| SkDEBUGCODE(fReadHeaderSucceeded = false;)
|
| }
|
|
|
| /**
|
| * Initialize the cinfo struct.
|
| * Calls jpeg_create_decompress, makes customizations, and
|
| - * finally calls jpeg_read_header. Returns true if jpeg_read_header
|
| + * finally calls jReadHeader. Returns true if jReadHeader
|
| * returns JPEG_HEADER_OK.
|
| * If cinfo was already initialized, destroyInfo must be called to
|
| * destroy the old one. Must not be called after startTileDecompress.
|
| @@ -149,7 +153,7 @@ public:
|
| SkASSERT(!fInfoInitialized && !fDecompressStarted);
|
| initialize_info(&fCInfo, &fSrcMgr);
|
| fInfoInitialized = true;
|
| - const bool success = (JPEG_HEADER_OK == jpeg_read_header(&fCInfo, true));
|
| + const bool success = (JPEG_HEADER_OK == jReadHeader(&fCInfo, true));
|
| SkDEBUGCODE(fReadHeaderSucceeded = success;)
|
| return success;
|
| }
|
| @@ -240,7 +244,7 @@ private:
|
| * Determine the appropriate bitmap colortype and out_color_space based on
|
| * both the preference of the caller and the jpeg_color_space on the
|
| * jpeg_decompress_struct passed in.
|
| - * Must be called after jpeg_read_header.
|
| + * Must be called after jReadHeader.
|
| */
|
| SkColorType getBitmapColorType(jpeg_decompress_struct*);
|
|
|
| @@ -255,7 +259,7 @@ public:
|
| JPEGAutoClean(): cinfo_ptr(NULL) {}
|
| ~JPEGAutoClean() {
|
| if (cinfo_ptr) {
|
| - jpeg_destroy_decompress(cinfo_ptr);
|
| + jDestDecompress(cinfo_ptr);
|
| }
|
| }
|
| void set(jpeg_decompress_struct* info) {
|
| @@ -289,7 +293,7 @@ static bool valid_output_dimensions(const jpeg_decompress_struct& cinfo) {
|
| static bool skip_src_rows(jpeg_decompress_struct* cinfo, void* buffer, int count) {
|
| for (int i = 0; i < count; i++) {
|
| JSAMPLE* rowptr = (JSAMPLE*)buffer;
|
| - int row_count = jpeg_read_scanlines(cinfo, &rowptr, 1);
|
| + int row_count = jReadScanlines(cinfo, &rowptr, 1);
|
| if (1 != row_count) {
|
| return false;
|
| }
|
| @@ -376,7 +380,7 @@ static void convert_CMYK_to_RGB(uint8_t* scanline, unsigned int width) {
|
| static void set_error_mgr(jpeg_decompress_struct* cinfo, skjpeg_error_mgr* errorManager) {
|
| SkASSERT(cinfo != NULL);
|
| SkASSERT(errorManager != NULL);
|
| - cinfo->err = jpeg_std_error(errorManager);
|
| + cinfo->err = jStdError(errorManager);
|
| errorManager->error_exit = skjpeg_error_exit;
|
| }
|
|
|
| @@ -562,7 +566,7 @@ SkImageDecoder::Result SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap*
|
| initialize_info(&cinfo, &srcManager);
|
| autoClean.set(&cinfo);
|
|
|
| - int status = jpeg_read_header(&cinfo, true);
|
| + int status = jReadHeader(&cinfo, true);
|
| if (status != JPEG_HEADER_OK) {
|
| return return_failure(cinfo, *bm, "read_header");
|
| }
|
| @@ -597,10 +601,10 @@ SkImageDecoder::Result SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap*
|
| }
|
|
|
| /* image_width and image_height are the original dimensions, available
|
| - after jpeg_read_header(). To see the scaled dimensions, we have to call
|
| - jpeg_start_decompress(), and then read output_width and output_height.
|
| + after jReadHeader(). To see the scaled dimensions, we have to call
|
| + jStrtDecompress(), and then read output_width and output_height.
|
| */
|
| - if (!jpeg_start_decompress(&cinfo)) {
|
| + if (!jStrtDecompress(&cinfo)) {
|
| /* If we failed here, we may still have enough information to return
|
| to the caller if they just wanted (subsampled bounds). If sampleSize
|
| was 1, then we would have already returned. Thus we just check if
|
| @@ -654,13 +658,13 @@ SkImageDecoder::Result SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap*
|
| INT32 const bpr = bm->rowBytes();
|
|
|
| while (cinfo.output_scanline < cinfo.output_height) {
|
| - int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1);
|
| + int row_count = jReadScanlines(&cinfo, &rowptr, 1);
|
| if (0 == row_count) {
|
| // if row_count == 0, then we didn't get a scanline,
|
| // so return early. We will return a partial image.
|
| fill_below_level(cinfo.output_scanline, bm);
|
| cinfo.output_scanline = cinfo.output_height;
|
| - jpeg_finish_decompress(&cinfo);
|
| + jFinDecompress(&cinfo);
|
| return kPartialSuccess;
|
| }
|
| if (this->shouldCancelDecode()) {
|
| @@ -668,7 +672,7 @@ SkImageDecoder::Result SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap*
|
| }
|
| rowptr += bpr;
|
| }
|
| - jpeg_finish_decompress(&cinfo);
|
| + jFinDecompress(&cinfo);
|
| return kSuccess;
|
| }
|
| #endif
|
| @@ -696,13 +700,13 @@ SkImageDecoder::Result SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap*
|
| // now loop through scanlines until y == bm->height() - 1
|
| for (int y = 0;; y++) {
|
| JSAMPLE* rowptr = (JSAMPLE*)srcRow;
|
| - int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1);
|
| + int row_count = jReadScanlines(&cinfo, &rowptr, 1);
|
| if (0 == row_count) {
|
| // if row_count == 0, then we didn't get a scanline,
|
| // so return early. We will return a partial image.
|
| fill_below_level(y, bm);
|
| cinfo.output_scanline = cinfo.output_height;
|
| - jpeg_finish_decompress(&cinfo);
|
| + jFinDecompress(&cinfo);
|
| return kPartialSuccess;
|
| }
|
| if (this->shouldCancelDecode()) {
|
| @@ -729,7 +733,7 @@ SkImageDecoder::Result SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap*
|
| cinfo.output_height - cinfo.output_scanline)) {
|
| return return_failure(cinfo, *bm, "skip rows");
|
| }
|
| - jpeg_finish_decompress(&cinfo);
|
| + jFinDecompress(&cinfo);
|
|
|
| return kSuccess;
|
| }
|
| @@ -835,7 +839,7 @@ static bool output_raw_data(jpeg_decompress_struct& cinfo, void* planes[3], size
|
| bufferraw2[24 + i] = dummyRow;
|
| }
|
| }
|
| - JDIMENSION scanlinesRead = jpeg_read_raw_data(&cinfo, bufferraw, yScanlinesToRead);
|
| + JDIMENSION scanlinesRead = jReadRawData(&cinfo, bufferraw, yScanlinesToRead);
|
|
|
| if (scanlinesRead == 0) {
|
| return false;
|
| @@ -882,7 +886,7 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS
|
| initialize_info(&cinfo, &srcManager);
|
| autoClean.set(&cinfo);
|
|
|
| - int status = jpeg_read_header(&cinfo, true);
|
| + int status = jReadHeader(&cinfo, true);
|
| if (status != JPEG_HEADER_OK) {
|
| return return_false(cinfo, "read_header YUV8");
|
| }
|
| @@ -912,14 +916,14 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS
|
| #endif
|
|
|
| /* image_width and image_height are the original dimensions, available
|
| - after jpeg_read_header(). To see the scaled dimensions, we have to call
|
| - jpeg_start_decompress(), and then read output_width and output_height.
|
| + after jReadHeader(). To see the scaled dimensions, we have to call
|
| + jStrtDecompress(), and then read output_width and output_height.
|
| */
|
| - if (!jpeg_start_decompress(&cinfo)) {
|
| + if (!jStrtDecompress(&cinfo)) {
|
| return return_false(cinfo, "start_decompress YUV8");
|
| }
|
|
|
| - // Seems like jpeg_start_decompress is updating our opinion of whether cinfo represents YUV.
|
| + // Seems like jStrtDecompress is updating our opinion of whether cinfo represents YUV.
|
| // Again, not really an error.
|
| if (!appears_to_be_yuv(cinfo)) {
|
| return false;
|
| @@ -930,7 +934,7 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS
|
| }
|
|
|
| update_components_sizes(cinfo, componentSizes, kActualSize_SizeType);
|
| - jpeg_finish_decompress(&cinfo);
|
| + jFinDecompress(&cinfo);
|
|
|
| if (NULL != colorSpace) {
|
| *colorSpace = kJPEG_SkYUVColorSpace;
|
| @@ -984,7 +988,7 @@ bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width
|
|
|
| turn_off_visual_optimizations(cinfo);
|
|
|
| - // instead of jpeg_start_decompress() we start a tiled decompress
|
| + // instead of jStrtDecompress() we start a tiled decompress
|
| if (!imageIndex->startTileDecompress()) {
|
| return false;
|
| }
|
| @@ -1359,7 +1363,7 @@ protected:
|
| // allocate these before set call setjmp
|
| SkAutoMalloc oneRow;
|
|
|
| - cinfo.err = jpeg_std_error(&sk_err);
|
| + cinfo.err = jStdError(&sk_err);
|
| sk_err.error_exit = skjpeg_error_exit;
|
| if (setjmp(sk_err.fJmpBuf)) {
|
| return false;
|
| @@ -1383,13 +1387,13 @@ protected:
|
| #endif
|
| cinfo.input_gamma = 1;
|
|
|
| - jpeg_set_defaults(&cinfo);
|
| - jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
|
| + jSetDefaults(&cinfo);
|
| + jSetQuality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
|
| #ifdef DCT_IFAST_SUPPORTED
|
| cinfo.dct_method = JDCT_IFAST;
|
| #endif
|
|
|
| - jpeg_start_compress(&cinfo, TRUE);
|
| + jStrtCompress(&cinfo, TRUE);
|
|
|
| const int width = bm.width();
|
| uint8_t* oneRowP = (uint8_t*)oneRow.reset(width * 3);
|
| @@ -1402,12 +1406,12 @@ protected:
|
|
|
| writer(oneRowP, srcRow, width, colors);
|
| row_pointer[0] = oneRowP;
|
| - (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
| + (void) jWrtScanlines(&cinfo, row_pointer, 1);
|
| srcRow = (const void*)((const char*)srcRow + bm.rowBytes());
|
| }
|
|
|
| - jpeg_finish_compress(&cinfo);
|
| - jpeg_destroy_compress(&cinfo);
|
| + jFinCompress(&cinfo);
|
| + jDestCompress(&cinfo);
|
|
|
| return true;
|
| }
|
|
|