OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The Android Open Source Project | 2 * Copyright 2015 The Android Open Source Project |
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 #ifndef SkCodecPriv_DEFINED | 8 #ifndef SkCodecPriv_DEFINED |
9 #define SkCodecPriv_DEFINED | 9 #define SkCodecPriv_DEFINED |
10 | 10 |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkColorTable.h" | 12 #include "SkColorTable.h" |
13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
15 #include "SkUtils.h" | 15 #include "SkUtils.h" |
16 | 16 |
| 17 #ifdef SK_PRINT_CODEC_MESSAGES |
| 18 #define SkCodecPrintf SkDebugf |
| 19 #else |
| 20 #define SkCodecPrintf(...) |
| 21 #endif |
| 22 |
17 // FIXME: Consider sharing with dm, nanbench, and tools. | 23 // FIXME: Consider sharing with dm, nanbench, and tools. |
18 inline float get_scale_from_sample_size(int sampleSize) { | 24 inline float get_scale_from_sample_size(int sampleSize) { |
19 return 1.0f / ((float) sampleSize); | 25 return 1.0f / ((float) sampleSize); |
20 } | 26 } |
21 | 27 |
22 inline bool is_valid_subset(const SkIRect& subset, const SkISize& imageDims) { | 28 inline bool is_valid_subset(const SkIRect& subset, const SkISize& imageDims) { |
23 return SkIRect::MakeSize(imageDims).contains(subset); | 29 return SkIRect::MakeSize(imageDims).contains(subset); |
24 } | 30 } |
25 | 31 |
26 /* | 32 /* |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // Return false on edge cases | 74 // Return false on edge cases |
69 if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaled
Dim) { | 75 if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaled
Dim) { |
70 return false; | 76 return false; |
71 } | 77 } |
72 | 78 |
73 // Every sampleFactor rows are necessary | 79 // Every sampleFactor rows are necessary |
74 return ((srcCoord - startCoord) % sampleFactor) == 0; | 80 return ((srcCoord - startCoord) % sampleFactor) == 0; |
75 } | 81 } |
76 | 82 |
77 inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { | 83 inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { |
78 // Check for supported alpha types | 84 if (kUnknown_SkAlphaType == dstAlpha) { |
| 85 return false; |
| 86 } |
| 87 |
79 if (srcAlpha != dstAlpha) { | 88 if (srcAlpha != dstAlpha) { |
80 if (kOpaque_SkAlphaType == srcAlpha) { | 89 if (kOpaque_SkAlphaType == srcAlpha) { |
81 // If the source is opaque, we must decode to opaque | 90 // If the source is opaque, we can support any. |
82 return false; | 91 SkCodecPrintf("Warning: an opaque image should be decoded as opaque
" |
| 92 "- it is being decoded as non-opaque, which will draw
slower\n"); |
| 93 return true; |
83 } | 94 } |
84 | 95 |
85 // The source is not opaque | 96 // The source is not opaque |
86 switch (dstAlpha) { | 97 switch (dstAlpha) { |
87 case kPremul_SkAlphaType: | 98 case kPremul_SkAlphaType: |
88 case kUnpremul_SkAlphaType: | 99 case kUnpremul_SkAlphaType: |
89 // The source is not opaque, so either of these is okay | 100 // The source is not opaque, so either of these is okay |
90 break; | 101 break; |
91 default: | 102 default: |
92 // We cannot decode a non-opaque image to opaque (or unknown) | 103 // We cannot decode a non-opaque image to opaque (or unknown) |
93 return false; | 104 return false; |
94 } | 105 } |
95 } | 106 } |
96 return true; | 107 return true; |
97 } | 108 } |
98 | 109 |
99 /* | 110 /* |
100 * Most of our codecs support the same conversions: | 111 * Most of our codecs support the same conversions: |
101 * - profileType must be the same | 112 * - profileType must be the same |
102 * - opaque only to opaque (and 565 only if opaque) | 113 * - opaque to any alpha type |
| 114 * - 565 only if opaque |
103 * - premul to unpremul and vice versa | 115 * - premul to unpremul and vice versa |
104 * - always support N32 | 116 * - always support N32 |
105 * - otherwise match the src color type | 117 * - otherwise match the src color type |
106 */ | 118 */ |
107 inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src)
{ | 119 inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src)
{ |
108 if (dst.profileType() != src.profileType()) { | 120 if (dst.profileType() != src.profileType()) { |
109 return false; | 121 return false; |
110 } | 122 } |
111 | 123 |
112 // Ensure the alpha type is valid | 124 // Ensure the alpha type is valid |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 inline uint32_t get_int(uint8_t* buffer, uint32_t i) { | 235 inline uint32_t get_int(uint8_t* buffer, uint32_t i) { |
224 uint32_t result; | 236 uint32_t result; |
225 memcpy(&result, &(buffer[i]), 4); | 237 memcpy(&result, &(buffer[i]), 4); |
226 #ifdef SK_CPU_BENDIAN | 238 #ifdef SK_CPU_BENDIAN |
227 return SkEndianSwap32(result); | 239 return SkEndianSwap32(result); |
228 #else | 240 #else |
229 return result; | 241 return result; |
230 #endif | 242 #endif |
231 } | 243 } |
232 | 244 |
233 #ifdef SK_PRINT_CODEC_MESSAGES | |
234 #define SkCodecPrintf SkDebugf | |
235 #else | |
236 #define SkCodecPrintf(...) | |
237 #endif | |
238 | |
239 #endif // SkCodecPriv_DEFINED | 245 #endif // SkCodecPriv_DEFINED |
OLD | NEW |