36 #include "libavutil/avconfig.h"
40 { 0, 1, 0, 1, 0, 1, 0, 1,},
41 { 1, 0, 1, 0, 1, 0, 1, 0,},
42 { 0, 1, 0, 1, 0, 1, 0, 1,},
43 { 1, 0, 1, 0, 1, 0, 1, 0,},
44 { 0, 1, 0, 1, 0, 1, 0, 1,},
45 { 1, 0, 1, 0, 1, 0, 1, 0,},
46 { 0, 1, 0, 1, 0, 1, 0, 1,},
47 { 1, 0, 1, 0, 1, 0, 1, 0,},
49 { 1, 2, 1, 2, 1, 2, 1, 2,},
50 { 3, 0, 3, 0, 3, 0, 3, 0,},
51 { 1, 2, 1, 2, 1, 2, 1, 2,},
52 { 3, 0, 3, 0, 3, 0, 3, 0,},
53 { 1, 2, 1, 2, 1, 2, 1, 2,},
54 { 3, 0, 3, 0, 3, 0, 3, 0,},
55 { 1, 2, 1, 2, 1, 2, 1, 2,},
56 { 3, 0, 3, 0, 3, 0, 3, 0,},
58 { 2, 4, 3, 5, 2, 4, 3, 5,},
59 { 6, 0, 7, 1, 6, 0, 7, 1,},
60 { 3, 5, 2, 4, 3, 5, 2, 4,},
61 { 7, 1, 6, 0, 7, 1, 6, 0,},
62 { 2, 4, 3, 5, 2, 4, 3, 5,},
63 { 6, 0, 7, 1, 6, 0, 7, 1,},
64 { 3, 5, 2, 4, 3, 5, 2, 4,},
65 { 7, 1, 6, 0, 7, 1, 6, 0,},
67 { 4, 8, 7, 11, 4, 8, 7, 11,},
68 { 12, 0, 15, 3, 12, 0, 15, 3,},
69 { 6, 10, 5, 9, 6, 10, 5, 9,},
70 { 14, 2, 13, 1, 14, 2, 13, 1,},
71 { 4, 8, 7, 11, 4, 8, 7, 11,},
72 { 12, 0, 15, 3, 12, 0, 15, 3,},
73 { 6, 10, 5, 9, 6, 10, 5, 9,},
74 { 14, 2, 13, 1, 14, 2, 13, 1,},
76 { 9, 17, 15, 23, 8, 16, 14, 22,},
77 { 25, 1, 31, 7, 24, 0, 30, 6,},
78 { 13, 21, 11, 19, 12, 20, 10, 18,},
79 { 29, 5, 27, 3, 28, 4, 26, 2,},
80 { 8, 16, 14, 22, 9, 17, 15, 23,},
81 { 24, 0, 30, 6, 25, 1, 31, 7,},
82 { 12, 20, 10, 18, 13, 21, 11, 19,},
83 { 28, 4, 26, 2, 29, 5, 27, 3,},
85 { 18, 34, 30, 46, 17, 33, 29, 45,},
86 { 50, 2, 62, 14, 49, 1, 61, 13,},
87 { 26, 42, 22, 38, 25, 41, 21, 37,},
88 { 58, 10, 54, 6, 57, 9, 53, 5,},
89 { 16, 32, 28, 44, 19, 35, 31, 47,},
90 { 48, 0, 60, 12, 51, 3, 63, 15,},
91 { 24, 40, 20, 36, 27, 43, 23, 39,},
92 { 56, 8, 52, 4, 59, 11, 55, 7,},
94 { 18, 34, 30, 46, 17, 33, 29, 45,},
95 { 50, 2, 62, 14, 49, 1, 61, 13,},
96 { 26, 42, 22, 38, 25, 41, 21, 37,},
97 { 58, 10, 54, 6, 57, 9, 53, 5,},
98 { 16, 32, 28, 44, 19, 35, 31, 47,},
99 { 48, 0, 60, 12, 51, 3, 63, 15,},
100 { 24, 40, 20, 36, 27, 43, 23, 39,},
101 { 56, 8, 52, 4, 59, 11, 55, 7,},
103 { 36, 68, 60, 92, 34, 66, 58, 90,},
104 { 100, 4,124, 28, 98, 2,122, 26,},
105 { 52, 84, 44, 76, 50, 82, 42, 74,},
106 { 116, 20,108, 12,114, 18,106, 10,},
107 { 32, 64, 56, 88, 38, 70, 62, 94,},
108 { 96, 0,120, 24,102, 6,126, 30,},
109 { 48, 80, 40, 72, 54, 86, 46, 78,},
110 { 112, 16,104, 8,118, 22,110, 14,},
129 dst += dstStride * srcSliceY;
130 if (dstStride == srcStride && srcStride > 0) {
143 int srcStride[],
int srcSliceY,
147 uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2;
150 dstParam[0], dstStride[0]);
154 srcStride[1], srcStride[2], dstStride[1]);
157 srcStride[2], srcStride[1], dstStride[1]);
163 int srcStride[],
int srcSliceY,
167 uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
168 uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
171 dstParam[0], dstStride[0]);
175 srcStride[1], dstStride[1], dstStride[2]);
178 srcStride[1], dstStride[2], dstStride[1]);
184 int srcStride[],
int srcSliceY,
188 uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY;
191 dstParam[0], dstStride[0]);
195 srcStride[1], srcStride[2], dstStride[1]);
198 srcStride[2], srcStride[1], dstStride[1]);
204 int srcStride[],
int srcSliceY,
208 uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY;
209 uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY;
212 dstParam[0], dstStride[0]);
216 srcStride[1], dstStride[1], dstStride[2]);
219 srcStride[1], dstStride[2], dstStride[1]);
225 int srcStride[],
int srcSliceY,
231 const uint16_t **
src = (
const uint16_t**)src8;
232 uint16_t *
dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
233 uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
237 const int shift[3] = {
246 av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
247 dstStride[0] % 2 || dstStride[1] % 2));
250 uint16_t *tdstY =
dstY;
251 const uint16_t *tsrc0 =
src[0];
252 for (x =
c->srcW; x > 0; x--) {
253 *tdstY++ = *tsrc0++ <<
shift[0];
255 src[0] += srcStride[0] / 2;
256 dstY += dstStride[0] / 2;
259 uint16_t *tdstUV = dstUV;
260 const uint16_t *tsrc1 =
src[1];
261 const uint16_t *tsrc2 =
src[2];
262 for (x =
c->srcW / 2; x > 0; x--) {
263 *tdstUV++ = *tsrc1++ <<
shift[1];
264 *tdstUV++ = *tsrc2++ <<
shift[2];
266 src[1] += srcStride[1] / 2;
267 src[2] += srcStride[2] / 2;
268 dstUV += dstStride[1] / 2;
275 #if AV_HAVE_BIGENDIAN
276 #define output_pixel(p, v) do { \
277 uint16_t *pp = (p); \
281 #define output_pixel(p, v) (*p) = (v)
285 int srcStride[],
int srcSliceY,
289 uint16_t *
dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
290 uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
293 av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
296 uint16_t *tdstY =
dstY;
298 for (x =
c->srcW; x > 0; x--) {
302 src[0] += srcStride[0];
303 dstY += dstStride[0] / 2;
306 uint16_t *tdstUV = dstUV;
309 for (x =
c->srcW / 2; x > 0; x--) {
315 src[1] += srcStride[1];
316 src[2] += srcStride[2];
317 dstUV += dstStride[1] / 2;
327 int srcStride[],
int srcSliceY,
int srcSliceH,
328 uint8_t *dstParam[],
int dstStride[])
330 uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
333 srcStride[1], dstStride[0]);
339 int srcStride[],
int srcSliceY,
int srcSliceH,
340 uint8_t *dstParam[],
int dstStride[])
342 uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
345 srcStride[1], dstStride[0]);
351 int srcStride[],
int srcSliceY,
int srcSliceH,
352 uint8_t *dstParam[],
int dstStride[])
354 uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
357 srcStride[1], dstStride[0]);
363 int srcStride[],
int srcSliceY,
int srcSliceH,
364 uint8_t *dstParam[],
int dstStride[])
366 uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
369 srcStride[1], dstStride[0]);
375 int srcStride[],
int srcSliceY,
int srcSliceH,
376 uint8_t *dstParam[],
int dstStride[])
378 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
379 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
380 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
383 dstStride[1], srcStride[0]);
392 int srcStride[],
int srcSliceY,
int srcSliceH,
393 uint8_t *dstParam[],
int dstStride[])
395 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
396 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
397 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
400 dstStride[1], srcStride[0]);
406 int srcStride[],
int srcSliceY,
int srcSliceH,
407 uint8_t *dstParam[],
int dstStride[])
409 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
410 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
411 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
414 dstStride[1], srcStride[0]);
423 int srcStride[],
int srcSliceY,
int srcSliceH,
424 uint8_t *dstParam[],
int dstStride[])
426 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
427 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
428 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
431 dstStride[1], srcStride[0]);
440 for (
i = 0;
i < num_pixels;
i++)
441 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] | (
src[(
i << 1) + 1] << 24);
449 for (
i = 0;
i < num_pixels;
i++)
450 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] |
src[(
i << 1) + 1];
458 for (
i = 0;
i < num_pixels;
i++) {
460 dst[0] = palette[
src[
i << 1] * 4 + 0];
461 dst[1] = palette[
src[
i << 1] * 4 + 1];
462 dst[2] = palette[
src[
i << 1] * 4 + 2];
468 int srcStride[],
int srcSliceY,
int srcSliceH,
469 uint8_t *dst[],
int dstStride[])
473 for (p = 0; p < 4; p++) {
474 int srcstr = srcStride[p] / 2;
475 int dststr = dstStride[p] / 2;
476 uint16_t *dstPtr = (uint16_t *) dst[p];
477 const uint16_t *srcPtr = (
const uint16_t *)
src[p];
479 if(!dstPtr || !srcPtr)
481 dstPtr += (srcSliceY >>
c->chrDstVSubSample) * dststr;
483 for (j = 0; j < min_stride; j++) {
495 int srcStride[],
int srcSliceY,
int srcSliceH,
496 uint8_t *dst[],
int dstStride[])
500 for (p = 0; p < 4; p++) {
501 int srcstr = srcStride[p] / 4;
502 int dststr = dstStride[p] / 4;
503 uint32_t *dstPtr = (uint32_t *) dst[p];
504 const uint32_t *srcPtr = (
const uint32_t *)
src[p];
506 if(!dstPtr || !srcPtr)
508 dstPtr += (srcSliceY >>
c->chrDstVSubSample) * dststr;
510 for (j = 0; j < min_stride; j++) {
531 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
560 srcPtr += srcStride[0];
561 dstPtr += dstStride[0];
569 uint16_t *dst[],
int dstStride[],
int srcSliceH,
570 int src_alpha,
int swap,
int shift,
int width)
573 int dst_alpha = dst[3] !=
NULL;
575 uint16_t *src_line = (uint16_t *)(
src + srcStride *
h);
578 if (src_alpha && dst_alpha) {
579 for (x = 0; x <
width; x++) {
585 }
else if (dst_alpha) {
586 for (x = 0; x <
width; x++) {
592 }
else if (src_alpha) {
593 for (x = 0; x <
width; x++) {
600 for (x = 0; x <
width; x++) {
608 if (src_alpha && dst_alpha) {
609 for (x = 0; x <
width; x++) {
615 }
else if (dst_alpha) {
616 for (x = 0; x <
width; x++) {
622 }
else if (src_alpha) {
623 for (x = 0; x <
width; x++) {
630 for (x = 0; x <
width; x++) {
638 if (src_alpha && dst_alpha) {
639 for (x = 0; x <
width; x++) {
645 }
else if (dst_alpha) {
646 for (x = 0; x <
width; x++) {
652 }
else if (src_alpha) {
653 for (x = 0; x <
width; x++) {
660 for (x = 0; x <
width; x++) {
668 if (src_alpha && dst_alpha) {
669 for (x = 0; x <
width; x++) {
670 dst[0][x] = *src_line++ >>
shift;
671 dst[1][x] = *src_line++ >>
shift;
672 dst[2][x] = *src_line++ >>
shift;
673 dst[3][x] = *src_line++ >>
shift;
675 }
else if (dst_alpha) {
676 for (x = 0; x <
width; x++) {
677 dst[0][x] = *src_line++ >>
shift;
678 dst[1][x] = *src_line++ >>
shift;
679 dst[2][x] = *src_line++ >>
shift;
682 }
else if (src_alpha) {
683 for (x = 0; x <
width; x++) {
684 dst[0][x] = *src_line++ >>
shift;
685 dst[1][x] = *src_line++ >>
shift;
686 dst[2][x] = *src_line++ >>
shift;
690 for (x = 0; x <
width; x++) {
691 dst[0][x] = *src_line++ >>
shift;
692 dst[1][x] = *src_line++ >>
shift;
693 dst[2][x] = *src_line++ >>
shift;
697 for (
i = 0;
i < 4;
i++)
698 dst[
i] += dstStride[
i] >> 1;
703 int srcStride[],
int srcSliceY,
int srcSliceH,
704 uint8_t *dst[],
int dstStride[])
706 uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
707 uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
708 int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
709 int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
727 src_format->
name, dst_format->
name);
732 dst2013[
i] += stride2013[
i] * srcSliceY / 2;
733 dst1023[
i] += stride1023[
i] * srcSliceY / 2;
736 switch (
c->srcFormat) {
755 "unsupported conversion to planar RGB %s -> %s\n",
756 src_format->
name, dst_format->
name);
767 int src_alpha =
src[3] !=
NULL;
768 int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
770 uint16_t *dest = (uint16_t *)(dst + dstStride *
h);
775 if (
alpha && !src_alpha) {
776 for (x = 0; x <
width; x++) {
778 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
780 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
782 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
785 }
else if (
alpha && src_alpha) {
786 for (x = 0; x <
width; x++) {
788 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
790 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
792 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
794 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
797 for (x = 0; x <
width; x++) {
799 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
801 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
803 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
808 if (
alpha && !src_alpha) {
809 for (x = 0; x <
width; x++) {
815 }
else if (
alpha && src_alpha) {
816 for (x = 0; x <
width; x++) {
823 for (x = 0; x <
width; x++) {
831 if (
alpha && !src_alpha) {
832 for (x = 0; x <
width; x++) {
838 }
else if (
alpha && src_alpha) {
839 for (x = 0; x <
width; x++) {
846 for (x = 0; x <
width; x++) {
854 if (
alpha && !src_alpha) {
855 for (x = 0; x <
width; x++) {
856 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
857 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
858 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
861 }
else if (
alpha && src_alpha) {
862 for (x = 0; x <
width; x++) {
863 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
864 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
865 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
866 *dest++ =
src[3][x] << scale_high |
src[3][x] >> scale_low;
869 for (x = 0; x <
width; x++) {
870 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
871 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
872 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
876 for (
i = 0;
i < 3 + src_alpha;
i++)
877 src[
i] += srcStride[
i] >> 1;
882 int srcStride[],
int srcSliceY,
int srcSliceH,
883 uint8_t *dst[],
int dstStride[])
885 const uint16_t *src102[] = { (uint16_t *)
src[1], (uint16_t *)
src[0], (uint16_t *)
src[2], (uint16_t *)
src[3] };
886 const uint16_t *src201[] = { (uint16_t *)
src[2], (uint16_t *)
src[0], (uint16_t *)
src[1], (uint16_t *)
src[3] };
887 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
888 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
891 int bits_per_sample = src_format->
comp[0].
depth;
902 bits_per_sample <= 8) {
904 src_format->
name, dst_format->
name);
907 switch (
c->dstFormat) {
911 dst[0] + srcSliceY * dstStride[0], dstStride[0],
912 srcSliceH, 0, swap, bits_per_sample,
c->srcW);
917 dst[0] + srcSliceY * dstStride[0], dstStride[0],
918 srcSliceH, 0, swap, bits_per_sample,
c->srcW);
923 dst[0] + srcSliceY * dstStride[0], dstStride[0],
924 srcSliceH, 1, swap, bits_per_sample,
c->srcW);
929 dst[0] + srcSliceY * dstStride[0], dstStride[0],
930 srcSliceH, 1, swap, bits_per_sample,
c->srcW);
934 "unsupported planar RGB conversion %s -> %s\n",
935 src_format->
name, dst_format->
name);
947 uint8_t *dest = dst + dstStride *
h;
948 for (x = 0; x <
width; x++) {
954 for (
i = 0;
i < 3;
i++)
955 src[
i] += srcStride[
i];
961 int alpha_first,
int width)
965 uint8_t *dest = dst + dstStride *
h;
968 for (x = 0; x <
width; x++) {
975 for (x = 0; x <
width; x++) {
983 for (
i = 0;
i < 3;
i++)
984 src[
i] += srcStride[
i];
990 int alpha_first,
int width)
994 uint8_t *dest = dst + dstStride *
h;
997 for (x = 0; x <
width; x++) {
1000 *dest++ =
src[1][x];
1001 *dest++ =
src[2][x];
1004 for (x = 0; x <
width; x++) {
1005 *dest++ =
src[0][x];
1006 *dest++ =
src[1][x];
1007 *dest++ =
src[2][x];
1008 *dest++ =
src[3][x];
1012 for (
i = 0;
i < 4;
i++)
1013 src[
i] += srcStride[
i];
1018 int srcStride[],
int srcSliceY,
int srcSliceH,
1019 uint8_t *dst[],
int dstStride[])
1021 int alpha_first = 0;
1024 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
1025 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1034 switch (
c->dstFormat) {
1037 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1043 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1051 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1059 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1065 "unsupported planar RGB conversion %s -> %s\n",
1074 int srcStride[],
int srcSliceY,
int srcSliceH,
1075 uint8_t *dst[],
int dstStride[])
1077 int alpha_first = 0;
1080 int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
1081 int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
1090 switch (
c->dstFormat) {
1093 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1099 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1107 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1115 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1121 "unsupported planar RGB conversion %s -> %s\n",
1132 uint8_t *dst[],
int dstStride[])
1135 dst[0], dstStride[0]);
1137 dst[1], dstStride[1]);
1139 dst[2], dstStride[2]);
1148 int alpha_first,
int inc_size,
int width)
1161 for (x = 0; x <
width; x++) {
1162 dest[0][x] =
src[0];
1163 dest[1][x] =
src[1];
1164 dest[2][x] =
src[2];
1168 src += srcStride -
width * inc_size;
1169 dest[0] += dstStride[0];
1170 dest[1] += dstStride[1];
1171 dest[2] += dstStride[2];
1176 int srcStride[],
int srcSliceY,
int srcSliceH,
1177 uint8_t *dst[],
int dstStride[])
1179 int alpha_first = 0;
1180 int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1181 int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1182 uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
1183 dst[0] + srcSliceY * dstStride[0],
1184 dst[2] + srcSliceY * dstStride[2] };
1185 uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
1186 dst[0] + srcSliceY * dstStride[0],
1187 dst[1] + srcSliceY * dstStride[1] };
1189 switch (
c->srcFormat) {
1192 stride201,
srcSliceH, alpha_first, 3,
c->srcW);
1196 stride102,
srcSliceH, alpha_first, 3,
c->srcW);
1202 stride201,
srcSliceH, alpha_first, 4,
c->srcW);
1208 stride102,
srcSliceH, alpha_first, 4,
c->srcW);
1212 "unsupported planar RGB conversion %s -> %s\n",
1222 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1227 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1232 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1237 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1242 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1247 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1252 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1257 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1262 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1267 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1272 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1277 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1283 uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1289 switch(
c->srcFormat) {
1290 #define CASE(pixfmt, prefix) \
1291 case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1292 interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1312 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1313 srcPtr += 2 * srcStride[0];
1314 dstPtr += 2 * dstStride[0];
1317 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1318 srcPtr += 2 * srcStride[0];
1319 dstPtr += 2 * dstStride[0];
1323 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->srcW);
1325 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1334 uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
1335 uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
1340 switch(
c->srcFormat) {
1341 #define CASE(pixfmt, prefix) \
1342 case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1343 interpolate = bayer_##prefix##_to_yv12_interpolate; \
1363 copy(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1364 srcPtr += 2 * srcStride[0];
1365 dstY += 2 * dstStride[0];
1366 dstU += dstStride[1];
1367 dstV += dstStride[1];
1370 interpolate(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1371 srcPtr += 2 * srcStride[0];
1372 dstY += 2 * dstStride[0];
1373 dstU += dstStride[1];
1374 dstV += dstStride[1];
1378 copy(srcPtr, -srcStride[0],
dstY, dstU, dstV, -dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1380 copy(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1384 #define isRGBA32(x) ( \
1385 (x) == AV_PIX_FMT_ARGB \
1386 || (x) == AV_PIX_FMT_RGBA \
1387 || (x) == AV_PIX_FMT_BGRA \
1388 || (x) == AV_PIX_FMT_ABGR \
1391 #define isRGBA64(x) ( \
1392 (x) == AV_PIX_FMT_RGBA64LE \
1393 || (x) == AV_PIX_FMT_RGBA64BE \
1394 || (x) == AV_PIX_FMT_BGRA64LE \
1395 || (x) == AV_PIX_FMT_BGRA64BE \
1398 #define isRGB48(x) ( \
1399 (x) == AV_PIX_FMT_RGB48LE \
1400 || (x) == AV_PIX_FMT_RGB48BE \
1401 || (x) == AV_PIX_FMT_BGR48LE \
1402 || (x) == AV_PIX_FMT_BGR48BE \
1411 const int srcId =
c->srcFormatBpp;
1412 const int dstId =
c->dstFormatBpp;
1415 #define IS_NOT_NE(bpp, desc) \
1416 (((bpp + 7) >> 3) == 2 && \
1417 (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1419 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1439 else if (
CONV_IS(RGB48LE, BGR48BE)
1444 if (
CONV_IS(RGB48LE, BGRA64LE)
1448 else if (
CONV_IS(RGB48LE, BGRA64BE)
1452 if (
CONV_IS(RGB48LE, RGBA64LE)
1456 else if (
CONV_IS(RGB48LE, RGBA64BE)
1461 if (
CONV_IS(RGBA64LE, BGR48LE)
1465 else if (
CONV_IS(RGBA64LE, BGR48BE)
1469 else if (
CONV_IS(RGBA64LE, RGB48LE)
1473 else if (
CONV_IS(RGBA64LE, RGB48BE)
1481 switch (srcId | (dstId << 16)) {
1498 switch (srcId | (dstId << 16)) {
1539 const int srcBpp = (
c->srcFormatBpp + 7) >> 3;
1540 const int dstBpp = (
c->dstFormatBpp + 7) >> 3;
1549 int src_bswap =
IS_NOT_NE(
c->srcFormatBpp, desc_src);
1550 int dst_bswap =
IS_NOT_NE(
c->dstFormatBpp, desc_dst);
1561 dstPtr[dstStride[0] * (srcSliceY +
i)] = 255;
1565 if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1566 !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1567 conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1568 (
srcSliceH - 1) * srcStride[0] +
c->srcW * srcBpp);
1571 dstPtr += dstStride[0] * srcSliceY;
1575 for(j=0; j<
c->srcW; j++)
1576 ((uint16_t*)
c->formatConvBuffer)[j] =
av_bswap16(((uint16_t*)srcPtr)[j]);
1577 conv(
c->formatConvBuffer, dstPtr,
c->srcW * srcBpp);
1579 conv(srcPtr, dstPtr,
c->srcW * srcBpp);
1581 for(j=0; j<
c->srcW; j++)
1582 ((uint16_t*)dstPtr)[j] =
av_bswap16(((uint16_t*)dstPtr)[j]);
1583 srcPtr += srcStride[0];
1584 dstPtr += dstStride[0];
1592 int srcStride[],
int srcSliceY,
int srcSliceH,
1593 uint8_t *dst[],
int dstStride[])
1597 dst[0] + srcSliceY * dstStride[0],
1598 dst[1] + (srcSliceY >> 1) * dstStride[1],
1599 dst[2] + (srcSliceY >> 1) * dstStride[2],
1601 dstStride[0], dstStride[1], srcStride[0],
1602 c->input_rgb2yuv_table);
1609 int srcStride[],
int srcSliceY,
int srcSliceH,
1610 uint8_t *dst[],
int dstStride[])
1613 dst[0], dstStride[0]);
1615 planar2x(
src[1], dst[1] + dstStride[1] * (srcSliceY >> 1),
c->chrSrcW,
1616 srcSliceH >> 2, srcStride[1], dstStride[1]);
1617 planar2x(
src[2], dst[2] + dstStride[2] * (srcSliceY >> 1),
c->chrSrcW,
1618 srcSliceH >> 2, srcStride[2], dstStride[2]);
1625 int srcStride[],
int srcSliceY,
1629 ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
1631 float *dstPtr = (
float *)(dst[0] + dstStride[0] * srcSliceY);
1634 for (x = 0; x <
c->srcW; ++x){
1635 dstPtr[x] =
c->uint2float_lut[srcPtr[x]];
1637 srcPtr += srcStride[0];
1638 dstPtr += dstStrideFloat;
1645 int srcStride[],
int srcSliceY,
1649 ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
1650 const float *srcPtr = (
const float *)
src[0];
1651 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1654 for (x = 0; x <
c->srcW; ++x){
1655 dstPtr[x] = av_clip_uint8(
lrintf(255.0
f * srcPtr[x]));
1657 srcPtr += srcStrideFloat;
1658 dstPtr += dstStride[0];
1666 int srcStride[],
int srcSliceY,
int srcSliceH,
1667 uint8_t *dst[],
int dstStride[])
1669 if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
1670 memcpy(dst[0] + dstStride[0] * srcSliceY,
src[0],
srcSliceH * dstStride[0]);
1674 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1678 while (length +
c->srcW <=
FFABS(dstStride[0]) &&
1679 length +
c->srcW <=
FFABS(srcStride[0]))
1684 memcpy(dstPtr, srcPtr, length);
1685 srcPtr += srcStride[0];
1686 dstPtr += dstStride[0];
1692 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
1693 unsigned shift= src_depth-dst_depth, tmp;\
1694 if (c->dither == SWS_DITHER_NONE) {\
1695 for (i = 0; i < height; i++) {\
1696 for (j = 0; j < length-7; j+=8) {\
1697 dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
1698 dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
1699 dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
1700 dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
1701 dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
1702 dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
1703 dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
1704 dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
1706 for (; j < length; j++) {\
1707 dst[j] = dbswap(bswap(src[j])>>shift);\
1712 } else if (shiftonly) {\
1713 for (i = 0; i < height; i++) {\
1714 const uint8_t *dither= dithers[shift-1][i&7];\
1715 for (j = 0; j < length-7; j+=8) {\
1716 tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
1717 tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
1718 tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
1719 tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
1720 tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
1721 tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
1722 tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
1723 tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
1725 for (; j < length; j++) {\
1726 tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
1732 for (i = 0; i < height; i++) {\
1733 const uint8_t *dither= dithers[shift-1][i&7];\
1734 for (j = 0; j < length-7; j+=8) {\
1735 tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
1736 tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
1737 tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
1738 tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
1739 tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
1740 tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
1741 tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
1742 tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
1744 for (; j < length; j++) {\
1745 tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
1753 int srcStride[],
int srcSliceY,
int srcSliceH,
1754 uint8_t *dst[],
int dstStride[])
1759 for (plane = 0; plane < 4; plane++) {
1760 int length = (plane == 0 || plane == 3) ?
c->srcW :
AV_CEIL_RSHIFT(
c->srcW,
c->chrDstHSubSample);
1761 int y = (plane == 0 || plane == 3) ? srcSliceY:
AV_CEIL_RSHIFT(srcSliceY,
c->chrDstVSubSample);
1764 uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
1765 int shiftonly = plane == 1 || plane == 2 || (!
c->srcRange && plane == 0);
1770 if (plane == 1 && !dst[2])
continue;
1771 if (!
src[plane] || (plane == 1 && !
src[2])) {
1774 plane == 3, desc_dst->
comp[plane].
depth,
1775 isBE(
c->dstFormat));
1778 (plane == 3) ? 255 : 128);
1784 const int src_depth = desc_src->
comp[plane].
depth;
1785 const int dst_depth = desc_dst->
comp[plane].
depth;
1786 const uint16_t *srcPtr2 = (
const uint16_t *) srcPtr;
1787 uint16_t *dstPtr2 = (uint16_t*)dstPtr;
1789 if (dst_depth == 8) {
1790 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN){
1791 DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
1795 }
else if (src_depth == 8) {
1799 for (j = 0; j < length; j++)\
1800 w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
1802 for (j = 0; j < length; j++)\
1803 w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
1804 (srcPtr[j]>>(2*8-dst_depth)));\
1806 if(
isBE(
c->dstFormat)){
1811 dstPtr2 += dstStride[plane]/2;
1812 srcPtr += srcStride[plane];
1814 }
else if (src_depth <= dst_depth) {
1817 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN &&
1818 isBE(
c->dstFormat) == HAVE_BIGENDIAN &&
1820 unsigned shift = dst_depth - src_depth;
1822 #define FAST_COPY_UP(shift) \
1823 for (; j < length - 3; j += 4) { \
1824 uint64_t v = AV_RN64A(srcPtr2 + j); \
1825 AV_WN64A(dstPtr2 + j, v << shift); \
1828 #define FAST_COPY_UP(shift) \
1829 for (; j < length - 1; j += 2) { \
1830 uint32_t v = AV_RN32A(srcPtr2 + j); \
1831 AV_WN32A(dstPtr2 + j, v << shift); \
1840 #define COPY_UP(r,w) \
1842 for (; j < length; j++){ \
1843 unsigned int v= r(&srcPtr2[j]);\
1844 w(&dstPtr2[j], v<<(dst_depth-src_depth));\
1847 for (; j < length; j++){ \
1848 unsigned int v= r(&srcPtr2[j]);\
1849 w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
1850 (v>>(2*src_depth-dst_depth)));\
1853 if(
isBE(
c->srcFormat)){
1854 if(
isBE(
c->dstFormat)){
1860 if(
isBE(
c->dstFormat)){
1866 dstPtr2 += dstStride[plane]/2;
1867 srcPtr2 += srcStride[plane]/2;
1870 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN){
1871 if(
isBE(
c->dstFormat) == HAVE_BIGENDIAN){
1872 DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
1877 if(
isBE(
c->dstFormat) == HAVE_BIGENDIAN){
1888 for (j = 0; j < length; j++)
1889 ((uint16_t *) dstPtr)[j] =
av_bswap16(((
const uint16_t *) srcPtr)[j]);
1890 srcPtr += srcStride[plane];
1891 dstPtr += dstStride[plane];
1896 for (j = 0; j < length; j++)
1897 ((uint32_t *) dstPtr)[j] =
av_bswap32(((
const uint32_t *) srcPtr)[j]);
1898 srcPtr += srcStride[plane];
1899 dstPtr += dstStride[plane];
1901 }
else if (dstStride[plane] == srcStride[plane] &&
1902 srcStride[plane] > 0 && srcStride[plane] == length) {
1903 memcpy(dst[plane] + dstStride[plane] * y,
src[plane],
1904 height * dstStride[plane]);
1911 memcpy(dstPtr, srcPtr, length);
1912 srcPtr += srcStride[plane];
1913 dstPtr += dstStride[plane];
1922 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
1923 ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
1924 (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
1931 const int flags =
c->flags;
1932 const int dstH =
c->dstH;
1936 c->dstFormatBpp < 24 &&
2001 #define isByteRGB(f) ( \
2002 f == AV_PIX_FMT_RGB32 || \
2003 f == AV_PIX_FMT_RGB32_1 || \
2004 f == AV_PIX_FMT_RGB24 || \
2005 f == AV_PIX_FMT_BGR32 || \
2006 f == AV_PIX_FMT_BGR32_1 || \
2007 f == AV_PIX_FMT_BGR24)
2154 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
2163 c->chrDstHSubSample ==
c->chrSrcHSubSample &&
2164 c->chrDstVSubSample ==
c->chrSrcVSubSample &&
2183 int num_pixels,
const uint8_t *palette)
2187 for (
i = 0;
i < num_pixels;
i++)
2188 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i]];
2193 int num_pixels,
const uint8_t *palette)
2197 for (
i = 0;
i < num_pixels;
i++) {
2199 dst[0] = palette[
src[
i] * 4 + 0];
2200 dst[1] = palette[
src[
i] * 4 + 1];
2201 dst[2] = palette[
src[
i] * 4 + 2];