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

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

Issue 9138050: Merge 117748 - Linear sub-rectangle scaler for use in Chromoting. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/963/src/
Patch Set: Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « media/base/simd/convert_yuv_to_rgb.h ('k') | media/base/yuv_convert.h » ('j') | 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) 2011 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 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) 8 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x)))
9 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \ 9 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \
10 (((x) + (y)) > 32767 ? 32767 : ((x) + (y)))) 10 (((x) + (y)) > 32767 ? 32767 : ((x) + (y))))
11 11
12 static inline void YUVPixel(uint8 y, 12 static inline void ConvertYUVToRGB32_C(uint8 y,
13 uint8 u, 13 uint8 u,
14 uint8 v, 14 uint8 v,
15 uint8* rgb_buf) { 15 uint8* rgb_buf) {
16
17 int b = kCoefficientsRgbY[256+u][0]; 16 int b = kCoefficientsRgbY[256+u][0];
18 int g = kCoefficientsRgbY[256+u][1]; 17 int g = kCoefficientsRgbY[256+u][1];
19 int r = kCoefficientsRgbY[256+u][2]; 18 int r = kCoefficientsRgbY[256+u][2];
20 int a = kCoefficientsRgbY[256+u][3]; 19 int a = kCoefficientsRgbY[256+u][3];
21 20
22 b = paddsw(b, kCoefficientsRgbY[512+v][0]); 21 b = paddsw(b, kCoefficientsRgbY[512+v][0]);
23 g = paddsw(g, kCoefficientsRgbY[512+v][1]); 22 g = paddsw(g, kCoefficientsRgbY[512+v][1]);
24 r = paddsw(r, kCoefficientsRgbY[512+v][2]); 23 r = paddsw(r, kCoefficientsRgbY[512+v][2]);
25 a = paddsw(a, kCoefficientsRgbY[512+v][3]); 24 a = paddsw(a, kCoefficientsRgbY[512+v][3]);
26 25
27 b = paddsw(b, kCoefficientsRgbY[y][0]); 26 b = paddsw(b, kCoefficientsRgbY[y][0]);
28 g = paddsw(g, kCoefficientsRgbY[y][1]); 27 g = paddsw(g, kCoefficientsRgbY[y][1]);
29 r = paddsw(r, kCoefficientsRgbY[y][2]); 28 r = paddsw(r, kCoefficientsRgbY[y][2]);
30 a = paddsw(a, kCoefficientsRgbY[y][3]); 29 a = paddsw(a, kCoefficientsRgbY[y][3]);
31 30
32 b >>= 6; 31 b >>= 6;
33 g >>= 6; 32 g >>= 6;
34 r >>= 6; 33 r >>= 6;
35 a >>= 6; 34 a >>= 6;
36 35
37 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) | 36 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) |
38 (packuswb(g) << 8) | 37 (packuswb(g) << 8) |
39 (packuswb(r) << 16) | 38 (packuswb(r) << 16) |
40 (packuswb(a) << 24); 39 (packuswb(a) << 24);
41 } 40 }
42 41
42 // 16.16 fixed point arithmetic
43 const int kFractionBits = 16;
44 const int kFractionMax = 1 << kFractionBits;
45 const int kFractionMask = ((1 << kFractionBits) - 1);
46
43 extern "C" { 47 extern "C" {
44 48
45 void ConvertYUVToRGB32Row_C(const uint8* y_buf, 49 void ConvertYUVToRGB32Row_C(const uint8* y_buf,
46 const uint8* u_buf, 50 const uint8* u_buf,
47 const uint8* v_buf, 51 const uint8* v_buf,
48 uint8* rgb_buf, 52 uint8* rgb_buf,
49 int width) { 53 int width) {
50 for (int x = 0; x < width; x += 2) { 54 for (int x = 0; x < width; x += 2) {
51 uint8 u = u_buf[x >> 1]; 55 uint8 u = u_buf[x >> 1];
52 uint8 v = v_buf[x >> 1]; 56 uint8 v = v_buf[x >> 1];
53 uint8 y0 = y_buf[x]; 57 uint8 y0 = y_buf[x];
54 YUVPixel(y0, u, v, rgb_buf); 58 ConvertYUVToRGB32_C(y0, u, v, rgb_buf);
55 if ((x + 1) < width) { 59 if ((x + 1) < width) {
56 uint8 y1 = y_buf[x + 1]; 60 uint8 y1 = y_buf[x + 1];
57 YUVPixel(y1, u, v, rgb_buf + 4); 61 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4);
58 } 62 }
59 rgb_buf += 8; // Advance 2 pixels. 63 rgb_buf += 8; // Advance 2 pixels.
60 } 64 }
61 } 65 }
62 66
63 // 16.16 fixed point is used. A shift by 16 isolates the integer. 67 // 16.16 fixed point is used. A shift by 16 isolates the integer.
64 // A shift by 17 is used to further subsample the chrominence channels. 68 // A shift by 17 is used to further subsample the chrominence channels.
65 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, 69 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits,
66 // for 1/65536 pixel accurate interpolation. 70 // for 1/65536 pixel accurate interpolation.
67 void ScaleYUVToRGB32Row_C(const uint8* y_buf, 71 void ScaleYUVToRGB32Row_C(const uint8* y_buf,
68 const uint8* u_buf, 72 const uint8* u_buf,
69 const uint8* v_buf, 73 const uint8* v_buf,
70 uint8* rgb_buf, 74 uint8* rgb_buf,
71 int width, 75 int width,
72 int source_dx) { 76 int source_dx) {
73 int x = 0; 77 int x = 0;
74 for (int i = 0; i < width; i += 2) { 78 for (int i = 0; i < width; i += 2) {
75 int y = y_buf[x >> 16]; 79 int y = y_buf[x >> 16];
76 int u = u_buf[(x >> 17)]; 80 int u = u_buf[(x >> 17)];
77 int v = v_buf[(x >> 17)]; 81 int v = v_buf[(x >> 17)];
78 YUVPixel(y, u, v, rgb_buf); 82 ConvertYUVToRGB32_C(y, u, v, rgb_buf);
79 x += source_dx; 83 x += source_dx;
80 if ((i + 1) < width) { 84 if ((i + 1) < width) {
81 y = y_buf[x >> 16]; 85 y = y_buf[x >> 16];
82 YUVPixel(y, u, v, rgb_buf+4); 86 ConvertYUVToRGB32_C(y, u, v, rgb_buf+4);
83 x += source_dx; 87 x += source_dx;
84 } 88 }
85 rgb_buf += 8; 89 rgb_buf += 8;
86 } 90 }
87 } 91 }
88 92
89 void LinearScaleYUVToRGB32Row_C(const uint8* y_buf, 93 void LinearScaleYUVToRGB32Row_C(const uint8* y_buf,
90 const uint8* u_buf, 94 const uint8* u_buf,
91 const uint8* v_buf, 95 const uint8* v_buf,
92 uint8* rgb_buf, 96 uint8* rgb_buf,
93 int width, 97 int width,
94 int source_dx) { 98 int source_dx) {
95 int x = 0; 99 // Avoid point-sampling for down-scaling by > 2:1.
96 if (source_dx >= 0x20000) { 100 int source_x = 0;
97 x = 32768; 101 if (source_dx >= 0x20000)
98 } 102 source_x += 0x8000;
99 for (int i = 0; i < width; i += 2) { 103 LinearScaleYUVToRGB32RowWithRange_C(y_buf, u_buf, v_buf, rgb_buf, width,
104 source_x, source_dx);
105 }
106
107 void LinearScaleYUVToRGB32RowWithRange_C(const uint8* y_buf,
108 const uint8* u_buf,
109 const uint8* v_buf,
110 uint8* rgb_buf,
111 int dest_width,
112 int x,
113 int source_dx) {
114 for (int i = 0; i < dest_width; i += 2) {
100 int y0 = y_buf[x >> 16]; 115 int y0 = y_buf[x >> 16];
101 int y1 = y_buf[(x >> 16) + 1]; 116 int y1 = y_buf[(x >> 16) + 1];
102 int u0 = u_buf[(x >> 17)]; 117 int u0 = u_buf[(x >> 17)];
103 int u1 = u_buf[(x >> 17) + 1]; 118 int u1 = u_buf[(x >> 17) + 1];
104 int v0 = v_buf[(x >> 17)]; 119 int v0 = v_buf[(x >> 17)];
105 int v1 = v_buf[(x >> 17) + 1]; 120 int v1 = v_buf[(x >> 17) + 1];
106 int y_frac = (x & 65535); 121 int y_frac = (x & 65535);
107 int uv_frac = ((x >> 1) & 65535); 122 int uv_frac = ((x >> 1) & 65535);
108 int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16; 123 int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
109 int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16; 124 int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16;
110 int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16; 125 int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16;
111 YUVPixel(y, u, v, rgb_buf); 126 ConvertYUVToRGB32_C(y, u, v, rgb_buf);
112 x += source_dx; 127 x += source_dx;
113 if ((i + 1) < width) { 128 if ((i + 1) < dest_width) {
114 y0 = y_buf[x >> 16]; 129 y0 = y_buf[x >> 16];
115 y1 = y_buf[(x >> 16) + 1]; 130 y1 = y_buf[(x >> 16) + 1];
116 y_frac = (x & 65535); 131 y_frac = (x & 65535);
117 y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16; 132 y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
118 YUVPixel(y, u, v, rgb_buf+4); 133 ConvertYUVToRGB32_C(y, u, v, rgb_buf+4);
119 x += source_dx; 134 x += source_dx;
120 } 135 }
121 rgb_buf += 8; 136 rgb_buf += 8;
122 } 137 }
123 } 138 }
124 139
125 } 140 }
126 141
127 namespace media { 142 namespace media {
128 143
(...skipping 16 matching lines...) Expand all
145 160
146 ConvertYUVToRGB32Row_C(y_ptr, 161 ConvertYUVToRGB32Row_C(y_ptr,
147 u_ptr, 162 u_ptr,
148 v_ptr, 163 v_ptr,
149 rgb_row, 164 rgb_row,
150 width); 165 width);
151 } 166 }
152 } 167 }
153 168
154 } // namespace media 169 } // namespace media
OLDNEW
« no previous file with comments | « media/base/simd/convert_yuv_to_rgb.h ('k') | media/base/yuv_convert.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698