diff options
author | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 23:18:05 +0000 |
---|---|---|
committer | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 23:18:05 +0000 |
commit | 4343dfbb634893311ae654e412d704831c8ba5ac (patch) | |
tree | 3ae77ab903d1017876fabc3ae26122255f684789 | |
parent | 4ae9839c98ddb20de44d0c776e278a9cdbea37d4 (diff) | |
download | chromium_src-4343dfbb634893311ae654e412d704831c8ba5ac.zip chromium_src-4343dfbb634893311ae654e412d704831c8ba5ac.tar.gz chromium_src-4343dfbb634893311ae654e412d704831c8ba5ac.tar.bz2 |
YUV scaling and conversion refactored into low levels per platform that do a row and high levels that step thru the image.
Low level is implemented in MMX assembly.
Mac and Linux use reference code for this version.
Review URL: http://codereview.chromium.org/113247
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16011 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/base/yuv_convert.cc | 537 | ||||
-rw-r--r-- | media/base/yuv_convert_unittest.cc | 24 | ||||
-rw-r--r-- | media/base/yuv_row.h | 63 | ||||
-rw-r--r-- | media/base/yuv_row_linux.cc | 254 | ||||
-rw-r--r-- | media/base/yuv_row_mac.cc | 254 | ||||
-rw-r--r-- | media/base/yuv_row_win.cc | 408 | ||||
-rw-r--r-- | media/base/yuv_scale.cc | 226 | ||||
-rw-r--r-- | media/base/yuv_scale.h | 1 | ||||
-rw-r--r-- | media/base/yuv_scale_unittest.cc | 21 | ||||
-rw-r--r-- | media/media.gyp | 4 |
10 files changed, 1054 insertions, 738 deletions
diff --git a/media/base/yuv_convert.cc b/media/base/yuv_convert.cc index 3ba6863..788fd99 100644 --- a/media/base/yuv_convert.cc +++ b/media/base/yuv_convert.cc @@ -73,403 +73,10 @@ #define DCHECK(a) #endif -// MMX for Windows, Linux and Mac. -// C++ code provided as a fall back. -// Compile with /DUSE_MMX=0 -#ifndef USE_MMX - -#ifdef ARCH_CPU_ARM_FAMILY -#define USE_MMX 0 -#else -#define USE_MMX 1 -#endif -#endif +#include "media/base/yuv_row.h" namespace media { -#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 \ -} - -#if defined(_MSC_VER) -#define MMX_ALIGNED(var) __declspec(align(16)) var -#else -#define MMX_ALIGNED(var) var __attribute__((aligned(16))) -#endif - -extern "C" { -MMX_ALIGNED(int16 coefficients_RGB_Y[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 coefficients_RGB_U[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 coefficients_RGB_V[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 - -#if defined(_MSC_VER) - -// Warning C4799: function has no EMMS instruction. -#pragma warning(disable: 4799) - -__declspec(naked) -void ConvertYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - size_t width) { - __asm { - pushad - mov edx, [esp + 32 + 4] // Y - mov edi, [esp + 32 + 8] // U - mov esi, [esp + 32 + 12] // V - mov ebp, [esp + 32 + 16] // rgb - mov ecx, [esp + 32 + 20] // width - shr ecx, 1 - - wloop : - movzx eax, byte ptr [edi] // NOLINT - add edi, 1 - movzx ebx, byte ptr [esi] // NOLINT - add esi, 1 - movq mm0, [coefficients_RGB_U + 8 * eax] - movzx eax, byte ptr [edx] // NOLINT - paddsw mm0, [coefficients_RGB_V + 8 * ebx] - movzx ebx, byte ptr [edx + 1] // NOLINT - movq mm1, [coefficients_RGB_Y + 8 * eax] - add edx, 2 - movq mm2, [coefficients_RGB_Y + 8 * ebx] - paddsw mm1, mm0 - paddsw mm2, mm0 - psraw mm1, 6 - psraw mm2, 6 - packuswb mm1, mm2 - movntq [ebp], mm1 // NOLINT - add ebp, 8 - sub ecx, 1 - jnz wloop - - popad - ret - } -} - - -#elif defined(__linux) - -void ConvertYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - size_t width) __attribute__((noinline)); - - asm( -"ConvertYV12ToRGB32Row:\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" - "shr %ecx\n" -"1:\n" - "movzb (%edi),%eax\n" - "add $0x1,%edi\n" - "movzb (%esi),%ebx\n" - "add $0x1,%esi\n" - "movq coefficients_RGB_U(,%eax,8),%mm0\n" - "movzb (%edx),%eax\n" - "paddsw coefficients_RGB_V(,%ebx,8),%mm0\n" - "movzb 0x1(%edx),%ebx\n" - "movq coefficients_RGB_Y(,%eax,8),%mm1\n" - "add $0x2,%edx\n" - "movq coefficients_RGB_Y(,%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" - "sub $0x1,%ecx\n" - "jne 1b\n" - "popa\n" - "ret\n" -); - -#else - - -void ConvertYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - size_t width) __attribute__((noinline)); - - asm( -"_ConvertYV12ToRGB32Row:\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" - "shr %ecx\n" - "xor %eax,%eax\n" - "xor %ebx,%ebx\n" -"1:\n" - "movzb (%edi),%eax\n" - "add $0x1,%edi\n" - "movzb (%esi),%ebx\n" - "add $0x1,%esi\n" - "movq _coefficients_RGB_U(,%eax,8),%mm0\n" - "movzb (%edx),%eax\n" - "paddsw _coefficients_RGB_V(,%ebx,8),%mm0\n" - "movzb 0x1(%edx),%ebx\n" - "movq _coefficients_RGB_Y(,%eax,8),%mm1\n" - "add $0x2,%edx\n" - "movq _coefficients_RGB_Y(,%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" - "sub $0x1,%ecx\n" - "jne 1b\n" - "popa\n" - "ret\n" -); - -#endif // MSC_VER -} // extern "C" - -#else // USE_MMX - -void ConvertYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - size_t width); -#endif - // Convert a frame of YV12 (aka YUV420) to 32 bit ARGB. void ConvertYV12ToRGB32(const uint8* y_buf, const uint8* u_buf, @@ -500,13 +107,7 @@ void ConvertYV12ToRGB32(const uint8* y_buf, d1, width); } -#if USE_MMX -#if defined(_MSC_VER) - __asm emms; -#else - asm("emms"); -#endif -#endif + EMMS(); } // Convert a frame of YV16 (aka YUV422) to 32 bit ARGB. @@ -539,139 +140,7 @@ void ConvertYV16ToRGB32(const uint8* y_buf, d1, width); } -#if USE_MMX -#if defined(_MSC_VER) - __asm emms; -#else - asm("emms"); -#endif -#endif -} - -//------------------------------------------------------------------------------ -// This is pure C code - -#if !USE_MMX - -// Reference version of YUV converter. -static const int kClipTableSize = 256; -static const int kClipOverflow = 128; - -static uint8 g_rgb_clip_table[kClipOverflow - + kClipTableSize - + kClipOverflow] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 128 underflow values - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cliped to 0. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // Unclipped values. - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, - 0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0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -}; - -// Clip an rgb channel value to 0..255 range. -// Source is signed fixed point 8.8. -// Table allows for values to underflow or overflow by 128. -// Therefore source range is -128 to 384. -// Output clips to unsigned 0 to 255. -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]); -} - - -void ConvertYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - size_t width) { - for (int32 x = 0; x < static_cast<int32>(width); x += 2) { - uint8 u = u_buf[x >> 1]; - uint8 v = v_buf[x >> 1]; - int32 d = static_cast<int32>(u) - 128; - int32 e = static_cast<int32>(v) - 128; - - int32 cb = (516 * d + 128); - int32 cg = (- 100 * d - 208 * e + 128); - int32 cr = (409 * e + 128); - - uint8 y0 = y_buf[x]; - int32 C298a = ((static_cast<int32>(y0) - 16) * 298 + 128); - *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) | - (clip(C298a + cg) << 8) | - (clip(C298a + cr) << 16) | - 0xff000000; - - uint8 y1 = y_buf[x + 1]; - int32 C298b = ((static_cast<int32>(y1) - 16) * 298 + 128); - *reinterpret_cast<uint32*>(rgb_buf + 4) = clip(C298b + cb) | - (clip(C298b + cg) << 8) | - (clip(C298b + cr) << 16) | - 0xff000000; - - rgb_buf += 8; // Advance 2 pixels. - } + EMMS(); } -#endif - } // namespace media diff --git a/media/base/yuv_convert_unittest.cc b/media/base/yuv_convert_unittest.cc index 28e1f1c..960e0b3 100644 --- a/media/base/yuv_convert_unittest.cc +++ b/media/base/yuv_convert_unittest.cc @@ -5,20 +5,19 @@ #include "base/base_paths.h" #include "base/file_util.h" #include "media/base/yuv_convert.h" +#include "media/base/yuv_row.h" #include "testing/gtest/include/gtest/gtest.h" // Reference images were created with the following steps // ffmpeg -vframes 25 -i bali.mov -vcodec rawvideo -pix_fmt yuv420p -an // bali.yv12.1280_720.yuv // yuvhalf -yv12 -skip 24 bali.yv12.1280_720.yuv bali.yv12.640_360.yuv -// yuvtool -yv12 bali.yv12.640_360.yuv bali.yv12.640_360.rgb // ffmpeg -vframes 25 -i bali.mov -vcodec rawvideo -pix_fmt yuv422p -an // bali.yv16.1280_720.yuv // yuvhalf -yv16 -skip 24 bali.yv16.1280_720.yuv bali.yv16.640_360.yuv -// yuvtool -yv16 bali.yv16.640_360.yuv bali.yv16.640_360.rgb - // Size of raw image. + static const int kWidth = 640; static const int kHeight = 360; static const int kBpp = 4; @@ -69,10 +68,17 @@ TEST(YUVConvertTest, YV12) { kWidth / 2, // UVStride kWidth * kBpp); // RGBStride +// TODO(fbarchard): The reference image was converted with MMX. +// Non-MMX implementations do not match exactly. In the future, +// Mac and Linux will use MMX as well and the unittest will be +// activated automatically. +#if USE_MMX // Compare converted YUV to reference conversion file. int rgb_diff = memcmp(rgb_converted_bytes.get(), rgb_bytes.get(), kRGBSize); - EXPECT_EQ(rgb_diff, 0); + EXPECT_EQ(0, rgb_diff); +#endif + return; // This is here to allow you to put a break point on this line } TEST(YUVConvertTest, YV16) { @@ -115,8 +121,16 @@ TEST(YUVConvertTest, YV16) { kWidth / 2, // UVStride kWidth * kBpp); // RGBStride +// TODO(fbarchard): The reference image was converted with MMX. +// Non-MMX implementations do not match exactly. In the future, +// Mac and Linux will use MMX as well and the unittest will be +// activated automatically. +#if USE_MMX // Compare converted YUV to reference conversion file. int rgb_diff = memcmp(rgb_converted_bytes.get(), rgb_bytes.get(), kRGBSize); - EXPECT_EQ(rgb_diff, 0); + EXPECT_EQ(0, rgb_diff); +#endif + return; } + diff --git a/media/base/yuv_row.h b/media/base/yuv_row.h new file mode 100644 index 0000000..11fc71f --- /dev/null +++ b/media/base/yuv_row.h @@ -0,0 +1,63 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// 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. + +#ifndef MEDIA_BASE_YUV_ROW_H_ +#define MEDIA_BASE_YUV_ROW_H_ + +#include "base/basictypes.h" + +namespace media { + +void ConvertYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width); + +void HalfYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width); + +void ScaleYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width, + int scaled_dx); + +void Half2Row(const uint8* in_row0, + const uint8* in_row1, + uint8* out_row, + int out_width); + +// MMX for Windows +// C++ code provided as a fall back. + +#ifndef USE_MMX +#if defined(_MSC_VER) +#define USE_MMX 1 +#else +#define USE_MMX 0 +#endif +#endif + +#if USE_MMX +#if defined(_MSC_VER) +#define EMMS() __asm emms +#else +#define EMMS() asm("emms") +#endif +#else +#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 new file mode 100644 index 0000000..4acc454 --- /dev/null +++ b/media/base/yuv_row_linux.cc @@ -0,0 +1,254 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#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 { + +// Reference version of YUV converter. +static const int kClipTableSize = 256; +static const int kClipOverflow = 256; + +static uint8 g_rgb_clip_table[kClipOverflow + + kClipTableSize + + kClipOverflow] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 256 underflow values + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // clipped to 0. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // Unclipped values. + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 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F, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +}; + +// Clip an rgb channel value to 0..255 range. +// Source is signed fixed point 8.8. +// Table allows for values to underflow or overflow by 128. +// Therefore source range is -128 to 384. +// Output clips to unsigned 0 to 255. +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]); +} + +static inline void YuvPixel(uint8 y, + uint8 u, + uint8 v, + uint8* rgb_buf) { + int32 d = static_cast<int32>(u) - 128; + int32 e = static_cast<int32>(v) - 128; + + int32 cb = (516 * d + 128); + int32 cg = (- 100 * d - 208 * e + 128); + int32 cr = (409 * e + 128); + + int32 C298a = ((static_cast<int32>(y) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf) = (clip(C298a + cb)) | + (clip(C298a + cg) << 8) | + (clip(C298a + cr) << 16) | + (0xff000000); +} + +void ConvertYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + for (int32 x = 0; x < static_cast<int32>(width); x += 2) { + uint8 u = u_buf[x >> 1]; + uint8 v = v_buf[x >> 1]; + int32 d = static_cast<int32>(u) - 128; + int32 e = static_cast<int32>(v) - 128; + + int32 cb = (516 * d + 128); + int32 cg = (- 100 * d - 208 * e + 128); + int32 cr = (409 * e + 128); + + uint8 y0 = y_buf[x]; + int32 C298a = ((static_cast<int32>(y0) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) | + (clip(C298a + cg) << 8) | + (clip(C298a + cr) << 16) | + 0xff000000; + + uint8 y1 = y_buf[x + 1]; + int32 C298b = ((static_cast<int32>(y1) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf + 4) = clip(C298b + cb) | + (clip(C298b + cg) << 8) | + (clip(C298b + cr) << 16) | + 0xff000000; + + rgb_buf += 8; // Advance 2 pixels. + } +} + +void HalfYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + for (int32 x = 0; x < width; ++x) { + uint8 u = u_buf[x]; + uint8 v = v_buf[x]; + int32 d = static_cast<int32>(u) - 128; + int32 e = static_cast<int32>(v) - 128; + + int32 cb = (516 * d + 128); + int32 cg = (- 100 * d - 208 * e + 128); + int32 cr = (409 * e + 128); + + uint8 y0 = y_buf[x * 2 + 0]; + uint8 y1 = y_buf[x * 2 + 1]; + int32 C298a = ((static_cast<int32>((y0 + y1) >> 1) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) | + (clip(C298a + cg) << 8) | + (clip(C298a + cr) << 16) | + 0xff000000; + + rgb_buf += 4; + } +} + +// 28.4 fixed point is used. A shift by 4 isolates the integer. +// A shift by 5 is used to further subsample the chrominence channels. +// & 15 isolates the fixed point fraction. >> 2 to get the upper 2 bits, +// for 1/4 pixel accurate interpolation. +void ScaleYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width, + int scaled_dx) { + int scaled_x = 0; + for (int32 x = 0; x < width; ++x) { + uint8 u = u_buf[scaled_x >> 5]; + uint8 v = v_buf[scaled_x >> 5]; + uint8 y0 = y_buf[scaled_x >> 4]; +#if MEDIA_BILINEAR_FILTER + uint8 y1 = y_buf[(scaled_x >> 4) + 1]; + switch ((scaled_x & 15) >> 2) { + case 1: // 75% first pixel, 25% second pixel. + y0 = (y0 + y0 + y0 + y1) >> 2; + break; + case 2: // 50/50 blend + y0 = (y0 + y1) >> 1; + break; + case 3: // 25% first pixel, 75% second pixel. + y0 = (y0 + y1 + y1 + y1) >> 2; + break; + default: + case 0: // 100% first pixel. + break; + } +#endif // MEDIA_BILINEAR_FILTER + + YuvPixel(y0, u, v, rgb_buf); + + rgb_buf += 4; + scaled_x += scaled_dx; + } +} + +} // namespace media + diff --git a/media/base/yuv_row_mac.cc b/media/base/yuv_row_mac.cc new file mode 100644 index 0000000..4acc454 --- /dev/null +++ b/media/base/yuv_row_mac.cc @@ -0,0 +1,254 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#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 { + +// Reference version of YUV converter. +static const int kClipTableSize = 256; +static const int kClipOverflow = 256; + +static uint8 g_rgb_clip_table[kClipOverflow + + kClipTableSize + + kClipOverflow] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 256 underflow values + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // clipped to 0. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // Unclipped values. + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0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xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +}; + +// Clip an rgb channel value to 0..255 range. +// Source is signed fixed point 8.8. +// Table allows for values to underflow or overflow by 128. +// Therefore source range is -128 to 384. +// Output clips to unsigned 0 to 255. +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]); +} + +static inline void YuvPixel(uint8 y, + uint8 u, + uint8 v, + uint8* rgb_buf) { + int32 d = static_cast<int32>(u) - 128; + int32 e = static_cast<int32>(v) - 128; + + int32 cb = (516 * d + 128); + int32 cg = (- 100 * d - 208 * e + 128); + int32 cr = (409 * e + 128); + + int32 C298a = ((static_cast<int32>(y) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf) = (clip(C298a + cb)) | + (clip(C298a + cg) << 8) | + (clip(C298a + cr) << 16) | + (0xff000000); +} + +void ConvertYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + for (int32 x = 0; x < static_cast<int32>(width); x += 2) { + uint8 u = u_buf[x >> 1]; + uint8 v = v_buf[x >> 1]; + int32 d = static_cast<int32>(u) - 128; + int32 e = static_cast<int32>(v) - 128; + + int32 cb = (516 * d + 128); + int32 cg = (- 100 * d - 208 * e + 128); + int32 cr = (409 * e + 128); + + uint8 y0 = y_buf[x]; + int32 C298a = ((static_cast<int32>(y0) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) | + (clip(C298a + cg) << 8) | + (clip(C298a + cr) << 16) | + 0xff000000; + + uint8 y1 = y_buf[x + 1]; + int32 C298b = ((static_cast<int32>(y1) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf + 4) = clip(C298b + cb) | + (clip(C298b + cg) << 8) | + (clip(C298b + cr) << 16) | + 0xff000000; + + rgb_buf += 8; // Advance 2 pixels. + } +} + +void HalfYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + for (int32 x = 0; x < width; ++x) { + uint8 u = u_buf[x]; + uint8 v = v_buf[x]; + int32 d = static_cast<int32>(u) - 128; + int32 e = static_cast<int32>(v) - 128; + + int32 cb = (516 * d + 128); + int32 cg = (- 100 * d - 208 * e + 128); + int32 cr = (409 * e + 128); + + uint8 y0 = y_buf[x * 2 + 0]; + uint8 y1 = y_buf[x * 2 + 1]; + int32 C298a = ((static_cast<int32>((y0 + y1) >> 1) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) | + (clip(C298a + cg) << 8) | + (clip(C298a + cr) << 16) | + 0xff000000; + + rgb_buf += 4; + } +} + +// 28.4 fixed point is used. A shift by 4 isolates the integer. +// A shift by 5 is used to further subsample the chrominence channels. +// & 15 isolates the fixed point fraction. >> 2 to get the upper 2 bits, +// for 1/4 pixel accurate interpolation. +void ScaleYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width, + int scaled_dx) { + int scaled_x = 0; + for (int32 x = 0; x < width; ++x) { + uint8 u = u_buf[scaled_x >> 5]; + uint8 v = v_buf[scaled_x >> 5]; + uint8 y0 = y_buf[scaled_x >> 4]; +#if MEDIA_BILINEAR_FILTER + uint8 y1 = y_buf[(scaled_x >> 4) + 1]; + switch ((scaled_x & 15) >> 2) { + case 1: // 75% first pixel, 25% second pixel. + y0 = (y0 + y0 + y0 + y1) >> 2; + break; + case 2: // 50/50 blend + y0 = (y0 + y1) >> 1; + break; + case 3: // 25% first pixel, 75% second pixel. + y0 = (y0 + y1 + y1 + y1) >> 2; + break; + default: + case 0: // 100% first pixel. + break; + } +#endif // MEDIA_BILINEAR_FILTER + + YuvPixel(y0, u, v, rgb_buf); + + rgb_buf += 4; + scaled_x += scaled_dx; + } +} + +} // namespace media + diff --git a/media/base/yuv_row_win.cc b/media/base/yuv_row_win.cc new file mode 100644 index 0000000..beae687 --- /dev/null +++ b/media/base/yuv_row_win.cc @@ -0,0 +1,408 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/base/yuv_row.h" + +// Enable bilinear filtering by turning on the following macro. +// #define MEDIA_BILINEAR_FILTER 1 + +namespace media { + +#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) __declspec(align(16)) var + +extern "C" { +MMX_ALIGNED(int16 coefficients_RGB_Y[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 coefficients_RGB_U[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 coefficients_RGB_V[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), +}; +} // extern "C" + +#undef RGBHY +#undef RGBY +#undef RGBU +#undef RGBV +#undef MMX_ALIGNED + +// Warning C4799: function has no EMMS instruction. +// EMMS() is slow and should be called by the calling function once per image. +#pragma warning(disable: 4799) + +__declspec(naked) +void ConvertYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + __asm { + pushad + mov edx, [esp + 32 + 4] // Y + mov edi, [esp + 32 + 8] // U + mov esi, [esp + 32 + 12] // V + mov ebp, [esp + 32 + 16] // rgb + mov ecx, [esp + 32 + 20] // width + shr ecx, 1 + + wloop : + movzx eax, byte ptr [edi] // NOLINT + add edi, 1 + movzx ebx, byte ptr [esi] // NOLINT + add esi, 1 + movq mm0, [coefficients_RGB_U + 8 * eax] + movzx eax, byte ptr [edx] // NOLINT + paddsw mm0, [coefficients_RGB_V + 8 * ebx] + movzx ebx, byte ptr [edx + 1] // NOLINT + movq mm1, [coefficients_RGB_Y + 8 * eax] + add edx, 2 + movq mm2, [coefficients_RGB_Y + 8 * ebx] + paddsw mm1, mm0 + paddsw mm2, mm0 + psraw mm1, 6 + psraw mm2, 6 + packuswb mm1, mm2 + movntq [ebp], mm1 // NOLINT + add ebp, 8 + sub ecx, 1 + jnz wloop + + popad + ret + } +} + +__declspec(naked) +void HalfYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + __asm { + pushad + mov edx, [esp + 32 + 4] // Y + mov edi, [esp + 32 + 8] // U + mov esi, [esp + 32 + 12] // V + mov ebp, [esp + 32 + 16] // rgb + mov ecx, [esp + 32 + 20] // width + + wloop : + movzx eax, byte ptr [edi] + add edi, 1 + movzx ebx, byte ptr [esi] + add esi, 1 + movq mm0, [coefficients_RGB_U + 8 * eax] + movzx eax, byte ptr [edx] + paddsw mm0, [coefficients_RGB_V + 8 * ebx] +#if MEDIA_BILINEAR_FILTER + movzx ebx, byte ptr [edx + 1] + add ebx, eax + shr ebx, 1 +#endif + paddsw mm0, [coefficients_RGB_Y + 8 * eax] + add edx, 2 + psraw mm0, 6 + packuswb mm0, mm0 + movd [ebp], mm0 + add ebp, 4 + sub ecx, 1 + jnz wloop + + popad + ret + } +} + +__declspec(naked) +void ScaleYV12ToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width, + int dx) { + __asm { + pushad + mov edx, [esp + 32 + 4] // Y + mov edi, [esp + 32 + 8] // U + mov esi, [esp + 32 + 12] // V + mov ebp, [esp + 32 + 16] // rgb + mov ecx, [esp + 32 + 20] // width + xor eax, eax // x + + wloop : + mov ebx, eax + sar ebx, 5 + movzx ebx, byte ptr [edi + ebx] + movq mm0, [coefficients_RGB_U + 8 * ebx] + mov ebx, eax + sar ebx, 5 + movzx ebx, byte ptr [esi + ebx] + paddsw mm0, [coefficients_RGB_V + 8 * ebx] + mov ebx, eax + sar ebx, 4 + movzx ebx, byte ptr [edx + ebx] + paddsw mm0, [coefficients_RGB_Y + 8 * ebx] + psraw mm0, 6 + packuswb mm0, mm0 + movd [ebp], mm0 + add ebp, 4 + add eax, [esp + 32 + 24] // x += dx + sub ecx, 1 + jnz wloop + + popad + ret + } +} + + +__declspec(naked) +void Half2Row(const uint8* in_row0, + const uint8* in_row1, + uint8* out_row, + int out_width) { + __asm { + pushad + mov esi, [esp + 32 + 4] // row0 + mov ebx, [esp + 32 + 8] // row1 + mov edi, [esp + 32 + 12] // out + mov ecx, [esp + 32 + 16] // width + + wloop : + movzx eax, byte ptr [esi] + movzx edx, byte ptr [esi+1] + add esi, 2 + add eax, edx + movzx edx, byte ptr [ebx] + add eax, edx + movzx edx, byte ptr [ebx+1] + add eax, edx + add ebx, 2 + shr eax, 2 + mov [edi], al + add edi, 1 + sub ecx, 1 + jnz wloop + + popad + ret + } +} + +} // namespace media + diff --git a/media/base/yuv_scale.cc b/media/base/yuv_scale.cc index 96e905c..ffe4f05 100644 --- a/media/base/yuv_scale.cc +++ b/media/base/yuv_scale.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include "media/base/yuv_scale.h" +// yuv_row.h included to detect USE_MMX +#include "media/base/yuv_row.h" #ifdef _OPENMP #include <omp.h> @@ -14,28 +16,15 @@ #define DCHECK(a) #endif -namespace media { - -static void ScaleYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - int width, - int scaled_width); -static void HalfYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - int width); +// TODO(fbarchard): Determine is HALF_TEST will be used or removed. +// Half test is a prototype function that may or may not be useful in the +// future. It is slower, but higher quality. The low level function +// Half2Row() is in yuv_row.h and yuv_row_win.cc. +// The function is small, so it has been left in, but if it turns out to +// be useless, it should be removed in the future. +// #define HALF_TEST 1 -// TODO(fbarchard): Refactor row functions into seperate module and test on Mac. -#ifdef _MSC_VER -extern "C" void ConvertYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - size_t width); -#endif +namespace media { // Scale a frame of YV12 (aka YUV420) to 32 bit ARGB. void ScaleYV12ToRGB32(const uint8* y_buf, @@ -76,30 +65,39 @@ void ScaleYV12ToRGB32(const uint8* y_buf, (view_rotate == MIRROR_ROTATE_0) || (view_rotate == MIRROR_ROTATE_180)); + int scaled_dx = width * 16 / scaled_width; #ifdef _OPENMP #pragma omp parallel for #endif for (int y = 0; y < scaled_height; ++y) { uint8* dest_pixel = rgb_buf + y * rgb_pitch; int scaled_y = (y * height / scaled_height); - const uint8* y_ptr = y_buf + scaled_y * y_pitch; const uint8* u_ptr = u_buf + scaled_y / 2 * uv_pitch; const uint8* v_ptr = v_buf + scaled_y / 2 * uv_pitch; -#ifdef _MSC_VER if (scaled_width == width) { ConvertYV12ToRGB32Row(y_ptr, u_ptr, v_ptr, dest_pixel, scaled_width); - } else -#endif - if (scaled_width == (width / 2)) { + } else if (scaled_width == (width / 2)) { +#if HALF_TEST + uint8 y_half[2048]; + uint8 u_half[1024]; + uint8 v_half[1024]; + Half2Row(y_ptr, y_ptr + y_pitch, y_half, scaled_width); + Half2Row(u_ptr, u_ptr + uv_pitch, u_half, scaled_width / 2); + Half2Row(v_ptr, v_ptr + uv_pitch, v_half, scaled_width / 2); + ConvertYV12ToRGB32Row(y_half, u_half, v_half, + dest_pixel, scaled_width); +#else HalfYV12ToRGB32Row(y_ptr, u_ptr, v_ptr, dest_pixel, scaled_width); +#endif } else { ScaleYV12ToRGB32Row(y_ptr, u_ptr, v_ptr, - dest_pixel, width, scaled_width); + dest_pixel, scaled_width, scaled_dx); } } + EMMS(); } // Scale a frame of YV16 (aka YUV422) to 32 bit ARGB. @@ -140,6 +138,7 @@ void ScaleYV16ToRGB32(const uint8* y_buf, (view_rotate == ROTATE_180) || (view_rotate == MIRROR_ROTATE_0) || (view_rotate == MIRROR_ROTATE_180)); + int scaled_dx = width * 16 / scaled_width; #ifdef _OPENMP #pragma omp parallel for #endif @@ -149,179 +148,18 @@ void ScaleYV16ToRGB32(const uint8* y_buf, const uint8* y_ptr = y_buf + scaled_y * y_pitch; const uint8* u_ptr = u_buf + scaled_y * uv_pitch; const uint8* v_ptr = v_buf + scaled_y * uv_pitch; - - if (scaled_width == (width / 2)) { + if (scaled_width == width) { + ConvertYV12ToRGB32Row(y_ptr, u_ptr, v_ptr, + dest_pixel, scaled_width); + } else if (scaled_width == (width / 2)) { HalfYV12ToRGB32Row(y_ptr, u_ptr, v_ptr, dest_pixel, scaled_width); } else { ScaleYV12ToRGB32Row(y_ptr, u_ptr, v_ptr, - dest_pixel, width, scaled_width); - } - } -} - -// Reference version of YUV Scaler. -static const int kClipTableSize = 256; -static const int kClipOverflow = 128; - -static uint8 g_rgb_clip_table[kClipOverflow - + kClipTableSize - + kClipOverflow] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 128 underflow values - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // clipped to 0. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // Unclipped values. - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x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Table allows for values to underflow or overflow by 128. -// Therefore source range is -128 to 384. -// Output clips to unsigned 0 to 255. -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]); -} - -// 28.4 fixed point is used. A shift by 4 isolates the integer. -// A shift by 5 is used to further subsample the chrominence channels. -// & 15 isolates the fixed point fraction. >> 2 to get the upper 2 bits, -// for 1/4 pixel accurate interpolation. - -static void ScaleYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - int width, - int scaled_width) { - int scaled_dx = width * 16 / scaled_width; - int scaled_x = 0; - for (int32 x = 0; x < scaled_width; ++x) { - uint8 u = u_buf[scaled_x >> 5]; - uint8 v = v_buf[scaled_x >> 5]; - int32 d = static_cast<int32>(u) - 128; - int32 e = static_cast<int32>(v) - 128; - - int32 cb = (516 * d + 128); - int32 cg = (- 100 * d - 208 * e + 128); - int32 cr = (409 * e + 128); - - uint8 y0 = y_buf[scaled_x >> 4]; - uint8 y1 = y_buf[(scaled_x >> 4) + 1]; - switch ((scaled_x & 15) >> 2) { - case 1: // 75% first pixel, 25% second pixel. - y0 = (y0 + y0 + y0 + y1) >> 2; - break; - case 2: // 50/50 blend - y0 = (y0 + y1) >> 1; - break; - case 3: // 25% first pixel, 75% second pixel. - y0 = (y0 + y1 + y1 + y1) >> 2; - break; - default: - case 0: // 100% first pixel. - break; + dest_pixel, scaled_width, scaled_dx); } - - int32 C298a = ((static_cast<int32>(y0) - 16) * 298 + 128); - *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) | - (clip(C298a + cg) << 8) | - (clip(C298a + cr) << 16) | - 0xff000000; - - rgb_buf += 4; - scaled_x += scaled_dx; - } -} - - -static void HalfYV12ToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - int width) { - for (int32 x = 0; x < width; ++x) { - uint8 u = u_buf[x]; - uint8 v = v_buf[x]; - int32 d = static_cast<int32>(u) - 128; - int32 e = static_cast<int32>(v) - 128; - - int32 cb = (516 * d + 128); - int32 cg = (- 100 * d - 208 * e + 128); - int32 cr = (409 * e + 128); - - uint8 y0 = y_buf[x * 2 + 0]; - uint8 y1 = y_buf[x * 2 + 1]; - int32 C298a = ((static_cast<int32>((y0 + y1) >> 1) - 16) * 298 + 128); - *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) | - (clip(C298a + cg) << 8) | - (clip(C298a + cr) << 16) | - 0xff000000; - - rgb_buf += 4; } + EMMS(); } } // namespace media diff --git a/media/base/yuv_scale.h b/media/base/yuv_scale.h index a029664..8913620 100644 --- a/media/base/yuv_scale.h +++ b/media/base/yuv_scale.h @@ -30,7 +30,6 @@ enum Rotate { // 6 5 // ->1 2<- - // Scale a frame of YV12 (aka YUV420) to 32 bit ARGB. void ScaleYV12ToRGB32(const uint8* yplane, const uint8* uplane, diff --git a/media/base/yuv_scale_unittest.cc b/media/base/yuv_scale_unittest.cc index c81c74f..2be0b7b 100644 --- a/media/base/yuv_scale_unittest.cc +++ b/media/base/yuv_scale_unittest.cc @@ -5,6 +5,7 @@ #include "base/base_paths.h" #include "base/file_util.h" #include "media/base/yuv_scale.h" +#include "media/base/yuv_row.h" #include "testing/gtest/include/gtest/gtest.h" // Reference images were created with the following steps @@ -33,13 +34,15 @@ static const int kScaledWidth = 1024; static const int kScaledHeight = 768; static const int kBpp = 4; +// TODO(fbarchard): Move hash function to somewhere common. +namespace { // DJB2 hash -unsigned int hash(unsigned char *s, size_t len) { - unsigned int hash = 5381; +unsigned int hash(unsigned char *s, size_t len, unsigned int hash = 5381) { while (len--) hash = hash * 33 + *s++; return hash; } +} TEST(YuvScaleTest, Basic) { // Read YUV reference data from file. @@ -76,7 +79,12 @@ TEST(YuvScaleTest, Basic) { // To get this hash value, run once and examine the following EXPECT_EQ. // Then plug new hash value into EXPECT_EQ statements. - EXPECT_EQ(rgb_hash, 1849654084u); + // TODO(fbarchard): Make reference code mimic MMX exactly +#if USE_MMX + EXPECT_EQ(379971680u, rgb_hash); +#else + EXPECT_EQ(197274901u, rgb_hash); +#endif return; // This is here to allow you to put a break point on this line } @@ -115,7 +123,12 @@ TEST(YV16ScaleTest, Basic) { // To get this hash value, run once and examine the following EXPECT_EQ. // Then plug new hash value into EXPECT_EQ statements. - EXPECT_EQ(rgb_hash, 1297606858u); + // TODO(fbarchard): Make reference code mimic MMX exactly +#if USE_MMX + EXPECT_EQ(2317989539u, rgb_hash); +#else + EXPECT_EQ(2946450771u, rgb_hash); +#endif return; } diff --git a/media/media.gyp b/media/media.gyp index 58297ed..5ed4720 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -66,6 +66,10 @@ 'base/video_frame_impl.h', 'base/yuv_convert.cc', 'base/yuv_convert.h', + 'base/yuv_row_win.cc', + 'base/yuv_row_mac.cc', + 'base/yuv_row_linux.cc', + 'base/yuv_row.h', 'base/yuv_scale.cc', 'base/yuv_scale.h', 'filters/audio_renderer_base.cc', |