diff options
author | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 01:04:13 +0000 |
---|---|---|
committer | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 01:04:13 +0000 |
commit | 24267bb2ef971593b3b11178320dc4d248940b56 (patch) | |
tree | 40f1c0da0e0f0fcc8ac6406bbb82ff1ecfc44126 /media | |
parent | 4be85a0d5e0f68724f4e44eb560fcd95c21b40e8 (diff) | |
download | chromium_src-24267bb2ef971593b3b11178320dc4d248940b56.zip chromium_src-24267bb2ef971593b3b11178320dc4d248940b56.tar.gz chromium_src-24267bb2ef971593b3b11178320dc4d248940b56.tar.bz2 |
mmx for linux yuv convert function.
BUG=18449,20718
TEST=play a video on linux without scaling and it should go 4 times faster than with scaling.
Review URL: http://codereview.chromium.org/174442
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25001 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/yuv_convert.cc | 2 | ||||
-rw-r--r-- | media/base/yuv_row.h | 13 | ||||
-rw-r--r-- | media/base/yuv_row_linux.cc | 431 | ||||
-rw-r--r-- | media/base/yuv_row_mac.cc | 431 | ||||
-rw-r--r-- | media/base/yuv_row_win.cc | 114 |
5 files changed, 903 insertions, 88 deletions
diff --git a/media/base/yuv_convert.cc b/media/base/yuv_convert.cc index 7e4da5e..c73dfe4 100644 --- a/media/base/yuv_convert.cc +++ b/media/base/yuv_convert.cc @@ -131,7 +131,7 @@ void ScaleYUVToRGB32(const uint8* y_buf, const uint8* u_ptr = u_buf + (scaled_y >> y_shift) * uv_pitch; const uint8* v_ptr = v_buf + (scaled_y >> y_shift) * uv_pitch; -#if USE_MMX +#if USE_MMX && defined(_MSC_VER) if (scaled_width == (width * 2)) { DoubleYUVToRGB32Row(y_ptr, u_ptr, v_ptr, dest_pixel, scaled_width); diff --git a/media/base/yuv_row.h b/media/base/yuv_row.h index b8651f5..bb06722 100644 --- a/media/base/yuv_row.h +++ b/media/base/yuv_row.h @@ -5,13 +5,14 @@ // yuv_row internal functions to handle YUV conversion and scaling to RGB. // These functions are used from both yuv_convert.cc and yuv_scale.cc. +// TODO(fbarchard): Write function that can handle rotation and scaling. + #ifndef MEDIA_BASE_YUV_ROW_H_ #define MEDIA_BASE_YUV_ROW_H_ #include "base/basictypes.h" -namespace media { - +extern "C" { // Can only do 1x. // This is the second fastest of the scalers. void FastConvertYUVToRGB32Row(const uint8* y_buf, @@ -59,11 +60,13 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, uint8* rgb_buf, int width, int scaled_dx); +} // extern "C" -// MMX for Windows; C++ for other platforms. -#ifndef USE_MMX +#if !defined(USE_MMX) #if defined(_MSC_VER) #define USE_MMX 1 +#elif defined(OS_LINUX) && !defined(ARCH_CPU_X86_64) +#define USE_MMX 1 #else #define USE_MMX 0 #endif @@ -79,7 +82,5 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, #define EMMS() #endif -} // namespace media - #endif // MEDIA_BASE_YUV_ROW_H_ diff --git a/media/base/yuv_row_linux.cc b/media/base/yuv_row_linux.cc index eb3d07e..9d567ad 100644 --- a/media/base/yuv_row_linux.cc +++ b/media/base/yuv_row_linux.cc @@ -4,24 +4,435 @@ #include "media/base/yuv_row.h" -// Enable bilinear filtering by turning on the following macro. -// #define MEDIA_BILINEAR_FILTER 1 - #ifdef _DEBUG #include "base/logging.h" #else #define DCHECK(a) #endif -namespace media { +// TODO(fbarchard): Move this to yuv_row_posix.cc to share with Mac. +// TODO(fbarchard): Do 64 bit version. + +extern "C" { +#if USE_MMX + +#define RGBY(i) { \ + static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ + static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ + static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ + 0 \ +} + +#define RGBU(i) { \ + static_cast<int16>(2.018 * 64 * (i - 128) + 0.5), \ + static_cast<int16>(-0.391 * 64 * (i - 128) + 0.5), \ + 0, \ + static_cast<int16>(256 * 64 - 1) \ +} + +#define RGBV(i) { \ + 0, \ + static_cast<int16>(-0.813 * 64 * (i - 128) + 0.5), \ + static_cast<int16>(1.596 * 64 * (i - 128) + 0.5), \ + 0 \ +} + +#define MMX_ALIGNED(var) var __attribute__((aligned(16))) + +MMX_ALIGNED(int16 kCoefficientsRgbY[256][4]) = { + RGBY(0x00), RGBY(0x01), RGBY(0x02), RGBY(0x03), + RGBY(0x04), RGBY(0x05), RGBY(0x06), RGBY(0x07), + RGBY(0x08), RGBY(0x09), RGBY(0x0A), RGBY(0x0B), + RGBY(0x0C), RGBY(0x0D), RGBY(0x0E), RGBY(0x0F), + RGBY(0x10), RGBY(0x11), RGBY(0x12), RGBY(0x13), + RGBY(0x14), RGBY(0x15), RGBY(0x16), RGBY(0x17), + RGBY(0x18), RGBY(0x19), RGBY(0x1A), RGBY(0x1B), + RGBY(0x1C), RGBY(0x1D), RGBY(0x1E), RGBY(0x1F), + RGBY(0x20), RGBY(0x21), RGBY(0x22), RGBY(0x23), + RGBY(0x24), RGBY(0x25), RGBY(0x26), RGBY(0x27), + RGBY(0x28), RGBY(0x29), RGBY(0x2A), RGBY(0x2B), + RGBY(0x2C), RGBY(0x2D), RGBY(0x2E), RGBY(0x2F), + RGBY(0x30), RGBY(0x31), RGBY(0x32), RGBY(0x33), + RGBY(0x34), RGBY(0x35), RGBY(0x36), RGBY(0x37), + RGBY(0x38), RGBY(0x39), RGBY(0x3A), RGBY(0x3B), + RGBY(0x3C), RGBY(0x3D), RGBY(0x3E), RGBY(0x3F), + RGBY(0x40), RGBY(0x41), RGBY(0x42), RGBY(0x43), + RGBY(0x44), RGBY(0x45), RGBY(0x46), RGBY(0x47), + RGBY(0x48), RGBY(0x49), RGBY(0x4A), RGBY(0x4B), + RGBY(0x4C), RGBY(0x4D), RGBY(0x4E), RGBY(0x4F), + RGBY(0x50), RGBY(0x51), RGBY(0x52), RGBY(0x53), + RGBY(0x54), RGBY(0x55), RGBY(0x56), RGBY(0x57), + RGBY(0x58), RGBY(0x59), RGBY(0x5A), RGBY(0x5B), + RGBY(0x5C), RGBY(0x5D), RGBY(0x5E), RGBY(0x5F), + RGBY(0x60), RGBY(0x61), RGBY(0x62), RGBY(0x63), + RGBY(0x64), RGBY(0x65), RGBY(0x66), RGBY(0x67), + RGBY(0x68), RGBY(0x69), RGBY(0x6A), RGBY(0x6B), + RGBY(0x6C), RGBY(0x6D), RGBY(0x6E), RGBY(0x6F), + RGBY(0x70), RGBY(0x71), RGBY(0x72), RGBY(0x73), + RGBY(0x74), RGBY(0x75), RGBY(0x76), RGBY(0x77), + RGBY(0x78), RGBY(0x79), RGBY(0x7A), RGBY(0x7B), + RGBY(0x7C), RGBY(0x7D), RGBY(0x7E), RGBY(0x7F), + RGBY(0x80), RGBY(0x81), RGBY(0x82), RGBY(0x83), + RGBY(0x84), RGBY(0x85), RGBY(0x86), RGBY(0x87), + RGBY(0x88), RGBY(0x89), RGBY(0x8A), RGBY(0x8B), + RGBY(0x8C), RGBY(0x8D), RGBY(0x8E), RGBY(0x8F), + RGBY(0x90), RGBY(0x91), RGBY(0x92), RGBY(0x93), + RGBY(0x94), RGBY(0x95), RGBY(0x96), RGBY(0x97), + RGBY(0x98), RGBY(0x99), RGBY(0x9A), RGBY(0x9B), + RGBY(0x9C), RGBY(0x9D), RGBY(0x9E), RGBY(0x9F), + RGBY(0xA0), RGBY(0xA1), RGBY(0xA2), RGBY(0xA3), + RGBY(0xA4), RGBY(0xA5), RGBY(0xA6), RGBY(0xA7), + RGBY(0xA8), RGBY(0xA9), RGBY(0xAA), RGBY(0xAB), + RGBY(0xAC), RGBY(0xAD), RGBY(0xAE), RGBY(0xAF), + RGBY(0xB0), RGBY(0xB1), RGBY(0xB2), RGBY(0xB3), + RGBY(0xB4), RGBY(0xB5), RGBY(0xB6), RGBY(0xB7), + RGBY(0xB8), RGBY(0xB9), RGBY(0xBA), RGBY(0xBB), + RGBY(0xBC), RGBY(0xBD), RGBY(0xBE), RGBY(0xBF), + RGBY(0xC0), RGBY(0xC1), RGBY(0xC2), RGBY(0xC3), + RGBY(0xC4), RGBY(0xC5), RGBY(0xC6), RGBY(0xC7), + RGBY(0xC8), RGBY(0xC9), RGBY(0xCA), RGBY(0xCB), + RGBY(0xCC), RGBY(0xCD), RGBY(0xCE), RGBY(0xCF), + RGBY(0xD0), RGBY(0xD1), RGBY(0xD2), RGBY(0xD3), + RGBY(0xD4), RGBY(0xD5), RGBY(0xD6), RGBY(0xD7), + RGBY(0xD8), RGBY(0xD9), RGBY(0xDA), RGBY(0xDB), + RGBY(0xDC), RGBY(0xDD), RGBY(0xDE), RGBY(0xDF), + RGBY(0xE0), RGBY(0xE1), RGBY(0xE2), RGBY(0xE3), + RGBY(0xE4), RGBY(0xE5), RGBY(0xE6), RGBY(0xE7), + RGBY(0xE8), RGBY(0xE9), RGBY(0xEA), RGBY(0xEB), + RGBY(0xEC), RGBY(0xED), RGBY(0xEE), RGBY(0xEF), + RGBY(0xF0), RGBY(0xF1), RGBY(0xF2), RGBY(0xF3), + RGBY(0xF4), RGBY(0xF5), RGBY(0xF6), RGBY(0xF7), + RGBY(0xF8), RGBY(0xF9), RGBY(0xFA), RGBY(0xFB), + RGBY(0xFC), RGBY(0xFD), RGBY(0xFE), RGBY(0xFF), +}; + +MMX_ALIGNED(int16 kCoefficientsRgbU[256][4]) = { + RGBU(0x00), RGBU(0x01), RGBU(0x02), RGBU(0x03), + RGBU(0x04), RGBU(0x05), RGBU(0x06), RGBU(0x07), + RGBU(0x08), RGBU(0x09), RGBU(0x0A), RGBU(0x0B), + RGBU(0x0C), RGBU(0x0D), RGBU(0x0E), RGBU(0x0F), + RGBU(0x10), RGBU(0x11), RGBU(0x12), RGBU(0x13), + RGBU(0x14), RGBU(0x15), RGBU(0x16), RGBU(0x17), + RGBU(0x18), RGBU(0x19), RGBU(0x1A), RGBU(0x1B), + RGBU(0x1C), RGBU(0x1D), RGBU(0x1E), RGBU(0x1F), + RGBU(0x20), RGBU(0x21), RGBU(0x22), RGBU(0x23), + RGBU(0x24), RGBU(0x25), RGBU(0x26), RGBU(0x27), + RGBU(0x28), RGBU(0x29), RGBU(0x2A), RGBU(0x2B), + RGBU(0x2C), RGBU(0x2D), RGBU(0x2E), RGBU(0x2F), + RGBU(0x30), RGBU(0x31), RGBU(0x32), RGBU(0x33), + RGBU(0x34), RGBU(0x35), RGBU(0x36), RGBU(0x37), + RGBU(0x38), RGBU(0x39), RGBU(0x3A), RGBU(0x3B), + RGBU(0x3C), RGBU(0x3D), RGBU(0x3E), RGBU(0x3F), + RGBU(0x40), RGBU(0x41), RGBU(0x42), RGBU(0x43), + RGBU(0x44), RGBU(0x45), RGBU(0x46), RGBU(0x47), + RGBU(0x48), RGBU(0x49), RGBU(0x4A), RGBU(0x4B), + RGBU(0x4C), RGBU(0x4D), RGBU(0x4E), RGBU(0x4F), + RGBU(0x50), RGBU(0x51), RGBU(0x52), RGBU(0x53), + RGBU(0x54), RGBU(0x55), RGBU(0x56), RGBU(0x57), + RGBU(0x58), RGBU(0x59), RGBU(0x5A), RGBU(0x5B), + RGBU(0x5C), RGBU(0x5D), RGBU(0x5E), RGBU(0x5F), + RGBU(0x60), RGBU(0x61), RGBU(0x62), RGBU(0x63), + RGBU(0x64), RGBU(0x65), RGBU(0x66), RGBU(0x67), + RGBU(0x68), RGBU(0x69), RGBU(0x6A), RGBU(0x6B), + RGBU(0x6C), RGBU(0x6D), RGBU(0x6E), RGBU(0x6F), + RGBU(0x70), RGBU(0x71), RGBU(0x72), RGBU(0x73), + RGBU(0x74), RGBU(0x75), RGBU(0x76), RGBU(0x77), + RGBU(0x78), RGBU(0x79), RGBU(0x7A), RGBU(0x7B), + RGBU(0x7C), RGBU(0x7D), RGBU(0x7E), RGBU(0x7F), + RGBU(0x80), RGBU(0x81), RGBU(0x82), RGBU(0x83), + RGBU(0x84), RGBU(0x85), RGBU(0x86), RGBU(0x87), + RGBU(0x88), RGBU(0x89), RGBU(0x8A), RGBU(0x8B), + RGBU(0x8C), RGBU(0x8D), RGBU(0x8E), RGBU(0x8F), + RGBU(0x90), RGBU(0x91), RGBU(0x92), RGBU(0x93), + RGBU(0x94), RGBU(0x95), RGBU(0x96), RGBU(0x97), + RGBU(0x98), RGBU(0x99), RGBU(0x9A), RGBU(0x9B), + RGBU(0x9C), RGBU(0x9D), RGBU(0x9E), RGBU(0x9F), + RGBU(0xA0), RGBU(0xA1), RGBU(0xA2), RGBU(0xA3), + RGBU(0xA4), RGBU(0xA5), RGBU(0xA6), RGBU(0xA7), + RGBU(0xA8), RGBU(0xA9), RGBU(0xAA), RGBU(0xAB), + RGBU(0xAC), RGBU(0xAD), RGBU(0xAE), RGBU(0xAF), + RGBU(0xB0), RGBU(0xB1), RGBU(0xB2), RGBU(0xB3), + RGBU(0xB4), RGBU(0xB5), RGBU(0xB6), RGBU(0xB7), + RGBU(0xB8), RGBU(0xB9), RGBU(0xBA), RGBU(0xBB), + RGBU(0xBC), RGBU(0xBD), RGBU(0xBE), RGBU(0xBF), + RGBU(0xC0), RGBU(0xC1), RGBU(0xC2), RGBU(0xC3), + RGBU(0xC4), RGBU(0xC5), RGBU(0xC6), RGBU(0xC7), + RGBU(0xC8), RGBU(0xC9), RGBU(0xCA), RGBU(0xCB), + RGBU(0xCC), RGBU(0xCD), RGBU(0xCE), RGBU(0xCF), + RGBU(0xD0), RGBU(0xD1), RGBU(0xD2), RGBU(0xD3), + RGBU(0xD4), RGBU(0xD5), RGBU(0xD6), RGBU(0xD7), + RGBU(0xD8), RGBU(0xD9), RGBU(0xDA), RGBU(0xDB), + RGBU(0xDC), RGBU(0xDD), RGBU(0xDE), RGBU(0xDF), + RGBU(0xE0), RGBU(0xE1), RGBU(0xE2), RGBU(0xE3), + RGBU(0xE4), RGBU(0xE5), RGBU(0xE6), RGBU(0xE7), + RGBU(0xE8), RGBU(0xE9), RGBU(0xEA), RGBU(0xEB), + RGBU(0xEC), RGBU(0xED), RGBU(0xEE), RGBU(0xEF), + RGBU(0xF0), RGBU(0xF1), RGBU(0xF2), RGBU(0xF3), + RGBU(0xF4), RGBU(0xF5), RGBU(0xF6), RGBU(0xF7), + RGBU(0xF8), RGBU(0xF9), RGBU(0xFA), RGBU(0xFB), + RGBU(0xFC), RGBU(0xFD), RGBU(0xFE), RGBU(0xFF), +}; + +MMX_ALIGNED(int16 kCoefficientsRgbV[256][4]) = { + RGBV(0x00), RGBV(0x01), RGBV(0x02), RGBV(0x03), + RGBV(0x04), RGBV(0x05), RGBV(0x06), RGBV(0x07), + RGBV(0x08), RGBV(0x09), RGBV(0x0A), RGBV(0x0B), + RGBV(0x0C), RGBV(0x0D), RGBV(0x0E), RGBV(0x0F), + RGBV(0x10), RGBV(0x11), RGBV(0x12), RGBV(0x13), + RGBV(0x14), RGBV(0x15), RGBV(0x16), RGBV(0x17), + RGBV(0x18), RGBV(0x19), RGBV(0x1A), RGBV(0x1B), + RGBV(0x1C), RGBV(0x1D), RGBV(0x1E), RGBV(0x1F), + RGBV(0x20), RGBV(0x21), RGBV(0x22), RGBV(0x23), + RGBV(0x24), RGBV(0x25), RGBV(0x26), RGBV(0x27), + RGBV(0x28), RGBV(0x29), RGBV(0x2A), RGBV(0x2B), + RGBV(0x2C), RGBV(0x2D), RGBV(0x2E), RGBV(0x2F), + RGBV(0x30), RGBV(0x31), RGBV(0x32), RGBV(0x33), + RGBV(0x34), RGBV(0x35), RGBV(0x36), RGBV(0x37), + RGBV(0x38), RGBV(0x39), RGBV(0x3A), RGBV(0x3B), + RGBV(0x3C), RGBV(0x3D), RGBV(0x3E), RGBV(0x3F), + RGBV(0x40), RGBV(0x41), RGBV(0x42), RGBV(0x43), + RGBV(0x44), RGBV(0x45), RGBV(0x46), RGBV(0x47), + RGBV(0x48), RGBV(0x49), RGBV(0x4A), RGBV(0x4B), + RGBV(0x4C), RGBV(0x4D), RGBV(0x4E), RGBV(0x4F), + RGBV(0x50), RGBV(0x51), RGBV(0x52), RGBV(0x53), + RGBV(0x54), RGBV(0x55), RGBV(0x56), RGBV(0x57), + RGBV(0x58), RGBV(0x59), RGBV(0x5A), RGBV(0x5B), + RGBV(0x5C), RGBV(0x5D), RGBV(0x5E), RGBV(0x5F), + RGBV(0x60), RGBV(0x61), RGBV(0x62), RGBV(0x63), + RGBV(0x64), RGBV(0x65), RGBV(0x66), RGBV(0x67), + RGBV(0x68), RGBV(0x69), RGBV(0x6A), RGBV(0x6B), + RGBV(0x6C), RGBV(0x6D), RGBV(0x6E), RGBV(0x6F), + RGBV(0x70), RGBV(0x71), RGBV(0x72), RGBV(0x73), + RGBV(0x74), RGBV(0x75), RGBV(0x76), RGBV(0x77), + RGBV(0x78), RGBV(0x79), RGBV(0x7A), RGBV(0x7B), + RGBV(0x7C), RGBV(0x7D), RGBV(0x7E), RGBV(0x7F), + RGBV(0x80), RGBV(0x81), RGBV(0x82), RGBV(0x83), + RGBV(0x84), RGBV(0x85), RGBV(0x86), RGBV(0x87), + RGBV(0x88), RGBV(0x89), RGBV(0x8A), RGBV(0x8B), + RGBV(0x8C), RGBV(0x8D), RGBV(0x8E), RGBV(0x8F), + RGBV(0x90), RGBV(0x91), RGBV(0x92), RGBV(0x93), + RGBV(0x94), RGBV(0x95), RGBV(0x96), RGBV(0x97), + RGBV(0x98), RGBV(0x99), RGBV(0x9A), RGBV(0x9B), + RGBV(0x9C), RGBV(0x9D), RGBV(0x9E), RGBV(0x9F), + RGBV(0xA0), RGBV(0xA1), RGBV(0xA2), RGBV(0xA3), + RGBV(0xA4), RGBV(0xA5), RGBV(0xA6), RGBV(0xA7), + RGBV(0xA8), RGBV(0xA9), RGBV(0xAA), RGBV(0xAB), + RGBV(0xAC), RGBV(0xAD), RGBV(0xAE), RGBV(0xAF), + RGBV(0xB0), RGBV(0xB1), RGBV(0xB2), RGBV(0xB3), + RGBV(0xB4), RGBV(0xB5), RGBV(0xB6), RGBV(0xB7), + RGBV(0xB8), RGBV(0xB9), RGBV(0xBA), RGBV(0xBB), + RGBV(0xBC), RGBV(0xBD), RGBV(0xBE), RGBV(0xBF), + RGBV(0xC0), RGBV(0xC1), RGBV(0xC2), RGBV(0xC3), + RGBV(0xC4), RGBV(0xC5), RGBV(0xC6), RGBV(0xC7), + RGBV(0xC8), RGBV(0xC9), RGBV(0xCA), RGBV(0xCB), + RGBV(0xCC), RGBV(0xCD), RGBV(0xCE), RGBV(0xCF), + RGBV(0xD0), RGBV(0xD1), RGBV(0xD2), RGBV(0xD3), + RGBV(0xD4), RGBV(0xD5), RGBV(0xD6), RGBV(0xD7), + RGBV(0xD8), RGBV(0xD9), RGBV(0xDA), RGBV(0xDB), + RGBV(0xDC), RGBV(0xDD), RGBV(0xDE), RGBV(0xDF), + RGBV(0xE0), RGBV(0xE1), RGBV(0xE2), RGBV(0xE3), + RGBV(0xE4), RGBV(0xE5), RGBV(0xE6), RGBV(0xE7), + RGBV(0xE8), RGBV(0xE9), RGBV(0xEA), RGBV(0xEB), + RGBV(0xEC), RGBV(0xED), RGBV(0xEE), RGBV(0xEF), + RGBV(0xF0), RGBV(0xF1), RGBV(0xF2), RGBV(0xF3), + RGBV(0xF4), RGBV(0xF5), RGBV(0xF6), RGBV(0xF7), + RGBV(0xF8), RGBV(0xF9), RGBV(0xFA), RGBV(0xFB), + RGBV(0xFC), RGBV(0xFD), RGBV(0xFE), RGBV(0xFF), +}; + +#undef RGBY +#undef RGBU +#undef RGBV +#undef MMX_ALIGNED + +// TODO(fbarchard): Use the following function instead of +// pure assembly to help make code more portable to 64 bit +// and Mac, which has different labels. +// no-gcse eliminates the frame pointer, freeing up ebp. + +#if defined(FUTURE_64BIT_VERSION) +void __attribute__((optimize("O2", "no-gcse"))) + NewFastConvertYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + asm( + "shr %4\n" +"1:\n" + "movzb (%1),%%eax\n" + "add $0x1,%1\n" + "movzb (%2),%%ebx\n" + "add $0x1,%2\n" + "movq kCoefficientsRgbU(,%%eax,8),%%mm0\n" + "movzb (%0),%%eax\n" + "paddsw kCoefficientsRgbV(,%%ebx,8),%%mm0\n" + "movzb 0x1(%0),%%ebx\n" + "movq kCoefficientsRgbY(,%%eax,8),%%mm1\n" + "add $0x2,%0\n" + "movq kCoefficientsRgbY(,%%ebx,8),%%mm2\n" + "paddsw %%mm0,%%mm1\n" + "paddsw %%mm0,%%mm2\n" + "psraw $0x6,%%mm1\n" + "psraw $0x6,%%mm2\n" + "packuswb %%mm2,%%mm1\n" + "movntq %%mm1,0x0(%3)\n" + "add $0x8,%3\n" + "sub $0x1,%4\n" + "jne 1b\n" + : : "r"(y_buf),"r"(u_buf),"r"(v_buf),"r"(rgb_buf),"r"(width) + : "eax","ebx"); +} +#endif + +void FastConvertYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width); + + asm( + ".global FastConvertYUVToRGB32Row\n" +"FastConvertYUVToRGB32Row:\n" + "pusha\n" + "mov 0x24(%esp),%edx\n" + "mov 0x28(%esp),%edi\n" + "mov 0x2c(%esp),%esi\n" + "mov 0x30(%esp),%ebp\n" + "mov 0x34(%esp),%ecx\n" + "jmp convertend\n" + +"convertloop:" + "movzbl (%edi),%eax\n" + "add $0x1,%edi\n" + "movzbl (%esi),%ebx\n" + "add $0x1,%esi\n" + "movq kCoefficientsRgbU(,%eax,8),%mm0\n" + "movzbl (%edx),%eax\n" + "paddsw kCoefficientsRgbV(,%ebx,8),%mm0\n" + "movzbl 0x1(%edx),%ebx\n" + "movq kCoefficientsRgbY(,%eax,8),%mm1\n" + "add $0x2,%edx\n" + "movq kCoefficientsRgbY(,%ebx,8),%mm2\n" + "paddsw %mm0,%mm1\n" + "paddsw %mm0,%mm2\n" + "psraw $0x6,%mm1\n" + "psraw $0x6,%mm2\n" + "packuswb %mm2,%mm1\n" + "movntq %mm1,0x0(%ebp)\n" + "add $0x8,%ebp\n" +"convertend:" + "sub $0x2,%ecx\n" + "jns convertloop\n" + + "and $0x1,%ecx\n" + "je convertdone\n" + + "movzbl (%edi),%eax\n" + "movq kCoefficientsRgbU(,%eax,8),%mm0\n" + "movzbl (%esi),%eax\n" + "paddsw kCoefficientsRgbV(,%eax,8),%mm0\n" + "movzbl (%edx),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm1\n" + "paddsw %mm0,%mm1\n" + "psraw $0x6,%mm1\n" + "packuswb %mm1,%mm1\n" + "movd %mm1,0x0(%ebp)\n" +"convertdone:" + "popa\n" + "ret\n" +); + + +void ScaleYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width, + int scaled_dx); + + asm( + ".global ScaleYUVToRGB32Row\n" +"ScaleYUVToRGB32Row:\n" + "pusha\n" + "mov 0x24(%esp),%edx\n" + "mov 0x28(%esp),%edi\n" + "mov 0x2c(%esp),%esi\n" + "mov 0x30(%esp),%ebp\n" + "mov 0x34(%esp),%ecx\n" + "xor %ebx,%ebx\n" + "jmp scaleend\n" + +"scaleloop:" + "mov %ebx,%eax\n" + "sar $0x5,%eax\n" + "movzbl (%edi,%eax,1),%eax\n" + "movq kCoefficientsRgbU(,%eax,8),%mm0\n" + "mov %ebx,%eax\n" + "sar $0x5,%eax\n" + "movzbl (%esi,%eax,1),%eax\n" + "paddsw kCoefficientsRgbV(,%eax,8),%mm0\n" + "mov %ebx,%eax\n" + "add 0x38(%esp),%ebx\n" + "sar $0x4,%eax\n" + "movzbl (%edx,%eax,1),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm1\n" + "mov %ebx,%eax\n" + "add 0x38(%esp),%ebx\n" + "sar $0x4,%eax\n" + "movzbl (%edx,%eax,1),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm2\n" + "paddsw %mm0,%mm1\n" + "paddsw %mm0,%mm2\n" + "psraw $0x6,%mm1\n" + "psraw $0x6,%mm2\n" + "packuswb %mm2,%mm1\n" + "movntq %mm1,0x0(%ebp)\n" + "add $0x8,%ebp\n" +"scaleend:" + "sub $0x2,%ecx\n" + "jns scaleloop\n" + + "and $0x1,%ecx\n" + "je scaledone\n" + + "mov %ebx,%eax\n" + "sar $0x5,%eax\n" + "movzbl (%edi,%eax,1),%eax\n" + "movq kCoefficientsRgbU(,%eax,8),%mm0\n" + "mov %ebx,%eax\n" + "sar $0x5,%eax\n" + "movzbl (%esi,%eax,1),%eax\n" + "paddsw kCoefficientsRgbV(,%eax,8),%mm0\n" + "mov %ebx,%eax\n" + "sar $0x4,%eax\n" + "movzbl (%edx,%eax,1),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm1\n" + "mov %ebx,%eax\n" + "sar $0x4,%eax\n" + "movzbl (%edx,%eax,1),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm2\n" + "paddsw %mm0,%mm1\n" + "paddsw %mm0,%mm2\n" + "psraw $0x6,%mm1\n" + "psraw $0x6,%mm2\n" + "packuswb %mm2,%mm1\n" + "movd %mm1,0x0(%ebp)\n" + +"scaledone:" + "popa\n" + "ret\n" +); + +#else // USE_MMX // Reference version of YUV converter. static const int kClipTableSize = 256; static const int kClipOverflow = 288; // Cb max is 535. -static uint8 g_rgb_clip_table[kClipOverflow + - kClipTableSize + - kClipOverflow] = { +static uint8 kRgbClipTable[kClipOverflow + + kClipTableSize + + kClipOverflow] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 288 underflow values 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // clipped to 0. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -137,7 +548,7 @@ static inline uint32 clip(int32 value) { DCHECK(((value >> 8) + kClipOverflow) >= 0); DCHECK(((value >> 8) + kClipOverflow) < (kClipOverflow + kClipTableSize + kClipOverflow)); - return static_cast<uint32>(g_rgb_clip_table[((value) >> 8) + kClipOverflow]); + return static_cast<uint32>(kRgbClipTable[((value) >> 8) + kClipOverflow]); } static inline void YuvPixel(uint8 y, @@ -196,6 +607,6 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, scaled_x += scaled_dx; } } - -} // namespace media +#endif // USE_MMX +} // extern "C" diff --git a/media/base/yuv_row_mac.cc b/media/base/yuv_row_mac.cc index eb3d07e..c80b213 100644 --- a/media/base/yuv_row_mac.cc +++ b/media/base/yuv_row_mac.cc @@ -4,24 +4,435 @@ #include "media/base/yuv_row.h" -// Enable bilinear filtering by turning on the following macro. -// #define MEDIA_BILINEAR_FILTER 1 - #ifdef _DEBUG #include "base/logging.h" #else #define DCHECK(a) #endif -namespace media { +// TODO(fbarchard): Make MMX work in DLLs. Currently only works in unittests. +// TODO(fbarchard): Do 64 bit version. + +extern "C" { +#if USE_MMX + +#define RGBY(i) { \ + static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ + static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ + static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ + 0 \ +} + +#define RGBU(i) { \ + static_cast<int16>(2.018 * 64 * (i - 128) + 0.5), \ + static_cast<int16>(-0.391 * 64 * (i - 128) + 0.5), \ + 0, \ + static_cast<int16>(256 * 64 - 1) \ +} + +#define RGBV(i) { \ + 0, \ + static_cast<int16>(-0.813 * 64 * (i - 128) + 0.5), \ + static_cast<int16>(1.596 * 64 * (i - 128) + 0.5), \ + 0 \ +} + +#define MMX_ALIGNED(var) var __attribute__((aligned(16))) + +MMX_ALIGNED(int16 kCoefficientsRgbY[256][4]) = { + RGBY(0x00), RGBY(0x01), RGBY(0x02), RGBY(0x03), + RGBY(0x04), RGBY(0x05), RGBY(0x06), RGBY(0x07), + RGBY(0x08), RGBY(0x09), RGBY(0x0A), RGBY(0x0B), + RGBY(0x0C), RGBY(0x0D), RGBY(0x0E), RGBY(0x0F), + RGBY(0x10), RGBY(0x11), RGBY(0x12), RGBY(0x13), + RGBY(0x14), RGBY(0x15), RGBY(0x16), RGBY(0x17), + RGBY(0x18), RGBY(0x19), RGBY(0x1A), RGBY(0x1B), + RGBY(0x1C), RGBY(0x1D), RGBY(0x1E), RGBY(0x1F), + RGBY(0x20), RGBY(0x21), RGBY(0x22), RGBY(0x23), + RGBY(0x24), RGBY(0x25), RGBY(0x26), RGBY(0x27), + RGBY(0x28), RGBY(0x29), RGBY(0x2A), RGBY(0x2B), + RGBY(0x2C), RGBY(0x2D), RGBY(0x2E), RGBY(0x2F), + RGBY(0x30), RGBY(0x31), RGBY(0x32), RGBY(0x33), + RGBY(0x34), RGBY(0x35), RGBY(0x36), RGBY(0x37), + RGBY(0x38), RGBY(0x39), RGBY(0x3A), RGBY(0x3B), + RGBY(0x3C), RGBY(0x3D), RGBY(0x3E), RGBY(0x3F), + RGBY(0x40), RGBY(0x41), RGBY(0x42), RGBY(0x43), + RGBY(0x44), RGBY(0x45), RGBY(0x46), RGBY(0x47), + RGBY(0x48), RGBY(0x49), RGBY(0x4A), RGBY(0x4B), + RGBY(0x4C), RGBY(0x4D), RGBY(0x4E), RGBY(0x4F), + RGBY(0x50), RGBY(0x51), RGBY(0x52), RGBY(0x53), + RGBY(0x54), RGBY(0x55), RGBY(0x56), RGBY(0x57), + RGBY(0x58), RGBY(0x59), RGBY(0x5A), RGBY(0x5B), + RGBY(0x5C), RGBY(0x5D), RGBY(0x5E), RGBY(0x5F), + RGBY(0x60), RGBY(0x61), RGBY(0x62), RGBY(0x63), + RGBY(0x64), RGBY(0x65), RGBY(0x66), RGBY(0x67), + RGBY(0x68), RGBY(0x69), RGBY(0x6A), RGBY(0x6B), + RGBY(0x6C), RGBY(0x6D), RGBY(0x6E), RGBY(0x6F), + RGBY(0x70), RGBY(0x71), RGBY(0x72), RGBY(0x73), + RGBY(0x74), RGBY(0x75), RGBY(0x76), RGBY(0x77), + RGBY(0x78), RGBY(0x79), RGBY(0x7A), RGBY(0x7B), + RGBY(0x7C), RGBY(0x7D), RGBY(0x7E), RGBY(0x7F), + RGBY(0x80), RGBY(0x81), RGBY(0x82), RGBY(0x83), + RGBY(0x84), RGBY(0x85), RGBY(0x86), RGBY(0x87), + RGBY(0x88), RGBY(0x89), RGBY(0x8A), RGBY(0x8B), + RGBY(0x8C), RGBY(0x8D), RGBY(0x8E), RGBY(0x8F), + RGBY(0x90), RGBY(0x91), RGBY(0x92), RGBY(0x93), + RGBY(0x94), RGBY(0x95), RGBY(0x96), RGBY(0x97), + RGBY(0x98), RGBY(0x99), RGBY(0x9A), RGBY(0x9B), + RGBY(0x9C), RGBY(0x9D), RGBY(0x9E), RGBY(0x9F), + RGBY(0xA0), RGBY(0xA1), RGBY(0xA2), RGBY(0xA3), + RGBY(0xA4), RGBY(0xA5), RGBY(0xA6), RGBY(0xA7), + RGBY(0xA8), RGBY(0xA9), RGBY(0xAA), RGBY(0xAB), + RGBY(0xAC), RGBY(0xAD), RGBY(0xAE), RGBY(0xAF), + RGBY(0xB0), RGBY(0xB1), RGBY(0xB2), RGBY(0xB3), + RGBY(0xB4), RGBY(0xB5), RGBY(0xB6), RGBY(0xB7), + RGBY(0xB8), RGBY(0xB9), RGBY(0xBA), RGBY(0xBB), + RGBY(0xBC), RGBY(0xBD), RGBY(0xBE), RGBY(0xBF), + RGBY(0xC0), RGBY(0xC1), RGBY(0xC2), RGBY(0xC3), + RGBY(0xC4), RGBY(0xC5), RGBY(0xC6), RGBY(0xC7), + RGBY(0xC8), RGBY(0xC9), RGBY(0xCA), RGBY(0xCB), + RGBY(0xCC), RGBY(0xCD), RGBY(0xCE), RGBY(0xCF), + RGBY(0xD0), RGBY(0xD1), RGBY(0xD2), RGBY(0xD3), + RGBY(0xD4), RGBY(0xD5), RGBY(0xD6), RGBY(0xD7), + RGBY(0xD8), RGBY(0xD9), RGBY(0xDA), RGBY(0xDB), + RGBY(0xDC), RGBY(0xDD), RGBY(0xDE), RGBY(0xDF), + RGBY(0xE0), RGBY(0xE1), RGBY(0xE2), RGBY(0xE3), + RGBY(0xE4), RGBY(0xE5), RGBY(0xE6), RGBY(0xE7), + RGBY(0xE8), RGBY(0xE9), RGBY(0xEA), RGBY(0xEB), + RGBY(0xEC), RGBY(0xED), RGBY(0xEE), RGBY(0xEF), + RGBY(0xF0), RGBY(0xF1), RGBY(0xF2), RGBY(0xF3), + RGBY(0xF4), RGBY(0xF5), RGBY(0xF6), RGBY(0xF7), + RGBY(0xF8), RGBY(0xF9), RGBY(0xFA), RGBY(0xFB), + RGBY(0xFC), RGBY(0xFD), RGBY(0xFE), RGBY(0xFF), +}; + +MMX_ALIGNED(int16 kCoefficientsRgbU[256][4]) = { + RGBU(0x00), RGBU(0x01), RGBU(0x02), RGBU(0x03), + RGBU(0x04), RGBU(0x05), RGBU(0x06), RGBU(0x07), + RGBU(0x08), RGBU(0x09), RGBU(0x0A), RGBU(0x0B), + RGBU(0x0C), RGBU(0x0D), RGBU(0x0E), RGBU(0x0F), + RGBU(0x10), RGBU(0x11), RGBU(0x12), RGBU(0x13), + RGBU(0x14), RGBU(0x15), RGBU(0x16), RGBU(0x17), + RGBU(0x18), RGBU(0x19), RGBU(0x1A), RGBU(0x1B), + RGBU(0x1C), RGBU(0x1D), RGBU(0x1E), RGBU(0x1F), + RGBU(0x20), RGBU(0x21), RGBU(0x22), RGBU(0x23), + RGBU(0x24), RGBU(0x25), RGBU(0x26), RGBU(0x27), + RGBU(0x28), RGBU(0x29), RGBU(0x2A), RGBU(0x2B), + RGBU(0x2C), RGBU(0x2D), RGBU(0x2E), RGBU(0x2F), + RGBU(0x30), RGBU(0x31), RGBU(0x32), RGBU(0x33), + RGBU(0x34), RGBU(0x35), RGBU(0x36), RGBU(0x37), + RGBU(0x38), RGBU(0x39), RGBU(0x3A), RGBU(0x3B), + RGBU(0x3C), RGBU(0x3D), RGBU(0x3E), RGBU(0x3F), + RGBU(0x40), RGBU(0x41), RGBU(0x42), RGBU(0x43), + RGBU(0x44), RGBU(0x45), RGBU(0x46), RGBU(0x47), + RGBU(0x48), RGBU(0x49), RGBU(0x4A), RGBU(0x4B), + RGBU(0x4C), RGBU(0x4D), RGBU(0x4E), RGBU(0x4F), + RGBU(0x50), RGBU(0x51), RGBU(0x52), RGBU(0x53), + RGBU(0x54), RGBU(0x55), RGBU(0x56), RGBU(0x57), + RGBU(0x58), RGBU(0x59), RGBU(0x5A), RGBU(0x5B), + RGBU(0x5C), RGBU(0x5D), RGBU(0x5E), RGBU(0x5F), + RGBU(0x60), RGBU(0x61), RGBU(0x62), RGBU(0x63), + RGBU(0x64), RGBU(0x65), RGBU(0x66), RGBU(0x67), + RGBU(0x68), RGBU(0x69), RGBU(0x6A), RGBU(0x6B), + RGBU(0x6C), RGBU(0x6D), RGBU(0x6E), RGBU(0x6F), + RGBU(0x70), RGBU(0x71), RGBU(0x72), RGBU(0x73), + RGBU(0x74), RGBU(0x75), RGBU(0x76), RGBU(0x77), + RGBU(0x78), RGBU(0x79), RGBU(0x7A), RGBU(0x7B), + RGBU(0x7C), RGBU(0x7D), RGBU(0x7E), RGBU(0x7F), + RGBU(0x80), RGBU(0x81), RGBU(0x82), RGBU(0x83), + RGBU(0x84), RGBU(0x85), RGBU(0x86), RGBU(0x87), + RGBU(0x88), RGBU(0x89), RGBU(0x8A), RGBU(0x8B), + RGBU(0x8C), RGBU(0x8D), RGBU(0x8E), RGBU(0x8F), + RGBU(0x90), RGBU(0x91), RGBU(0x92), RGBU(0x93), + RGBU(0x94), RGBU(0x95), RGBU(0x96), RGBU(0x97), + RGBU(0x98), RGBU(0x99), RGBU(0x9A), RGBU(0x9B), + RGBU(0x9C), RGBU(0x9D), RGBU(0x9E), RGBU(0x9F), + RGBU(0xA0), RGBU(0xA1), RGBU(0xA2), RGBU(0xA3), + RGBU(0xA4), RGBU(0xA5), RGBU(0xA6), RGBU(0xA7), + RGBU(0xA8), RGBU(0xA9), RGBU(0xAA), RGBU(0xAB), + RGBU(0xAC), RGBU(0xAD), RGBU(0xAE), RGBU(0xAF), + RGBU(0xB0), RGBU(0xB1), RGBU(0xB2), RGBU(0xB3), + RGBU(0xB4), RGBU(0xB5), RGBU(0xB6), RGBU(0xB7), + RGBU(0xB8), RGBU(0xB9), RGBU(0xBA), RGBU(0xBB), + RGBU(0xBC), RGBU(0xBD), RGBU(0xBE), RGBU(0xBF), + RGBU(0xC0), RGBU(0xC1), RGBU(0xC2), RGBU(0xC3), + RGBU(0xC4), RGBU(0xC5), RGBU(0xC6), RGBU(0xC7), + RGBU(0xC8), RGBU(0xC9), RGBU(0xCA), RGBU(0xCB), + RGBU(0xCC), RGBU(0xCD), RGBU(0xCE), RGBU(0xCF), + RGBU(0xD0), RGBU(0xD1), RGBU(0xD2), RGBU(0xD3), + RGBU(0xD4), RGBU(0xD5), RGBU(0xD6), RGBU(0xD7), + RGBU(0xD8), RGBU(0xD9), RGBU(0xDA), RGBU(0xDB), + RGBU(0xDC), RGBU(0xDD), RGBU(0xDE), RGBU(0xDF), + RGBU(0xE0), RGBU(0xE1), RGBU(0xE2), RGBU(0xE3), + RGBU(0xE4), RGBU(0xE5), RGBU(0xE6), RGBU(0xE7), + RGBU(0xE8), RGBU(0xE9), RGBU(0xEA), RGBU(0xEB), + RGBU(0xEC), RGBU(0xED), RGBU(0xEE), RGBU(0xEF), + RGBU(0xF0), RGBU(0xF1), RGBU(0xF2), RGBU(0xF3), + RGBU(0xF4), RGBU(0xF5), RGBU(0xF6), RGBU(0xF7), + RGBU(0xF8), RGBU(0xF9), RGBU(0xFA), RGBU(0xFB), + RGBU(0xFC), RGBU(0xFD), RGBU(0xFE), RGBU(0xFF), +}; + +MMX_ALIGNED(int16 kCoefficientsRgbV[256][4]) = { + RGBV(0x00), RGBV(0x01), RGBV(0x02), RGBV(0x03), + RGBV(0x04), RGBV(0x05), RGBV(0x06), RGBV(0x07), + RGBV(0x08), RGBV(0x09), RGBV(0x0A), RGBV(0x0B), + RGBV(0x0C), RGBV(0x0D), RGBV(0x0E), RGBV(0x0F), + RGBV(0x10), RGBV(0x11), RGBV(0x12), RGBV(0x13), + RGBV(0x14), RGBV(0x15), RGBV(0x16), RGBV(0x17), + RGBV(0x18), RGBV(0x19), RGBV(0x1A), RGBV(0x1B), + RGBV(0x1C), RGBV(0x1D), RGBV(0x1E), RGBV(0x1F), + RGBV(0x20), RGBV(0x21), RGBV(0x22), RGBV(0x23), + RGBV(0x24), RGBV(0x25), RGBV(0x26), RGBV(0x27), + RGBV(0x28), RGBV(0x29), RGBV(0x2A), RGBV(0x2B), + RGBV(0x2C), RGBV(0x2D), RGBV(0x2E), RGBV(0x2F), + RGBV(0x30), RGBV(0x31), RGBV(0x32), RGBV(0x33), + RGBV(0x34), RGBV(0x35), RGBV(0x36), RGBV(0x37), + RGBV(0x38), RGBV(0x39), RGBV(0x3A), RGBV(0x3B), + RGBV(0x3C), RGBV(0x3D), RGBV(0x3E), RGBV(0x3F), + RGBV(0x40), RGBV(0x41), RGBV(0x42), RGBV(0x43), + RGBV(0x44), RGBV(0x45), RGBV(0x46), RGBV(0x47), + RGBV(0x48), RGBV(0x49), RGBV(0x4A), RGBV(0x4B), + RGBV(0x4C), RGBV(0x4D), RGBV(0x4E), RGBV(0x4F), + RGBV(0x50), RGBV(0x51), RGBV(0x52), RGBV(0x53), + RGBV(0x54), RGBV(0x55), RGBV(0x56), RGBV(0x57), + RGBV(0x58), RGBV(0x59), RGBV(0x5A), RGBV(0x5B), + RGBV(0x5C), RGBV(0x5D), RGBV(0x5E), RGBV(0x5F), + RGBV(0x60), RGBV(0x61), RGBV(0x62), RGBV(0x63), + RGBV(0x64), RGBV(0x65), RGBV(0x66), RGBV(0x67), + RGBV(0x68), RGBV(0x69), RGBV(0x6A), RGBV(0x6B), + RGBV(0x6C), RGBV(0x6D), RGBV(0x6E), RGBV(0x6F), + RGBV(0x70), RGBV(0x71), RGBV(0x72), RGBV(0x73), + RGBV(0x74), RGBV(0x75), RGBV(0x76), RGBV(0x77), + RGBV(0x78), RGBV(0x79), RGBV(0x7A), RGBV(0x7B), + RGBV(0x7C), RGBV(0x7D), RGBV(0x7E), RGBV(0x7F), + RGBV(0x80), RGBV(0x81), RGBV(0x82), RGBV(0x83), + RGBV(0x84), RGBV(0x85), RGBV(0x86), RGBV(0x87), + RGBV(0x88), RGBV(0x89), RGBV(0x8A), RGBV(0x8B), + RGBV(0x8C), RGBV(0x8D), RGBV(0x8E), RGBV(0x8F), + RGBV(0x90), RGBV(0x91), RGBV(0x92), RGBV(0x93), + RGBV(0x94), RGBV(0x95), RGBV(0x96), RGBV(0x97), + RGBV(0x98), RGBV(0x99), RGBV(0x9A), RGBV(0x9B), + RGBV(0x9C), RGBV(0x9D), RGBV(0x9E), RGBV(0x9F), + RGBV(0xA0), RGBV(0xA1), RGBV(0xA2), RGBV(0xA3), + RGBV(0xA4), RGBV(0xA5), RGBV(0xA6), RGBV(0xA7), + RGBV(0xA8), RGBV(0xA9), RGBV(0xAA), RGBV(0xAB), + RGBV(0xAC), RGBV(0xAD), RGBV(0xAE), RGBV(0xAF), + RGBV(0xB0), RGBV(0xB1), RGBV(0xB2), RGBV(0xB3), + RGBV(0xB4), RGBV(0xB5), RGBV(0xB6), RGBV(0xB7), + RGBV(0xB8), RGBV(0xB9), RGBV(0xBA), RGBV(0xBB), + RGBV(0xBC), RGBV(0xBD), RGBV(0xBE), RGBV(0xBF), + RGBV(0xC0), RGBV(0xC1), RGBV(0xC2), RGBV(0xC3), + RGBV(0xC4), RGBV(0xC5), RGBV(0xC6), RGBV(0xC7), + RGBV(0xC8), RGBV(0xC9), RGBV(0xCA), RGBV(0xCB), + RGBV(0xCC), RGBV(0xCD), RGBV(0xCE), RGBV(0xCF), + RGBV(0xD0), RGBV(0xD1), RGBV(0xD2), RGBV(0xD3), + RGBV(0xD4), RGBV(0xD5), RGBV(0xD6), RGBV(0xD7), + RGBV(0xD8), RGBV(0xD9), RGBV(0xDA), RGBV(0xDB), + RGBV(0xDC), RGBV(0xDD), RGBV(0xDE), RGBV(0xDF), + RGBV(0xE0), RGBV(0xE1), RGBV(0xE2), RGBV(0xE3), + RGBV(0xE4), RGBV(0xE5), RGBV(0xE6), RGBV(0xE7), + RGBV(0xE8), RGBV(0xE9), RGBV(0xEA), RGBV(0xEB), + RGBV(0xEC), RGBV(0xED), RGBV(0xEE), RGBV(0xEF), + RGBV(0xF0), RGBV(0xF1), RGBV(0xF2), RGBV(0xF3), + RGBV(0xF4), RGBV(0xF5), RGBV(0xF6), RGBV(0xF7), + RGBV(0xF8), RGBV(0xF9), RGBV(0xFA), RGBV(0xFB), + RGBV(0xFC), RGBV(0xFD), RGBV(0xFE), RGBV(0xFF), +}; + +#undef RGBY +#undef RGBU +#undef RGBV +#undef MMX_ALIGNED + +// TODO(fbarchard): Use the following function instead of +// pure assembly to help make code more portable to 64 bit +// and Mac, which has different labels. +// no-gcse eliminates the frame pointer, freeing up ebp. + +#if defined(FUTURE_64BIT_VERSION) +void __attribute__((optimize("O2", "no-gcse"))) + NewFastConvertYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + asm( + "shr %4\n" +"1:\n" + "movzb (%1),%%eax\n" + "add $0x1,%1\n" + "movzb (%2),%%ebx\n" + "add $0x1,%2\n" + "movq kCoefficientsRgbU(,%%eax,8),%%mm0\n" + "movzb (%0),%%eax\n" + "paddsw kCoefficientsRgbV(,%%ebx,8),%%mm0\n" + "movzb 0x1(%0),%%ebx\n" + "movq kCoefficientsRgbY(,%%eax,8),%%mm1\n" + "add $0x2,%0\n" + "movq kCoefficientsRgbY(,%%ebx,8),%%mm2\n" + "paddsw %%mm0,%%mm1\n" + "paddsw %%mm0,%%mm2\n" + "psraw $0x6,%%mm1\n" + "psraw $0x6,%%mm2\n" + "packuswb %%mm2,%%mm1\n" + "movntq %%mm1,0x0(%3)\n" + "add $0x8,%3\n" + "sub $0x1,%4\n" + "jne 1b\n" + : : "r"(y_buf),"r"(u_buf),"r"(v_buf),"r"(rgb_buf),"r"(width) + : "eax","ebx"); +} +#endif + +extern void FastConvertYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width); + + __asm__( +" .globl _FastConvertYUVToRGB32Row\n" +"_FastConvertYUVToRGB32Row:\n" + "pusha\n" + "mov 0x24(%esp),%edx\n" + "mov 0x28(%esp),%edi\n" + "mov 0x2c(%esp),%esi\n" + "mov 0x30(%esp),%ebp\n" + "mov 0x34(%esp),%ecx\n" + "jmp convertend\n" + +"convertloop:" + "movzbl (%edi),%eax\n" + "add $0x1,%edi\n" + "movzbl (%esi),%ebx\n" + "add $0x1,%esi\n" + "movq _kCoefficientsRgbU(,%eax,8),%mm0\n" + "movzbl (%edx),%eax\n" + "paddsw _kCoefficientsRgbV(,%ebx,8),%mm0\n" + "movzbl 0x1(%edx),%ebx\n" + "movq _kCoefficientsRgbY(,%eax,8),%mm1\n" + "add $0x2,%edx\n" + "movq _kCoefficientsRgbY(,%ebx,8),%mm2\n" + "paddsw %mm0,%mm1\n" + "paddsw %mm0,%mm2\n" + "psraw $0x6,%mm1\n" + "psraw $0x6,%mm2\n" + "packuswb %mm2,%mm1\n" + "movntq %mm1,0x0(%ebp)\n" + "add $0x8,%ebp\n" +"convertend:" + "sub $0x2,%ecx\n" + "jns convertloop\n" + + "and $0x1,%ecx\n" + "je convertdone\n" + + "movzbl (%edi),%eax\n" + "movq _kCoefficientsRgbU(,%eax,8),%mm0\n" + "movzbl (%esi),%eax\n" + "paddsw _kCoefficientsRgbV(,%eax,8),%mm0\n" + "movzbl (%edx),%eax\n" + "movq _kCoefficientsRgbY(,%eax,8),%mm1\n" + "paddsw %mm0,%mm1\n" + "psraw $0x6,%mm1\n" + "packuswb %mm1,%mm1\n" + "movd %mm1,0x0(%ebp)\n" +"convertdone:" + "popa\n" + "ret\n" +); + + +extern void ScaleYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width, + int scaled_dx); + + __asm__( +" .globl _ScaleYUVToRGB32Row\n" +"_ScaleYUVToRGB32Row:\n" + "pusha\n" + "mov 0x24(%esp),%edx\n" + "mov 0x28(%esp),%edi\n" + "mov 0x2c(%esp),%esi\n" + "mov 0x30(%esp),%ebp\n" + "mov 0x34(%esp),%ecx\n" + "xor %ebx,%ebx\n" + "jmp scaleend\n" + +"scaleloop:" + "mov %ebx,%eax\n" + "sar $0x5,%eax\n" + "movzbl (%edi,%eax,1),%eax\n" + "movq kCoefficientsRgbU(,%eax,8),%mm0\n" + "mov %ebx,%eax\n" + "sar $0x5,%eax\n" + "movzbl (%esi,%eax,1),%eax\n" + "paddsw kCoefficientsRgbV(,%eax,8),%mm0\n" + "mov %ebx,%eax\n" + "add 0x38(%esp),%ebx\n" + "sar $0x4,%eax\n" + "movzbl (%edx,%eax,1),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm1\n" + "mov %ebx,%eax\n" + "add 0x38(%esp),%ebx\n" + "sar $0x4,%eax\n" + "movzbl (%edx,%eax,1),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm2\n" + "paddsw %mm0,%mm1\n" + "paddsw %mm0,%mm2\n" + "psraw $0x6,%mm1\n" + "psraw $0x6,%mm2\n" + "packuswb %mm2,%mm1\n" + "movntq %mm1,0x0(%ebp)\n" + "add $0x8,%ebp\n" +"scaleend:" + "sub $0x2,%ecx\n" + "jns scaleloop\n" + + "and $0x1,%ecx\n" + "je scaledone\n" + + "mov %ebx,%eax\n" + "sar $0x5,%eax\n" + "movzbl (%edi,%eax,1),%eax\n" + "movq kCoefficientsRgbU(,%eax,8),%mm0\n" + "mov %ebx,%eax\n" + "sar $0x5,%eax\n" + "movzbl (%esi,%eax,1),%eax\n" + "paddsw kCoefficientsRgbV(,%eax,8),%mm0\n" + "mov %ebx,%eax\n" + "sar $0x4,%eax\n" + "movzbl (%edx,%eax,1),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm1\n" + "mov %ebx,%eax\n" + "sar $0x4,%eax\n" + "movzbl (%edx,%eax,1),%eax\n" + "movq kCoefficientsRgbY(,%eax,8),%mm2\n" + "paddsw %mm0,%mm1\n" + "paddsw %mm0,%mm2\n" + "psraw $0x6,%mm1\n" + "psraw $0x6,%mm2\n" + "packuswb %mm2,%mm1\n" + "movd %mm1,0x0(%ebp)\n" + +"scaledone:" + "popa\n" + "ret\n" +); + +#else // USE_MMX // Reference version of YUV converter. static const int kClipTableSize = 256; static const int kClipOverflow = 288; // Cb max is 535. -static uint8 g_rgb_clip_table[kClipOverflow + - kClipTableSize + - kClipOverflow] = { +static uint8 kRgbClipTable[kClipOverflow + + kClipTableSize + + kClipOverflow] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 288 underflow values 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // clipped to 0. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -137,7 +548,7 @@ static inline uint32 clip(int32 value) { DCHECK(((value >> 8) + kClipOverflow) >= 0); DCHECK(((value >> 8) + kClipOverflow) < (kClipOverflow + kClipTableSize + kClipOverflow)); - return static_cast<uint32>(g_rgb_clip_table[((value) >> 8) + kClipOverflow]); + return static_cast<uint32>(kRgbClipTable[((value) >> 8) + kClipOverflow]); } static inline void YuvPixel(uint8 y, @@ -196,6 +607,6 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, scaled_x += scaled_dx; } } - -} // namespace media +#endif // USE_MMX +} // extern "C" diff --git a/media/base/yuv_row_win.cc b/media/base/yuv_row_win.cc index 53dadc4..e6f15bb 100644 --- a/media/base/yuv_row_win.cc +++ b/media/base/yuv_row_win.cc @@ -4,11 +4,7 @@ #include "media/base/yuv_row.h" -// Enable bilinear filtering by turning on the following macro. -// #define MEDIA_BILINEAR_FILTER 1 - -namespace media { - +extern "C" { #define RGBY(i) { \ static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ @@ -32,8 +28,7 @@ namespace media { #define MMX_ALIGNED(var) __declspec(align(16)) var -extern "C" { -MMX_ALIGNED(int16 coefficients_RGB_Y[256][4]) = { +MMX_ALIGNED(int16 kCoefficientsRgbY[256][4]) = { RGBY(0x00), RGBY(0x01), RGBY(0x02), RGBY(0x03), RGBY(0x04), RGBY(0x05), RGBY(0x06), RGBY(0x07), RGBY(0x08), RGBY(0x09), RGBY(0x0A), RGBY(0x0B), @@ -100,7 +95,7 @@ MMX_ALIGNED(int16 coefficients_RGB_Y[256][4]) = { RGBY(0xFC), RGBY(0xFD), RGBY(0xFE), RGBY(0xFF), }; -MMX_ALIGNED(int16 coefficients_RGB_U[256][4]) = { +MMX_ALIGNED(int16 kCoefficientsRgbU[256][4]) = { RGBU(0x00), RGBU(0x01), RGBU(0x02), RGBU(0x03), RGBU(0x04), RGBU(0x05), RGBU(0x06), RGBU(0x07), RGBU(0x08), RGBU(0x09), RGBU(0x0A), RGBU(0x0B), @@ -167,7 +162,7 @@ MMX_ALIGNED(int16 coefficients_RGB_U[256][4]) = { RGBU(0xFC), RGBU(0xFD), RGBU(0xFE), RGBU(0xFF), }; -MMX_ALIGNED(int16 coefficients_RGB_V[256][4]) = { +MMX_ALIGNED(int16 kCoefficientsRgbV[256][4]) = { RGBV(0x00), RGBV(0x01), RGBV(0x02), RGBV(0x03), RGBV(0x04), RGBV(0x05), RGBV(0x06), RGBV(0x07), RGBV(0x08), RGBV(0x09), RGBV(0x0A), RGBV(0x0B), @@ -233,7 +228,6 @@ MMX_ALIGNED(int16 coefficients_RGB_V[256][4]) = { RGBV(0xF8), RGBV(0xF9), RGBV(0xFA), RGBV(0xFB), RGBV(0xFC), RGBV(0xFD), RGBV(0xFE), RGBV(0xFF), }; -} // extern "C" #undef RGBHY #undef RGBY @@ -258,20 +252,20 @@ void FastConvertYUVToRGB32Row(const uint8* y_buf, mov esi, [esp + 32 + 12] // V mov ebp, [esp + 32 + 16] // rgb mov ecx, [esp + 32 + 20] // width - jmp wend + jmp convertend - wloop : + convertloop : movzx eax, byte ptr [edi] add edi, 1 movzx ebx, byte ptr [esi] add esi, 1 - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] movzx eax, byte ptr [edx] - paddsw mm0, [coefficients_RGB_V + 8 * ebx] + paddsw mm0, [kCoefficientsRgbV + 8 * ebx] movzx ebx, byte ptr [edx + 1] - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] add edx, 2 - movq mm2, [coefficients_RGB_Y + 8 * ebx] + movq mm2, [kCoefficientsRgbY + 8 * ebx] paddsw mm1, mm0 paddsw mm2, mm0 psraw mm1, 6 @@ -279,24 +273,24 @@ void FastConvertYUVToRGB32Row(const uint8* y_buf, packuswb mm1, mm2 movntq [ebp], mm1 add ebp, 8 - wend : + convertend : sub ecx, 2 - jns wloop + jns convertloop and ecx, 1 // odd number of pixels? - jz wdone + jz convertdone movzx eax, byte ptr [edi] - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] movzx eax, byte ptr [esi] - paddsw mm0, [coefficients_RGB_V + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * eax] movzx eax, byte ptr [edx] - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 psraw mm1, 6 packuswb mm1, mm1 movd [ebp], mm1 - wdone : + convertdone : popad ret @@ -323,16 +317,16 @@ void ConvertYUVToRGB32Row(const uint8* y_buf, wloop : movzx eax, byte ptr [edi] add edi, ebx - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] movzx eax, byte ptr [esi] add esi, ebx - paddsw mm0, [coefficients_RGB_V + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * eax] movzx eax, byte ptr [edx] add edx, ebx - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] movzx eax, byte ptr [edx] add edx, ebx - movq mm2, [coefficients_RGB_Y + 8 * eax] + movq mm2, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 paddsw mm2, mm0 psraw mm1, 6 @@ -348,11 +342,11 @@ void ConvertYUVToRGB32Row(const uint8* y_buf, jz wdone movzx eax, byte ptr [edi] - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] movzx eax, byte ptr [esi] - paddsw mm0, [coefficients_RGB_V + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * eax] movzx eax, byte ptr [edx] - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 psraw mm1, 6 packuswb mm1, mm1 @@ -385,17 +379,17 @@ void RotateConvertYUVToRGB32Row(const uint8* y_buf, movzx eax, byte ptr [edi] mov ebx, [esp + 32 + 28] // uvstep add edi, ebx - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] movzx eax, byte ptr [esi] add esi, ebx - paddsw mm0, [coefficients_RGB_V + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * eax] movzx eax, byte ptr [edx] mov ebx, [esp + 32 + 24] // ystep add edx, ebx - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] movzx eax, byte ptr [edx] add edx, ebx - movq mm2, [coefficients_RGB_Y + 8 * eax] + movq mm2, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 paddsw mm2, mm0 psraw mm1, 6 @@ -411,11 +405,11 @@ void RotateConvertYUVToRGB32Row(const uint8* y_buf, jz wdone movzx eax, byte ptr [edi] - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] movzx eax, byte ptr [esi] - paddsw mm0, [coefficients_RGB_V + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * eax] movzx eax, byte ptr [edx] - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 psraw mm1, 6 packuswb mm1, mm1 @@ -447,10 +441,10 @@ void DoubleYUVToRGB32Row(const uint8* y_buf, add edi, 1 movzx ebx, byte ptr [esi] add esi, 1 - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] movzx eax, byte ptr [edx] - paddsw mm0, [coefficients_RGB_V + 8 * ebx] - movq mm1, [coefficients_RGB_Y + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * ebx] + movq mm1, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 psraw mm1, 6 packuswb mm1, mm1 @@ -459,7 +453,7 @@ void DoubleYUVToRGB32Row(const uint8* y_buf, movzx ebx, byte ptr [edx + 1] add edx, 2 - paddsw mm0, [coefficients_RGB_Y + 8 * ebx] + paddsw mm0, [kCoefficientsRgbY + 8 * ebx] psraw mm0, 6 packuswb mm0, mm0 punpckldq mm0, mm0 @@ -473,11 +467,11 @@ void DoubleYUVToRGB32Row(const uint8* y_buf, jz wdone movzx eax, byte ptr [edi] - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] movzx eax, byte ptr [esi] - paddsw mm0, [coefficients_RGB_V + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * eax] movzx eax, byte ptr [edx] - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 psraw mm1, 6 packuswb mm1, mm1 @@ -514,27 +508,27 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, mov ebp, [esp + 32 + 16] // rgb mov ecx, [esp + 32 + 20] // width xor ebx, ebx // x - jmp wend + jmp scaleend - wloop : + scaleloop : mov eax, ebx sar eax, 5 movzx eax, byte ptr [edi + eax] - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] mov eax, ebx sar eax, 5 movzx eax, byte ptr [esi + eax] - paddsw mm0, [coefficients_RGB_V + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * eax] mov eax, ebx add ebx, [esp + 32 + 24] // x += dx sar eax, 4 movzx eax, byte ptr [edx + eax] - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] mov eax, ebx add ebx, [esp + 32 + 24] // x += dx sar eax, 4 movzx eax, byte ptr [edx + eax] - movq mm2, [coefficients_RGB_Y + 8 * eax] + movq mm2, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 paddsw mm2, mm0 psraw mm1, 6 @@ -542,29 +536,29 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, packuswb mm1, mm2 movntq [ebp], mm1 add ebp, 8 - wend : + scaleend : sub ecx, 2 - jns wloop + jns scaleloop and ecx, 1 // odd number of pixels? - jz wdone + jz scaledone mov eax, ebx sar eax, 5 movzx eax, byte ptr [edi + eax] - movq mm0, [coefficients_RGB_U + 8 * eax] + movq mm0, [kCoefficientsRgbU + 8 * eax] mov eax, ebx sar eax, 5 movzx eax, byte ptr [esi + eax] - paddsw mm0, [coefficients_RGB_V + 8 * eax] + paddsw mm0, [kCoefficientsRgbV + 8 * eax] mov eax, ebx sar eax, 4 movzx eax, byte ptr [edx + eax] - movq mm1, [coefficients_RGB_Y + 8 * eax] + movq mm1, [kCoefficientsRgbY + 8 * eax] mov eax, ebx sar eax, 4 movzx eax, byte ptr [edx + eax] - movq mm2, [coefficients_RGB_Y + 8 * eax] + movq mm2, [kCoefficientsRgbY + 8 * eax] paddsw mm1, mm0 paddsw mm2, mm0 psraw mm1, 6 @@ -572,12 +566,10 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, packuswb mm1, mm2 movd [ebp], mm1 - wdone : - + scaledone : popad ret } } - -} // namespace media +} // extern "C" |