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 "SkMSAN.h" | 9 #include "SkMSAN.h" |
10 #include "SkJpegCodec.h" | 10 #include "SkJpegCodec.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 default: | 364 default: |
365 // This function should only be called if the colorType is suppo rted by jpeg | 365 // This function should only be called if the colorType is suppo rted by jpeg |
366 SkASSERT(false); | 366 SkASSERT(false); |
367 } | 367 } |
368 } | 368 } |
369 | 369 |
370 if (JCS_RGB == fDecoderMgr->dinfo()->out_color_space) { | 370 if (JCS_RGB == fDecoderMgr->dinfo()->out_color_space) { |
371 srcConfig = SkSwizzler::kRGB; | 371 srcConfig = SkSwizzler::kRGB; |
372 } | 372 } |
373 | 373 |
374 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti ons)); | 374 Options swizzlerOptions = options; |
375 if (options.fSubset) { | |
376 // Use fSwizzlerSubset if this is a subset decode. This is necessary in the case | |
377 // where libjpeg-turbo provides a subset and then we need to subset it f urther. | |
378 swizzlerOptions.fSubset = &fSwizzlerSubset; | |
scroggo
2016/02/22 15:55:03
Should we assert here that fSwizzlerSubset is init
msarett
2016/02/22 17:38:16
Yes that is a bit confusing. I'll add an assert.
| |
379 } | |
380 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, swiz zlerOptions)); | |
375 SkASSERT(fSwizzler); | 381 SkASSERT(fSwizzler); |
376 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); | 382 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); |
377 fSrcRow = fStorage.get(); | 383 fSrcRow = fStorage.get(); |
378 } | 384 } |
379 | 385 |
380 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { | 386 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { |
381 if (!createIfNecessary || fSwizzler) { | 387 if (!createIfNecessary || fSwizzler) { |
382 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); | 388 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); |
383 return fSwizzler; | 389 return fSwizzler; |
384 } | 390 } |
(...skipping 19 matching lines...) Expand all Loading... | |
404 fSwizzler.reset(nullptr); | 410 fSwizzler.reset(nullptr); |
405 fSrcRow = nullptr; | 411 fSrcRow = nullptr; |
406 fStorage.free(); | 412 fStorage.free(); |
407 | 413 |
408 // Now, given valid output dimensions, we can start the decompress | 414 // Now, given valid output dimensions, we can start the decompress |
409 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { | 415 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { |
410 SkCodecPrintf("start decompress failed\n"); | 416 SkCodecPrintf("start decompress failed\n"); |
411 return kInvalidInput; | 417 return kInvalidInput; |
412 } | 418 } |
413 | 419 |
420 if (options.fSubset) { | |
421 fSwizzlerSubset = *options.fSubset; | |
422 } | |
423 | |
424 #ifdef TURBO_HAS_CROP | |
425 if (options.fSubset) { | |
426 uint32_t startX = options.fSubset->x(); | |
427 uint32_t width = options.fSubset->width(); | |
428 | |
429 // libjpeg-turbo may need to align startX to a multiple of the IDCT | |
430 // block size. If this is the case, it will decrease the value of | |
431 // startX to the appropriate alignment and also increase the value | |
432 // of width so that the right edge of the requested subset remains | |
433 // the same. | |
434 jpeg_crop_scanline(fDecoderMgr->dinfo(), &startX, &width); | |
435 | |
436 SkASSERT(startX <= (uint32_t) options.fSubset->x()); | |
437 SkASSERT(width >= (uint32_t) options.fSubset->width()); | |
438 SkASSERT(startX + width >= (uint32_t) options.fSubset->right()); | |
439 | |
440 // Instruct the swizzler (if it is necessary) to further subset the | |
441 // output provided by libjpeg-turbo | |
442 fSwizzlerSubset.setXYWH(options.fSubset->x() - startX, 0, | |
scroggo
2016/02/22 15:55:03
So if I understand correctly, this is set here (ra
msarett
2016/02/22 17:38:16
Yes that's correct.
scroggo
2016/02/22 18:46:47
Maybe add a comment?
msarett
2016/02/22 19:07:43
Done.
| |
443 options.fSubset->width(), options.fSubset->height()); | |
scroggo
2016/02/22 15:55:03
It seems odd that we ever care about the startY an
msarett
2016/02/22 17:38:16
No they don't. They are ignored by SkSwizzler. T
scroggo
2016/02/22 18:46:47
Maybe add a comment?
msarett
2016/02/22 19:07:43
Done.
| |
444 | |
445 // We will need a swizzler if libjpeg-turbo cannot provide the exact | |
446 // subset that we request. Or if we are converting from CMYK. | |
scroggo
2016/02/22 15:55:03
This part of the comment seems unnecessary here. I
msarett
2016/02/22 17:38:16
Done.
| |
447 if (startX != (uint32_t) options.fSubset->x() || | |
448 width != (uint32_t) options.fSubset->width()) { | |
449 this->initializeSwizzler(dstInfo, options); | |
450 } | |
451 } | |
452 | |
453 // Make sure we have a swizzler if we are converting from CMYK. | |
454 if (!fSwizzler && JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { | |
455 this->initializeSwizzler(dstInfo, options); | |
456 } | |
457 #else | |
414 // We will need a swizzler if we are performing a subset decode or | 458 // We will need a swizzler if we are performing a subset decode or |
415 // converting from CMYK. | 459 // converting from CMYK. |
416 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->out_color_space; | 460 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->out_color_space; |
417 if (options.fSubset || JCS_CMYK == colorSpace || JCS_RGB == colorSpace) { | 461 if (options.fSubset || JCS_CMYK == colorSpace || JCS_RGB == colorSpace) { |
418 this->initializeSwizzler(dstInfo, options); | 462 this->initializeSwizzler(dstInfo, options); |
419 } | 463 } |
464 #endif | |
420 | 465 |
421 return kSuccess; | 466 return kSuccess; |
422 } | 467 } |
423 | 468 |
424 int SkJpegCodec::onGetScanlines(void* dst, int count, size_t dstRowBytes) { | 469 int SkJpegCodec::onGetScanlines(void* dst, int count, size_t dstRowBytes) { |
425 // Set the jump location for libjpeg errors | 470 // Set the jump location for libjpeg errors |
426 if (setjmp(fDecoderMgr->getJmpBuf())) { | 471 if (setjmp(fDecoderMgr->getJmpBuf())) { |
427 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); | 472 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
428 } | 473 } |
429 // Read rows one at a time | 474 // Read rows one at a time |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 | 711 |
667 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); | 712 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
668 if (linesRead < remainingRows) { | 713 if (linesRead < remainingRows) { |
669 // FIXME: Handle incomplete YUV decodes without signalling an error. | 714 // FIXME: Handle incomplete YUV decodes without signalling an error. |
670 return kInvalidInput; | 715 return kInvalidInput; |
671 } | 716 } |
672 } | 717 } |
673 | 718 |
674 return kSuccess; | 719 return kSuccess; |
675 } | 720 } |
OLD | NEW |