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

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

Issue 1665583002: Handle gray alpha conversions in SkSwizzler (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Compile in Debug mode :) Created 4 years, 10 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 | src/codec/SkSwizzler.h » ('j') | 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 colorType = kN32_SkColorType; 290 colorType = kN32_SkColorType;
291 break; 291 break;
292 case PNG_COLOR_TYPE_GRAY: 292 case PNG_COLOR_TYPE_GRAY:
293 // Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/p ixel. 293 // Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/p ixel.
294 if (bitDepth < 8) { 294 if (bitDepth < 8) {
295 // TODO: Should we use SkSwizzler here? 295 // TODO: Should we use SkSwizzler here?
296 png_set_expand_gray_1_2_4_to_8(png_ptr); 296 png_set_expand_gray_1_2_4_to_8(png_ptr);
297 } 297 }
298 298
299 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { 299 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
300 // Convert to RGBA if there is a transparency chunk.
301 png_set_tRNS_to_alpha(png_ptr); 300 png_set_tRNS_to_alpha(png_ptr);
302 png_set_gray_to_rgb(png_ptr); 301
302 // We will recommend kN32 here since we do not support kGray
303 // with alpha.
303 colorType = kN32_SkColorType; 304 colorType = kN32_SkColorType;
304 alphaType = kUnpremul_SkAlphaType; 305 alphaType = kUnpremul_SkAlphaType;
305 } else { 306 } else {
306 colorType = kGray_8_SkColorType; 307 colorType = kGray_8_SkColorType;
307 alphaType = kOpaque_SkAlphaType; 308 alphaType = kOpaque_SkAlphaType;
308 } 309 }
309 break; 310 break;
310 case PNG_COLOR_TYPE_GRAY_ALPHA: 311 case PNG_COLOR_TYPE_GRAY_ALPHA:
311 // Convert to RGBA if the image has alpha. 312 // We will recommend kN32 here since we do not support anything
312 png_set_gray_to_rgb(png_ptr); 313 // similar to GRAY_ALPHA.
313 colorType = kN32_SkColorType; 314 colorType = kN32_SkColorType;
314 alphaType = kUnpremul_SkAlphaType; 315 alphaType = kUnpremul_SkAlphaType;
315 break; 316 break;
316 case PNG_COLOR_TYPE_RGBA: 317 case PNG_COLOR_TYPE_RGBA:
317 colorType = kN32_SkColorType; 318 colorType = kN32_SkColorType;
318 alphaType = kUnpremul_SkAlphaType; 319 alphaType = kUnpremul_SkAlphaType;
319 break; 320 break;
320 default: 321 default:
321 // All the color types have been covered above. 322 // All the color types have been covered above.
322 SkASSERT(false); 323 SkASSERT(false);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 SkPMColor ctable[], 378 SkPMColor ctable[],
378 int* ctableCount) { 379 int* ctableCount) {
379 // FIXME: Could we use the return value of setjmp to specify the type of 380 // FIXME: Could we use the return value of setjmp to specify the type of
380 // error? 381 // error?
381 if (setjmp(png_jmpbuf(fPng_ptr))) { 382 if (setjmp(png_jmpbuf(fPng_ptr))) {
382 SkCodecPrintf("setjmp long jump!\n"); 383 SkCodecPrintf("setjmp long jump!\n");
383 return kInvalidInput; 384 return kInvalidInput;
384 } 385 }
385 png_read_update_info(fPng_ptr, fInfo_ptr); 386 png_read_update_info(fPng_ptr, fInfo_ptr);
386 387
387 // srcColorType was determined in read_header() which determined png color t ype 388 // suggestedColorType was determined in read_header() based on the encodedCo lorType
388 const SkColorType srcColorType = this->getInfo().colorType(); 389 const SkColorType suggestedColorType = this->getInfo().colorType();
389 390
390 switch (srcColorType) { 391 switch (suggestedColorType) {
391 case kIndex_8_SkColorType: 392 case kIndex_8_SkColorType:
392 //decode palette to Skia format 393 //decode palette to Skia format
393 fSrcConfig = SkSwizzler::kIndex; 394 fSrcConfig = SkSwizzler::kIndex;
394 if (!this->decodePalette(kPremul_SkAlphaType == requestedInfo.alphaT ype(), 395 if (!this->decodePalette(kPremul_SkAlphaType == requestedInfo.alphaT ype(),
395 ctableCount)) { 396 ctableCount)) {
396 return kInvalidInput; 397 return kInvalidInput;
397 } 398 }
398 break; 399 break;
399 case kGray_8_SkColorType: 400 case kGray_8_SkColorType:
400 fSrcConfig = SkSwizzler::kGray; 401 fSrcConfig = SkSwizzler::kGray;
401 break; 402 break;
402 case kN32_SkColorType: 403 case kN32_SkColorType: {
403 if (this->getInfo().alphaType() == kOpaque_SkAlphaType) { 404 const uint8_t encodedColorType = png_get_color_type(fPng_ptr, fInfo_ ptr);
405 if (PNG_COLOR_TYPE_GRAY_ALPHA == encodedColorType ||
406 PNG_COLOR_TYPE_GRAY == encodedColorType) {
407 // If encodedColorType is GRAY, there must be a transparent chun k.
408 // Otherwise, suggestedColorType would be kGray. We have alread y
409 // instructed libpng to convert the transparent chunk to alpha,
410 // so we can treat both GRAY and GRAY_ALPHA as kGrayAlpha.
411 SkASSERT(encodedColorType == PNG_COLOR_TYPE_GRAY_ALPHA ||
412 png_get_valid(fPng_ptr, fInfo_ptr, PNG_INFO_tRNS));
413
414 fSrcConfig = SkSwizzler::kGrayAlpha;
415 } else {
416 if (this->getInfo().alphaType() == kOpaque_SkAlphaType) {
404 fSrcConfig = SkSwizzler::kRGB; 417 fSrcConfig = SkSwizzler::kRGB;
405 } else { 418 } else {
406 fSrcConfig = SkSwizzler::kRGBA; 419 fSrcConfig = SkSwizzler::kRGBA;
420 }
407 } 421 }
408 break; 422 break;
423 }
409 default: 424 default:
410 // We will always recommend one of the above colorTypes. 425 // We will always recommend one of the above colorTypes.
411 SkASSERT(false); 426 SkASSERT(false);
412 } 427 }
413 428
414 // Copy the color table to the client if they request kIndex8 mode 429 // Copy the color table to the client if they request kIndex8 mode
415 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount); 430 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount);
416 431
417 // Create the swizzler. SkPngCodec retains ownership of the color table. 432 // Create the swizzler. SkPngCodec retains ownership of the color table.
418 const SkPMColor* colors = get_color_ptr(fColorTable.get()); 433 const SkPMColor* colors = get_color_ptr(fColorTable.get());
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 } 763 }
749 764
750 if (1 == numberPasses) { 765 if (1 == numberPasses) {
751 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader, 766 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader,
752 png_ptr, info_ptr, bitDepth); 767 png_ptr, info_ptr, bitDepth);
753 } 768 }
754 769
755 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader, 770 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader,
756 png_ptr, info_ptr, bitDepth, numbe rPasses); 771 png_ptr, info_ptr, bitDepth, numbe rPasses);
757 } 772 }
OLDNEW
« no previous file with comments | « no previous file | src/codec/SkSwizzler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698