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