More efficient Jpeg skipScanlines for older versions of libjpeg-turbo
authormsarett <msarett@google.com>
Wed, 10 Feb 2016 21:49:36 +0000 (13:49 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 10 Feb 2016 21:49:36 +0000 (13:49 -0800)
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

index aefe264f1ad9b1963e0359da4d51801b35b3d734..50186e721310a6d33253fead2899825211c69126 100644 (file)
@@ -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<uint8_t> 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) {