| 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 21 matching lines...) Expand all Loading... |
| 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 "config.h" | 39 #include "config.h" |
| 40 #include "platform/image-decoders/png/PNGImageDecoder.h" | 40 #include "platform/image-decoders/png/PNGImageDecoder.h" |
| 41 | 41 |
| 42 #include "platform/graphics/GraphicsScreen.h" |
| 43 |
| 42 #include "png.h" | 44 #include "png.h" |
| 43 #if !defined(PNG_LIBPNG_VER_MAJOR) || !defined(PNG_LIBPNG_VER_MINOR) | 45 #if !defined(PNG_LIBPNG_VER_MAJOR) || !defined(PNG_LIBPNG_VER_MINOR) |
| 44 #error version error: compile against a versioned libpng. | 46 #error version error: compile against a versioned libpng. |
| 45 #endif | 47 #endif |
| 46 #if USE(QCMSLIB) | 48 #if USE(QCMSLIB) |
| 47 #include "qcms.h" | 49 #include "qcms.h" |
| 48 #endif | 50 #endif |
| 49 | 51 |
| 50 #if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MIN
OR >= 4) | 52 #if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MIN
OR >= 4) |
| 51 #define JMPBUF(png_ptr) png_jmpbuf(png_ptr) | 53 #define JMPBUF(png_ptr) png_jmpbuf(png_ptr) |
| (...skipping 98 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 |
| 176 // We currently only support color profiles for RGB and RGBA images. | 181 // We currently only support color profiles for RGB and RGBA images. |
| 177 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); | 182 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); |
| 178 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_
8; | 183 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_
8; |
| 179 // FIXME: Don't force perceptual intent if the image profile contains an
intent. | 184 // FIXME: Don't force perceptual intent if the image profile contains an
intent. |
| 180 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); | 185 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); |
| 186 if (m_transform) |
| 187 return ColorSpaceProfile::create(inputProfile); |
| 188 |
| 181 qcms_profile_release(inputProfile); | 189 qcms_profile_release(inputProfile); |
| 190 return nullptr; |
| 182 } | 191 } |
| 183 #endif | 192 #endif |
| 184 | 193 |
| 185 private: | 194 private: |
| 186 png_structp m_png; | 195 png_structp m_png; |
| 187 png_infop m_info; | 196 png_infop m_info; |
| 188 PNGImageDecoder* m_decoder; | 197 PNGImageDecoder* m_decoder; |
| 189 unsigned m_readOffset; | 198 unsigned m_readOffset; |
| 190 unsigned m_currentBufferSize; | 199 unsigned m_currentBufferSize; |
| 191 bool m_decodingSizeOnly; | 200 bool m_decodingSizeOnly; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // We only support color profiles for color PALETTE and RGB[A] PNG. Supp
orting | 301 // We only support color profiles for color PALETTE and RGB[A] PNG. Supp
orting |
| 293 // color profiles for gray-scale images is slightly tricky, at least usi
ng the | 302 // color profiles for gray-scale images is slightly tricky, at least usi
ng the |
| 294 // CoreGraphics ICC library, because we expand gray-scale images to RGB
but we | 303 // CoreGraphics ICC library, because we expand gray-scale images to RGB
but we |
| 295 // do not similarly transform the color profile. We'd either need to tra
nsform | 304 // do not similarly transform the color profile. We'd either need to tra
nsform |
| 296 // the color profile or we'd need to decode into a gray-scale image buff
er and | 305 // the color profile or we'd need to decode into a gray-scale image buff
er and |
| 297 // hand that to CoreGraphics. | 306 // hand that to CoreGraphics. |
| 298 bool sRGB = false; | 307 bool sRGB = false; |
| 299 ColorProfile colorProfile; | 308 ColorProfile colorProfile; |
| 300 getColorProfile(png, info, colorProfile, sRGB); | 309 getColorProfile(png, info, colorProfile, sRGB); |
| 301 bool imageHasAlpha = (colorType & PNG_COLOR_MASK_ALPHA) || trnsCount; | 310 bool imageHasAlpha = (colorType & PNG_COLOR_MASK_ALPHA) || trnsCount; |
| 302 m_reader->createColorTransform(colorProfile, imageHasAlpha, sRGB); | 311 RefPtr<ColorSpaceProfile> imageColorProfile = m_reader->createColorTrans
form(colorProfile, imageHasAlpha, sRGB); |
| 303 m_hasColorProfile = !!m_reader->colorTransform(); | 312 m_hasColorProfile = !!imageColorProfile.get(); |
| 313 |
| 314 if (m_hasColorProfile && imageColorProfilesEnabled()) { |
| 315 RELEASE_ASSERT(imageColorProfile->profile()); |
| 316 m_colorProfile = imageColorProfile; |
| 317 // Do not color correct decoded frames during decoding. |
| 318 m_reader->clearColorTransform(); |
| 319 RELEASE_ASSERT(!m_reader->colorTransform()); |
| 320 } |
| 304 } | 321 } |
| 305 #endif | 322 #endif |
| 306 | 323 |
| 307 if (!m_hasColorProfile) { | 324 if (!m_hasColorProfile) { |
| 308 // Deal with gamma and keep it under our control. | 325 // Deal with gamma and keep it under our control. |
| 309 const double inverseGamma = 0.45455; | 326 const double inverseGamma = 0.45455; |
| 310 const double defaultGamma = 2.2; | 327 const double defaultGamma = 2.2; |
| 311 double gamma; | 328 double gamma; |
| 312 if (!m_ignoreGammaAndColorProfile && png_get_gAMA(png, info, &gamma)) { | 329 if (!m_ignoreGammaAndColorProfile && png_get_gAMA(png, info, &gamma)) { |
| 313 const double maxGamma = 21474.83; | 330 const double maxGamma = 21474.83; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 // has failed. | 512 // has failed. |
| 496 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 513 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
| 497 setFailed(); | 514 setFailed(); |
| 498 | 515 |
| 499 // If decoding is done or failed, we don't need the PNGImageReader anymore. | 516 // If decoding is done or failed, we don't need the PNGImageReader anymore. |
| 500 if (isComplete(this) || failed()) | 517 if (isComplete(this) || failed()) |
| 501 m_reader.clear(); | 518 m_reader.clear(); |
| 502 } | 519 } |
| 503 | 520 |
| 504 } // namespace blink | 521 } // namespace blink |
| OLD | NEW |