| 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 21 matching lines...) Expand all Loading... |
| 32 * deletingthe provisions above and replace them with the notice and | 32 * deletingthe provisions above and replace them with the notice and |
| 33 * other provisions required by the MPL or the GPL, as the case may be. | 33 * other provisions required by the MPL or the GPL, as the case may be. |
| 34 * If you do not delete the provisions above, a recipient may use your | 34 * If you do not delete the provisions above, a recipient may use your |
| 35 * version of this file under any of the LGPL, the MPL or the GPL. | 35 * version of this file under any of the LGPL, the MPL or the GPL. |
| 36 */ | 36 */ |
| 37 | 37 |
| 38 #include "config.h" | 38 #include "config.h" |
| 39 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" | 39 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" |
| 40 | 40 |
| 41 #include "platform/PlatformInstrumentation.h" | 41 #include "platform/PlatformInstrumentation.h" |
| 42 #include "platform/graphics/GraphicsScreen.h" |
| 42 | 43 |
| 43 extern "C" { | 44 extern "C" { |
| 44 #include <stdio.h> // jpeglib.h needs stdio FILE. | 45 #include <stdio.h> // jpeglib.h needs stdio FILE. |
| 45 #include "jpeglib.h" | 46 #include "jpeglib.h" |
| 46 #if USE(ICCJPEG) | 47 #if USE(ICCJPEG) |
| 47 #include "iccjpeg.h" | 48 #include "iccjpeg.h" |
| 48 #endif | 49 #endif |
| 49 #if USE(QCMSLIB) | 50 #if USE(QCMSLIB) |
| 50 #include "qcms.h" | 51 #include "qcms.h" |
| 51 #endif | 52 #endif |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 jpeg_calc_output_dimensions(&m_info); | 471 jpeg_calc_output_dimensions(&m_info); |
| 471 m_decoder->setDecodedSize(m_info.output_width, m_info.output_height)
; | 472 m_decoder->setDecodedSize(m_info.output_width, m_info.output_height)
; |
| 472 | 473 |
| 473 m_decoder->setOrientation(readImageOrientation(info())); | 474 m_decoder->setOrientation(readImageOrientation(info())); |
| 474 | 475 |
| 475 #if USE(QCMSLIB) | 476 #if USE(QCMSLIB) |
| 476 // Allow color management of the decoded RGBA pixels if possible. | 477 // Allow color management of the decoded RGBA pixels if possible. |
| 477 if (!m_decoder->ignoresGammaAndColorProfile()) { | 478 if (!m_decoder->ignoresGammaAndColorProfile()) { |
| 478 ColorProfile colorProfile; | 479 ColorProfile colorProfile; |
| 479 readColorProfile(info(), colorProfile); | 480 readColorProfile(info(), colorProfile); |
| 480 createColorTransform(colorProfile, colorSpaceHasAlpha(m_info.out
_color_space)); | 481 bool imageHasAlpha = colorSpaceHasAlpha(m_info.out_color_space); |
| 481 if (m_transform) { | 482 RefPtr<ColorSpaceProfile> imageColorProfile = createColorTransfo
rm(colorProfile, imageHasAlpha); |
| 483 m_decoder->setHasColorProfile(!!imageColorProfile.get()); |
| 484 |
| 485 if (m_decoder->hasColorProfile() && imageColorProfilesEnabled())
{ |
| 486 // FIXME: allow YUV decoding of color profiled images. |
| 487 overrideColorSpace = JCS_UNKNOWN; |
| 488 RELEASE_ASSERT(imageColorProfile->profile()); |
| 489 m_decoder->setColorProfile(imageColorProfile); |
| 490 // Do not color correct decoded frames during decoding. |
| 491 clearColorTransform(); |
| 492 RELEASE_ASSERT(!m_transform); |
| 493 } |
| 494 |
| 495 if (m_decoder->hasColorProfile() && !imageColorProfilesEnabled()
) { |
| 496 // FIXME: allow YUV decoding of color profiled images. |
| 482 overrideColorSpace = JCS_UNKNOWN; | 497 overrideColorSpace = JCS_UNKNOWN; |
| 483 #if defined(TURBO_JPEG_RGB_SWIZZLE) | 498 #if defined(TURBO_JPEG_RGB_SWIZZLE) |
| 484 // Input RGBA data to qcms. Note: restored to BGRA on output
. | 499 // Input RGBA data to qcms. Note: restored to BGRA on output
. |
| 485 if (m_info.out_color_space == JCS_EXT_BGRA) | 500 if (m_info.out_color_space == JCS_EXT_BGRA) |
| 486 m_info.out_color_space = JCS_EXT_RGBA; | 501 m_info.out_color_space = JCS_EXT_RGBA; |
| 487 #endif | 502 #endif |
| 488 } | 503 } |
| 489 m_decoder->setHasColorProfile(!!m_transform); | |
| 490 } | 504 } |
| 491 #endif | 505 #endif |
| 492 if (overrideColorSpace == JCS_YCbCr) { | 506 if (overrideColorSpace == JCS_YCbCr) { |
| 493 m_info.out_color_space = JCS_YCbCr; | 507 m_info.out_color_space = JCS_YCbCr; |
| 494 m_info.raw_data_out = TRUE; | 508 m_info.raw_data_out = TRUE; |
| 495 m_uvSize = computeYUVSize(&m_info, 1, ImageDecoder::SizeForMemor
yAllocation); // U size and V size have to be the same if we got here | 509 m_uvSize = computeYUVSize(&m_info, 1, ImageDecoder::SizeForMemor
yAllocation); // U size and V size have to be the same if we got here |
| 496 } | 510 } |
| 497 | 511 |
| 498 // Don't allocate a giant and superfluous memory buffer when the | 512 // Don't allocate a giant and superfluous memory buffer when the |
| 499 // image is a sequential JPEG. | 513 // image is a sequential JPEG. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 #if USE(QCMSLIB) | 642 #if USE(QCMSLIB) |
| 629 qcms_transform* colorTransform() const { return m_transform; } | 643 qcms_transform* colorTransform() const { return m_transform; } |
| 630 | 644 |
| 631 void clearColorTransform() | 645 void clearColorTransform() |
| 632 { | 646 { |
| 633 if (m_transform) | 647 if (m_transform) |
| 634 qcms_transform_release(m_transform); | 648 qcms_transform_release(m_transform); |
| 635 m_transform = 0; | 649 m_transform = 0; |
| 636 } | 650 } |
| 637 | 651 |
| 638 void createColorTransform(const ColorProfile& colorProfile, bool hasAlpha) | 652 PassRefPtr<ColorSpaceProfile> createColorTransform(const ColorProfile& color
Profile, bool hasAlpha) |
| 639 { | 653 { |
| 640 clearColorTransform(); | 654 clearColorTransform(); |
| 641 | 655 |
| 642 if (colorProfile.isEmpty()) | 656 if (colorProfile.isEmpty()) |
| 643 return; | 657 return nullptr; |
| 658 |
| 644 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); | 659 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); |
| 645 if (!deviceProfile) | 660 if (!deviceProfile) |
| 646 return; | 661 return nullptr; |
| 662 |
| 647 qcms_profile* inputProfile = qcms_profile_from_memory(colorProfile.data(
), colorProfile.size()); | 663 qcms_profile* inputProfile = qcms_profile_from_memory(colorProfile.data(
), colorProfile.size()); |
| 648 if (!inputProfile) | 664 if (!inputProfile) |
| 649 return; | 665 return nullptr; |
| 666 |
| 650 // We currently only support color profiles for RGB profiled images. | 667 // We currently only support color profiles for RGB profiled images. |
| 651 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); | 668 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); |
| 652 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_
8; | 669 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_
8; |
| 653 // FIXME: Don't force perceptual intent if the image profile contains an
intent. | 670 // FIXME: Don't force perceptual intent if the image profile contains an
intent. |
| 654 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); | 671 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); |
| 672 if (m_transform) |
| 673 return ColorSpaceProfile::create(inputProfile); |
| 674 |
| 655 qcms_profile_release(inputProfile); | 675 qcms_profile_release(inputProfile); |
| 676 return nullptr; |
| 656 } | 677 } |
| 657 #endif | 678 #endif |
| 658 | 679 |
| 659 private: | 680 private: |
| 660 JSAMPARRAY allocateSampleArray() | 681 JSAMPARRAY allocateSampleArray() |
| 661 { | 682 { |
| 662 // Some output color spaces don't need the sample array: don't allocate
in that case. | 683 // Some output color spaces don't need the sample array: don't allocate
in that case. |
| 663 #if defined(TURBO_JPEG_RGB_SWIZZLE) | 684 #if defined(TURBO_JPEG_RGB_SWIZZLE) |
| 664 if (turboSwizzled(m_info.out_color_space)) | 685 if (turboSwizzled(m_info.out_color_space)) |
| 665 return nullptr; | 686 return nullptr; |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 // has failed. | 1081 // has failed. |
| 1061 if (!m_reader->decode(onlySize) && isAllDataReceived()) | 1082 if (!m_reader->decode(onlySize) && isAllDataReceived()) |
| 1062 setFailed(); | 1083 setFailed(); |
| 1063 | 1084 |
| 1064 // If decoding is done or failed, we don't need the JPEGImageReader anymore. | 1085 // If decoding is done or failed, we don't need the JPEGImageReader anymore. |
| 1065 if (isComplete(this, onlySize) || failed()) | 1086 if (isComplete(this, onlySize) || failed()) |
| 1066 m_reader.clear(); | 1087 m_reader.clear(); |
| 1067 } | 1088 } |
| 1068 | 1089 |
| 1069 } | 1090 } |
| OLD | NEW |