summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/base/yuv_convert.cc180
-rw-r--r--media/base/yuv_convert.h12
-rw-r--r--media/base/yuv_convert_unittest.cc98
-rw-r--r--media/base/yuv_row.h36
-rw-r--r--media/base/yuv_row_posix.cc547
-rw-r--r--media/base/yuv_row_table.cc233
-rw-r--r--media/base/yuv_row_win.cc402
-rw-r--r--media/media.gyp1
8 files changed, 682 insertions, 827 deletions
diff --git a/media/base/yuv_convert.cc b/media/base/yuv_convert.cc
index 0e06c00..e9b8c59 100644
--- a/media/base/yuv_convert.cc
+++ b/media/base/yuv_convert.cc
@@ -28,29 +28,30 @@
#endif
#endif
-#if USE_SSE
+#if USE_SSE2
#include <emmintrin.h>
#endif
namespace media {
-// 16.16 fixed point arithmetic.
+// 16.16 fixed point arithmetic
const int kFractionBits = 16;
const int kFractionMax = 1 << kFractionBits;
+const int kFractionMask = ((1 << kFractionBits) - 1);
// Convert a frame of YUV to 32 bit ARGB.
void ConvertYUVToRGB32(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int height,
+ int source_width,
+ int source_height,
int y_pitch,
int uv_pitch,
int rgb_pitch,
YUVType yuv_type) {
unsigned int y_shift = yuv_type;
- for (int y = 0; y < height; ++y) {
+ for (int y = 0; y < source_height; ++y) {
uint8* rgb_row = rgb_buf + y * rgb_pitch;
const uint8* y_ptr = y_buf + y * y_pitch;
const uint8* u_ptr = u_buf + (y >> y_shift) * uv_pitch;
@@ -60,26 +61,25 @@ void ConvertYUVToRGB32(const uint8* y_buf,
u_ptr,
v_ptr,
rgb_row,
- width);
+ source_width);
}
// MMX used for FastConvertYUVToRGB32Row requires emms instruction.
EMMS();
}
-#if USE_MMX
-#if USE_SSE
+#if USE_SSE2
// FilterRows combines two rows of the image using linear interpolation.
// SSE2 version blends 8 pixels at a time.
static void FilterRows(uint8* ybuf, const uint8* y0_ptr, const uint8* y1_ptr,
- int width, int scaled_y_fraction) {
+ int source_width, int source_y_fraction) {
__m128i zero = _mm_setzero_si128();
__m128i y1_fraction = _mm_set1_epi16(
- static_cast<uint16>(scaled_y_fraction >> 8));
+ static_cast<uint16>(source_y_fraction >> 8));
__m128i y0_fraction = _mm_set1_epi16(
- static_cast<uint16>((scaled_y_fraction >> 8) ^ 255));
+ static_cast<uint16>(256 - (source_y_fraction >> 8)));
- uint8* end = ybuf + width;
+ uint8* end = ybuf + source_width;
if (ybuf < end) {
do {
__m128i y0 = _mm_loadl_epi64(reinterpret_cast<__m128i const*>(y0_ptr));
@@ -99,17 +99,17 @@ static void FilterRows(uint8* ybuf, const uint8* y0_ptr, const uint8* y1_ptr,
}
}
-#else
+#elif USE_MMX
// MMX version blends 4 pixels at a time.
static void FilterRows(uint8* ybuf, const uint8* y0_ptr, const uint8* y1_ptr,
- int width, int scaled_y_fraction) {
+ int source_width, int source_y_fraction) {
__m64 zero = _mm_setzero_si64();
__m64 y1_fraction = _mm_set1_pi16(
- static_cast<int16>(scaled_y_fraction >> 8));
+ static_cast<int16>(source_y_fraction >> 8));
__m64 y0_fraction = _mm_set1_pi16(
- static_cast<int16>((scaled_y_fraction >> 8) ^ 255));
+ static_cast<int16>(256 - (source_y_fraction >> 8)));
- uint8* end = ybuf + width;
+ uint8* end = ybuf + source_width;
if (ybuf < end) {
do {
__m64 y0 = _mm_cvtsi32_si64(*reinterpret_cast<const int *>(y0_ptr));
@@ -128,38 +128,39 @@ static void FilterRows(uint8* ybuf, const uint8* y0_ptr, const uint8* y1_ptr,
} while (ybuf < end);
}
}
-
-#endif // USE_SSE
-#else // no MMX or SSE
+#else // no MMX or SSE2
// C version blends 4 pixels at a time.
static void FilterRows(uint8* ybuf, const uint8* y0_ptr, const uint8* y1_ptr,
- int width, int scaled_y_fraction) {
- int y0_fraction = kFractionMax - scaled_y_fraction;
- int y1_fraction = scaled_y_fraction;
- uint8* end = ybuf + width;
+ int source_width, int source_y_fraction) {
+ int y1_fraction = source_y_fraction >> 8;
+ int y0_fraction = 256 - (source_y_fraction >> 8);
+
+ int y0_fraction = kFractionMax - source_y_fraction;
+ int y1_fraction = source_y_fraction;
+ uint8* end = ybuf + source_width;
if (ybuf < end) {
do {
- ybuf[0] = (y0_ptr[0] * (y0_fraction) + y1_ptr[0] * (y1_fraction)) >> 16;
- ybuf[1] = (y0_ptr[1] * (y0_fraction) + y1_ptr[1] * (y1_fraction)) >> 16;
- ybuf[2] = (y0_ptr[2] * (y0_fraction) + y1_ptr[2] * (y1_fraction)) >> 16;
- ybuf[3] = (y0_ptr[3] * (y0_fraction) + y1_ptr[3] * (y1_fraction)) >> 16;
+ ybuf[0] = (y0_ptr[0] * (y0_fraction) + y1_ptr[0] * (y1_fraction)) >> 8;
+ ybuf[1] = (y0_ptr[1] * (y0_fraction) + y1_ptr[1] * (y1_fraction)) >> 8;
+ ybuf[2] = (y0_ptr[2] * (y0_fraction) + y1_ptr[2] * (y1_fraction)) >> 8;
+ ybuf[3] = (y0_ptr[3] * (y0_fraction) + y1_ptr[3] * (y1_fraction)) >> 8;
y0_ptr += 4;
y1_ptr += 4;
ybuf += 4;
} while (ybuf < end);
}
}
-#endif // USE_MMX
+#endif
// Scale a frame of YUV to 32 bit ARGB.
void ScaleYUVToRGB32(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
+ int source_width,
+ int source_height,
int width,
int height,
- int scaled_width,
- int scaled_height,
int y_pitch,
int uv_pitch,
int rgb_pitch,
@@ -170,7 +171,8 @@ void ScaleYUVToRGB32(const uint8* y_buf,
// Disable filtering if the screen is too big (to avoid buffer overflows).
// This should never happen to regular users: they don't have monitors
// wider than 8192 pixels.
- if (width > kFilterBufferSize)
+ // TODO(fbarchard): Allow rotated videos to filter.
+ if (source_width > kFilterBufferSize || view_rotate)
filter = FILTER_NONE;
unsigned int y_shift = yuv_type;
@@ -185,46 +187,46 @@ void ScaleYUVToRGB32(const uint8* y_buf,
(view_rotate == ROTATE_270) ||
(view_rotate == MIRROR_ROTATE_0) ||
(view_rotate == MIRROR_ROTATE_90)) {
- y_buf += width - 1;
- u_buf += width / 2 - 1;
- v_buf += width / 2 - 1;
- width = -width;
+ y_buf += source_width - 1;
+ u_buf += source_width / 2 - 1;
+ v_buf += source_width / 2 - 1;
+ source_width = -source_width;
}
// Rotations that start at bottom of image.
if ((view_rotate == ROTATE_90) ||
(view_rotate == ROTATE_180) ||
(view_rotate == MIRROR_ROTATE_90) ||
(view_rotate == MIRROR_ROTATE_180)) {
- y_buf += (height - 1) * y_pitch;
- u_buf += ((height >> y_shift) - 1) * uv_pitch;
- v_buf += ((height >> y_shift) - 1) * uv_pitch;
- height = -height;
+ y_buf += (source_height - 1) * y_pitch;
+ u_buf += ((source_height >> y_shift) - 1) * uv_pitch;
+ v_buf += ((source_height >> y_shift) - 1) * uv_pitch;
+ source_height = -source_height;
}
// Handle zero sized destination.
- if (scaled_width == 0 || scaled_height == 0)
+ if (width == 0 || height == 0)
return;
- int scaled_dx = width * kFractionMax / scaled_width;
- int scaled_dy = height * kFractionMax / scaled_height;
- int scaled_dx_uv = scaled_dx;
+ int source_dx = source_width * kFractionMax / width;
+ int source_dy = source_height * kFractionMax / height;
+ int source_dx_uv = source_dx;
if ((view_rotate == ROTATE_90) ||
(view_rotate == ROTATE_270)) {
- int tmp = scaled_height;
- scaled_height = scaled_width;
- scaled_width = tmp;
- tmp = height;
+ int tmp = height;
height = width;
width = tmp;
- int original_dx = scaled_dx;
- int original_dy = scaled_dy;
- scaled_dx = ((original_dy >> kFractionBits) * y_pitch) << kFractionBits;
- scaled_dx_uv = ((original_dy >> kFractionBits) * uv_pitch) << kFractionBits;
- scaled_dy = original_dx;
+ tmp = source_height;
+ source_height = source_width;
+ source_width = tmp;
+ int original_dx = source_dx;
+ int original_dy = source_dy;
+ source_dx = ((original_dy >> kFractionBits) * y_pitch) << kFractionBits;
+ source_dx_uv = ((original_dy >> kFractionBits) * uv_pitch) << kFractionBits;
+ source_dy = original_dx;
if (view_rotate == ROTATE_90) {
y_pitch = -1;
uv_pitch = -1;
- height = -height;
+ source_height = -source_height;
} else {
y_pitch = 1;
uv_pitch = 1;
@@ -236,8 +238,9 @@ void ScaleYUVToRGB32(const uint8* y_buf,
uint8 ybuf[kFilterBufferSize + 16];
uint8 ubuf[kFilterBufferSize / 2 + 16];
uint8 vbuf[kFilterBufferSize / 2 + 16];
- int yscale_fixed = (height << kFractionBits) / scaled_height;
- for (int y = 0; y < scaled_height; ++y) {
+ // TODO(fbarchard): Fixed point math is off by 1 on negatives.
+ int yscale_fixed = (source_height << kFractionBits) / height;
+ for (int y = 0; y < height; ++y) {
uint8* dest_pixel = rgb_buf + y * rgb_pitch;
int source_y_subpixel = (y * yscale_fixed);
int source_y = source_y_subpixel >> kFractionBits;
@@ -250,8 +253,8 @@ void ScaleYUVToRGB32(const uint8* y_buf,
const uint8* v0_ptr = v_buf + (source_y >> y_shift) * uv_pitch;
const uint8* v1_ptr = v0_ptr + uv_pitch;
- int scaled_y_fraction = source_y_subpixel & (kFractionMax - 1);
- int scaled_uv_fraction = (source_y_subpixel >> y_shift) & (kFractionMax - 1);
+ int source_y_fraction = source_y_subpixel & kFractionMask;
+ int source_uv_fraction = (source_y_subpixel >> y_shift) & kFractionMask;
const uint8* y_ptr = y0_ptr;
const uint8* u_ptr = u0_ptr;
@@ -260,42 +263,63 @@ void ScaleYUVToRGB32(const uint8* y_buf,
// TODO(fbarchard): Remove memcpy when not necessary.
if (filter == media::FILTER_BILINEAR) {
if (yscale_fixed != kFractionMax &&
- scaled_y_fraction && ((source_y + 1) < height)) {
- FilterRows(ybuf, y0_ptr, y1_ptr, width, scaled_y_fraction);
+ source_y_fraction && ((source_y + 1) < source_height)) {
+ FilterRows(ybuf, y0_ptr, y1_ptr, source_width, source_y_fraction);
} else {
- memcpy(ybuf, y0_ptr, width);
+ memcpy(ybuf, y0_ptr, source_width);
}
y_ptr = ybuf;
- ybuf[width] = ybuf[width-1];
- int uv_width = (width + 1) / 2;
+ ybuf[source_width] = ybuf[source_width-1];
+ int uv_source_width = (source_width + 1) / 2;
if (yscale_fixed != kFractionMax &&
- scaled_uv_fraction &&
- (((source_y >> y_shift) + 1) < (height >> y_shift))) {
- FilterRows(ubuf, u0_ptr, u1_ptr, uv_width, scaled_uv_fraction);
- FilterRows(vbuf, v0_ptr, v1_ptr, uv_width, scaled_uv_fraction);
+ source_uv_fraction &&
+ (((source_y >> y_shift) + 1) < (source_height >> y_shift))) {
+ FilterRows(ubuf, u0_ptr, u1_ptr, uv_source_width, source_uv_fraction);
+ FilterRows(vbuf, v0_ptr, v1_ptr, uv_source_width, source_uv_fraction);
} else {
- memcpy(ubuf, u0_ptr, uv_width);
- memcpy(vbuf, v0_ptr, uv_width);
+ memcpy(ubuf, u0_ptr, uv_source_width);
+ memcpy(vbuf, v0_ptr, uv_source_width);
}
u_ptr = ubuf;
v_ptr = vbuf;
- ubuf[uv_width] = ubuf[uv_width - 1];
- vbuf[uv_width] = vbuf[uv_width - 1];
+ ubuf[uv_source_width] = ubuf[uv_source_width - 1];
+ vbuf[uv_source_width] = vbuf[uv_source_width - 1];
}
- if (scaled_dx == kFractionMax) { // Not scaled
+ if (source_dx == kFractionMax) { // Not scaled
FastConvertYUVToRGB32Row(y_ptr, u_ptr, v_ptr,
- dest_pixel, scaled_width);
+ dest_pixel, width);
} else {
if (filter == FILTER_BILINEAR)
LinearScaleYUVToRGB32Row(y_ptr, u_ptr, v_ptr,
- dest_pixel, scaled_width, scaled_dx);
- else
+ dest_pixel, width, source_dx);
+ else {
+// Specialized scalers and rotation.
+#if USE_MMX && defined(_MSC_VER)
+ if (width == (source_width * 2)) {
+ DoubleYUVToRGB32Row(y_ptr, u_ptr, v_ptr,
+ dest_pixel, width);
+ } else if ((source_dx & kFractionMask) == 0) {
+ // Scaling by integer scale factor. ie half.
+ ConvertYUVToRGB32Row(y_ptr, u_ptr, v_ptr,
+ dest_pixel, width,
+ source_dx >> kFractionBits);
+ } else if (source_dx_uv == source_dx) { // Not rotated.
+ ScaleYUVToRGB32Row(y_ptr, u_ptr, v_ptr,
+ dest_pixel, width, source_dx);
+ } else {
+ RotateConvertYUVToRGB32Row(y_ptr, u_ptr, v_ptr,
+ dest_pixel, width,
+ source_dx >> kFractionBits,
+ source_dx_uv >> kFractionBits);
+ }
+#else
ScaleYUVToRGB32Row(y_ptr, u_ptr, v_ptr,
- dest_pixel, scaled_width, scaled_dx);
+ dest_pixel, width, source_dx);
+#endif
+ }
}
}
-
- // MMX used for FastConvertYUVToRGB32Row requires emms instruction.
+ // MMX used for FastConvertYUVToRGB32Row and FilterRows requires emms.
EMMS();
}
diff --git a/media/base/yuv_convert.h b/media/base/yuv_convert.h
index cca7d49..2ef4847 100644
--- a/media/base/yuv_convert.h
+++ b/media/base/yuv_convert.h
@@ -41,8 +41,8 @@ void ConvertYUVToRGB32(const uint8* yplane,
const uint8* uplane,
const uint8* vplane,
uint8* rgbframe,
- int frame_width,
- int frame_height,
+ int source_width,
+ int source_height,
int ystride,
int uvstride,
int rgbstride,
@@ -54,10 +54,10 @@ void ScaleYUVToRGB32(const uint8* yplane,
const uint8* uplane,
const uint8* vplane,
uint8* rgbframe,
- int frame_width,
- int frame_height,
- int scaled_width,
- int scaled_height,
+ int source_width,
+ int source_height,
+ int width,
+ int height,
int ystride,
int uvstride,
int rgbstride,
diff --git a/media/base/yuv_convert_unittest.cc b/media/base/yuv_convert_unittest.cc
index 29dbeea..8a919ad 100644
--- a/media/base/yuv_convert_unittest.cc
+++ b/media/base/yuv_convert_unittest.cc
@@ -21,17 +21,17 @@
// Size of raw image.
// Size of raw image.
-static const int kWidth = 640;
-static const int kHeight = 360;
+static const int kSourceWidth = 640;
+static const int kSourceHeight = 360;
static const int kScaledWidth = 1024;
static const int kScaledHeight = 768;
static const int kBpp = 4;
// Surface sizes.
-static const size_t kYUV12Size = kWidth * kHeight * 12 / 8;
-static const size_t kYUV16Size = kWidth * kHeight * 16 / 8;
-static const size_t kRGBSize = kWidth * kHeight * kBpp;
-static const size_t kRGBSizeConverted = kWidth * kHeight * kBpp;
+static const size_t kYUV12Size = kSourceWidth * kSourceHeight * 12 / 8;
+static const size_t kYUV16Size = kSourceWidth * kSourceHeight * 16 / 8;
+static const size_t kRGBSize = kSourceWidth * kSourceHeight * kBpp;
+static const size_t kRGBSizeConverted = kSourceWidth * kSourceHeight * kBpp;
// Set to 100 to time ConvertYUVToRGB32.
static const int kTestTimes = 1;
@@ -57,13 +57,13 @@ TEST(YUVConvertTest, YV12) {
for (int i = 0; i < kTestTimes; ++i) {
// Convert a frame of YUV to 32 bit ARGB.
media::ConvertYUVToRGB32(yuv_bytes.get(), // Y
- yuv_bytes.get() + kWidth * kHeight, // U
- yuv_bytes.get() + kWidth * kHeight * 5 / 4, // V
+ yuv_bytes.get() + kSourceWidth * kSourceHeight, // U
+ yuv_bytes.get() + kSourceWidth * kSourceHeight * 5 / 4, // V
rgb_converted_bytes.get(), // RGB output
- kWidth, kHeight, // Dimensions
- kWidth, // YStride
- kWidth / 2, // UVStride
- kWidth * kBpp, // RGBStride
+ kSourceWidth, kSourceHeight, // Dimensions
+ kSourceWidth, // YStride
+ kSourceWidth / 2, // UVStride
+ kSourceWidth * kBpp, // RGBStride
media::YV12);
}
@@ -73,12 +73,7 @@ TEST(YUVConvertTest, YV12) {
// To get this hash value, run once and examine the following EXPECT_EQ.
// Then plug new hash value into EXPECT_EQ statements.
- // TODO(fbarchard): Make reference code mimic MMX exactly
-#if USE_MMX
EXPECT_EQ(2413171226u, rgb_hash);
-#else
- EXPECT_EQ(2936300063u, rgb_hash);
-#endif
}
TEST(YUVConvertTest, YV16) {
@@ -102,13 +97,13 @@ TEST(YUVConvertTest, YV16) {
for (int i = 0; i < kTestTimes; ++i) {
// Convert a frame of YUV to 32 bit ARGB.
media::ConvertYUVToRGB32(yuv_bytes.get(), // Y
- yuv_bytes.get() + kWidth * kHeight, // U
- yuv_bytes.get() + kWidth * kHeight * 3 / 2, // V
+ yuv_bytes.get() + kSourceWidth * kSourceHeight, // U
+ yuv_bytes.get() + kSourceWidth * kSourceHeight * 3 / 2, // V
rgb_converted_bytes.get(), // RGB output
- kWidth, kHeight, // Dimensions
- kWidth, // YStride
- kWidth / 2, // UVStride
- kWidth * kBpp, // RGBStride
+ kSourceWidth, kSourceHeight, // Dimensions
+ kSourceWidth, // YStride
+ kSourceWidth / 2, // UVStride
+ kSourceWidth * kBpp, // RGBStride
media::YV16);
}
@@ -118,12 +113,7 @@ TEST(YUVConvertTest, YV16) {
// To get this hash value, run once and examine the following EXPECT_EQ.
// Then plug new hash value into EXPECT_EQ statements.
- // TODO(fbarchard): Make reference code mimic MMX exactly
-#if USE_MMX
EXPECT_EQ(4222342047u, rgb_hash);
-#else
- EXPECT_EQ(106869773u, rgb_hash);
-#endif
}
TEST(YUVScaleTest, YV12) {
@@ -134,7 +124,7 @@ TEST(YUVScaleTest, YV12) {
.Append(FILE_PATH_LITERAL("test"))
.Append(FILE_PATH_LITERAL("data"))
.Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv"));
- const size_t size_of_yuv = kWidth * kHeight * 12 / 8; // 12 bpp.
+ const size_t size_of_yuv = kSourceWidth * kSourceHeight * 12 / 8; // 12 bpp.
scoped_array<uint8> yuv_bytes(new uint8[size_of_yuv]);
EXPECT_EQ(static_cast<int>(size_of_yuv),
file_util::ReadFile(yuv_url,
@@ -143,35 +133,30 @@ TEST(YUVScaleTest, YV12) {
// Scale a frame of YUV to 32 bit ARGB.
const size_t size_of_rgb_scaled = kScaledWidth * kScaledHeight * kBpp;
- scoped_array<uint8> rgb_scaled_bytes(new uint8[size_of_rgb_scaled]);
+ scoped_array<uint8> rgb_source_bytes(new uint8[size_of_rgb_scaled]);
for (int i = 0; i < kTestTimes; ++i) {
media::ScaleYUVToRGB32(yuv_bytes.get(), // Y
- yuv_bytes.get() + kWidth * kHeight, // U
- yuv_bytes.get() + kWidth * kHeight * 5 / 4, // V
- rgb_scaled_bytes.get(), // Rgb output
- kWidth, kHeight, // Dimensions
+ yuv_bytes.get() + kSourceWidth * kSourceHeight, // U
+ yuv_bytes.get() + kSourceWidth * kSourceHeight * 5 / 4, // V
+ rgb_source_bytes.get(), // Rgb output
+ kSourceWidth, kSourceHeight, // Dimensions
kScaledWidth, kScaledHeight, // Dimensions
- kWidth, // YStride
- kWidth / 2, // UvStride
+ kSourceWidth, // YStride
+ kSourceWidth / 2, // UvStride
kScaledWidth * kBpp, // RgbStride
media::YV12,
media::ROTATE_0,
media::FILTER_NONE);
}
- unsigned int rgb_hash = DJB2Hash(rgb_scaled_bytes.get(), size_of_rgb_scaled,
+ unsigned int rgb_hash = DJB2Hash(rgb_source_bytes.get(), size_of_rgb_scaled,
kDJB2HashSeed);
// To get this hash value, run once and examine the following EXPECT_EQ.
// Then plug new hash value into EXPECT_EQ statements.
- // TODO(fbarchard): Make reference code mimic MMX exactly
-#if USE_MMX
EXPECT_EQ(4259656254u, rgb_hash);
-#else
- EXPECT_EQ(197274901u, rgb_hash);
-#endif
}
TEST(YUVScaleTest, YV16) {
@@ -182,7 +167,7 @@ TEST(YUVScaleTest, YV16) {
.Append(FILE_PATH_LITERAL("test"))
.Append(FILE_PATH_LITERAL("data"))
.Append(FILE_PATH_LITERAL("bali_640x360_P422.yuv"));
- const size_t size_of_yuv = kWidth * kHeight * 16 / 8; // 16 bpp.
+ const size_t size_of_yuv = kSourceWidth * kSourceHeight * 16 / 8; // 16 bpp.
scoped_array<uint8> yuv_bytes(new uint8[size_of_yuv]);
EXPECT_EQ(static_cast<int>(size_of_yuv),
file_util::ReadFile(yuv_url,
@@ -191,35 +176,30 @@ TEST(YUVScaleTest, YV16) {
// Scale a frame of YUV to 32 bit ARGB.
const size_t size_of_rgb_scaled = kScaledWidth * kScaledHeight * kBpp;
- scoped_array<uint8> rgb_scaled_bytes(new uint8[size_of_rgb_scaled]);
+ scoped_array<uint8> rgb_source_bytes(new uint8[size_of_rgb_scaled]);
for (int i = 0; i < kTestTimes; ++i) {
media::ScaleYUVToRGB32(yuv_bytes.get(), // Y
- yuv_bytes.get() + kWidth * kHeight, // U
- yuv_bytes.get() + kWidth * kHeight * 3 / 2, // V
- rgb_scaled_bytes.get(), // Rgb output
- kWidth, kHeight, // Dimensions
+ yuv_bytes.get() + kSourceWidth * kSourceHeight, // U
+ yuv_bytes.get() + kSourceWidth * kSourceHeight * 3 / 2, // V
+ rgb_source_bytes.get(), // Rgb output
+ kSourceWidth, kSourceHeight, // Dimensions
kScaledWidth, kScaledHeight, // Dimensions
- kWidth, // YStride
- kWidth / 2, // UvStride
+ kSourceWidth, // YStride
+ kSourceWidth / 2, // UvStride
kScaledWidth * kBpp, // RgbStride
media::YV16,
media::ROTATE_0,
media::FILTER_NONE);
}
- unsigned int rgb_hash = DJB2Hash(rgb_scaled_bytes.get(), size_of_rgb_scaled,
+ unsigned int rgb_hash = DJB2Hash(rgb_source_bytes.get(), size_of_rgb_scaled,
kDJB2HashSeed);
// To get this hash value, run once and examine the following EXPECT_EQ.
// Then plug new hash value into EXPECT_EQ statements.
- // TODO(fbarchard): Make reference code mimic MMX exactly
-#if USE_MMX
EXPECT_EQ(974965419u, rgb_hash);
-#else
- EXPECT_EQ(2946450771u, rgb_hash);
-#endif
}
// This tests a known worst case YUV value, and for overflow.
@@ -236,13 +216,7 @@ TEST(YUVConvertTest, Clamp) {
// Prefill extra large destination buffer to test for overflow.
unsigned char rgb[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
- // TODO(fbarchard): Make reference code mimic MMX exactly
- // The code is fixed point and has slight rounding differences.
-#if USE_MMX
unsigned char expected[8] = { 255, 255, 104, 255, 4, 5, 6, 7 };
-#else
- unsigned char expected[8] = { 255, 255, 105, 255, 4, 5, 6, 7 };
-#endif
// Convert a frame of YUV to 32 bit ARGB.
media::ConvertYUVToRGB32(&y, // Y
&u, // U
diff --git a/media/base/yuv_row.h b/media/base/yuv_row.h
index 2d8a9a6..7855b9b 100644
--- a/media/base/yuv_row.h
+++ b/media/base/yuv_row.h
@@ -19,7 +19,7 @@ void FastConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width);
+ int source_width);
// Can do 1x, half size or any scale down by an integer amount.
// Step can be negative (mirroring, rotate 180).
@@ -28,7 +28,7 @@ void ConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
+ int source_width,
int step);
// Rotate is like Convert, but applies different step to Y versus U and V.
@@ -38,7 +38,7 @@ void RotateConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
+ int source_width,
int ystep,
int uvstep);
@@ -48,7 +48,7 @@ void DoubleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width);
+ int source_width);
// Handles arbitrary scaling up or down.
// Mirroring is supported, but not 90 or 270 degree rotation.
@@ -58,16 +58,26 @@ void ScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx);
+ int source_width,
+ int source_dx);
void LinearScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
+ int source_width,
int dx);
-} // extern "C"
+
+#if defined(_MSC_VER)
+#define SIMD_ALIGNED(var) __declspec(align(16)) var
+#else
+#define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
+#endif
+extern SIMD_ALIGNED(int16 kCoefficientsRgbY[768][4]);
+
+// Method to force C version.
+//#define USE_MMX 0
+//#define USE_SSE2 0
#if !defined(USE_MMX)
// Windows, Mac and Linux/BSD use MMX
@@ -78,15 +88,17 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
#endif
#endif
-#if !defined(USE_SSE)
+#if !defined(USE_SSE2)
#if defined(__SSE2__) || defined(ARCH_CPU_X86_64) || _M_IX86_FP==2
-#define USE_SSE 1
+#define USE_SSE2 1
#else
-#define USE_SSE 0
+#define USE_SSE2 0
#endif
#endif
// x64 uses MMX2 (SSE) so emms is not required.
+// Warning C4799: function has no EMMS instruction.
+// EMMS() is slow and should be called by the calling function once per image.
#if USE_MMX && !defined(ARCH_CPU_X86_64)
#if defined(_MSC_VER)
#define EMMS() __asm emms
@@ -98,4 +110,6 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
#define EMMS()
#endif
+} // extern "C"
+
#endif // MEDIA_BASE_YUV_ROW_H_
diff --git a/media/base/yuv_row_posix.cc b/media/base/yuv_row_posix.cc
index c0d8cb5..b992177 100644
--- a/media/base/yuv_row_posix.cc
+++ b/media/base/yuv_row_posix.cc
@@ -11,244 +11,15 @@
#endif
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[768][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),
-
- // Chroma U table.
- 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),
-
- // Chroma V table.
- 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(ARCH_CPU_X86_64)
+#if USE_SSE2 && defined(ARCH_CPU_X86_64)
// AMD64 ABI uses register paremters.
void FastConvertYUVToRGB32Row(const uint8* y_buf, // rdi
const uint8* u_buf, // rsi
const uint8* v_buf, // rdx
uint8* rgb_buf, // rcx
- int width) { // r8
+ int source_width) { // r8
asm(
"jmp convertend\n"
"convertloop:"
@@ -296,7 +67,7 @@ void FastConvertYUVToRGB32Row(const uint8* y_buf, // rdi
"r"(u_buf), // %1
"r"(v_buf), // %2
"r"(rgb_buf), // %3
- "r"(width), // %4
+ "r"(source_width), // %4
"r" (kCoefficientsRgbY) // %5
: "memory", "r10", "r11", "xmm0", "xmm1", "xmm2", "xmm3"
);
@@ -306,8 +77,8 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, // rdi
const uint8* u_buf, // rsi
const uint8* v_buf, // rdx
uint8* rgb_buf, // rcx
- int width, // r8
- int scaled_dx) { // r9
+ int source_width, // r8
+ int source_dx) { // r9
asm(
"xor %%r11,%%r11\n"
"sub $0x2,%4\n"
@@ -364,9 +135,9 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, // rdi
"r"(u_buf), // %1
"r"(v_buf), // %2
"r"(rgb_buf), // %3
- "r"(width), // %4
+ "r"(source_width), // %4
"r" (kCoefficientsRgbY), // %5
- "r"(static_cast<long>(scaled_dx)) // %6
+ "r"(static_cast<long>(source_dx)) // %6
: "memory", "r10", "r11", "rax", "xmm0", "xmm1", "xmm2"
);
}
@@ -375,8 +146,8 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx) {
+ int source_width,
+ int source_dx) {
asm(
"xor %%r11,%%r11\n"
"sub $0x2,%4\n"
@@ -477,25 +248,23 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
"r"(u_buf), // %1
"r"(v_buf), // %2
"r"(rgb_buf), // %3
- "r"(width), // %4
+ "r"(source_width), // %4
"r" (kCoefficientsRgbY), // %5
- "r"(static_cast<long>(scaled_dx)) // %6
+ "r"(static_cast<long>(source_dx)) // %6
: "memory", "r10", "r11", "r13", "r14", "rax", "xmm0", "xmm1", "xmm2"
);
}
-#else // !AMD64
+#elif USE_MMX && !defined(ARCH_CPU_X86_64) && !defined(__PIC__)
// PIC version is slower because less registers are available, so
// non-PIC is used on platforms where it is possible.
-#if !defined(__PIC__)
-
void FastConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width);
+ int source_width);
asm(
".global FastConvertYUVToRGB32Row\n"
@@ -554,8 +323,8 @@ void ScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx);
+ int source_width,
+ int source_dx);
asm(
".global ScaleYUVToRGB32Row\n"
@@ -628,8 +397,8 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx);
+ int source_width,
+ int source_dx);
asm(
".global LinearScaleYUVToRGB32Row\n"
@@ -640,7 +409,7 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
"mov 0x30(%esp),%ebp\n"
"xor %ebx,%ebx\n"
- // width = width * scaled_dx + ebx
+ // source_width = source_width * source_dx + ebx
"mov 0x34(%esp), %ecx\n"
"imull 0x38(%esp), %ecx\n"
"addl %ebx, %ecx\n"
@@ -732,13 +501,13 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
"ret\n"
);
-#else // __PIC__
+#elif USE_MMX && !defined(ARCH_CPU_X86_64) && defined(__PIC__)
extern void PICConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
+ int source_width,
int16 *kCoefficientsRgbY);
__asm__(
"_PICConvertYUVToRGB32Row:\n"
@@ -796,8 +565,8 @@ void FastConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width) {
- PICConvertYUVToRGB32Row(y_buf, u_buf, v_buf, rgb_buf, width,
+ int source_width) {
+ PICConvertYUVToRGB32Row(y_buf, u_buf, v_buf, rgb_buf, source_width,
&kCoefficientsRgbY[0][0]);
}
@@ -805,8 +574,8 @@ extern void PICScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx,
+ int source_width,
+ int source_dx,
int16 *kCoefficientsRgbY);
__asm__(
@@ -880,9 +649,9 @@ void ScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx) {
- PICScaleYUVToRGB32Row(y_buf, u_buf, v_buf, rgb_buf, width, scaled_dx,
+ int source_width,
+ int source_dx) {
+ PICScaleYUVToRGB32Row(y_buf, u_buf, v_buf, rgb_buf, source_width, source_dx,
&kCoefficientsRgbY[0][0]);
}
@@ -890,8 +659,8 @@ void PICLinearScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx,
+ int source_width,
+ int source_dx,
int16 *kCoefficientsRgbY);
asm(
@@ -903,7 +672,7 @@ void PICLinearScaleYUVToRGB32Row(const uint8* y_buf,
"mov 0x3c(%esp),%edi\n"
"xor %ebx,%ebx\n"
- // width = width * scaled_dx + ebx
+ // source_width = source_width * source_dx + ebx
"mov 0x34(%esp), %ecx\n"
"imull 0x38(%esp), %ecx\n"
"addl %ebx, %ecx\n"
@@ -1000,172 +769,84 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx) {
- PICLinearScaleYUVToRGB32Row(y_buf, u_buf, v_buf, rgb_buf, width, scaled_dx,
+ int source_width,
+ int source_dx) {
+ PICLinearScaleYUVToRGB32Row(y_buf, u_buf, v_buf, rgb_buf, source_width, source_dx,
&kCoefficientsRgbY[0][0]);
}
-#endif // !__PIC__
-
-#endif // !AMD64
-
-#else // USE_MMX
-
-// Reference version of YUV converter.
-static const int kClipTableSize = 256;
-static const int kClipOverflow = 288; // Cb max is 535.
-
-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,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 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,
- 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
- 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
- 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
- 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
- 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
- 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
- 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
- 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
- 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
- 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
- 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 288 overflow values
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // clipped to 255.
- 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, 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, 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, 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>(kRgbClipTable[((value) >> 8) + kClipOverflow]);
+#else // Use C code instead of MMX/SSE2.
+
+// C reference code that mimic the YUV assembly.
+#define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x)))
+#define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \\
+ (((x) + (y)) > 32767 ? 32767 : ((x) + (y))))
+
+static inline void YuvPixel(uint8 y,
+ uint8 u,
+ uint8 v,
+ uint8* rgb_buf) {
+
+ int b = kCoefficientsRgbY[256+u][0];
+ int g = kCoefficientsRgbY[256+u][1];
+ int r = kCoefficientsRgbY[256+u][2];
+ int a = kCoefficientsRgbY[256+u][3];
+
+ b = paddsw(b, kCoefficientsRgbY[512+v][0]);
+ g = paddsw(g, kCoefficientsRgbY[512+v][1]);
+ r = paddsw(r, kCoefficientsRgbY[512+v][2]);
+ a = paddsw(a, kCoefficientsRgbY[512+v][3]);
+
+ b = paddsw(b, kCoefficientsRgbY[y][0]);
+ g = paddsw(g, kCoefficientsRgbY[y][1]);
+ r = paddsw(r, kCoefficientsRgbY[y][2]);
+ a = paddsw(a, kCoefficientsRgbY[y][3]);
+
+ b >>= 6;
+ g >>= 6;
+ r >>= 6;
+ a >>= 6;
+
+ *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) |
+ (packuswb(g) << 8) |
+ (packuswb(r) << 16) |
+ (packuswb(a) << 24);
}
+#if TEST_MMX_YUV
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);
+
+ __asm {
+ movzx eax, u
+ movq mm0, [kCoefficientsRgbY+2048 + 8 * eax]
+ movzx eax, v
+ paddsw mm0, [kCoefficientsRgbY+4096 + 8 * eax]
+ movzx eax, y
+ movq mm1, [kCoefficientsRgbY + 8 * eax]
+ paddsw mm1, mm0
+ psraw mm1, 6
+ packuswb mm1, mm1
+ mov eax, rgb_buf
+ movd [eax], mm1
+ emms
+ }
}
+#endif
void FastConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width) {
- for (int x = 0; x < width; x += 2) {
+ int source_width) {
+ for (int x = 0; x < source_width; x += 2) {
uint8 u = u_buf[x >> 1];
uint8 v = v_buf[x >> 1];
uint8 y0 = y_buf[x];
YuvPixel(y0, u, v, rgb_buf);
- if ((x + 1) < width) {
+ if ((x + 1) < source_width) {
uint8 y1 = y_buf[x + 1];
YuvPixel(y1, u, v, rgb_buf + 4);
}
@@ -1181,16 +862,21 @@ void ScaleYUVToRGB32Row(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 (int x = 0; x < width; ++x) {
- uint8 u = u_buf[scaled_x >> 17];
- uint8 v = v_buf[scaled_x >> 17];
- uint8 y0 = y_buf[scaled_x >> 16];
- YuvPixel(y0, u, v, rgb_buf);
- rgb_buf += 4;
- scaled_x += scaled_dx;
+ int source_width,
+ int dx) {
+ int x = 0;
+ for (int i = 0; i < source_width; i += 2) {
+ int y = y_buf[x >> 16];
+ int u = u_buf[(x >> 17)];
+ int v = v_buf[(x >> 17)];
+ YuvPixel(y, u, v, rgb_buf);
+ x += dx;
+ if ((i + 1) < source_width) {
+ y = y_buf[x >> 16];
+ YuvPixel(y, u, v, rgb_buf+4);
+ x += dx;
+ }
+ rgb_buf += 8;
}
}
@@ -1198,22 +884,35 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
+ int source_width,
int dx) {
- for (int x = 0; x < width * dx; x += dx) {
+ int x = 0;
+ for (int i = 0; i < source_width; i += 2) {
int y0 = y_buf[x >> 16];
int y1 = y_buf[(x >> 16) + 1];
int u0 = u_buf[(x >> 17)];
int u1 = u_buf[(x >> 17) + 1];
int v0 = v_buf[(x >> 17)];
int v1 = v_buf[(x >> 17) + 1];
- int y = ((x & 65535) * y1 + ((x & 65535) ^ 65535) * y0) >> 16;
- int u = ((x & 65535) * u1 + ((x & 65535) ^ 65535) * u0) >> 16;
- int v = ((x & 65535) * v1 + ((x & 65535) ^ 65535) * v0) >> 16;
+ int y_frac = (x & 65535);
+ int uv_frac = ((x >> 1) & 65535);
+ int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
+ int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16;
+ int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16;
YuvPixel(y, u, v, rgb_buf);
- rgb_buf += 4;
+ x += dx;
+ if ((i + 1) < source_width) {
+ y0 = y_buf[x >> 16];
+ y1 = y_buf[(x >> 16) + 1];
+ y_frac = (x & 65535);
+ y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
+ YuvPixel(y, u, v, rgb_buf+4);
+ x += dx;
+ }
+ rgb_buf += 8;
}
}
#endif // USE_MMX
} // extern "C"
+
diff --git a/media/base/yuv_row_table.cc b/media/base/yuv_row_table.cc
new file mode 100644
index 0000000..296380b
--- /dev/null
+++ b/media/base/yuv_row_table.cc
@@ -0,0 +1,233 @@
+// Copyright (c) 2010 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"
+
+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), \
+ 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 \
+}
+
+SIMD_ALIGNED(int16 kCoefficientsRgbY[256 * 3][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),
+
+ // Chroma U table.
+ 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),
+
+ // Chroma V table.
+ 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
+
+} // extern "C"
diff --git a/media/base/yuv_row_win.cc b/media/base/yuv_row_win.cc
index c7cf8d3..e5354a8 100644
--- a/media/base/yuv_row_win.cc
+++ b/media/base/yuv_row_win.cc
@@ -4,254 +4,25 @@
#include "media/base/yuv_row.h"
-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), \
- 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
-
-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),
-};
+#define kCoefficientsRgbU kCoefficientsRgbY + 2048
+#define kCoefficientsRgbV kCoefficientsRgbY + 4096
-#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)
+extern "C" {
+#if USE_MMX
__declspec(naked)
void FastConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width) {
+ int source_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
+ mov ecx, [esp + 32 + 20] // source_width
jmp convertend
convertloop :
@@ -302,7 +73,7 @@ void ConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
+ int source_width,
int step) {
__asm {
pushad
@@ -310,7 +81,7 @@ void ConvertYUVToRGB32Row(const uint8* y_buf,
mov edi, [esp + 32 + 8] // U
mov esi, [esp + 32 + 12] // V
mov ebp, [esp + 32 + 16] // rgb
- mov ecx, [esp + 32 + 20] // width
+ mov ecx, [esp + 32 + 20] // source_width
mov ebx, [esp + 32 + 24] // step
jmp wend
@@ -363,7 +134,7 @@ void RotateConvertYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
+ int source_width,
int ystep,
int uvstep) {
__asm {
@@ -372,7 +143,7 @@ void RotateConvertYUVToRGB32Row(const uint8* y_buf,
mov edi, [esp + 32 + 8] // U
mov esi, [esp + 32 + 12] // V
mov ebp, [esp + 32 + 16] // rgb
- mov ecx, [esp + 32 + 20] // width
+ mov ecx, [esp + 32 + 20] // source_width
jmp wend
wloop :
@@ -426,14 +197,14 @@ void DoubleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width) {
+ int source_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
+ mov ecx, [esp + 32 + 20] // source_width
jmp wend
wloop :
@@ -498,7 +269,7 @@ void ScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
+ int source_width,
int dx) {
__asm {
pushad
@@ -506,7 +277,7 @@ void ScaleYUVToRGB32Row(const uint8* y_buf,
mov edi, [esp + 32 + 8] // U
mov esi, [esp + 32 + 12] // V
mov ebp, [esp + 32 + 16] // rgb
- mov ecx, [esp + 32 + 20] // width
+ mov ecx, [esp + 32 + 20] // source_width
xor ebx, ebx // x
jmp scaleend
@@ -571,14 +342,14 @@ void LinearScaleYUVToRGB32Row(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
- int width,
- int scaled_dx) {
+ int source_width,
+ int source_dx) {
__asm {
pushad
mov edx, [esp + 32 + 4]
mov edi, [esp + 32 + 8]
mov ebp, [esp + 32 + 16]
- mov ecx, [esp + 32 + 20] // width = width * scaled_dx + ebx
+ mov ecx, [esp + 32 + 20] // source_width = source_width * source_dx + ebx
imul ecx, [esp + 32 + 24]
xor ebx, ebx
add ecx, ebx
@@ -668,5 +439,144 @@ lscalelastpixel:
ret
};
}
+#else // USE_MMX
+
+// C reference code that mimic the YUV assembly.
+#define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x)))
+#define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \\
+ (((x) + (y)) > 32767 ? 32767 : ((x) + (y))))
+
+static inline void YuvPixel(uint8 y,
+ uint8 u,
+ uint8 v,
+ uint8* rgb_buf) {
+
+ int b = kCoefficientsRgbY[256+u][0];
+ int g = kCoefficientsRgbY[256+u][1];
+ int r = kCoefficientsRgbY[256+u][2];
+ int a = kCoefficientsRgbY[256+u][3];
+
+ b = paddsw(b, kCoefficientsRgbY[512+v][0]);
+ g = paddsw(g, kCoefficientsRgbY[512+v][1]);
+ r = paddsw(r, kCoefficientsRgbY[512+v][2]);
+ a = paddsw(a, kCoefficientsRgbY[512+v][3]);
+
+ b = paddsw(b, kCoefficientsRgbY[y][0]);
+ g = paddsw(g, kCoefficientsRgbY[y][1]);
+ r = paddsw(r, kCoefficientsRgbY[y][2]);
+ a = paddsw(a, kCoefficientsRgbY[y][3]);
+
+ b >>= 6;
+ g >>= 6;
+ r >>= 6;
+ a >>= 6;
+
+ *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) |
+ (packuswb(g) << 8) |
+ (packuswb(r) << 16) |
+ (packuswb(a) << 24);
+}
+
+#if TEST_MMX_YUV
+static inline void YuvPixel(uint8 y,
+ uint8 u,
+ uint8 v,
+ uint8* rgb_buf) {
+
+ __asm {
+ movzx eax, u
+ movq mm0, [kCoefficientsRgbY+2048 + 8 * eax]
+ movzx eax, v
+ paddsw mm0, [kCoefficientsRgbY+4096 + 8 * eax]
+ movzx eax, y
+ movq mm1, [kCoefficientsRgbY + 8 * eax]
+ paddsw mm1, mm0
+ psraw mm1, 6
+ packuswb mm1, mm1
+ mov eax, rgb_buf
+ movd [eax], mm1
+ emms
+ }
+}
+#endif
+void FastConvertYUVToRGB32Row(const uint8* y_buf,
+ const uint8* u_buf,
+ const uint8* v_buf,
+ uint8* rgb_buf,
+ int source_width) {
+ for (int x = 0; x < source_width; x += 2) {
+ uint8 u = u_buf[x >> 1];
+ uint8 v = v_buf[x >> 1];
+ uint8 y0 = y_buf[x];
+ YuvPixel(y0, u, v, rgb_buf);
+ if ((x + 1) < source_width) {
+ uint8 y1 = y_buf[x + 1];
+ YuvPixel(y1, u, v, rgb_buf + 4);
+ }
+ rgb_buf += 8; // Advance 2 pixels.
+ }
+}
+
+// 16.16 fixed point is used. A shift by 16 isolates the integer.
+// A shift by 17 is used to further subsample the chrominence channels.
+// & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits,
+// for 1/65536 pixel accurate interpolation.
+void ScaleYUVToRGB32Row(const uint8* y_buf,
+ const uint8* u_buf,
+ const uint8* v_buf,
+ uint8* rgb_buf,
+ int source_width,
+ int dx) {
+ int x = 0;
+ for (int i = 0; i < source_width; i += 2) {
+ int y = y_buf[x >> 16];
+ int u = u_buf[(x >> 17)];
+ int v = v_buf[(x >> 17)];
+ YuvPixel(y, u, v, rgb_buf);
+ x += dx;
+ if ((i + 1) < source_width) {
+ y = y_buf[x >> 16];
+ YuvPixel(y, u, v, rgb_buf+4);
+ x += dx;
+ }
+ rgb_buf += 8;
+ }
+}
+
+void LinearScaleYUVToRGB32Row(const uint8* y_buf,
+ const uint8* u_buf,
+ const uint8* v_buf,
+ uint8* rgb_buf,
+ int source_width,
+ int dx) {
+ int x = 0;
+ for (int i = 0; i < source_width; i += 2) {
+ int y0 = y_buf[x >> 16];
+ int y1 = y_buf[(x >> 16) + 1];
+ int u0 = u_buf[(x >> 17)];
+ int u1 = u_buf[(x >> 17) + 1];
+ int v0 = v_buf[(x >> 17)];
+ int v1 = v_buf[(x >> 17) + 1];
+ int y_frac = (x & 65535);
+ int uv_frac = ((x >> 1) & 65535);
+ int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
+ int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16;
+ int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16;
+ YuvPixel(y, u, v, rgb_buf);
+ x += dx;
+ if ((i + 1) < source_width) {
+ y0 = y_buf[x >> 16];
+ y1 = y_buf[(x >> 16) + 1];
+ y_frac = (x & 65535);
+ y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
+ YuvPixel(y, u, v, rgb_buf+4);
+ x += dx;
+ }
+ rgb_buf += 8;
+ }
+}
+
+#endif // USE_MMX
} // extern "C"
+
diff --git a/media/media.gyp b/media/media.gyp
index c12aabf..7190cf3 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -80,6 +80,7 @@
'base/yuv_convert.h',
'base/yuv_row_win.cc',
'base/yuv_row_posix.cc',
+ 'base/yuv_row_table.cc',
'base/yuv_row.h',
'ffmpeg/ffmpeg_common.cc',
'ffmpeg/ffmpeg_common.h',