From d5951b1d8562b7c8bd8f5108c2021cbe81e9ba98 Mon Sep 17 00:00:00 2001 From: msarett Date: Wed, 10 Feb 2016 13:49:36 -0800 Subject: [PATCH] More efficient Jpeg skipScanlines for older versions of libjpeg-turbo BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1683283002 Review URL: https://codereview.chromium.org/1683283002 --- src/codec/SkJpegCodec.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index aefe264..50186e7 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -438,27 +438,27 @@ int SkJpegCodec::onGetScanlines(void* dst, int count, size_t dstRowBytes) { return count; } -#ifndef TURBO_HAS_SKIP -// TODO (msarett): Avoid reallocating the memory buffer on each call to skip. -static uint32_t jpeg_skip_scanlines(jpeg_decompress_struct* dinfo, int count) { - SkAutoTMalloc storage(get_row_bytes(dinfo)); - uint8_t* storagePtr = storage.get(); - for (int y = 0; y < count; y++) { - if (1 != jpeg_read_scanlines(dinfo, &storagePtr, 1)) { - return y; - } - } - return count; -} -#endif - bool SkJpegCodec::onSkipScanlines(int count) { // Set the jump location for libjpeg errors if (setjmp(fDecoderMgr->getJmpBuf())) { return fDecoderMgr->returnFalse("setjmp"); } +#ifdef TURBO_HAS_SKIP return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); +#else + if (!fSrcRow) { + fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); + fSrcRow = fStorage.get(); + } + + for (int y = 0; y < count; y++) { + if (1 != jpeg_read_scanlines(fDecoderMgr->dinfo(), &fSrcRow, 1)) { + return false; + } + } + return true; +#endif } static bool is_yuv_supported(jpeg_decompress_struct* dinfo) { -- 2.7.4