Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 // srcColorType was determined in read_header() which determined png color t ype |
|
scroggo
2016/02/03 16:11:33
suggestedColorType*
msarett
2016/02/03 17:21:13
Done. Comment now reads:
suggestedColorType was d
| |
| 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 uint8_t encodedColorType = png_get_color_type(fPng_ptr, fInfo_ptr); |
|
scroggo
2016/02/03 16:11:33
Could be const
msarett
2016/02/03 17:21:13
Done.
| |
| 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. | |
|
scroggo
2016/02/03 16:11:33
SkASSERT this?
msarett
2016/02/03 17:21:13
Done.
| |
| 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 fSrcConfig = SkSwizzler::kGrayAlpha; | |
| 412 } else { | |
| 413 if (this->getInfo().alphaType() == kOpaque_SkAlphaType) { | |
| 404 fSrcConfig = SkSwizzler::kRGB; | 414 fSrcConfig = SkSwizzler::kRGB; |
| 405 } else { | 415 } else { |
| 406 fSrcConfig = SkSwizzler::kRGBA; | 416 fSrcConfig = SkSwizzler::kRGBA; |
| 417 } | |
| 407 } | 418 } |
| 408 break; | 419 break; |
| 420 } | |
| 409 default: | 421 default: |
| 410 // We will always recommend one of the above colorTypes. | 422 // We will always recommend one of the above colorTypes. |
| 411 SkASSERT(false); | 423 SkASSERT(false); |
| 412 } | 424 } |
| 413 | 425 |
| 414 // Copy the color table to the client if they request kIndex8 mode | 426 // Copy the color table to the client if they request kIndex8 mode |
| 415 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount); | 427 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount); |
| 416 | 428 |
| 417 // Create the swizzler. SkPngCodec retains ownership of the color table. | 429 // Create the swizzler. SkPngCodec retains ownership of the color table. |
| 418 const SkPMColor* colors = get_color_ptr(fColorTable.get()); | 430 const SkPMColor* colors = get_color_ptr(fColorTable.get()); |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 } | 760 } |
| 749 | 761 |
| 750 if (1 == numberPasses) { | 762 if (1 == numberPasses) { |
| 751 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader, | 763 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader, |
| 752 png_ptr, info_ptr, bitDepth); | 764 png_ptr, info_ptr, bitDepth); |
| 753 } | 765 } |
| 754 | 766 |
| 755 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader, | 767 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader, |
| 756 png_ptr, info_ptr, bitDepth, numbe rPasses); | 768 png_ptr, info_ptr, bitDepth, numbe rPasses); |
| 757 } | 769 } |
| OLD | NEW |