| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 | 8 |
| 9 #include "SkColor.h" | 9 #include "SkColor.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 return error_return(gif, *bm, "TopLeft"); | 241 return error_return(gif, *bm, "TopLeft"); |
| 242 } | 242 } |
| 243 | 243 |
| 244 // now we decode the colortable | 244 // now we decode the colortable |
| 245 int colorCount = 0; | 245 int colorCount = 0; |
| 246 { | 246 { |
| 247 const ColorMapObject* cmap = find_colormap(gif); | 247 const ColorMapObject* cmap = find_colormap(gif); |
| 248 if (NULL == cmap) { | 248 if (NULL == cmap) { |
| 249 return error_return(gif, *bm, "null cmap"); | 249 return error_return(gif, *bm, "null cmap"); |
| 250 } | 250 } |
| 251 |
| 251 colorCount = cmap->ColorCount; | 252 colorCount = cmap->ColorCount; |
| 252 if (colorCount > 256) { | 253 SkAutoTMalloc<SkPMColor> colorStorage(colorCount); |
| 253 colorCount = 256; // our kIndex8 can't support more | 254 SkPMColor* colorPtr = colorStorage.get(); |
| 254 } | |
| 255 | |
| 256 SkPMColor colorPtr[256]; // storage for worst-case | |
| 257 SkAlphaType alphaType = kOpaque_SkAlphaType; | |
| 258 for (int index = 0; index < colorCount; index++) { | 255 for (int index = 0; index < colorCount; index++) { |
| 259 colorPtr[index] = SkPackARGB32(0xFF, | 256 colorPtr[index] = SkPackARGB32(0xFF, |
| 260 cmap->Colors[index].Red, | 257 cmap->Colors[index].Red, |
| 261 cmap->Colors[index].Green, | 258 cmap->Colors[index].Green, |
| 262 cmap->Colors[index].Blue); | 259 cmap->Colors[index].Blue); |
| 263 } | 260 } |
| 264 | 261 |
| 265 transpIndex = find_transpIndex(temp_save, colorCount); | 262 transpIndex = find_transpIndex(temp_save, colorCount); |
| 266 bool reallyHasAlpha = transpIndex >= 0; | 263 bool reallyHasAlpha = transpIndex >= 0; |
| 267 if (reallyHasAlpha) { | 264 if (reallyHasAlpha) { |
| 268 colorPtr[transpIndex] = SK_ColorTRANSPARENT; // ram in a tra
nsparent SkPMColor | 265 colorPtr[transpIndex] = SK_ColorTRANSPARENT; // ram in a tra
nsparent SkPMColor |
| 269 alphaType = kPremul_SkAlphaType; | |
| 270 } | 266 } |
| 271 | 267 |
| 272 SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable, | 268 SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable, (colo
rPtr, colorCount))); |
| 273 (colorPtr, colorCount, | 269 ctable->setIsOpaque(!reallyHasAlpha); |
| 274 alphaType))); | |
| 275 if (!this->allocPixelRef(bm, ctable)) { | 270 if (!this->allocPixelRef(bm, ctable)) { |
| 276 return error_return(gif, *bm, "allocPixelRef"); | 271 return error_return(gif, *bm, "allocPixelRef"); |
| 277 } | 272 } |
| 278 } | 273 } |
| 279 | 274 |
| 280 const int innerWidth = desc.Width; | 275 const int innerWidth = desc.Width; |
| 281 const int innerHeight = desc.Height; | 276 const int innerHeight = desc.Height; |
| 282 | 277 |
| 283 // abort if either inner dimension is <= 0 | 278 // abort if either inner dimension is <= 0 |
| 284 if (innerWidth <= 0 || innerHeight <= 0) { | 279 if (innerWidth <= 0 || innerHeight <= 0) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 static SkImageDecoder_DecodeReg gReg(sk_libgif_dfactory); | 435 static SkImageDecoder_DecodeReg gReg(sk_libgif_dfactory); |
| 441 | 436 |
| 442 static SkImageDecoder::Format get_format_gif(SkStreamRewindable* stream) { | 437 static SkImageDecoder::Format get_format_gif(SkStreamRewindable* stream) { |
| 443 if (is_gif(stream)) { | 438 if (is_gif(stream)) { |
| 444 return SkImageDecoder::kGIF_Format; | 439 return SkImageDecoder::kGIF_Format; |
| 445 } | 440 } |
| 446 return SkImageDecoder::kUnknown_Format; | 441 return SkImageDecoder::kUnknown_Format; |
| 447 } | 442 } |
| 448 | 443 |
| 449 static SkImageDecoder_FormatReg gFormatReg(get_format_gif); | 444 static SkImageDecoder_FormatReg gFormatReg(get_format_gif); |
| OLD | NEW |