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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 dst = SkTAddOffset<JSAMPLE>(dst, dstRowBytes); | 503 dst = SkTAddOffset<JSAMPLE>(dst, dstRowBytes); |
504 } else { | 504 } else { |
505 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); | 505 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); |
506 } | 506 } |
507 } | 507 } |
508 | 508 |
509 return kSuccess; | 509 return kSuccess; |
510 } | 510 } |
511 | 511 |
512 void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& options) { | 512 void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& options) { |
513 SkSwizzler::SrcConfig srcConfig = SkSwizzler::kUnknown; | 513 // libjpeg-turbo may have already performed color conversion. In this |
514 if (JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { | 514 // case, we must indicate to the swizzler the appropriate encoded format. |
515 srcConfig = SkSwizzler::kCMYK; | 515 SkEncodedInfo encodedInfo; |
516 } else { | 516 switch (fDecoderMgr->dinfo()->out_color_space) { |
517 // If the out_color_space is not CMYK, the only reason we would need a s wizzler is | 517 case JCS_GRAYSCALE: |
518 // for sampling and/or subsetting. | 518 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kGray_ Color); |
519 switch (dstInfo.colorType()) { | 519 break; |
520 case kGray_8_SkColorType: | 520 case JCS_RGB: |
521 srcConfig = SkSwizzler::kNoOp8; | 521 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kRGB_C olor); |
522 break; | 522 break; |
523 case kN32_SkColorType: | 523 #ifdef LIBJPEG_TURBO_VERSION |
524 srcConfig = SkSwizzler::kNoOp32; | 524 case JCS_EXT_RGBA: |
525 break; | 525 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kRGBA_ Color); |
526 case kRGB_565_SkColorType: | 526 break; |
527 srcConfig = SkSwizzler::kNoOp16; | 527 case JCS_EXT_BGRA: |
528 break; | 528 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kBGRA_ Color); |
529 default: | 529 break; |
530 // This function should only be called if the colorType is suppo rted by jpeg | 530 #endif |
531 SkASSERT(false); | 531 case JCS_CMYK: |
532 } | 532 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kInver tedCMYK_Color); |
533 } | 533 break; |
534 | 534 #ifdef TURBO_HAS_565 |
535 if (JCS_RGB == fDecoderMgr->dinfo()->out_color_space) { | 535 case JCS_RGB565: |
536 srcConfig = SkSwizzler::kRGB; | 536 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kUnkno wn_Color); |
scroggo
2016/04/21 15:09:11
If you don't add a new color type for this, I thin
msarett
2016/04/21 16:03:41
Using kPreSwizzled.
| |
537 break; | |
538 #endif | |
539 default: | |
540 SkASSERT(false); | |
541 break; | |
537 } | 542 } |
538 | 543 |
539 Options swizzlerOptions = options; | 544 Options swizzlerOptions = options; |
540 if (options.fSubset) { | 545 if (options.fSubset) { |
541 // Use fSwizzlerSubset if this is a subset decode. This is necessary in the case | 546 // Use fSwizzlerSubset if this is a subset decode. This is necessary in the case |
542 // where libjpeg-turbo provides a subset and then we need to subset it f urther. | 547 // where libjpeg-turbo provides a subset and then we need to subset it f urther. |
543 // Also, verify that fSwizzlerSubset is initialized and valid. | 548 // Also, verify that fSwizzlerSubset is initialized and valid. |
544 SkASSERT(!fSwizzlerSubset.isEmpty() && fSwizzlerSubset.x() <= options.fS ubset->x() && | 549 SkASSERT(!fSwizzlerSubset.isEmpty() && fSwizzlerSubset.x() <= options.fS ubset->x() && |
545 fSwizzlerSubset.width() == options.fSubset->width()); | 550 fSwizzlerSubset.width() == options.fSubset->width()); |
546 swizzlerOptions.fSubset = &fSwizzlerSubset; | 551 swizzlerOptions.fSubset = &fSwizzlerSubset; |
547 } | 552 } |
548 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, swiz zlerOptions)); | 553 fSwizzler.reset(SkSwizzler::CreateSwizzler(encodedInfo, nullptr, dstInfo, sw izzlerOptions)); |
549 SkASSERT(fSwizzler); | 554 SkASSERT(fSwizzler); |
550 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); | 555 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); |
551 fSrcRow = fStorage.get(); | 556 fSrcRow = fStorage.get(); |
552 } | 557 } |
553 | 558 |
554 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { | 559 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { |
555 if (!createIfNecessary || fSwizzler) { | 560 if (!createIfNecessary || fSwizzler) { |
556 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); | 561 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); |
557 return fSwizzler; | 562 return fSwizzler; |
558 } | 563 } |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 | 898 |
894 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); | 899 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
895 if (linesRead < remainingRows) { | 900 if (linesRead < remainingRows) { |
896 // FIXME: Handle incomplete YUV decodes without signalling an error. | 901 // FIXME: Handle incomplete YUV decodes without signalling an error. |
897 return kInvalidInput; | 902 return kInvalidInput; |
898 } | 903 } |
899 } | 904 } |
900 | 905 |
901 return kSuccess; | 906 return kSuccess; |
902 } | 907 } |
OLD | NEW |