Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: src/codec/SkMaskSwizzler.cpp

Issue 1277213002: Support more swizzles to 565 in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update new 565 swizzling functions for scaling Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SkMaskSwizzler.h" 10 #include "SkMaskSwizzler.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 uint8_t red = masks->getRed(p); 56 uint8_t red = masks->getRed(p);
57 uint8_t green = masks->getGreen(p); 57 uint8_t green = masks->getGreen(p);
58 uint8_t blue = masks->getBlue(p); 58 uint8_t blue = masks->getBlue(p);
59 uint8_t alpha = masks->getAlpha(p); 59 uint8_t alpha = masks->getAlpha(p);
60 UPDATE_RESULT_ALPHA(alpha); 60 UPDATE_RESULT_ALPHA(alpha);
61 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 61 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
62 } 62 }
63 return COMPUTE_RESULT_ALPHA; 63 return COMPUTE_RESULT_ALPHA;
64 } 64 }
65 65
66 // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to
67 // convert it back to 565. Instead, we should swizzle to 565 directly.
68 static SkSwizzler::ResultAlpha swizzle_mask16_to_565(
69 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
70
71 // Use the masks to decode to the destination
72 uint16_t* srcPtr = (uint16_t*) srcRow;
73 uint16_t* dstPtr = (uint16_t*) dstRow;
74 for (int i = 0; i < width; i++) {
75 uint16_t p = srcPtr[i];
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);
80 }
81 return SkSwizzler::kOpaque_ResultAlpha;
82 }
83
66 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_opaque( 84 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_opaque(
67 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 85 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
68 86
69 // Use the masks to decode to the destination 87 // Use the masks to decode to the destination
70 SkPMColor* dstPtr = (SkPMColor*) dstRow; 88 SkPMColor* dstPtr = (SkPMColor*) dstRow;
71 for (int i = 0; i < 3*width; i += 3) { 89 for (int i = 0; i < 3*width; i += 3) {
72 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16; 90 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16;
73 uint8_t red = masks->getRed(p); 91 uint8_t red = masks->getRed(p);
74 uint8_t green = masks->getGreen(p); 92 uint8_t green = masks->getGreen(p);
75 uint8_t blue = masks->getBlue(p); 93 uint8_t blue = masks->getBlue(p);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 uint8_t red = masks->getRed(p); 125 uint8_t red = masks->getRed(p);
108 uint8_t green = masks->getGreen(p); 126 uint8_t green = masks->getGreen(p);
109 uint8_t blue = masks->getBlue(p); 127 uint8_t blue = masks->getBlue(p);
110 uint8_t alpha = masks->getAlpha(p); 128 uint8_t alpha = masks->getAlpha(p);
111 UPDATE_RESULT_ALPHA(alpha); 129 UPDATE_RESULT_ALPHA(alpha);
112 dstPtr[i/3] = SkPreMultiplyARGB(alpha, red, green, blue); 130 dstPtr[i/3] = SkPreMultiplyARGB(alpha, red, green, blue);
113 } 131 }
114 return COMPUTE_RESULT_ALPHA; 132 return COMPUTE_RESULT_ALPHA;
115 } 133 }
116 134
135 static SkSwizzler::ResultAlpha swizzle_mask24_to_565(
136 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
137
138 // Use the masks to decode to the destination
139 uint16_t* dstPtr = (uint16_t*) dstRow;
140 for (int i = 0; i < 3*width; i += 3) {
141 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16;
142 uint8_t red = masks->getRed(p);
143 uint8_t green = masks->getGreen(p);
144 uint8_t blue = masks->getBlue(p);
145 dstPtr[i/3] = SkPack888ToRGB16(red, green, blue);
146 }
147 return SkSwizzler::kOpaque_ResultAlpha;
148 }
149
117 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_opaque( 150 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_opaque(
118 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 151 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
119 152
120 // Use the masks to decode to the destination 153 // Use the masks to decode to the destination
121 uint32_t* srcPtr = (uint32_t*) srcRow; 154 uint32_t* srcPtr = (uint32_t*) srcRow;
122 SkPMColor* dstPtr = (SkPMColor*) dstRow; 155 SkPMColor* dstPtr = (SkPMColor*) dstRow;
123 for (int i = 0; i < width; i++) { 156 for (int i = 0; i < width; i++) {
124 uint32_t p = srcPtr[i]; 157 uint32_t p = srcPtr[i];
125 uint8_t red = masks->getRed(p); 158 uint8_t red = masks->getRed(p);
126 uint8_t green = masks->getGreen(p); 159 uint8_t green = masks->getGreen(p);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 uint8_t red = masks->getRed(p); 194 uint8_t red = masks->getRed(p);
162 uint8_t green = masks->getGreen(p); 195 uint8_t green = masks->getGreen(p);
163 uint8_t blue = masks->getBlue(p); 196 uint8_t blue = masks->getBlue(p);
164 uint8_t alpha = masks->getAlpha(p); 197 uint8_t alpha = masks->getAlpha(p);
165 UPDATE_RESULT_ALPHA(alpha); 198 UPDATE_RESULT_ALPHA(alpha);
166 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 199 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
167 } 200 }
168 return COMPUTE_RESULT_ALPHA; 201 return COMPUTE_RESULT_ALPHA;
169 } 202 }
170 203
204 static SkSwizzler::ResultAlpha swizzle_mask32_to_565(
205 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
206 // Use the masks to decode to the destination
207 uint32_t* srcPtr = (uint32_t*) srcRow;
208 uint16_t* dstPtr = (uint16_t*) dstRow;
209 for (int i = 0; i < width; i++) {
210 uint32_t p = srcPtr[i];
211 uint8_t red = masks->getRed(p);
212 uint8_t green = masks->getGreen(p);
213 uint8_t blue = masks->getBlue(p);
214 dstPtr[i] = SkPack888ToRGB16(red, green, blue);
215 }
216 return SkSwizzler::kOpaque_ResultAlpha;
217 }
218
171 /* 219 /*
172 * 220 *
173 * Create a new mask swizzler 221 * Create a new mask swizzler
174 * 222 *
175 */ 223 */
176 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler( 224 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(
177 const SkImageInfo& info, SkMasks* masks, uint32_t bitsPerPixel) { 225 const SkImageInfo& info, SkMasks* masks, uint32_t bitsPerPixel) {
178 226
179 // Choose the appropriate row procedure 227 // Choose the appropriate row procedure
180 RowProc proc = NULL; 228 RowProc proc = NULL;
181 switch (bitsPerPixel) { 229 switch (bitsPerPixel) {
182 case 16: 230 case 16:
183 switch (info.colorType()) { 231 switch (info.colorType()) {
184 case kN32_SkColorType: 232 case kN32_SkColorType:
185 switch (info.alphaType()) { 233 switch (info.alphaType()) {
186 case kUnpremul_SkAlphaType: 234 case kUnpremul_SkAlphaType:
187 proc = &swizzle_mask16_to_n32_unpremul; 235 proc = &swizzle_mask16_to_n32_unpremul;
188 break; 236 break;
189 case kPremul_SkAlphaType: 237 case kPremul_SkAlphaType:
190 proc = &swizzle_mask16_to_n32_premul; 238 proc = &swizzle_mask16_to_n32_premul;
191 break; 239 break;
192 case kOpaque_SkAlphaType: 240 case kOpaque_SkAlphaType:
193 proc = &swizzle_mask16_to_n32_opaque; 241 proc = &swizzle_mask16_to_n32_opaque;
194 break; 242 break;
195 default: 243 default:
196 break; 244 break;
197 } 245 }
198 break; 246 break;
247 case kRGB_565_SkColorType:
248 switch (info.alphaType()) {
249 case kOpaque_SkAlphaType:
250 proc = &swizzle_mask16_to_565;
251 break;
252 default:
253 break;
254 }
255 break;
199 default: 256 default:
200 break; 257 break;
201 } 258 }
202 break; 259 break;
203 case 24: 260 case 24:
204 switch (info.colorType()) { 261 switch (info.colorType()) {
205 case kN32_SkColorType: 262 case kN32_SkColorType:
206 switch (info.alphaType()) { 263 switch (info.alphaType()) {
207 case kUnpremul_SkAlphaType: 264 case kUnpremul_SkAlphaType:
208 proc = &swizzle_mask24_to_n32_unpremul; 265 proc = &swizzle_mask24_to_n32_unpremul;
209 break; 266 break;
210 case kPremul_SkAlphaType: 267 case kPremul_SkAlphaType:
211 proc = &swizzle_mask24_to_n32_premul; 268 proc = &swizzle_mask24_to_n32_premul;
212 break; 269 break;
213 case kOpaque_SkAlphaType: 270 case kOpaque_SkAlphaType:
214 proc = &swizzle_mask24_to_n32_opaque; 271 proc = &swizzle_mask24_to_n32_opaque;
215 break; 272 break;
216 default: 273 default:
217 break; 274 break;
218 } 275 }
219 break; 276 break;
277 case kRGB_565_SkColorType:
278 switch (info.alphaType()) {
279 case kOpaque_SkAlphaType:
280 proc = &swizzle_mask24_to_565;
281 break;
282 default:
283 break;
284 }
285 break;
220 default: 286 default:
221 break; 287 break;
222 } 288 }
223 break; 289 break;
224 case 32: 290 case 32:
225 switch (info.colorType()) { 291 switch (info.colorType()) {
226 case kN32_SkColorType: 292 case kN32_SkColorType:
227 switch (info.alphaType()) { 293 switch (info.alphaType()) {
228 case kUnpremul_SkAlphaType: 294 case kUnpremul_SkAlphaType:
229 proc = &swizzle_mask32_to_n32_unpremul; 295 proc = &swizzle_mask32_to_n32_unpremul;
230 break; 296 break;
231 case kPremul_SkAlphaType: 297 case kPremul_SkAlphaType:
232 proc = &swizzle_mask32_to_n32_premul; 298 proc = &swizzle_mask32_to_n32_premul;
233 break; 299 break;
234 case kOpaque_SkAlphaType: 300 case kOpaque_SkAlphaType:
235 proc = &swizzle_mask32_to_n32_opaque; 301 proc = &swizzle_mask32_to_n32_opaque;
236 break; 302 break;
237 default: 303 default:
238 break; 304 break;
239 } 305 }
240 break; 306 break;
307 case kRGB_565_SkColorType:
308 switch (info.alphaType()) {
309 case kOpaque_SkAlphaType:
310 proc = &swizzle_mask32_to_565;
311 break;
312 default:
313 break;
314 }
315 break;
241 default: 316 default:
242 break; 317 break;
243 } 318 }
244 break; 319 break;
245 default: 320 default:
246 SkASSERT(false); 321 SkASSERT(false);
247 return NULL; 322 return NULL;
248 } 323 }
249 return SkNEW_ARGS(SkMaskSwizzler, (info, masks, proc)); 324 return SkNEW_ARGS(SkMaskSwizzler, (info, masks, proc));
250 } 325 }
(...skipping 12 matching lines...) Expand all
263 338
264 /* 339 /*
265 * 340 *
266 * Swizzle the specified row 341 * Swizzle the specified row
267 * 342 *
268 */ 343 */
269 SkSwizzler::ResultAlpha SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RES TRICT src) { 344 SkSwizzler::ResultAlpha SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RES TRICT src) {
270 SkASSERT(NULL != dst && NULL != src); 345 SkASSERT(NULL != dst && NULL != src);
271 return fRowProc(dst, src, fDstInfo.width(), fMasks); 346 return fRowProc(dst, src, fDstInfo.width(), fMasks);
272 } 347 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec_wbmp.cpp ('k') | src/codec/SkSwizzler.cpp » ('j') | src/codec/SkSwizzler.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698