OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
3 * | 3 * |
4 * Portions are Copyright (C) 2001-6 mozilla.org | 4 * Portions are Copyright (C) 2001-6 mozilla.org |
5 * | 5 * |
6 * Other contributors: | 6 * Other contributors: |
7 * Stuart Parmenter <stuart@mozilla.com> | 7 * Stuart Parmenter <stuart@mozilla.com> |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Lesser General Public | 10 * modify it under the terms of the GNU Lesser General Public |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 #error Blink assumes a little-endian target. | 58 #error Blink assumes a little-endian target. |
59 #endif | 59 #endif |
60 | 60 |
61 #if defined(JCS_ALPHA_EXTENSIONS) | 61 #if defined(JCS_ALPHA_EXTENSIONS) |
62 #define TURBO_JPEG_RGB_SWIZZLE | 62 #define TURBO_JPEG_RGB_SWIZZLE |
63 #if SK_B32_SHIFT // Output little-endian RGBA pixels (Android). | 63 #if SK_B32_SHIFT // Output little-endian RGBA pixels (Android). |
64 inline J_COLOR_SPACE rgbOutputColorSpace() { return JCS_EXT_RGBA; } | 64 inline J_COLOR_SPACE rgbOutputColorSpace() { return JCS_EXT_RGBA; } |
65 #else // Output little-endian BGRA pixels. | 65 #else // Output little-endian BGRA pixels. |
66 inline J_COLOR_SPACE rgbOutputColorSpace() { return JCS_EXT_BGRA; } | 66 inline J_COLOR_SPACE rgbOutputColorSpace() { return JCS_EXT_BGRA; } |
67 #endif | 67 #endif |
68 inline bool turboSwizzled(J_COLOR_SPACE colorSpace) { return colorSpace == JCS_E XT_RGBA || colorSpace == JCS_EXT_BGRA; } | 68 inline bool turboSwizzled(J_COLOR_SPACE colorSpace) { return colorSpace == JCS_E XT_RGBA || colorSpace == JCS_EXT_BGRA || colorSpace == JCS_RGB565; } |
69 inline bool colorSpaceHasAlpha(J_COLOR_SPACE colorSpace) { return turboSwizzled( colorSpace); } | 69 inline bool colorSpaceHasAlpha(J_COLOR_SPACE colorSpace) { return turboSwizzled( colorSpace); } |
70 #else | 70 #else |
71 inline J_COLOR_SPACE rgbOutputColorSpace() { return JCS_RGB; } | 71 inline J_COLOR_SPACE rgbOutputColorSpace() { return JCS_RGB; } |
72 inline bool colorSpaceHasAlpha(J_COLOR_SPACE) { return false; } | 72 inline bool colorSpaceHasAlpha(J_COLOR_SPACE) { return false; } |
73 #endif | 73 #endif |
74 | 74 |
75 namespace { | 75 namespace { |
76 | 76 |
77 const int exifMarker = JPEG_APP0 + 1; | 77 const int exifMarker = JPEG_APP0 + 1; |
78 | 78 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 break; | 465 break; |
466 case JCS_CMYK: | 466 case JCS_CMYK: |
467 case JCS_YCCK: | 467 case JCS_YCCK: |
468 // libjpeg can convert YCCK to CMYK, but neither to RGB, so we | 468 // libjpeg can convert YCCK to CMYK, but neither to RGB, so we |
469 // manually convert CMKY to RGB. | 469 // manually convert CMKY to RGB. |
470 m_info.out_color_space = JCS_CMYK; | 470 m_info.out_color_space = JCS_CMYK; |
471 break; | 471 break; |
472 default: | 472 default: |
473 return m_decoder->setFailed(); | 473 return m_decoder->setFailed(); |
474 } | 474 } |
475 if (m_decoder->decodeToRGB565Enabled()) { | |
476 if (m_info.out_color_space == rgbOutputColorSpace()) { | |
477 // the rest would need to be converted manually on write | |
478 #if defined (JCS_ALPHA_EXTENSIONS) | |
479 m_info.out_color_space = JCS_RGB565; | |
480 #else | |
481 m_info.out_color_space = JCS_RGB; | |
scroggo_chromium
2015/10/19 20:41:36
Isn't that the same as rgbOutputColorSpace when JC
aleksandar.stojiljkovic
2015/10/20 09:51:12
Correct, not needed to set to same.
| |
482 #endif | |
483 #if USE(QCMSLIB) | |
484 // if there is colorprofile, use JCS_RGB as QCMS is not supp orting RGB565 | |
485 // conversion, RGB->RGB565 happens in outputRows<>() | |
486 if (!m_decoder->ignoresGammaAndColorProfile()) | |
487 m_info.out_color_space = JCS_RGB; | |
488 #endif | |
489 } | |
490 } | |
491 // fell through | |
scroggo_chromium
2015/10/19 20:41:36
nit: Other places in this file say "FALL THROUGH".
aleksandar.stojiljkovic
2015/10/20 09:51:12
Done.
| |
475 | 492 |
476 m_state = JPEG_START_DECOMPRESS; | 493 m_state = JPEG_START_DECOMPRESS; |
477 | 494 |
478 // We can fill in the size now that the header is available. | 495 // We can fill in the size now that the header is available. |
479 if (!m_decoder->setSize(m_info.image_width, m_info.image_height)) | 496 if (!m_decoder->setSize(m_info.image_width, m_info.image_height)) |
480 return false; | 497 return false; |
481 | 498 |
482 // Calculate and set decoded size. | 499 // Calculate and set decoded size. |
483 m_info.scale_num = m_decoder->desiredScaleNumerator(); | 500 m_info.scale_num = m_decoder->desiredScaleNumerator(); |
484 m_info.scale_denom = scaleDenominator; | 501 m_info.scale_denom = scaleDenominator; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 clearBuffer(); | 555 clearBuffer(); |
539 return true; | 556 return true; |
540 } | 557 } |
541 // FALL THROUGH | 558 // FALL THROUGH |
542 | 559 |
543 case JPEG_START_DECOMPRESS: | 560 case JPEG_START_DECOMPRESS: |
544 // Set parameters for decompression. | 561 // Set parameters for decompression. |
545 // FIXME -- Should reset dct_method and dither mode for final pass | 562 // FIXME -- Should reset dct_method and dither mode for final pass |
546 // of progressive JPEG. | 563 // of progressive JPEG. |
547 m_info.dct_method = JDCT_ISLOW; | 564 m_info.dct_method = JDCT_ISLOW; |
548 m_info.dither_mode = JDITHER_FS; | 565 m_info.dither_mode = JDITHER_FS; |
aleksandar.stojiljkovic
2015/10/19 18:17:10
Dither: Floyd-Steinberg set here for all decoding.
| |
549 m_info.do_fancy_upsampling = true; | 566 m_info.do_fancy_upsampling = true; |
550 m_info.do_block_smoothing = true; | 567 m_info.do_block_smoothing = true; |
551 m_info.enable_2pass_quant = false; | 568 m_info.enable_2pass_quant = false; |
552 // FIXME: should we just assert these? | 569 // FIXME: should we just assert these? |
553 m_info.enable_external_quant = false; | 570 m_info.enable_external_quant = false; |
554 m_info.enable_1pass_quant = false; | 571 m_info.enable_1pass_quant = false; |
555 m_info.quantize_colors = false; | 572 m_info.quantize_colors = false; |
556 m_info.colormap = 0; | 573 m_info.colormap = 0; |
557 | 574 |
558 // Make a one-row-high sample array that will go away when done with | 575 // Make a one-row-high sample array that will go away when done with |
(...skipping 22 matching lines...) Expand all Loading... | |
581 return false; // I/O suspension. | 598 return false; // I/O suspension. |
582 | 599 |
583 // If we've completed image output... | 600 // If we've completed image output... |
584 ASSERT(m_info.output_scanline == m_info.output_height); | 601 ASSERT(m_info.output_scanline == m_info.output_height); |
585 m_state = JPEG_DONE; | 602 m_state = JPEG_DONE; |
586 } | 603 } |
587 // FALL THROUGH | 604 // FALL THROUGH |
588 | 605 |
589 case JPEG_DECOMPRESS_PROGRESSIVE: | 606 case JPEG_DECOMPRESS_PROGRESSIVE: |
590 if (m_state == JPEG_DECOMPRESS_PROGRESSIVE) { | 607 if (m_state == JPEG_DECOMPRESS_PROGRESSIVE) { |
608 | |
scroggo_chromium
2015/10/19 20:41:36
Why the extra line here?
| |
591 int status = 0; | 609 int status = 0; |
592 do { | 610 do { |
593 decoder_error_mgr* err = reinterpret_cast_ptr<decoder_error_ mgr*>(m_info.err); | 611 decoder_error_mgr* err = reinterpret_cast_ptr<decoder_error_ mgr*>(m_info.err); |
594 if (err->num_corrupt_warnings) | 612 if (err->num_corrupt_warnings) |
595 break; | 613 break; |
596 status = jpeg_consume_input(&m_info); | 614 status = jpeg_consume_input(&m_info); |
597 } while ((status != JPEG_SUSPENDED) && (status != JPEG_REACHED_E OI)); | 615 } while ((status != JPEG_SUSPENDED) && (status != JPEG_REACHED_E OI)); |
598 | 616 |
599 for (;;) { | 617 for (;;) { |
600 if (!m_info.output_scanline) { | 618 if (!m_info.output_scanline) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 | 791 |
774 void term_source(j_decompress_ptr jd) | 792 void term_source(j_decompress_ptr jd) |
775 { | 793 { |
776 decoder_source_mgr* src = reinterpret_cast_ptr<decoder_source_mgr*>(jd->src) ; | 794 decoder_source_mgr* src = reinterpret_cast_ptr<decoder_source_mgr*>(jd->src) ; |
777 src->decoder->decoder()->complete(); | 795 src->decoder->decoder()->complete(); |
778 } | 796 } |
779 | 797 |
780 JPEGImageDecoder::JPEGImageDecoder(AlphaOption alphaOption, GammaAndColorProfile Option colorOptions, size_t maxDecodedBytes) | 798 JPEGImageDecoder::JPEGImageDecoder(AlphaOption alphaOption, GammaAndColorProfile Option colorOptions, size_t maxDecodedBytes) |
781 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) | 799 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) |
782 , m_hasColorProfile(false) | 800 , m_hasColorProfile(false) |
801 , m_decodeToRGB565(false) | |
783 { | 802 { |
784 } | 803 } |
785 | 804 |
786 JPEGImageDecoder::~JPEGImageDecoder() | 805 JPEGImageDecoder::~JPEGImageDecoder() |
787 { | 806 { |
788 } | 807 } |
789 | 808 |
790 bool JPEGImageDecoder::setSize(unsigned width, unsigned height) | 809 bool JPEGImageDecoder::setSize(unsigned width, unsigned height) |
791 { | 810 { |
792 if (!ImageDecoder::setSize(width, height)) | 811 if (!ImageDecoder::setSize(width, height)) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 return scaleNumerator; | 853 return scaleNumerator; |
835 } | 854 } |
836 | 855 |
837 bool JPEGImageDecoder::canDecodeToYUV() | 856 bool JPEGImageDecoder::canDecodeToYUV() |
838 { | 857 { |
839 // Calling isSizeAvailable() ensures the reader is created and the output | 858 // Calling isSizeAvailable() ensures the reader is created and the output |
840 // color space is set. | 859 // color space is set. |
841 return isSizeAvailable() && m_reader->info()->out_color_space == JCS_YCbCr; | 860 return isSizeAvailable() && m_reader->info()->out_color_space == JCS_YCbCr; |
842 } | 861 } |
843 | 862 |
863 bool JPEGImageDecoder::canDecodeToRGB565() | |
864 { | |
865 // Calling isSizeAvailable() ensures the reader is created and the output | |
scroggo_chromium
2015/10/19 20:41:36
I do not follow how this comment applies.
aleksandar.stojiljkovic
2015/10/20 09:51:12
Didn't do cleanup after copy paste.
Also decoding
| |
866 // color space is set. | |
867 #if defined(JCS_ALPHA_EXTENSIONS) | |
868 return true; | |
869 #else | |
870 return false; | |
871 #endif | |
872 } | |
873 | |
874 bool JPEGImageDecoder::setDecodeRGB565Enabled(const bool enable) | |
875 { | |
876 #if defined(JCS_ALPHA_EXTENSIONS) | |
877 m_decodeToRGB565 = enable; | |
scroggo_chromium
2015/10/19 20:41:36
Should m_decodeToRGB565 only be defined if JCS_ALP
aleksandar.stojiljkovic
2015/10/20 09:51:12
Done.
| |
878 return true; | |
879 #else | |
880 if (!enable) | |
scroggo_chromium
2015/10/19 20:41:36
Can this just be:
return !enable
and then drop
aleksandar.stojiljkovic
2015/10/20 09:51:12
Done.
| |
881 return true; | |
882 #endif | |
883 return false; | |
884 } | |
885 | |
886 | |
844 bool JPEGImageDecoder::decodeToYUV() | 887 bool JPEGImageDecoder::decodeToYUV() |
845 { | 888 { |
846 if (!hasImagePlanes()) | 889 if (!hasImagePlanes()) |
847 return false; | 890 return false; |
848 PlatformInstrumentation::willDecodeImage("JPEG"); | 891 PlatformInstrumentation::willDecodeImage("JPEG"); |
849 decode(false); | 892 decode(false); |
850 PlatformInstrumentation::didDecodeImage(); | 893 PlatformInstrumentation::didDecodeImage(); |
851 return !failed(); | 894 return !failed(); |
852 } | 895 } |
853 | 896 |
854 void JPEGImageDecoder::setImagePlanes(PassOwnPtr<ImagePlanes> imagePlanes) | 897 void JPEGImageDecoder::setImagePlanes(PassOwnPtr<ImagePlanes> imagePlanes) |
855 { | 898 { |
856 m_imagePlanes = imagePlanes; | 899 m_imagePlanes = imagePlanes; |
857 } | 900 } |
858 | 901 |
859 template <J_COLOR_SPACE colorSpace> void setPixel(ImageFrame& buffer, ImageFrame ::PixelData* pixel, JSAMPARRAY samples, int column) | 902 template <J_COLOR_SPACE colorSpace, class T> void setPixel(ImageFrame& buffer, T * pixel, JSAMPARRAY samples, int column) |
860 { | 903 { |
861 ASSERT_NOT_REACHED(); | 904 ASSERT_NOT_REACHED(); |
862 } | 905 } |
863 | 906 |
864 template <> void setPixel<JCS_RGB>(ImageFrame& buffer, ImageFrame::PixelData* pi xel, JSAMPARRAY samples, int column) | 907 template <> void setPixel<JCS_RGB, ImageFrame::PixelData>(ImageFrame& buffer, Im ageFrame::PixelData* pixel, JSAMPARRAY samples, int column) |
865 { | 908 { |
866 JSAMPLE* jsample = *samples + column * 3; | 909 JSAMPLE* jsample = *samples + column * 3; |
867 buffer.setRGBARaw(pixel, jsample[0], jsample[1], jsample[2], 255); | 910 buffer.setRGBARaw(pixel, jsample[0], jsample[1], jsample[2], 255); |
868 } | 911 } |
869 | 912 |
870 template <> void setPixel<JCS_CMYK>(ImageFrame& buffer, ImageFrame::PixelData* p ixel, JSAMPARRAY samples, int column) | 913 template <> void setPixel<JCS_CMYK, ImageFrame::PixelData>(ImageFrame& buffer, I mageFrame::PixelData* pixel, JSAMPARRAY samples, int column) |
871 { | 914 { |
872 JSAMPLE* jsample = *samples + column * 4; | 915 JSAMPLE* jsample = *samples + column * 4; |
873 | 916 |
874 // Source is 'Inverted CMYK', output is RGB. | 917 // Source is 'Inverted CMYK', output is RGB. |
875 // See: http://www.easyrgb.com/math.php?MATH=M12#text12 | 918 // See: http://www.easyrgb.com/math.php?MATH=M12#text12 |
876 // Or: http://www.ilkeratalay.com/colorspacesfaq.php#rgb | 919 // Or: http://www.ilkeratalay.com/colorspacesfaq.php#rgb |
877 // From CMYK to CMY: | 920 // From CMYK to CMY: |
878 // X = X * (1 - K ) + K [for X = C, M, or Y] | 921 // X = X * (1 - K ) + K [for X = C, M, or Y] |
879 // Thus, from Inverted CMYK to CMY is: | 922 // Thus, from Inverted CMYK to CMY is: |
880 // X = (1-iX) * (1 - (1-iK)) + (1-iK) => 1 - iX*iK | 923 // X = (1-iX) * (1 - (1-iK)) + (1-iK) => 1 - iX*iK |
881 // From CMY (0..1) to RGB (0..1): | 924 // From CMY (0..1) to RGB (0..1): |
882 // R = 1 - C => 1 - (1 - iC*iK) => iC*iK [G and B similar] | 925 // R = 1 - C => 1 - (1 - iC*iK) => iC*iK [G and B similar] |
883 unsigned k = jsample[3]; | 926 unsigned k = jsample[3]; |
884 buffer.setRGBARaw(pixel, jsample[0] * k / 255, jsample[1] * k / 255, jsample [2] * k / 255, 255); | 927 buffer.setRGBARaw(pixel, jsample[0] * k / 255, jsample[1] * k / 255, jsample [2] * k / 255, 255); |
885 } | 928 } |
886 | 929 |
887 template <J_COLOR_SPACE colorSpace> bool outputRows(JPEGImageReader* reader, Ima geFrame& buffer) | 930 template <> void setPixel<JCS_RGB, ImageFrame::PixelData16>(ImageFrame& buffer, ImageFrame::PixelData16* pixel, JSAMPARRAY samples, int column) |
931 { | |
932 JSAMPLE* jsample = *samples + column * 3; | |
933 buffer.setRGB565(pixel, jsample[0], jsample[1], jsample[2]); | |
934 } | |
935 | |
936 template <> void setPixel<JCS_CMYK, ImageFrame::PixelData16>(ImageFrame& buffer, ImageFrame::PixelData16* pixel, JSAMPARRAY samples, int column) | |
937 { | |
938 JSAMPLE* jsample = *samples + column * 4; | |
939 | |
940 // Source is 'Inverted CMYK', output is RGB. | |
941 // See: http://www.easyrgb.com/math.php?MATH=M12#text12 | |
942 // Or: http://www.ilkeratalay.com/colorspacesfaq.php#rgb | |
943 // From CMYK to CMY: | |
944 // X = X * (1 - K ) + K [for X = C, M, or Y] | |
945 // Thus, from Inverted CMYK to CMY is: | |
946 // X = (1-iX) * (1 - (1-iK)) + (1-iK) => 1 - iX*iK | |
947 // From CMY (0..1) to RGB (0..1): | |
948 // R = 1 - C => 1 - (1 - iC*iK) => iC*iK [G and B similar] | |
949 unsigned k = jsample[3]; | |
950 buffer.setRGB565(pixel, jsample[0] * k / 255, jsample[1] * k / 255, jsample[ 2] * k / 255); | |
951 } | |
952 | |
953 template <J_COLOR_SPACE colorSpace, class T> bool outputRows(JPEGImageReader* re ader, ImageFrame& buffer) | |
888 { | 954 { |
889 JSAMPARRAY samples = reader->samples(); | 955 JSAMPARRAY samples = reader->samples(); |
890 jpeg_decompress_struct* info = reader->info(); | 956 jpeg_decompress_struct* info = reader->info(); |
891 int width = info->output_width; | 957 int width = info->output_width; |
892 | 958 |
893 while (info->output_scanline < info->output_height) { | 959 while (info->output_scanline < info->output_height) { |
894 // jpeg_read_scanlines will increase the scanline counter, so we | 960 // jpeg_read_scanlines will increase the scanline counter, so we |
895 // save the scanline before calling it. | 961 // save the scanline before calling it. |
896 int y = info->output_scanline; | 962 int y = info->output_scanline; |
897 // Request one scanline: returns 0 or 1 scanlines. | 963 // Request one scanline: returns 0 or 1 scanlines. |
898 if (jpeg_read_scanlines(info, samples, 1) != 1) | 964 if (jpeg_read_scanlines(info, samples, 1) != 1) |
899 return false; | 965 return false; |
900 #if USE(QCMSLIB) | 966 #if USE(QCMSLIB) |
901 if (reader->colorTransform() && colorSpace == JCS_RGB) | 967 if (reader->colorTransform() && colorSpace == JCS_RGB) |
902 qcms_transform_data(reader->colorTransform(), *samples, *samples, wi dth); | 968 qcms_transform_data(reader->colorTransform(), *samples, *samples, wi dth); |
903 #endif | 969 #endif |
904 ImageFrame::PixelData* pixel = buffer.getAddr(0, y); | 970 T* pixel = buffer.getAddrT<T>(0, y); |
905 for (int x = 0; x < width; ++pixel, ++x) | 971 for (int x = 0; x < width; ++pixel, ++x) |
906 setPixel<colorSpace>(buffer, pixel, samples, x); | 972 setPixel<colorSpace, T>(buffer, pixel, samples, x); |
907 } | 973 } |
908 | 974 |
909 buffer.setPixelsChanged(true); | 975 buffer.setPixelsChanged(true); |
910 return true; | 976 return true; |
911 } | 977 } |
912 | 978 |
913 static bool outputRawData(JPEGImageReader* reader, ImagePlanes* imagePlanes) | 979 static bool outputRawData(JPEGImageReader* reader, ImagePlanes* imagePlanes) |
914 { | 980 { |
915 JSAMPARRAY samples = reader->samples(); | 981 JSAMPARRAY samples = reader->samples(); |
916 jpeg_decompress_struct* info = reader->info(); | 982 jpeg_decompress_struct* info = reader->info(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
998 return false; | 1064 return false; |
999 | 1065 |
1000 jpeg_decompress_struct* info = m_reader->info(); | 1066 jpeg_decompress_struct* info = m_reader->info(); |
1001 | 1067 |
1002 // Initialize the framebuffer if needed. | 1068 // Initialize the framebuffer if needed. |
1003 ImageFrame& buffer = m_frameBufferCache[0]; | 1069 ImageFrame& buffer = m_frameBufferCache[0]; |
1004 if (buffer.status() == ImageFrame::FrameEmpty) { | 1070 if (buffer.status() == ImageFrame::FrameEmpty) { |
1005 ASSERT(info->output_width == static_cast<JDIMENSION>(m_decodedSize.width ())); | 1071 ASSERT(info->output_width == static_cast<JDIMENSION>(m_decodedSize.width ())); |
1006 ASSERT(info->output_height == static_cast<JDIMENSION>(m_decodedSize.heig ht())); | 1072 ASSERT(info->output_height == static_cast<JDIMENSION>(m_decodedSize.heig ht())); |
1007 | 1073 |
1008 if (!buffer.setSize(info->output_width, info->output_height)) | 1074 if (!buffer.setSize(info->output_width, info->output_height, decodeToRGB 565Enabled() |
1075 ? ImageFrame::RGB565 : ImageFrame::RGBA8888)) | |
1009 return setFailed(); | 1076 return setFailed(); |
1010 buffer.setStatus(ImageFrame::FramePartial); | 1077 buffer.setStatus(ImageFrame::FramePartial); |
1011 // The buffer is transparent outside the decoded area while the image is | 1078 // The buffer is transparent outside the decoded area while the image is |
1012 // loading. The image will be marked fully opaque in complete(). | 1079 // loading. The image will be marked fully opaque in complete(). |
1080 // for RGB565 this would just fail, having bitmap opaque during decoding | |
scroggo_chromium
2015/10/19 20:41:36
So doesn't this need to say something like if (!56
aleksandar.stojiljkovic
2015/10/20 09:51:12
Done.
| |
1013 buffer.setHasAlpha(true); | 1081 buffer.setHasAlpha(true); |
1014 | 1082 |
1015 // For JPEGs, the frame always fills the entire image. | 1083 // For JPEGs, the frame always fills the entire image. |
1016 buffer.setOriginalFrameRect(IntRect(IntPoint(), size())); | 1084 buffer.setOriginalFrameRect(IntRect(IntPoint(), size())); |
1017 } | 1085 } |
1018 | 1086 |
1019 #if defined(TURBO_JPEG_RGB_SWIZZLE) | 1087 #if defined(TURBO_JPEG_RGB_SWIZZLE) |
1020 if (turboSwizzled(info->out_color_space)) { | 1088 if (turboSwizzled(info->out_color_space)) { |
1021 while (info->output_scanline < info->output_height) { | 1089 while (info->output_scanline < info->output_height) { |
1022 unsigned char* row = reinterpret_cast_ptr<unsigned char*>(buffer.get Addr(0, info->output_scanline)); | 1090 unsigned char* row = decodeToRGB565Enabled() |
1023 if (jpeg_read_scanlines(info, &row, 1) != 1) | 1091 ? reinterpret_cast_ptr<unsigned char*>(buffer.getAddrT<ImageFram e::PixelData16>(0, info->output_scanline)) |
1092 : reinterpret_cast_ptr<unsigned char*>(buffer.getAddr(0, info->o utput_scanline)); | |
1093 if (jpeg_read_scanlines(info, &row, 1) != 1) { | |
1024 return false; | 1094 return false; |
1095 } | |
1025 #if USE(QCMSLIB) | 1096 #if USE(QCMSLIB) |
1026 if (qcms_transform* transform = m_reader->colorTransform()) | 1097 if (qcms_transform* transform = m_reader->colorTransform()) |
1027 qcms_transform_data_type(transform, row, row, info->output_width , rgbOutputColorSpace() == JCS_EXT_BGRA ? QCMS_OUTPUT_BGRX : QCMS_OUTPUT_RGBX); | 1098 qcms_transform_data_type(transform, row, row, info->output_width , rgbOutputColorSpace() == JCS_EXT_BGRA ? QCMS_OUTPUT_BGRX : QCMS_OUTPUT_RGBX); |
1028 #endif | 1099 #endif |
1029 } | 1100 } |
1030 buffer.setPixelsChanged(true); | 1101 buffer.setPixelsChanged(true); |
1031 return true; | 1102 return true; |
1032 } | 1103 } |
1033 #endif | 1104 #endif |
1034 | 1105 |
1035 switch (info->out_color_space) { | 1106 switch (info->out_color_space) { |
1036 case JCS_RGB: | 1107 case JCS_RGB: |
1037 return outputRows<JCS_RGB>(m_reader.get(), buffer); | 1108 if (decodeToRGB565Enabled()) |
1109 return outputRows<JCS_RGB, ImageFrame::PixelData16>(m_reader.get(), buffer); | |
1110 return outputRows<JCS_RGB, ImageFrame::PixelData>(m_reader.get(), buffer ); | |
1038 case JCS_CMYK: | 1111 case JCS_CMYK: |
1039 return outputRows<JCS_CMYK>(m_reader.get(), buffer); | 1112 if (decodeToRGB565Enabled()) |
1113 return outputRows<JCS_CMYK, ImageFrame::PixelData16>(m_reader.get(), buffer); | |
1114 return outputRows<JCS_CMYK, ImageFrame::PixelData>(m_reader.get(), buffe r); | |
1040 default: | 1115 default: |
1041 ASSERT_NOT_REACHED(); | 1116 ASSERT_NOT_REACHED(); |
1042 } | 1117 } |
1043 | 1118 |
1044 return setFailed(); | 1119 return setFailed(); |
1045 } | 1120 } |
1046 | 1121 |
1047 void JPEGImageDecoder::complete() | 1122 void JPEGImageDecoder::complete() |
1048 { | 1123 { |
1049 if (m_frameBufferCache.isEmpty()) | 1124 if (m_frameBufferCache.isEmpty()) |
(...skipping 26 matching lines...) Expand all Loading... | |
1076 // has failed. | 1151 // has failed. |
1077 if (!m_reader->decode(onlySize) && isAllDataReceived()) | 1152 if (!m_reader->decode(onlySize) && isAllDataReceived()) |
1078 setFailed(); | 1153 setFailed(); |
1079 | 1154 |
1080 // If decoding is done or failed, we don't need the JPEGImageReader anymore. | 1155 // If decoding is done or failed, we don't need the JPEGImageReader anymore. |
1081 if (isComplete(this, onlySize) || failed()) | 1156 if (isComplete(this, onlySize) || failed()) |
1082 m_reader.clear(); | 1157 m_reader.clear(); |
1083 } | 1158 } |
1084 | 1159 |
1085 } | 1160 } |
OLD | NEW |