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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 // Check if we will decode to CMYK because a conversion to RGBA is not suppo rted | 366 // Check if we will decode to CMYK because a conversion to RGBA is not suppo rted |
367 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space; | 367 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space; |
368 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; | 368 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; |
369 | 369 |
370 // Check for valid color types and set the output color space | 370 // Check for valid color types and set the output color space |
371 switch (dst.colorType()) { | 371 switch (dst.colorType()) { |
372 case kRGBA_8888_SkColorType: | 372 case kRGBA_8888_SkColorType: |
373 if (isCMYK) { | 373 if (isCMYK) { |
374 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; | 374 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
375 } else { | 375 } else { |
376 #ifdef LIBJPEG_TURBO_VERSION | 376 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; |
377 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; | |
378 #else | |
379 fDecoderMgr->dinfo()->out_color_space = JCS_RGB; | |
380 #endif | |
381 } | 377 } |
382 return true; | 378 return true; |
383 case kBGRA_8888_SkColorType: | 379 case kBGRA_8888_SkColorType: |
384 if (isCMYK) { | 380 if (isCMYK) { |
385 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; | 381 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
386 } else { | 382 } else { |
387 #ifdef LIBJPEG_TURBO_VERSION | 383 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; |
388 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; | |
389 #else | |
390 fDecoderMgr->dinfo()->out_color_space = JCS_RGB; | |
391 #endif | |
392 } | 384 } |
393 return true; | 385 return true; |
394 case kRGB_565_SkColorType: | 386 case kRGB_565_SkColorType: |
395 if (isCMYK) { | 387 if (isCMYK) { |
396 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; | 388 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
397 } else { | 389 } else { |
398 #ifdef TURBO_HAS_565 | 390 #ifdef TURBO_HAS_565 |
399 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; | 391 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; |
400 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; | 392 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; |
401 #else | 393 #else |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 } | 502 } |
511 | 503 |
512 for (uint32_t y = 0; y < dstHeight; y++) { | 504 for (uint32_t y = 0; y < dstHeight; y++) { |
513 // Read rows of the image | 505 // Read rows of the image |
514 uint32_t lines = jpeg_read_scanlines(dinfo, &dstRow, 1); | 506 uint32_t lines = jpeg_read_scanlines(dinfo, &dstRow, 1); |
515 sk_msan_mark_initialized(dstRow, dstRow + dstRowBytes, "skbug.com/4550") ; | 507 sk_msan_mark_initialized(dstRow, dstRow + dstRowBytes, "skbug.com/4550") ; |
516 | 508 |
517 // If we cannot read enough rows, assume the input is incomplete | 509 // If we cannot read enough rows, assume the input is incomplete |
518 if (lines != 1) { | 510 if (lines != 1) { |
519 *rowsDecoded = y; | 511 *rowsDecoded = y; |
520 | |
521 return fDecoderMgr->returnFailure("Incomplete image data", kIncomple teInput); | 512 return fDecoderMgr->returnFailure("Incomplete image data", kIncomple teInput); |
522 } | 513 } |
523 | 514 |
524 if (fSwizzler) { | 515 if (fSwizzler) { |
525 // use swizzler to sample row | 516 // use swizzler to sample row |
526 fSwizzler->swizzle(dst, dstRow); | 517 fSwizzler->swizzle(dst, dstRow); |
527 dst = SkTAddOffset<JSAMPLE>(dst, dstRowBytes); | 518 dst = SkTAddOffset<JSAMPLE>(dst, dstRowBytes); |
528 } else { | 519 } else { |
529 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); | 520 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); |
530 } | 521 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 if (!this->setOutputColorSpace(dstInfo)) { | 584 if (!this->setOutputColorSpace(dstInfo)) { |
594 return kInvalidConversion; | 585 return kInvalidConversion; |
595 } | 586 } |
596 | 587 |
597 // Now, given valid output dimensions, we can start the decompress | 588 // Now, given valid output dimensions, we can start the decompress |
598 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { | 589 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { |
599 SkCodecPrintf("start decompress failed\n"); | 590 SkCodecPrintf("start decompress failed\n"); |
600 return kInvalidInput; | 591 return kInvalidInput; |
601 } | 592 } |
602 | 593 |
603 if (options.fSubset) { | |
msarett
2016/07/21 15:26:53
Just moved this code block because it was confusin
| |
604 fSwizzlerSubset = *options.fSubset; | |
605 } | |
606 | |
607 #ifdef TURBO_HAS_CROP | 594 #ifdef TURBO_HAS_CROP |
608 if (options.fSubset) { | 595 if (options.fSubset) { |
609 uint32_t startX = options.fSubset->x(); | 596 uint32_t startX = options.fSubset->x(); |
610 uint32_t width = options.fSubset->width(); | 597 uint32_t width = options.fSubset->width(); |
611 | 598 |
612 // libjpeg-turbo may need to align startX to a multiple of the IDCT | 599 // libjpeg-turbo may need to align startX to a multiple of the IDCT |
613 // block size. If this is the case, it will decrease the value of | 600 // block size. If this is the case, it will decrease the value of |
614 // startX to the appropriate alignment and also increase the value | 601 // startX to the appropriate alignment and also increase the value |
615 // of width so that the right edge of the requested subset remains | 602 // of width so that the right edge of the requested subset remains |
616 // the same. | 603 // the same. |
(...skipping 23 matching lines...) Expand all Loading... | |
640 width != (uint32_t) options.fSubset->width()) { | 627 width != (uint32_t) options.fSubset->width()) { |
641 this->initializeSwizzler(dstInfo, options); | 628 this->initializeSwizzler(dstInfo, options); |
642 } | 629 } |
643 } | 630 } |
644 | 631 |
645 // Make sure we have a swizzler if we are converting from CMYK. | 632 // Make sure we have a swizzler if we are converting from CMYK. |
646 if (!fSwizzler && JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { | 633 if (!fSwizzler && JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { |
647 this->initializeSwizzler(dstInfo, options); | 634 this->initializeSwizzler(dstInfo, options); |
648 } | 635 } |
649 #else | 636 #else |
637 if (options.fSubset) { | |
638 fSwizzlerSubset = *options.fSubset; | |
639 } | |
640 | |
650 // We will need a swizzler if we are performing a subset decode or | 641 // We will need a swizzler if we are performing a subset decode or |
651 // converting from CMYK. | 642 // converting from CMYK. |
652 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->out_color_space; | 643 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->out_color_space; |
653 if (options.fSubset || JCS_CMYK == colorSpace || JCS_RGB == colorSpace) { | 644 if (options.fSubset || JCS_CMYK == colorSpace || JCS_RGB == colorSpace) { |
654 this->initializeSwizzler(dstInfo, options); | 645 this->initializeSwizzler(dstInfo, options); |
655 } | 646 } |
656 #endif | 647 #endif |
657 | 648 |
658 return kSuccess; | 649 return kSuccess; |
659 } | 650 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 | 899 |
909 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); | 900 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
910 if (linesRead < remainingRows) { | 901 if (linesRead < remainingRows) { |
911 // FIXME: Handle incomplete YUV decodes without signalling an error. | 902 // FIXME: Handle incomplete YUV decodes without signalling an error. |
912 return kInvalidInput; | 903 return kInvalidInput; |
913 } | 904 } |
914 } | 905 } |
915 | 906 |
916 return kSuccess; | 907 return kSuccess; |
917 } | 908 } |
OLD | NEW |