FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/rgb2rgb_template.c
Date: 2026-10-30 17:37:53
Exec Total Coverage
Lines: 261 487 53.6%
Functions: 26 46 56.5%
Branches: 61 112 54.5%

Line Branch Exec 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 133 static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst,
32 int src_size)
33 {
34 133 uint8_t *dest = dst;
35 133 const uint8_t *s = src;
36 133 const uint8_t *end = s + src_size;
37
38
2/2
✓ Branch 0 taken 918316 times.
✓ Branch 1 taken 133 times.
918449 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 918316 *dest++ = *s++;
48 918316 *dest++ = *s++;
49 918316 *dest++ = *s++;
50 918316 *dest++ = 255;
51 #endif
52 }
53 133 }
54
55 62 static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst,
56 int src_size)
57 {
58 62 uint8_t *dest = dst;
59 62 const uint8_t *s = src;
60 62 const uint8_t *end = s + src_size;
61
62
2/2
✓ Branch 0 taken 57161 times.
✓ Branch 1 taken 62 times.
57223 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 57161 *dest++ = *s++;
72 57161 *dest++ = *s++;
73 57161 *dest++ = *s++;
74 57161 s++;
75 #endif
76 }
77 62 }
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 {
87 ✗ register uint8_t *d = dst;
88 ✗ register const uint8_t *s = src;
89 ✗ register const uint8_t *end = s + src_size;
90 ✗ const uint8_t *mm_end = end - 3;
91
92 ✗ while (s < mm_end) {
93 ✗ register unsigned x = *((const uint32_t *)s);
94 ✗ *((uint32_t *)d) = (x & 0x7FFF7FFF) + (x & 0x7FE07FE0);
95 ✗ d += 4;
96 ✗ s += 4;
97 }
98 ✗ if (s < end) {
99 ✗ register unsigned short x = *((const uint16_t *)s);
100 ✗ *((uint16_t *)d) = (x & 0x7FFF) + (x & 0x7FE0);
101 }
102 ✗ }
103
104 ✗ static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, int src_size)
105 {
106 ✗ register uint8_t *d = dst;
107 ✗ register const uint8_t *s = src;
108 ✗ register const uint8_t *end = s + src_size;
109 ✗ const uint8_t *mm_end = end - 3;
110
111 ✗ while (s < mm_end) {
112 ✗ register uint32_t x = *((const uint32_t *)s);
113 ✗ *((uint32_t *)d) = ((x >> 1) & 0x7FE07FE0) | (x & 0x001F001F);
114 ✗ s += 4;
115 ✗ d += 4;
116 }
117 ✗ if (s < end) {
118 ✗ register uint16_t x = *((const uint16_t *)s);
119 ✗ *((uint16_t *)d) = ((x >> 1) & 0x7FE0) | (x & 0x001F);
120 }
121 ✗ }
122
123 ✗ static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, int src_size)
124 {
125 ✗ uint16_t *d = (uint16_t *)dst;
126 ✗ const uint8_t *s = src;
127 ✗ const uint8_t *end = s + src_size;
128
129 ✗ while (s < end) {
130 ✗ register int rgb = *(const uint32_t *)s;
131 ✗ s += 4;
132 ✗ *d++ = ((rgb & 0xFF) >> 3) +
133 ✗ ((rgb & 0xFC00) >> 5) +
134 ✗ ((rgb & 0xF80000) >> 8);
135 }
136 ✗ }
137
138 ✗ static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst,
139 int src_size)
140 {
141 ✗ uint16_t *d = (uint16_t *)dst;
142 ✗ const uint8_t *s = src;
143 ✗ const uint8_t *end = s + src_size;
144
145 ✗ while (s < end) {
146 ✗ register int rgb = *(const uint32_t *)s;
147 ✗ s += 4;
148 ✗ *d++ = ((rgb & 0xF8) << 8) +
149 ✗ ((rgb & 0xFC00) >> 5) +
150 ✗ ((rgb & 0xF80000) >> 19);
151 }
152 ✗ }
153
154 ✗ static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size)
155 {
156 ✗ uint16_t *d = (uint16_t *)dst;
157 ✗ const uint8_t *s = src;
158 ✗ const uint8_t *end = s + src_size;
159
160 ✗ while (s < end) {
161 ✗ register int rgb = *(const uint32_t *)s;
162 ✗ s += 4;
163 ✗ *d++ = ((rgb & 0xFF) >> 3) +
164 ✗ ((rgb & 0xF800) >> 6) +
165 ✗ ((rgb & 0xF80000) >> 9);
166 }
167 ✗ }
168
169 ✗ static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst,
170 int src_size)
171 {
172 ✗ uint16_t *d = (uint16_t *)dst;
173 ✗ const uint8_t *s = src;
174 ✗ const uint8_t *end = s + src_size;
175
176 ✗ while (s < end) {
177 ✗ register int rgb = *(const uint32_t *)s;
178 ✗ s += 4;
179 ✗ *d++ = ((rgb & 0xF8) << 7) +
180 ✗ ((rgb & 0xF800) >> 6) +
181 ✗ ((rgb & 0xF80000) >> 19);
182 }
183 ✗ }
184
185 ✗ static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst,
186 int src_size)
187 {
188 ✗ uint16_t *d = (uint16_t *)dst;
189 ✗ const uint8_t *s = src;
190 ✗ const uint8_t *end = s + src_size;
191
192 ✗ while (s < end) {
193 ✗ const int b = *s++;
194 ✗ const int g = *s++;
195 ✗ const int r = *s++;
196 ✗ *d++ = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
197 }
198 ✗ }
199
200 ✗ static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size)
201 {
202 ✗ uint16_t *d = (uint16_t *)dst;
203 ✗ const uint8_t *s = src;
204 ✗ const uint8_t *end = s + src_size;
205
206 ✗ while (s < end) {
207 ✗ const int r = *s++;
208 ✗ const int g = *s++;
209 ✗ const int b = *s++;
210 ✗ *d++ = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
211 }
212 ✗ }
213
214 ✗ static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst,
215 int src_size)
216 {
217 ✗ uint16_t *d = (uint16_t *)dst;
218 ✗ const uint8_t *s = src;
219 ✗ const uint8_t *end = s + src_size;
220
221 ✗ while (s < end) {
222 ✗ const int b = *s++;
223 ✗ const int g = *s++;
224 ✗ const int r = *s++;
225 ✗ *d++ = (b >> 3) | ((g & 0xF8) << 2) | ((r & 0xF8) << 7);
226 }
227 ✗ }
228
229 ✗ static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size)
230 {
231 ✗ uint16_t *d = (uint16_t *)dst;
232 ✗ const uint8_t *s = src;
233 ✗ const uint8_t *end = s + src_size;
234
235 ✗ while (s < end) {
236 ✗ const int r = *s++;
237 ✗ const int g = *s++;
238 ✗ const int b = *s++;
239 ✗ *d++ = (b >> 3) | ((g & 0xF8) << 2) | ((r & 0xF8) << 7);
240 }
241 ✗ }
242
243 19497 static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst,
244 int src_size)
245 {
246 19497 uint8_t *d = dst;
247 19497 const uint16_t *s = (const uint16_t *)src;
248 19497 const uint16_t *end = s + src_size / 2;
249
250
2/2
✓ Branch 0 taken 4808192 times.
✓ Branch 1 taken 19497 times.
4827689 while (s < end) {
251 4808192 register uint16_t bgr = *s++;
252 4808192 *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
253 4808192 *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
254 4808192 *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
255 }
256 19497 }
257
258 ✗ static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst,
259 int src_size)
260 {
261 ✗ uint8_t *d = (uint8_t *)dst;
262 ✗ const uint16_t *s = (const uint16_t *)src;
263 ✗ const uint16_t *end = s + src_size / 2;
264
265 ✗ while (s < end) {
266 ✗ register uint16_t bgr = *s++;
267 ✗ *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
268 ✗ *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
269 ✗ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
270 }
271 ✗ }
272
273 ✗ static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size)
274 {
275 ✗ uint8_t *d = dst;
276 ✗ const uint16_t *s = (const uint16_t *)src;
277 ✗ const uint16_t *end = s + src_size / 2;
278
279 ✗ while (s < end) {
280 ✗ 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 ✗ *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
288 ✗ *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
289 ✗ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
290 ✗ *d++ = 255;
291 #endif
292 }
293 ✗ }
294
295 ✗ static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size)
296 {
297 ✗ uint8_t *d = dst;
298 ✗ const uint16_t *s = (const uint16_t *)src;
299 ✗ const uint16_t *end = s + src_size / 2;
300
301 ✗ while (s < end) {
302 ✗ 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 ✗ *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
310 ✗ *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
311 ✗ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
312 ✗ *d++ = 255;
313 #endif
314 }
315 ✗ }
316
317 123 static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst,
318 int src_size)
319 {
320 123 int idx = 15 - src_size;
321 123 const uint8_t *s = src - idx;
322 123 uint8_t *d = dst - idx;
323
324
2/2
✓ Branch 0 taken 441999 times.
✓ Branch 1 taken 123 times.
442122 for (; idx < 15; idx += 4) {
325 441999 register unsigned v = *(const uint32_t *)&s[idx], g = v & 0xff00ff00;
326 441999 v &= 0xff00ff;
327 441999 *(uint32_t *)&d[idx] = (v >> 16) + g + (v << 16);
328 }
329 123 }
330
331 19 static inline void shuffle_bytes_0321_c(const uint8_t *src, uint8_t *dst,
332 int src_size)
333 {
334 19 int idx = 15 - src_size;
335 19 const uint8_t *s = src - idx;
336 19 uint8_t *d = dst - idx;
337
338
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 19 times.
234 for (; idx < 15; idx += 4) {
339 215 register unsigned v = *(const uint32_t *)&s[idx], g = v & 0x00ff00ff;
340 215 v &= 0xff00ff00;
341 215 *(uint32_t *)&d[idx] = (v >> 16) + g + (v << 16);
342 }
343 19 }
344
345 #define DEFINE_SHUFFLE_BYTES(name, a, b, c, d) \
346 static void shuffle_bytes_##name (const uint8_t *src, \
347 uint8_t *dst, int src_size) \
348 { \
349 int i; \
350 \
351 for (i = 0; i < src_size; i += 4) { \
352 dst[i + 0] = src[i + a]; \
353 dst[i + 1] = src[i + b]; \
354 dst[i + 2] = src[i + c]; \
355 dst[i + 3] = src[i + d]; \
356 } \
357 }
358
359
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 19 times.
234 DEFINE_SHUFFLE_BYTES(1230_c, 1, 2, 3, 0)
360
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 19 times.
234 DEFINE_SHUFFLE_BYTES(3012_c, 3, 0, 1, 2)
361
2/2
✓ Branch 0 taken 8985815 times.
✓ Branch 1 taken 253 times.
8986068 DEFINE_SHUFFLE_BYTES(3210_c, 3, 2, 1, 0)
362
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 19 times.
234 DEFINE_SHUFFLE_BYTES(3102_c, 3, 1, 0, 2)
363
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 19 times.
234 DEFINE_SHUFFLE_BYTES(2013_c, 2, 0, 1, 3)
364
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 19 times.
234 DEFINE_SHUFFLE_BYTES(2130_c, 2, 1, 3, 0)
365
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 19 times.
234 DEFINE_SHUFFLE_BYTES(1203_c, 1, 2, 0, 3)
366
367 889 static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
368 {
369 unsigned i;
370
371
2/2
✓ Branch 0 taken 8004537 times.
✓ Branch 1 taken 889 times.
8005426 for (i = 0; i < src_size; i += 3) {
372 8004537 register uint8_t x = src[i + 2];
373 8004537 dst[i + 1] = src[i + 1];
374 8004537 dst[i + 2] = src[i + 0];
375 8004537 dst[i + 0] = x;
376 }
377 889 }
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 {
385 int y, i;
386 ✗ const int chromWidth = width >> 1;
387
388 ✗ 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 & ~1); 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 ✗ ff_pack_yuv422_line(dst, ysrc, usrc, vsrc, chromWidth & ~1, chromWidth, 1);
403
404 #else
405 int *idst = (int32_t *)dst;
406 const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
407
408 for (i = 0; i < chromWidth; i++) {
409 #if HAVE_BIGENDIAN
410 *idst++ = ((unsigned)yc[0] << 24) + (uc[0] << 16) +
411 (yc[1] << 8) + (vc[0] << 0);
412 #else
413 *idst++ = yc[0] + (uc[0] << 8) +
414 (yc[1] << 16) + ((unsigned)vc[0] << 24);
415 #endif
416 yc += 2;
417 uc++;
418 vc++;
419 }
420 #endif
421 ✗ if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
422 ✗ usrc += chromStride;
423 ✗ vsrc += chromStride;
424 }
425 ✗ ysrc += lumStride;
426 ✗ dst += dstStride;
427 }
428 ✗ }
429
430 ✗ static inline void yv12toyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
431 const uint8_t *vsrc, uint8_t *dst,
432 int width, int height, int lumStride,
433 int chromStride, int dstStride)
434 {
435 //FIXME interpolate chroma
436 ✗ yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
437 chromStride, dstStride, 2);
438 ✗ }
439
440 ✗ static inline void yuvPlanartouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
441 const uint8_t *vsrc, uint8_t *dst,
442 int width, int height,
443 int lumStride, int chromStride,
444 int dstStride, int vertLumPerChroma)
445 {
446 int y, i;
447 ✗ const int chromWidth = width >> 1;
448
449 ✗ for (y = 0; y < height; y++) {
450 #if HAVE_FAST_64BIT
451 ✗ uint64_t *ldst = (uint64_t *)dst;
452 ✗ const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
453 ✗ for (i = 0; i < (chromWidth & ~1); i += 2) {
454 ✗ uint64_t k = uc[0] + (yc[0] << 8) +
455 ✗ (vc[0] << 16) + ((unsigned) yc[1] << 24);
456 ✗ uint64_t l = uc[1] + (yc[2] << 8) +
457 ✗ (vc[1] << 16) + ((unsigned) yc[3] << 24);
458 ✗ *ldst++ = k + (l << 32);
459 ✗ yc += 4;
460 ✗ uc += 2;
461 ✗ vc += 2;
462 }
463 ✗ ff_pack_yuv422_line(dst, ysrc, usrc, vsrc, chromWidth & ~1, chromWidth, 0);
464
465 #else
466 int *idst = (int32_t *)dst;
467 const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
468
469 for (i = 0; i < chromWidth; i++) {
470 #if HAVE_BIGENDIAN
471 *idst++ = ((unsigned)uc[0] << 24) + (yc[0] << 16) +
472 (vc[0] << 8) + (yc[1] << 0);
473 #else
474 *idst++ = uc[0] + (yc[0] << 8) +
475 (vc[0] << 16) + ((unsigned)yc[1] << 24);
476 #endif
477 yc += 2;
478 uc++;
479 vc++;
480 }
481 #endif
482 ✗ if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
483 ✗ usrc += chromStride;
484 ✗ vsrc += chromStride;
485 }
486 ✗ ysrc += lumStride;
487 ✗ dst += dstStride;
488 }
489 ✗ }
490
491 ✗ static inline void yv12touyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
492 const uint8_t *vsrc, uint8_t *dst,
493 int width, int height, int lumStride,
494 int chromStride, int dstStride)
495 {
496 //FIXME interpolate chroma
497 ✗ yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
498 chromStride, dstStride, 2);
499 ✗ }
500
501 ✗ static inline void yuv422ptouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
502 const uint8_t *vsrc, uint8_t *dst,
503 int width, int height, int lumStride,
504 int chromStride, int dstStride)
505 {
506 ✗ yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
507 chromStride, dstStride, 1);
508 ✗ }
509
510 ✗ static inline void yuv422ptoyuy2_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 {
515 ✗ yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
516 chromStride, dstStride, 1);
517 ✗ }
518
519 ✗ static inline void planar2x_c(const uint8_t *src, uint8_t *dst, int srcWidth,
520 int srcHeight, int srcStride, int dstStride)
521 {
522 int x, y;
523
524 ✗ dst[0] = src[0];
525
526 // first line
527 ✗ for (x = 0; x < srcWidth - 1; x++) {
528 ✗ dst[2 * x + 1] = (3 * src[x] + src[x + 1]) >> 2;
529 ✗ dst[2 * x + 2] = (src[x] + 3 * src[x + 1]) >> 2;
530 }
531 ✗ dst[2 * srcWidth - 1] = src[srcWidth - 1];
532
533 ✗ dst += dstStride;
534
535 ✗ for (y = 1; y < srcHeight; y++) {
536 ✗ const int mmxSize = 1;
537
538 ✗ dst[0] = (src[0] * 3 + src[srcStride]) >> 2;
539 ✗ dst[dstStride] = (src[0] + 3 * src[srcStride]) >> 2;
540
541 ✗ for (x = mmxSize - 1; x < srcWidth - 1; x++) {
542 ✗ dst[2 * x + 1] = (src[x + 0] * 3 + src[x + srcStride + 1]) >> 2;
543 ✗ dst[2 * x + dstStride + 2] = (src[x + 0] + 3 * src[x + srcStride + 1]) >> 2;
544 ✗ dst[2 * x + dstStride + 1] = (src[x + 1] + 3 * src[x + srcStride]) >> 2;
545 ✗ dst[2 * x + 2] = (src[x + 1] * 3 + src[x + srcStride]) >> 2;
546 }
547 ✗ dst[srcWidth * 2 - 1] = (src[srcWidth - 1] * 3 + src[srcWidth - 1 + srcStride]) >> 2;
548 ✗ dst[srcWidth * 2 - 1 + dstStride] = (src[srcWidth - 1] + 3 * src[srcWidth - 1 + srcStride]) >> 2;
549
550 ✗ dst += dstStride * 2;
551 ✗ src += srcStride;
552 }
553
554 // last line
555 ✗ dst[0] = src[0];
556
557 ✗ for (x = 0; x < srcWidth - 1; x++) {
558 ✗ dst[2 * x + 1] = (src[x] * 3 + src[x + 1]) >> 2;
559 ✗ dst[2 * x + 2] = (src[x] + 3 * src[x + 1]) >> 2;
560 }
561 ✗ dst[2 * srcWidth - 1] = src[srcWidth - 1];
562 ✗ }
563
564 /**
565 * width should be a multiple of 2.
566 * (If this is a problem for anyone then tell me, and I will fix it.)
567 */
568 15 void ff_rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
569 uint8_t *vdst, int width, int height, int lumStride,
570 int chromStride, int srcStride, const int32_t *rgb2yuv)
571 {
572 15 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
573 15 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
574 15 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
575 int y;
576 15 const int chromWidth = width >> 1;
577 15 const uint8_t *src1 = src;
578 15 const uint8_t *src2 = src1 + srcStride;
579 15 uint8_t *ydst1 = ydst;
580 15 uint8_t *ydst2 = ydst + lumStride;
581
582
2/2
✓ Branch 0 taken 426 times.
✓ Branch 1 taken 15 times.
441 for (y = 0; y < height; y += 2) {
583 int i;
584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 426 times.
426 if (y + 1 == height) {
585 ✗ ydst2 = ydst1;
586 ✗ src2 = src1;
587 }
588
589
2/2
✓ Branch 0 taken 25824 times.
✓ Branch 1 taken 426 times.
26250 for (i = 0; i < chromWidth; i++) {
590 25824 unsigned int b11 = src1[6 * i + 0];
591 25824 unsigned int g11 = src1[6 * i + 1];
592 25824 unsigned int r11 = src1[6 * i + 2];
593 25824 unsigned int b12 = src1[6 * i + 3];
594 25824 unsigned int g12 = src1[6 * i + 4];
595 25824 unsigned int r12 = src1[6 * i + 5];
596 25824 unsigned int b21 = src2[6 * i + 0];
597 25824 unsigned int g21 = src2[6 * i + 1];
598 25824 unsigned int r21 = src2[6 * i + 2];
599 25824 unsigned int b22 = src2[6 * i + 3];
600 25824 unsigned int g22 = src2[6 * i + 4];
601 25824 unsigned int r22 = src2[6 * i + 5];
602
603 25824 unsigned int Y11 = ((ry * r11 + gy * g11 + by * b11) >> RGB2YUV_SHIFT) + 16;
604 25824 unsigned int Y12 = ((ry * r12 + gy * g12 + by * b12) >> RGB2YUV_SHIFT) + 16;
605 25824 unsigned int Y21 = ((ry * r21 + gy * g21 + by * b21) >> RGB2YUV_SHIFT) + 16;
606 25824 unsigned int Y22 = ((ry * r22 + gy * g22 + by * b22) >> RGB2YUV_SHIFT) + 16;
607
608 25824 unsigned int bx = (b11 + b12 + b21 + b22) >> 2;
609 25824 unsigned int gx = (g11 + g12 + g21 + g22) >> 2;
610 25824 unsigned int rx = (r11 + r12 + r21 + r22) >> 2;
611
612 25824 unsigned int U = ((ru * rx + gu * gx + bu * bx) >> RGB2YUV_SHIFT) + 128;
613 25824 unsigned int V = ((rv * rx + gv * gx + bv * bx) >> RGB2YUV_SHIFT) + 128;
614
615 25824 ydst1[2 * i + 0] = Y11;
616 25824 ydst1[2 * i + 1] = Y12;
617 25824 ydst2[2 * i + 0] = Y21;
618 25824 ydst2[2 * i + 1] = Y22;
619 25824 udst[i] = U;
620 25824 vdst[i] = V;
621 }
622 426 src1 += srcStride * 2;
623 426 src2 += srcStride * 2;
624 426 ydst1 += lumStride * 2;
625 426 ydst2 += lumStride * 2;
626 426 udst += chromStride;
627 426 vdst += chromStride;
628 }
629 15 }
630
631 1505 static void interleaveBytes_c(const uint8_t *src1, const uint8_t *src2,
632 uint8_t *dest, int width, int height,
633 int src1Stride, int src2Stride, int dstStride)
634 {
635 int h;
636
637
2/2
✓ Branch 0 taken 43346 times.
✓ Branch 1 taken 1505 times.
44851 for (h = 0; h < height; h++) {
638 int w;
639
2/2
✓ Branch 0 taken 11600354 times.
✓ Branch 1 taken 43346 times.
11643700 for (w = 0; w < width; w++) {
640 11600354 dest[2 * w + 0] = src1[w];
641 11600354 dest[2 * w + 1] = src2[w];
642 }
643 43346 dest += dstStride;
644 43346 src1 += src1Stride;
645 43346 src2 += src2Stride;
646 }
647 1505 }
648
649 1422 static void deinterleaveBytes_c(const uint8_t *src, uint8_t *dst1, uint8_t *dst2,
650 int width, int height, int srcStride,
651 int dst1Stride, int dst2Stride)
652 {
653 int h;
654
655
2/2
✓ Branch 0 taken 32530 times.
✓ Branch 1 taken 1422 times.
33952 for (h = 0; h < height; h++) {
656 int w;
657
2/2
✓ Branch 0 taken 7981026 times.
✓ Branch 1 taken 32530 times.
8013556 for (w = 0; w < width; w++) {
658 7981026 dst1[w] = src[2 * w + 0];
659 7981026 dst2[w] = src[2 * w + 1];
660 }
661 32530 src += srcStride;
662 32530 dst1 += dst1Stride;
663 32530 dst2 += dst2Stride;
664 }
665 1422 }
666
667 5096 static void extract_even_c(const uint8_t *src, uint8_t *dst, int count)
668 {
669 5096 dst += count;
670 5096 src += count * 2;
671 5096 count = -count;
672
2/2
✓ Branch 0 taken 311596 times.
✓ Branch 1 taken 5096 times.
316692 while (count < 0) {
673 311596 dst[count] = src[2 * count];
674 311596 count++;
675 }
676 5096 }
677
678 1274 static void extract_even2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1,
679 int count)
680 {
681 1274 dst0 += count;
682 1274 dst1 += count;
683 1274 src += count * 4;
684 1274 count = -count;
685
2/2
✓ Branch 0 taken 39026 times.
✓ Branch 1 taken 1274 times.
40300 while (count < 0) {
686 39026 dst0[count] = src[4 * count + 0];
687 39026 dst1[count] = src[4 * count + 2];
688 39026 count++;
689 }
690 1274 }
691
692 625 static void extract_even2avg_c(const uint8_t *src0, const uint8_t *src1,
693 uint8_t *dst0, uint8_t *dst1, int count)
694 {
695 625 dst0 += count;
696 625 dst1 += count;
697 625 src0 += count * 4;
698 625 src1 += count * 4;
699 625 count = -count;
700
2/2
✓ Branch 0 taken 19252 times.
✓ Branch 1 taken 625 times.
19877 while (count < 0) {
701 19252 dst0[count] = (src0[4 * count + 0] + src1[4 * count + 0] + 1) >> 1;
702 19252 dst1[count] = (src0[4 * count + 2] + src1[4 * count + 2] + 1) >> 1;
703 19252 count++;
704 }
705 625 }
706
707 1274 static void extract_odd2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1,
708 int count)
709 {
710 1274 dst0 += count;
711 1274 dst1 += count;
712 1274 src += count * 4;
713 1274 count = -count;
714 1274 src++;
715
2/2
✓ Branch 0 taken 39026 times.
✓ Branch 1 taken 1274 times.
40300 while (count < 0) {
716 39026 dst0[count] = src[4 * count + 0];
717 39026 dst1[count] = src[4 * count + 2];
718 39026 count++;
719 }
720 1274 }
721
722 625 static void extract_odd2avg_c(const uint8_t *src0, const uint8_t *src1,
723 uint8_t *dst0, uint8_t *dst1, int count)
724 {
725 625 dst0 += count;
726 625 dst1 += count;
727 625 src0 += count * 4;
728 625 src1 += count * 4;
729 625 count = -count;
730 625 src0++;
731 625 src1++;
732
2/2
✓ Branch 0 taken 19252 times.
✓ Branch 1 taken 625 times.
19877 while (count < 0) {
733 19252 dst0[count] = (src0[4 * count + 0] + src1[4 * count + 0] + 1) >> 1;
734 19252 dst1[count] = (src0[4 * count + 2] + src1[4 * count + 2] + 1) >> 1;
735 19252 count++;
736 }
737 625 }
738
739 49 static void yuyvtoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
740 const uint8_t *src, int width, int height,
741 int lumStride, int chromStride, int srcStride)
742 {
743 int y;
744 49 const int chromWidth = AV_CEIL_RSHIFT(width, 1);
745
746
2/2
✓ Branch 0 taken 1274 times.
✓ Branch 1 taken 49 times.
1323 for (y = 0; y < height; y++) {
747 1274 extract_even_c(src, ydst, width);
748
2/2
✓ Branch 0 taken 625 times.
✓ Branch 1 taken 649 times.
1274 if (y & 1) {
749 625 extract_odd2avg_c(src - srcStride, src, udst, vdst, chromWidth);
750 625 udst += chromStride;
751 625 vdst += chromStride;
752 }
753
754 1274 src += srcStride;
755 1274 ydst += lumStride;
756 }
757 49 }
758
759 49 static void yuyvtoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
760 const uint8_t *src, int width, int height,
761 int lumStride, int chromStride, int srcStride)
762 {
763 int y;
764 49 const int chromWidth = AV_CEIL_RSHIFT(width, 1);
765
766
2/2
✓ Branch 0 taken 1274 times.
✓ Branch 1 taken 49 times.
1323 for (y = 0; y < height; y++) {
767 1274 extract_even_c(src, ydst, width);
768 1274 extract_odd2_c(src, udst, vdst, chromWidth);
769
770 1274 src += srcStride;
771 1274 ydst += lumStride;
772 1274 udst += chromStride;
773 1274 vdst += chromStride;
774 }
775 49 }
776
777 49 static void uyvytoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
778 const uint8_t *src, int width, int height,
779 int lumStride, int chromStride, int srcStride)
780 {
781 int y;
782 49 const int chromWidth = AV_CEIL_RSHIFT(width, 1);
783
784
2/2
✓ Branch 0 taken 1274 times.
✓ Branch 1 taken 49 times.
1323 for (y = 0; y < height; y++) {
785 1274 extract_even_c(src + 1, ydst, width);
786
2/2
✓ Branch 0 taken 625 times.
✓ Branch 1 taken 649 times.
1274 if (y & 1) {
787 625 extract_even2avg_c(src - srcStride, src, udst, vdst, chromWidth);
788 625 udst += chromStride;
789 625 vdst += chromStride;
790 }
791
792 1274 src += srcStride;
793 1274 ydst += lumStride;
794 }
795 49 }
796
797 49 static void uyvytoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
798 const uint8_t *src, int width, int height,
799 int lumStride, int chromStride, int srcStride)
800 {
801 int y;
802 49 const int chromWidth = AV_CEIL_RSHIFT(width, 1);
803
804
2/2
✓ Branch 0 taken 1274 times.
✓ Branch 1 taken 49 times.
1323 for (y = 0; y < height; y++) {
805 1274 extract_even_c(src + 1, ydst, width);
806 1274 extract_even2_c(src, udst, vdst, chromWidth);
807
808 1274 src += srcStride;
809 1274 ydst += lumStride;
810 1274 udst += chromStride;
811 1274 vdst += chromStride;
812 }
813 49 }
814
815 5221 static av_cold void rgb2rgb_init_c(void)
816 {
817 5221 rgb15to16 = rgb15to16_c;
818 5221 rgb15tobgr24 = rgb15tobgr24_c;
819 5221 rgb15to32 = rgb15to32_c;
820 5221 rgb16tobgr24 = rgb16tobgr24_c;
821 5221 rgb16to32 = rgb16to32_c;
822 5221 rgb16to15 = rgb16to15_c;
823 5221 rgb24tobgr16 = rgb24tobgr16_c;
824 5221 rgb24tobgr15 = rgb24tobgr15_c;
825 5221 rgb24tobgr32 = rgb24tobgr32_c;
826 5221 rgb32to16 = rgb32to16_c;
827 5221 rgb32to15 = rgb32to15_c;
828 5221 rgb32tobgr24 = rgb32tobgr24_c;
829 5221 rgb24to15 = rgb24to15_c;
830 5221 rgb24to16 = rgb24to16_c;
831 5221 rgb24tobgr24 = rgb24tobgr24_c;
832 #if HAVE_BIGENDIAN
833 shuffle_bytes_0321 = shuffle_bytes_2103_c;
834 shuffle_bytes_2103 = shuffle_bytes_0321_c;
835 #else
836 5221 shuffle_bytes_0321 = shuffle_bytes_0321_c;
837 5221 shuffle_bytes_2103 = shuffle_bytes_2103_c;
838 #endif
839 5221 shuffle_bytes_1230 = shuffle_bytes_1230_c;
840 5221 shuffle_bytes_3012 = shuffle_bytes_3012_c;
841 5221 shuffle_bytes_3210 = shuffle_bytes_3210_c;
842 5221 shuffle_bytes_3102 = shuffle_bytes_3102_c;
843 5221 shuffle_bytes_2013 = shuffle_bytes_2013_c;
844 5221 shuffle_bytes_2130 = shuffle_bytes_2130_c;
845 5221 shuffle_bytes_1203 = shuffle_bytes_1203_c;
846 5221 rgb32tobgr16 = rgb32tobgr16_c;
847 5221 rgb32tobgr15 = rgb32tobgr15_c;
848 5221 yv12toyuy2 = yv12toyuy2_c;
849 5221 yv12touyvy = yv12touyvy_c;
850 5221 yuv422ptoyuy2 = yuv422ptoyuy2_c;
851 5221 yuv422ptouyvy = yuv422ptouyvy_c;
852 5221 planar2x = planar2x_c;
853 5221 ff_rgb24toyv12 = ff_rgb24toyv12_c;
854 5221 interleaveBytes = interleaveBytes_c;
855 5221 deinterleaveBytes = deinterleaveBytes_c;
856
857 5221 uyvytoyuv420 = uyvytoyuv420_c;
858 5221 uyvytoyuv422 = uyvytoyuv422_c;
859 5221 yuyvtoyuv420 = yuyvtoyuv420_c;
860 5221 yuyvtoyuv422 = yuyvtoyuv422_c;
861 5221 }
862