Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: src/codec/SkJpegCodec.cpp

Issue 1683283002: More efficient Jpeg skipScanlines for older versions of libjpeg-turbo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkMSAN.h" 9 #include "SkMSAN.h"
10 #include "SkJpegCodec.h" 10 #include "SkJpegCodec.h"
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // use swizzler to sample row 431 // use swizzler to sample row
432 fSwizzler->swizzle(dst, dstRow); 432 fSwizzler->swizzle(dst, dstRow);
433 dst = SkTAddOffset<JSAMPLE>(dst, dstRowBytes); 433 dst = SkTAddOffset<JSAMPLE>(dst, dstRowBytes);
434 } else { 434 } else {
435 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); 435 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes);
436 } 436 }
437 } 437 }
438 return count; 438 return count;
439 } 439 }
440 440
441 #ifndef TURBO_HAS_SKIP
442 // TODO (msarett): Avoid reallocating the memory buffer on each call to skip.
443 static uint32_t jpeg_skip_scanlines(jpeg_decompress_struct* dinfo, int count) {
444 SkAutoTMalloc<uint8_t> storage(get_row_bytes(dinfo));
445 uint8_t* storagePtr = storage.get();
446 for (int y = 0; y < count; y++) {
447 if (1 != jpeg_read_scanlines(dinfo, &storagePtr, 1)) {
448 return y;
449 }
450 }
451 return count;
452 }
453 #endif
454
455 bool SkJpegCodec::onSkipScanlines(int count) { 441 bool SkJpegCodec::onSkipScanlines(int count) {
456 // Set the jump location for libjpeg errors 442 // Set the jump location for libjpeg errors
457 if (setjmp(fDecoderMgr->getJmpBuf())) { 443 if (setjmp(fDecoderMgr->getJmpBuf())) {
458 return fDecoderMgr->returnFalse("setjmp"); 444 return fDecoderMgr->returnFalse("setjmp");
459 } 445 }
460 446
447 #ifdef TURBO_HAS_SKIP
461 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); 448 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count);
449 #else
450 if (!fSrcRow) {
451 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo()));
452 fSrcRow = fStorage.get();
453 }
454
455 for (int y = 0; y < count; y++) {
456 if (1 != jpeg_read_scanlines(fDecoderMgr->dinfo(), &fSrcRow, 1)) {
457 return false;
458 }
459 }
460 return true;
461 #endif
462 } 462 }
463 463
464 static bool is_yuv_supported(jpeg_decompress_struct* dinfo) { 464 static bool is_yuv_supported(jpeg_decompress_struct* dinfo) {
465 // Scaling is not supported in raw data mode. 465 // Scaling is not supported in raw data mode.
466 SkASSERT(dinfo->scale_num == dinfo->scale_denom); 466 SkASSERT(dinfo->scale_num == dinfo->scale_denom);
467 467
468 // I can't imagine that this would ever change, but we do depend on it. 468 // I can't imagine that this would ever change, but we do depend on it.
469 static_assert(8 == DCTSIZE, "DCTSIZE (defined in jpeg library) should always be 8."); 469 static_assert(8 == DCTSIZE, "DCTSIZE (defined in jpeg library) should always be 8.");
470 470
471 if (JCS_YCbCr != dinfo->jpeg_color_space) { 471 if (JCS_YCbCr != dinfo->jpeg_color_space) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 646
647 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); 647 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock);
648 if (linesRead < remainingRows) { 648 if (linesRead < remainingRows) {
649 // FIXME: Handle incomplete YUV decodes without signalling an error. 649 // FIXME: Handle incomplete YUV decodes without signalling an error.
650 return kInvalidInput; 650 return kInvalidInput;
651 } 651 }
652 } 652 }
653 653
654 return kSuccess; 654 return kSuccess;
655 } 655 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698