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 case kRGB_565_SkColorType: | 409 case kRGB_565_SkColorType: |
423 return src.alphaType() == kOpaque_SkAlphaType; | 410 return src.alphaType() == kOpaque_SkAlphaType; |
424 default: | 411 default: |
425 return dst.colorType() == src.colorType(); | 412 return dst.colorType() == src.colorType(); |
426 } | 413 } |
427 } | 414 } |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 | 794 |
808 const SkImageInfo& srcInfo = codec->getInfo(); | 795 const SkImageInfo& srcInfo = codec->getInfo(); |
809 if (codec->fNumberPasses > 1) { | 796 if (codec->fNumberPasses > 1) { |
810 // interlaced image | 797 // interlaced image |
811 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (srcInfo, codec.detach
())); | 798 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (srcInfo, codec.detach
())); |
812 } | 799 } |
813 | 800 |
814 return SkNEW_ARGS(SkPngScanlineDecoder, (srcInfo, codec.detach())); | 801 return SkNEW_ARGS(SkPngScanlineDecoder, (srcInfo, codec.detach())); |
815 } | 802 } |
816 | 803 |
OLD | NEW |