Chromium Code Reviews| 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 "SkScaledCodec.h" | |
| 10 #include "SkSwizzler.h" | 11 #include "SkSwizzler.h" |
| 11 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
| 12 #include "SkUtils.h" | 13 #include "SkUtils.h" |
| 13 | 14 |
| 14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, | 15 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, |
| 15 uint8_t maxAlpha) { | 16 uint8_t maxAlpha) { |
| 16 // In the transparent case, this returns 0x0000 | 17 // In the transparent case, this returns 0x0000 |
| 17 // In the opaque case, this returns 0xFFFF | 18 // In the opaque case, this returns 0xFFFF |
| 18 // If the row is neither transparent nor opaque, returns something else | 19 // If the row is neither transparent nor opaque, returns something else |
| 19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; | 20 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; |
| 20 } | 21 } |
| 21 | 22 |
| 23 // samples the row. Does not do anything else but sampling | |
| 24 static SkSwizzler::ResultAlpha sample565(void* SK_RESTRICT dstRow, const uint8_t * SK_RESTRICT src, | |
| 25 int width, int deltaSrc, int offset, const SkPMColor ctable[]){ | |
| 26 | |
| 27 src += offset; | |
| 28 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | |
| 29 for (int x = 0; x < width; x++) { | |
| 30 dst[x] = src[1] << 8 | src[0]; | |
| 31 src += deltaSrc; | |
| 32 } | |
| 33 // 565 is always opaque | |
| 34 return SkSwizzler::kOpaque_ResultAlpha; | |
| 35 } | |
| 36 | |
| 22 // kBit | 37 // kBit |
| 23 // These routines exclusively choose between white and black | 38 // These routines exclusively choose between white and black |
| 24 | 39 |
| 25 #define GRAYSCALE_BLACK 0 | 40 #define GRAYSCALE_BLACK 0 |
| 26 #define GRAYSCALE_WHITE 0xFF | 41 #define GRAYSCALE_WHITE 0xFF |
| 27 | 42 |
| 43 | |
| 28 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( | 44 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( |
| 29 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 45 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 30 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { | 46 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { |
| 47 | |
| 31 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 48 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 32 | 49 |
| 33 // Determine how many full bytes are in the row | 50 int x = 0; |
| 34 int bytesInRow = width >> 3; | 51 // increment src by byte offset and bitIndex by bit offset |
| 35 int i; | 52 int byteOffset = offset >> 3; |
| 36 for (i = 0; i < bytesInRow; i++) { | 53 src += byteOffset; |
| 37 U8CPU currByte = src[i]; | 54 int bitIndex = offset - byteOffset * 8; |
| 38 for (int j = 0; j < 8; j++) { | 55 |
| 39 dst[j] = ((currByte >> (7 - j)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_B LACK; | 56 U8CPU currByte = src[0]; |
| 57 int sample = deltaSrc; | |
| 58 | |
| 59 while (x < width) { | |
| 60 if (8 == bitIndex) { | |
| 61 src++; | |
| 62 currByte = *src; | |
| 63 bitIndex = 0; | |
| 40 } | 64 } |
| 41 dst += 8; | 65 if (deltaSrc == sample) { |
| 42 } | 66 dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSC ALE_BLACK; |
| 43 | 67 sample = 0; |
| 44 // Finish the remaining bits | 68 x++; |
| 45 width &= 7; | |
| 46 if (width > 0) { | |
| 47 U8CPU currByte = src[i]; | |
| 48 for (int j = 0; j < width; j++) { | |
| 49 dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; | |
| 50 currByte <<= 1; | |
| 51 } | 69 } |
| 70 sample++; | |
| 71 bitIndex++; | |
| 52 } | 72 } |
| 53 return SkSwizzler::kOpaque_ResultAlpha; | 73 return SkSwizzler::kOpaque_ResultAlpha; |
| 54 } | 74 } |
| 55 | 75 |
| 56 #undef GRAYSCALE_BLACK | 76 #undef GRAYSCALE_BLACK |
| 57 #undef GRAYSCALE_WHITE | 77 #undef GRAYSCALE_WHITE |
| 58 | 78 |
| 59 static SkSwizzler::ResultAlpha swizzle_bit_to_index( | 79 static SkSwizzler::ResultAlpha swizzle_bit_to_index( |
| 60 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 80 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 61 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { | 81 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { |
| 62 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 82 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 63 | 83 |
| 64 // Determine how many full bytes are in the row | 84 int x = 0; |
|
scroggo
2015/08/11 21:33:30
nit: x is defined several lines before it's used.
| |
| 65 int bytesInRow = width >> 3; | 85 // increment src by byte offset and bitIndex by bit offset |
| 66 int i; | 86 int byteOffset = offset >> 3; |
| 67 for (i = 0; i < bytesInRow; i++) { | 87 src += byteOffset; |
| 68 U8CPU currByte = src[i]; | 88 int bitIndex = offset - byteOffset * 8; |
| 69 for (int j = 0; j < 8; j++) { | 89 |
| 70 dst[j] = (currByte >> (7 - j)) & 1; | 90 U8CPU currByte = src[0]; |
| 91 int sample = deltaSrc; | |
| 92 | |
| 93 while (x < width) { | |
| 94 if (8 == bitIndex) { | |
| 95 src++; | |
| 96 currByte = *src; | |
| 97 bitIndex = 0; | |
| 71 } | 98 } |
| 72 dst += 8; | 99 if (deltaSrc == sample) { |
|
scroggo
2015/08/11 21:33:30
Ok, I think I understand this code: we basically l
emmaleer
2015/08/12 14:04:33
I don't think that way would work, or maybe I'm no
scroggo
2015/08/12 14:35:22
Similar to the first calculation of bitIndex - usi
msarett
2015/08/12 14:37:41
Emmalee and I revised this function in person to t
| |
| 73 } | 100 dst[x] = ((currByte >> (7-bitIndex)) & 1); |
| 74 | 101 sample = 0; |
| 75 // Finish the remaining bits | 102 x++; |
| 76 width &= 7; | |
| 77 if (width > 0) { | |
| 78 U8CPU currByte = src[i]; | |
| 79 for (int j = 0; j < width; j++) { | |
| 80 dst[j] = ((currByte >> 7) & 1); | |
| 81 currByte <<= 1; | |
| 82 } | 103 } |
| 104 sample++; | |
| 105 bitIndex++; | |
| 83 } | 106 } |
| 84 return SkSwizzler::kOpaque_ResultAlpha; | 107 return SkSwizzler::kOpaque_ResultAlpha; |
| 85 } | 108 } |
| 86 | 109 |
| 110 | |
| 87 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( | 111 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( |
| 88 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 112 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 89 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { | 113 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { |
| 90 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | 114 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
| 91 | 115 |
| 92 // Determine how many full bytes are in the row | 116 int x = 0; |
| 93 int bytesInRow = width >> 3; | 117 // increment src by byte offset and bitIndex by bit offset |
| 94 int i; | 118 int byteOffset = offset >> 3; |
| 95 for (i = 0; i < bytesInRow; i++) { | 119 src += byteOffset; |
| 96 U8CPU currByte = src[i]; | 120 int bitIndex = offset - byteOffset * 8; |
| 97 for (int j = 0; j < 8; j++) { | 121 |
| 98 dst[j] = ((currByte >> (7 - j)) & 1) ? SK_ColorWHITE : SK_ColorBLACK ; | 122 U8CPU currByte = src[0]; |
| 123 int sample = deltaSrc; | |
| 124 | |
| 125 while (x < width) { | |
| 126 if (8 == bitIndex) { | |
| 127 src++; | |
| 128 currByte = *src; | |
| 129 bitIndex = 0; | |
| 99 } | 130 } |
| 100 dst += 8; | 131 if (deltaSrc == sample) { |
| 101 } | 132 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_Col orBLACK; |
| 102 | 133 sample = 0; |
| 103 // Finish the remaining bits | 134 x++; |
| 104 width &= 7; | |
| 105 if (width > 0) { | |
| 106 U8CPU currByte = src[i]; | |
| 107 for (int j = 0; j < width; j++) { | |
| 108 dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; | |
| 109 currByte <<= 1; | |
| 110 } | 135 } |
| 136 sample++; | |
| 137 bitIndex++; | |
| 111 } | 138 } |
| 112 return SkSwizzler::kOpaque_ResultAlpha; | 139 return SkSwizzler::kOpaque_ResultAlpha; |
| 113 } | 140 } |
| 114 | 141 |
| 115 // kIndex1, kIndex2, kIndex4 | 142 // kIndex1, kIndex2, kIndex4 |
| 116 | 143 |
| 117 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( | 144 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
| 118 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 145 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 119 int bitsPerPixel, const SkPMColor ctable[]) { | 146 int bitsPerPixel, int offset, const SkPMColor ctable[]) { |
| 120 | 147 |
| 148 src += offset; | |
| 121 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 149 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 122 INIT_RESULT_ALPHA; | 150 INIT_RESULT_ALPHA; |
| 123 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 151 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| 124 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); | 152 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); |
| 125 const uint8_t mask = (1 << bitsPerPixel) - 1; | 153 const uint8_t mask = (1 << bitsPerPixel) - 1; |
| 126 int x = 0; | 154 int x = 0; |
| 127 for (uint32_t byte = 0; byte < rowBytes; byte++) { | 155 for (uint32_t byte = 0; byte < rowBytes; byte++) { |
| 128 uint8_t pixelData = src[byte]; | 156 uint8_t pixelData = src[byte]; |
| 129 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { | 157 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { |
| 130 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | 158 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; |
| 131 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); | 159 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); |
| 132 dst[x] = index; | 160 dst[x] = index; |
| 133 pixelData <<= bitsPerPixel; | 161 pixelData <<= bitsPerPixel; |
| 134 x++; | 162 x++; |
| 135 } | 163 } |
| 136 } | 164 } |
| 137 return COMPUTE_RESULT_ALPHA; | 165 return COMPUTE_RESULT_ALPHA; |
| 138 } | 166 } |
| 139 | 167 |
| 140 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( | 168 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( |
| 141 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 169 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 142 int bitsPerPixel, const SkPMColor ctable[]) { | 170 int bitsPerPixel, int offset, const SkPMColor ctable[]) { |
| 143 | 171 |
| 172 src += offset; | |
| 144 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | 173 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
| 145 INIT_RESULT_ALPHA; | 174 INIT_RESULT_ALPHA; |
| 146 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 175 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| 147 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); | 176 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); |
| 148 const uint8_t mask = (1 << bitsPerPixel) - 1; | 177 const uint8_t mask = (1 << bitsPerPixel) - 1; |
| 149 int x = 0; | 178 int x = 0; |
| 150 for (uint32_t byte = 0; byte < rowBytes; byte++) { | 179 for (uint32_t byte = 0; byte < rowBytes; byte++) { |
| 151 uint8_t pixelData = src[byte]; | 180 uint8_t pixelData = src[byte]; |
| 152 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { | 181 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { |
| 153 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | 182 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; |
| 154 SkPMColor c = ctable[index]; | 183 SkPMColor c = ctable[index]; |
| 155 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 184 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
| 156 dst[x] = c; | 185 dst[x] = c; |
| 157 pixelData <<= bitsPerPixel; | 186 pixelData <<= bitsPerPixel; |
| 158 x++; | 187 x++; |
| 159 } | 188 } |
| 160 } | 189 } |
| 161 return COMPUTE_RESULT_ALPHA; | 190 return COMPUTE_RESULT_ALPHA; |
| 162 } | 191 } |
| 163 | 192 |
| 164 // kIndex | 193 // kIndex |
| 165 | 194 |
| 166 static SkSwizzler::ResultAlpha swizzle_index_to_index( | 195 static SkSwizzler::ResultAlpha swizzle_index_to_index( |
| 167 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 196 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 168 int bytesPerPixel, const SkPMColor ctable[]) { | 197 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 169 | 198 |
| 199 src += offset; | |
| 170 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 200 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 171 memcpy(dst, src, width); | 201 if (1 == deltaSrc) { |
| 202 memcpy(dst, src, width); | |
| 203 } else { | |
| 204 for (int x = 0; x < width; x++) { | |
| 205 dst[x] = src[0]; | |
| 206 src += deltaSrc; | |
| 207 } | |
| 208 } | |
| 172 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? | 209 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? |
| 173 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous | 210 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous |
| 174 // and probably wrong since gif and bmp (rarely) may have al pha. | 211 // and probably wrong since gif and bmp (rarely) may have al pha. |
| 175 INIT_RESULT_ALPHA; | 212 INIT_RESULT_ALPHA; |
| 176 for (int x = 0; x < width; x++) { | 213 for (int x = 0; x < width; x++) { |
| 177 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); | 214 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); |
| 178 } | 215 } |
| 179 return COMPUTE_RESULT_ALPHA; | 216 return COMPUTE_RESULT_ALPHA; |
| 180 } | 217 } |
| 181 | 218 |
| 182 static SkSwizzler::ResultAlpha swizzle_index_to_n32( | 219 static SkSwizzler::ResultAlpha swizzle_index_to_n32( |
| 183 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 220 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 184 int bytesPerPixel, const SkPMColor ctable[]) { | 221 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 185 | 222 |
| 223 src += offset; | |
| 186 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 224 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 187 INIT_RESULT_ALPHA; | 225 INIT_RESULT_ALPHA; |
| 188 for (int x = 0; x < width; x++) { | 226 for (int x = 0; x < width; x++) { |
| 189 SkPMColor c = ctable[src[x]]; | 227 SkPMColor c = ctable[*src]; |
| 190 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 228 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
| 191 dst[x] = c; | 229 dst[x] = c; |
| 230 src += deltaSrc; | |
| 192 } | 231 } |
| 193 return COMPUTE_RESULT_ALPHA; | 232 return COMPUTE_RESULT_ALPHA; |
| 194 } | 233 } |
| 195 | 234 |
| 196 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( | 235 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( |
| 197 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 236 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 198 int bytesPerPixel, const SkPMColor ctable[]) { | 237 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 199 | 238 |
| 239 src += offset; | |
| 200 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 240 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 201 INIT_RESULT_ALPHA; | 241 INIT_RESULT_ALPHA; |
| 202 for (int x = 0; x < width; x++) { | 242 for (int x = 0; x < width; x++) { |
| 203 SkPMColor c = ctable[src[x]]; | 243 SkPMColor c = ctable[*src]; |
| 204 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 244 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
| 205 if (c != 0) { | 245 if (c != 0) { |
| 206 dst[x] = c; | 246 dst[x] = c; |
| 207 } | 247 } |
| 248 src += deltaSrc; | |
| 208 } | 249 } |
| 209 return COMPUTE_RESULT_ALPHA; | 250 return COMPUTE_RESULT_ALPHA; |
| 210 } | 251 } |
| 211 | 252 |
| 212 static SkSwizzler::ResultAlpha swizzle_index_to_565( | 253 static SkSwizzler::ResultAlpha swizzle_index_to_565( |
| 213 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 254 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 214 int bytesPerPixel, const SkPMColor ctable[]) { | 255 int bytesPerPixel, int offset, const SkPMColor ctable[]) { |
| 215 // FIXME: Support dithering? Requires knowing y, which I think is a bigger | 256 // FIXME: Support dithering? Requires knowing y, which I think is a bigger |
| 216 // change. | 257 // change. |
| 258 src += offset; | |
| 217 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 259 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 218 for (int x = 0; x < width; x++) { | 260 for (int x = 0; x < width; x++) { |
| 219 dst[x] = SkPixel32ToPixel16(ctable[*src]); | 261 dst[x] = SkPixel32ToPixel16(ctable[*src]); |
| 220 src += bytesPerPixel; | 262 src += bytesPerPixel; |
| 221 } | 263 } |
| 222 return SkSwizzler::kOpaque_ResultAlpha; | 264 return SkSwizzler::kOpaque_ResultAlpha; |
| 223 } | 265 } |
| 224 | 266 |
| 225 | 267 |
| 226 #undef A32_MASK_IN_PLACE | 268 #undef A32_MASK_IN_PLACE |
| 227 | 269 |
| 228 // kGray | 270 // kGray |
| 229 | 271 |
| 230 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( | 272 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( |
| 231 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 273 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 232 int bytesPerPixel, const SkPMColor ctable[]) { | 274 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 233 | 275 |
| 276 src += offset; | |
| 234 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 277 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 235 for (int x = 0; x < width; x++) { | 278 for (int x = 0; x < width; x++) { |
| 236 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]); | 279 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); |
| 280 src += deltaSrc; | |
| 237 } | 281 } |
| 238 return SkSwizzler::kOpaque_ResultAlpha; | 282 return SkSwizzler::kOpaque_ResultAlpha; |
| 239 } | 283 } |
| 240 | 284 |
| 241 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( | 285 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( |
| 242 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 286 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 243 int bytesPerPixel, const SkPMColor ctable[]) { | 287 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 244 memcpy(dstRow, src, width); | 288 |
| 289 src += offset; | |
| 290 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | |
| 291 if (1 == deltaSrc) { | |
| 292 memcpy(dstRow, src, width); | |
| 293 } else { | |
| 294 for (int x = 0; x < width; x++) { | |
| 295 dst[x] = src[0]; | |
| 296 src += deltaSrc; | |
| 297 } | |
| 298 } | |
| 245 return SkSwizzler::kOpaque_ResultAlpha; | 299 return SkSwizzler::kOpaque_ResultAlpha; |
| 246 } | 300 } |
| 247 | 301 |
| 248 static SkSwizzler::ResultAlpha swizzle_gray_to_565( | 302 static SkSwizzler::ResultAlpha swizzle_gray_to_565( |
| 249 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 303 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 250 int bytesPerPixel, const SkPMColor ctable[]) { | 304 int bytesPerPixel, int offset, const SkPMColor ctable[]) { |
| 251 // FIXME: Support dithering? | 305 // FIXME: Support dithering? |
| 306 src += offset; | |
| 252 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 307 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 253 for (int x = 0; x < width; x++) { | 308 for (int x = 0; x < width; x++) { |
| 254 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); | 309 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); |
| 255 src += bytesPerPixel; | 310 src += bytesPerPixel; |
| 256 } | 311 } |
| 257 return SkSwizzler::kOpaque_ResultAlpha; | 312 return SkSwizzler::kOpaque_ResultAlpha; |
| 258 } | 313 } |
| 259 | 314 |
| 260 // kBGRX | 315 // kBGRX |
| 261 | 316 |
| 262 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( | 317 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
| 263 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 318 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 264 int bytesPerPixel, const SkPMColor ctable[]) { | 319 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 265 | 320 |
| 321 src += offset; | |
| 266 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 322 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 267 for (int x = 0; x < width; x++) { | 323 for (int x = 0; x < width; x++) { |
| 268 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 324 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
| 269 src += bytesPerPixel; | 325 src += deltaSrc; |
| 270 } | 326 } |
| 271 return SkSwizzler::kOpaque_ResultAlpha; | 327 return SkSwizzler::kOpaque_ResultAlpha; |
| 272 } | 328 } |
| 273 | 329 |
| 274 // kBGRA | 330 // kBGRA |
| 275 | 331 |
| 276 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( | 332 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
| 277 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 333 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 278 int bytesPerPixel, const SkPMColor ctable[]) { | 334 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 279 | 335 |
| 336 src += offset; | |
| 280 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 337 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 281 INIT_RESULT_ALPHA; | 338 INIT_RESULT_ALPHA; |
| 282 for (int x = 0; x < width; x++) { | 339 for (int x = 0; x < width; x++) { |
| 283 uint8_t alpha = src[3]; | 340 uint8_t alpha = src[3]; |
| 284 UPDATE_RESULT_ALPHA(alpha); | 341 UPDATE_RESULT_ALPHA(alpha); |
| 285 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | 342 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
| 286 src += bytesPerPixel; | 343 src += deltaSrc; |
| 287 } | 344 } |
| 288 return COMPUTE_RESULT_ALPHA; | 345 return COMPUTE_RESULT_ALPHA; |
| 289 } | 346 } |
| 290 | 347 |
| 291 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( | 348 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
| 292 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 349 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 293 int bytesPerPixel, const SkPMColor ctable[]) { | 350 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 294 | 351 |
| 352 src += offset; | |
| 295 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 353 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 296 INIT_RESULT_ALPHA; | 354 INIT_RESULT_ALPHA; |
| 297 for (int x = 0; x < width; x++) { | 355 for (int x = 0; x < width; x++) { |
| 298 uint8_t alpha = src[3]; | 356 uint8_t alpha = src[3]; |
| 299 UPDATE_RESULT_ALPHA(alpha); | 357 UPDATE_RESULT_ALPHA(alpha); |
| 300 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); | 358 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); |
| 301 src += bytesPerPixel; | 359 src += deltaSrc; |
| 302 } | 360 } |
| 303 return COMPUTE_RESULT_ALPHA; | 361 return COMPUTE_RESULT_ALPHA; |
| 304 } | 362 } |
| 305 | 363 |
| 306 // kRGBX | 364 // kRGBX |
| 307 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( | 365 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
| 308 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 366 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 309 int bytesPerPixel, const SkPMColor ctable[]) { | 367 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 310 | 368 |
| 369 src += offset; | |
| 311 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 370 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 312 for (int x = 0; x < width; x++) { | 371 for (int x = 0; x < width; x++) { |
| 313 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 372 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
| 314 src += bytesPerPixel; | 373 src += deltaSrc; |
| 315 } | 374 } |
| 316 return SkSwizzler::kOpaque_ResultAlpha; | 375 return SkSwizzler::kOpaque_ResultAlpha; |
| 317 } | 376 } |
| 318 | 377 |
| 319 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( | 378 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( |
| 320 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 379 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 321 int bytesPerPixel, const SkPMColor ctable[]) { | 380 int bytesPerPixel, int offset, const SkPMColor ctable[]) { |
| 322 // FIXME: Support dithering? | 381 // FIXME: Support dithering? |
| 382 src += offset; | |
| 323 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 383 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 324 for (int x = 0; x < width; x++) { | 384 for (int x = 0; x < width; x++) { |
| 325 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 385 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
| 326 src += bytesPerPixel; | 386 src += bytesPerPixel; |
| 327 } | 387 } |
| 328 return SkSwizzler::kOpaque_ResultAlpha; | 388 return SkSwizzler::kOpaque_ResultAlpha; |
| 329 } | 389 } |
| 330 | 390 |
| 331 | 391 |
| 332 // kRGBA | 392 // kRGBA |
| 333 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( | 393 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( |
| 334 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 394 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 335 int bytesPerPixel, const SkPMColor ctable[]) { | 395 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 336 | 396 |
| 397 src += offset; | |
| 337 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 398 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 338 INIT_RESULT_ALPHA; | 399 INIT_RESULT_ALPHA; |
| 339 for (int x = 0; x < width; x++) { | 400 for (int x = 0; x < width; x++) { |
| 340 unsigned alpha = src[3]; | 401 unsigned alpha = src[3]; |
| 341 UPDATE_RESULT_ALPHA(alpha); | 402 UPDATE_RESULT_ALPHA(alpha); |
| 342 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); | 403 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
| 343 src += bytesPerPixel; | 404 src += deltaSrc; |
| 344 } | 405 } |
| 345 return COMPUTE_RESULT_ALPHA; | 406 return COMPUTE_RESULT_ALPHA; |
| 346 } | 407 } |
| 347 | 408 |
| 348 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( | 409 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( |
| 349 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 410 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 350 int bytesPerPixel, const SkPMColor ctable[]) { | 411 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 351 | 412 |
| 413 src += offset; | |
| 352 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 414 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| 353 INIT_RESULT_ALPHA; | 415 INIT_RESULT_ALPHA; |
| 354 for (int x = 0; x < width; x++) { | 416 for (int x = 0; x < width; x++) { |
| 355 unsigned alpha = src[3]; | 417 unsigned alpha = src[3]; |
| 356 UPDATE_RESULT_ALPHA(alpha); | 418 UPDATE_RESULT_ALPHA(alpha); |
| 357 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 419 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
| 358 src += bytesPerPixel; | 420 src += deltaSrc; |
| 359 } | 421 } |
| 360 return COMPUTE_RESULT_ALPHA; | 422 return COMPUTE_RESULT_ALPHA; |
| 361 } | 423 } |
| 362 | 424 |
| 363 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( | 425 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( |
| 364 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 426 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 365 int bytesPerPixel, const SkPMColor ctable[]) { | 427 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 366 | 428 |
| 429 src += offset; | |
| 367 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 430 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 368 INIT_RESULT_ALPHA; | 431 INIT_RESULT_ALPHA; |
| 369 for (int x = 0; x < width; x++) { | 432 for (int x = 0; x < width; x++) { |
| 370 unsigned alpha = src[3]; | 433 unsigned alpha = src[3]; |
| 371 UPDATE_RESULT_ALPHA(alpha); | 434 UPDATE_RESULT_ALPHA(alpha); |
| 372 if (0 != alpha) { | 435 if (0 != alpha) { |
| 373 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); | 436 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
| 374 } | 437 } |
| 375 src += bytesPerPixel; | 438 src += deltaSrc; |
| 376 } | 439 } |
| 377 return COMPUTE_RESULT_ALPHA; | 440 return COMPUTE_RESULT_ALPHA; |
| 378 } | 441 } |
| 379 | 442 |
| 380 /** | 443 /** |
| 381 FIXME: This was my idea to cheat in order to continue taking advantage of sk ipping zeroes. | 444 FIXME: This was my idea to cheat in order to continue taking advantage of sk ipping zeroes. |
| 382 This would be fine for drawing normally, but not for drawing with transfer m odes. Being | 445 This would be fine for drawing normally, but not for drawing with transfer m odes. Being |
| 383 honest means we can draw correctly with transfer modes, with the cost of not being able | 446 honest means we can draw correctly with transfer modes, with the cost of not being able |
| 384 to take advantage of Android's free unwritten pages. Something to keep in mi nd when we | 447 to take advantage of Android's free unwritten pages. Something to keep in mi nd when we |
| 385 decide whether to switch to unpremul default. | 448 decide whether to switch to unpremul default. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 399 } | 462 } |
| 400 src += deltaSrc; | 463 src += deltaSrc; |
| 401 alphaMask &= alpha; | 464 alphaMask &= alpha; |
| 402 } | 465 } |
| 403 return alphaMask != 0xFF; | 466 return alphaMask != 0xFF; |
| 404 } | 467 } |
| 405 */ | 468 */ |
| 406 | 469 |
| 407 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, | 470 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| 408 const SkPMColor* ctable, | 471 const SkPMColor* ctable, |
| 409 const SkImageInfo& info, | 472 const SkImageInfo& dstInfo, |
| 410 SkCodec::ZeroInitialized zeroInit) { | 473 SkCodec::ZeroInitialized zeroInit, |
| 411 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 474 int srcWidth) { |
| 475 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | |
| 412 return NULL; | 476 return NULL; |
| 413 } | 477 } |
| 414 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 478 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
| 415 && NULL == ctable) { | 479 && NULL == ctable) { |
| 416 return NULL; | 480 return NULL; |
| 417 } | 481 } |
| 418 RowProc proc = NULL; | 482 RowProc proc = NULL; |
| 483 | |
| 419 switch (sc) { | 484 switch (sc) { |
| 420 case kBit: | 485 case kBit: |
| 421 switch (info.colorType()) { | 486 switch (dstInfo.colorType()) { |
| 422 case kN32_SkColorType: | 487 case kN32_SkColorType: |
| 423 proc = &swizzle_bit_to_n32; | 488 proc = &swizzle_bit_to_n32; |
| 424 break; | 489 break; |
| 425 case kIndex_8_SkColorType: | 490 case kIndex_8_SkColorType: |
| 426 proc = &swizzle_bit_to_index; | 491 proc = &swizzle_bit_to_index; |
| 427 break; | 492 break; |
| 428 case kGray_8_SkColorType: | 493 case kGray_8_SkColorType: |
| 429 proc = &swizzle_bit_to_grayscale; | 494 proc = &swizzle_bit_to_grayscale; |
| 430 break; | 495 break; |
| 431 default: | 496 default: |
| 432 break; | 497 break; |
| 433 } | 498 } |
| 434 break; | 499 break; |
| 435 case kIndex1: | 500 case kIndex1: |
| 436 case kIndex2: | 501 case kIndex2: |
| 437 case kIndex4: | 502 case kIndex4: |
| 438 switch (info.colorType()) { | 503 switch (dstInfo.colorType()) { |
| 439 case kN32_SkColorType: | 504 case kN32_SkColorType: |
| 440 proc = &swizzle_small_index_to_n32; | 505 proc = &swizzle_small_index_to_n32; |
| 441 break; | 506 break; |
| 442 case kIndex_8_SkColorType: | 507 case kIndex_8_SkColorType: |
| 443 proc = &swizzle_small_index_to_index; | 508 proc = &swizzle_small_index_to_index; |
| 444 break; | 509 break; |
| 445 default: | 510 default: |
| 446 break; | 511 break; |
| 447 } | 512 } |
| 448 break; | 513 break; |
| 449 case kIndex: | 514 case kIndex: |
| 450 switch (info.colorType()) { | 515 switch (dstInfo.colorType()) { |
| 451 case kN32_SkColorType: | 516 case kN32_SkColorType: |
| 452 // We assume the color premultiplied ctable (or not) as desi red. | 517 // We assume the color premultiplied ctable (or not) as desi red. |
| 453 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 518 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 454 proc = &swizzle_index_to_n32_skipZ; | 519 proc = &swizzle_index_to_n32_skipZ; |
| 455 break; | 520 break; |
| 456 } else { | 521 } else { |
| 457 proc = &swizzle_index_to_n32; | 522 proc = &swizzle_index_to_n32; |
| 458 break; | 523 break; |
| 459 } | 524 } |
| 460 break; | 525 break; |
| 461 case kRGB_565_SkColorType: | 526 case kRGB_565_SkColorType: |
| 462 proc = &swizzle_index_to_565; | 527 proc = &swizzle_index_to_565; |
| 463 break; | 528 break; |
| 464 case kIndex_8_SkColorType: | 529 case kIndex_8_SkColorType: |
| 465 proc = &swizzle_index_to_index; | 530 proc = &swizzle_index_to_index; |
| 466 break; | 531 break; |
| 467 default: | 532 default: |
| 468 break; | 533 break; |
| 469 } | 534 } |
| 470 break; | 535 break; |
| 471 case kGray: | 536 case kGray: |
| 472 switch (info.colorType()) { | 537 switch (dstInfo.colorType()) { |
| 473 case kN32_SkColorType: | 538 case kN32_SkColorType: |
| 474 proc = &swizzle_gray_to_n32; | 539 proc = &swizzle_gray_to_n32; |
| 475 break; | 540 break; |
| 476 case kGray_8_SkColorType: | 541 case kGray_8_SkColorType: |
| 477 proc = &swizzle_gray_to_gray; | 542 proc = &swizzle_gray_to_gray; |
| 478 break; | 543 break; |
| 479 case kRGB_565_SkColorType: | 544 case kRGB_565_SkColorType: |
| 480 proc = &swizzle_gray_to_565; | 545 proc = &swizzle_gray_to_565; |
| 481 break; | 546 break; |
| 482 default: | 547 default: |
| 483 break; | 548 break; |
| 484 } | 549 } |
| 485 break; | 550 break; |
| 486 case kBGR: | 551 case kBGR: |
| 487 case kBGRX: | 552 case kBGRX: |
| 488 switch (info.colorType()) { | 553 switch (dstInfo.colorType()) { |
| 489 case kN32_SkColorType: | 554 case kN32_SkColorType: |
| 490 proc = &swizzle_bgrx_to_n32; | 555 proc = &swizzle_bgrx_to_n32; |
| 491 break; | 556 break; |
| 492 default: | 557 default: |
| 493 break; | 558 break; |
| 494 } | 559 } |
| 495 break; | 560 break; |
| 496 case kBGRA: | 561 case kBGRA: |
| 497 switch (info.colorType()) { | 562 switch (dstInfo.colorType()) { |
| 498 case kN32_SkColorType: | 563 case kN32_SkColorType: |
| 499 switch (info.alphaType()) { | 564 switch (dstInfo.alphaType()) { |
| 500 case kUnpremul_SkAlphaType: | 565 case kUnpremul_SkAlphaType: |
| 501 proc = &swizzle_bgra_to_n32_unpremul; | 566 proc = &swizzle_bgra_to_n32_unpremul; |
| 502 break; | 567 break; |
| 503 case kPremul_SkAlphaType: | 568 case kPremul_SkAlphaType: |
| 504 proc = &swizzle_bgra_to_n32_premul; | 569 proc = &swizzle_bgra_to_n32_premul; |
| 505 break; | 570 break; |
| 506 default: | 571 default: |
| 507 break; | 572 break; |
| 508 } | 573 } |
| 509 break; | 574 break; |
| 510 default: | 575 default: |
| 511 break; | 576 break; |
| 512 } | 577 } |
| 513 break; | 578 break; |
| 514 case kRGBX: | 579 case kRGBX: |
| 515 // TODO: Support other swizzles. | 580 // TODO: Support other swizzles. |
| 516 switch (info.colorType()) { | 581 switch (dstInfo.colorType()) { |
| 517 case kN32_SkColorType: | 582 case kN32_SkColorType: |
| 518 proc = &swizzle_rgbx_to_n32; | 583 proc = &swizzle_rgbx_to_n32; |
| 519 break; | 584 break; |
| 520 case kRGB_565_SkColorType: | 585 case kRGB_565_SkColorType: |
| 521 proc = &swizzle_rgbx_to_565; | 586 proc = &swizzle_rgbx_to_565; |
| 522 default: | 587 default: |
| 523 break; | 588 break; |
| 524 } | 589 } |
| 525 break; | 590 break; |
| 526 case kRGBA: | 591 case kRGBA: |
| 527 switch (info.colorType()) { | 592 switch (dstInfo.colorType()) { |
| 528 case kN32_SkColorType: | 593 case kN32_SkColorType: |
| 529 if (info.alphaType() == kUnpremul_SkAlphaType) { | 594 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 530 // Respect zeroInit? | 595 // Respect zeroInit? |
| 531 proc = &swizzle_rgba_to_n32_unpremul; | 596 proc = &swizzle_rgba_to_n32_unpremul; |
| 532 } else { | 597 } else { |
| 533 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 598 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 534 proc = &swizzle_rgba_to_n32_premul_skipZ; | 599 proc = &swizzle_rgba_to_n32_premul_skipZ; |
| 535 } else { | 600 } else { |
| 536 proc = &swizzle_rgba_to_n32_premul; | 601 proc = &swizzle_rgba_to_n32_premul; |
| 537 } | 602 } |
| 538 } | 603 } |
| 539 break; | 604 break; |
| 540 default: | 605 default: |
| 541 break; | 606 break; |
| 542 } | 607 } |
| 543 break; | 608 break; |
| 544 case kRGB: | 609 case kRGB: |
| 545 switch (info.colorType()) { | 610 switch (dstInfo.colorType()) { |
| 546 case kN32_SkColorType: | 611 case kN32_SkColorType: |
| 547 proc = &swizzle_rgbx_to_n32; | 612 proc = &swizzle_rgbx_to_n32; |
| 548 break; | 613 break; |
| 549 default: | 614 default: |
| 550 break; | 615 break; |
| 551 } | 616 } |
| 552 break; | 617 break; |
| 618 case kRGB_565: | |
| 619 switch (dstInfo.colorType()) { | |
| 620 case kRGB_565_SkColorType: | |
| 621 proc = &sample565; | |
| 622 break; | |
| 623 default: | |
| 624 break; | |
| 625 } | |
| 553 default: | 626 default: |
| 554 break; | 627 break; |
| 555 } | 628 } |
| 556 if (NULL == proc) { | 629 if (NULL == proc) { |
| 557 return NULL; | 630 return NULL; |
| 558 } | 631 } |
| 559 | 632 |
| 560 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits | 633 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits |
| 561 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : | 634 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix el(sc); |
| 562 BitsPerPixel(sc); | 635 |
| 563 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info)); | 636 int sampleX = SkScaledCodec::GetSampleSize(srcWidth, dstInfo.width()); |
| 637 | |
| 638 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, dstInfo, sampleX)); | |
| 564 } | 639 } |
| 565 | 640 |
| 566 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, | 641 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
| 567 int deltaSrc, const SkImageInfo& info) | 642 int deltaSrc, const SkImageInfo& info, int sampleX) |
| 568 : fRowProc(proc) | 643 : fRowProc(proc) |
| 569 , fColorTable(ctable) | 644 , fColorTable(ctable) |
| 570 , fDeltaSrc(deltaSrc) | 645 , fDeltaSrc(deltaSrc) |
| 571 , fDstInfo(info) | 646 , fDstInfo(info) |
| 572 {} | 647 , fSampleX(sampleX) |
| 648 , fX0(sampleX == 1 ? 0 : sampleX >> 1) | |
| 649 { | |
| 650 // check that fX0 is less than original width | |
| 651 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); | |
| 652 } | |
| 573 | 653 |
| 574 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { | 654 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { |
| 575 SkASSERT(NULL != dst && NULL != src); | 655 SkASSERT(NULL != dst && NULL != src); |
| 576 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fColorTable); | 656 return fRowProc(dst, src, fDstInfo.width(), fSampleX * fDeltaSrc, fX0 * fDel taSrc, fColorTable); |
| 577 } | 657 } |
| 578 | 658 |
| 579 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, | 659 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, |
| 580 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { | 660 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { |
| 581 SkASSERT(dstStartRow != NULL); | 661 SkASSERT(dstStartRow != NULL); |
| 582 SkASSERT(numRows <= (uint32_t) dstInfo.height()); | 662 SkASSERT(numRows <= (uint32_t) dstInfo.height()); |
| 583 | 663 |
| 584 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. | 664 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. |
| 585 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes); | 665 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes); |
| 586 | 666 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 // bits of SK_ColorBLACK are identical to the 565 representation | 715 // bits of SK_ColorBLACK are identical to the 565 representation |
| 636 // for black. | 716 // for black. |
| 637 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); | 717 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); |
| 638 break; | 718 break; |
| 639 default: | 719 default: |
| 640 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 720 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
| 641 SkASSERT(false); | 721 SkASSERT(false); |
| 642 break; | 722 break; |
| 643 } | 723 } |
| 644 } | 724 } |
| OLD | NEW |