/src/ffmpeg/libswscale/rgb2rgb_template.c
Line | Count | Source |
1 | | /* |
2 | | * software RGB to RGB converter |
3 | | * pluralize by software PAL8 to RGB converter |
4 | | * software YUV to YUV converter |
5 | | * software YUV to RGB converter |
6 | | * Written by Nick Kurshev. |
7 | | * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at) |
8 | | * lot of big-endian byte order fixes by Alex Beregszaszi |
9 | | * |
10 | | * This file is part of FFmpeg. |
11 | | * |
12 | | * FFmpeg is free software; you can redistribute it and/or |
13 | | * modify it under the terms of the GNU Lesser General Public |
14 | | * License as published by the Free Software Foundation; either |
15 | | * version 2.1 of the License, or (at your option) any later version. |
16 | | * |
17 | | * FFmpeg is distributed in the hope that it will be useful, |
18 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | | * Lesser General Public License for more details. |
21 | | * |
22 | | * You should have received a copy of the GNU Lesser General Public |
23 | | * License along with FFmpeg; if not, write to the Free Software |
24 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
25 | | */ |
26 | | |
27 | | #include <stddef.h> |
28 | | |
29 | | #include "libavutil/attributes.h" |
30 | | |
31 | | static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, |
32 | | int src_size) |
33 | 0 | { |
34 | 0 | uint8_t *dest = dst; |
35 | 0 | const uint8_t *s = src; |
36 | 0 | const uint8_t *end = s + src_size; |
37 | |
|
38 | 0 | while (s < end) { |
39 | | #if HAVE_BIGENDIAN |
40 | | /* RGB24 (= R, G, B) -> RGB32 (= A, B, G, R) */ |
41 | | *dest++ = 255; |
42 | | *dest++ = s[2]; |
43 | | *dest++ = s[1]; |
44 | | *dest++ = s[0]; |
45 | | s += 3; |
46 | | #else |
47 | 0 | *dest++ = *s++; |
48 | 0 | *dest++ = *s++; |
49 | 0 | *dest++ = *s++; |
50 | 0 | *dest++ = 255; |
51 | 0 | #endif |
52 | 0 | } |
53 | 0 | } |
54 | | |
55 | | static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, |
56 | | int src_size) |
57 | 0 | { |
58 | 0 | uint8_t *dest = dst; |
59 | 0 | const uint8_t *s = src; |
60 | 0 | const uint8_t *end = s + src_size; |
61 | |
|
62 | 0 | while (s < end) { |
63 | | #if HAVE_BIGENDIAN |
64 | | /* RGB32 (= A, B, G, R) -> RGB24 (= R, G, B) */ |
65 | | s++; |
66 | | dest[2] = *s++; |
67 | | dest[1] = *s++; |
68 | | dest[0] = *s++; |
69 | | dest += 3; |
70 | | #else |
71 | 0 | *dest++ = *s++; |
72 | 0 | *dest++ = *s++; |
73 | 0 | *dest++ = *s++; |
74 | 0 | s++; |
75 | 0 | #endif |
76 | 0 | } |
77 | 0 | } |
78 | | |
79 | | /* |
80 | | * original by Strepto/Astral |
81 | | * ported to gcc & bugfixed: A'rpi |
82 | | * MMXEXT, 3DNOW optimization by Nick Kurshev |
83 | | * 32-bit C version, and and&add trick by Michael Niedermayer |
84 | | */ |
85 | | static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, int src_size) |
86 | 0 | { |
87 | 0 | register uint8_t *d = dst; |
88 | 0 | register const uint8_t *s = src; |
89 | 0 | register const uint8_t *end = s + src_size; |
90 | 0 | const uint8_t *mm_end = end - 3; |
91 | |
|
92 | 0 | while (s < mm_end) { |
93 | 0 | register unsigned x = *((const uint32_t *)s); |
94 | 0 | *((uint32_t *)d) = (x & 0x7FFF7FFF) + (x & 0x7FE07FE0); |
95 | 0 | d += 4; |
96 | 0 | s += 4; |
97 | 0 | } |
98 | 0 | if (s < end) { |
99 | 0 | register unsigned short x = *((const uint16_t *)s); |
100 | 0 | *((uint16_t *)d) = (x & 0x7FFF) + (x & 0x7FE0); |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | | static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, int src_size) |
105 | 0 | { |
106 | 0 | register uint8_t *d = dst; |
107 | 0 | register const uint8_t *s = src; |
108 | 0 | register const uint8_t *end = s + src_size; |
109 | 0 | const uint8_t *mm_end = end - 3; |
110 | |
|
111 | 0 | while (s < mm_end) { |
112 | 0 | register uint32_t x = *((const uint32_t *)s); |
113 | 0 | *((uint32_t *)d) = ((x >> 1) & 0x7FE07FE0) | (x & 0x001F001F); |
114 | 0 | s += 4; |
115 | 0 | d += 4; |
116 | 0 | } |
117 | 0 | if (s < end) { |
118 | 0 | register uint16_t x = *((const uint16_t *)s); |
119 | 0 | *((uint16_t *)d) = ((x >> 1) & 0x7FE0) | (x & 0x001F); |
120 | 0 | } |
121 | 0 | } |
122 | | |
123 | | static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, int src_size) |
124 | 0 | { |
125 | 0 | uint16_t *d = (uint16_t *)dst; |
126 | 0 | const uint8_t *s = src; |
127 | 0 | const uint8_t *end = s + src_size; |
128 | |
|
129 | 0 | while (s < end) { |
130 | 0 | register int rgb = *(const uint32_t *)s; |
131 | 0 | s += 4; |
132 | 0 | *d++ = ((rgb & 0xFF) >> 3) + |
133 | 0 | ((rgb & 0xFC00) >> 5) + |
134 | 0 | ((rgb & 0xF80000) >> 8); |
135 | 0 | } |
136 | 0 | } |
137 | | |
138 | | static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, |
139 | | int src_size) |
140 | 0 | { |
141 | 0 | uint16_t *d = (uint16_t *)dst; |
142 | 0 | const uint8_t *s = src; |
143 | 0 | const uint8_t *end = s + src_size; |
144 | |
|
145 | 0 | while (s < end) { |
146 | 0 | register int rgb = *(const uint32_t *)s; |
147 | 0 | s += 4; |
148 | 0 | *d++ = ((rgb & 0xF8) << 8) + |
149 | 0 | ((rgb & 0xFC00) >> 5) + |
150 | 0 | ((rgb & 0xF80000) >> 19); |
151 | 0 | } |
152 | 0 | } |
153 | | |
154 | | static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size) |
155 | 0 | { |
156 | 0 | uint16_t *d = (uint16_t *)dst; |
157 | 0 | const uint8_t *s = src; |
158 | 0 | const uint8_t *end = s + src_size; |
159 | |
|
160 | 0 | while (s < end) { |
161 | 0 | register int rgb = *(const uint32_t *)s; |
162 | 0 | s += 4; |
163 | 0 | *d++ = ((rgb & 0xFF) >> 3) + |
164 | 0 | ((rgb & 0xF800) >> 6) + |
165 | 0 | ((rgb & 0xF80000) >> 9); |
166 | 0 | } |
167 | 0 | } |
168 | | |
169 | | static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, |
170 | | int src_size) |
171 | 0 | { |
172 | 0 | uint16_t *d = (uint16_t *)dst; |
173 | 0 | const uint8_t *s = src; |
174 | 0 | const uint8_t *end = s + src_size; |
175 | |
|
176 | 0 | while (s < end) { |
177 | 0 | register int rgb = *(const uint32_t *)s; |
178 | 0 | s += 4; |
179 | 0 | *d++ = ((rgb & 0xF8) << 7) + |
180 | 0 | ((rgb & 0xF800) >> 6) + |
181 | 0 | ((rgb & 0xF80000) >> 19); |
182 | 0 | } |
183 | 0 | } |
184 | | |
185 | | static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, |
186 | | int src_size) |
187 | 0 | { |
188 | 0 | uint16_t *d = (uint16_t *)dst; |
189 | 0 | const uint8_t *s = src; |
190 | 0 | const uint8_t *end = s + src_size; |
191 | |
|
192 | 0 | while (s < end) { |
193 | 0 | const int b = *s++; |
194 | 0 | const int g = *s++; |
195 | 0 | const int r = *s++; |
196 | 0 | *d++ = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8); |
197 | 0 | } |
198 | 0 | } |
199 | | |
200 | | static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size) |
201 | 0 | { |
202 | 0 | uint16_t *d = (uint16_t *)dst; |
203 | 0 | const uint8_t *s = src; |
204 | 0 | const uint8_t *end = s + src_size; |
205 | |
|
206 | 0 | while (s < end) { |
207 | 0 | const int r = *s++; |
208 | 0 | const int g = *s++; |
209 | 0 | const int b = *s++; |
210 | 0 | *d++ = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8); |
211 | 0 | } |
212 | 0 | } |
213 | | |
214 | | static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, |
215 | | int src_size) |
216 | 0 | { |
217 | 0 | uint16_t *d = (uint16_t *)dst; |
218 | 0 | const uint8_t *s = src; |
219 | 0 | const uint8_t *end = s + src_size; |
220 | |
|
221 | 0 | while (s < end) { |
222 | 0 | const int b = *s++; |
223 | 0 | const int g = *s++; |
224 | 0 | const int r = *s++; |
225 | 0 | *d++ = (b >> 3) | ((g & 0xF8) << 2) | ((r & 0xF8) << 7); |
226 | 0 | } |
227 | 0 | } |
228 | | |
229 | | static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size) |
230 | 0 | { |
231 | 0 | uint16_t *d = (uint16_t *)dst; |
232 | 0 | const uint8_t *s = src; |
233 | 0 | const uint8_t *end = s + src_size; |
234 | |
|
235 | 0 | while (s < end) { |
236 | 0 | const int r = *s++; |
237 | 0 | const int g = *s++; |
238 | 0 | const int b = *s++; |
239 | 0 | *d++ = (b >> 3) | ((g & 0xF8) << 2) | ((r & 0xF8) << 7); |
240 | 0 | } |
241 | 0 | } |
242 | | |
243 | | static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, |
244 | | int src_size) |
245 | 0 | { |
246 | 0 | uint8_t *d = dst; |
247 | 0 | const uint16_t *s = (const uint16_t *)src; |
248 | 0 | const uint16_t *end = s + src_size / 2; |
249 | |
|
250 | 0 | while (s < end) { |
251 | 0 | register uint16_t bgr = *s++; |
252 | 0 | *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2); |
253 | 0 | *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7); |
254 | 0 | *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); |
255 | 0 | } |
256 | 0 | } |
257 | | |
258 | | static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, |
259 | | int src_size) |
260 | 0 | { |
261 | 0 | uint8_t *d = (uint8_t *)dst; |
262 | 0 | const uint16_t *s = (const uint16_t *)src; |
263 | 0 | const uint16_t *end = s + src_size / 2; |
264 | |
|
265 | 0 | while (s < end) { |
266 | 0 | register uint16_t bgr = *s++; |
267 | 0 | *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2); |
268 | 0 | *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9); |
269 | 0 | *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); |
270 | 0 | } |
271 | 0 | } |
272 | | |
273 | | static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size) |
274 | 0 | { |
275 | 0 | uint8_t *d = dst; |
276 | 0 | const uint16_t *s = (const uint16_t *)src; |
277 | 0 | const uint16_t *end = s + src_size / 2; |
278 | |
|
279 | 0 | while (s < end) { |
280 | 0 | register uint16_t bgr = *s++; |
281 | | #if HAVE_BIGENDIAN |
282 | | *d++ = 255; |
283 | | *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); |
284 | | *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7); |
285 | | *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2); |
286 | | #else |
287 | 0 | *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2); |
288 | 0 | *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7); |
289 | 0 | *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); |
290 | 0 | *d++ = 255; |
291 | 0 | #endif |
292 | 0 | } |
293 | 0 | } |
294 | | |
295 | | static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size) |
296 | 0 | { |
297 | 0 | uint8_t *d = dst; |
298 | 0 | const uint16_t *s = (const uint16_t *)src; |
299 | 0 | const uint16_t *end = s + src_size / 2; |
300 | |
|
301 | 0 | while (s < end) { |
302 | 0 | register uint16_t bgr = *s++; |
303 | | #if HAVE_BIGENDIAN |
304 | | *d++ = 255; |
305 | | *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); |
306 | | *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9); |
307 | | *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2); |
308 | | #else |
309 | 0 | *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2); |
310 | 0 | *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9); |
311 | 0 | *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); |
312 | 0 | *d++ = 255; |
313 | 0 | #endif |
314 | 0 | } |
315 | 0 | } |
316 | | |
317 | | static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, |
318 | | int src_size) |
319 | 0 | { |
320 | 0 | int idx = 15 - src_size; |
321 | 0 | const uint8_t *s = src - idx; |
322 | 0 | uint8_t *d = dst - idx; |
323 | |
|
324 | 0 | for (; idx < 15; idx += 4) { |
325 | 0 | register unsigned v = *(const uint32_t *)&s[idx], g = v & 0xff00ff00; |
326 | 0 | v &= 0xff00ff; |
327 | 0 | *(uint32_t *)&d[idx] = (v >> 16) + g + (v << 16); |
328 | 0 | } |
329 | 0 | } |
330 | | |
331 | | static inline void shuffle_bytes_0321_c(const uint8_t *src, uint8_t *dst, |
332 | | int src_size) |
333 | 0 | { |
334 | 0 | int idx = 15 - src_size; |
335 | 0 | const uint8_t *s = src - idx; |
336 | 0 | uint8_t *d = dst - idx; |
337 | |
|
338 | 0 | for (; idx < 15; idx += 4) { |
339 | 0 | register unsigned v = *(const uint32_t *)&s[idx], g = v & 0x00ff00ff; |
340 | 0 | v &= 0xff00ff00; |
341 | 0 | *(uint32_t *)&d[idx] = (v >> 16) + g + (v << 16); |
342 | 0 | } |
343 | 0 | } |
344 | | |
345 | | #define DEFINE_SHUFFLE_BYTES(name, a, b, c, d) \ |
346 | | static void shuffle_bytes_##name (const uint8_t *src, \ |
347 | 0 | uint8_t *dst, int src_size) \ |
348 | 0 | { \ |
349 | 0 | int i; \ |
350 | 0 | \ |
351 | 0 | for (i = 0; i < src_size; i += 4) { \ |
352 | 0 | dst[i + 0] = src[i + a]; \ |
353 | 0 | dst[i + 1] = src[i + b]; \ |
354 | 0 | dst[i + 2] = src[i + c]; \ |
355 | 0 | dst[i + 3] = src[i + d]; \ |
356 | 0 | } \ |
357 | 0 | } Unexecuted instantiation: rgb2rgb.c:shuffle_bytes_1230_c Unexecuted instantiation: rgb2rgb.c:shuffle_bytes_3012_c Unexecuted instantiation: rgb2rgb.c:shuffle_bytes_3210_c Unexecuted instantiation: rgb2rgb.c:shuffle_bytes_3102_c Unexecuted instantiation: rgb2rgb.c:shuffle_bytes_2013_c Unexecuted instantiation: rgb2rgb.c:shuffle_bytes_2130_c Unexecuted instantiation: rgb2rgb.c:shuffle_bytes_1203_c |
358 | | |
359 | | DEFINE_SHUFFLE_BYTES(1230_c, 1, 2, 3, 0) |
360 | | DEFINE_SHUFFLE_BYTES(3012_c, 3, 0, 1, 2) |
361 | | DEFINE_SHUFFLE_BYTES(3210_c, 3, 2, 1, 0) |
362 | | DEFINE_SHUFFLE_BYTES(3102_c, 3, 1, 0, 2) |
363 | | DEFINE_SHUFFLE_BYTES(2013_c, 2, 0, 1, 3) |
364 | | DEFINE_SHUFFLE_BYTES(2130_c, 2, 1, 3, 0) |
365 | | DEFINE_SHUFFLE_BYTES(1203_c, 1, 2, 0, 3) |
366 | | |
367 | | static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) |
368 | 0 | { |
369 | 0 | unsigned i; |
370 | |
|
371 | 0 | for (i = 0; i < src_size; i += 3) { |
372 | 0 | register uint8_t x = src[i + 2]; |
373 | 0 | dst[i + 1] = src[i + 1]; |
374 | 0 | dst[i + 2] = src[i + 0]; |
375 | 0 | dst[i + 0] = x; |
376 | 0 | } |
377 | 0 | } |
378 | | |
379 | | static inline void yuvPlanartoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc, |
380 | | const uint8_t *vsrc, uint8_t *dst, |
381 | | int width, int height, |
382 | | int lumStride, int chromStride, |
383 | | int dstStride, int vertLumPerChroma) |
384 | 0 | { |
385 | 0 | int y, i; |
386 | 0 | const int chromWidth = width >> 1; |
387 | |
|
388 | 0 | for (y = 0; y < height; y++) { |
389 | | #if HAVE_FAST_64BIT |
390 | | uint64_t *ldst = (uint64_t *)dst; |
391 | | const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; |
392 | | for (i = 0; i < chromWidth; i += 2) { |
393 | | uint64_t k = yc[0] + (uc[0] << 8) + |
394 | | (yc[1] << 16) + ((unsigned) vc[0] << 24); |
395 | | uint64_t l = yc[2] + (uc[1] << 8) + |
396 | | (yc[3] << 16) + ((unsigned) vc[1] << 24); |
397 | | *ldst++ = k + (l << 32); |
398 | | yc += 4; |
399 | | uc += 2; |
400 | | vc += 2; |
401 | | } |
402 | | |
403 | | #else |
404 | 0 | int *idst = (int32_t *)dst; |
405 | 0 | const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; |
406 | |
|
407 | 0 | for (i = 0; i < chromWidth; i++) { |
408 | | #if HAVE_BIGENDIAN |
409 | | *idst++ = (yc[0] << 24) + (uc[0] << 16) + |
410 | | (yc[1] << 8) + (vc[0] << 0); |
411 | | #else |
412 | 0 | *idst++ = yc[0] + (uc[0] << 8) + |
413 | 0 | (yc[1] << 16) + (vc[0] << 24); |
414 | 0 | #endif |
415 | 0 | yc += 2; |
416 | 0 | uc++; |
417 | 0 | vc++; |
418 | 0 | } |
419 | 0 | #endif |
420 | 0 | if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) { |
421 | 0 | usrc += chromStride; |
422 | 0 | vsrc += chromStride; |
423 | 0 | } |
424 | 0 | ysrc += lumStride; |
425 | 0 | dst += dstStride; |
426 | 0 | } |
427 | 0 | } |
428 | | |
429 | | /** |
430 | | * Height should be a multiple of 2 and width should be a multiple of 16. |
431 | | * (If this is a problem for anyone then tell me, and I will fix it.) |
432 | | */ |
433 | | static inline void yv12toyuy2_c(const uint8_t *ysrc, const uint8_t *usrc, |
434 | | const uint8_t *vsrc, uint8_t *dst, |
435 | | int width, int height, int lumStride, |
436 | | int chromStride, int dstStride) |
437 | 0 | { |
438 | | //FIXME interpolate chroma |
439 | 0 | yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride, |
440 | 0 | chromStride, dstStride, 2); |
441 | 0 | } |
442 | | |
443 | | static inline void yuvPlanartouyvy_c(const uint8_t *ysrc, const uint8_t *usrc, |
444 | | const uint8_t *vsrc, uint8_t *dst, |
445 | | int width, int height, |
446 | | int lumStride, int chromStride, |
447 | | int dstStride, int vertLumPerChroma) |
448 | 0 | { |
449 | 0 | int y, i; |
450 | 0 | const int chromWidth = width >> 1; |
451 | |
|
452 | 0 | for (y = 0; y < height; y++) { |
453 | | #if HAVE_FAST_64BIT |
454 | | uint64_t *ldst = (uint64_t *)dst; |
455 | | const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; |
456 | | for (i = 0; i < chromWidth; i += 2) { |
457 | | uint64_t k = uc[0] + (yc[0] << 8) + |
458 | | (vc[0] << 16) + ((unsigned) yc[1] << 24); |
459 | | uint64_t l = uc[1] + (yc[2] << 8) + |
460 | | (vc[1] << 16) + ((unsigned) yc[3] << 24); |
461 | | *ldst++ = k + (l << 32); |
462 | | yc += 4; |
463 | | uc += 2; |
464 | | vc += 2; |
465 | | } |
466 | | |
467 | | #else |
468 | 0 | int *idst = (int32_t *)dst; |
469 | 0 | const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; |
470 | |
|
471 | 0 | for (i = 0; i < chromWidth; i++) { |
472 | | #if HAVE_BIGENDIAN |
473 | | *idst++ = ((unsigned)uc[0] << 24) + (yc[0] << 16) + |
474 | | (vc[0] << 8) + (yc[1] << 0); |
475 | | #else |
476 | 0 | *idst++ = uc[0] + (yc[0] << 8) + |
477 | 0 | (vc[0] << 16) + ((unsigned)yc[1] << 24); |
478 | 0 | #endif |
479 | 0 | yc += 2; |
480 | 0 | uc++; |
481 | 0 | vc++; |
482 | 0 | } |
483 | 0 | #endif |
484 | 0 | if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) { |
485 | 0 | usrc += chromStride; |
486 | 0 | vsrc += chromStride; |
487 | 0 | } |
488 | 0 | ysrc += lumStride; |
489 | 0 | dst += dstStride; |
490 | 0 | } |
491 | 0 | } |
492 | | |
493 | | /** |
494 | | * Height should be a multiple of 2 and width should be a multiple of 16 |
495 | | * (If this is a problem for anyone then tell me, and I will fix it.) |
496 | | */ |
497 | | static inline void yv12touyvy_c(const uint8_t *ysrc, const uint8_t *usrc, |
498 | | const uint8_t *vsrc, uint8_t *dst, |
499 | | int width, int height, int lumStride, |
500 | | int chromStride, int dstStride) |
501 | 0 | { |
502 | | //FIXME interpolate chroma |
503 | 0 | yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride, |
504 | 0 | chromStride, dstStride, 2); |
505 | 0 | } |
506 | | |
507 | | /** |
508 | | * Width should be a multiple of 16. |
509 | | */ |
510 | | static inline void yuv422ptouyvy_c(const uint8_t *ysrc, const uint8_t *usrc, |
511 | | const uint8_t *vsrc, uint8_t *dst, |
512 | | int width, int height, int lumStride, |
513 | | int chromStride, int dstStride) |
514 | 0 | { |
515 | 0 | yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride, |
516 | 0 | chromStride, dstStride, 1); |
517 | 0 | } |
518 | | |
519 | | /** |
520 | | * Width should be a multiple of 16. |
521 | | */ |
522 | | static inline void yuv422ptoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc, |
523 | | const uint8_t *vsrc, uint8_t *dst, |
524 | | int width, int height, int lumStride, |
525 | | int chromStride, int dstStride) |
526 | 0 | { |
527 | 0 | yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride, |
528 | 0 | chromStride, dstStride, 1); |
529 | 0 | } |
530 | | |
531 | | static inline void planar2x_c(const uint8_t *src, uint8_t *dst, int srcWidth, |
532 | | int srcHeight, int srcStride, int dstStride) |
533 | 0 | { |
534 | 0 | int x, y; |
535 | |
|
536 | 0 | dst[0] = src[0]; |
537 | | |
538 | | // first line |
539 | 0 | for (x = 0; x < srcWidth - 1; x++) { |
540 | 0 | dst[2 * x + 1] = (3 * src[x] + src[x + 1]) >> 2; |
541 | 0 | dst[2 * x + 2] = (src[x] + 3 * src[x + 1]) >> 2; |
542 | 0 | } |
543 | 0 | dst[2 * srcWidth - 1] = src[srcWidth - 1]; |
544 | |
|
545 | 0 | dst += dstStride; |
546 | |
|
547 | 0 | for (y = 1; y < srcHeight; y++) { |
548 | 0 | const int mmxSize = 1; |
549 | |
|
550 | 0 | dst[0] = (src[0] * 3 + src[srcStride]) >> 2; |
551 | 0 | dst[dstStride] = (src[0] + 3 * src[srcStride]) >> 2; |
552 | |
|
553 | 0 | for (x = mmxSize - 1; x < srcWidth - 1; x++) { |
554 | 0 | dst[2 * x + 1] = (src[x + 0] * 3 + src[x + srcStride + 1]) >> 2; |
555 | 0 | dst[2 * x + dstStride + 2] = (src[x + 0] + 3 * src[x + srcStride + 1]) >> 2; |
556 | 0 | dst[2 * x + dstStride + 1] = (src[x + 1] + 3 * src[x + srcStride]) >> 2; |
557 | 0 | dst[2 * x + 2] = (src[x + 1] * 3 + src[x + srcStride]) >> 2; |
558 | 0 | } |
559 | 0 | dst[srcWidth * 2 - 1] = (src[srcWidth - 1] * 3 + src[srcWidth - 1 + srcStride]) >> 2; |
560 | 0 | dst[srcWidth * 2 - 1 + dstStride] = (src[srcWidth - 1] + 3 * src[srcWidth - 1 + srcStride]) >> 2; |
561 | |
|
562 | 0 | dst += dstStride * 2; |
563 | 0 | src += srcStride; |
564 | 0 | } |
565 | | |
566 | | // last line |
567 | 0 | dst[0] = src[0]; |
568 | |
|
569 | 0 | for (x = 0; x < srcWidth - 1; x++) { |
570 | 0 | dst[2 * x + 1] = (src[x] * 3 + src[x + 1]) >> 2; |
571 | 0 | dst[2 * x + 2] = (src[x] + 3 * src[x + 1]) >> 2; |
572 | 0 | } |
573 | 0 | dst[2 * srcWidth - 1] = src[srcWidth - 1]; |
574 | 0 | } |
575 | | |
576 | | /** |
577 | | * width should be a multiple of 2. |
578 | | * (If this is a problem for anyone then tell me, and I will fix it.) |
579 | | */ |
580 | | void ff_rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, |
581 | | uint8_t *vdst, int width, int height, int lumStride, |
582 | | int chromStride, int srcStride, const int32_t *rgb2yuv) |
583 | 0 | { |
584 | 0 | int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX]; |
585 | 0 | int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX]; |
586 | 0 | int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX]; |
587 | 0 | int y; |
588 | 0 | const int chromWidth = width >> 1; |
589 | 0 | const uint8_t *src1 = src; |
590 | 0 | const uint8_t *src2 = src1 + srcStride; |
591 | 0 | uint8_t *ydst1 = ydst; |
592 | 0 | uint8_t *ydst2 = ydst + lumStride; |
593 | |
|
594 | 0 | for (y = 0; y < height; y += 2) { |
595 | 0 | int i; |
596 | 0 | if (y + 1 == height) { |
597 | 0 | ydst2 = ydst1; |
598 | 0 | src2 = src1; |
599 | 0 | } |
600 | |
|
601 | 0 | for (i = 0; i < chromWidth; i++) { |
602 | 0 | unsigned int b11 = src1[6 * i + 0]; |
603 | 0 | unsigned int g11 = src1[6 * i + 1]; |
604 | 0 | unsigned int r11 = src1[6 * i + 2]; |
605 | 0 | unsigned int b12 = src1[6 * i + 3]; |
606 | 0 | unsigned int g12 = src1[6 * i + 4]; |
607 | 0 | unsigned int r12 = src1[6 * i + 5]; |
608 | 0 | unsigned int b21 = src2[6 * i + 0]; |
609 | 0 | unsigned int g21 = src2[6 * i + 1]; |
610 | 0 | unsigned int r21 = src2[6 * i + 2]; |
611 | 0 | unsigned int b22 = src2[6 * i + 3]; |
612 | 0 | unsigned int g22 = src2[6 * i + 4]; |
613 | 0 | unsigned int r22 = src2[6 * i + 5]; |
614 | |
|
615 | 0 | unsigned int Y11 = ((ry * r11 + gy * g11 + by * b11) >> RGB2YUV_SHIFT) + 16; |
616 | 0 | unsigned int Y12 = ((ry * r12 + gy * g12 + by * b12) >> RGB2YUV_SHIFT) + 16; |
617 | 0 | unsigned int Y21 = ((ry * r21 + gy * g21 + by * b21) >> RGB2YUV_SHIFT) + 16; |
618 | 0 | unsigned int Y22 = ((ry * r22 + gy * g22 + by * b22) >> RGB2YUV_SHIFT) + 16; |
619 | |
|
620 | 0 | unsigned int bx = (b11 + b12 + b21 + b22) >> 2; |
621 | 0 | unsigned int gx = (g11 + g12 + g21 + g22) >> 2; |
622 | 0 | unsigned int rx = (r11 + r12 + r21 + r22) >> 2; |
623 | |
|
624 | 0 | unsigned int U = ((ru * rx + gu * gx + bu * bx) >> RGB2YUV_SHIFT) + 128; |
625 | 0 | unsigned int V = ((rv * rx + gv * gx + bv * bx) >> RGB2YUV_SHIFT) + 128; |
626 | |
|
627 | 0 | ydst1[2 * i + 0] = Y11; |
628 | 0 | ydst1[2 * i + 1] = Y12; |
629 | 0 | ydst2[2 * i + 0] = Y21; |
630 | 0 | ydst2[2 * i + 1] = Y22; |
631 | 0 | udst[i] = U; |
632 | 0 | vdst[i] = V; |
633 | 0 | } |
634 | 0 | src1 += srcStride * 2; |
635 | 0 | src2 += srcStride * 2; |
636 | 0 | ydst1 += lumStride * 2; |
637 | 0 | ydst2 += lumStride * 2; |
638 | 0 | udst += chromStride; |
639 | 0 | vdst += chromStride; |
640 | 0 | } |
641 | 0 | } |
642 | | |
643 | | static void interleaveBytes_c(const uint8_t *src1, const uint8_t *src2, |
644 | | uint8_t *dest, int width, int height, |
645 | | int src1Stride, int src2Stride, int dstStride) |
646 | 0 | { |
647 | 0 | int h; |
648 | |
|
649 | 0 | for (h = 0; h < height; h++) { |
650 | 0 | int w; |
651 | 0 | for (w = 0; w < width; w++) { |
652 | 0 | dest[2 * w + 0] = src1[w]; |
653 | 0 | dest[2 * w + 1] = src2[w]; |
654 | 0 | } |
655 | 0 | dest += dstStride; |
656 | 0 | src1 += src1Stride; |
657 | 0 | src2 += src2Stride; |
658 | 0 | } |
659 | 0 | } |
660 | | |
661 | | static void deinterleaveBytes_c(const uint8_t *src, uint8_t *dst1, uint8_t *dst2, |
662 | | int width, int height, int srcStride, |
663 | | int dst1Stride, int dst2Stride) |
664 | 0 | { |
665 | 0 | int h; |
666 | |
|
667 | 0 | for (h = 0; h < height; h++) { |
668 | 0 | int w; |
669 | 0 | for (w = 0; w < width; w++) { |
670 | 0 | dst1[w] = src[2 * w + 0]; |
671 | 0 | dst2[w] = src[2 * w + 1]; |
672 | 0 | } |
673 | 0 | src += srcStride; |
674 | 0 | dst1 += dst1Stride; |
675 | 0 | dst2 += dst2Stride; |
676 | 0 | } |
677 | 0 | } |
678 | | |
679 | | static void extract_even_c(const uint8_t *src, uint8_t *dst, int count) |
680 | 0 | { |
681 | 0 | dst += count; |
682 | 0 | src += count * 2; |
683 | 0 | count = -count; |
684 | 0 | while (count < 0) { |
685 | 0 | dst[count] = src[2 * count]; |
686 | 0 | count++; |
687 | 0 | } |
688 | 0 | } |
689 | | |
690 | | static void extract_even2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, |
691 | | int count) |
692 | 0 | { |
693 | 0 | dst0 += count; |
694 | 0 | dst1 += count; |
695 | 0 | src += count * 4; |
696 | 0 | count = -count; |
697 | 0 | while (count < 0) { |
698 | 0 | dst0[count] = src[4 * count + 0]; |
699 | 0 | dst1[count] = src[4 * count + 2]; |
700 | 0 | count++; |
701 | 0 | } |
702 | 0 | } |
703 | | |
704 | | static void extract_even2avg_c(const uint8_t *src0, const uint8_t *src1, |
705 | | uint8_t *dst0, uint8_t *dst1, int count) |
706 | 0 | { |
707 | 0 | dst0 += count; |
708 | 0 | dst1 += count; |
709 | 0 | src0 += count * 4; |
710 | 0 | src1 += count * 4; |
711 | 0 | count = -count; |
712 | 0 | while (count < 0) { |
713 | 0 | dst0[count] = (src0[4 * count + 0] + src1[4 * count + 0]) >> 1; |
714 | 0 | dst1[count] = (src0[4 * count + 2] + src1[4 * count + 2]) >> 1; |
715 | 0 | count++; |
716 | 0 | } |
717 | 0 | } |
718 | | |
719 | | static void extract_odd2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, |
720 | | int count) |
721 | 0 | { |
722 | 0 | dst0 += count; |
723 | 0 | dst1 += count; |
724 | 0 | src += count * 4; |
725 | 0 | count = -count; |
726 | 0 | src++; |
727 | 0 | while (count < 0) { |
728 | 0 | dst0[count] = src[4 * count + 0]; |
729 | 0 | dst1[count] = src[4 * count + 2]; |
730 | 0 | count++; |
731 | 0 | } |
732 | 0 | } |
733 | | |
734 | | static void extract_odd2avg_c(const uint8_t *src0, const uint8_t *src1, |
735 | | uint8_t *dst0, uint8_t *dst1, int count) |
736 | 0 | { |
737 | 0 | dst0 += count; |
738 | 0 | dst1 += count; |
739 | 0 | src0 += count * 4; |
740 | 0 | src1 += count * 4; |
741 | 0 | count = -count; |
742 | 0 | src0++; |
743 | 0 | src1++; |
744 | 0 | while (count < 0) { |
745 | 0 | dst0[count] = (src0[4 * count + 0] + src1[4 * count + 0]) >> 1; |
746 | 0 | dst1[count] = (src0[4 * count + 2] + src1[4 * count + 2]) >> 1; |
747 | 0 | count++; |
748 | 0 | } |
749 | 0 | } |
750 | | |
751 | | static void yuyvtoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, |
752 | | const uint8_t *src, int width, int height, |
753 | | int lumStride, int chromStride, int srcStride) |
754 | 0 | { |
755 | 0 | int y; |
756 | 0 | const int chromWidth = AV_CEIL_RSHIFT(width, 1); |
757 | |
|
758 | 0 | for (y = 0; y < height; y++) { |
759 | 0 | extract_even_c(src, ydst, width); |
760 | 0 | if (y & 1) { |
761 | 0 | extract_odd2avg_c(src - srcStride, src, udst, vdst, chromWidth); |
762 | 0 | udst += chromStride; |
763 | 0 | vdst += chromStride; |
764 | 0 | } |
765 | |
|
766 | 0 | src += srcStride; |
767 | 0 | ydst += lumStride; |
768 | 0 | } |
769 | 0 | } |
770 | | |
771 | | static void yuyvtoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, |
772 | | const uint8_t *src, int width, int height, |
773 | | int lumStride, int chromStride, int srcStride) |
774 | 0 | { |
775 | 0 | int y; |
776 | 0 | const int chromWidth = AV_CEIL_RSHIFT(width, 1); |
777 | |
|
778 | 0 | for (y = 0; y < height; y++) { |
779 | 0 | extract_even_c(src, ydst, width); |
780 | 0 | extract_odd2_c(src, udst, vdst, chromWidth); |
781 | |
|
782 | 0 | src += srcStride; |
783 | 0 | ydst += lumStride; |
784 | 0 | udst += chromStride; |
785 | 0 | vdst += chromStride; |
786 | 0 | } |
787 | 0 | } |
788 | | |
789 | | static void uyvytoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, |
790 | | const uint8_t *src, int width, int height, |
791 | | int lumStride, int chromStride, int srcStride) |
792 | 0 | { |
793 | 0 | int y; |
794 | 0 | const int chromWidth = AV_CEIL_RSHIFT(width, 1); |
795 | |
|
796 | 0 | for (y = 0; y < height; y++) { |
797 | 0 | extract_even_c(src + 1, ydst, width); |
798 | 0 | if (y & 1) { |
799 | 0 | extract_even2avg_c(src - srcStride, src, udst, vdst, chromWidth); |
800 | 0 | udst += chromStride; |
801 | 0 | vdst += chromStride; |
802 | 0 | } |
803 | |
|
804 | 0 | src += srcStride; |
805 | 0 | ydst += lumStride; |
806 | 0 | } |
807 | 0 | } |
808 | | |
809 | | static void uyvytoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, |
810 | | const uint8_t *src, int width, int height, |
811 | | int lumStride, int chromStride, int srcStride) |
812 | 0 | { |
813 | 0 | int y; |
814 | 0 | const int chromWidth = AV_CEIL_RSHIFT(width, 1); |
815 | |
|
816 | 0 | for (y = 0; y < height; y++) { |
817 | 0 | extract_even_c(src + 1, ydst, width); |
818 | 0 | extract_even2_c(src, udst, vdst, chromWidth); |
819 | |
|
820 | 0 | src += srcStride; |
821 | 0 | ydst += lumStride; |
822 | 0 | udst += chromStride; |
823 | 0 | vdst += chromStride; |
824 | 0 | } |
825 | 0 | } |
826 | | |
827 | | static av_cold void rgb2rgb_init_c(void) |
828 | 0 | { |
829 | 0 | rgb15to16 = rgb15to16_c; |
830 | 0 | rgb15tobgr24 = rgb15tobgr24_c; |
831 | 0 | rgb15to32 = rgb15to32_c; |
832 | 0 | rgb16tobgr24 = rgb16tobgr24_c; |
833 | 0 | rgb16to32 = rgb16to32_c; |
834 | 0 | rgb16to15 = rgb16to15_c; |
835 | 0 | rgb24tobgr16 = rgb24tobgr16_c; |
836 | 0 | rgb24tobgr15 = rgb24tobgr15_c; |
837 | 0 | rgb24tobgr32 = rgb24tobgr32_c; |
838 | 0 | rgb32to16 = rgb32to16_c; |
839 | 0 | rgb32to15 = rgb32to15_c; |
840 | 0 | rgb32tobgr24 = rgb32tobgr24_c; |
841 | 0 | rgb24to15 = rgb24to15_c; |
842 | 0 | rgb24to16 = rgb24to16_c; |
843 | 0 | rgb24tobgr24 = rgb24tobgr24_c; |
844 | | #if HAVE_BIGENDIAN |
845 | | shuffle_bytes_0321 = shuffle_bytes_2103_c; |
846 | | shuffle_bytes_2103 = shuffle_bytes_0321_c; |
847 | | #else |
848 | 0 | shuffle_bytes_0321 = shuffle_bytes_0321_c; |
849 | 0 | shuffle_bytes_2103 = shuffle_bytes_2103_c; |
850 | 0 | #endif |
851 | 0 | shuffle_bytes_1230 = shuffle_bytes_1230_c; |
852 | 0 | shuffle_bytes_3012 = shuffle_bytes_3012_c; |
853 | 0 | shuffle_bytes_3210 = shuffle_bytes_3210_c; |
854 | 0 | shuffle_bytes_3102 = shuffle_bytes_3102_c; |
855 | 0 | shuffle_bytes_2013 = shuffle_bytes_2013_c; |
856 | 0 | shuffle_bytes_2130 = shuffle_bytes_2130_c; |
857 | 0 | shuffle_bytes_1203 = shuffle_bytes_1203_c; |
858 | 0 | rgb32tobgr16 = rgb32tobgr16_c; |
859 | 0 | rgb32tobgr15 = rgb32tobgr15_c; |
860 | 0 | yv12toyuy2 = yv12toyuy2_c; |
861 | 0 | yv12touyvy = yv12touyvy_c; |
862 | 0 | yuv422ptoyuy2 = yuv422ptoyuy2_c; |
863 | 0 | yuv422ptouyvy = yuv422ptouyvy_c; |
864 | 0 | planar2x = planar2x_c; |
865 | 0 | ff_rgb24toyv12 = ff_rgb24toyv12_c; |
866 | 0 | interleaveBytes = interleaveBytes_c; |
867 | 0 | deinterleaveBytes = deinterleaveBytes_c; |
868 | |
|
869 | 0 | uyvytoyuv420 = uyvytoyuv420_c; |
870 | 0 | uyvytoyuv422 = uyvytoyuv422_c; |
871 | 0 | yuyvtoyuv420 = yuyvtoyuv420_c; |
872 | 0 | yuyvtoyuv422 = yuyvtoyuv422_c; |
873 | 0 | } |