| 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 "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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 fPng_ptr = NULL; | 93 fPng_ptr = NULL; |
| 94 fInfo_ptr = NULL; | 94 fInfo_ptr = NULL; |
| 95 } | 95 } |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 png_structp fPng_ptr; | 98 png_structp fPng_ptr; |
| 99 png_infop fInfo_ptr; | 99 png_infop fInfo_ptr; |
| 100 }; | 100 }; |
| 101 #define AutoCleanPng(...) SK_REQUIRE_LOCAL_VAR(AutoCleanPng) | 101 #define AutoCleanPng(...) SK_REQUIRE_LOCAL_VAR(AutoCleanPng) |
| 102 | 102 |
| 103 // call only if color_type is PALETTE. Returns true if the ctable has alpha | 103 //checks if there is transparency info in the tRNS chunk |
| 104 static bool has_transparency_in_palette(png_structp png_ptr, | 104 //image types which could have data in the tRNS chunk include: Index8, Gray8, RG
B |
| 105 static bool has_transparency_in_tRNS(png_structp png_ptr, |
| 105 png_infop info_ptr) { | 106 png_infop info_ptr) { |
| 106 if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { | 107 if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { |
| 107 return false; | 108 return false; |
| 108 } | 109 } |
| 109 | 110 |
| 110 png_bytep trans; | 111 png_bytep trans; |
| 111 int num_trans; | 112 int num_trans; |
| 112 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL); | 113 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL); |
| 113 return num_trans > 0; | 114 return num_trans > 0; |
| 114 } | 115 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) { | 281 if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) { |
| 281 png_set_expand_gray_1_2_4_to_8(png_ptr); | 282 png_set_expand_gray_1_2_4_to_8(png_ptr); |
| 282 } | 283 } |
| 283 | 284 |
| 284 // Now determine the default SkColorType and SkAlphaType and set required tr
ansforms | 285 // Now determine the default SkColorType and SkAlphaType and set required tr
ansforms |
| 285 SkColorType skColorType; | 286 SkColorType skColorType; |
| 286 SkAlphaType skAlphaType; | 287 SkAlphaType skAlphaType; |
| 287 switch (colorType) { | 288 switch (colorType) { |
| 288 case PNG_COLOR_TYPE_PALETTE: | 289 case PNG_COLOR_TYPE_PALETTE: |
| 289 skColorType = kIndex_8_SkColorType; | 290 skColorType = kIndex_8_SkColorType; |
| 290 skAlphaType = has_transparency_in_palette(png_ptr, info_ptr) ? | 291 skAlphaType = has_transparency_in_tRNS(png_ptr, info_ptr) ? |
| 291 kUnpremul_SkAlphaType : kOpaque_SkAlphaType; | 292 kUnpremul_SkAlphaType : kOpaque_SkAlphaType; |
| 292 break; | 293 break; |
| 293 case PNG_COLOR_TYPE_RGB: | 294 case PNG_COLOR_TYPE_RGB: |
| 294 if (has_transparency_in_palette(png_ptr, info_ptr)) { | 295 if (has_transparency_in_tRNS(png_ptr, info_ptr)) { |
| 295 //convert to RGBA with tranparency information in tRNS chunk if
it exists | 296 //convert to RGBA with tranparency information in tRNS chunk if
it exists |
| 296 png_set_tRNS_to_alpha(png_ptr); | 297 png_set_tRNS_to_alpha(png_ptr); |
| 297 skAlphaType = kUnpremul_SkAlphaType; | 298 skAlphaType = kUnpremul_SkAlphaType; |
| 298 } else { | 299 } else { |
| 299 //convert to RGBA with Opaque Alpha | 300 //convert to RGBA with Opaque Alpha |
| 300 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); | 301 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); |
| 301 skAlphaType = kOpaque_SkAlphaType; | 302 skAlphaType = kOpaque_SkAlphaType; |
| 302 } | 303 } |
| 303 skColorType = kN32_SkColorType; | 304 skColorType = kN32_SkColorType; |
| 304 break; | 305 break; |
| 305 case PNG_COLOR_TYPE_GRAY: | 306 case PNG_COLOR_TYPE_GRAY: |
| 306 if (has_transparency_in_palette(png_ptr, info_ptr)) { | 307 if (has_transparency_in_tRNS(png_ptr, info_ptr)) { |
| 307 //FIXME: support gray with alpha as a color type | 308 //FIXME: support gray with alpha as a color type |
| 308 //convert to RGBA if there is transparentcy info in the tRNS chu
nk | 309 //convert to RGBA if there is transparentcy info in the tRNS chu
nk |
| 309 png_set_tRNS_to_alpha(png_ptr); | 310 png_set_tRNS_to_alpha(png_ptr); |
| 310 png_set_gray_to_rgb(png_ptr); | 311 png_set_gray_to_rgb(png_ptr); |
| 311 skColorType = kN32_SkColorType; | 312 skColorType = kN32_SkColorType; |
| 312 skAlphaType = kUnpremul_SkAlphaType; | 313 skAlphaType = kUnpremul_SkAlphaType; |
| 313 } else { | 314 } else { |
| 314 skColorType = kGray_8_SkColorType; | 315 skColorType = kGray_8_SkColorType; |
| 315 skAlphaType = kOpaque_SkAlphaType; | 316 skAlphaType = kOpaque_SkAlphaType; |
| 316 } | 317 } |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 | 762 |
| 762 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); | 763 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); |
| 763 if (fNumberPasses > 1) { | 764 if (fNumberPasses > 1) { |
| 764 // interlaced image | 765 // interlaced image |
| 765 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (dstInfo, this)); | 766 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (dstInfo, this)); |
| 766 } | 767 } |
| 767 | 768 |
| 768 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this)); | 769 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this)); |
| 769 } | 770 } |
| 770 | 771 |
| OLD | NEW |