| 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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkSwizzler.h" | 10 #include "SkSwizzler.h" |
| 11 #include "SkTemplates.h" | 11 #include "SkTemplates.h" |
| 12 | 12 |
| 13 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, | |
| 14 uint8_t maxAlpha) { | |
| 15 // In the transparent case, this returns 0x0000 | |
| 16 // In the opaque case, this returns 0xFFFF | |
| 17 // If the row is neither transparent nor opaque, returns something else | |
| 18 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; | |
| 19 } | |
| 20 | |
| 21 // samples the row. Does not do anything else but sampling | 13 // samples the row. Does not do anything else but sampling |
| 22 static SkSwizzler::ResultAlpha sample565(void* SK_RESTRICT dstRow, const uint8_t
* SK_RESTRICT src, | 14 static void sample565(void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, |
| 23 int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[]){ | 15 int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[]){ |
| 24 | 16 |
| 25 src += offset; | 17 src += offset; |
| 26 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | 18 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; |
| 27 for (int x = 0; x < width; x++) { | 19 for (int x = 0; x < width; x++) { |
| 28 dst[x] = src[1] << 8 | src[0]; | 20 dst[x] = src[1] << 8 | src[0]; |
| 29 src += deltaSrc; | 21 src += deltaSrc; |
| 30 } | 22 } |
| 31 // 565 is always opaque | |
| 32 return SkSwizzler::kOpaque_ResultAlpha; | |
| 33 } | 23 } |
| 34 | 24 |
| 35 // TODO (msarett): Investigate SIMD optimizations for swizzle routines. | 25 // TODO (msarett): Investigate SIMD optimizations for swizzle routines. |
| 36 | 26 |
| 37 // kBit | 27 // kBit |
| 38 // These routines exclusively choose between white and black | 28 // These routines exclusively choose between white and black |
| 39 | 29 |
| 40 #define GRAYSCALE_BLACK 0 | 30 #define GRAYSCALE_BLACK 0 |
| 41 #define GRAYSCALE_WHITE 0xFF | 31 #define GRAYSCALE_WHITE 0xFF |
| 42 | 32 |
| 43 | 33 |
| 44 // same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned
to dst[x] | 34 // same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned
to dst[x] |
| 45 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( | 35 static void swizzle_bit_to_grayscale( |
| 46 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 36 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 47 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) { | 37 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) { |
| 48 | 38 |
| 49 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 39 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 50 | 40 |
| 51 // increment src by byte offset and bitIndex by bit offset | 41 // increment src by byte offset and bitIndex by bit offset |
| 52 src += offset / 8; | 42 src += offset / 8; |
| 53 int bitIndex = offset % 8; | 43 int bitIndex = offset % 8; |
| 54 uint8_t currByte = *src; | 44 uint8_t currByte = *src; |
| 55 | 45 |
| 56 dst[0] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLAC
K; | 46 dst[0] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLAC
K; |
| 57 | 47 |
| 58 for (int x = 1; x < dstWidth; x++) { | 48 for (int x = 1; x < dstWidth; x++) { |
| 59 int bitOffset = bitIndex + deltaSrc; | 49 int bitOffset = bitIndex + deltaSrc; |
| 60 bitIndex = bitOffset % 8; | 50 bitIndex = bitOffset % 8; |
| 61 currByte = *(src += bitOffset / 8); | 51 currByte = *(src += bitOffset / 8); |
| 62 dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_
BLACK; | 52 dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_
BLACK; |
| 63 } | 53 } |
| 64 | |
| 65 return SkSwizzler::kOpaque_ResultAlpha; | |
| 66 } | 54 } |
| 67 | 55 |
| 68 #undef GRAYSCALE_BLACK | 56 #undef GRAYSCALE_BLACK |
| 69 #undef GRAYSCALE_WHITE | 57 #undef GRAYSCALE_WHITE |
| 70 | 58 |
| 71 // same as swizzle_bit_to_grayscale and swizzle_bit_to_n32 except for value assi
gned to dst[x] | 59 // same as swizzle_bit_to_grayscale and swizzle_bit_to_n32 except for value assi
gned to dst[x] |
| 72 static SkSwizzler::ResultAlpha swizzle_bit_to_index( | 60 static void swizzle_bit_to_index( |
| 73 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 61 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 74 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) { | 62 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) { |
| 75 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 63 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 76 | 64 |
| 77 // increment src by byte offset and bitIndex by bit offset | 65 // increment src by byte offset and bitIndex by bit offset |
| 78 src += offset / 8; | 66 src += offset / 8; |
| 79 int bitIndex = offset % 8; | 67 int bitIndex = offset % 8; |
| 80 uint8_t currByte = *src; | 68 uint8_t currByte = *src; |
| 81 | 69 |
| 82 dst[0] = ((currByte >> (7-bitIndex)) & 1); | 70 dst[0] = ((currByte >> (7-bitIndex)) & 1); |
| 83 | 71 |
| 84 for (int x = 1; x < dstWidth; x++) { | 72 for (int x = 1; x < dstWidth; x++) { |
| 85 int bitOffset = bitIndex + deltaSrc; | 73 int bitOffset = bitIndex + deltaSrc; |
| 86 bitIndex = bitOffset % 8; | 74 bitIndex = bitOffset % 8; |
| 87 currByte = *(src += bitOffset / 8); | 75 currByte = *(src += bitOffset / 8); |
| 88 dst[x] = ((currByte >> (7-bitIndex)) & 1); | 76 dst[x] = ((currByte >> (7-bitIndex)) & 1); |
| 89 } | 77 } |
| 90 | |
| 91 return SkSwizzler::kOpaque_ResultAlpha; | |
| 92 } | 78 } |
| 93 | 79 |
| 94 // same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value as
signed to dst[x] | 80 // same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value as
signed to dst[x] |
| 95 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( | 81 static void swizzle_bit_to_n32( |
| 96 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 82 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 97 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) { | 83 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) { |
| 98 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | 84 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
| 99 | 85 |
| 100 // increment src by byte offset and bitIndex by bit offset | 86 // increment src by byte offset and bitIndex by bit offset |
| 101 src += offset / 8; | 87 src += offset / 8; |
| 102 int bitIndex = offset % 8; | 88 int bitIndex = offset % 8; |
| 103 uint8_t currByte = *src; | 89 uint8_t currByte = *src; |
| 104 | 90 |
| 105 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK; | 91 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| 106 | 92 |
| 107 for (int x = 1; x < dstWidth; x++) { | 93 for (int x = 1; x < dstWidth; x++) { |
| 108 int bitOffset = bitIndex + deltaSrc; | 94 int bitOffset = bitIndex + deltaSrc; |
| 109 bitIndex = bitOffset % 8; | 95 bitIndex = bitOffset % 8; |
| 110 currByte = *(src += bitOffset / 8); | 96 currByte = *(src += bitOffset / 8); |
| 111 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBL
ACK; | 97 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBL
ACK; |
| 112 } | 98 } |
| 113 | |
| 114 return SkSwizzler::kOpaque_ResultAlpha; | |
| 115 } | 99 } |
| 116 | 100 |
| 117 #define RGB565_BLACK 0 | 101 #define RGB565_BLACK 0 |
| 118 #define RGB565_WHITE 0xFFFF | 102 #define RGB565_WHITE 0xFFFF |
| 119 | 103 |
| 120 static SkSwizzler::ResultAlpha swizzle_bit_to_565( | 104 static void swizzle_bit_to_565( |
| 121 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 105 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 122 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) { | 106 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) { |
| 123 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | 107 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; |
| 124 | 108 |
| 125 // increment src by byte offset and bitIndex by bit offset | 109 // increment src by byte offset and bitIndex by bit offset |
| 126 src += offset / 8; | 110 src += offset / 8; |
| 127 int bitIndex = offset % 8; | 111 int bitIndex = offset % 8; |
| 128 uint8_t currByte = *src; | 112 uint8_t currByte = *src; |
| 129 | 113 |
| 130 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK; | 114 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK; |
| 131 | 115 |
| 132 for (int x = 1; x < dstWidth; x++) { | 116 for (int x = 1; x < dstWidth; x++) { |
| 133 int bitOffset = bitIndex + deltaSrc; | 117 int bitOffset = bitIndex + deltaSrc; |
| 134 bitIndex = bitOffset % 8; | 118 bitIndex = bitOffset % 8; |
| 135 currByte = *(src += bitOffset / 8); | 119 currByte = *(src += bitOffset / 8); |
| 136 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLAC
K; | 120 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLAC
K; |
| 137 } | 121 } |
| 138 | |
| 139 return SkSwizzler::kOpaque_ResultAlpha; | |
| 140 } | 122 } |
| 141 | 123 |
| 142 #undef RGB565_BLACK | 124 #undef RGB565_BLACK |
| 143 #undef RGB565_WHITE | 125 #undef RGB565_WHITE |
| 144 | 126 |
| 145 // kIndex1, kIndex2, kIndex4 | 127 // kIndex1, kIndex2, kIndex4 |
| 146 | 128 |
| 147 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( | 129 static void swizzle_small_index_to_index( |
| 148 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 130 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 149 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 131 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 150 | 132 |
| 151 uint8_t* dst = (uint8_t*) dstRow; | 133 uint8_t* dst = (uint8_t*) dstRow; |
| 152 INIT_RESULT_ALPHA; | |
| 153 src += offset / 8; | 134 src += offset / 8; |
| 154 int bitIndex = offset % 8; | 135 int bitIndex = offset % 8; |
| 155 uint8_t currByte = *src; | 136 uint8_t currByte = *src; |
| 156 const uint8_t mask = (1 << bpp) - 1; | 137 const uint8_t mask = (1 << bpp) - 1; |
| 157 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask; | 138 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask; |
| 158 dst[0] = index; | 139 dst[0] = index; |
| 159 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); | |
| 160 | 140 |
| 161 for (int x = 1; x < dstWidth; x++) { | 141 for (int x = 1; x < dstWidth; x++) { |
| 162 int bitOffset = bitIndex + deltaSrc; | 142 int bitOffset = bitIndex + deltaSrc; |
| 163 bitIndex = bitOffset % 8; | 143 bitIndex = bitOffset % 8; |
| 164 currByte = *(src += bitOffset / 8); | 144 currByte = *(src += bitOffset / 8); |
| 165 index = (currByte >> (8 - bpp - bitIndex)) & mask; | 145 index = (currByte >> (8 - bpp - bitIndex)) & mask; |
| 166 dst[x] = index; | 146 dst[x] = index; |
| 167 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); | |
| 168 } | 147 } |
| 169 return COMPUTE_RESULT_ALPHA; | |
| 170 } | 148 } |
| 171 | 149 |
| 172 static SkSwizzler::ResultAlpha swizzle_small_index_to_565( | 150 static void swizzle_small_index_to_565( |
| 173 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 151 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 174 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 152 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 175 | 153 |
| 176 uint16_t* dst = (uint16_t*) dstRow; | 154 uint16_t* dst = (uint16_t*) dstRow; |
| 177 src += offset / 8; | 155 src += offset / 8; |
| 178 int bitIndex = offset % 8; | 156 int bitIndex = offset % 8; |
| 179 uint8_t currByte = *src; | 157 uint8_t currByte = *src; |
| 180 const uint8_t mask = (1 << bpp) - 1; | 158 const uint8_t mask = (1 << bpp) - 1; |
| 181 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask; | 159 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask; |
| 182 dst[0] = SkPixel32ToPixel16(ctable[index]); | 160 dst[0] = SkPixel32ToPixel16(ctable[index]); |
| 183 | 161 |
| 184 for (int x = 1; x < dstWidth; x++) { | 162 for (int x = 1; x < dstWidth; x++) { |
| 185 int bitOffset = bitIndex + deltaSrc; | 163 int bitOffset = bitIndex + deltaSrc; |
| 186 bitIndex = bitOffset % 8; | 164 bitIndex = bitOffset % 8; |
| 187 currByte = *(src += bitOffset / 8); | 165 currByte = *(src += bitOffset / 8); |
| 188 index = (currByte >> (8 - bpp - bitIndex)) & mask; | 166 index = (currByte >> (8 - bpp - bitIndex)) & mask; |
| 189 dst[x] = SkPixel32ToPixel16(ctable[index]); | 167 dst[x] = SkPixel32ToPixel16(ctable[index]); |
| 190 } | 168 } |
| 191 return SkAlphaType::kOpaque_SkAlphaType; | |
| 192 } | 169 } |
| 193 | 170 |
| 194 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( | 171 static void swizzle_small_index_to_n32( |
| 195 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 172 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 196 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 173 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 197 | 174 |
| 198 SkPMColor* dst = (SkPMColor*) dstRow; | 175 SkPMColor* dst = (SkPMColor*) dstRow; |
| 199 INIT_RESULT_ALPHA; | |
| 200 src += offset / 8; | 176 src += offset / 8; |
| 201 int bitIndex = offset % 8; | 177 int bitIndex = offset % 8; |
| 202 uint8_t currByte = *src; | 178 uint8_t currByte = *src; |
| 203 const uint8_t mask = (1 << bpp) - 1; | 179 const uint8_t mask = (1 << bpp) - 1; |
| 204 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask; | 180 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask; |
| 205 dst[0] = ctable[index]; | 181 dst[0] = ctable[index]; |
| 206 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); | |
| 207 | 182 |
| 208 for (int x = 1; x < dstWidth; x++) { | 183 for (int x = 1; x < dstWidth; x++) { |
| 209 int bitOffset = bitIndex + deltaSrc; | 184 int bitOffset = bitIndex + deltaSrc; |
| 210 bitIndex = bitOffset % 8; | 185 bitIndex = bitOffset % 8; |
| 211 currByte = *(src += bitOffset / 8); | 186 currByte = *(src += bitOffset / 8); |
| 212 index = (currByte >> (8 - bpp - bitIndex)) & mask; | 187 index = (currByte >> (8 - bpp - bitIndex)) & mask; |
| 213 dst[x] = ctable[index]; | 188 dst[x] = ctable[index]; |
| 214 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); | |
| 215 } | 189 } |
| 216 return COMPUTE_RESULT_ALPHA; | |
| 217 } | 190 } |
| 218 | 191 |
| 219 // kIndex | 192 // kIndex |
| 220 | 193 |
| 221 static SkSwizzler::ResultAlpha swizzle_index_to_index( | 194 static void swizzle_index_to_index( |
| 222 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 195 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 223 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 196 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 224 | 197 |
| 225 src += offset; | 198 src += offset; |
| 226 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 199 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 227 INIT_RESULT_ALPHA; | |
| 228 // TODO (msarett): Should we skip the loop here and guess that the row is op
aque/not opaque? | |
| 229 // SkScaledBitmap sampler just guesses that it is opaque. T
his is dangerous | |
| 230 // and probably wrong since gif and bmp (rarely) may have al
pha. | |
| 231 if (1 == deltaSrc) { | 200 if (1 == deltaSrc) { |
| 232 memcpy(dst, src, dstWidth); | 201 memcpy(dst, src, dstWidth); |
| 233 for (int x = 0; x < dstWidth; x++) { | |
| 234 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); | |
| 235 } | |
| 236 } else { | 202 } else { |
| 237 for (int x = 0; x < dstWidth; x++) { | 203 for (int x = 0; x < dstWidth; x++) { |
| 238 dst[x] = *src; | 204 dst[x] = *src; |
| 239 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); | |
| 240 src += deltaSrc; | 205 src += deltaSrc; |
| 241 } | 206 } |
| 242 } | 207 } |
| 243 return COMPUTE_RESULT_ALPHA; | |
| 244 } | 208 } |
| 245 | 209 |
| 246 static SkSwizzler::ResultAlpha swizzle_index_to_n32( | 210 static void swizzle_index_to_n32( |
| 247 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 211 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 248 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 212 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 249 | 213 |
| 250 src += offset; | 214 src += offset; |
| 251 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 215 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 252 INIT_RESULT_ALPHA; | |
| 253 for (int x = 0; x < dstWidth; x++) { | 216 for (int x = 0; x < dstWidth; x++) { |
| 254 SkPMColor c = ctable[*src]; | 217 SkPMColor c = ctable[*src]; |
| 255 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | |
| 256 dst[x] = c; | 218 dst[x] = c; |
| 257 src += deltaSrc; | 219 src += deltaSrc; |
| 258 } | 220 } |
| 259 return COMPUTE_RESULT_ALPHA; | |
| 260 } | 221 } |
| 261 | 222 |
| 262 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( | 223 static void swizzle_index_to_n32_skipZ( |
| 263 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 224 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 264 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 225 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 265 | 226 |
| 266 src += offset; | 227 src += offset; |
| 267 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 228 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 268 INIT_RESULT_ALPHA; | |
| 269 for (int x = 0; x < dstWidth; x++) { | 229 for (int x = 0; x < dstWidth; x++) { |
| 270 SkPMColor c = ctable[*src]; | 230 SkPMColor c = ctable[*src]; |
| 271 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | |
| 272 if (c != 0) { | 231 if (c != 0) { |
| 273 dst[x] = c; | 232 dst[x] = c; |
| 274 } | 233 } |
| 275 src += deltaSrc; | 234 src += deltaSrc; |
| 276 } | 235 } |
| 277 return COMPUTE_RESULT_ALPHA; | |
| 278 } | 236 } |
| 279 | 237 |
| 280 static SkSwizzler::ResultAlpha swizzle_index_to_565( | 238 static void swizzle_index_to_565( |
| 281 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 239 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 282 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 240 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 283 // FIXME: Support dithering? Requires knowing y, which I think is a bigger | |
| 284 // change. | |
| 285 src += offset; | 241 src += offset; |
| 286 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 242 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 287 for (int x = 0; x < dstWidth; x++) { | 243 for (int x = 0; x < dstWidth; x++) { |
| 288 dst[x] = SkPixel32ToPixel16(ctable[*src]); | 244 dst[x] = SkPixel32ToPixel16(ctable[*src]); |
| 289 src += deltaSrc; | 245 src += deltaSrc; |
| 290 } | 246 } |
| 291 return SkSwizzler::kOpaque_ResultAlpha; | |
| 292 } | 247 } |
| 293 | 248 |
| 294 | |
| 295 #undef A32_MASK_IN_PLACE | |
| 296 | |
| 297 // kGray | 249 // kGray |
| 298 | 250 |
| 299 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( | 251 static void swizzle_gray_to_n32( |
| 300 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 252 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 301 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 253 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 302 | 254 |
| 303 src += offset; | 255 src += offset; |
| 304 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 256 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 305 for (int x = 0; x < dstWidth; x++) { | 257 for (int x = 0; x < dstWidth; x++) { |
| 306 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); | 258 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); |
| 307 src += deltaSrc; | 259 src += deltaSrc; |
| 308 } | 260 } |
| 309 return SkSwizzler::kOpaque_ResultAlpha; | |
| 310 } | 261 } |
| 311 | 262 |
| 312 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( | 263 static void swizzle_gray_to_gray( |
| 313 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 264 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 314 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 265 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 315 | 266 |
| 316 src += offset; | 267 src += offset; |
| 317 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 268 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 318 if (1 == deltaSrc) { | 269 if (1 == deltaSrc) { |
| 319 memcpy(dstRow, src, dstWidth); | 270 memcpy(dstRow, src, dstWidth); |
| 320 } else { | 271 } else { |
| 321 for (int x = 0; x < dstWidth; x++) { | 272 for (int x = 0; x < dstWidth; x++) { |
| 322 dst[x] = src[0]; | 273 dst[x] = src[0]; |
| 323 src += deltaSrc; | 274 src += deltaSrc; |
| 324 } | 275 } |
| 325 } | 276 } |
| 326 return SkSwizzler::kOpaque_ResultAlpha; | |
| 327 } | 277 } |
| 328 | 278 |
| 329 static SkSwizzler::ResultAlpha swizzle_gray_to_565( | 279 static void swizzle_gray_to_565( |
| 330 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 280 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 331 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 281 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 332 // FIXME: Support dithering? | 282 |
| 333 src += offset; | 283 src += offset; |
| 334 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 284 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 335 for (int x = 0; x < dstWidth; x++) { | 285 for (int x = 0; x < dstWidth; x++) { |
| 336 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); | 286 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); |
| 337 src += deltaSrc; | 287 src += deltaSrc; |
| 338 } | 288 } |
| 339 return SkSwizzler::kOpaque_ResultAlpha; | |
| 340 } | 289 } |
| 341 | 290 |
| 342 // kBGRX | 291 // kBGRX |
| 343 | 292 |
| 344 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( | 293 static void swizzle_bgrx_to_n32( |
| 345 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 294 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 346 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 295 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 347 | 296 |
| 348 src += offset; | 297 src += offset; |
| 349 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 298 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 350 for (int x = 0; x < dstWidth; x++) { | 299 for (int x = 0; x < dstWidth; x++) { |
| 351 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 300 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
| 352 src += deltaSrc; | 301 src += deltaSrc; |
| 353 } | 302 } |
| 354 return SkSwizzler::kOpaque_ResultAlpha; | |
| 355 } | 303 } |
| 356 | 304 |
| 357 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565( | 305 static void swizzle_bgrx_to_565( |
| 358 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 306 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 359 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 307 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 360 // FIXME: Support dithering? | 308 |
| 361 src += offset; | 309 src += offset; |
| 362 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 310 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 363 for (int x = 0; x < dstWidth; x++) { | 311 for (int x = 0; x < dstWidth; x++) { |
| 364 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); | 312 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); |
| 365 src += deltaSrc; | 313 src += deltaSrc; |
| 366 } | 314 } |
| 367 return SkSwizzler::kOpaque_ResultAlpha; | |
| 368 } | 315 } |
| 369 | 316 |
| 370 // kBGRA | 317 // kBGRA |
| 371 | 318 |
| 372 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( | 319 static void swizzle_bgra_to_n32_unpremul( |
| 373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 320 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 321 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 375 | 322 |
| 376 src += offset; | 323 src += offset; |
| 377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 324 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 378 INIT_RESULT_ALPHA; | |
| 379 for (int x = 0; x < dstWidth; x++) { | 325 for (int x = 0; x < dstWidth; x++) { |
| 380 uint8_t alpha = src[3]; | 326 uint8_t alpha = src[3]; |
| 381 UPDATE_RESULT_ALPHA(alpha); | |
| 382 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | 327 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
| 383 src += deltaSrc; | 328 src += deltaSrc; |
| 384 } | 329 } |
| 385 return COMPUTE_RESULT_ALPHA; | |
| 386 } | 330 } |
| 387 | 331 |
| 388 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( | 332 static void swizzle_bgra_to_n32_premul( |
| 389 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 333 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 390 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 334 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 391 | 335 |
| 392 src += offset; | 336 src += offset; |
| 393 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 337 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 394 INIT_RESULT_ALPHA; | |
| 395 for (int x = 0; x < dstWidth; x++) { | 338 for (int x = 0; x < dstWidth; x++) { |
| 396 uint8_t alpha = src[3]; | 339 uint8_t alpha = src[3]; |
| 397 UPDATE_RESULT_ALPHA(alpha); | |
| 398 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); | 340 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); |
| 399 src += deltaSrc; | 341 src += deltaSrc; |
| 400 } | 342 } |
| 401 return COMPUTE_RESULT_ALPHA; | |
| 402 } | 343 } |
| 403 | 344 |
| 404 // kRGBX | 345 // kRGBX |
| 405 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( | 346 static void swizzle_rgbx_to_n32( |
| 406 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 347 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 407 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 348 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 408 | 349 |
| 409 src += offset; | 350 src += offset; |
| 410 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 351 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 411 for (int x = 0; x < dstWidth; x++) { | 352 for (int x = 0; x < dstWidth; x++) { |
| 412 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 353 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
| 413 src += deltaSrc; | 354 src += deltaSrc; |
| 414 } | 355 } |
| 415 return SkSwizzler::kOpaque_ResultAlpha; | |
| 416 } | 356 } |
| 417 | 357 |
| 418 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( | 358 static void swizzle_rgbx_to_565( |
| 419 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 359 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 420 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 360 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 421 // FIXME: Support dithering? | 361 |
| 422 src += offset; | 362 src += offset; |
| 423 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 363 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 424 for (int x = 0; x < dstWidth; x++) { | 364 for (int x = 0; x < dstWidth; x++) { |
| 425 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 365 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
| 426 src += deltaSrc; | 366 src += deltaSrc; |
| 427 } | 367 } |
| 428 return SkSwizzler::kOpaque_ResultAlpha; | |
| 429 } | 368 } |
| 430 | 369 |
| 431 | 370 |
| 432 // kRGBA | 371 // kRGBA |
| 433 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( | 372 static void swizzle_rgba_to_n32_premul( |
| 434 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 435 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 436 | 375 |
| 437 src += offset; | 376 src += offset; |
| 438 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 439 INIT_RESULT_ALPHA; | |
| 440 for (int x = 0; x < dstWidth; x++) { | 378 for (int x = 0; x < dstWidth; x++) { |
| 441 unsigned alpha = src[3]; | 379 unsigned alpha = src[3]; |
| 442 UPDATE_RESULT_ALPHA(alpha); | |
| 443 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); | 380 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); |
| 444 src += deltaSrc; | 381 src += deltaSrc; |
| 445 } | 382 } |
| 446 return COMPUTE_RESULT_ALPHA; | |
| 447 } | 383 } |
| 448 | 384 |
| 449 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( | 385 static void swizzle_rgba_to_n32_unpremul( |
| 450 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 386 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 451 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 387 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 452 | 388 |
| 453 src += offset; | 389 src += offset; |
| 454 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 390 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| 455 INIT_RESULT_ALPHA; | |
| 456 for (int x = 0; x < dstWidth; x++) { | 391 for (int x = 0; x < dstWidth; x++) { |
| 457 unsigned alpha = src[3]; | 392 unsigned alpha = src[3]; |
| 458 UPDATE_RESULT_ALPHA(alpha); | |
| 459 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 393 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
| 460 src += deltaSrc; | 394 src += deltaSrc; |
| 461 } | 395 } |
| 462 return COMPUTE_RESULT_ALPHA; | |
| 463 } | 396 } |
| 464 | 397 |
| 465 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( | 398 static void swizzle_rgba_to_n32_premul_skipZ( |
| 466 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 399 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 467 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 400 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 468 | 401 |
| 469 src += offset; | 402 src += offset; |
| 470 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 403 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 471 INIT_RESULT_ALPHA; | |
| 472 for (int x = 0; x < dstWidth; x++) { | 404 for (int x = 0; x < dstWidth; x++) { |
| 473 unsigned alpha = src[3]; | 405 unsigned alpha = src[3]; |
| 474 UPDATE_RESULT_ALPHA(alpha); | |
| 475 if (0 != alpha) { | 406 if (0 != alpha) { |
| 476 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); | 407 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); |
| 477 } | 408 } |
| 478 src += deltaSrc; | 409 src += deltaSrc; |
| 479 } | 410 } |
| 480 return COMPUTE_RESULT_ALPHA; | |
| 481 } | 411 } |
| 482 | 412 |
| 483 // kCMYK | 413 // kCMYK |
| 484 // | 414 // |
| 485 // CMYK is stored as four bytes per pixel. | 415 // CMYK is stored as four bytes per pixel. |
| 486 // | 416 // |
| 487 // We will implement a crude conversion from CMYK -> RGB using formulas | 417 // We will implement a crude conversion from CMYK -> RGB using formulas |
| 488 // from easyrgb.com. | 418 // from easyrgb.com. |
| 489 // | 419 // |
| 490 // CMYK -> CMY | 420 // CMYK -> CMY |
| (...skipping 27 matching lines...) Expand all Loading... |
| 518 // B = Y * K * 255 | 448 // B = Y * K * 255 |
| 519 // | 449 // |
| 520 // As a final note, we have treated the CMYK values as if they were on | 450 // As a final note, we have treated the CMYK values as if they were on |
| 521 // a scale from 0-1, when in fact they are 8-bit ints scaling from 0-255. | 451 // a scale from 0-1, when in fact they are 8-bit ints scaling from 0-255. |
| 522 // We must divide each CMYK component by 255 to obtain the true conversion | 452 // We must divide each CMYK component by 255 to obtain the true conversion |
| 523 // we should perform. | 453 // we should perform. |
| 524 // CMYK -> RGB | 454 // CMYK -> RGB |
| 525 // R = C * K / 255 | 455 // R = C * K / 255 |
| 526 // G = M * K / 255 | 456 // G = M * K / 255 |
| 527 // B = Y * K / 255 | 457 // B = Y * K / 255 |
| 528 static SkSwizzler::ResultAlpha swizzle_cmyk_to_n32( | 458 static void swizzle_cmyk_to_n32( |
| 529 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 459 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 530 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 460 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 531 | 461 |
| 532 src += offset; | 462 src += offset; |
| 533 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 463 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 534 for (int x = 0; x < dstWidth; x++) { | 464 for (int x = 0; x < dstWidth; x++) { |
| 535 const uint8_t r = SkMulDiv255Round(src[0], src[3]); | 465 const uint8_t r = SkMulDiv255Round(src[0], src[3]); |
| 536 const uint8_t g = SkMulDiv255Round(src[1], src[3]); | 466 const uint8_t g = SkMulDiv255Round(src[1], src[3]); |
| 537 const uint8_t b = SkMulDiv255Round(src[2], src[3]); | 467 const uint8_t b = SkMulDiv255Round(src[2], src[3]); |
| 538 | 468 |
| 539 dst[x] = SkPackARGB32NoCheck(0xFF, r, g, b); | 469 dst[x] = SkPackARGB32NoCheck(0xFF, r, g, b); |
| 540 src += deltaSrc; | 470 src += deltaSrc; |
| 541 } | 471 } |
| 542 | |
| 543 // CMYK is always opaque | |
| 544 return SkSwizzler::kOpaque_ResultAlpha; | |
| 545 } | 472 } |
| 546 | 473 |
| 547 static SkSwizzler::ResultAlpha swizzle_cmyk_to_565( | 474 static void swizzle_cmyk_to_565( |
| 548 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 475 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 549 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 476 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 550 | 477 |
| 551 src += offset; | 478 src += offset; |
| 552 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 479 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 553 for (int x = 0; x < dstWidth; x++) { | 480 for (int x = 0; x < dstWidth; x++) { |
| 554 const uint8_t r = SkMulDiv255Round(src[0], src[3]); | 481 const uint8_t r = SkMulDiv255Round(src[0], src[3]); |
| 555 const uint8_t g = SkMulDiv255Round(src[1], src[3]); | 482 const uint8_t g = SkMulDiv255Round(src[1], src[3]); |
| 556 const uint8_t b = SkMulDiv255Round(src[2], src[3]); | 483 const uint8_t b = SkMulDiv255Round(src[2], src[3]); |
| 557 | 484 |
| 558 dst[x] = SkPack888ToRGB16(r, g, b); | 485 dst[x] = SkPack888ToRGB16(r, g, b); |
| 559 src += deltaSrc; | 486 src += deltaSrc; |
| 560 } | 487 } |
| 561 | |
| 562 // CMYK is always opaque | |
| 563 return SkSwizzler::kOpaque_ResultAlpha; | |
| 564 } | 488 } |
| 565 | 489 |
| 566 /** | 490 /** |
| 567 FIXME: This was my idea to cheat in order to continue taking advantage of sk
ipping zeroes. | 491 FIXME: This was my idea to cheat in order to continue taking advantage of sk
ipping zeroes. |
| 568 This would be fine for drawing normally, but not for drawing with transfer m
odes. Being | 492 This would be fine for drawing normally, but not for drawing with transfer m
odes. Being |
| 569 honest means we can draw correctly with transfer modes, with the cost of not
being able | 493 honest means we can draw correctly with transfer modes, with the cost of not
being able |
| 570 to take advantage of Android's free unwritten pages. Something to keep in mi
nd when we | 494 to take advantage of Android's free unwritten pages. Something to keep in mi
nd when we |
| 571 decide whether to switch to unpremul default. | 495 decide whether to switch to unpremul default. |
| 572 static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow, | 496 static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow, |
| 573 const uint8_t* SK_RESTRICT src, | 497 const uint8_t* SK_RESTRICT src, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 // way to report failure? | 745 // way to report failure? |
| 822 fSampleX = sampleX; | 746 fSampleX = sampleX; |
| 823 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; | 747 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; |
| 824 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; | 748 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; |
| 825 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); | 749 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); |
| 826 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); | 750 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); |
| 827 | 751 |
| 828 return fAllocatedWidth; | 752 return fAllocatedWidth; |
| 829 } | 753 } |
| 830 | 754 |
| 831 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { | 755 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| 832 SkASSERT(nullptr != dst && nullptr != src); | 756 SkASSERT(nullptr != dst && nullptr != src); |
| 833 return fRowProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth
, fSrcBPP, | 757 fRowProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcB
PP, |
| 834 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 758 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| 835 } | 759 } |
| OLD | NEW |