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

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

Issue 1055743003: Swizzler changes Index8 and 565 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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
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 "SkCodec_libpng.h" 8 #include "SkCodec_libpng.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // the case here. 121 // the case here.
122 bool SkPngCodec::decodePalette(bool premultiply) { 122 bool SkPngCodec::decodePalette(bool premultiply) {
123 int numPalette; 123 int numPalette;
124 png_colorp palette; 124 png_colorp palette;
125 png_bytep trans; 125 png_bytep trans;
126 126
127 if (!png_get_PLTE(fPng_ptr, fInfo_ptr, &palette, &numPalette)) { 127 if (!png_get_PLTE(fPng_ptr, fInfo_ptr, &palette, &numPalette)) {
128 return false; 128 return false;
129 } 129 }
130 130
131 /* BUGGY IMAGE WORKAROUND
132
133 We hit some images (e.g. fruit_.png) who contain bytes that are == color table_count
134 which is a problem since we use the byte as an index. To work around thi s we grow
135 the colortable by 1 (if its < 256) and duplicate the last color into tha t slot.
136 */
137 const int colorCount = numPalette + (numPalette < 256);
scroggo 2015/04/02 19:20:31 Part of the contract of onGetPixels is that we wil
msarett 2015/04/03 18:01:32 Didn't know this. I think I now handle this prope
138 // Note: These are not necessarily SkPMColors. 131 // Note: These are not necessarily SkPMColors.
139 SkPMColor colorStorage[256]; // worst-case storage 132 SkPMColor* colorPtr = fColorTable;
140 SkPMColor* colorPtr = colorStorage;
141 133
142 int numTrans; 134 int numTrans;
143 if (png_get_valid(fPng_ptr, fInfo_ptr, PNG_INFO_tRNS)) { 135 if (png_get_valid(fPng_ptr, fInfo_ptr, PNG_INFO_tRNS)) {
144 png_get_tRNS(fPng_ptr, fInfo_ptr, &trans, &numTrans, NULL); 136 png_get_tRNS(fPng_ptr, fInfo_ptr, &trans, &numTrans, NULL);
145 } else { 137 } else {
146 numTrans = 0; 138 numTrans = 0;
147 } 139 }
148 140
149 // check for bad images that might make us crash 141 // check for bad images that might make us crash
150 if (numTrans > numPalette) { 142 if (numTrans > numPalette) {
(...skipping 17 matching lines...) Expand all
168 palette++; 160 palette++;
169 } 161 }
170 162
171 fReallyHasAlpha = transLessThanFF < 0; 163 fReallyHasAlpha = transLessThanFF < 0;
172 164
173 for (; index < numPalette; index++) { 165 for (; index < numPalette; index++) {
174 *colorPtr++ = SkPackARGB32(0xFF, palette->red, palette->green, palette-> blue); 166 *colorPtr++ = SkPackARGB32(0xFF, palette->red, palette->green, palette-> blue);
175 palette++; 167 palette++;
176 } 168 }
177 169
178 // see BUGGY IMAGE WORKAROUND comment above 170 /* BUGGY IMAGE WORKAROUND
scroggo 2015/04/02 19:20:31 As long as you're touching this code, you might as
msarett 2015/04/03 18:01:32 Done.
171
172 We hit some images (e.g. fruit_.png) who contain bytes that are == color table_count
173 which is a problem since we use the byte as an index. To work around thi s we grow
174 the colortable by 1 (if its < 256) and duplicate the last color into tha t slot.
175 */
179 if (numPalette < 256) { 176 if (numPalette < 256) {
180 *colorPtr = colorPtr[-1]; 177 *colorPtr = colorPtr[-1];
181 } 178 }
182 179
183 fColorTable.reset(SkNEW_ARGS(SkColorTable, (colorStorage, colorCount)));
184 return true; 180 return true;
185 } 181 }
186 182
187 /////////////////////////////////////////////////////////////////////////////// 183 ///////////////////////////////////////////////////////////////////////////////
188 // Creation 184 // Creation
189 /////////////////////////////////////////////////////////////////////////////// 185 ///////////////////////////////////////////////////////////////////////////////
190 186
191 #define PNG_BYTES_TO_CHECK 4 187 #define PNG_BYTES_TO_CHECK 4
192 188
193 bool SkPngCodec::IsPng(SkStream* stream) { 189 bool SkPngCodec::IsPng(SkStream* stream) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) { 265 if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) {
270 png_set_expand_gray_1_2_4_to_8(png_ptr); 266 png_set_expand_gray_1_2_4_to_8(png_ptr);
271 } 267 }
272 268
273 269
274 // Now determine the default SkColorType and SkAlphaType. 270 // Now determine the default SkColorType and SkAlphaType.
275 SkColorType skColorType; 271 SkColorType skColorType;
276 SkAlphaType skAlphaType; 272 SkAlphaType skAlphaType;
277 switch (colorType) { 273 switch (colorType) {
278 case PNG_COLOR_TYPE_PALETTE: 274 case PNG_COLOR_TYPE_PALETTE:
279 // Technically, this is true of the data, but I don't think we want 275 skColorType = kIndex_8_SkColorType;
280 // to support it.
281 // skColorType = kIndex8_SkColorType;
282 skColorType = kN32_SkColorType;
283 skAlphaType = has_transparency_in_palette(png_ptr, info_ptr) ? 276 skAlphaType = has_transparency_in_palette(png_ptr, info_ptr) ?
284 kUnpremul_SkAlphaType : kOpaque_SkAlphaType; 277 kUnpremul_SkAlphaType : kOpaque_SkAlphaType;
285 break; 278 break;
286 case PNG_COLOR_TYPE_GRAY: 279 case PNG_COLOR_TYPE_GRAY:
287 if (false) { 280 if (false) {
288 // FIXME: Is this the wrong default behavior? This means if the 281 // FIXME: Is this the wrong default behavior? This means if the
289 // caller supplies the info we gave them, they'll get Alpha 8. 282 // caller supplies the info we gave them, they'll get Alpha 8.
290 skColorType = kAlpha_8_SkColorType; 283 skColorType = kAlpha_8_SkColorType;
291 // FIXME: Strangely, the canonical type for Alpha 8 is Premul. 284 // FIXME: Strangely, the canonical type for Alpha 8 is Premul.
292 skAlphaType = kPremul_SkAlphaType; 285 skAlphaType = kPremul_SkAlphaType;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } else if (kAlpha_8_SkColorType == requestedInfo.colorType()) { 421 } else if (kAlpha_8_SkColorType == requestedInfo.colorType()) {
429 // Note: we check the destination, since otherwise we would have 422 // Note: we check the destination, since otherwise we would have
430 // told png to upscale. 423 // told png to upscale.
431 SkASSERT(PNG_COLOR_TYPE_GRAY == pngColorType); 424 SkASSERT(PNG_COLOR_TYPE_GRAY == pngColorType);
432 fSrcConfig = SkSwizzler::kGray; 425 fSrcConfig = SkSwizzler::kGray;
433 } else if (this->getInfo().alphaType() == kOpaque_SkAlphaType) { 426 } else if (this->getInfo().alphaType() == kOpaque_SkAlphaType) {
434 fSrcConfig = SkSwizzler::kRGBX; 427 fSrcConfig = SkSwizzler::kRGBX;
435 } else { 428 } else {
436 fSrcConfig = SkSwizzler::kRGBA; 429 fSrcConfig = SkSwizzler::kRGBA;
437 } 430 }
438 const SkPMColor* colors = fColorTable ? fColorTable->readColors() : NULL; 431 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, fColorTable, requeste dInfo,
439 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo ,
440 dst, rowBytes, options.fZeroInitialized)); 432 dst, rowBytes, options.fZeroInitialized));
441 if (!fSwizzler) { 433 if (!fSwizzler) {
442 // FIXME: CreateSwizzler could fail for another reason. 434 // FIXME: CreateSwizzler could fail for another reason.
443 return kUnimplemented; 435 return kUnimplemented;
444 } 436 }
445 437
446 // FIXME: Here is where we should likely insert some of the modifications 438 // FIXME: Here is where we should likely insert some of the modifications
447 // made in the factory. 439 // made in the factory.
448 png_read_update_info(fPng_ptr, fInfo_ptr); 440 png_read_update_info(fPng_ptr, fInfo_ptr);
449 441
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 if (!this->handleRewind()) { 476 if (!this->handleRewind()) {
485 return kCouldNotRewind; 477 return kCouldNotRewind;
486 } 478 }
487 if (requestedInfo.dimensions() != this->getInfo().dimensions()) { 479 if (requestedInfo.dimensions() != this->getInfo().dimensions()) {
488 return kInvalidScale; 480 return kInvalidScale;
489 } 481 }
490 if (!conversion_possible(requestedInfo, this->getInfo())) { 482 if (!conversion_possible(requestedInfo, this->getInfo())) {
491 return kInvalidConversion; 483 return kInvalidConversion;
492 } 484 }
493 485
486 // Get a valid color table pointer
487 SkPMColor ctableAlternate[256];
488 fColorTable = get_color_table_ptr(requestedInfo.colorType(), ctable, ctableC ount,
scroggo 2015/04/02 19:20:31 Once again, we're potentially setting the member p
msarett 2015/04/03 18:01:32 This has been fixed.
489 ctableAlternate);
490
494 const Result result = this->initializeSwizzler(requestedInfo, dst, rowBytes, 491 const Result result = this->initializeSwizzler(requestedInfo, dst, rowBytes,
495 options); 492 options);
496 if (result != kSuccess) { 493 if (result != kSuccess) {
497 return result; 494 return result;
498 } 495 }
499 496
500 // FIXME: Could we use the return value of setjmp to specify the type of 497 // FIXME: Could we use the return value of setjmp to specify the type of
501 // error? 498 // error?
502 if (setjmp(png_jmpbuf(fPng_ptr))) { 499 if (setjmp(png_jmpbuf(fPng_ptr))) {
503 SkCodecPrintf("setjmp long jump!\n"); 500 SkCodecPrintf("setjmp long jump!\n");
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 634
638 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); 635 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES);
639 if (fNumberPasses > 1) { 636 if (fNumberPasses > 1) {
640 // We cannot efficiently do scanline decoding. 637 // We cannot efficiently do scanline decoding.
641 return NULL; 638 return NULL;
642 } 639 }
643 640
644 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this)); 641 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this));
645 } 642 }
646 643
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698