Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: media/base/simd/convert_yuv_to_rgb_c.cc

Issue 17043007: Fix the WebRTC color bug. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Andrew's comments. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/simd/convert_yuv_to_rgb.h" 5 #include "media/base/simd/convert_yuv_to_rgb.h"
6 #include "media/base/simd/yuv_to_rgb_table.h" 6 #include "media/base/simd/yuv_to_rgb_table.h"
7 7
8 namespace media { 8 namespace media {
9 9
10 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) 10 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x)))
11 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \ 11 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \
12 (((x) + (y)) > 32767 ? 32767 : ((x) + (y)))) 12 (((x) + (y)) > 32767 ? 32767 : ((x) + (y))))
13 13
14 // On Android, pixel layout is RGBA
15 // (see third_party/skia/include/core/SkColorPriv.h);
16 // however, other Chrome platforms use BGRA
17 // (see skia/config/SkUserConfig.h).
18 // Ideally, android should not use the function here
19 // due to performance issue(crbug/249980).
scherkus (not reviewing) 2013/06/15 00:31:56 nit: can you better format this comment? for exam
hkuang1 2013/06/15 00:54:01 Done.
20 #if defined(OS_ANDROID)
21 #define SK_R32_SHIFT 0
22 #define SK_G32_SHIFT 8
23 #define SK_B32_SHIFT 16
24 #define SK_A32_SHIFT 24
25 #else
26 #define SK_B32_SHIFT 0
27 #define SK_G32_SHIFT 8
28 #define SK_R32_SHIFT 16
29 #define SK_A32_SHIFT 24
30 #endif
31
14 static inline void ConvertYUVToRGB32_C(uint8 y, 32 static inline void ConvertYUVToRGB32_C(uint8 y,
15 uint8 u, 33 uint8 u,
16 uint8 v, 34 uint8 v,
17 uint8* rgb_buf) { 35 uint8* rgb_buf) {
18 int b = kCoefficientsRgbY[256+u][0]; 36 int b = kCoefficientsRgbY[256+u][0];
19 int g = kCoefficientsRgbY[256+u][1]; 37 int g = kCoefficientsRgbY[256+u][1];
20 int r = kCoefficientsRgbY[256+u][2]; 38 int r = kCoefficientsRgbY[256+u][2];
21 int a = kCoefficientsRgbY[256+u][3]; 39 int a = kCoefficientsRgbY[256+u][3];
22 40
23 b = paddsw(b, kCoefficientsRgbY[512+v][0]); 41 b = paddsw(b, kCoefficientsRgbY[512+v][0]);
24 g = paddsw(g, kCoefficientsRgbY[512+v][1]); 42 g = paddsw(g, kCoefficientsRgbY[512+v][1]);
25 r = paddsw(r, kCoefficientsRgbY[512+v][2]); 43 r = paddsw(r, kCoefficientsRgbY[512+v][2]);
26 a = paddsw(a, kCoefficientsRgbY[512+v][3]); 44 a = paddsw(a, kCoefficientsRgbY[512+v][3]);
27 45
28 b = paddsw(b, kCoefficientsRgbY[y][0]); 46 b = paddsw(b, kCoefficientsRgbY[y][0]);
29 g = paddsw(g, kCoefficientsRgbY[y][1]); 47 g = paddsw(g, kCoefficientsRgbY[y][1]);
30 r = paddsw(r, kCoefficientsRgbY[y][2]); 48 r = paddsw(r, kCoefficientsRgbY[y][2]);
31 a = paddsw(a, kCoefficientsRgbY[y][3]); 49 a = paddsw(a, kCoefficientsRgbY[y][3]);
32 50
33 b >>= 6; 51 b >>= 6;
34 g >>= 6; 52 g >>= 6;
35 r >>= 6; 53 r >>= 6;
36 a >>= 6; 54 a >>= 6;
37 55
38 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) | 56 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b) << SK_B32_SHIFT) |
39 (packuswb(g) << 8) | 57 (packuswb(g) << SK_G32_SHIFT) |
40 (packuswb(r) << 16) | 58 (packuswb(r) << SK_R32_SHIFT) |
41 (packuswb(a) << 24); 59 (packuswb(a) << SK_A32_SHIFT);
42 } 60 }
43 61
44 static inline void ConvertYUVAToARGB_C(uint8 y, 62 static inline void ConvertYUVAToARGB_C(uint8 y,
45 uint8 u, 63 uint8 u,
46 uint8 v, 64 uint8 v,
47 uint8 a, 65 uint8 a,
48 uint8* rgb_buf) { 66 uint8* rgb_buf) {
49 int b = kCoefficientsRgbY[256+u][0]; 67 int b = kCoefficientsRgbY[256+u][0];
50 int g = kCoefficientsRgbY[256+u][1]; 68 int g = kCoefficientsRgbY[256+u][1];
51 int r = kCoefficientsRgbY[256+u][2]; 69 int r = kCoefficientsRgbY[256+u][2];
52 70
53 b = paddsw(b, kCoefficientsRgbY[512+v][0]); 71 b = paddsw(b, kCoefficientsRgbY[512+v][0]);
54 g = paddsw(g, kCoefficientsRgbY[512+v][1]); 72 g = paddsw(g, kCoefficientsRgbY[512+v][1]);
55 r = paddsw(r, kCoefficientsRgbY[512+v][2]); 73 r = paddsw(r, kCoefficientsRgbY[512+v][2]);
56 74
57 b = paddsw(b, kCoefficientsRgbY[y][0]); 75 b = paddsw(b, kCoefficientsRgbY[y][0]);
58 g = paddsw(g, kCoefficientsRgbY[y][1]); 76 g = paddsw(g, kCoefficientsRgbY[y][1]);
59 r = paddsw(r, kCoefficientsRgbY[y][2]); 77 r = paddsw(r, kCoefficientsRgbY[y][2]);
60 78
61 b >>= 6; 79 b >>= 6;
62 g >>= 6; 80 g >>= 6;
63 r >>= 6; 81 r >>= 6;
64 82
65 b = packuswb(b) * a >> 8; 83 b = packuswb(b) * a >> 8;
66 g = packuswb(g) * a >> 8; 84 g = packuswb(g) * a >> 8;
67 r = packuswb(r) * a >> 8; 85 r = packuswb(r) * a >> 8;
68 86
69 *reinterpret_cast<uint32*>(rgb_buf) = b | (g << 8) | (r << 16) | (a << 24); 87 *reinterpret_cast<uint32*>(rgb_buf) = (b << SK_B32_SHIFT) |
88 (g << SK_G32_SHIFT) |
89 (r << SK_R32_SHIFT) |
90 (a << SK_A32_SHIFT);
70 } 91 }
71 92
72 void ConvertYUVToRGB32Row_C(const uint8* y_buf, 93 void ConvertYUVToRGB32Row_C(const uint8* y_buf,
73 const uint8* u_buf, 94 const uint8* u_buf,
74 const uint8* v_buf, 95 const uint8* v_buf,
75 uint8* rgb_buf, 96 uint8* rgb_buf,
76 ptrdiff_t width) { 97 ptrdiff_t width) {
77 for (int x = 0; x < width; x += 2) { 98 for (int x = 0; x < width; x += 2) {
78 uint8 u = u_buf[x >> 1]; 99 uint8 u = u_buf[x >> 1];
79 uint8 v = v_buf[x >> 1]; 100 uint8 v = v_buf[x >> 1];
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 ConvertYUVAToARGBRow_C(y_ptr, 250 ConvertYUVAToARGBRow_C(y_ptr,
230 u_ptr, 251 u_ptr,
231 v_ptr, 252 v_ptr,
232 a_ptr, 253 a_ptr,
233 rgba_row, 254 rgba_row,
234 width); 255 width);
235 } 256 }
236 } 257 }
237 258
238 } // namespace media 259 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698