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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 png_get_tRNS(png, info, &trns, &trnsCount, 0); | 209 png_get_tRNS(png, info, &trns, &trnsCount, 0); |
210 png_set_expand(png); | 210 png_set_expand(png); |
211 } | 211 } |
212 | 212 |
213 if (bitDepth == 16) | 213 if (bitDepth == 16) |
214 png_set_strip_16(png); | 214 png_set_strip_16(png); |
215 | 215 |
216 if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALP
HA) | 216 if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALP
HA) |
217 png_set_gray_to_rgb(png); | 217 png_set_gray_to_rgb(png); |
218 | 218 |
219 #if USE(QCMSLIB) | |
220 if ((colorType & PNG_COLOR_MASK_COLOR) && !m_ignoreGammaAndColorProfile) { | 219 if ((colorType & PNG_COLOR_MASK_COLOR) && !m_ignoreGammaAndColorProfile) { |
221 // We only support color profiles for color PALETTE and RGB[A] PNG. Supp
orting | 220 // We only support color profiles for color PALETTE and RGB[A] PNG. Supp
orting |
222 // color profiles for gray-scale images is slightly tricky, at least usi
ng the | 221 // color profiles for gray-scale images is slightly tricky, at least usi
ng the |
223 // CoreGraphics ICC library, because we expand gray-scale images to RGB
but we | 222 // CoreGraphics ICC library, because we expand gray-scale images to RGB
but we |
224 // do not similarly transform the color profile. We'd either need to tra
nsform | 223 // do not similarly transform the color profile. We'd either need to tra
nsform |
225 // the color profile or we'd need to decode into a gray-scale image buff
er and | 224 // the color profile or we'd need to decode into a gray-scale image buff
er and |
226 // hand that to CoreGraphics. | 225 // hand that to CoreGraphics. |
227 bool imageHasAlpha = (colorType & PNG_COLOR_MASK_ALPHA) || trnsCount; | 226 bool imageHasAlpha = (colorType & PNG_COLOR_MASK_ALPHA) || trnsCount; |
228 #ifdef PNG_iCCP_SUPPORTED | 227 #ifdef PNG_iCCP_SUPPORTED |
229 if (png_get_valid(png, info, PNG_INFO_sRGB)) { | 228 if (png_get_valid(png, info, PNG_INFO_sRGB)) { |
230 setColorProfileAndTransform(nullptr, 0, imageHasAlpha, true /* useSR
GB */); | 229 setColorProfileAndComputeTransform(nullptr, 0, imageHasAlpha, true /
* useSRGB */); |
231 } else { | 230 } else { |
232 char* profileName = nullptr; | 231 char* profileName = nullptr; |
233 int compressionType = 0; | 232 int compressionType = 0; |
234 #if (PNG_LIBPNG_VER < 10500) | 233 #if (PNG_LIBPNG_VER < 10500) |
235 png_charp profile = nullptr; | 234 png_charp profile = nullptr; |
236 #else | 235 #else |
237 png_bytep profile = nullptr; | 236 png_bytep profile = nullptr; |
238 #endif | 237 #endif |
239 png_uint_32 profileLength = 0; | 238 png_uint_32 profileLength = 0; |
240 if (png_get_iCCP(png, info, &profileName, &compressionType, &profile
, &profileLength)) { | 239 if (png_get_iCCP(png, info, &profileName, &compressionType, &profile
, &profileLength)) { |
241 setColorProfileAndTransform(reinterpret_cast<char*>(profile), pr
ofileLength, imageHasAlpha, false /* useSRGB */); | 240 setColorProfileAndComputeTransform(reinterpret_cast<char*>(profi
le), profileLength, imageHasAlpha, false /* useSRGB */); |
242 } | 241 } |
243 } | 242 } |
244 #endif // PNG_iCCP_SUPPORTED | 243 #endif // PNG_iCCP_SUPPORTED |
245 } | 244 } |
246 #endif // USE(QCMSLIB) | |
247 | 245 |
248 if (!hasColorProfile()) { | 246 if (!hasColorProfile()) { |
249 // Deal with gamma and keep it under our control. | 247 // Deal with gamma and keep it under our control. |
250 const double inverseGamma = 0.45455; | 248 const double inverseGamma = 0.45455; |
251 const double defaultGamma = 2.2; | 249 const double defaultGamma = 2.2; |
252 double gamma; | 250 double gamma; |
253 if (!m_ignoreGammaAndColorProfile && png_get_gAMA(png, info, &gamma)) { | 251 if (!m_ignoreGammaAndColorProfile && png_get_gAMA(png, info, &gamma)) { |
254 const double maxGamma = 21474.83; | 252 const double maxGamma = 21474.83; |
255 if ((gamma <= 0.0) || (gamma > maxGamma)) { | 253 if ((gamma <= 0.0) || (gamma > maxGamma)) { |
256 gamma = inverseGamma; | 254 gamma = inverseGamma; |
(...skipping 30 matching lines...) Expand all Loading... |
287 | 285 |
288 void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
int) | 286 void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
int) |
289 { | 287 { |
290 if (m_frameBufferCache.isEmpty()) | 288 if (m_frameBufferCache.isEmpty()) |
291 return; | 289 return; |
292 | 290 |
293 // Initialize the framebuffer if needed. | 291 // Initialize the framebuffer if needed. |
294 ImageFrame& buffer = m_frameBufferCache[0]; | 292 ImageFrame& buffer = m_frameBufferCache[0]; |
295 if (buffer.getStatus() == ImageFrame::FrameEmpty) { | 293 if (buffer.getStatus() == ImageFrame::FrameEmpty) { |
296 png_structp png = m_reader->pngPtr(); | 294 png_structp png = m_reader->pngPtr(); |
297 if (!buffer.setSize(size().width(), size().height())) { | 295 if (!buffer.setSizeAndColorProfile(size().width(), size().height(), colo
rProfile())) { |
298 longjmp(JMPBUF(png), 1); | 296 longjmp(JMPBUF(png), 1); |
299 return; | 297 return; |
300 } | 298 } |
301 | 299 |
302 unsigned colorChannels = m_reader->hasAlpha() ? 4 : 3; | 300 unsigned colorChannels = m_reader->hasAlpha() ? 4 : 3; |
303 if (PNG_INTERLACE_ADAM7 == png_get_interlace_type(png, m_reader->infoPtr
())) { | 301 if (PNG_INTERLACE_ADAM7 == png_get_interlace_type(png, m_reader->infoPtr
())) { |
304 m_reader->createInterlaceBuffer(colorChannels * size().width() * siz
e().height()); | 302 m_reader->createInterlaceBuffer(colorChannels * size().width() * siz
e().height()); |
305 if (!m_reader->interlaceBuffer()) { | 303 if (!m_reader->interlaceBuffer()) { |
306 longjmp(JMPBUF(png), 1); | 304 longjmp(JMPBUF(png), 1); |
307 return; | 305 return; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 // has failed. | 434 // has failed. |
437 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 435 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
438 setFailed(); | 436 setFailed(); |
439 | 437 |
440 // If decoding is done or failed, we don't need the PNGImageReader anymore. | 438 // If decoding is done or failed, we don't need the PNGImageReader anymore. |
441 if (isComplete(this) || failed()) | 439 if (isComplete(this) || failed()) |
442 m_reader.reset(); | 440 m_reader.reset(); |
443 } | 441 } |
444 | 442 |
445 } // namespace blink | 443 } // namespace blink |
OLD | NEW |