| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 U8CPU r = SkGetPackedR32(c); | 37 U8CPU r = SkGetPackedR32(c); |
| 38 U8CPU g = SkGetPackedG32(c); | 38 U8CPU g = SkGetPackedG32(c); |
| 39 U8CPU b = SkGetPackedB32(c); | 39 U8CPU b = SkGetPackedB32(c); |
| 40 return SkPreMultiplyARGB(a, r, g, b); | 40 return SkPreMultiplyARGB(a, r, g, b); |
| 41 } | 41 } |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Return true if this stream format should be skipped, due | 44 * Return true if this stream format should be skipped, due |
| 45 * to do being an opaque format or not a valid format. | 45 * to do being an opaque format or not a valid format. |
| 46 */ | 46 */ |
| 47 static bool skip_image_format(SkImageDecoder::Format format) { | 47 static bool skip_image_format(SkEncodedFormat format) { |
| 48 switch (format) { | 48 switch (format) { |
| 49 case SkImageDecoder::kPNG_Format: | 49 case kPNG_SkEncodedFormat: |
| 50 case SkImageDecoder::kWEBP_Format: | 50 case kWEBP_SkEncodedFormat: |
| 51 return false; | 51 return false; |
| 52 // Skip unknown since it will not be decoded anyway. | 52 // Skip unknown since it will not be decoded anyway. |
| 53 case SkImageDecoder::kUnknown_Format: | 53 case kUnknown_SkEncodedFormat: |
| 54 // Technically ICO and BMP supports alpha channels, but our image | 54 // Technically ICO and BMP supports alpha channels, but our image |
| 55 // decoders do not, so skip them as well. | 55 // decoders do not, so skip them as well. |
| 56 case SkImageDecoder::kICO_Format: | 56 case kICO_SkEncodedFormat: |
| 57 case SkImageDecoder::kBMP_Format: | 57 case kBMP_SkEncodedFormat: |
| 58 // KTX and ASTC are texture formats so it's not particularly clear how t
o | 58 // KTX and ASTC are texture formats so it's not particularly clear how t
o |
| 59 // decode the alpha from them. | 59 // decode the alpha from them. |
| 60 case SkImageDecoder::kKTX_Format: | 60 case kKTX_SkEncodedFormat: |
| 61 case SkImageDecoder::kASTC_Format: | 61 case kASTC_SkEncodedFormat: |
| 62 // The rest of these are opaque. | 62 // The rest of these are opaque. |
| 63 case SkImageDecoder::kPKM_Format: | 63 case kPKM_SkEncodedFormat: |
| 64 case SkImageDecoder::kWBMP_Format: | 64 case kWBMP_SkEncodedFormat: |
| 65 case SkImageDecoder::kGIF_Format: | 65 case kGIF_SkEncodedFormat: |
| 66 case SkImageDecoder::kJPEG_Format: | 66 case kJPEG_SkEncodedFormat: |
| 67 return true; | 67 return true; |
| 68 } | 68 } |
| 69 SkASSERT(false); | 69 SkASSERT(false); |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Test decoding an image in premultiplied mode and unpremultiplied mode and co
mpare | 74 * Test decoding an image in premultiplied mode and unpremultiplied mode and co
mpare |
| 75 * them. | 75 * them. |
| 76 */ | 76 */ |
| 77 static void compare_unpremul(skiatest::Reporter* reporter, const SkString& filen
ame) { | 77 static void compare_unpremul(skiatest::Reporter* reporter, const SkString& filen
ame) { |
| 78 // Decode a resource: | 78 // Decode a resource: |
| 79 SkBitmap bm8888; | 79 SkBitmap bm8888; |
| 80 SkBitmap bm8888Unpremul; | 80 SkBitmap bm8888Unpremul; |
| 81 | 81 |
| 82 SkFILEStream stream(filename.c_str()); | 82 SkFILEStream stream(filename.c_str()); |
| 83 | 83 |
| 84 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&stream); | 84 SkEncodedFormat format = SkImageDecoder::GetStreamFormat(&stream); |
| 85 if (skip_image_format(format)) { | 85 if (skip_image_format(format)) { |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream)); | 89 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream)); |
| 90 if (NULL == decoder.get()) { | 90 if (NULL == decoder.get()) { |
| 91 SkDebugf("couldn't decode %s\n", filename.c_str()); | 91 SkDebugf("couldn't decode %s\n", filename.c_str()); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 | 94 |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount))); | 744 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount))); |
| 745 decoder->setAllocator(allocator); | 745 decoder->setAllocator(allocator); |
| 746 decoder->setSampleSize(2); | 746 decoder->setSampleSize(2); |
| 747 SkBitmap bitmap; | 747 SkBitmap bitmap; |
| 748 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, | 748 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, |
| 749 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; | 749 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; |
| 750 REPORTER_ASSERT(r, success); | 750 REPORTER_ASSERT(r, success); |
| 751 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory | 751 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory |
| 752 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); | 752 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); |
| 753 } | 753 } |
| OLD | NEW |