| OLD | NEW |
| 1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
| 4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
| 5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // Utilities for processing transparent channel. | 10 // Utilities for processing transparent channel. |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 static void ApplyAlphaMultiply_16b(uint8_t* rgba4444, | 278 static void ApplyAlphaMultiply_16b(uint8_t* rgba4444, |
| 279 int w, int h, int stride) { | 279 int w, int h, int stride) { |
| 280 #ifdef WEBP_SWAP_16BIT_CSP | 280 #ifdef WEBP_SWAP_16BIT_CSP |
| 281 ApplyAlphaMultiply4444(rgba4444, w, h, stride, 1); | 281 ApplyAlphaMultiply4444(rgba4444, w, h, stride, 1); |
| 282 #else | 282 #else |
| 283 ApplyAlphaMultiply4444(rgba4444, w, h, stride, 0); | 283 ApplyAlphaMultiply4444(rgba4444, w, h, stride, 0); |
| 284 #endif | 284 #endif |
| 285 } | 285 } |
| 286 | 286 |
| 287 static int DispatchAlpha(const uint8_t* alpha, int alpha_stride, | 287 static int DispatchAlpha_C(const uint8_t* alpha, int alpha_stride, |
| 288 int width, int height, | 288 int width, int height, |
| 289 uint8_t* dst, int dst_stride) { | 289 uint8_t* dst, int dst_stride) { |
| 290 uint32_t alpha_mask = 0xff; | 290 uint32_t alpha_mask = 0xff; |
| 291 int i, j; | 291 int i, j; |
| 292 | 292 |
| 293 for (j = 0; j < height; ++j) { | 293 for (j = 0; j < height; ++j) { |
| 294 for (i = 0; i < width; ++i) { | 294 for (i = 0; i < width; ++i) { |
| 295 const uint32_t alpha_value = alpha[i]; | 295 const uint32_t alpha_value = alpha[i]; |
| 296 dst[4 * i] = alpha_value; | 296 dst[4 * i] = alpha_value; |
| 297 alpha_mask &= alpha_value; | 297 alpha_mask &= alpha_value; |
| 298 } | 298 } |
| 299 alpha += alpha_stride; | 299 alpha += alpha_stride; |
| 300 dst += dst_stride; | 300 dst += dst_stride; |
| 301 } | 301 } |
| 302 | 302 |
| 303 return (alpha_mask != 0xff); | 303 return (alpha_mask != 0xff); |
| 304 } | 304 } |
| 305 | 305 |
| 306 static void DispatchAlphaToGreen(const uint8_t* alpha, int alpha_stride, | 306 static void DispatchAlphaToGreen_C(const uint8_t* alpha, int alpha_stride, |
| 307 int width, int height, | 307 int width, int height, |
| 308 uint32_t* dst, int dst_stride) { | 308 uint32_t* dst, int dst_stride) { |
| 309 int i, j; | 309 int i, j; |
| 310 for (j = 0; j < height; ++j) { | 310 for (j = 0; j < height; ++j) { |
| 311 for (i = 0; i < width; ++i) { | 311 for (i = 0; i < width; ++i) { |
| 312 dst[i] = alpha[i] << 8; // leave A/R/B channels zero'd. | 312 dst[i] = alpha[i] << 8; // leave A/R/B channels zero'd. |
| 313 } | 313 } |
| 314 alpha += alpha_stride; | 314 alpha += alpha_stride; |
| 315 dst += dst_stride; | 315 dst += dst_stride; |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 static int ExtractAlpha(const uint8_t* argb, int argb_stride, | 319 static int ExtractAlpha_C(const uint8_t* argb, int argb_stride, |
| 320 int width, int height, | 320 int width, int height, |
| 321 uint8_t* alpha, int alpha_stride) { | 321 uint8_t* alpha, int alpha_stride) { |
| 322 uint8_t alpha_mask = 0xff; | 322 uint8_t alpha_mask = 0xff; |
| 323 int i, j; | 323 int i, j; |
| 324 | 324 |
| 325 for (j = 0; j < height; ++j) { | 325 for (j = 0; j < height; ++j) { |
| 326 for (i = 0; i < width; ++i) { | 326 for (i = 0; i < width; ++i) { |
| 327 const uint8_t alpha_value = argb[4 * i]; | 327 const uint8_t alpha_value = argb[4 * i]; |
| 328 alpha[i] = alpha_value; | 328 alpha[i] = alpha_value; |
| 329 alpha_mask &= alpha_value; | 329 alpha_mask &= alpha_value; |
| 330 } | 330 } |
| 331 argb += argb_stride; | 331 argb += argb_stride; |
| 332 alpha += alpha_stride; | 332 alpha += alpha_stride; |
| 333 } | 333 } |
| 334 return (alpha_mask == 0xff); | 334 return (alpha_mask == 0xff); |
| 335 } | 335 } |
| 336 | 336 |
| 337 static void ExtractGreen_C(const uint32_t* argb, uint8_t* alpha, int size) { |
| 338 int i; |
| 339 for (i = 0; i < size; ++i) alpha[i] = argb[i] >> 8; |
| 340 } |
| 341 |
| 337 void (*WebPApplyAlphaMultiply)(uint8_t*, int, int, int, int); | 342 void (*WebPApplyAlphaMultiply)(uint8_t*, int, int, int, int); |
| 338 void (*WebPApplyAlphaMultiply4444)(uint8_t*, int, int, int); | 343 void (*WebPApplyAlphaMultiply4444)(uint8_t*, int, int, int); |
| 339 int (*WebPDispatchAlpha)(const uint8_t*, int, int, int, uint8_t*, int); | 344 int (*WebPDispatchAlpha)(const uint8_t*, int, int, int, uint8_t*, int); |
| 340 void (*WebPDispatchAlphaToGreen)(const uint8_t*, int, int, int, uint32_t*, int); | 345 void (*WebPDispatchAlphaToGreen)(const uint8_t*, int, int, int, uint32_t*, int); |
| 341 int (*WebPExtractAlpha)(const uint8_t*, int, int, int, uint8_t*, int); | 346 int (*WebPExtractAlpha)(const uint8_t*, int, int, int, uint8_t*, int); |
| 347 void (*WebPExtractGreen)(const uint32_t* argb, uint8_t* alpha, int size); |
| 342 | 348 |
| 343 //------------------------------------------------------------------------------ | 349 //------------------------------------------------------------------------------ |
| 344 // Init function | 350 // Init function |
| 345 | 351 |
| 346 extern void WebPInitAlphaProcessingMIPSdspR2(void); | 352 extern void WebPInitAlphaProcessingMIPSdspR2(void); |
| 347 extern void WebPInitAlphaProcessingSSE2(void); | 353 extern void WebPInitAlphaProcessingSSE2(void); |
| 348 extern void WebPInitAlphaProcessingSSE41(void); | 354 extern void WebPInitAlphaProcessingSSE41(void); |
| 355 extern void WebPInitAlphaProcessingNEON(void); |
| 349 | 356 |
| 350 static volatile VP8CPUInfo alpha_processing_last_cpuinfo_used = | 357 static volatile VP8CPUInfo alpha_processing_last_cpuinfo_used = |
| 351 (VP8CPUInfo)&alpha_processing_last_cpuinfo_used; | 358 (VP8CPUInfo)&alpha_processing_last_cpuinfo_used; |
| 352 | 359 |
| 353 WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) { | 360 WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) { |
| 354 if (alpha_processing_last_cpuinfo_used == VP8GetCPUInfo) return; | 361 if (alpha_processing_last_cpuinfo_used == VP8GetCPUInfo) return; |
| 355 | 362 |
| 356 WebPMultARGBRow = WebPMultARGBRowC; | 363 WebPMultARGBRow = WebPMultARGBRowC; |
| 357 WebPMultRow = WebPMultRowC; | 364 WebPMultRow = WebPMultRowC; |
| 358 WebPApplyAlphaMultiply = ApplyAlphaMultiply; | 365 WebPApplyAlphaMultiply = ApplyAlphaMultiply; |
| 359 WebPApplyAlphaMultiply4444 = ApplyAlphaMultiply_16b; | 366 WebPApplyAlphaMultiply4444 = ApplyAlphaMultiply_16b; |
| 360 WebPDispatchAlpha = DispatchAlpha; | 367 |
| 361 WebPDispatchAlphaToGreen = DispatchAlphaToGreen; | 368 WebPDispatchAlpha = DispatchAlpha_C; |
| 362 WebPExtractAlpha = ExtractAlpha; | 369 WebPDispatchAlphaToGreen = DispatchAlphaToGreen_C; |
| 370 WebPExtractAlpha = ExtractAlpha_C; |
| 371 WebPExtractGreen = ExtractGreen_C; |
| 363 | 372 |
| 364 // If defined, use CPUInfo() to overwrite some pointers with faster versions. | 373 // If defined, use CPUInfo() to overwrite some pointers with faster versions. |
| 365 if (VP8GetCPUInfo != NULL) { | 374 if (VP8GetCPUInfo != NULL) { |
| 366 #if defined(WEBP_USE_SSE2) | 375 #if defined(WEBP_USE_SSE2) |
| 367 if (VP8GetCPUInfo(kSSE2)) { | 376 if (VP8GetCPUInfo(kSSE2)) { |
| 368 WebPInitAlphaProcessingSSE2(); | 377 WebPInitAlphaProcessingSSE2(); |
| 369 #if defined(WEBP_USE_SSE41) | 378 #if defined(WEBP_USE_SSE41) |
| 370 if (VP8GetCPUInfo(kSSE4_1)) { | 379 if (VP8GetCPUInfo(kSSE4_1)) { |
| 371 WebPInitAlphaProcessingSSE41(); | 380 WebPInitAlphaProcessingSSE41(); |
| 372 } | 381 } |
| 373 #endif | 382 #endif |
| 374 } | 383 } |
| 375 #endif | 384 #endif |
| 385 #if defined(WEBP_USE_NEON) |
| 386 if (VP8GetCPUInfo(kNEON)) { |
| 387 WebPInitAlphaProcessingNEON(); |
| 388 } |
| 389 #endif |
| 376 #if defined(WEBP_USE_MIPS_DSP_R2) | 390 #if defined(WEBP_USE_MIPS_DSP_R2) |
| 377 if (VP8GetCPUInfo(kMIPSdspR2)) { | 391 if (VP8GetCPUInfo(kMIPSdspR2)) { |
| 378 WebPInitAlphaProcessingMIPSdspR2(); | 392 WebPInitAlphaProcessingMIPSdspR2(); |
| 379 } | 393 } |
| 380 #endif | 394 #endif |
| 381 } | 395 } |
| 382 alpha_processing_last_cpuinfo_used = VP8GetCPUInfo; | 396 alpha_processing_last_cpuinfo_used = VP8GetCPUInfo; |
| 383 } | 397 } |
| OLD | NEW |