OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include <stdint.h> | |
6 | |
7 #include "build/build_config.h" | |
8 #include "media/base/simd/convert_rgb_to_yuv.h" | |
9 | |
10 namespace media { | |
11 | |
12 static int clip_byte(int x) { | |
13 if (x > 255) | |
14 return 255; | |
15 else if (x < 0) | |
16 return 0; | |
17 else | |
18 return x; | |
19 } | |
20 | |
21 void ConvertRGB32ToYUV_C(const uint8_t* rgbframe, | |
22 uint8_t* yplane, | |
23 uint8_t* uplane, | |
24 uint8_t* vplane, | |
25 int width, | |
26 int height, | |
27 int rgbstride, | |
28 int ystride, | |
29 int uvstride) { | |
30 #if defined(OS_ANDROID) | |
31 const int r = 0; | |
32 const int g = 1; | |
33 const int b = 2; | |
34 #else | |
35 const int r = 2; | |
36 const int g = 1; | |
37 const int b = 0; | |
38 #endif | |
39 | |
40 for (int i = 0; i < height; ++i) { | |
41 for (int j = 0; j < width; ++j) { | |
42 // Since the input pixel format is RGB32, there are 4 bytes per pixel. | |
43 const uint8_t* pixel = rgbframe + 4 * j; | |
44 yplane[j] = clip_byte(((pixel[r] * 66 + pixel[g] * 129 + | |
45 pixel[b] * 25 + 128) >> 8) + 16); | |
46 if (i % 2 == 0 && j % 2 == 0) { | |
47 uplane[j / 2] = clip_byte(((pixel[r] * -38 + pixel[g] * -74 + | |
48 pixel[b] * 112 + 128) >> 8) + 128); | |
49 vplane[j / 2] = clip_byte(((pixel[r] * 112 + pixel[g] * -94 + | |
50 pixel[b] * -18 + 128) >> 8) + 128); | |
51 } | |
52 } | |
53 rgbframe += rgbstride; | |
54 yplane += ystride; | |
55 if (i % 2 == 0) { | |
56 uplane += uvstride; | |
57 vplane += uvstride; | |
58 } | |
59 } | |
60 } | |
61 | |
62 void ConvertRGB24ToYUV_C(const uint8_t* rgbframe, | |
63 uint8_t* yplane, | |
64 uint8_t* uplane, | |
65 uint8_t* vplane, | |
66 int width, | |
67 int height, | |
68 int rgbstride, | |
69 int ystride, | |
70 int uvstride) { | |
71 for (int i = 0; i < height; ++i) { | |
72 for (int j = 0; j < width; ++j) { | |
73 // Since the input pixel format is RGB24, there are 3 bytes per pixel. | |
74 const uint8_t* pixel = rgbframe + 3 * j; | |
75 yplane[j] = clip_byte(((pixel[2] * 66 + pixel[1] * 129 + | |
76 pixel[0] * 25 + 128) >> 8) + 16); | |
77 if (i % 2 == 0 && j % 2 == 0) { | |
78 uplane[j / 2] = clip_byte(((pixel[2] * -38 + pixel[1] * -74 + | |
79 pixel[0] * 112 + 128) >> 8) + 128); | |
80 vplane[j / 2] = clip_byte(((pixel[2] * 112 + pixel[1] * -94 + | |
81 pixel[0] * -18 + 128) >> 8) + 128); | |
82 } | |
83 } | |
84 | |
85 rgbframe += rgbstride; | |
86 yplane += ystride; | |
87 if (i % 2 == 0) { | |
88 uplane += uvstride; | |
89 vplane += uvstride; | |
90 } | |
91 } | |
92 } | |
93 | |
94 } // namespace media | |
OLD | NEW |