OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/yuv_row.h" | 5 #include "media/base/yuv_row.h" |
6 | 6 |
| 7 #define kCoefficientsRgbU kCoefficientsRgbY + 2048 |
| 8 #define kCoefficientsRgbV kCoefficientsRgbY + 4096 |
| 9 |
7 extern "C" { | 10 extern "C" { |
8 #define RGBY(i) { \ | |
9 static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ | |
10 static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ | |
11 static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ | |
12 0 \ | |
13 } | |
14 | 11 |
15 #define RGBU(i) { \ | 12 #if USE_MMX |
16 static_cast<int16>(2.018 * 64 * (i - 128) + 0.5), \ | |
17 static_cast<int16>(-0.391 * 64 * (i - 128) + 0.5), \ | |
18 0, \ | |
19 static_cast<int16>(256 * 64 - 1) \ | |
20 } | |
21 | |
22 #define RGBV(i) { \ | |
23 0, \ | |
24 static_cast<int16>(-0.813 * 64 * (i - 128) + 0.5), \ | |
25 static_cast<int16>(1.596 * 64 * (i - 128) + 0.5), \ | |
26 0 \ | |
27 } | |
28 | |
29 #define MMX_ALIGNED(var) __declspec(align(16)) var | |
30 | |
31 MMX_ALIGNED(int16 kCoefficientsRgbY[256][4]) = { | |
32 RGBY(0x00), RGBY(0x01), RGBY(0x02), RGBY(0x03), | |
33 RGBY(0x04), RGBY(0x05), RGBY(0x06), RGBY(0x07), | |
34 RGBY(0x08), RGBY(0x09), RGBY(0x0A), RGBY(0x0B), | |
35 RGBY(0x0C), RGBY(0x0D), RGBY(0x0E), RGBY(0x0F), | |
36 RGBY(0x10), RGBY(0x11), RGBY(0x12), RGBY(0x13), | |
37 RGBY(0x14), RGBY(0x15), RGBY(0x16), RGBY(0x17), | |
38 RGBY(0x18), RGBY(0x19), RGBY(0x1A), RGBY(0x1B), | |
39 RGBY(0x1C), RGBY(0x1D), RGBY(0x1E), RGBY(0x1F), | |
40 RGBY(0x20), RGBY(0x21), RGBY(0x22), RGBY(0x23), | |
41 RGBY(0x24), RGBY(0x25), RGBY(0x26), RGBY(0x27), | |
42 RGBY(0x28), RGBY(0x29), RGBY(0x2A), RGBY(0x2B), | |
43 RGBY(0x2C), RGBY(0x2D), RGBY(0x2E), RGBY(0x2F), | |
44 RGBY(0x30), RGBY(0x31), RGBY(0x32), RGBY(0x33), | |
45 RGBY(0x34), RGBY(0x35), RGBY(0x36), RGBY(0x37), | |
46 RGBY(0x38), RGBY(0x39), RGBY(0x3A), RGBY(0x3B), | |
47 RGBY(0x3C), RGBY(0x3D), RGBY(0x3E), RGBY(0x3F), | |
48 RGBY(0x40), RGBY(0x41), RGBY(0x42), RGBY(0x43), | |
49 RGBY(0x44), RGBY(0x45), RGBY(0x46), RGBY(0x47), | |
50 RGBY(0x48), RGBY(0x49), RGBY(0x4A), RGBY(0x4B), | |
51 RGBY(0x4C), RGBY(0x4D), RGBY(0x4E), RGBY(0x4F), | |
52 RGBY(0x50), RGBY(0x51), RGBY(0x52), RGBY(0x53), | |
53 RGBY(0x54), RGBY(0x55), RGBY(0x56), RGBY(0x57), | |
54 RGBY(0x58), RGBY(0x59), RGBY(0x5A), RGBY(0x5B), | |
55 RGBY(0x5C), RGBY(0x5D), RGBY(0x5E), RGBY(0x5F), | |
56 RGBY(0x60), RGBY(0x61), RGBY(0x62), RGBY(0x63), | |
57 RGBY(0x64), RGBY(0x65), RGBY(0x66), RGBY(0x67), | |
58 RGBY(0x68), RGBY(0x69), RGBY(0x6A), RGBY(0x6B), | |
59 RGBY(0x6C), RGBY(0x6D), RGBY(0x6E), RGBY(0x6F), | |
60 RGBY(0x70), RGBY(0x71), RGBY(0x72), RGBY(0x73), | |
61 RGBY(0x74), RGBY(0x75), RGBY(0x76), RGBY(0x77), | |
62 RGBY(0x78), RGBY(0x79), RGBY(0x7A), RGBY(0x7B), | |
63 RGBY(0x7C), RGBY(0x7D), RGBY(0x7E), RGBY(0x7F), | |
64 RGBY(0x80), RGBY(0x81), RGBY(0x82), RGBY(0x83), | |
65 RGBY(0x84), RGBY(0x85), RGBY(0x86), RGBY(0x87), | |
66 RGBY(0x88), RGBY(0x89), RGBY(0x8A), RGBY(0x8B), | |
67 RGBY(0x8C), RGBY(0x8D), RGBY(0x8E), RGBY(0x8F), | |
68 RGBY(0x90), RGBY(0x91), RGBY(0x92), RGBY(0x93), | |
69 RGBY(0x94), RGBY(0x95), RGBY(0x96), RGBY(0x97), | |
70 RGBY(0x98), RGBY(0x99), RGBY(0x9A), RGBY(0x9B), | |
71 RGBY(0x9C), RGBY(0x9D), RGBY(0x9E), RGBY(0x9F), | |
72 RGBY(0xA0), RGBY(0xA1), RGBY(0xA2), RGBY(0xA3), | |
73 RGBY(0xA4), RGBY(0xA5), RGBY(0xA6), RGBY(0xA7), | |
74 RGBY(0xA8), RGBY(0xA9), RGBY(0xAA), RGBY(0xAB), | |
75 RGBY(0xAC), RGBY(0xAD), RGBY(0xAE), RGBY(0xAF), | |
76 RGBY(0xB0), RGBY(0xB1), RGBY(0xB2), RGBY(0xB3), | |
77 RGBY(0xB4), RGBY(0xB5), RGBY(0xB6), RGBY(0xB7), | |
78 RGBY(0xB8), RGBY(0xB9), RGBY(0xBA), RGBY(0xBB), | |
79 RGBY(0xBC), RGBY(0xBD), RGBY(0xBE), RGBY(0xBF), | |
80 RGBY(0xC0), RGBY(0xC1), RGBY(0xC2), RGBY(0xC3), | |
81 RGBY(0xC4), RGBY(0xC5), RGBY(0xC6), RGBY(0xC7), | |
82 RGBY(0xC8), RGBY(0xC9), RGBY(0xCA), RGBY(0xCB), | |
83 RGBY(0xCC), RGBY(0xCD), RGBY(0xCE), RGBY(0xCF), | |
84 RGBY(0xD0), RGBY(0xD1), RGBY(0xD2), RGBY(0xD3), | |
85 RGBY(0xD4), RGBY(0xD5), RGBY(0xD6), RGBY(0xD7), | |
86 RGBY(0xD8), RGBY(0xD9), RGBY(0xDA), RGBY(0xDB), | |
87 RGBY(0xDC), RGBY(0xDD), RGBY(0xDE), RGBY(0xDF), | |
88 RGBY(0xE0), RGBY(0xE1), RGBY(0xE2), RGBY(0xE3), | |
89 RGBY(0xE4), RGBY(0xE5), RGBY(0xE6), RGBY(0xE7), | |
90 RGBY(0xE8), RGBY(0xE9), RGBY(0xEA), RGBY(0xEB), | |
91 RGBY(0xEC), RGBY(0xED), RGBY(0xEE), RGBY(0xEF), | |
92 RGBY(0xF0), RGBY(0xF1), RGBY(0xF2), RGBY(0xF3), | |
93 RGBY(0xF4), RGBY(0xF5), RGBY(0xF6), RGBY(0xF7), | |
94 RGBY(0xF8), RGBY(0xF9), RGBY(0xFA), RGBY(0xFB), | |
95 RGBY(0xFC), RGBY(0xFD), RGBY(0xFE), RGBY(0xFF), | |
96 }; | |
97 | |
98 MMX_ALIGNED(int16 kCoefficientsRgbU[256][4]) = { | |
99 RGBU(0x00), RGBU(0x01), RGBU(0x02), RGBU(0x03), | |
100 RGBU(0x04), RGBU(0x05), RGBU(0x06), RGBU(0x07), | |
101 RGBU(0x08), RGBU(0x09), RGBU(0x0A), RGBU(0x0B), | |
102 RGBU(0x0C), RGBU(0x0D), RGBU(0x0E), RGBU(0x0F), | |
103 RGBU(0x10), RGBU(0x11), RGBU(0x12), RGBU(0x13), | |
104 RGBU(0x14), RGBU(0x15), RGBU(0x16), RGBU(0x17), | |
105 RGBU(0x18), RGBU(0x19), RGBU(0x1A), RGBU(0x1B), | |
106 RGBU(0x1C), RGBU(0x1D), RGBU(0x1E), RGBU(0x1F), | |
107 RGBU(0x20), RGBU(0x21), RGBU(0x22), RGBU(0x23), | |
108 RGBU(0x24), RGBU(0x25), RGBU(0x26), RGBU(0x27), | |
109 RGBU(0x28), RGBU(0x29), RGBU(0x2A), RGBU(0x2B), | |
110 RGBU(0x2C), RGBU(0x2D), RGBU(0x2E), RGBU(0x2F), | |
111 RGBU(0x30), RGBU(0x31), RGBU(0x32), RGBU(0x33), | |
112 RGBU(0x34), RGBU(0x35), RGBU(0x36), RGBU(0x37), | |
113 RGBU(0x38), RGBU(0x39), RGBU(0x3A), RGBU(0x3B), | |
114 RGBU(0x3C), RGBU(0x3D), RGBU(0x3E), RGBU(0x3F), | |
115 RGBU(0x40), RGBU(0x41), RGBU(0x42), RGBU(0x43), | |
116 RGBU(0x44), RGBU(0x45), RGBU(0x46), RGBU(0x47), | |
117 RGBU(0x48), RGBU(0x49), RGBU(0x4A), RGBU(0x4B), | |
118 RGBU(0x4C), RGBU(0x4D), RGBU(0x4E), RGBU(0x4F), | |
119 RGBU(0x50), RGBU(0x51), RGBU(0x52), RGBU(0x53), | |
120 RGBU(0x54), RGBU(0x55), RGBU(0x56), RGBU(0x57), | |
121 RGBU(0x58), RGBU(0x59), RGBU(0x5A), RGBU(0x5B), | |
122 RGBU(0x5C), RGBU(0x5D), RGBU(0x5E), RGBU(0x5F), | |
123 RGBU(0x60), RGBU(0x61), RGBU(0x62), RGBU(0x63), | |
124 RGBU(0x64), RGBU(0x65), RGBU(0x66), RGBU(0x67), | |
125 RGBU(0x68), RGBU(0x69), RGBU(0x6A), RGBU(0x6B), | |
126 RGBU(0x6C), RGBU(0x6D), RGBU(0x6E), RGBU(0x6F), | |
127 RGBU(0x70), RGBU(0x71), RGBU(0x72), RGBU(0x73), | |
128 RGBU(0x74), RGBU(0x75), RGBU(0x76), RGBU(0x77), | |
129 RGBU(0x78), RGBU(0x79), RGBU(0x7A), RGBU(0x7B), | |
130 RGBU(0x7C), RGBU(0x7D), RGBU(0x7E), RGBU(0x7F), | |
131 RGBU(0x80), RGBU(0x81), RGBU(0x82), RGBU(0x83), | |
132 RGBU(0x84), RGBU(0x85), RGBU(0x86), RGBU(0x87), | |
133 RGBU(0x88), RGBU(0x89), RGBU(0x8A), RGBU(0x8B), | |
134 RGBU(0x8C), RGBU(0x8D), RGBU(0x8E), RGBU(0x8F), | |
135 RGBU(0x90), RGBU(0x91), RGBU(0x92), RGBU(0x93), | |
136 RGBU(0x94), RGBU(0x95), RGBU(0x96), RGBU(0x97), | |
137 RGBU(0x98), RGBU(0x99), RGBU(0x9A), RGBU(0x9B), | |
138 RGBU(0x9C), RGBU(0x9D), RGBU(0x9E), RGBU(0x9F), | |
139 RGBU(0xA0), RGBU(0xA1), RGBU(0xA2), RGBU(0xA3), | |
140 RGBU(0xA4), RGBU(0xA5), RGBU(0xA6), RGBU(0xA7), | |
141 RGBU(0xA8), RGBU(0xA9), RGBU(0xAA), RGBU(0xAB), | |
142 RGBU(0xAC), RGBU(0xAD), RGBU(0xAE), RGBU(0xAF), | |
143 RGBU(0xB0), RGBU(0xB1), RGBU(0xB2), RGBU(0xB3), | |
144 RGBU(0xB4), RGBU(0xB5), RGBU(0xB6), RGBU(0xB7), | |
145 RGBU(0xB8), RGBU(0xB9), RGBU(0xBA), RGBU(0xBB), | |
146 RGBU(0xBC), RGBU(0xBD), RGBU(0xBE), RGBU(0xBF), | |
147 RGBU(0xC0), RGBU(0xC1), RGBU(0xC2), RGBU(0xC3), | |
148 RGBU(0xC4), RGBU(0xC5), RGBU(0xC6), RGBU(0xC7), | |
149 RGBU(0xC8), RGBU(0xC9), RGBU(0xCA), RGBU(0xCB), | |
150 RGBU(0xCC), RGBU(0xCD), RGBU(0xCE), RGBU(0xCF), | |
151 RGBU(0xD0), RGBU(0xD1), RGBU(0xD2), RGBU(0xD3), | |
152 RGBU(0xD4), RGBU(0xD5), RGBU(0xD6), RGBU(0xD7), | |
153 RGBU(0xD8), RGBU(0xD9), RGBU(0xDA), RGBU(0xDB), | |
154 RGBU(0xDC), RGBU(0xDD), RGBU(0xDE), RGBU(0xDF), | |
155 RGBU(0xE0), RGBU(0xE1), RGBU(0xE2), RGBU(0xE3), | |
156 RGBU(0xE4), RGBU(0xE5), RGBU(0xE6), RGBU(0xE7), | |
157 RGBU(0xE8), RGBU(0xE9), RGBU(0xEA), RGBU(0xEB), | |
158 RGBU(0xEC), RGBU(0xED), RGBU(0xEE), RGBU(0xEF), | |
159 RGBU(0xF0), RGBU(0xF1), RGBU(0xF2), RGBU(0xF3), | |
160 RGBU(0xF4), RGBU(0xF5), RGBU(0xF6), RGBU(0xF7), | |
161 RGBU(0xF8), RGBU(0xF9), RGBU(0xFA), RGBU(0xFB), | |
162 RGBU(0xFC), RGBU(0xFD), RGBU(0xFE), RGBU(0xFF), | |
163 }; | |
164 | |
165 MMX_ALIGNED(int16 kCoefficientsRgbV[256][4]) = { | |
166 RGBV(0x00), RGBV(0x01), RGBV(0x02), RGBV(0x03), | |
167 RGBV(0x04), RGBV(0x05), RGBV(0x06), RGBV(0x07), | |
168 RGBV(0x08), RGBV(0x09), RGBV(0x0A), RGBV(0x0B), | |
169 RGBV(0x0C), RGBV(0x0D), RGBV(0x0E), RGBV(0x0F), | |
170 RGBV(0x10), RGBV(0x11), RGBV(0x12), RGBV(0x13), | |
171 RGBV(0x14), RGBV(0x15), RGBV(0x16), RGBV(0x17), | |
172 RGBV(0x18), RGBV(0x19), RGBV(0x1A), RGBV(0x1B), | |
173 RGBV(0x1C), RGBV(0x1D), RGBV(0x1E), RGBV(0x1F), | |
174 RGBV(0x20), RGBV(0x21), RGBV(0x22), RGBV(0x23), | |
175 RGBV(0x24), RGBV(0x25), RGBV(0x26), RGBV(0x27), | |
176 RGBV(0x28), RGBV(0x29), RGBV(0x2A), RGBV(0x2B), | |
177 RGBV(0x2C), RGBV(0x2D), RGBV(0x2E), RGBV(0x2F), | |
178 RGBV(0x30), RGBV(0x31), RGBV(0x32), RGBV(0x33), | |
179 RGBV(0x34), RGBV(0x35), RGBV(0x36), RGBV(0x37), | |
180 RGBV(0x38), RGBV(0x39), RGBV(0x3A), RGBV(0x3B), | |
181 RGBV(0x3C), RGBV(0x3D), RGBV(0x3E), RGBV(0x3F), | |
182 RGBV(0x40), RGBV(0x41), RGBV(0x42), RGBV(0x43), | |
183 RGBV(0x44), RGBV(0x45), RGBV(0x46), RGBV(0x47), | |
184 RGBV(0x48), RGBV(0x49), RGBV(0x4A), RGBV(0x4B), | |
185 RGBV(0x4C), RGBV(0x4D), RGBV(0x4E), RGBV(0x4F), | |
186 RGBV(0x50), RGBV(0x51), RGBV(0x52), RGBV(0x53), | |
187 RGBV(0x54), RGBV(0x55), RGBV(0x56), RGBV(0x57), | |
188 RGBV(0x58), RGBV(0x59), RGBV(0x5A), RGBV(0x5B), | |
189 RGBV(0x5C), RGBV(0x5D), RGBV(0x5E), RGBV(0x5F), | |
190 RGBV(0x60), RGBV(0x61), RGBV(0x62), RGBV(0x63), | |
191 RGBV(0x64), RGBV(0x65), RGBV(0x66), RGBV(0x67), | |
192 RGBV(0x68), RGBV(0x69), RGBV(0x6A), RGBV(0x6B), | |
193 RGBV(0x6C), RGBV(0x6D), RGBV(0x6E), RGBV(0x6F), | |
194 RGBV(0x70), RGBV(0x71), RGBV(0x72), RGBV(0x73), | |
195 RGBV(0x74), RGBV(0x75), RGBV(0x76), RGBV(0x77), | |
196 RGBV(0x78), RGBV(0x79), RGBV(0x7A), RGBV(0x7B), | |
197 RGBV(0x7C), RGBV(0x7D), RGBV(0x7E), RGBV(0x7F), | |
198 RGBV(0x80), RGBV(0x81), RGBV(0x82), RGBV(0x83), | |
199 RGBV(0x84), RGBV(0x85), RGBV(0x86), RGBV(0x87), | |
200 RGBV(0x88), RGBV(0x89), RGBV(0x8A), RGBV(0x8B), | |
201 RGBV(0x8C), RGBV(0x8D), RGBV(0x8E), RGBV(0x8F), | |
202 RGBV(0x90), RGBV(0x91), RGBV(0x92), RGBV(0x93), | |
203 RGBV(0x94), RGBV(0x95), RGBV(0x96), RGBV(0x97), | |
204 RGBV(0x98), RGBV(0x99), RGBV(0x9A), RGBV(0x9B), | |
205 RGBV(0x9C), RGBV(0x9D), RGBV(0x9E), RGBV(0x9F), | |
206 RGBV(0xA0), RGBV(0xA1), RGBV(0xA2), RGBV(0xA3), | |
207 RGBV(0xA4), RGBV(0xA5), RGBV(0xA6), RGBV(0xA7), | |
208 RGBV(0xA8), RGBV(0xA9), RGBV(0xAA), RGBV(0xAB), | |
209 RGBV(0xAC), RGBV(0xAD), RGBV(0xAE), RGBV(0xAF), | |
210 RGBV(0xB0), RGBV(0xB1), RGBV(0xB2), RGBV(0xB3), | |
211 RGBV(0xB4), RGBV(0xB5), RGBV(0xB6), RGBV(0xB7), | |
212 RGBV(0xB8), RGBV(0xB9), RGBV(0xBA), RGBV(0xBB), | |
213 RGBV(0xBC), RGBV(0xBD), RGBV(0xBE), RGBV(0xBF), | |
214 RGBV(0xC0), RGBV(0xC1), RGBV(0xC2), RGBV(0xC3), | |
215 RGBV(0xC4), RGBV(0xC5), RGBV(0xC6), RGBV(0xC7), | |
216 RGBV(0xC8), RGBV(0xC9), RGBV(0xCA), RGBV(0xCB), | |
217 RGBV(0xCC), RGBV(0xCD), RGBV(0xCE), RGBV(0xCF), | |
218 RGBV(0xD0), RGBV(0xD1), RGBV(0xD2), RGBV(0xD3), | |
219 RGBV(0xD4), RGBV(0xD5), RGBV(0xD6), RGBV(0xD7), | |
220 RGBV(0xD8), RGBV(0xD9), RGBV(0xDA), RGBV(0xDB), | |
221 RGBV(0xDC), RGBV(0xDD), RGBV(0xDE), RGBV(0xDF), | |
222 RGBV(0xE0), RGBV(0xE1), RGBV(0xE2), RGBV(0xE3), | |
223 RGBV(0xE4), RGBV(0xE5), RGBV(0xE6), RGBV(0xE7), | |
224 RGBV(0xE8), RGBV(0xE9), RGBV(0xEA), RGBV(0xEB), | |
225 RGBV(0xEC), RGBV(0xED), RGBV(0xEE), RGBV(0xEF), | |
226 RGBV(0xF0), RGBV(0xF1), RGBV(0xF2), RGBV(0xF3), | |
227 RGBV(0xF4), RGBV(0xF5), RGBV(0xF6), RGBV(0xF7), | |
228 RGBV(0xF8), RGBV(0xF9), RGBV(0xFA), RGBV(0xFB), | |
229 RGBV(0xFC), RGBV(0xFD), RGBV(0xFE), RGBV(0xFF), | |
230 }; | |
231 | |
232 #undef RGBHY | |
233 #undef RGBY | |
234 #undef RGBU | |
235 #undef RGBV | |
236 #undef MMX_ALIGNED | |
237 | |
238 // Warning C4799: function has no EMMS instruction. | |
239 // EMMS() is slow and should be called by the calling function once per image. | |
240 #pragma warning(disable: 4799) | |
241 | |
242 __declspec(naked) | 13 __declspec(naked) |
243 void FastConvertYUVToRGB32Row(const uint8* y_buf, | 14 void FastConvertYUVToRGB32Row(const uint8* y_buf, |
244 const uint8* u_buf, | 15 const uint8* u_buf, |
245 const uint8* v_buf, | 16 const uint8* v_buf, |
246 uint8* rgb_buf, | 17 uint8* rgb_buf, |
247 int width) { | 18 int source_width) { |
248 __asm { | 19 __asm { |
249 pushad | 20 pushad |
250 mov edx, [esp + 32 + 4] // Y | 21 mov edx, [esp + 32 + 4] // Y |
251 mov edi, [esp + 32 + 8] // U | 22 mov edi, [esp + 32 + 8] // U |
252 mov esi, [esp + 32 + 12] // V | 23 mov esi, [esp + 32 + 12] // V |
253 mov ebp, [esp + 32 + 16] // rgb | 24 mov ebp, [esp + 32 + 16] // rgb |
254 mov ecx, [esp + 32 + 20] // width | 25 mov ecx, [esp + 32 + 20] // source_width |
255 jmp convertend | 26 jmp convertend |
256 | 27 |
257 convertloop : | 28 convertloop : |
258 movzx eax, byte ptr [edi] | 29 movzx eax, byte ptr [edi] |
259 add edi, 1 | 30 add edi, 1 |
260 movzx ebx, byte ptr [esi] | 31 movzx ebx, byte ptr [esi] |
261 add esi, 1 | 32 add esi, 1 |
262 movq mm0, [kCoefficientsRgbU + 8 * eax] | 33 movq mm0, [kCoefficientsRgbU + 8 * eax] |
263 movzx eax, byte ptr [edx] | 34 movzx eax, byte ptr [edx] |
264 paddsw mm0, [kCoefficientsRgbV + 8 * ebx] | 35 paddsw mm0, [kCoefficientsRgbV + 8 * ebx] |
(...skipping 30 matching lines...) Expand all Loading... |
295 popad | 66 popad |
296 ret | 67 ret |
297 } | 68 } |
298 } | 69 } |
299 | 70 |
300 __declspec(naked) | 71 __declspec(naked) |
301 void ConvertYUVToRGB32Row(const uint8* y_buf, | 72 void ConvertYUVToRGB32Row(const uint8* y_buf, |
302 const uint8* u_buf, | 73 const uint8* u_buf, |
303 const uint8* v_buf, | 74 const uint8* v_buf, |
304 uint8* rgb_buf, | 75 uint8* rgb_buf, |
305 int width, | 76 int source_width, |
306 int step) { | 77 int step) { |
307 __asm { | 78 __asm { |
308 pushad | 79 pushad |
309 mov edx, [esp + 32 + 4] // Y | 80 mov edx, [esp + 32 + 4] // Y |
310 mov edi, [esp + 32 + 8] // U | 81 mov edi, [esp + 32 + 8] // U |
311 mov esi, [esp + 32 + 12] // V | 82 mov esi, [esp + 32 + 12] // V |
312 mov ebp, [esp + 32 + 16] // rgb | 83 mov ebp, [esp + 32 + 16] // rgb |
313 mov ecx, [esp + 32 + 20] // width | 84 mov ecx, [esp + 32 + 20] // source_width |
314 mov ebx, [esp + 32 + 24] // step | 85 mov ebx, [esp + 32 + 24] // step |
315 jmp wend | 86 jmp wend |
316 | 87 |
317 wloop : | 88 wloop : |
318 movzx eax, byte ptr [edi] | 89 movzx eax, byte ptr [edi] |
319 add edi, ebx | 90 add edi, ebx |
320 movq mm0, [kCoefficientsRgbU + 8 * eax] | 91 movq mm0, [kCoefficientsRgbU + 8 * eax] |
321 movzx eax, byte ptr [esi] | 92 movzx eax, byte ptr [esi] |
322 add esi, ebx | 93 add esi, ebx |
323 paddsw mm0, [kCoefficientsRgbV + 8 * eax] | 94 paddsw mm0, [kCoefficientsRgbV + 8 * eax] |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 popad | 127 popad |
357 ret | 128 ret |
358 } | 129 } |
359 } | 130 } |
360 | 131 |
361 __declspec(naked) | 132 __declspec(naked) |
362 void RotateConvertYUVToRGB32Row(const uint8* y_buf, | 133 void RotateConvertYUVToRGB32Row(const uint8* y_buf, |
363 const uint8* u_buf, | 134 const uint8* u_buf, |
364 const uint8* v_buf, | 135 const uint8* v_buf, |
365 uint8* rgb_buf, | 136 uint8* rgb_buf, |
366 int width, | 137 int source_width, |
367 int ystep, | 138 int ystep, |
368 int uvstep) { | 139 int uvstep) { |
369 __asm { | 140 __asm { |
370 pushad | 141 pushad |
371 mov edx, [esp + 32 + 4] // Y | 142 mov edx, [esp + 32 + 4] // Y |
372 mov edi, [esp + 32 + 8] // U | 143 mov edi, [esp + 32 + 8] // U |
373 mov esi, [esp + 32 + 12] // V | 144 mov esi, [esp + 32 + 12] // V |
374 mov ebp, [esp + 32 + 16] // rgb | 145 mov ebp, [esp + 32 + 16] // rgb |
375 mov ecx, [esp + 32 + 20] // width | 146 mov ecx, [esp + 32 + 20] // source_width |
376 jmp wend | 147 jmp wend |
377 | 148 |
378 wloop : | 149 wloop : |
379 movzx eax, byte ptr [edi] | 150 movzx eax, byte ptr [edi] |
380 mov ebx, [esp + 32 + 28] // uvstep | 151 mov ebx, [esp + 32 + 28] // uvstep |
381 add edi, ebx | 152 add edi, ebx |
382 movq mm0, [kCoefficientsRgbU + 8 * eax] | 153 movq mm0, [kCoefficientsRgbU + 8 * eax] |
383 movzx eax, byte ptr [esi] | 154 movzx eax, byte ptr [esi] |
384 add esi, ebx | 155 add esi, ebx |
385 paddsw mm0, [kCoefficientsRgbV + 8 * eax] | 156 paddsw mm0, [kCoefficientsRgbV + 8 * eax] |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 popad | 190 popad |
420 ret | 191 ret |
421 } | 192 } |
422 } | 193 } |
423 | 194 |
424 __declspec(naked) | 195 __declspec(naked) |
425 void DoubleYUVToRGB32Row(const uint8* y_buf, | 196 void DoubleYUVToRGB32Row(const uint8* y_buf, |
426 const uint8* u_buf, | 197 const uint8* u_buf, |
427 const uint8* v_buf, | 198 const uint8* v_buf, |
428 uint8* rgb_buf, | 199 uint8* rgb_buf, |
429 int width) { | 200 int source_width) { |
430 __asm { | 201 __asm { |
431 pushad | 202 pushad |
432 mov edx, [esp + 32 + 4] // Y | 203 mov edx, [esp + 32 + 4] // Y |
433 mov edi, [esp + 32 + 8] // U | 204 mov edi, [esp + 32 + 8] // U |
434 mov esi, [esp + 32 + 12] // V | 205 mov esi, [esp + 32 + 12] // V |
435 mov ebp, [esp + 32 + 16] // rgb | 206 mov ebp, [esp + 32 + 16] // rgb |
436 mov ecx, [esp + 32 + 20] // width | 207 mov ecx, [esp + 32 + 20] // source_width |
437 jmp wend | 208 jmp wend |
438 | 209 |
439 wloop : | 210 wloop : |
440 movzx eax, byte ptr [edi] | 211 movzx eax, byte ptr [edi] |
441 add edi, 1 | 212 add edi, 1 |
442 movzx ebx, byte ptr [esi] | 213 movzx ebx, byte ptr [esi] |
443 add esi, 1 | 214 add esi, 1 |
444 movq mm0, [kCoefficientsRgbU + 8 * eax] | 215 movq mm0, [kCoefficientsRgbU + 8 * eax] |
445 movzx eax, byte ptr [edx] | 216 movzx eax, byte ptr [edx] |
446 paddsw mm0, [kCoefficientsRgbV + 8 * ebx] | 217 paddsw mm0, [kCoefficientsRgbV + 8 * ebx] |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 262 |
492 // This version does general purpose scaling by any amount, up or down. | 263 // This version does general purpose scaling by any amount, up or down. |
493 // The only thing it can not do it rotation by 90 or 270. | 264 // The only thing it can not do it rotation by 90 or 270. |
494 // For performance the chroma is under sampled, reducing cost of a 3x | 265 // For performance the chroma is under sampled, reducing cost of a 3x |
495 // 1080p scale from 8.4 ms to 5.4 ms. | 266 // 1080p scale from 8.4 ms to 5.4 ms. |
496 __declspec(naked) | 267 __declspec(naked) |
497 void ScaleYUVToRGB32Row(const uint8* y_buf, | 268 void ScaleYUVToRGB32Row(const uint8* y_buf, |
498 const uint8* u_buf, | 269 const uint8* u_buf, |
499 const uint8* v_buf, | 270 const uint8* v_buf, |
500 uint8* rgb_buf, | 271 uint8* rgb_buf, |
501 int width, | 272 int source_width, |
502 int dx) { | 273 int dx) { |
503 __asm { | 274 __asm { |
504 pushad | 275 pushad |
505 mov edx, [esp + 32 + 4] // Y | 276 mov edx, [esp + 32 + 4] // Y |
506 mov edi, [esp + 32 + 8] // U | 277 mov edi, [esp + 32 + 8] // U |
507 mov esi, [esp + 32 + 12] // V | 278 mov esi, [esp + 32 + 12] // V |
508 mov ebp, [esp + 32 + 16] // rgb | 279 mov ebp, [esp + 32 + 16] // rgb |
509 mov ecx, [esp + 32 + 20] // width | 280 mov ecx, [esp + 32 + 20] // source_width |
510 xor ebx, ebx // x | 281 xor ebx, ebx // x |
511 jmp scaleend | 282 jmp scaleend |
512 | 283 |
513 scaleloop : | 284 scaleloop : |
514 mov eax, ebx | 285 mov eax, ebx |
515 sar eax, 17 | 286 sar eax, 17 |
516 movzx eax, byte ptr [edi + eax] | 287 movzx eax, byte ptr [edi + eax] |
517 movq mm0, [kCoefficientsRgbU + 8 * eax] | 288 movq mm0, [kCoefficientsRgbU + 8 * eax] |
518 mov eax, ebx | 289 mov eax, ebx |
519 sar eax, 17 | 290 sar eax, 17 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 popad | 335 popad |
565 ret | 336 ret |
566 } | 337 } |
567 } | 338 } |
568 | 339 |
569 __declspec(naked) | 340 __declspec(naked) |
570 void LinearScaleYUVToRGB32Row(const uint8* y_buf, | 341 void LinearScaleYUVToRGB32Row(const uint8* y_buf, |
571 const uint8* u_buf, | 342 const uint8* u_buf, |
572 const uint8* v_buf, | 343 const uint8* v_buf, |
573 uint8* rgb_buf, | 344 uint8* rgb_buf, |
574 int width, | 345 int source_width, |
575 int scaled_dx) { | 346 int source_dx) { |
576 __asm { | 347 __asm { |
577 pushad | 348 pushad |
578 mov edx, [esp + 32 + 4] | 349 mov edx, [esp + 32 + 4] |
579 mov edi, [esp + 32 + 8] | 350 mov edi, [esp + 32 + 8] |
580 mov ebp, [esp + 32 + 16] | 351 mov ebp, [esp + 32 + 16] |
581 mov ecx, [esp + 32 + 20] // width = width * scaled_dx + ebx | 352 mov ecx, [esp + 32 + 20] // source_width = source_width * source_dx + ebx |
582 imul ecx, [esp + 32 + 24] | 353 imul ecx, [esp + 32 + 24] |
583 xor ebx, ebx | 354 xor ebx, ebx |
584 add ecx, ebx | 355 add ecx, ebx |
585 mov [esp + 32 + 20], ecx | 356 mov [esp + 32 + 20], ecx |
586 jmp lscaleend | 357 jmp lscaleend |
587 lscaleloop: | 358 lscaleloop: |
588 mov eax, ebx | 359 mov eax, ebx |
589 sar eax, 0x11 | 360 sar eax, 0x11 |
590 | 361 |
591 movzx ecx, byte ptr [edi + eax] | 362 movzx ecx, byte ptr [edi + eax] |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 | 432 |
662 lscalelastpixel: | 433 lscalelastpixel: |
663 paddsw mm1, mm0 | 434 paddsw mm1, mm0 |
664 psraw mm1, 6 | 435 psraw mm1, 6 |
665 packuswb mm1, mm1 | 436 packuswb mm1, mm1 |
666 movd [ebp], mm1 | 437 movd [ebp], mm1 |
667 popad | 438 popad |
668 ret | 439 ret |
669 }; | 440 }; |
670 } | 441 } |
| 442 #else // USE_MMX |
671 | 443 |
| 444 // C reference code that mimic the YUV assembly. |
| 445 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) |
| 446 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \\ |
| 447 (((x) + (y)) > 32767 ? 32767 : ((x) + (y)))) |
| 448 |
| 449 static inline void YuvPixel(uint8 y, |
| 450 uint8 u, |
| 451 uint8 v, |
| 452 uint8* rgb_buf) { |
| 453 |
| 454 int b = kCoefficientsRgbY[256+u][0]; |
| 455 int g = kCoefficientsRgbY[256+u][1]; |
| 456 int r = kCoefficientsRgbY[256+u][2]; |
| 457 int a = kCoefficientsRgbY[256+u][3]; |
| 458 |
| 459 b = paddsw(b, kCoefficientsRgbY[512+v][0]); |
| 460 g = paddsw(g, kCoefficientsRgbY[512+v][1]); |
| 461 r = paddsw(r, kCoefficientsRgbY[512+v][2]); |
| 462 a = paddsw(a, kCoefficientsRgbY[512+v][3]); |
| 463 |
| 464 b = paddsw(b, kCoefficientsRgbY[y][0]); |
| 465 g = paddsw(g, kCoefficientsRgbY[y][1]); |
| 466 r = paddsw(r, kCoefficientsRgbY[y][2]); |
| 467 a = paddsw(a, kCoefficientsRgbY[y][3]); |
| 468 |
| 469 b >>= 6; |
| 470 g >>= 6; |
| 471 r >>= 6; |
| 472 a >>= 6; |
| 473 |
| 474 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) | |
| 475 (packuswb(g) << 8) | |
| 476 (packuswb(r) << 16) | |
| 477 (packuswb(a) << 24); |
| 478 } |
| 479 |
| 480 #if TEST_MMX_YUV |
| 481 static inline void YuvPixel(uint8 y, |
| 482 uint8 u, |
| 483 uint8 v, |
| 484 uint8* rgb_buf) { |
| 485 |
| 486 __asm { |
| 487 movzx eax, u |
| 488 movq mm0, [kCoefficientsRgbY+2048 + 8 * eax] |
| 489 movzx eax, v |
| 490 paddsw mm0, [kCoefficientsRgbY+4096 + 8 * eax] |
| 491 movzx eax, y |
| 492 movq mm1, [kCoefficientsRgbY + 8 * eax] |
| 493 paddsw mm1, mm0 |
| 494 psraw mm1, 6 |
| 495 packuswb mm1, mm1 |
| 496 mov eax, rgb_buf |
| 497 movd [eax], mm1 |
| 498 emms |
| 499 } |
| 500 } |
| 501 #endif |
| 502 |
| 503 void FastConvertYUVToRGB32Row(const uint8* y_buf, |
| 504 const uint8* u_buf, |
| 505 const uint8* v_buf, |
| 506 uint8* rgb_buf, |
| 507 int source_width) { |
| 508 for (int x = 0; x < source_width; x += 2) { |
| 509 uint8 u = u_buf[x >> 1]; |
| 510 uint8 v = v_buf[x >> 1]; |
| 511 uint8 y0 = y_buf[x]; |
| 512 YuvPixel(y0, u, v, rgb_buf); |
| 513 if ((x + 1) < source_width) { |
| 514 uint8 y1 = y_buf[x + 1]; |
| 515 YuvPixel(y1, u, v, rgb_buf + 4); |
| 516 } |
| 517 rgb_buf += 8; // Advance 2 pixels. |
| 518 } |
| 519 } |
| 520 |
| 521 // 16.16 fixed point is used. A shift by 16 isolates the integer. |
| 522 // A shift by 17 is used to further subsample the chrominence channels. |
| 523 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, |
| 524 // for 1/65536 pixel accurate interpolation. |
| 525 void ScaleYUVToRGB32Row(const uint8* y_buf, |
| 526 const uint8* u_buf, |
| 527 const uint8* v_buf, |
| 528 uint8* rgb_buf, |
| 529 int source_width, |
| 530 int dx) { |
| 531 int x = 0; |
| 532 for (int i = 0; i < source_width; i += 2) { |
| 533 int y = y_buf[x >> 16]; |
| 534 int u = u_buf[(x >> 17)]; |
| 535 int v = v_buf[(x >> 17)]; |
| 536 YuvPixel(y, u, v, rgb_buf); |
| 537 x += dx; |
| 538 if ((i + 1) < source_width) { |
| 539 y = y_buf[x >> 16]; |
| 540 YuvPixel(y, u, v, rgb_buf+4); |
| 541 x += dx; |
| 542 } |
| 543 rgb_buf += 8; |
| 544 } |
| 545 } |
| 546 |
| 547 void LinearScaleYUVToRGB32Row(const uint8* y_buf, |
| 548 const uint8* u_buf, |
| 549 const uint8* v_buf, |
| 550 uint8* rgb_buf, |
| 551 int source_width, |
| 552 int dx) { |
| 553 int x = 0; |
| 554 for (int i = 0; i < source_width; i += 2) { |
| 555 int y0 = y_buf[x >> 16]; |
| 556 int y1 = y_buf[(x >> 16) + 1]; |
| 557 int u0 = u_buf[(x >> 17)]; |
| 558 int u1 = u_buf[(x >> 17) + 1]; |
| 559 int v0 = v_buf[(x >> 17)]; |
| 560 int v1 = v_buf[(x >> 17) + 1]; |
| 561 int y_frac = (x & 65535); |
| 562 int uv_frac = ((x >> 1) & 65535); |
| 563 int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16; |
| 564 int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16; |
| 565 int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16; |
| 566 YuvPixel(y, u, v, rgb_buf); |
| 567 x += dx; |
| 568 if ((i + 1) < source_width) { |
| 569 y0 = y_buf[x >> 16]; |
| 570 y1 = y_buf[(x >> 16) + 1]; |
| 571 y_frac = (x & 65535); |
| 572 y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16; |
| 573 YuvPixel(y, u, v, rgb_buf+4); |
| 574 x += dx; |
| 575 } |
| 576 rgb_buf += 8; |
| 577 } |
| 578 } |
| 579 |
| 580 #endif // USE_MMX |
672 } // extern "C" | 581 } // extern "C" |
| 582 |
OLD | NEW |