1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/base/simd/convert_rgb_to_yuv.h"
9 static int clip_byte(int x
) {
18 void ConvertRGB32ToYUV_C(const uint8
* rgbframe
,
27 #if defined(OS_ANDROID)
37 for (int i
= 0; i
< height
; ++i
) {
38 for (int j
= 0; j
< width
; ++j
) {
39 // Since the input pixel format is RGB32, there are 4 bytes per pixel.
40 const uint8
* pixel
= rgbframe
+ 4 * j
;
41 yplane
[j
] = clip_byte(((pixel
[r
] * 66 + pixel
[g
] * 129 +
42 pixel
[b
] * 25 + 128) >> 8) + 16);
43 if (i
% 2 == 0 && j
% 2 == 0) {
44 uplane
[j
/ 2] = clip_byte(((pixel
[r
] * -38 + pixel
[g
] * -74 +
45 pixel
[b
] * 112 + 128) >> 8) + 128);
46 vplane
[j
/ 2] = clip_byte(((pixel
[r
] * 112 + pixel
[g
] * -94 +
47 pixel
[b
] * -18 + 128) >> 8) + 128);
50 rgbframe
+= rgbstride
;
59 void ConvertRGB24ToYUV_C(const uint8
* rgbframe
,
68 for (int i
= 0; i
< height
; ++i
) {
69 for (int j
= 0; j
< width
; ++j
) {
70 // Since the input pixel format is RGB24, there are 3 bytes per pixel.
71 const uint8
* pixel
= rgbframe
+ 3 * j
;
72 yplane
[j
] = clip_byte(((pixel
[2] * 66 + pixel
[1] * 129 +
73 pixel
[0] * 25 + 128) >> 8) + 16);
74 if (i
% 2 == 0 && j
% 2 == 0) {
75 uplane
[j
/ 2] = clip_byte(((pixel
[2] * -38 + pixel
[1] * -74 +
76 pixel
[0] * 112 + 128) >> 8) + 128);
77 vplane
[j
/ 2] = clip_byte(((pixel
[2] * 112 + pixel
[1] * -94 +
78 pixel
[0] * -18 + 128) >> 8) + 128);
82 rgbframe
+= rgbstride
;