OLD | NEW |
---|---|
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 "SkJpegCodec.h" | 9 #include "SkJpegCodec.h" |
10 #include "SkJpegDecoderMgr.h" | 10 #include "SkJpegDecoderMgr.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 fSwizzler.reset(nullptr); | 380 fSwizzler.reset(nullptr); |
381 fSrcRow = nullptr; | 381 fSrcRow = nullptr; |
382 fStorage.free(); | 382 fStorage.free(); |
383 | 383 |
384 // Now, given valid output dimensions, we can start the decompress | 384 // Now, given valid output dimensions, we can start the decompress |
385 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { | 385 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { |
386 SkCodecPrintf("start decompress failed\n"); | 386 SkCodecPrintf("start decompress failed\n"); |
387 return kInvalidInput; | 387 return kInvalidInput; |
388 } | 388 } |
389 | 389 |
390 // We will need a swizzler if we are performing a subset decode or | 390 Options subsetOptions = options; |
scroggo
2015/12/16 18:17:01
I almost suggested "partialOptions", but it is act
| |
391 // converting from CMYK. | 391 SkIRect subsetRect = *options.fSubset; |
392 if (options.fSubset || JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { | 392 if (options.fSubset) { |
393 uint32_t startX = options.fSubset->x(); | |
394 uint32_t width = options.fSubset->width(); | |
395 // libjpeg-turbo may need to align startX to a multiple of the IDCT | |
scroggo
2015/12/16 18:17:01
nit: blank line before comments
| |
396 // block size. If this is the case, it will decrease the value of | |
397 // startX to the appropriate alignment and also increase the value | |
398 // of width so that the right edge of the requested subset remains | |
399 // the same. | |
400 jpeg_set_partial_scanline(fDecoderMgr->dinfo(), &startX, &width); | |
scroggo
2015/12/16 18:17:01
Should we have a fallback if jpeg_set_partial_scan
| |
401 | |
402 // We will need a swizzler if libjpeg-turbo cannot provide the exact sub set | |
403 // that we request. Or if we are converting from CMYK. | |
404 if (startX != (uint32_t) options.fSubset->x() || | |
405 width != (uint32_t) options.fSubset->width() || | |
406 JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { | |
scroggo
2015/12/16 18:17:01
I don't understand why we need to check for this h
| |
407 SkASSERT(startX <= (uint32_t) options.fSubset->x()); | |
408 SkASSERT(width >= (uint32_t) options.fSubset->width()); | |
409 SkASSERT(startX + width >= (uint32_t) options.fSubset->right()); | |
scroggo
2015/12/16 18:17:01
nit: blank line between asserts and code
| |
410 subsetRect.fLeft = options.fSubset->x() - startX; | |
scroggo
2015/12/16 18:17:00
IIUC, this means that the subset is now the subset
| |
411 subsetRect.fRight = subsetRect.fLeft + options.fSubset->width(); | |
412 subsetOptions.fSubset = &subsetRect; | |
413 this->initializeSwizzler(dstInfo, subsetOptions); | |
414 } | |
415 } | |
416 | |
417 // Make sure we have a swizzler if we are converting from CMYK. | |
418 if (!fSwizzler && JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { | |
393 this->initializeSwizzler(dstInfo, options); | 419 this->initializeSwizzler(dstInfo, options); |
394 } | 420 } |
395 | 421 |
396 return kSuccess; | 422 return kSuccess; |
397 } | 423 } |
398 | 424 |
399 int SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { | 425 int SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
400 // Set the jump location for libjpeg errors | 426 // Set the jump location for libjpeg errors |
401 if (setjmp(fDecoderMgr->getJmpBuf())) { | 427 if (setjmp(fDecoderMgr->getJmpBuf())) { |
402 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); | 428 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 #endif | 471 #endif |
446 | 472 |
447 bool SkJpegCodec::onSkipScanlines(int count) { | 473 bool SkJpegCodec::onSkipScanlines(int count) { |
448 // Set the jump location for libjpeg errors | 474 // Set the jump location for libjpeg errors |
449 if (setjmp(fDecoderMgr->getJmpBuf())) { | 475 if (setjmp(fDecoderMgr->getJmpBuf())) { |
450 return fDecoderMgr->returnFalse("setjmp"); | 476 return fDecoderMgr->returnFalse("setjmp"); |
451 } | 477 } |
452 | 478 |
453 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); | 479 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
454 } | 480 } |
OLD | NEW |