msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkCodecPriv.h" |
| 9 | #include "SkColorPriv.h" |
| 10 | #include "SkMaskSwizzler.h" |
| 11 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 12 | static void swizzle_mask16_to_n32_opaque( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 13 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 14 | uint32_t startX, uint32_t sampleX) { |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 15 | |
| 16 | // Use the masks to decode to the destination |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 17 | uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 18 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
| 19 | for (int i = 0; i < width; i++) { |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 20 | uint16_t p = srcPtr[0]; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 21 | uint8_t red = masks->getRed(p); |
| 22 | uint8_t green = masks->getGreen(p); |
| 23 | uint8_t blue = masks->getBlue(p); |
| 24 | dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 25 | srcPtr += sampleX; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 26 | } |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 27 | } |
| 28 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 29 | static void swizzle_mask16_to_n32_unpremul( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 30 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 31 | uint32_t startX, uint32_t sampleX) { |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 32 | |
| 33 | // Use the masks to decode to the destination |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 34 | uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 35 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 36 | for (int i = 0; i < width; i++) { |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 37 | uint16_t p = srcPtr[0]; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 38 | uint8_t red = masks->getRed(p); |
| 39 | uint8_t green = masks->getGreen(p); |
| 40 | uint8_t blue = masks->getBlue(p); |
| 41 | uint8_t alpha = masks->getAlpha(p); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 42 | dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 43 | srcPtr += sampleX; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 44 | } |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 45 | } |
| 46 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 47 | static void swizzle_mask16_to_n32_premul( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 48 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 49 | uint32_t startX, uint32_t sampleX) { |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 50 | |
| 51 | // Use the masks to decode to the destination |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 52 | uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 53 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 54 | for (int i = 0; i < width; i++) { |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 55 | uint16_t p = srcPtr[0]; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 56 | uint8_t red = masks->getRed(p); |
| 57 | uint8_t green = masks->getGreen(p); |
| 58 | uint8_t blue = masks->getBlue(p); |
| 59 | uint8_t alpha = masks->getAlpha(p); |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 60 | dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 61 | srcPtr += sampleX; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 62 | } |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 63 | } |
| 64 | |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 65 | // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to |
| 66 | // convert it back to 565. Instead, we should swizzle to 565 directly. |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 67 | static void swizzle_mask16_to_565( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 68 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 69 | uint32_t startX, uint32_t sampleX) { |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 70 | |
| 71 | // Use the masks to decode to the destination |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 72 | uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 73 | uint16_t* dstPtr = (uint16_t*) dstRow; |
| 74 | for (int i = 0; i < width; i++) { |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 75 | uint16_t p = srcPtr[0]; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 76 | uint8_t red = masks->getRed(p); |
| 77 | uint8_t green = masks->getGreen(p); |
| 78 | uint8_t blue = masks->getBlue(p); |
| 79 | dstPtr[i] = SkPack888ToRGB16(red, green, blue); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 80 | srcPtr += sampleX; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 81 | } |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 82 | } |
| 83 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 84 | static void swizzle_mask24_to_n32_opaque( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 85 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 86 | uint32_t startX, uint32_t sampleX) { |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 87 | |
| 88 | // Use the masks to decode to the destination |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 89 | srcRow += 3 * startX; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 90 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 91 | for (int i = 0; i < width; i++) { |
| 92 | uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 93 | uint8_t red = masks->getRed(p); |
| 94 | uint8_t green = masks->getGreen(p); |
| 95 | uint8_t blue = masks->getBlue(p); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 96 | dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
| 97 | srcRow += 3 * sampleX; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 98 | } |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 99 | } |
| 100 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 101 | static void swizzle_mask24_to_n32_unpremul( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 102 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 103 | uint32_t startX, uint32_t sampleX) { |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 104 | |
| 105 | // Use the masks to decode to the destination |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 106 | srcRow += 3 * startX; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 107 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 108 | for (int i = 0; i < width; i++) { |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 109 | uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 110 | uint8_t red = masks->getRed(p); |
| 111 | uint8_t green = masks->getGreen(p); |
| 112 | uint8_t blue = masks->getBlue(p); |
| 113 | uint8_t alpha = masks->getAlpha(p); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 114 | dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 115 | srcRow += 3 * sampleX; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 116 | } |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 117 | } |
| 118 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 119 | static void swizzle_mask24_to_n32_premul( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 120 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 121 | uint32_t startX, uint32_t sampleX) { |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 122 | |
| 123 | // Use the masks to decode to the destination |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 124 | srcRow += 3 * startX; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 125 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 126 | for (int i = 0; i < width; i++) { |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 127 | uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 128 | uint8_t red = masks->getRed(p); |
| 129 | uint8_t green = masks->getGreen(p); |
| 130 | uint8_t blue = masks->getBlue(p); |
| 131 | uint8_t alpha = masks->getAlpha(p); |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 132 | dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 133 | srcRow += 3 * sampleX; |
| 134 | } |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 135 | } |
| 136 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 137 | static void swizzle_mask24_to_565( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 138 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 139 | uint32_t startX, uint32_t sampleX) { |
| 140 | |
| 141 | // Use the masks to decode to the destination |
| 142 | srcRow += 3 * startX; |
| 143 | uint16_t* dstPtr = (uint16_t*) dstRow; |
| 144 | for (int i = 0; i < width; i++) { |
| 145 | uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; |
| 146 | uint8_t red = masks->getRed(p); |
| 147 | uint8_t green = masks->getGreen(p); |
| 148 | uint8_t blue = masks->getBlue(p); |
| 149 | dstPtr[i] = SkPack888ToRGB16(red, green, blue); |
| 150 | srcRow += 3 * sampleX; |
| 151 | } |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 152 | } |
| 153 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 154 | static void swizzle_mask32_to_n32_opaque( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 155 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 156 | uint32_t startX, uint32_t sampleX) { |
| 157 | |
| 158 | // Use the masks to decode to the destination |
| 159 | uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; |
| 160 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
| 161 | for (int i = 0; i < width; i++) { |
| 162 | uint32_t p = srcPtr[0]; |
| 163 | uint8_t red = masks->getRed(p); |
| 164 | uint8_t green = masks->getGreen(p); |
| 165 | uint8_t blue = masks->getBlue(p); |
| 166 | dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
| 167 | srcPtr += sampleX; |
| 168 | } |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 169 | } |
| 170 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 171 | static void swizzle_mask32_to_n32_unpremul( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 172 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 173 | uint32_t startX, uint32_t sampleX) { |
| 174 | |
| 175 | // Use the masks to decode to the destination |
| 176 | uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; |
| 177 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 178 | for (int i = 0; i < width; i++) { |
| 179 | uint32_t p = srcPtr[0]; |
| 180 | uint8_t red = masks->getRed(p); |
| 181 | uint8_t green = masks->getGreen(p); |
| 182 | uint8_t blue = masks->getBlue(p); |
| 183 | uint8_t alpha = masks->getAlpha(p); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 184 | dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); |
| 185 | srcPtr += sampleX; |
| 186 | } |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 187 | } |
| 188 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 189 | static void swizzle_mask32_to_n32_premul( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 190 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 191 | uint32_t startX, uint32_t sampleX) { |
| 192 | |
| 193 | // Use the masks to decode to the destination |
| 194 | uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; |
| 195 | SkPMColor* dstPtr = (SkPMColor*) dstRow; |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 196 | for (int i = 0; i < width; i++) { |
| 197 | uint32_t p = srcPtr[0]; |
| 198 | uint8_t red = masks->getRed(p); |
| 199 | uint8_t green = masks->getGreen(p); |
| 200 | uint8_t blue = masks->getBlue(p); |
| 201 | uint8_t alpha = masks->getAlpha(p); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 202 | dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); |
| 203 | srcPtr += sampleX; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 204 | } |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 205 | } |
| 206 | |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 207 | static void swizzle_mask32_to_565( |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 208 | void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 209 | uint32_t startX, uint32_t sampleX) { |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 210 | // Use the masks to decode to the destination |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 211 | uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 212 | uint16_t* dstPtr = (uint16_t*) dstRow; |
| 213 | for (int i = 0; i < width; i++) { |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 214 | uint32_t p = srcPtr[0]; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 215 | uint8_t red = masks->getRed(p); |
| 216 | uint8_t green = masks->getGreen(p); |
| 217 | uint8_t blue = masks->getBlue(p); |
| 218 | dstPtr[i] = SkPack888ToRGB16(red, green, blue); |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 219 | srcPtr += sampleX; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 220 | } |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 221 | } |
| 222 | |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 223 | /* |
| 224 | * |
| 225 | * Create a new mask swizzler |
| 226 | * |
| 227 | */ |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 228 | SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo, |
| 229 | const SkImageInfo& srcInfo, SkMasks* masks, uint32_t bitsPerPixel, |
| 230 | const SkCodec::Options& options) { |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 231 | |
| 232 | // Choose the appropriate row procedure |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 233 | RowProc proc = nullptr; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 234 | switch (bitsPerPixel) { |
| 235 | case 16: |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 236 | switch (dstInfo.colorType()) { |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 237 | case kN32_SkColorType: |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 238 | switch (dstInfo.alphaType()) { |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 239 | case kUnpremul_SkAlphaType: |
| 240 | proc = &swizzle_mask16_to_n32_unpremul; |
| 241 | break; |
| 242 | case kPremul_SkAlphaType: |
| 243 | proc = &swizzle_mask16_to_n32_premul; |
| 244 | break; |
| 245 | case kOpaque_SkAlphaType: |
| 246 | proc = &swizzle_mask16_to_n32_opaque; |
| 247 | break; |
| 248 | default: |
| 249 | break; |
| 250 | } |
| 251 | break; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 252 | case kRGB_565_SkColorType: |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame^] | 253 | proc = &swizzle_mask16_to_565; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 254 | break; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 255 | default: |
| 256 | break; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 257 | } |
| 258 | break; |
| 259 | case 24: |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 260 | switch (dstInfo.colorType()) { |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 261 | case kN32_SkColorType: |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 262 | switch (dstInfo.alphaType()) { |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 263 | case kUnpremul_SkAlphaType: |
| 264 | proc = &swizzle_mask24_to_n32_unpremul; |
| 265 | break; |
| 266 | case kPremul_SkAlphaType: |
| 267 | proc = &swizzle_mask24_to_n32_premul; |
| 268 | break; |
| 269 | case kOpaque_SkAlphaType: |
| 270 | proc = &swizzle_mask24_to_n32_opaque; |
| 271 | break; |
| 272 | default: |
| 273 | break; |
| 274 | } |
| 275 | break; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 276 | case kRGB_565_SkColorType: |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame^] | 277 | proc = &swizzle_mask24_to_565; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 278 | break; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 279 | default: |
| 280 | break; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 281 | } |
| 282 | break; |
| 283 | case 32: |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 284 | switch (dstInfo.colorType()) { |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 285 | case kN32_SkColorType: |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 286 | switch (dstInfo.alphaType()) { |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 287 | case kUnpremul_SkAlphaType: |
| 288 | proc = &swizzle_mask32_to_n32_unpremul; |
| 289 | break; |
| 290 | case kPremul_SkAlphaType: |
| 291 | proc = &swizzle_mask32_to_n32_premul; |
| 292 | break; |
| 293 | case kOpaque_SkAlphaType: |
| 294 | proc = &swizzle_mask32_to_n32_opaque; |
| 295 | break; |
| 296 | default: |
| 297 | break; |
| 298 | } |
| 299 | break; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 300 | case kRGB_565_SkColorType: |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame^] | 301 | proc = &swizzle_mask32_to_565; |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 302 | break; |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 303 | default: |
| 304 | break; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 305 | } |
| 306 | break; |
| 307 | default: |
| 308 | SkASSERT(false); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 309 | return nullptr; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 310 | } |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 311 | |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 312 | int srcOffset = 0; |
| 313 | int srcWidth = dstInfo.width(); |
| 314 | if (options.fSubset) { |
| 315 | srcOffset = options.fSubset->left(); |
| 316 | srcWidth = options.fSubset->width(); |
| 317 | } |
| 318 | |
| 319 | return new SkMaskSwizzler(masks, proc, srcOffset, srcWidth); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /* |
| 323 | * |
| 324 | * Constructor for mask swizzler |
| 325 | * |
| 326 | */ |
msarett | 80803ff | 2015-10-16 10:54:12 -0700 | [diff] [blame] | 327 | SkMaskSwizzler::SkMaskSwizzler(SkMasks* masks, RowProc proc, int srcOffset, int subsetWidth) |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 328 | : fMasks(masks) |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 329 | , fRowProc(proc) |
msarett | 80803ff | 2015-10-16 10:54:12 -0700 | [diff] [blame] | 330 | , fSubsetWidth(subsetWidth) |
| 331 | , fDstWidth(subsetWidth) |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 332 | , fSampleX(1) |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 333 | , fSrcOffset(srcOffset) |
| 334 | , fX0(srcOffset) |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 335 | {} |
| 336 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 337 | int SkMaskSwizzler::onSetSampleX(int sampleX) { |
| 338 | // FIXME: Share this function with SkSwizzler? |
| 339 | SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be |
| 340 | // way to report failure? |
| 341 | fSampleX = sampleX; |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 342 | fX0 = get_start_coord(sampleX) + fSrcOffset; |
msarett | 80803ff | 2015-10-16 10:54:12 -0700 | [diff] [blame] | 343 | fDstWidth = get_scaled_dimension(fSubsetWidth, sampleX); |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 344 | |
msarett | 80803ff | 2015-10-16 10:54:12 -0700 | [diff] [blame] | 345 | // check that fX0 is valid |
| 346 | SkASSERT(fX0 >= 0); |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 347 | return fDstWidth; |
| 348 | } |
| 349 | |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 350 | /* |
| 351 | * |
msarett | eed039b | 2015-03-18 11:11:19 -0700 | [diff] [blame] | 352 | * Swizzle the specified row |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 353 | * |
| 354 | */ |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 355 | void SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 356 | SkASSERT(nullptr != dst && nullptr != src); |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 357 | fRowProc(dst, src, fDstWidth, fMasks, fX0, fSampleX); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 358 | } |