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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 SkCodecPrintf("Warning: an opaque image should be decoded as opaque " | 349 SkCodecPrintf("Warning: an opaque image should be decoded as opaque " |
350 "- it is being decoded as non-opaque, which will draw slow
er\n"); | 350 "- it is being decoded as non-opaque, which will draw slow
er\n"); |
351 } | 351 } |
352 | 352 |
353 // Check if we will decode to CMYK because a conversion to RGBA is not suppo
rted | 353 // Check if we will decode to CMYK because a conversion to RGBA is not suppo
rted |
354 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space; | 354 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space; |
355 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; | 355 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; |
356 | 356 |
357 // Check for valid color types and set the output color space | 357 // Check for valid color types and set the output color space |
358 switch (dst.colorType()) { | 358 switch (dst.colorType()) { |
359 case kN32_SkColorType: | 359 case kRGBA_8888_SkColorType: |
360 if (isCMYK) { | 360 if (isCMYK) { |
361 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; | 361 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
362 } else { | 362 } else { |
363 #ifdef LIBJPEG_TURBO_VERSION | 363 #ifdef LIBJPEG_TURBO_VERSION |
364 // Check the byte ordering of the RGBA color space for the | |
365 // current platform | |
366 #ifdef SK_PMCOLOR_IS_RGBA | |
367 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; | 364 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; |
368 #else | |
369 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; | |
370 #endif | |
371 #else | 365 #else |
372 fDecoderMgr->dinfo()->out_color_space = JCS_RGB; | 366 fDecoderMgr->dinfo()->out_color_space = JCS_RGB; |
373 #endif | 367 #endif |
| 368 } |
| 369 return true; |
| 370 case kBGRA_8888_SkColorType: |
| 371 if (isCMYK) { |
| 372 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
| 373 } else { |
| 374 #ifdef LIBJPEG_TURBO_VERSION |
| 375 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; |
| 376 #else |
| 377 fDecoderMgr->dinfo()->out_color_space = JCS_RGB; |
| 378 #endif |
374 } | 379 } |
375 return true; | 380 return true; |
376 case kRGB_565_SkColorType: | 381 case kRGB_565_SkColorType: |
377 if (isCMYK) { | 382 if (isCMYK) { |
378 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; | 383 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
379 } else { | 384 } else { |
380 #ifdef TURBO_HAS_565 | 385 #ifdef TURBO_HAS_565 |
381 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; | 386 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; |
382 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; | 387 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; |
383 #else | 388 #else |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 dst = SkTAddOffset<JSAMPLE>(dst, dstRowBytes); | 514 dst = SkTAddOffset<JSAMPLE>(dst, dstRowBytes); |
510 } else { | 515 } else { |
511 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); | 516 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); |
512 } | 517 } |
513 } | 518 } |
514 | 519 |
515 return kSuccess; | 520 return kSuccess; |
516 } | 521 } |
517 | 522 |
518 void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options&
options) { | 523 void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options&
options) { |
519 SkSwizzler::SrcConfig srcConfig = SkSwizzler::kUnknown; | 524 // libjpeg-turbo may have already performed color conversion. In this |
520 if (JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { | 525 // case, we must indicate to the swizzler the appropriate encoded format. |
521 srcConfig = SkSwizzler::kCMYK; | 526 SkEncodedInfo encodedInfo; |
522 } else { | 527 switch (fDecoderMgr->dinfo()->out_color_space) { |
523 // If the out_color_space is not CMYK, the only reason we would need a s
wizzler is | 528 case JCS_GRAYSCALE: |
524 // for sampling and/or subsetting. | 529 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kGray_
Color); |
525 switch (dstInfo.colorType()) { | 530 break; |
526 case kGray_8_SkColorType: | 531 case JCS_RGB: |
527 srcConfig = SkSwizzler::kNoOp8; | 532 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kRGB_C
olor); |
528 break; | 533 break; |
529 case kN32_SkColorType: | 534 #ifdef LIBJPEG_TURBO_VERSION |
530 srcConfig = SkSwizzler::kNoOp32; | 535 case JCS_EXT_RGBA: |
531 break; | 536 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kRGBA_
Color); |
532 case kRGB_565_SkColorType: | 537 break; |
533 srcConfig = SkSwizzler::kNoOp16; | 538 case JCS_EXT_BGRA: |
534 break; | 539 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kBGRA_
Color); |
535 default: | 540 break; |
536 // This function should only be called if the colorType is suppo
rted by jpeg | 541 #endif |
537 SkASSERT(false); | 542 case JCS_CMYK: |
538 } | 543 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kInver
tedCMYK_Color); |
539 } | 544 break; |
540 | 545 #ifdef TURBO_HAS_565 |
541 if (JCS_RGB == fDecoderMgr->dinfo()->out_color_space) { | 546 case JCS_RGB565: |
542 srcConfig = SkSwizzler::kRGB; | 547 encodedInfo = this->getEncodedInfo().makeColor(SkEncodedInfo::kUnkno
wn_Color); |
| 548 break; |
| 549 #endif |
| 550 default: |
| 551 SkASSERT(false); |
| 552 break; |
543 } | 553 } |
544 | 554 |
545 Options swizzlerOptions = options; | 555 Options swizzlerOptions = options; |
546 if (options.fSubset) { | 556 if (options.fSubset) { |
547 // Use fSwizzlerSubset if this is a subset decode. This is necessary in
the case | 557 // Use fSwizzlerSubset if this is a subset decode. This is necessary in
the case |
548 // where libjpeg-turbo provides a subset and then we need to subset it f
urther. | 558 // where libjpeg-turbo provides a subset and then we need to subset it f
urther. |
549 // Also, verify that fSwizzlerSubset is initialized and valid. | 559 // Also, verify that fSwizzlerSubset is initialized and valid. |
550 SkASSERT(!fSwizzlerSubset.isEmpty() && fSwizzlerSubset.x() <= options.fS
ubset->x() && | 560 SkASSERT(!fSwizzlerSubset.isEmpty() && fSwizzlerSubset.x() <= options.fS
ubset->x() && |
551 fSwizzlerSubset.width() == options.fSubset->width()); | 561 fSwizzlerSubset.width() == options.fSubset->width()); |
552 swizzlerOptions.fSubset = &fSwizzlerSubset; | 562 swizzlerOptions.fSubset = &fSwizzlerSubset; |
553 } | 563 } |
554 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, swiz
zlerOptions)); | 564 fSwizzler.reset(SkSwizzler::CreateSwizzler(encodedInfo, nullptr, dstInfo, sw
izzlerOptions)); |
555 SkASSERT(fSwizzler); | 565 SkASSERT(fSwizzler); |
556 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); | 566 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); |
557 fSrcRow = fStorage.get(); | 567 fSrcRow = fStorage.get(); |
558 } | 568 } |
559 | 569 |
560 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { | 570 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { |
561 if (!createIfNecessary || fSwizzler) { | 571 if (!createIfNecessary || fSwizzler) { |
562 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); | 572 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); |
563 return fSwizzler; | 573 return fSwizzler; |
564 } | 574 } |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 | 909 |
900 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); | 910 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
901 if (linesRead < remainingRows) { | 911 if (linesRead < remainingRows) { |
902 // FIXME: Handle incomplete YUV decodes without signalling an error. | 912 // FIXME: Handle incomplete YUV decodes without signalling an error. |
903 return kInvalidInput; | 913 return kInvalidInput; |
904 } | 914 } |
905 } | 915 } |
906 | 916 |
907 return kSuccess; | 917 return kSuccess; |
908 } | 918 } |
OLD | NEW |