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 "SkOpts.h" | 10 #include "SkOpts.h" |
| 11 #include "SkSwizzler.h" | 11 #include "SkSwizzler.h" |
| 12 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
| 13 | 13 |
| 14 // samples the row. Does not do anything else but sampling | 14 static void copy(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc , int offset, |
| 15 static void sample565(void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, | 15 const SkPMColor ctable[]) { |
| 16 int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[]){ | 16 // This function must not be called if we are sampling. If we are not |
| 17 // sampling, deltaSrc should equal bpp. | |
| 18 SkASSERT(deltaSrc == bpp); | |
| 17 | 19 |
| 20 memcpy(dst, src + offset, width * bpp); | |
| 21 } | |
| 22 | |
| 23 static void sample1(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset, | |
| 24 const SkPMColor ctable[]) { | |
| 18 src += offset; | 25 src += offset; |
| 19 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | 26 uint8_t* dst8 = (uint8_t*) dst; |
| 20 for (int x = 0; x < width; x++) { | 27 for (int x = 0; x < width; x++) { |
| 21 dst[x] = src[1] << 8 | src[0]; | 28 dst8[x] = *src; |
| 22 src += deltaSrc; | 29 src += deltaSrc; |
| 23 } | 30 } |
| 24 } | 31 } |
| 32 | |
| 33 static void sample2(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset, | |
| 34 const SkPMColor ctable[]) { | |
| 35 src += offset; | |
| 36 uint16_t* dst16 = (uint16_t*) dst; | |
| 37 for (int x = 0; x < width; x++) { | |
| 38 dst16[x] = *((const uint16_t*) src); | |
| 39 src += deltaSrc; | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 static void sample4(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset, | |
| 44 const SkPMColor ctable[]) { | |
| 45 src += offset; | |
| 46 uint32_t* dst32 = (uint32_t*) dst; | |
| 47 for (int x = 0; x < width; x++) { | |
| 48 dst32[x] = *((const uint32_t*) src); | |
| 49 src += deltaSrc; | |
| 50 } | |
| 51 } | |
| 25 | 52 |
| 26 // TODO (msarett): Investigate SIMD optimizations for swizzle routines. | 53 // TODO (msarett): Investigate SIMD optimizations for swizzle routines. |
|
scroggo
2016/01/14 21:28:18
Not related to this patch set, but time to remove
msarett
2016/01/14 22:25:20
Done.
| |
| 27 | 54 |
| 28 // kBit | 55 // kBit |
| 29 // These routines exclusively choose between white and black | 56 // These routines exclusively choose between white and black |
| 30 | 57 |
| 31 #define GRAYSCALE_BLACK 0 | 58 #define GRAYSCALE_BLACK 0 |
| 32 #define GRAYSCALE_WHITE 0xFF | 59 #define GRAYSCALE_WHITE 0xFF |
| 33 | 60 |
| 34 | 61 |
| 35 // same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned to dst[x] | 62 // same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned to dst[x] |
| 36 static void swizzle_bit_to_grayscale( | 63 static void swizzle_bit_to_grayscale( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 int bitOffset = bitIndex + deltaSrc; | 212 int bitOffset = bitIndex + deltaSrc; |
| 186 bitIndex = bitOffset % 8; | 213 bitIndex = bitOffset % 8; |
| 187 currByte = *(src += bitOffset / 8); | 214 currByte = *(src += bitOffset / 8); |
| 188 index = (currByte >> (8 - bpp - bitIndex)) & mask; | 215 index = (currByte >> (8 - bpp - bitIndex)) & mask; |
| 189 dst[x] = ctable[index]; | 216 dst[x] = ctable[index]; |
| 190 } | 217 } |
| 191 } | 218 } |
| 192 | 219 |
| 193 // kIndex | 220 // kIndex |
| 194 | 221 |
| 195 static void swizzle_index_to_index( | |
| 196 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
| 197 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | |
| 198 | |
| 199 src += offset; | |
| 200 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | |
| 201 if (1 == deltaSrc) { | |
| 202 memcpy(dst, src, dstWidth); | |
| 203 } else { | |
| 204 for (int x = 0; x < dstWidth; x++) { | |
| 205 dst[x] = *src; | |
| 206 src += deltaSrc; | |
| 207 } | |
| 208 } | |
| 209 } | |
| 210 | |
| 211 static void swizzle_index_to_n32( | 222 static void swizzle_index_to_n32( |
| 212 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 223 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 213 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 224 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 214 | 225 |
| 215 src += offset; | 226 src += offset; |
| 216 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 227 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 217 for (int x = 0; x < dstWidth; x++) { | 228 for (int x = 0; x < dstWidth; x++) { |
| 218 SkPMColor c = ctable[*src]; | 229 SkPMColor c = ctable[*src]; |
| 219 dst[x] = c; | 230 dst[x] = c; |
| 220 src += deltaSrc; | 231 src += deltaSrc; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 265 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 255 | 266 |
| 256 src += offset; | 267 src += offset; |
| 257 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 268 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 258 for (int x = 0; x < dstWidth; x++) { | 269 for (int x = 0; x < dstWidth; x++) { |
| 259 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); | 270 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); |
| 260 src += deltaSrc; | 271 src += deltaSrc; |
| 261 } | 272 } |
| 262 } | 273 } |
| 263 | 274 |
| 264 static void swizzle_gray_to_gray( | |
| 265 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
| 266 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | |
| 267 | |
| 268 src += offset; | |
| 269 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | |
| 270 if (1 == deltaSrc) { | |
| 271 memcpy(dstRow, src, dstWidth); | |
| 272 } else { | |
| 273 for (int x = 0; x < dstWidth; x++) { | |
| 274 dst[x] = src[0]; | |
| 275 src += deltaSrc; | |
| 276 } | |
| 277 } | |
| 278 } | |
| 279 | |
| 280 static void swizzle_gray_to_565( | 275 static void swizzle_gray_to_565( |
| 281 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 276 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 282 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 277 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 283 | 278 |
| 284 src += offset; | 279 src += offset; |
| 285 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 280 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 286 for (int x = 0; x < dstWidth; x++) { | 281 for (int x = 0; x < dstWidth; x++) { |
| 287 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); | 282 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); |
| 288 src += deltaSrc; | 283 src += deltaSrc; |
| 289 } | 284 } |
| 290 } | 285 } |
| 291 | 286 |
| 292 // kBGRX | 287 // kBGRX |
| 293 | 288 |
| 294 static void swizzle_bgrx_to_n32( | 289 static void swizzle_bgrx_to_n32( |
| 295 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 290 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 296 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 291 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 297 | 292 |
| 298 src += offset; | 293 src += offset; |
| 299 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 294 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 300 for (int x = 0; x < dstWidth; x++) { | 295 for (int x = 0; x < dstWidth; x++) { |
| 301 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 296 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
| 302 src += deltaSrc; | 297 src += deltaSrc; |
| 303 } | 298 } |
| 304 } | 299 } |
| 305 | 300 |
| 306 static void fast_swizzle_bgrx_to_32( | |
| 307 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, | |
| 308 const SkPMColor ctable[]) { | |
| 309 | |
| 310 // This function must not be called if we are sampling. If we are not | |
| 311 // sampling, deltaSrc should equal bpp. | |
| 312 SkASSERT(deltaSrc == bpp); | |
| 313 | |
| 314 // The default swizzle supports BGR->N32 and BGRX->N32. This only | |
| 315 // supports BGRX->N32. | |
| 316 SkASSERT(4 == bpp); | |
| 317 | |
| 318 // These swizzles trust that the alpha value is already 0xFF. | |
| 319 #ifdef SK_PMCOLOR_IS_RGBA | |
| 320 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); | |
| 321 #else | |
| 322 memcpy(dst, src + offset, width * bpp); | |
| 323 #endif | |
| 324 } | |
| 325 | |
| 326 static void swizzle_bgrx_to_565( | 301 static void swizzle_bgrx_to_565( |
| 327 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 302 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 328 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 303 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 329 | 304 |
| 330 src += offset; | 305 src += offset; |
| 331 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 306 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 332 for (int x = 0; x < dstWidth; x++) { | 307 for (int x = 0; x < dstWidth; x++) { |
| 333 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); | 308 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); |
| 334 src += deltaSrc; | 309 src += deltaSrc; |
| 335 } | 310 } |
| 336 } | 311 } |
| 337 | 312 |
| 338 // kBGRA | 313 // kBGRA |
| 339 | 314 |
| 340 static void swizzle_bgra_to_n32_unpremul( | 315 static void swizzle_bgra_to_n32_unpremul( |
| 341 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 316 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 342 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 317 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 343 | 318 |
| 344 src += offset; | 319 src += offset; |
| 345 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 320 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 346 for (int x = 0; x < dstWidth; x++) { | 321 for (int x = 0; x < dstWidth; x++) { |
| 347 uint8_t alpha = src[3]; | 322 uint8_t alpha = src[3]; |
| 348 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | 323 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
| 349 src += deltaSrc; | 324 src += deltaSrc; |
| 350 } | 325 } |
| 351 } | 326 } |
| 352 | 327 |
| 328 static void fast_swizzle_bgra_to_n32_unpremul( | |
|
scroggo
2016/01/14 21:28:18
I thought we were going to use the same methods fo
msarett
2016/01/14 22:25:20
We can and maybe should consider sharing more code
| |
| 329 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, | |
| 330 const SkPMColor ctable[]) { | |
| 331 | |
| 332 // This function must not be called if we are sampling. If we are not | |
| 333 // sampling, deltaSrc should equal bpp. | |
| 334 SkASSERT(deltaSrc == bpp); | |
| 335 | |
| 336 // These swizzles trust that the alpha value is already 0xFF. | |
| 337 #ifdef SK_PMCOLOR_IS_RGBA | |
| 338 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); | |
| 339 #else | |
| 340 memcpy(dst, src + offset, width * bpp); | |
| 341 #endif | |
| 342 } | |
| 343 | |
| 353 static void swizzle_bgra_to_n32_premul( | 344 static void swizzle_bgra_to_n32_premul( |
| 354 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 345 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 355 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 346 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 356 | 347 |
| 357 src += offset; | 348 src += offset; |
| 358 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 349 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 359 for (int x = 0; x < dstWidth; x++) { | 350 for (int x = 0; x < dstWidth; x++) { |
| 360 uint8_t alpha = src[3]; | 351 uint8_t alpha = src[3]; |
| 361 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); | 352 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); |
| 362 src += deltaSrc; | 353 src += deltaSrc; |
| 363 } | 354 } |
| 364 } | 355 } |
| 365 | 356 |
| 366 static void fast_swizzle_bgra_to_n32_premul( | 357 static void fast_swizzle_bgra_to_n32_premul( |
| 367 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, | 358 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, |
| 368 const SkPMColor ctable[]) { | 359 const SkPMColor ctable[]) { |
| 369 | 360 |
| 370 // This function must not be called if we are sampling. If we are not | 361 // This function must not be called if we are sampling. If we are not |
| 371 // sampling, deltaSrc should equal bpp. | 362 // sampling, deltaSrc should equal bpp. |
| 372 SkASSERT(deltaSrc == bpp); | 363 SkASSERT(deltaSrc == bpp); |
| 373 | 364 |
| 374 #ifdef SK_PMCOLOR_IS_RGBA | 365 #ifdef SK_PMCOLOR_IS_RGBA |
| 375 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset) , width); | 366 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset) , width); |
| 376 #else | 367 #else |
| 377 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); | 368 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); |
| 378 #endif | 369 #endif |
| 379 } | 370 } |
| 380 | 371 |
| 381 // kRGBX | 372 // kRGB |
| 382 | 373 |
| 383 static void swizzle_rgbx_to_n32( | 374 static void swizzle_rgb_to_n32( |
| 384 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 375 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 385 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 376 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 386 | 377 |
| 387 src += offset; | 378 src += offset; |
| 388 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 379 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 389 for (int x = 0; x < dstWidth; x++) { | 380 for (int x = 0; x < dstWidth; x++) { |
| 390 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 381 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
| 391 src += deltaSrc; | 382 src += deltaSrc; |
| 392 } | 383 } |
| 393 } | 384 } |
| 394 | 385 |
| 395 static void fast_swizzle_rgbx_to_32( | |
| 396 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, | |
| 397 const SkPMColor ctable[]) { | |
| 398 | 386 |
| 399 // This function must not be called if we are sampling. If we are not | |
| 400 // sampling, deltaSrc should equal bpp. | |
| 401 SkASSERT(deltaSrc == bpp); | |
| 402 | 387 |
| 403 // The default swizzle supports RGB->N32 and RGBX->N32. This only | 388 static void swizzle_rgb_to_565( |
| 404 // supports RGBX->N32. | |
| 405 SkASSERT(4 == bpp); | |
| 406 | |
| 407 // These swizzles trust that the alpha value is already 0xFF. | |
| 408 #ifdef SK_PMCOLOR_IS_RGBA | |
| 409 memcpy(dst, src + offset, width * bpp); | |
| 410 #else | |
| 411 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); | |
| 412 #endif | |
| 413 } | |
| 414 | |
| 415 static void swizzle_rgbx_to_565( | |
| 416 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 389 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 417 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 390 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 418 | 391 |
| 419 src += offset; | 392 src += offset; |
| 420 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 393 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 421 for (int x = 0; x < dstWidth; x++) { | 394 for (int x = 0; x < dstWidth; x++) { |
| 422 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 395 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
| 423 src += deltaSrc; | 396 src += deltaSrc; |
| 424 } | 397 } |
| 425 } | 398 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 | 433 |
| 461 src += offset; | 434 src += offset; |
| 462 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 435 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| 463 for (int x = 0; x < dstWidth; x++) { | 436 for (int x = 0; x < dstWidth; x++) { |
| 464 unsigned alpha = src[3]; | 437 unsigned alpha = src[3]; |
| 465 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 438 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
| 466 src += deltaSrc; | 439 src += deltaSrc; |
| 467 } | 440 } |
| 468 } | 441 } |
| 469 | 442 |
| 443 static void fast_swizzle_rgba_to_n32_unpremul( | |
|
scroggo
2016/01/14 21:28:18
This name is confusing. It looks like it actually
msarett
2016/01/14 22:25:20
Let me know if the name is still confusing after o
scroggo
2016/01/19 18:06:35
No, the confusion was mine :)
| |
| 444 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, | |
| 445 const SkPMColor ctable[]) { | |
| 446 | |
| 447 // This function must not be called if we are sampling. If we are not | |
| 448 // sampling, deltaSrc should equal bpp. | |
| 449 SkASSERT(deltaSrc == bpp); | |
| 450 | |
| 451 // These swizzles trust that the alpha value is already 0xFF. | |
| 452 #ifdef SK_PMCOLOR_IS_RGBA | |
| 453 memcpy(dst, src + offset, width * bpp); | |
| 454 #else | |
| 455 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); | |
| 456 #endif | |
| 457 } | |
| 458 | |
| 470 // kCMYK | 459 // kCMYK |
| 471 // | 460 // |
| 472 // CMYK is stored as four bytes per pixel. | 461 // CMYK is stored as four bytes per pixel. |
| 473 // | 462 // |
| 474 // We will implement a crude conversion from CMYK -> RGB using formulas | 463 // We will implement a crude conversion from CMYK -> RGB using formulas |
| 475 // from easyrgb.com. | 464 // from easyrgb.com. |
| 476 // | 465 // |
| 477 // CMYK -> CMY | 466 // CMYK -> CMY |
| 478 // C = C * (1 - K) + K | 467 // C = C * (1 - K) + K |
| 479 // M = M * (1 - K) + K | 468 // M = M * (1 - K) + K |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 break; | 612 break; |
| 624 } else { | 613 } else { |
| 625 proc = &swizzle_index_to_n32; | 614 proc = &swizzle_index_to_n32; |
| 626 break; | 615 break; |
| 627 } | 616 } |
| 628 break; | 617 break; |
| 629 case kRGB_565_SkColorType: | 618 case kRGB_565_SkColorType: |
| 630 proc = &swizzle_index_to_565; | 619 proc = &swizzle_index_to_565; |
| 631 break; | 620 break; |
| 632 case kIndex_8_SkColorType: | 621 case kIndex_8_SkColorType: |
| 633 proc = &swizzle_index_to_index; | 622 proc = &sample1; |
| 623 fastProc = © | |
| 634 break; | 624 break; |
| 635 default: | 625 default: |
| 636 break; | 626 break; |
| 637 } | 627 } |
| 638 break; | 628 break; |
| 639 case kGray: | 629 case kGray: |
| 640 switch (dstInfo.colorType()) { | 630 switch (dstInfo.colorType()) { |
| 641 case kN32_SkColorType: | 631 case kN32_SkColorType: |
| 642 proc = &swizzle_gray_to_n32; | 632 proc = &swizzle_gray_to_n32; |
| 643 break; | 633 break; |
| 644 case kGray_8_SkColorType: | 634 case kGray_8_SkColorType: |
| 645 proc = &swizzle_gray_to_gray; | 635 proc = &sample1; |
| 636 fastProc = © | |
| 646 break; | 637 break; |
| 647 case kRGB_565_SkColorType: | 638 case kRGB_565_SkColorType: |
| 648 proc = &swizzle_gray_to_565; | 639 proc = &swizzle_gray_to_565; |
| 649 break; | 640 break; |
| 650 default: | 641 default: |
| 651 break; | 642 break; |
| 652 } | 643 } |
| 653 break; | 644 break; |
| 654 case kBGR: | 645 case kBGR: |
| 655 case kBGRX: | 646 case kBGRX: |
| 656 switch (dstInfo.colorType()) { | 647 switch (dstInfo.colorType()) { |
| 657 case kN32_SkColorType: | 648 case kN32_SkColorType: |
| 658 proc = &swizzle_bgrx_to_n32; | 649 proc = &swizzle_bgrx_to_n32; |
| 659 break; | 650 break; |
| 660 case kRGB_565_SkColorType: | 651 case kRGB_565_SkColorType: |
| 661 proc = &swizzle_bgrx_to_565; | 652 proc = &swizzle_bgrx_to_565; |
| 662 break; | 653 break; |
| 663 default: | 654 default: |
| 664 break; | 655 break; |
| 665 } | 656 } |
| 666 break; | 657 break; |
| 667 case kBGRA: | 658 case kBGRA: |
| 668 switch (dstInfo.colorType()) { | 659 switch (dstInfo.colorType()) { |
| 669 case kN32_SkColorType: | 660 case kN32_SkColorType: |
| 670 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 661 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 671 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 662 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 672 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _unpremul>; | 663 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _unpremul>; |
| 673 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg rx_to_32>; | 664 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg ra_to_n32_unpremul>; |
| 674 } else { | 665 } else { |
| 675 proc = &swizzle_bgra_to_n32_unpremul; | 666 proc = &swizzle_bgra_to_n32_unpremul; |
| 676 fastProc = &fast_swizzle_bgrx_to_32; | 667 fastProc = &fast_swizzle_bgra_to_n32_unpremul; |
| 677 } | 668 } |
| 678 } else { | 669 } else { |
| 679 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 670 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 680 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _premul>; | 671 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _premul>; |
| 681 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg ra_to_n32_premul>; | 672 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg ra_to_n32_premul>; |
| 682 } else { | 673 } else { |
| 683 proc = &swizzle_bgra_to_n32_premul; | 674 proc = &swizzle_bgra_to_n32_premul; |
| 684 fastProc = &fast_swizzle_bgra_to_n32_premul; | 675 fastProc = &fast_swizzle_bgra_to_n32_premul; |
| 685 } | 676 } |
| 686 } | 677 } |
| 687 break; | 678 break; |
| 688 default: | 679 default: |
| 689 break; | 680 break; |
| 690 } | 681 } |
| 691 break; | 682 break; |
| 692 case kRGBX: | 683 case kRGB: |
| 693 switch (dstInfo.colorType()) { | 684 switch (dstInfo.colorType()) { |
| 694 case kN32_SkColorType: | 685 case kN32_SkColorType: |
| 695 proc = &swizzle_rgbx_to_n32; | 686 proc = &swizzle_rgb_to_n32; |
| 696 fastProc = &fast_swizzle_rgbx_to_32; | |
| 697 break; | 687 break; |
| 698 case kRGB_565_SkColorType: | 688 case kRGB_565_SkColorType: |
| 699 proc = &swizzle_rgbx_to_565; | 689 proc = &swizzle_rgb_to_565; |
| 700 default: | 690 default: |
| 701 break; | 691 break; |
| 702 } | 692 } |
| 703 break; | 693 break; |
| 704 case kRGBA: | 694 case kRGBA: |
| 705 switch (dstInfo.colorType()) { | 695 switch (dstInfo.colorType()) { |
| 706 case kN32_SkColorType: | 696 case kN32_SkColorType: |
| 707 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 697 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 708 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 698 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 709 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _unpremul>; | 699 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _unpremul>; |
| 710 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg bx_to_32>; | 700 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_unpremul>; |
| 711 } else { | 701 } else { |
| 712 proc = &swizzle_rgba_to_n32_unpremul; | 702 proc = &swizzle_rgba_to_n32_unpremul; |
| 713 fastProc = &fast_swizzle_rgbx_to_32; | 703 fastProc = &fast_swizzle_rgba_to_n32_unpremul; |
| 714 } | 704 } |
| 715 } else { | 705 } else { |
| 716 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 706 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 717 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _premul>; | 707 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _premul>; |
| 718 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_premul>; | 708 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_premul>; |
| 719 } else { | 709 } else { |
| 720 proc = &swizzle_rgba_to_n32_premul; | 710 proc = &swizzle_rgba_to_n32_premul; |
| 721 fastProc = &fast_swizzle_rgba_to_n32_premul; | 711 fastProc = &fast_swizzle_rgba_to_n32_premul; |
| 722 } | 712 } |
| 723 } | 713 } |
| 724 break; | 714 break; |
| 725 default: | 715 default: |
| 726 break; | 716 break; |
| 727 } | 717 } |
| 728 break; | 718 break; |
| 729 case kRGB: | |
| 730 switch (dstInfo.colorType()) { | |
| 731 case kN32_SkColorType: | |
| 732 proc = &swizzle_rgbx_to_n32; | |
| 733 break; | |
| 734 default: | |
| 735 break; | |
| 736 } | |
| 737 break; | |
| 738 case kRGB_565: | |
| 739 switch (dstInfo.colorType()) { | |
| 740 case kRGB_565_SkColorType: | |
| 741 proc = &sample565; | |
| 742 break; | |
| 743 default: | |
| 744 break; | |
| 745 } | |
| 746 break; | |
| 747 case kCMYK: | 719 case kCMYK: |
| 748 switch (dstInfo.colorType()) { | 720 switch (dstInfo.colorType()) { |
| 749 case kN32_SkColorType: | 721 case kN32_SkColorType: |
| 750 proc = &swizzle_cmyk_to_n32; | 722 proc = &swizzle_cmyk_to_n32; |
| 751 break; | 723 break; |
| 752 case kRGB_565_SkColorType: | 724 case kRGB_565_SkColorType: |
| 753 proc = &swizzle_cmyk_to_565; | 725 proc = &swizzle_cmyk_to_565; |
| 754 break; | 726 break; |
| 755 default: | 727 default: |
| 756 break; | 728 break; |
| 757 } | 729 } |
| 758 break; | 730 break; |
| 731 case kNOOP1: | |
| 732 proc = &sample1; | |
| 733 fastProc = © | |
|
scroggo
2016/01/14 21:28:18
This looks like the right thing to do, except I th
msarett
2016/01/14 22:25:20
We will never be able to know that we are sampling
| |
| 734 break; | |
| 735 case kNOOP2: | |
| 736 proc = sample2; | |
| 737 fastProc = © | |
| 738 break; | |
| 739 case kNOOP4: | |
| 740 proc = &sample4; | |
| 741 fastProc = © | |
| 742 break; | |
| 759 default: | 743 default: |
| 760 break; | 744 break; |
| 761 } | 745 } |
| 762 | 746 |
| 763 // Store bpp in bytes if it is an even multiple, otherwise use bits | 747 // Store bpp in bytes if it is an even multiple, otherwise use bits |
| 764 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); | 748 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); |
| 765 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); | 749 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); |
| 766 | 750 |
| 767 int srcOffset = 0; | 751 int srcOffset = 0; |
| 768 int srcWidth = dstInfo.width(); | 752 int srcWidth = dstInfo.width(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 int SkSwizzler::onSetSampleX(int sampleX) { | 789 int SkSwizzler::onSetSampleX(int sampleX) { |
| 806 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be | 790 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be |
| 807 // way to report failure? | 791 // way to report failure? |
| 808 fSampleX = sampleX; | 792 fSampleX = sampleX; |
| 809 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; | 793 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; |
| 810 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; | 794 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; |
| 811 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); | 795 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); |
| 812 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); | 796 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); |
| 813 | 797 |
| 814 // The optimized swizzler routines do not (yet) support sampling. | 798 // The optimized swizzler routines do not (yet) support sampling. |
| 815 fFastProc = nullptr; | 799 fFastProc = nullptr; |
|
scroggo
2016/01/14 21:28:18
This predates this CL, but I could imagine the fol
msarett
2016/01/14 22:25:20
Right on all counts. Can I fix a follow-up CL?
scroggo
2016/01/19 18:06:35
sgtm
| |
| 816 | 800 |
| 817 return fAllocatedWidth; | 801 return fAllocatedWidth; |
| 818 } | 802 } |
| 819 | 803 |
| 820 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 804 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| 821 SkASSERT(nullptr != dst && nullptr != src); | 805 SkASSERT(nullptr != dst && nullptr != src); |
| 822 RowProc proc = fFastProc ? fFastProc : fProc; | 806 RowProc proc = fFastProc ? fFastProc : fProc; |
|
scroggo
2016/01/14 21:28:18
We could fix the (future?) problem I mentioned abo
msarett
2016/01/14 22:25:20
+1 on this idea. That will be a nice way to handl
scroggo
2016/01/19 18:06:35
sgtm
| |
| 823 proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, | 807 proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, |
| 824 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 808 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| 825 } | 809 } |
| OLD | NEW |