aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-09 16:34:47 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-09 16:34:47 +0000
commit9864c24e40448ef64b1fe367eee1d63a872e51b8 (patch)
treee2f4f0f77d9e8176ab572a061e2594dbd8c9e01e /src/images
parentb6aec0558810f5d3531ff7d530be0a3d148c5639 (diff)
change SkColorTable to be immutable
BUG= R=scroggo@google.com Review URL: https://codereview.chromium.org/25353002 git-svn-id: http://skia.googlecode.com/svn/trunk@11676 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images')
-rw-r--r--src/images/SkImageDecoder_libgif.cpp15
-rw-r--r--src/images/SkImageDecoder_libpng.cpp25
2 files changed, 26 insertions, 14 deletions
diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp
index 08f37efced..ab0fbdaf3f 100644
--- a/src/images/SkImageDecoder_libgif.cpp
+++ b/src/images/SkImageDecoder_libgif.cpp
@@ -248,10 +248,13 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) {
if (NULL == cmap) {
return error_return(gif, *bm, "null cmap");
}
-
colorCount = cmap->ColorCount;
- SkAutoTMalloc<SkPMColor> colorStorage(colorCount);
- SkPMColor* colorPtr = colorStorage.get();
+ if (colorCount > 256) {
+ colorCount = 256; // our kIndex8 can't support more
+ }
+
+ SkPMColor colorPtr[256]; // storage for worst-case
+ SkAlphaType alphaType = kOpaque_SkAlphaType;
for (int index = 0; index < colorCount; index++) {
colorPtr[index] = SkPackARGB32(0xFF,
cmap->Colors[index].Red,
@@ -263,10 +266,12 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) {
bool reallyHasAlpha = transpIndex >= 0;
if (reallyHasAlpha) {
colorPtr[transpIndex] = SK_ColorTRANSPARENT; // ram in a transparent SkPMColor
+ alphaType = kPremul_SkAlphaType;
}
- SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable, (colorPtr, colorCount)));
- ctable->setIsOpaque(!reallyHasAlpha);
+ SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable,
+ (colorPtr, colorCount,
+ alphaType)));
if (!this->allocPixelRef(bm, ctable)) {
return error_return(gif, *bm, "allocPixelRef");
}
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index 4e4106aede..951083b0f4 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;
}