OLD | NEW |
1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // This code is licensed under the same terms as WebM: | 3 // This code is licensed under the same terms as WebM: |
4 // Software License Agreement: http://www.webmproject.org/license/software/ | 4 // Software License Agreement: http://www.webmproject.org/license/software/ |
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ | 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
6 // ----------------------------------------------------------------------------- | 6 // ----------------------------------------------------------------------------- |
7 // | 7 // |
8 // YUV to RGB upsampling functions. | 8 // YUV to RGB upsampling functions. |
9 // | 9 // |
10 // Author: somnath@google.com (Somnath Banerjee) | 10 // Author: somnath@google.com (Somnath Banerjee) |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 264 } |
265 } | 265 } |
266 rgba += stride; | 266 rgba += stride; |
267 } | 267 } |
268 } | 268 } |
269 #undef MULTIPLIER | 269 #undef MULTIPLIER |
270 #undef PREMULTIPLY | 270 #undef PREMULTIPLY |
271 | 271 |
272 // rgbA4444 | 272 // rgbA4444 |
273 | 273 |
274 #define MULTIPLIER(a) ((a) * 0x11) | 274 #define MULTIPLIER(a) ((a) * 0x1111) // 0x1111 ~= (1 << 16) / 15 |
275 #define PREMULTIPLY(x, m) (((x) * (m)) >> 12) | |
276 | 275 |
277 static WEBP_INLINE uint8_t dither_hi(uint8_t x) { | 276 static WEBP_INLINE uint8_t dither_hi(uint8_t x) { |
278 return (x & 0xf0) | (x >> 4); | 277 return (x & 0xf0) | (x >> 4); |
279 } | 278 } |
280 | 279 |
281 static WEBP_INLINE uint8_t dither_lo(uint8_t x) { | 280 static WEBP_INLINE uint8_t dither_lo(uint8_t x) { |
282 return (x & 0x0f) | (x << 4); | 281 return (x & 0x0f) | (x << 4); |
283 } | 282 } |
284 | 283 |
| 284 static WEBP_INLINE uint8_t multiply(uint8_t x, uint32_t m) { |
| 285 return (x * m) >> 16; |
| 286 } |
| 287 |
285 static void ApplyAlphaMultiply4444(uint8_t* rgba4444, | 288 static void ApplyAlphaMultiply4444(uint8_t* rgba4444, |
286 int w, int h, int stride) { | 289 int w, int h, int stride) { |
287 while (h-- > 0) { | 290 while (h-- > 0) { |
288 int i; | 291 int i; |
289 for (i = 0; i < w; ++i) { | 292 for (i = 0; i < w; ++i) { |
290 const uint8_t a = dither_lo(rgba4444[2 * i + 1]); | 293 const uint8_t a = (rgba4444[2 * i + 1] & 0x0f); |
291 const uint32_t mult = MULTIPLIER(a); | 294 const uint32_t mult = MULTIPLIER(a); |
292 const uint8_t r = PREMULTIPLY(dither_hi(rgba4444[2 * i + 0]), mult); | 295 const uint8_t r = multiply(dither_hi(rgba4444[2 * i + 0]), mult); |
293 const uint8_t g = PREMULTIPLY(dither_lo(rgba4444[2 * i + 0]), mult); | 296 const uint8_t g = multiply(dither_lo(rgba4444[2 * i + 0]), mult); |
294 const uint8_t b = PREMULTIPLY(dither_hi(rgba4444[2 * i + 1]), mult); | 297 const uint8_t b = multiply(dither_hi(rgba4444[2 * i + 1]), mult); |
295 rgba4444[2 * i + 0] = (r & 0xf0) | (g & 0x0f); | 298 rgba4444[2 * i + 0] = (r & 0xf0) | ((g >> 4) & 0x0f); |
296 rgba4444[2 * i + 1] = (b & 0xf0) | a; | 299 rgba4444[2 * i + 1] = (b & 0xf0) | a; |
297 } | 300 } |
298 rgba4444 += stride; | 301 rgba4444 += stride; |
299 } | 302 } |
300 } | 303 } |
301 #undef MULTIPLIER | 304 #undef MULTIPLIER |
302 #undef PREMULTIPLY | |
303 | 305 |
304 void (*WebPApplyAlphaMultiply)(uint8_t*, int, int, int, int) | 306 void (*WebPApplyAlphaMultiply)(uint8_t*, int, int, int, int) |
305 = ApplyAlphaMultiply; | 307 = ApplyAlphaMultiply; |
306 void (*WebPApplyAlphaMultiply4444)(uint8_t*, int, int, int) | 308 void (*WebPApplyAlphaMultiply4444)(uint8_t*, int, int, int) |
307 = ApplyAlphaMultiply4444; | 309 = ApplyAlphaMultiply4444; |
308 | 310 |
309 //------------------------------------------------------------------------------ | 311 //------------------------------------------------------------------------------ |
310 // Main call | 312 // Main call |
311 | 313 |
312 void WebPInitUpsamplers(void) { | 314 void WebPInitUpsamplers(void) { |
313 #ifdef FANCY_UPSAMPLING | 315 #ifdef FANCY_UPSAMPLING |
314 WebPUpsamplers[MODE_RGB] = UpsampleRgbLinePair; | 316 WebPUpsamplers[MODE_RGB] = UpsampleRgbLinePair; |
315 WebPUpsamplers[MODE_RGBA] = UpsampleRgbaLinePair; | 317 WebPUpsamplers[MODE_RGBA] = UpsampleRgbaLinePair; |
316 WebPUpsamplers[MODE_BGR] = UpsampleBgrLinePair; | 318 WebPUpsamplers[MODE_BGR] = UpsampleBgrLinePair; |
317 WebPUpsamplers[MODE_BGRA] = UpsampleBgraLinePair; | 319 WebPUpsamplers[MODE_BGRA] = UpsampleBgraLinePair; |
318 WebPUpsamplers[MODE_ARGB] = UpsampleArgbLinePair; | 320 WebPUpsamplers[MODE_ARGB] = UpsampleArgbLinePair; |
319 WebPUpsamplers[MODE_RGBA_4444] = UpsampleRgba4444LinePair; | 321 WebPUpsamplers[MODE_RGBA_4444] = UpsampleRgba4444LinePair; |
320 WebPUpsamplers[MODE_RGB_565] = UpsampleRgb565LinePair; | 322 WebPUpsamplers[MODE_RGB_565] = UpsampleRgb565LinePair; |
321 | 323 |
322 // If defined, use CPUInfo() to overwrite some pointers with faster versions. | 324 // If defined, use CPUInfo() to overwrite some pointers with faster versions. |
323 if (VP8GetCPUInfo != NULL) { | 325 if (VP8GetCPUInfo != NULL) { |
324 #if defined(WEBP_USE_SSE2) | 326 #if defined(WEBP_USE_SSE2) |
325 if (VP8GetCPUInfo(kSSE2)) { | 327 if (VP8GetCPUInfo(kSSE2)) { |
326 WebPInitUpsamplersSSE2(); | 328 WebPInitUpsamplersSSE2(); |
327 } | 329 } |
328 #endif | 330 #endif |
| 331 #if defined(WEBP_USE_NEON) |
| 332 if (VP8GetCPUInfo(kNEON)) { |
| 333 WebPInitUpsamplersNEON(); |
| 334 } |
| 335 #endif |
329 } | 336 } |
330 #endif // FANCY_UPSAMPLING | 337 #endif // FANCY_UPSAMPLING |
331 } | 338 } |
332 | 339 |
333 void WebPInitPremultiply(void) { | 340 void WebPInitPremultiply(void) { |
334 WebPApplyAlphaMultiply = ApplyAlphaMultiply; | 341 WebPApplyAlphaMultiply = ApplyAlphaMultiply; |
335 WebPApplyAlphaMultiply4444 = ApplyAlphaMultiply4444; | 342 WebPApplyAlphaMultiply4444 = ApplyAlphaMultiply4444; |
336 | 343 |
337 #ifdef FANCY_UPSAMPLING | 344 #ifdef FANCY_UPSAMPLING |
338 WebPUpsamplers[MODE_rgbA] = UpsampleRgbaLinePair; | 345 WebPUpsamplers[MODE_rgbA] = UpsampleRgbaLinePair; |
339 WebPUpsamplers[MODE_bgrA] = UpsampleBgraLinePair; | 346 WebPUpsamplers[MODE_bgrA] = UpsampleBgraLinePair; |
340 WebPUpsamplers[MODE_Argb] = UpsampleArgbLinePair; | 347 WebPUpsamplers[MODE_Argb] = UpsampleArgbLinePair; |
341 WebPUpsamplers[MODE_rgbA_4444] = UpsampleRgba4444LinePair; | 348 WebPUpsamplers[MODE_rgbA_4444] = UpsampleRgba4444LinePair; |
342 | 349 |
343 if (VP8GetCPUInfo != NULL) { | 350 if (VP8GetCPUInfo != NULL) { |
344 #if defined(WEBP_USE_SSE2) | 351 #if defined(WEBP_USE_SSE2) |
345 if (VP8GetCPUInfo(kSSE2)) { | 352 if (VP8GetCPUInfo(kSSE2)) { |
346 WebPInitPremultiplySSE2(); | 353 WebPInitPremultiplySSE2(); |
347 } | 354 } |
348 #endif | 355 #endif |
| 356 #if defined(WEBP_USE_NEON) |
| 357 if (VP8GetCPUInfo(kNEON)) { |
| 358 WebPInitPremultiplyNEON(); |
| 359 } |
| 360 #endif |
349 } | 361 } |
350 #endif // FANCY_UPSAMPLING | 362 #endif // FANCY_UPSAMPLING |
351 } | 363 } |
352 | 364 |
353 #if defined(__cplusplus) || defined(c_plusplus) | 365 #if defined(__cplusplus) || defined(c_plusplus) |
354 } // extern "C" | 366 } // extern "C" |
355 #endif | 367 #endif |
OLD | NEW |