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

Side by Side Diff: src/codec/SkPngCodec.cpp

Issue 1767723003: Check libpng version before reading color space (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Future proof for version 2 Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkColorTable.h" 10 #include "SkColorTable.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // do the conversion ourselves rather than convert 171 // do the conversion ourselves rather than convert
172 // fixed point -> double -> float. 172 // fixed point -> double -> float.
173 return ((float) x) * 0.00001f; 173 return ((float) x) * 0.00001f;
174 } 174 }
175 175
176 // Returns a colorSpace object that represents any color space information in 176 // Returns a colorSpace object that represents any color space information in
177 // the encoded data. If the encoded data contains no color space, this will 177 // the encoded data. If the encoded data contains no color space, this will
178 // return NULL. 178 // return NULL.
179 SkColorSpace* read_color_space(png_structp png_ptr, png_infop info_ptr) { 179 SkColorSpace* read_color_space(png_structp png_ptr, png_infop info_ptr) {
180 180
181 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M INOR >= 6)
182
181 // First check for an ICC profile 183 // First check for an ICC profile
182 png_bytep profile; 184 png_bytep profile;
183 png_uint_32 length; 185 png_uint_32 length;
184 // The below variables are unused, however, we need to pass them in anyway o r 186 // The below variables are unused, however, we need to pass them in anyway o r
185 // png_get_iCCP() will return nothing. 187 // png_get_iCCP() will return nothing.
186 // Could knowing the |name| of the profile ever be interesting? Maybe for d ebugging? 188 // Could knowing the |name| of the profile ever be interesting? Maybe for d ebugging?
187 png_charp name; 189 png_charp name;
188 // The |compression| is uninteresting since: 190 // The |compression| is uninteresting since:
189 // (1) libpng has already decompressed the profile for us. 191 // (1) libpng has already decompressed the profile for us.
190 // (2) "deflate" is the only mode of decompression that libpng supports. 192 // (2) "deflate" is the only mode of decompression that libpng supports.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // FIXME (msarett): Should SkFloat3x3 have a method to set the identity matrix? 244 // FIXME (msarett): Should SkFloat3x3 have a method to set the identity matrix?
243 memset(toXYZD50.fMat, 0, 9 * sizeof(float)); 245 memset(toXYZD50.fMat, 0, 9 * sizeof(float));
244 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f; 246 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f;
245 247
246 // Set the gammas. 248 // Set the gammas.
247 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = png_fixed_point_to_fl oat(gamma); 249 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = png_fixed_point_to_fl oat(gamma);
248 250
249 return SkColorSpace::NewRGB(toXYZD50, gammas); 251 return SkColorSpace::NewRGB(toXYZD50, gammas);
250 } 252 }
251 253
254 #endif // LIBPNG >= 1.6
255
252 // Finally, what should we do if there is no color space information in the PNG? 256 // Finally, what should we do if there is no color space information in the PNG?
253 // The specification says that this indicates "gamma is unknown" and that th e 257 // The specification says that this indicates "gamma is unknown" and that th e
254 // "color is device dependent". I'm assuming we can represent this with NUL L. 258 // "color is device dependent". I'm assuming we can represent this with NUL L.
255 // But should we guess sRGB? Most images are sRGB, even if they don't speci fy. 259 // But should we guess sRGB? Most images are sRGB, even if they don't speci fy.
256 return nullptr; 260 return nullptr;
257 } 261 }
258 262
259 // Reads the header and initializes the output fields, if not NULL. 263 // Reads the header and initializes the output fields, if not NULL.
260 // 264 //
261 // @param stream Input data. Will be read to get enough information to properly 265 // @param stream Input data. Will be read to get enough information to properly
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 841
838 if (1 == numberPasses) { 842 if (1 == numberPasses) {
839 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader, 843 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader,
840 png_ptr, info_ptr, bitDepth, colorSpace) ; 844 png_ptr, info_ptr, bitDepth, colorSpace) ;
841 } 845 }
842 846
843 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader, 847 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader,
844 png_ptr, info_ptr, bitDepth, numbe rPasses, 848 png_ptr, info_ptr, bitDepth, numbe rPasses,
845 colorSpace); 849 colorSpace);
846 } 850 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698