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. We must indic
ate the |
514 if (JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { | 514 // appropriate format to the swizzler. |
515 srcConfig = SkSwizzler::kCMYK; | 515 SkEncodedInfo swizzlerInfo; |
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_RGB: |
518 // for sampling and/or subsetting. | 518 swizzlerInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kRGB_
Color); |
519 switch (dstInfo.colorType()) { | 519 break; |
520 case kGray_8_SkColorType: | 520 case JCS_CMYK: |
521 srcConfig = SkSwizzler::kNoOp8; | 521 swizzlerInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kInve
rtedCMYK_Color); |
522 break; | 522 break; |
523 case kN32_SkColorType: | 523 default: |
524 srcConfig = SkSwizzler::kNoOp32; | 524 swizzlerInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kPreS
wizzled_Color); |
525 break; | 525 break; |
526 case kRGB_565_SkColorType: | |
527 srcConfig = SkSwizzler::kNoOp16; | |
528 break; | |
529 default: | |
530 // This function should only be called if the colorType is suppo
rted by jpeg | |
531 SkASSERT(false); | |
532 } | |
533 } | |
534 | |
535 if (JCS_RGB == fDecoderMgr->dinfo()->out_color_space) { | |
536 srcConfig = SkSwizzler::kRGB; | |
537 } | 526 } |
538 | 527 |
539 Options swizzlerOptions = options; | 528 Options swizzlerOptions = options; |
540 if (options.fSubset) { | 529 if (options.fSubset) { |
541 // Use fSwizzlerSubset if this is a subset decode. This is necessary in
the case | 530 // 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. | 531 // where libjpeg-turbo provides a subset and then we need to subset it f
urther. |
543 // Also, verify that fSwizzlerSubset is initialized and valid. | 532 // Also, verify that fSwizzlerSubset is initialized and valid. |
544 SkASSERT(!fSwizzlerSubset.isEmpty() && fSwizzlerSubset.x() <= options.fS
ubset->x() && | 533 SkASSERT(!fSwizzlerSubset.isEmpty() && fSwizzlerSubset.x() <= options.fS
ubset->x() && |
545 fSwizzlerSubset.width() == options.fSubset->width()); | 534 fSwizzlerSubset.width() == options.fSubset->width()); |
546 swizzlerOptions.fSubset = &fSwizzlerSubset; | 535 swizzlerOptions.fSubset = &fSwizzlerSubset; |
547 } | 536 } |
548 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, swiz
zlerOptions)); | 537 fSwizzler.reset(SkSwizzler::CreateSwizzler(swizzlerInfo, nullptr, dstInfo, s
wizzlerOptions)); |
549 SkASSERT(fSwizzler); | 538 SkASSERT(fSwizzler); |
550 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); | 539 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); |
551 fSrcRow = fStorage.get(); | 540 fSrcRow = fStorage.get(); |
552 } | 541 } |
553 | 542 |
554 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { | 543 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { |
555 if (!createIfNecessary || fSwizzler) { | 544 if (!createIfNecessary || fSwizzler) { |
556 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); | 545 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); |
557 return fSwizzler; | 546 return fSwizzler; |
558 } | 547 } |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 | 882 |
894 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); | 883 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
895 if (linesRead < remainingRows) { | 884 if (linesRead < remainingRows) { |
896 // FIXME: Handle incomplete YUV decodes without signalling an error. | 885 // FIXME: Handle incomplete YUV decodes without signalling an error. |
897 return kInvalidInput; | 886 return kInvalidInput; |
898 } | 887 } |
899 } | 888 } |
900 | 889 |
901 return kSuccess; | 890 return kSuccess; |
902 } | 891 } |
OLD | NEW |