| 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 } |
| 25 | 32 |
| 26 // TODO (msarett): Investigate SIMD optimizations for swizzle routines. | 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 } |
| 27 | 52 |
| 28 // kBit | 53 // kBit |
| 29 // These routines exclusively choose between white and black | 54 // These routines exclusively choose between white and black |
| 30 | 55 |
| 31 #define GRAYSCALE_BLACK 0 | 56 #define GRAYSCALE_BLACK 0 |
| 32 #define GRAYSCALE_WHITE 0xFF | 57 #define GRAYSCALE_WHITE 0xFF |
| 33 | 58 |
| 34 | 59 |
| 35 // same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned
to dst[x] | 60 // 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( | 61 static void swizzle_bit_to_grayscale( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 int bitOffset = bitIndex + deltaSrc; | 210 int bitOffset = bitIndex + deltaSrc; |
| 186 bitIndex = bitOffset % 8; | 211 bitIndex = bitOffset % 8; |
| 187 currByte = *(src += bitOffset / 8); | 212 currByte = *(src += bitOffset / 8); |
| 188 index = (currByte >> (8 - bpp - bitIndex)) & mask; | 213 index = (currByte >> (8 - bpp - bitIndex)) & mask; |
| 189 dst[x] = ctable[index]; | 214 dst[x] = ctable[index]; |
| 190 } | 215 } |
| 191 } | 216 } |
| 192 | 217 |
| 193 // kIndex | 218 // kIndex |
| 194 | 219 |
| 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( | 220 static void swizzle_index_to_n32( |
| 212 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 221 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 213 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 222 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 214 | 223 |
| 215 src += offset; | 224 src += offset; |
| 216 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 225 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 217 for (int x = 0; x < dstWidth; x++) { | 226 for (int x = 0; x < dstWidth; x++) { |
| 218 SkPMColor c = ctable[*src]; | 227 SkPMColor c = ctable[*src]; |
| 219 dst[x] = c; | 228 dst[x] = c; |
| 220 src += deltaSrc; | 229 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[]) { | 263 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 255 | 264 |
| 256 src += offset; | 265 src += offset; |
| 257 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 266 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 258 for (int x = 0; x < dstWidth; x++) { | 267 for (int x = 0; x < dstWidth; x++) { |
| 259 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); | 268 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); |
| 260 src += deltaSrc; | 269 src += deltaSrc; |
| 261 } | 270 } |
| 262 } | 271 } |
| 263 | 272 |
| 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( | 273 static void swizzle_gray_to_565( |
| 281 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 274 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 282 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 275 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 283 | 276 |
| 284 src += offset; | 277 src += offset; |
| 285 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 278 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 286 for (int x = 0; x < dstWidth; x++) { | 279 for (int x = 0; x < dstWidth; x++) { |
| 287 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); | 280 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); |
| 288 src += deltaSrc; | 281 src += deltaSrc; |
| 289 } | 282 } |
| 290 } | 283 } |
| 291 | 284 |
| 292 // kBGRX | 285 // kBGRX |
| 293 | 286 |
| 294 static void swizzle_bgrx_to_n32( | 287 static void swizzle_bgrx_to_n32( |
| 295 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 288 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 296 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 289 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 297 | 290 |
| 298 src += offset; | 291 src += offset; |
| 299 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 292 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 300 for (int x = 0; x < dstWidth; x++) { | 293 for (int x = 0; x < dstWidth; x++) { |
| 301 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 294 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
| 302 src += deltaSrc; | 295 src += deltaSrc; |
| 303 } | 296 } |
| 304 } | 297 } |
| 305 | 298 |
| 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( | 299 static void swizzle_bgrx_to_565( |
| 327 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 300 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 328 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 301 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 329 | 302 |
| 330 src += offset; | 303 src += offset; |
| 331 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 304 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 332 for (int x = 0; x < dstWidth; x++) { | 305 for (int x = 0; x < dstWidth; x++) { |
| 333 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); | 306 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); |
| 334 src += deltaSrc; | 307 src += deltaSrc; |
| 335 } | 308 } |
| 336 } | 309 } |
| 337 | 310 |
| 338 // kBGRA | 311 // kBGRA |
| 339 | 312 |
| 340 static void swizzle_bgra_to_n32_unpremul( | 313 static void swizzle_bgra_to_n32_unpremul( |
| 341 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 314 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 342 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 315 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 343 | 316 |
| 344 src += offset; | 317 src += offset; |
| 345 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 318 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 346 for (int x = 0; x < dstWidth; x++) { | 319 for (int x = 0; x < dstWidth; x++) { |
| 347 uint8_t alpha = src[3]; | 320 uint8_t alpha = src[3]; |
| 348 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | 321 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
| 349 src += deltaSrc; | 322 src += deltaSrc; |
| 350 } | 323 } |
| 351 } | 324 } |
| 352 | 325 |
| 326 static void fast_swizzle_bgra_to_n32_unpremul( |
| 327 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 328 const SkPMColor ctable[]) { |
| 329 |
| 330 // This function must not be called if we are sampling. If we are not |
| 331 // sampling, deltaSrc should equal bpp. |
| 332 SkASSERT(deltaSrc == bpp); |
| 333 |
| 334 // These swizzles trust that the alpha value is already 0xFF. |
| 335 #ifdef SK_PMCOLOR_IS_RGBA |
| 336 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
); |
| 337 #else |
| 338 memcpy(dst, src + offset, width * bpp); |
| 339 #endif |
| 340 } |
| 341 |
| 353 static void swizzle_bgra_to_n32_premul( | 342 static void swizzle_bgra_to_n32_premul( |
| 354 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 343 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 355 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 344 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 356 | 345 |
| 357 src += offset; | 346 src += offset; |
| 358 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 347 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 359 for (int x = 0; x < dstWidth; x++) { | 348 for (int x = 0; x < dstWidth; x++) { |
| 360 uint8_t alpha = src[3]; | 349 uint8_t alpha = src[3]; |
| 361 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); | 350 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); |
| 362 src += deltaSrc; | 351 src += deltaSrc; |
| 363 } | 352 } |
| 364 } | 353 } |
| 365 | 354 |
| 366 static void fast_swizzle_bgra_to_n32_premul( | 355 static void fast_swizzle_bgra_to_n32_premul( |
| 367 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 356 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 368 const SkPMColor ctable[]) { | 357 const SkPMColor ctable[]) { |
| 369 | 358 |
| 370 // This function must not be called if we are sampling. If we are not | 359 // This function must not be called if we are sampling. If we are not |
| 371 // sampling, deltaSrc should equal bpp. | 360 // sampling, deltaSrc should equal bpp. |
| 372 SkASSERT(deltaSrc == bpp); | 361 SkASSERT(deltaSrc == bpp); |
| 373 | 362 |
| 374 #ifdef SK_PMCOLOR_IS_RGBA | 363 #ifdef SK_PMCOLOR_IS_RGBA |
| 375 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset)
, width); | 364 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset)
, width); |
| 376 #else | 365 #else |
| 377 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
); | 366 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
); |
| 378 #endif | 367 #endif |
| 379 } | 368 } |
| 380 | 369 |
| 381 // kRGBX | 370 // kRGB |
| 382 | 371 |
| 383 static void swizzle_rgbx_to_n32( | 372 static void swizzle_rgb_to_n32( |
| 384 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 385 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 386 | 375 |
| 387 src += offset; | 376 src += offset; |
| 388 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 389 for (int x = 0; x < dstWidth; x++) { | 378 for (int x = 0; x < dstWidth; x++) { |
| 390 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 379 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
| 391 src += deltaSrc; | 380 src += deltaSrc; |
| 392 } | 381 } |
| 393 } | 382 } |
| 394 | 383 |
| 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 | 384 |
| 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 | 385 |
| 403 // The default swizzle supports RGB->N32 and RGBX->N32. This only | 386 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, | 387 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 417 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 388 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 418 | 389 |
| 419 src += offset; | 390 src += offset; |
| 420 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 391 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 421 for (int x = 0; x < dstWidth; x++) { | 392 for (int x = 0; x < dstWidth; x++) { |
| 422 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 393 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
| 423 src += deltaSrc; | 394 src += deltaSrc; |
| 424 } | 395 } |
| 425 } | 396 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 431 |
| 461 src += offset; | 432 src += offset; |
| 462 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 433 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| 463 for (int x = 0; x < dstWidth; x++) { | 434 for (int x = 0; x < dstWidth; x++) { |
| 464 unsigned alpha = src[3]; | 435 unsigned alpha = src[3]; |
| 465 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 436 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
| 466 src += deltaSrc; | 437 src += deltaSrc; |
| 467 } | 438 } |
| 468 } | 439 } |
| 469 | 440 |
| 441 static void fast_swizzle_rgba_to_n32_unpremul( |
| 442 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 443 const SkPMColor ctable[]) { |
| 444 |
| 445 // This function must not be called if we are sampling. If we are not |
| 446 // sampling, deltaSrc should equal bpp. |
| 447 SkASSERT(deltaSrc == bpp); |
| 448 |
| 449 // These swizzles trust that the alpha value is already 0xFF. |
| 450 #ifdef SK_PMCOLOR_IS_RGBA |
| 451 memcpy(dst, src + offset, width * bpp); |
| 452 #else |
| 453 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
); |
| 454 #endif |
| 455 } |
| 456 |
| 470 // kCMYK | 457 // kCMYK |
| 471 // | 458 // |
| 472 // CMYK is stored as four bytes per pixel. | 459 // CMYK is stored as four bytes per pixel. |
| 473 // | 460 // |
| 474 // We will implement a crude conversion from CMYK -> RGB using formulas | 461 // We will implement a crude conversion from CMYK -> RGB using formulas |
| 475 // from easyrgb.com. | 462 // from easyrgb.com. |
| 476 // | 463 // |
| 477 // CMYK -> CMY | 464 // CMYK -> CMY |
| 478 // C = C * (1 - K) + K | 465 // C = C * (1 - K) + K |
| 479 // M = M * (1 - K) + K | 466 // M = M * (1 - K) + K |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 break; | 610 break; |
| 624 } else { | 611 } else { |
| 625 proc = &swizzle_index_to_n32; | 612 proc = &swizzle_index_to_n32; |
| 626 break; | 613 break; |
| 627 } | 614 } |
| 628 break; | 615 break; |
| 629 case kRGB_565_SkColorType: | 616 case kRGB_565_SkColorType: |
| 630 proc = &swizzle_index_to_565; | 617 proc = &swizzle_index_to_565; |
| 631 break; | 618 break; |
| 632 case kIndex_8_SkColorType: | 619 case kIndex_8_SkColorType: |
| 633 proc = &swizzle_index_to_index; | 620 proc = &sample1; |
| 621 fastProc = © |
| 634 break; | 622 break; |
| 635 default: | 623 default: |
| 636 break; | 624 break; |
| 637 } | 625 } |
| 638 break; | 626 break; |
| 639 case kGray: | 627 case kGray: |
| 640 switch (dstInfo.colorType()) { | 628 switch (dstInfo.colorType()) { |
| 641 case kN32_SkColorType: | 629 case kN32_SkColorType: |
| 642 proc = &swizzle_gray_to_n32; | 630 proc = &swizzle_gray_to_n32; |
| 643 break; | 631 break; |
| 644 case kGray_8_SkColorType: | 632 case kGray_8_SkColorType: |
| 645 proc = &swizzle_gray_to_gray; | 633 proc = &sample1; |
| 634 fastProc = © |
| 646 break; | 635 break; |
| 647 case kRGB_565_SkColorType: | 636 case kRGB_565_SkColorType: |
| 648 proc = &swizzle_gray_to_565; | 637 proc = &swizzle_gray_to_565; |
| 649 break; | 638 break; |
| 650 default: | 639 default: |
| 651 break; | 640 break; |
| 652 } | 641 } |
| 653 break; | 642 break; |
| 654 case kBGR: | 643 case kBGR: |
| 655 case kBGRX: | 644 case kBGRX: |
| 656 switch (dstInfo.colorType()) { | 645 switch (dstInfo.colorType()) { |
| 657 case kN32_SkColorType: | 646 case kN32_SkColorType: |
| 658 proc = &swizzle_bgrx_to_n32; | 647 proc = &swizzle_bgrx_to_n32; |
| 659 break; | 648 break; |
| 660 case kRGB_565_SkColorType: | 649 case kRGB_565_SkColorType: |
| 661 proc = &swizzle_bgrx_to_565; | 650 proc = &swizzle_bgrx_to_565; |
| 662 break; | 651 break; |
| 663 default: | 652 default: |
| 664 break; | 653 break; |
| 665 } | 654 } |
| 666 break; | 655 break; |
| 667 case kBGRA: | 656 case kBGRA: |
| 668 switch (dstInfo.colorType()) { | 657 switch (dstInfo.colorType()) { |
| 669 case kN32_SkColorType: | 658 case kN32_SkColorType: |
| 670 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 659 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 671 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 660 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 672 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
_unpremul>; | 661 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
_unpremul>; |
| 673 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
rx_to_32>; | 662 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
ra_to_n32_unpremul>; |
| 674 } else { | 663 } else { |
| 675 proc = &swizzle_bgra_to_n32_unpremul; | 664 proc = &swizzle_bgra_to_n32_unpremul; |
| 676 fastProc = &fast_swizzle_bgrx_to_32; | 665 fastProc = &fast_swizzle_bgra_to_n32_unpremul; |
| 677 } | 666 } |
| 678 } else { | 667 } else { |
| 679 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 668 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 680 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
_premul>; | 669 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
_premul>; |
| 681 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
ra_to_n32_premul>; | 670 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
ra_to_n32_premul>; |
| 682 } else { | 671 } else { |
| 683 proc = &swizzle_bgra_to_n32_premul; | 672 proc = &swizzle_bgra_to_n32_premul; |
| 684 fastProc = &fast_swizzle_bgra_to_n32_premul; | 673 fastProc = &fast_swizzle_bgra_to_n32_premul; |
| 685 } | 674 } |
| 686 } | 675 } |
| 687 break; | 676 break; |
| 688 default: | 677 default: |
| 689 break; | 678 break; |
| 690 } | 679 } |
| 691 break; | 680 break; |
| 692 case kRGBX: | 681 case kRGB: |
| 693 switch (dstInfo.colorType()) { | 682 switch (dstInfo.colorType()) { |
| 694 case kN32_SkColorType: | 683 case kN32_SkColorType: |
| 695 proc = &swizzle_rgbx_to_n32; | 684 proc = &swizzle_rgb_to_n32; |
| 696 fastProc = &fast_swizzle_rgbx_to_32; | |
| 697 break; | 685 break; |
| 698 case kRGB_565_SkColorType: | 686 case kRGB_565_SkColorType: |
| 699 proc = &swizzle_rgbx_to_565; | 687 proc = &swizzle_rgb_to_565; |
| 700 default: | 688 default: |
| 701 break; | 689 break; |
| 702 } | 690 } |
| 703 break; | 691 break; |
| 704 case kRGBA: | 692 case kRGBA: |
| 705 switch (dstInfo.colorType()) { | 693 switch (dstInfo.colorType()) { |
| 706 case kN32_SkColorType: | 694 case kN32_SkColorType: |
| 707 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 695 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 708 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 696 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 709 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_unpremul>; | 697 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_unpremul>; |
| 710 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
bx_to_32>; | 698 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_n32_unpremul>; |
| 711 } else { | 699 } else { |
| 712 proc = &swizzle_rgba_to_n32_unpremul; | 700 proc = &swizzle_rgba_to_n32_unpremul; |
| 713 fastProc = &fast_swizzle_rgbx_to_32; | 701 fastProc = &fast_swizzle_rgba_to_n32_unpremul; |
| 714 } | 702 } |
| 715 } else { | 703 } else { |
| 716 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 704 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 717 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_premul>; | 705 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_premul>; |
| 718 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_n32_premul>; | 706 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_n32_premul>; |
| 719 } else { | 707 } else { |
| 720 proc = &swizzle_rgba_to_n32_premul; | 708 proc = &swizzle_rgba_to_n32_premul; |
| 721 fastProc = &fast_swizzle_rgba_to_n32_premul; | 709 fastProc = &fast_swizzle_rgba_to_n32_premul; |
| 722 } | 710 } |
| 723 } | 711 } |
| 724 break; | 712 break; |
| 725 default: | 713 default: |
| 726 break; | 714 break; |
| 727 } | 715 } |
| 728 break; | 716 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: | 717 case kCMYK: |
| 748 switch (dstInfo.colorType()) { | 718 switch (dstInfo.colorType()) { |
| 749 case kN32_SkColorType: | 719 case kN32_SkColorType: |
| 750 proc = &swizzle_cmyk_to_n32; | 720 proc = &swizzle_cmyk_to_n32; |
| 751 break; | 721 break; |
| 752 case kRGB_565_SkColorType: | 722 case kRGB_565_SkColorType: |
| 753 proc = &swizzle_cmyk_to_565; | 723 proc = &swizzle_cmyk_to_565; |
| 754 break; | 724 break; |
| 755 default: | 725 default: |
| 756 break; | 726 break; |
| 757 } | 727 } |
| 758 break; | 728 break; |
| 729 case kNoOp8: |
| 730 proc = &sample1; |
| 731 fastProc = © |
| 732 break; |
| 733 case kNoOp16: |
| 734 proc = sample2; |
| 735 fastProc = © |
| 736 break; |
| 737 case kNoOp32: |
| 738 proc = &sample4; |
| 739 fastProc = © |
| 740 break; |
| 759 default: | 741 default: |
| 760 break; | 742 break; |
| 761 } | 743 } |
| 762 | 744 |
| 763 // Store bpp in bytes if it is an even multiple, otherwise use bits | 745 // Store bpp in bytes if it is an even multiple, otherwise use bits |
| 764 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel
(sc); | 746 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel
(sc); |
| 765 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); | 747 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); |
| 766 | 748 |
| 767 int srcOffset = 0; | 749 int srcOffset = 0; |
| 768 int srcWidth = dstInfo.width(); | 750 int srcWidth = dstInfo.width(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 | 798 |
| 817 return fAllocatedWidth; | 799 return fAllocatedWidth; |
| 818 } | 800 } |
| 819 | 801 |
| 820 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 802 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| 821 SkASSERT(nullptr != dst && nullptr != src); | 803 SkASSERT(nullptr != dst && nullptr != src); |
| 822 RowProc proc = fFastProc ? fFastProc : fProc; | 804 RowProc proc = fFastProc ? fFastProc : fProc; |
| 823 proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, | 805 proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, |
| 824 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 806 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| 825 } | 807 } |
| OLD | NEW |