| 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 20 matching lines...) Expand all Loading... |
| 31 * version of this file under the LGPL, indicate your decision by | 31 * version of this file under the LGPL, indicate your decision by |
| 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 "platform/image-decoders/jpeg/JPEGImageDecoder.h" | 38 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" |
| 39 | 39 |
| 40 #include "platform/PlatformInstrumentation.h" | 40 #include "platform/PlatformInstrumentation.h" |
| 41 #include "platform/graphics/GraphicsScreen.h" |
| 41 | 42 |
| 42 extern "C" { | 43 extern "C" { |
| 43 #include <stdio.h> // jpeglib.h needs stdio FILE. | 44 #include <stdio.h> // jpeglib.h needs stdio FILE. |
| 44 #include "jpeglib.h" | 45 #include "jpeglib.h" |
| 45 #if USE(ICCJPEG) | 46 #if USE(ICCJPEG) |
| 46 #include "iccjpeg.h" | 47 #include "iccjpeg.h" |
| 47 #endif | 48 #endif |
| 48 #if USE(QCMSLIB) | 49 #if USE(QCMSLIB) |
| 49 #include "qcms.h" | 50 #include "qcms.h" |
| 50 #endif | 51 #endif |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 jpeg_calc_output_dimensions(&m_info); | 473 jpeg_calc_output_dimensions(&m_info); |
| 473 m_decoder->setDecodedSize(m_info.output_width, m_info.output_height)
; | 474 m_decoder->setDecodedSize(m_info.output_width, m_info.output_height)
; |
| 474 | 475 |
| 475 m_decoder->setOrientation(readImageOrientation(info())); | 476 m_decoder->setOrientation(readImageOrientation(info())); |
| 476 | 477 |
| 477 #if USE(QCMSLIB) | 478 #if USE(QCMSLIB) |
| 478 // Allow color management of the decoded RGBA pixels if possible. | 479 // Allow color management of the decoded RGBA pixels if possible. |
| 479 if (!m_decoder->ignoresGammaAndColorProfile()) { | 480 if (!m_decoder->ignoresGammaAndColorProfile()) { |
| 480 ColorProfile colorProfile; | 481 ColorProfile colorProfile; |
| 481 readColorProfile(info(), colorProfile); | 482 readColorProfile(info(), colorProfile); |
| 482 createColorTransform(colorProfile, colorSpaceHasAlpha(m_info.out
_color_space)); | 483 bool imageHasAlpha = colorSpaceHasAlpha(m_info.out_color_space); |
| 483 if (m_transform) { | 484 RefPtr<ColorSpaceProfile> imageColorProfile = createColorTransfo
rm(colorProfile, imageHasAlpha); |
| 485 m_decoder->setHasColorProfile(!!imageColorProfile.get()); |
| 486 |
| 487 if (m_decoder->hasColorProfile() && imageColorProfilesEnabled())
{ |
| 488 // FIXME: allow YUV decoding of color profiled images. |
| 489 overrideColorSpace = JCS_UNKNOWN; |
| 490 RELEASE_ASSERT(imageColorProfile->profile()); |
| 491 m_decoder->setColorProfile(imageColorProfile); |
| 492 // Do not color correct decoded frames during decoding. |
| 493 clearColorTransform(); |
| 494 RELEASE_ASSERT(!m_transform); |
| 495 } |
| 496 |
| 497 if (m_decoder->hasColorProfile() && !imageColorProfilesEnabled()
) { |
| 498 // FIXME: allow YUV decoding of color profiled images. |
| 484 overrideColorSpace = JCS_UNKNOWN; | 499 overrideColorSpace = JCS_UNKNOWN; |
| 485 #if defined(TURBO_JPEG_RGB_SWIZZLE) | 500 #if defined(TURBO_JPEG_RGB_SWIZZLE) |
| 486 // Input RGBA data to qcms. Note: restored to BGRA on output
. | 501 // Input RGBA data to qcms. Note: restored to BGRA on output
. |
| 487 if (m_info.out_color_space == JCS_EXT_BGRA) | 502 if (m_info.out_color_space == JCS_EXT_BGRA) |
| 488 m_info.out_color_space = JCS_EXT_RGBA; | 503 m_info.out_color_space = JCS_EXT_RGBA; |
| 489 #endif | 504 #endif |
| 490 } | 505 } |
| 491 m_decoder->setHasColorProfile(!!m_transform); | |
| 492 } | 506 } |
| 493 #endif | 507 #endif |
| 494 if (overrideColorSpace == JCS_YCbCr) { | 508 if (overrideColorSpace == JCS_YCbCr) { |
| 495 m_info.out_color_space = JCS_YCbCr; | 509 m_info.out_color_space = JCS_YCbCr; |
| 496 m_info.raw_data_out = TRUE; | 510 m_info.raw_data_out = TRUE; |
| 497 m_uvSize = computeYUVSize(&m_info, 1, ImageDecoder::SizeForMemor
yAllocation); // U size and V size have to be the same if we got here | 511 m_uvSize = computeYUVSize(&m_info, 1, ImageDecoder::SizeForMemor
yAllocation); // U size and V size have to be the same if we got here |
| 498 } | 512 } |
| 499 | 513 |
| 500 // Don't allocate a giant and superfluous memory buffer when the | 514 // Don't allocate a giant and superfluous memory buffer when the |
| 501 // image is a sequential JPEG. | 515 // image is a sequential JPEG. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 #if USE(QCMSLIB) | 644 #if USE(QCMSLIB) |
| 631 qcms_transform* colorTransform() const { return m_transform; } | 645 qcms_transform* colorTransform() const { return m_transform; } |
| 632 | 646 |
| 633 void clearColorTransform() | 647 void clearColorTransform() |
| 634 { | 648 { |
| 635 if (m_transform) | 649 if (m_transform) |
| 636 qcms_transform_release(m_transform); | 650 qcms_transform_release(m_transform); |
| 637 m_transform = 0; | 651 m_transform = 0; |
| 638 } | 652 } |
| 639 | 653 |
| 640 void createColorTransform(const ColorProfile& colorProfile, bool hasAlpha) | 654 PassRefPtr<ColorSpaceProfile> createColorTransform(const ColorProfile& color
Profile, bool hasAlpha) |
| 641 { | 655 { |
| 642 clearColorTransform(); | 656 clearColorTransform(); |
| 643 | 657 |
| 644 if (colorProfile.isEmpty()) | 658 if (colorProfile.isEmpty()) |
| 645 return; | 659 return nullptr; |
| 660 |
| 646 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); | 661 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); |
| 647 if (!deviceProfile) | 662 if (!deviceProfile) |
| 648 return; | 663 return nullptr; |
| 664 |
| 649 qcms_profile* inputProfile = qcms_profile_from_memory(colorProfile.data(
), colorProfile.size()); | 665 qcms_profile* inputProfile = qcms_profile_from_memory(colorProfile.data(
), colorProfile.size()); |
| 650 if (!inputProfile) | 666 if (!inputProfile) |
| 651 return; | 667 return nullptr; |
| 668 |
| 669 if (imageColorProfilesEnabled()) |
| 670 return ColorSpaceProfile::create(inputProfile); |
| 652 | 671 |
| 653 // We currently only support color profiles for RGB profiled images. | 672 // We currently only support color profiles for RGB profiled images. |
| 654 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); | 673 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); |
| 655 | 674 |
| 656 if (qcms_profile_match(inputProfile, deviceProfile)) { | 675 if (qcms_profile_match(inputProfile, deviceProfile)) { |
| 657 qcms_profile_release(inputProfile); | 676 qcms_profile_release(inputProfile); |
| 658 return; | 677 return nullptr; |
| 659 } | 678 } |
| 660 | 679 |
| 661 // FIXME: Don't force perceptual intent if the image profile contains an
intent. | 680 // FIXME: Don't force perceptual intent if the image profile contains an
intent. |
| 662 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_
8; | 681 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_
8; |
| 663 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); | 682 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); |
| 664 | 683 |
| 684 if (m_transform) |
| 685 return ColorSpaceProfile::create(inputProfile); |
| 686 |
| 665 qcms_profile_release(inputProfile); | 687 qcms_profile_release(inputProfile); |
| 688 return nullptr; |
| 666 } | 689 } |
| 667 #endif | 690 #endif |
| 668 | 691 |
| 669 private: | 692 private: |
| 670 JSAMPARRAY allocateSampleArray() | 693 JSAMPARRAY allocateSampleArray() |
| 671 { | 694 { |
| 672 // Some output color spaces don't need the sample array: don't allocate
in that case. | 695 // Some output color spaces don't need the sample array: don't allocate
in that case. |
| 673 #if defined(TURBO_JPEG_RGB_SWIZZLE) | 696 #if defined(TURBO_JPEG_RGB_SWIZZLE) |
| 674 if (turboSwizzled(m_info.out_color_space)) | 697 if (turboSwizzled(m_info.out_color_space)) |
| 675 return nullptr; | 698 return nullptr; |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 // has failed. | 1093 // has failed. |
| 1071 if (!m_reader->decode(onlySize) && isAllDataReceived()) | 1094 if (!m_reader->decode(onlySize) && isAllDataReceived()) |
| 1072 setFailed(); | 1095 setFailed(); |
| 1073 | 1096 |
| 1074 // If decoding is done or failed, we don't need the JPEGImageReader anymore. | 1097 // If decoding is done or failed, we don't need the JPEGImageReader anymore. |
| 1075 if (isComplete(this, onlySize) || failed()) | 1098 if (isComplete(this, onlySize) || failed()) |
| 1076 m_reader.clear(); | 1099 m_reader.clear(); |
| 1077 } | 1100 } |
| 1078 | 1101 |
| 1079 } | 1102 } |
| OLD | NEW |