Chromium Code Reviews| Index: third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.cpp |
| diff --git a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.cpp b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.cpp |
| index 9364c72a79906194d9df742db7e093d71589afd8..6223b0b34071322341e61fbef72aff99ce18430c 100644 |
| --- a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.cpp |
| +++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.cpp |
| @@ -194,7 +194,33 @@ inline sk_sp<SkColorSpace> readColorSpace(png_structp png, png_infop info) { |
| return SkColorSpace::MakeRGB(fn, toXYZD50); |
| } |
| +void PNGImageDecoder::setColorSpace() { |
| + if (ignoresColorSpace()) |
| + return; |
| + png_structp png = m_reader->pngPtr(); |
| + png_infop info = m_reader->infoPtr(); |
| + const int colorType = png_get_color_type(png, info); |
| + if (!(colorType & PNG_COLOR_MASK_COLOR)) |
| + return; |
| + // We only support color profiles for color PALETTE and RGB[A] PNG. |
| + // TODO(msarret): Add GRAY profile support, block CYMK? |
|
msarett1
2017/03/22 19:28:06
nit: I realize that you're just moving this code,
scroggo_chromium
2017/03/22 19:37:17
Haha done! Sorry for overlooking.
|
| + sk_sp<SkColorSpace> colorSpace = readColorSpace(png, info); |
| + if (colorSpace) |
| + setEmbeddedColorSpace(colorSpace); |
| +} |
| + |
| +bool PNGImageDecoder::setSize(unsigned width, unsigned height) { |
| + DCHECK(!isDecodedSizeAvailable()); |
| + // Protect against large PNGs. See http://bugzil.la/251381 for more details. |
| + const unsigned long maxPNGSize = 1000000UL; |
| + if (width > maxPNGSize || height > maxPNGSize) |
| + return false; |
| + return ImageDecoder::setSize(width, height); |
| +} |
| + |
| void PNGImageDecoder::headerAvailable() { |
| + DCHECK(isDecodedSizeAvailable()); |
| + |
| png_structp png = m_reader->pngPtr(); |
| png_infop info = m_reader->infoPtr(); |
| @@ -220,31 +246,6 @@ void PNGImageDecoder::headerAvailable() { |
| colorType == PNG_COLOR_TYPE_GRAY_ALPHA) |
| png_set_gray_to_rgb(png); |
| - // Only set the size and the color space of the image once since non-first |
| - // frames also use this method: there is no per-frame color space, and the |
| - // image size is determined from the header width and height. |
| - if (!isDecodedSizeAvailable()) { |
| - // Protect against large PNGs. See http://bugzil.la/251381 for more details. |
| - const unsigned long maxPNGSize = 1000000UL; |
| - if (width > maxPNGSize || height > maxPNGSize) { |
| - longjmp(JMPBUF(png), 1); |
| - return; |
| - } |
| - |
| - // Set the image size now that the image header is available. |
| - if (!setSize(width, height)) { |
| - longjmp(JMPBUF(png), 1); |
| - return; |
| - } |
| - |
| - if ((colorType & PNG_COLOR_MASK_COLOR) && !ignoresColorSpace()) { |
| - // We only support color profiles for color PALETTE and RGB[A] PNG. |
| - // TODO(msarret): Add GRAY profile support, block CYMK? |
| - if (sk_sp<SkColorSpace> colorSpace = readColorSpace(png, info)) |
| - setEmbeddedColorSpace(colorSpace); |
| - } |
| - } |
| - |
| if (!hasEmbeddedColorSpace()) { |
| const double inverseGamma = 0.45455; |
| const double defaultGamma = 2.2; |
| @@ -261,8 +262,6 @@ void PNGImageDecoder::headerAvailable() { |
| } |
| } |
| - DCHECK(isDecodedSizeAvailable()); |
| - |
| // Tell libpng to send us rows for interlaced pngs. |
| if (interlaceType == PNG_INTERLACE_ADAM7) |
| png_set_interlace_handling(png); |