Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This webpage shows layout of YV12 and other YUV formats | 5 // This webpage shows layout of YV12 and other YUV formats |
| 6 // http://www.fourcc.org/yuv.php | 6 // http://www.fourcc.org/yuv.php |
| 7 // The actual conversion is best described here | 7 // The actual conversion is best described here |
| 8 // http://en.wikipedia.org/wiki/YUV | 8 // http://en.wikipedia.org/wiki/YUV |
| 9 // An article on optimizing YUV conversion using tables instead of multiplies | 9 // An article on optimizing YUV conversion using tables instead of multiplies |
| 10 // http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf | 10 // http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf |
| 11 // | 11 // |
| 12 // YV12 is a full plane of Y and a half height, half width chroma planes | 12 // YV12 is a full plane of Y and a half height, half width chroma planes |
| 13 // YV16 is a full plane of Y and a full height, half width chroma planes | 13 // YV16 is a full plane of Y and a full height, half width chroma planes |
| 14 // | 14 // |
| 15 // ARGB pixel format is output, which on little endian is stored as BGRA. | 15 // ARGB pixel format is output, which on little endian is stored as BGRA. |
| 16 // The alpha is set to 255, allowing the application to use RGBA or RGB32. | 16 // The alpha is set to 255, allowing the application to use RGBA or RGB32. |
| 17 | 17 |
| 18 #include "media/base/yuv_convert.h" | 18 #include "media/base/yuv_convert.h" |
| 19 | 19 |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "media/base/cpu_features.h" | 21 #include "media/base/cpu_features.h" |
| 22 #include "media/base/simd/yuv_convert.h" | |
| 22 #include "media/base/yuv_convert_internal.h" | 23 #include "media/base/yuv_convert_internal.h" |
| 23 #include "media/base/yuv_row.h" | 24 #include "media/base/yuv_row.h" |
| 24 | 25 |
| 25 #if USE_MMX | 26 #if USE_MMX |
| 26 #if defined(_MSC_VER) | 27 #if defined(_MSC_VER) |
| 27 #include <intrin.h> | 28 #include <intrin.h> |
| 28 #else | 29 #else |
| 29 #include <mmintrin.h> | 30 #include <mmintrin.h> |
| 30 #endif | 31 #endif |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 #if USE_SSE2 | 34 #if USE_SSE2 |
| 34 #include <emmintrin.h> | 35 #include <emmintrin.h> |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 38 #define USE_YASM | |
|
Alpha Left Google
2011/08/22 14:16:59
It's better not to use this #ifdef.
| |
| 39 | |
| 37 namespace media { | 40 namespace media { |
| 38 | 41 |
| 39 // 16.16 fixed point arithmetic | 42 // 16.16 fixed point arithmetic |
| 40 const int kFractionBits = 16; | 43 const int kFractionBits = 16; |
| 41 const int kFractionMax = 1 << kFractionBits; | 44 const int kFractionMax = 1 << kFractionBits; |
| 42 const int kFractionMask = ((1 << kFractionBits) - 1); | 45 const int kFractionMask = ((1 << kFractionBits) - 1); |
| 43 | 46 |
| 44 // Convert a frame of YUV to 32 bit ARGB. | 47 // Convert a frame of YUV to 32 bit ARGB. |
| 45 void ConvertYUVToRGB32(const uint8* y_buf, | 48 void ConvertYUVToRGB32(const uint8* y_buf, |
| 46 const uint8* u_buf, | 49 const uint8* u_buf, |
| 47 const uint8* v_buf, | 50 const uint8* v_buf, |
| 48 uint8* rgb_buf, | 51 uint8* rgb_buf, |
| 49 int width, | 52 int width, |
| 50 int height, | 53 int height, |
| 51 int y_pitch, | 54 int y_pitch, |
| 52 int uv_pitch, | 55 int uv_pitch, |
| 53 int rgb_pitch, | 56 int rgb_pitch, |
| 54 YUVType yuv_type) { | 57 YUVType yuv_type) { |
| 58 #ifdef USE_YASM | |
|
Alpha Left Google
2011/08/22 14:16:59
There seems to be a slow down using this new YUV->
| |
| 59 if (hasSSE2()) { | |
| 60 simd::ConvertYUVtoRGB32(y_buf, u_buf, v_buf, rgb_buf, width, height, | |
| 61 y_pitch, uv_pitch, rgb_pitch, yuv_type); | |
| 62 return; | |
| 63 } | |
| 64 #endif | |
| 65 | |
| 55 unsigned int y_shift = yuv_type; | 66 unsigned int y_shift = yuv_type; |
| 56 for (int y = 0; y < height; ++y) { | 67 for (int y = 0; y < height; ++y) { |
| 57 uint8* rgb_row = rgb_buf + y * rgb_pitch; | 68 uint8* rgb_row = rgb_buf + y * rgb_pitch; |
| 58 const uint8* y_ptr = y_buf + y * y_pitch; | 69 const uint8* y_ptr = y_buf + y * y_pitch; |
| 59 const uint8* u_ptr = u_buf + (y >> y_shift) * uv_pitch; | 70 const uint8* u_ptr = u_buf + (y >> y_shift) * uv_pitch; |
| 60 const uint8* v_ptr = v_buf + (y >> y_shift) * uv_pitch; | 71 const uint8* v_ptr = v_buf + (y >> y_shift) * uv_pitch; |
| 61 | 72 |
| 62 FastConvertYUVToRGB32Row(y_ptr, | 73 FastConvertYUVToRGB32Row(y_ptr, |
| 63 u_ptr, | 74 u_ptr, |
| 64 v_ptr, | 75 v_ptr, |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 int uvstride) { | 371 int uvstride) { |
| 361 static void (*convert_proc)(const uint8*, uint8*, uint8*, uint8*, | 372 static void (*convert_proc)(const uint8*, uint8*, uint8*, uint8*, |
| 362 int, int, int, int, int) = NULL; | 373 int, int, int, int, int) = NULL; |
| 363 if (!convert_proc) { | 374 if (!convert_proc) { |
| 364 #if defined(ARCH_CPU_ARM_FAMILY) | 375 #if defined(ARCH_CPU_ARM_FAMILY) |
| 365 // For ARM processors, always use C version. | 376 // For ARM processors, always use C version. |
| 366 // TODO(hclam): Implement a NEON version. | 377 // TODO(hclam): Implement a NEON version. |
| 367 convert_proc = &ConvertRGB32ToYUV_C; | 378 convert_proc = &ConvertRGB32ToYUV_C; |
| 368 #else | 379 #else |
| 369 // For x86 processors, check if SSE2 is supported. | 380 // For x86 processors, check if SSE2 is supported. |
| 370 if (hasSSE2()) | 381 if (hasSSE2()) |
|
Alpha Left Google
2011/08/22 14:16:59
if hasSSE2() compiles on all platform we can get r
| |
| 382 #ifdef USE_YASM | |
|
Alpha Left Google
2011/08/22 14:16:59
Don't use an ifdef, just apply the new function.
| |
| 383 convert_proc = &simd::ConvertRGB32toYUV; | |
| 384 #else | |
| 371 convert_proc = &ConvertRGB32ToYUV_SSE2; | 385 convert_proc = &ConvertRGB32ToYUV_SSE2; |
|
Alpha Left Google
2011/08/22 14:16:59
Remove this line.
| |
| 386 #endif | |
| 372 else | 387 else |
| 373 convert_proc = &ConvertRGB32ToYUV_C; | 388 convert_proc = &ConvertRGB32ToYUV_C; |
| 374 #endif | 389 #endif |
| 375 } | 390 } |
| 376 | 391 |
| 377 convert_proc(rgbframe, yplane, uplane, vplane, width, height, | 392 convert_proc(rgbframe, yplane, uplane, vplane, width, height, |
| 378 rgbstride, ystride, uvstride); | 393 rgbstride, ystride, uvstride); |
| 379 } | 394 } |
| 380 | 395 |
| 381 void ConvertRGB24ToYUV(const uint8* rgbframe, | 396 void ConvertRGB24ToYUV(const uint8* rgbframe, |
| 382 uint8* yplane, | 397 uint8* yplane, |
| 383 uint8* uplane, | 398 uint8* uplane, |
| 384 uint8* vplane, | 399 uint8* vplane, |
| 385 int width, | 400 int width, |
| 386 int height, | 401 int height, |
| 387 int rgbstride, | 402 int rgbstride, |
| 388 int ystride, | 403 int ystride, |
| 389 int uvstride) { | 404 int uvstride) { |
| 405 #ifdef USE_YASM | |
|
Alpha Left Google
2011/08/22 14:16:59
Same here use if without ifdef. Also because with
| |
| 406 if (hasSSE2()) { | |
| 407 simd::ConvertRGB24toYUV(rgbframe, yplane, uplane, vplane, width, height, | |
| 408 rgbstride, ystride, uvstride); | |
| 409 return; | |
| 410 } | |
| 411 #endif | |
| 390 ConvertRGB24ToYUV_C(rgbframe, yplane, uplane, vplane, width, height, | 412 ConvertRGB24ToYUV_C(rgbframe, yplane, uplane, vplane, width, height, |
| 391 rgbstride, ystride, uvstride); | 413 rgbstride, ystride, uvstride); |
| 392 } | 414 } |
| 393 | 415 |
| 394 void ConvertYUY2ToYUV(const uint8* src, | 416 void ConvertYUY2ToYUV(const uint8* src, |
| 395 uint8* yplane, | 417 uint8* yplane, |
| 396 uint8* uplane, | 418 uint8* uplane, |
| 397 uint8* vplane, | 419 uint8* vplane, |
| 398 int width, | 420 int width, |
| 399 int height) { | 421 int height) { |
| 400 ConvertYUY2ToYUV_C(src, yplane, uplane, vplane, width, height); | 422 ConvertYUY2ToYUV_C(src, yplane, uplane, vplane, width, height); |
| 401 } | 423 } |
| 402 } // namespace media | 424 } // namespace media |
| OLD | NEW |