summaryrefslogtreecommitdiffstats
path: root/media/base/yuv_convert_c.cc
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 20:59:30 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 20:59:30 +0000
commit699158b7034b3027ce0fb11ef4e134294bc6d6ce (patch)
tree9e57535c1edcfbac7eea8cbc1bddf184497d2da9 /media/base/yuv_convert_c.cc
parent9c99d1ce15520712578e2b7e9102c909e4ab379c (diff)
downloadchromium_src-699158b7034b3027ce0fb11ef4e134294bc6d6ce.zip
chromium_src-699158b7034b3027ce0fb11ef4e134294bc6d6ce.tar.gz
chromium_src-699158b7034b3027ce0fb11ef4e134294bc6d6ce.tar.bz2
RGB to YUV conversion using SSE2
This code uses SSE2 intrinsics with the feature of 2x2 subsampling for U and V. Performance compared to a pure C version is about 20% faster with better quality. BUG=None TEST=None Review URL: http://codereview.chromium.org/6268018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73339 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/yuv_convert_c.cc')
-rw-r--r--media/base/yuv_convert_c.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/media/base/yuv_convert_c.cc b/media/base/yuv_convert_c.cc
new file mode 100644
index 0000000..b5d8345
--- /dev/null
+++ b/media/base/yuv_convert_c.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2011 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_convert.h"
+
+namespace media {
+
+static int clip_byte(int x) {
+ if (x > 255)
+ return 255;
+ else if (x < 0)
+ return 0;
+ else
+ return x;
+}
+
+void ConvertRGB32ToYUV(const uint8* rgbframe,
+ uint8* yplane,
+ uint8* uplane,
+ uint8* vplane,
+ int width,
+ int height,
+ int rgbstride,
+ int ystride,
+ int uvstride) {
+ for (int i = 0; i < height; ++i) {
+ for (int j = 0; j < width; ++j) {
+ // Since the input pixel format is RGB32, there are 4 bytes per pixel.
+ const uint8* pixel = rgbframe + 4 * j;
+ yplane[j] = clip_byte(((pixel[2] * 66 + pixel[1] * 129 +
+ pixel[0] * 25 + 128) >> 8) + 16);
+ if (i % 2 == 0 && j % 2 == 0) {
+ uplane[j / 2] = clip_byte(((pixel[2] * -38 + pixel[1] * -74 +
+ pixel[0] * 112 + 128) >> 8) + 128);
+ vplane[j / 2] = clip_byte(((pixel[2] * 112 + pixel[1] * -94 +
+ pixel[1] * -18 + 128) >> 8) + 128);
+ }
+ }
+
+ rgbframe += rgbstride;
+ yplane += ystride;
+ if (i % 2 == 0) {
+ uplane += uvstride;
+ vplane += uvstride;
+ }
+ }
+}
+
+} // namespace media