| 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 /////////////////////////////////////////////////////////////////////////////// | 390 /////////////////////////////////////////////////////////////////////////////// |
| 391 // Getting the pixels | 391 // Getting the pixels |
| 392 /////////////////////////////////////////////////////////////////////////////// | 392 /////////////////////////////////////////////////////////////////////////////// |
| 393 | 393 |
| 394 static bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src)
{ | 394 static bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src)
{ |
| 395 // TODO: Support other conversions | 395 // TODO: Support other conversions |
| 396 if (dst.profileType() != src.profileType()) { | 396 if (dst.profileType() != src.profileType()) { |
| 397 return false; | 397 return false; |
| 398 } | 398 } |
| 399 | 399 |
| 400 // Check for supported alpha types | 400 // Ensure the alpha type is valid |
| 401 if (src.alphaType() != dst.alphaType()) { | 401 if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
| 402 if (kOpaque_SkAlphaType == src.alphaType()) { | 402 return false; |
| 403 // If the source is opaque, we must decode to opaque | 403 } |
| 404 return false; | |
| 405 } | |
| 406 | 404 |
| 407 // The source is not opaque | |
| 408 switch (dst.alphaType()) { | |
| 409 case kPremul_SkAlphaType: | |
| 410 case kUnpremul_SkAlphaType: | |
| 411 // The source is not opaque, so either of these is okay | |
| 412 break; | |
| 413 default: | |
| 414 // We cannot decode a non-opaque image to opaque (or unknown) | |
| 415 return false; | |
| 416 } | |
| 417 } | |
| 418 // Check for supported color types | 405 // Check for supported color types |
| 419 switch (dst.colorType()) { | 406 switch (dst.colorType()) { |
| 420 case kN32_SkColorType: | 407 case kN32_SkColorType: |
| 421 return true; | 408 return true; |
| 422 default: | 409 default: |
| 423 return dst.colorType() == src.colorType(); | 410 return dst.colorType() == src.colorType(); |
| 424 } | 411 } |
| 425 } | 412 } |
| 426 | 413 |
| 427 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, | 414 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 | 737 |
| 751 SkASSERT(codec->fNumberPasses != INVALID_NUMBER_PASSES); | 738 SkASSERT(codec->fNumberPasses != INVALID_NUMBER_PASSES); |
| 752 if (codec->fNumberPasses > 1) { | 739 if (codec->fNumberPasses > 1) { |
| 753 // interlaced image | 740 // interlaced image |
| 754 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (dstInfo, codec.detach
())); | 741 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (dstInfo, codec.detach
())); |
| 755 } | 742 } |
| 756 | 743 |
| 757 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, codec.detach())); | 744 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, codec.detach())); |
| 758 } | 745 } |
| 759 | 746 |
| OLD | NEW |