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

Unified Diff: src/images/SkImageDecoder_libpng.cpp

Issue 26572006: Revert "Revert "change SkColorTable to be immutable"" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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
« no previous file with comments | « src/images/SkImageDecoder_libgif.cpp ('k') | src/opts/SkBitmapProcState_opts_arm.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkImageDecoder_libpng.cpp
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index 4e4106aede85f8266c3b9ffd234e025f9f6a0e02..951083b0f467d4ad9e31889447f05009f6090916 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -648,8 +648,6 @@ bool SkPNGImageDecoder::decodePalette(png_structp png_ptr, png_infop info_ptr,
png_colorp palette;
png_bytep trans;
int numTrans;
- bool reallyHasAlpha = false;
- SkColorTable* colorTable = NULL;
png_get_PLTE(png_ptr, info_ptr, &palette, &numPalette);
@@ -660,17 +658,16 @@ bool SkPNGImageDecoder::decodePalette(png_structp png_ptr, png_infop info_ptr,
the colortable by 1 (if its < 256) and duplicate the last color into that slot.
*/
int colorCount = numPalette + (numPalette < 256);
+ SkPMColor colorStorage[256]; // worst-case storage
+ SkPMColor* colorPtr = colorStorage;
- colorTable = SkNEW_ARGS(SkColorTable, (colorCount));
-
- SkPMColor* colorPtr = colorTable->lockColors();
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_get_tRNS(png_ptr, info_ptr, &trans, &numTrans, NULL);
*hasAlphap = (numTrans > 0);
} else {
numTrans = 0;
- colorTable->setFlags(colorTable->getFlags() | SkColorTable::kColorsAreOpaque_Flag);
}
+
// check for bad images that might make us crash
if (numTrans > numPalette) {
numTrans = numPalette;
@@ -692,7 +689,7 @@ bool SkPNGImageDecoder::decodePalette(png_structp png_ptr, png_infop info_ptr,
*colorPtr++ = proc(*trans++, palette->red, palette->green, palette->blue);
palette++;
}
- reallyHasAlpha |= (transLessThanFF < 0);
+ bool reallyHasAlpha = (transLessThanFF < 0);
for (; index < numPalette; index++) {
*colorPtr++ = SkPackARGB32(0xFF, palette->red, palette->green, palette->blue);
@@ -703,8 +700,18 @@ bool SkPNGImageDecoder::decodePalette(png_structp png_ptr, png_infop info_ptr,
if (numPalette < 256) {
*colorPtr = colorPtr[-1];
}
- colorTable->unlockColors(true);
- *colorTablep = colorTable;
+
+ SkAlphaType alphaType = kOpaque_SkAlphaType;
+ if (reallyHasAlpha) {
+ if (this->getRequireUnpremultipliedColors()) {
+ alphaType = kUnpremul_SkAlphaType;
+ } else {
+ alphaType = kPremul_SkAlphaType;
+ }
+ }
+
+ *colorTablep = SkNEW_ARGS(SkColorTable,
+ (colorStorage, colorCount, alphaType));
*reallyHasAlphap = reallyHasAlpha;
return true;
}
« no previous file with comments | « src/images/SkImageDecoder_libgif.cpp ('k') | src/opts/SkBitmapProcState_opts_arm.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698