| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
| 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 4 * | 4 * |
| 5 * Portions are Copyright (C) 2001 mozilla.org | 5 * Portions are Copyright (C) 2001 mozilla.org |
| 6 * | 6 * |
| 7 * Other contributors: | 7 * Other contributors: |
| 8 * Stuart Parmenter <stuart@mozilla.com> | 8 * Stuart Parmenter <stuart@mozilla.com> |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 * licenses (the MPL or the GPL) and not to allow others to use your | 31 * licenses (the MPL or the GPL) and not to allow others to use your |
| 32 * version of this file under the LGPL, indicate your decision by | 32 * version of this file under the LGPL, indicate your decision by |
| 33 * deletingthe provisions above and replace them with the notice and | 33 * deletingthe provisions above and replace them with the notice and |
| 34 * other provisions required by the MPL or the GPL, as the case may be. | 34 * other provisions required by the MPL or the GPL, as the case may be. |
| 35 * If you do not delete the provisions above, a recipient may use your | 35 * If you do not delete the provisions above, a recipient may use your |
| 36 * version of this file under any of the LGPL, the MPL or the GPL. | 36 * version of this file under any of the LGPL, the MPL or the GPL. |
| 37 */ | 37 */ |
| 38 | 38 |
| 39 #include "platform/image-decoders/png/PNGImageDecoder.h" | 39 #include "platform/image-decoders/png/PNGImageDecoder.h" |
| 40 | 40 |
| 41 #include "platform/graphics/GraphicsScreen.h" |
| 42 |
| 41 #include "png.h" | 43 #include "png.h" |
| 42 #if !defined(PNG_LIBPNG_VER_MAJOR) || !defined(PNG_LIBPNG_VER_MINOR) | 44 #if !defined(PNG_LIBPNG_VER_MAJOR) || !defined(PNG_LIBPNG_VER_MINOR) |
| 43 #error version error: compile against a versioned libpng. | 45 #error version error: compile against a versioned libpng. |
| 44 #endif | 46 #endif |
| 45 #if USE(QCMSLIB) | 47 #if USE(QCMSLIB) |
| 46 #include "qcms.h" | 48 #include "qcms.h" |
| 47 #endif | 49 #endif |
| 48 | 50 |
| 49 #if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MIN
OR >= 4) | 51 #if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MIN
OR >= 4) |
| 50 #define JMPBUF(png_ptr) png_jmpbuf(png_ptr) | 52 #define JMPBUF(png_ptr) png_jmpbuf(png_ptr) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void createRowBuffer(int size) { m_rowBuffer = adoptArrayPtr(new png_byte[si
ze]); } | 152 void createRowBuffer(int size) { m_rowBuffer = adoptArrayPtr(new png_byte[si
ze]); } |
| 151 qcms_transform* colorTransform() const { return m_transform; } | 153 qcms_transform* colorTransform() const { return m_transform; } |
| 152 | 154 |
| 153 void clearColorTransform() | 155 void clearColorTransform() |
| 154 { | 156 { |
| 155 if (m_transform) | 157 if (m_transform) |
| 156 qcms_transform_release(m_transform); | 158 qcms_transform_release(m_transform); |
| 157 m_transform = 0; | 159 m_transform = 0; |
| 158 } | 160 } |
| 159 | 161 |
| 160 void createColorTransform(const ColorProfile& colorProfile, bool hasAlpha, b
ool sRGB) | 162 PassRefPtr<ColorSpaceProfile> createColorTransform(const ColorProfile& color
Profile, bool hasAlpha, bool sRGB) |
| 161 { | 163 { |
| 162 clearColorTransform(); | 164 clearColorTransform(); |
| 163 | 165 |
| 164 if (colorProfile.isEmpty() && !sRGB) | 166 if (colorProfile.isEmpty() && !sRGB) |
| 165 return; | 167 return nullptr; |
| 168 |
| 166 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); | 169 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); |
| 167 if (!deviceProfile) | 170 if (!deviceProfile) |
| 168 return; | 171 return nullptr; |
| 172 |
| 169 qcms_profile* inputProfile = 0; | 173 qcms_profile* inputProfile = 0; |
| 170 if (!colorProfile.isEmpty()) | 174 if (!colorProfile.isEmpty()) |
| 171 inputProfile = qcms_profile_from_memory(colorProfile.data(), colorPr
ofile.size()); | 175 inputProfile = qcms_profile_from_memory(colorProfile.data(), colorPr
ofile.size()); |
| 172 else | 176 else |
| 173 inputProfile = qcms_profile_sRGB(); | 177 inputProfile = qcms_profile_sRGB(); |
| 174 if (!inputProfile) | 178 if (!inputProfile) |
| 175 return; | 179 return nullptr; |
| 180 |
| 181 if (imageColorProfilesEnabled()) |
| 182 return ColorSpaceProfile::create(inputProfile); |
| 176 | 183 |
| 177 // We currently only support color profiles for RGB and RGBA images. | 184 // We currently only support color profiles for RGB and RGBA images. |
| 178 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); | 185 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); |
| 179 | 186 |
| 180 if (qcms_profile_match(inputProfile, deviceProfile)) { | 187 if (qcms_profile_match(inputProfile, deviceProfile)) { |
| 181 qcms_profile_release(inputProfile); | 188 qcms_profile_release(inputProfile); |
| 182 return; | 189 return nullptr; |
| 183 } | 190 } |
| 184 | 191 |
| 185 // FIXME: Don't force perceptual intent if the image profile contains an
intent. | 192 // FIXME: Don't force perceptual intent if the image profile contains an
intent. |
| 186 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_
8; | 193 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_
8; |
| 187 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); | 194 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); |
| 188 | 195 |
| 196 if (m_transform) |
| 197 return ColorSpaceProfile::create(inputProfile); |
| 198 |
| 189 qcms_profile_release(inputProfile); | 199 qcms_profile_release(inputProfile); |
| 200 return nullptr; |
| 190 } | 201 } |
| 191 #endif | 202 #endif |
| 192 | 203 |
| 193 private: | 204 private: |
| 194 png_structp m_png; | 205 png_structp m_png; |
| 195 png_infop m_info; | 206 png_infop m_info; |
| 196 PNGImageDecoder* m_decoder; | 207 PNGImageDecoder* m_decoder; |
| 197 size_t m_readOffset; | 208 size_t m_readOffset; |
| 198 size_t m_currentBufferSize; | 209 size_t m_currentBufferSize; |
| 199 bool m_decodingSizeOnly; | 210 bool m_decodingSizeOnly; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // We only support color profiles for color PALETTE and RGB[A] PNG. Supp
orting | 311 // We only support color profiles for color PALETTE and RGB[A] PNG. Supp
orting |
| 301 // color profiles for gray-scale images is slightly tricky, at least usi
ng the | 312 // color profiles for gray-scale images is slightly tricky, at least usi
ng the |
| 302 // CoreGraphics ICC library, because we expand gray-scale images to RGB
but we | 313 // CoreGraphics ICC library, because we expand gray-scale images to RGB
but we |
| 303 // do not similarly transform the color profile. We'd either need to tra
nsform | 314 // do not similarly transform the color profile. We'd either need to tra
nsform |
| 304 // the color profile or we'd need to decode into a gray-scale image buff
er and | 315 // the color profile or we'd need to decode into a gray-scale image buff
er and |
| 305 // hand that to CoreGraphics. | 316 // hand that to CoreGraphics. |
| 306 bool sRGB = false; | 317 bool sRGB = false; |
| 307 ColorProfile colorProfile; | 318 ColorProfile colorProfile; |
| 308 getColorProfile(png, info, colorProfile, sRGB); | 319 getColorProfile(png, info, colorProfile, sRGB); |
| 309 bool imageHasAlpha = (colorType & PNG_COLOR_MASK_ALPHA) || trnsCount; | 320 bool imageHasAlpha = (colorType & PNG_COLOR_MASK_ALPHA) || trnsCount; |
| 310 m_reader->createColorTransform(colorProfile, imageHasAlpha, sRGB); | 321 RefPtr<ColorSpaceProfile> imageColorProfile = m_reader->createColorTrans
form(colorProfile, imageHasAlpha, sRGB); |
| 311 m_hasColorProfile = !!m_reader->colorTransform(); | 322 m_hasColorProfile = !!imageColorProfile.get(); |
| 323 |
| 324 if (m_hasColorProfile && imageColorProfilesEnabled()) { |
| 325 RELEASE_ASSERT(imageColorProfile->profile()); |
| 326 m_colorProfile = imageColorProfile; |
| 327 // Do not color correct decoded frames during decoding. |
| 328 m_reader->clearColorTransform(); |
| 329 RELEASE_ASSERT(!m_reader->colorTransform()); |
| 330 } |
| 312 } | 331 } |
| 313 #endif | 332 #endif |
| 314 | 333 |
| 315 if (!m_hasColorProfile) { | 334 if (!m_hasColorProfile) { |
| 316 // Deal with gamma and keep it under our control. | 335 // Deal with gamma and keep it under our control. |
| 317 const double inverseGamma = 0.45455; | 336 const double inverseGamma = 0.45455; |
| 318 const double defaultGamma = 2.2; | 337 const double defaultGamma = 2.2; |
| 319 double gamma; | 338 double gamma; |
| 320 if (!m_ignoreGammaAndColorProfile && png_get_gAMA(png, info, &gamma)) { | 339 if (!m_ignoreGammaAndColorProfile && png_get_gAMA(png, info, &gamma)) { |
| 321 const double maxGamma = 21474.83; | 340 const double maxGamma = 21474.83; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // has failed. | 522 // has failed. |
| 504 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 523 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
| 505 setFailed(); | 524 setFailed(); |
| 506 | 525 |
| 507 // If decoding is done or failed, we don't need the PNGImageReader anymore. | 526 // If decoding is done or failed, we don't need the PNGImageReader anymore. |
| 508 if (isComplete(this) || failed()) | 527 if (isComplete(this) || failed()) |
| 509 m_reader.clear(); | 528 m_reader.clear(); |
| 510 } | 529 } |
| 511 | 530 |
| 512 } // namespace blink | 531 } // namespace blink |
| OLD | NEW |