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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 uint8_t zeroAlpha = 0; \ | 23 uint8_t zeroAlpha = 0; \ |
24 uint8_t maxAlpha = 0xFF; | 24 uint8_t maxAlpha = 0xFF; |
25 | 25 |
26 #define UPDATE_RESULT_ALPHA(alpha) \ | 26 #define UPDATE_RESULT_ALPHA(alpha) \ |
27 zeroAlpha |= (alpha); \ | 27 zeroAlpha |= (alpha); \ |
28 maxAlpha &= (alpha); | 28 maxAlpha &= (alpha); |
29 | 29 |
30 #define COMPUTE_RESULT_ALPHA \ | 30 #define COMPUTE_RESULT_ALPHA \ |
31 SkSwizzler::GetResult(zeroAlpha, maxAlpha); | 31 SkSwizzler::GetResult(zeroAlpha, maxAlpha); |
32 | 32 |
| 33 static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { |
| 34 // Check for supported alpha types |
| 35 if (srcAlpha != dstAlpha) { |
| 36 if (kOpaque_SkAlphaType == srcAlpha) { |
| 37 // If the source is opaque, we must decode to opaque |
| 38 return false; |
| 39 } |
| 40 |
| 41 // The source is not opaque |
| 42 switch (dstAlpha) { |
| 43 case kPremul_SkAlphaType: |
| 44 case kUnpremul_SkAlphaType: |
| 45 // The source is not opaque, so either of these is okay |
| 46 break; |
| 47 default: |
| 48 // We cannot decode a non-opaque image to opaque (or unknown) |
| 49 return false; |
| 50 } |
| 51 } |
| 52 return true; |
| 53 } |
| 54 |
33 /* | 55 /* |
34 * If there is a color table, get a pointer to the colors, otherwise return NULL | 56 * If there is a color table, get a pointer to the colors, otherwise return NULL |
35 */ | 57 */ |
36 static const SkPMColor* get_color_ptr(SkColorTable* colorTable) { | 58 static const SkPMColor* get_color_ptr(SkColorTable* colorTable) { |
37 return NULL != colorTable ? colorTable->readColors() : NULL; | 59 return NULL != colorTable ? colorTable->readColors() : NULL; |
38 } | 60 } |
39 | 61 |
40 /* | 62 /* |
41 * | 63 * |
42 * Copy the codec color table back to the client when kIndex8 color type is requ
ested | 64 * Copy the codec color table back to the client when kIndex8 color type is requ
ested |
43 * | |
44 */ | 65 */ |
45 static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* co
lorTable, | 66 static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* co
lorTable, |
46 SkPMColor* inputColorPtr, int* inputColorCount) { | 67 SkPMColor* inputColorPtr, int* inputColorCount) { |
47 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 68 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
48 SkASSERT(NULL != inputColorPtr); | 69 SkASSERT(NULL != inputColorPtr); |
49 SkASSERT(NULL != inputColorCount); | 70 SkASSERT(NULL != inputColorCount); |
50 SkASSERT(NULL != colorTable); | 71 SkASSERT(NULL != colorTable); |
51 memcpy(inputColorPtr, colorTable->readColors(), *inputColorCount * 4); | 72 memcpy(inputColorPtr, colorTable->readColors(), *inputColorCount * 4); |
52 } | 73 } |
53 } | 74 } |
54 | 75 |
55 /* | 76 /* |
56 * | |
57 * Compute row bytes for an image using pixels per byte | 77 * Compute row bytes for an image using pixels per byte |
58 * | |
59 */ | 78 */ |
60 static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { | 79 static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { |
61 return (width + pixelsPerByte - 1) / pixelsPerByte; | 80 return (width + pixelsPerByte - 1) / pixelsPerByte; |
62 } | 81 } |
63 | 82 |
64 /* | 83 /* |
65 * | |
66 * Compute row bytes for an image using bytes per pixel | 84 * Compute row bytes for an image using bytes per pixel |
67 * | |
68 */ | 85 */ |
69 static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { | 86 static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { |
70 return width * bytesPerPixel; | 87 return width * bytesPerPixel; |
71 } | 88 } |
72 | 89 |
73 /* | 90 /* |
74 * | |
75 * Compute row bytes for an image | 91 * Compute row bytes for an image |
76 * | |
77 */ | 92 */ |
78 static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { | 93 static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { |
79 if (bitsPerPixel < 16) { | 94 if (bitsPerPixel < 16) { |
80 SkASSERT(0 == 8 % bitsPerPixel); | 95 SkASSERT(0 == 8 % bitsPerPixel); |
81 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 96 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
82 return compute_row_bytes_ppb(width, pixelsPerByte); | 97 return compute_row_bytes_ppb(width, pixelsPerByte); |
83 } else { | 98 } else { |
84 SkASSERT(0 == bitsPerPixel % 8); | 99 SkASSERT(0 == bitsPerPixel % 8); |
85 const uint32_t bytesPerPixel = bitsPerPixel / 8; | 100 const uint32_t bytesPerPixel = bitsPerPixel / 8; |
86 return compute_row_bytes_bpp(width, bytesPerPixel); | 101 return compute_row_bytes_bpp(width, bytesPerPixel); |
87 } | 102 } |
88 } | 103 } |
89 | 104 |
90 /* | 105 /* |
91 * | |
92 * Get a byte from a buffer | 106 * Get a byte from a buffer |
93 * This method is unsafe, the caller is responsible for performing a check | 107 * This method is unsafe, the caller is responsible for performing a check |
94 * | |
95 */ | 108 */ |
96 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { | 109 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { |
97 return buffer[i]; | 110 return buffer[i]; |
98 } | 111 } |
99 | 112 |
100 /* | 113 /* |
101 * | |
102 * Get a short from a buffer | 114 * Get a short from a buffer |
103 * This method is unsafe, the caller is responsible for performing a check | 115 * This method is unsafe, the caller is responsible for performing a check |
104 * | |
105 */ | 116 */ |
106 static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { | 117 static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { |
107 uint16_t result; | 118 uint16_t result; |
108 memcpy(&result, &(buffer[i]), 2); | 119 memcpy(&result, &(buffer[i]), 2); |
109 #ifdef SK_CPU_BENDIAN | 120 #ifdef SK_CPU_BENDIAN |
110 return SkEndianSwap16(result); | 121 return SkEndianSwap16(result); |
111 #else | 122 #else |
112 return result; | 123 return result; |
113 #endif | 124 #endif |
114 } | 125 } |
115 | 126 |
116 /* | 127 /* |
117 * | |
118 * Get an int from a buffer | 128 * Get an int from a buffer |
119 * This method is unsafe, the caller is responsible for performing a check | 129 * This method is unsafe, the caller is responsible for performing a check |
120 * | |
121 */ | 130 */ |
122 static inline uint32_t get_int(uint8_t* buffer, uint32_t i) { | 131 static inline uint32_t get_int(uint8_t* buffer, uint32_t i) { |
123 uint32_t result; | 132 uint32_t result; |
124 memcpy(&result, &(buffer[i]), 4); | 133 memcpy(&result, &(buffer[i]), 4); |
125 #ifdef SK_CPU_BENDIAN | 134 #ifdef SK_CPU_BENDIAN |
126 return SkEndianSwap32(result); | 135 return SkEndianSwap32(result); |
127 #else | 136 #else |
128 return result; | 137 return result; |
129 #endif | 138 #endif |
130 } | 139 } |
131 | 140 |
132 #ifdef SK_PRINT_CODEC_MESSAGES | 141 #ifdef SK_PRINT_CODEC_MESSAGES |
133 #define SkCodecPrintf SkDebugf | 142 #define SkCodecPrintf SkDebugf |
134 #else | 143 #else |
135 #define SkCodecPrintf(...) | 144 #define SkCodecPrintf(...) |
136 #endif | 145 #endif |
137 | 146 |
138 #endif // SkCodecPriv_DEFINED | 147 #endif // SkCodecPriv_DEFINED |
OLD | NEW |