Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.cpp

Issue 2766263002: Refactor PNGImageDecoder's call to setSize (Closed)
Patch Set: Single return statement Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b362e12c554392cca4b65a9199192bf3c053f0b5 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,32 @@ 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(msarett): Add GRAY profile support, block CYMK?
+ 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;
+ return (width <= maxPNGSize) && (height <= maxPNGSize) &&
+ ImageDecoder::setSize(width, height);
+}
+
void PNGImageDecoder::headerAvailable() {
+ DCHECK(isDecodedSizeAvailable());
+
png_structp png = m_reader->pngPtr();
png_infop info = m_reader->infoPtr();
@@ -220,31 +245,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 +261,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);

Powered by Google App Engine
This is Rietveld 408576698