37 #include "libavutil/avconfig.h"
41 { 0, 1, 0, 1, 0, 1, 0, 1,},
42 { 1, 0, 1, 0, 1, 0, 1, 0,},
43 { 0, 1, 0, 1, 0, 1, 0, 1,},
44 { 1, 0, 1, 0, 1, 0, 1, 0,},
45 { 0, 1, 0, 1, 0, 1, 0, 1,},
46 { 1, 0, 1, 0, 1, 0, 1, 0,},
47 { 0, 1, 0, 1, 0, 1, 0, 1,},
48 { 1, 0, 1, 0, 1, 0, 1, 0,},
50 { 1, 2, 1, 2, 1, 2, 1, 2,},
51 { 3, 0, 3, 0, 3, 0, 3, 0,},
52 { 1, 2, 1, 2, 1, 2, 1, 2,},
53 { 3, 0, 3, 0, 3, 0, 3, 0,},
54 { 1, 2, 1, 2, 1, 2, 1, 2,},
55 { 3, 0, 3, 0, 3, 0, 3, 0,},
56 { 1, 2, 1, 2, 1, 2, 1, 2,},
57 { 3, 0, 3, 0, 3, 0, 3, 0,},
59 { 2, 4, 3, 5, 2, 4, 3, 5,},
60 { 6, 0, 7, 1, 6, 0, 7, 1,},
61 { 3, 5, 2, 4, 3, 5, 2, 4,},
62 { 7, 1, 6, 0, 7, 1, 6, 0,},
63 { 2, 4, 3, 5, 2, 4, 3, 5,},
64 { 6, 0, 7, 1, 6, 0, 7, 1,},
65 { 3, 5, 2, 4, 3, 5, 2, 4,},
66 { 7, 1, 6, 0, 7, 1, 6, 0,},
68 { 4, 8, 7, 11, 4, 8, 7, 11,},
69 { 12, 0, 15, 3, 12, 0, 15, 3,},
70 { 6, 10, 5, 9, 6, 10, 5, 9,},
71 { 14, 2, 13, 1, 14, 2, 13, 1,},
72 { 4, 8, 7, 11, 4, 8, 7, 11,},
73 { 12, 0, 15, 3, 12, 0, 15, 3,},
74 { 6, 10, 5, 9, 6, 10, 5, 9,},
75 { 14, 2, 13, 1, 14, 2, 13, 1,},
77 { 9, 17, 15, 23, 8, 16, 14, 22,},
78 { 25, 1, 31, 7, 24, 0, 30, 6,},
79 { 13, 21, 11, 19, 12, 20, 10, 18,},
80 { 29, 5, 27, 3, 28, 4, 26, 2,},
81 { 8, 16, 14, 22, 9, 17, 15, 23,},
82 { 24, 0, 30, 6, 25, 1, 31, 7,},
83 { 12, 20, 10, 18, 13, 21, 11, 19,},
84 { 28, 4, 26, 2, 29, 5, 27, 3,},
86 { 18, 34, 30, 46, 17, 33, 29, 45,},
87 { 50, 2, 62, 14, 49, 1, 61, 13,},
88 { 26, 42, 22, 38, 25, 41, 21, 37,},
89 { 58, 10, 54, 6, 57, 9, 53, 5,},
90 { 16, 32, 28, 44, 19, 35, 31, 47,},
91 { 48, 0, 60, 12, 51, 3, 63, 15,},
92 { 24, 40, 20, 36, 27, 43, 23, 39,},
93 { 56, 8, 52, 4, 59, 11, 55, 7,},
95 { 18, 34, 30, 46, 17, 33, 29, 45,},
96 { 50, 2, 62, 14, 49, 1, 61, 13,},
97 { 26, 42, 22, 38, 25, 41, 21, 37,},
98 { 58, 10, 54, 6, 57, 9, 53, 5,},
99 { 16, 32, 28, 44, 19, 35, 31, 47,},
100 { 48, 0, 60, 12, 51, 3, 63, 15,},
101 { 24, 40, 20, 36, 27, 43, 23, 39,},
102 { 56, 8, 52, 4, 59, 11, 55, 7,},
104 { 36, 68, 60, 92, 34, 66, 58, 90,},
105 { 100, 4,124, 28, 98, 2,122, 26,},
106 { 52, 84, 44, 76, 50, 82, 42, 74,},
107 { 116, 20,108, 12,114, 18,106, 10,},
108 { 32, 64, 56, 88, 38, 70, 62, 94,},
109 { 96, 0,120, 24,102, 6,126, 30,},
110 { 48, 80, 40, 72, 54, 86, 46, 78,},
111 { 112, 16,104, 8,118, 22,110, 14,},
130 dst += dstStride * srcSliceY;
131 if (dstStride == srcStride && srcStride > 0) {
144 int srcStride[],
int srcSliceY,
148 uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2;
151 dstParam[0], dstStride[0]);
155 srcStride[1], srcStride[2], dstStride[1]);
158 srcStride[2], srcStride[1], dstStride[1]);
164 int srcStride[],
int srcSliceY,
168 uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
169 uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
172 dstParam[0], dstStride[0]);
176 srcStride[1], dstStride[1], dstStride[2]);
179 srcStride[1], dstStride[2], dstStride[1]);
185 int srcStride[],
int srcSliceY,
189 uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY;
192 dstParam[0], dstStride[0]);
196 srcStride[1], srcStride[2], dstStride[1]);
199 srcStride[2], srcStride[1], dstStride[1]);
205 int srcStride[],
int srcSliceY,
209 uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY;
210 uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY;
213 dstParam[0], dstStride[0]);
217 srcStride[1], dstStride[1], dstStride[2]);
220 srcStride[1], dstStride[2], dstStride[1]);
226 int srcStride[],
int srcSliceY,
232 const uint16_t **
src = (
const uint16_t**)src8;
233 uint16_t *
dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
234 uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
238 const int shift[3] = {
247 av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
248 dstStride[0] % 2 || dstStride[1] % 2));
251 uint16_t *tdstY =
dstY;
252 const uint16_t *tsrc0 =
src[0];
253 for (x =
c->srcW; x > 0; x--) {
254 *tdstY++ = *tsrc0++ <<
shift[0];
256 src[0] += srcStride[0] / 2;
257 dstY += dstStride[0] / 2;
260 uint16_t *tdstUV = dstUV;
261 const uint16_t *tsrc1 =
src[1];
262 const uint16_t *tsrc2 =
src[2];
263 for (x =
c->srcW / 2; x > 0; x--) {
264 *tdstUV++ = *tsrc1++ <<
shift[1];
265 *tdstUV++ = *tsrc2++ <<
shift[2];
267 src[1] += srcStride[1] / 2;
268 src[2] += srcStride[2] / 2;
269 dstUV += dstStride[1] / 2;
276 #if AV_HAVE_BIGENDIAN
277 #define output_pixel(p, v) do { \
278 uint16_t *pp = (p); \
282 #define output_pixel(p, v) (*p) = (v)
286 int srcStride[],
int srcSliceY,
290 uint16_t *
dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
291 uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
294 av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
297 uint16_t *tdstY =
dstY;
299 for (x =
c->srcW; x > 0; x--) {
303 src[0] += srcStride[0];
304 dstY += dstStride[0] / 2;
307 uint16_t *tdstUV = dstUV;
310 for (x =
c->srcW / 2; x > 0; x--) {
316 src[1] += srcStride[1];
317 src[2] += srcStride[2];
318 dstUV += dstStride[1] / 2;
328 int srcStride[],
int srcSliceY,
int srcSliceH,
329 uint8_t *dstParam[],
int dstStride[])
331 uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
334 srcStride[1], dstStride[0]);
340 int srcStride[],
int srcSliceY,
int srcSliceH,
341 uint8_t *dstParam[],
int dstStride[])
343 uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
346 srcStride[1], dstStride[0]);
352 int srcStride[],
int srcSliceY,
int srcSliceH,
353 uint8_t *dstParam[],
int dstStride[])
355 uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
358 srcStride[1], dstStride[0]);
364 int srcStride[],
int srcSliceY,
int srcSliceH,
365 uint8_t *dstParam[],
int dstStride[])
367 uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
370 srcStride[1], dstStride[0]);
376 int srcStride[],
int srcSliceY,
int srcSliceH,
377 uint8_t *dstParam[],
int dstStride[])
379 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
380 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
381 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
384 dstStride[1], srcStride[0]);
393 int srcStride[],
int srcSliceY,
int srcSliceH,
394 uint8_t *dstParam[],
int dstStride[])
396 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
397 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
398 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
401 dstStride[1], srcStride[0]);
407 int srcStride[],
int srcSliceY,
int srcSliceH,
408 uint8_t *dstParam[],
int dstStride[])
410 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
411 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
412 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
415 dstStride[1], srcStride[0]);
424 int srcStride[],
int srcSliceY,
int srcSliceH,
425 uint8_t *dstParam[],
int dstStride[])
427 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
428 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
429 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
432 dstStride[1], srcStride[0]);
441 for (
i = 0;
i < num_pixels;
i++)
442 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] | (
src[(
i << 1) + 1] << 24);
450 for (
i = 0;
i < num_pixels;
i++)
451 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] |
src[(
i << 1) + 1];
459 for (
i = 0;
i < num_pixels;
i++) {
461 dst[0] = palette[
src[
i << 1] * 4 + 0];
462 dst[1] = palette[
src[
i << 1] * 4 + 1];
463 dst[2] = palette[
src[
i << 1] * 4 + 2];
469 int srcStride[],
int srcSliceY,
int srcSliceH,
470 uint8_t *dst[],
int dstStride[])
474 for (p = 0; p < 4; p++) {
475 int srcstr = srcStride[p] / 2;
476 int dststr = dstStride[p] / 2;
477 uint16_t *dstPtr = (uint16_t *) dst[p];
478 const uint16_t *srcPtr = (
const uint16_t *)
src[p];
480 if(!dstPtr || !srcPtr)
482 dstPtr += (srcSliceY >>
c->chrDstVSubSample) * dststr;
484 for (j = 0; j < min_stride; j++) {
496 int srcStride[],
int srcSliceY,
int srcSliceH,
497 uint8_t *dst[],
int dstStride[])
501 for (p = 0; p < 4; p++) {
502 int srcstr = srcStride[p] / 4;
503 int dststr = dstStride[p] / 4;
504 uint32_t *dstPtr = (uint32_t *) dst[p];
505 const uint32_t *srcPtr = (
const uint32_t *)
src[p];
507 if(!dstPtr || !srcPtr)
509 dstPtr += (srcSliceY >>
c->chrDstVSubSample) * dststr;
511 for (j = 0; j < min_stride; j++) {
532 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
561 srcPtr += srcStride[0];
562 dstPtr += dstStride[0];
570 uint16_t *dst[],
int dstStride[],
int srcSliceH,
571 int src_alpha,
int swap,
int shift,
int width)
574 int dst_alpha = dst[3] !=
NULL;
576 uint16_t *src_line = (uint16_t *)(
src + srcStride *
h);
579 if (src_alpha && dst_alpha) {
580 for (x = 0; x <
width; x++) {
586 }
else if (dst_alpha) {
587 for (x = 0; x <
width; x++) {
593 }
else if (src_alpha) {
594 for (x = 0; x <
width; x++) {
601 for (x = 0; x <
width; x++) {
609 if (src_alpha && dst_alpha) {
610 for (x = 0; x <
width; x++) {
616 }
else if (dst_alpha) {
617 for (x = 0; x <
width; x++) {
623 }
else if (src_alpha) {
624 for (x = 0; x <
width; x++) {
631 for (x = 0; x <
width; x++) {
639 if (src_alpha && dst_alpha) {
640 for (x = 0; x <
width; x++) {
646 }
else if (dst_alpha) {
647 for (x = 0; x <
width; x++) {
653 }
else if (src_alpha) {
654 for (x = 0; x <
width; x++) {
661 for (x = 0; x <
width; x++) {
669 if (src_alpha && dst_alpha) {
670 for (x = 0; x <
width; x++) {
671 dst[0][x] = *src_line++ >>
shift;
672 dst[1][x] = *src_line++ >>
shift;
673 dst[2][x] = *src_line++ >>
shift;
674 dst[3][x] = *src_line++ >>
shift;
676 }
else if (dst_alpha) {
677 for (x = 0; x <
width; x++) {
678 dst[0][x] = *src_line++ >>
shift;
679 dst[1][x] = *src_line++ >>
shift;
680 dst[2][x] = *src_line++ >>
shift;
683 }
else if (src_alpha) {
684 for (x = 0; x <
width; x++) {
685 dst[0][x] = *src_line++ >>
shift;
686 dst[1][x] = *src_line++ >>
shift;
687 dst[2][x] = *src_line++ >>
shift;
691 for (x = 0; x <
width; x++) {
692 dst[0][x] = *src_line++ >>
shift;
693 dst[1][x] = *src_line++ >>
shift;
694 dst[2][x] = *src_line++ >>
shift;
698 for (
i = 0;
i < 4;
i++)
699 dst[
i] += dstStride[
i] >> 1;
704 int srcStride[],
int srcSliceY,
int srcSliceH,
705 uint8_t *dst[],
int dstStride[])
707 uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
708 uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
709 int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
710 int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
728 src_format->
name, dst_format->
name);
733 dst2013[
i] += stride2013[
i] * srcSliceY / 2;
734 dst1023[
i] += stride1023[
i] * srcSliceY / 2;
737 switch (
c->srcFormat) {
756 "unsupported conversion to planar RGB %s -> %s\n",
757 src_format->
name, dst_format->
name);
768 int src_alpha =
src[3] !=
NULL;
769 int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
771 uint16_t *dest = (uint16_t *)(dst + dstStride *
h);
776 if (
alpha && !src_alpha) {
777 for (x = 0; x <
width; x++) {
779 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
781 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
783 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
786 }
else if (
alpha && src_alpha) {
787 for (x = 0; x <
width; x++) {
789 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
791 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
793 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
795 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
798 for (x = 0; x <
width; x++) {
800 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
802 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
804 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
809 if (
alpha && !src_alpha) {
810 for (x = 0; x <
width; x++) {
816 }
else if (
alpha && src_alpha) {
817 for (x = 0; x <
width; x++) {
824 for (x = 0; x <
width; x++) {
832 if (
alpha && !src_alpha) {
833 for (x = 0; x <
width; x++) {
839 }
else if (
alpha && src_alpha) {
840 for (x = 0; x <
width; x++) {
847 for (x = 0; x <
width; x++) {
855 if (
alpha && !src_alpha) {
856 for (x = 0; x <
width; x++) {
857 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
858 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
859 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
862 }
else if (
alpha && src_alpha) {
863 for (x = 0; x <
width; x++) {
864 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
865 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
866 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
867 *dest++ =
src[3][x] << scale_high |
src[3][x] >> scale_low;
870 for (x = 0; x <
width; x++) {
871 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
872 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
873 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
877 for (
i = 0;
i < 3 + src_alpha;
i++)
878 src[
i] += srcStride[
i] >> 1;
883 int srcStride[],
int srcSliceY,
int srcSliceH,
884 uint8_t *dst[],
int dstStride[])
886 const uint16_t *src102[] = { (uint16_t *)
src[1], (uint16_t *)
src[0], (uint16_t *)
src[2], (uint16_t *)
src[3] };
887 const uint16_t *src201[] = { (uint16_t *)
src[2], (uint16_t *)
src[0], (uint16_t *)
src[1], (uint16_t *)
src[3] };
888 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
889 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
892 int bits_per_sample = src_format->
comp[0].
depth;
903 bits_per_sample <= 8) {
905 src_format->
name, dst_format->
name);
908 switch (
c->dstFormat) {
912 dst[0] + srcSliceY * dstStride[0], dstStride[0],
913 srcSliceH, 0, swap, bits_per_sample,
c->srcW);
918 dst[0] + srcSliceY * dstStride[0], dstStride[0],
919 srcSliceH, 0, swap, bits_per_sample,
c->srcW);
924 dst[0] + srcSliceY * dstStride[0], dstStride[0],
925 srcSliceH, 1, swap, bits_per_sample,
c->srcW);
930 dst[0] + srcSliceY * dstStride[0], dstStride[0],
931 srcSliceH, 1, swap, bits_per_sample,
c->srcW);
935 "unsupported planar RGB conversion %s -> %s\n",
936 src_format->
name, dst_format->
name);
948 uint8_t *dest = dst + dstStride *
h;
949 for (x = 0; x <
width; x++) {
955 for (
i = 0;
i < 3;
i++)
956 src[
i] += srcStride[
i];
962 int alpha_first,
int width)
966 uint8_t *dest = dst + dstStride *
h;
969 for (x = 0; x <
width; x++) {
976 for (x = 0; x <
width; x++) {
984 for (
i = 0;
i < 3;
i++)
985 src[
i] += srcStride[
i];
991 int alpha_first,
int width)
995 uint8_t *dest = dst + dstStride *
h;
998 for (x = 0; x <
width; x++) {
1000 *dest++ =
src[0][x];
1001 *dest++ =
src[1][x];
1002 *dest++ =
src[2][x];
1005 for (x = 0; x <
width; x++) {
1006 *dest++ =
src[0][x];
1007 *dest++ =
src[1][x];
1008 *dest++ =
src[2][x];
1009 *dest++ =
src[3][x];
1013 for (
i = 0;
i < 4;
i++)
1014 src[
i] += srcStride[
i];
1019 int srcStride[],
int srcSliceY,
int srcSliceH,
1020 uint8_t *dst[],
int dstStride[])
1022 int alpha_first = 0;
1025 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
1026 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1035 switch (
c->dstFormat) {
1038 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1044 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1052 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1060 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1066 "unsupported planar RGB conversion %s -> %s\n",
1075 int srcStride[],
int srcSliceY,
int srcSliceH,
1076 uint8_t *dst[],
int dstStride[])
1078 int alpha_first = 0;
1081 int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
1082 int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
1091 switch (
c->dstFormat) {
1094 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1100 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1108 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1116 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1122 "unsupported planar RGB conversion %s -> %s\n",
1133 uint8_t *dst[],
int dstStride[])
1136 dst[0], dstStride[0]);
1138 dst[1], dstStride[1]);
1140 dst[2], dstStride[2]);
1149 int alpha_first,
int inc_size,
int width)
1162 for (x = 0; x <
width; x++) {
1163 dest[0][x] =
src[0];
1164 dest[1][x] =
src[1];
1165 dest[2][x] =
src[2];
1169 src += srcStride -
width * inc_size;
1170 dest[0] += dstStride[0];
1171 dest[1] += dstStride[1];
1172 dest[2] += dstStride[2];
1177 int srcStride[],
int srcSliceY,
int srcSliceH,
1178 uint8_t *dst[],
int dstStride[])
1180 int alpha_first = 0;
1181 int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1182 int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1183 uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
1184 dst[0] + srcSliceY * dstStride[0],
1185 dst[2] + srcSliceY * dstStride[2] };
1186 uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
1187 dst[0] + srcSliceY * dstStride[0],
1188 dst[1] + srcSliceY * dstStride[1] };
1190 switch (
c->srcFormat) {
1193 stride201,
srcSliceH, alpha_first, 3,
c->srcW);
1197 stride102,
srcSliceH, alpha_first, 3,
c->srcW);
1203 stride201,
srcSliceH, alpha_first, 4,
c->srcW);
1209 stride102,
srcSliceH, alpha_first, 4,
c->srcW);
1213 "unsupported planar RGB conversion %s -> %s\n",
1223 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1228 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1233 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1238 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1243 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1248 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1253 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1258 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1263 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1268 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1273 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1278 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1284 uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1290 switch(
c->srcFormat) {
1291 #define CASE(pixfmt, prefix) \
1292 case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1293 interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1313 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1314 srcPtr += 2 * srcStride[0];
1315 dstPtr += 2 * dstStride[0];
1318 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1319 srcPtr += 2 * srcStride[0];
1320 dstPtr += 2 * dstStride[0];
1324 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->srcW);
1326 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1333 uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1339 switch(
c->srcFormat) {
1340 #define CASE(pixfmt, prefix) \
1341 case pixfmt: copy = bayer_##prefix##_to_rgb48_copy; \
1342 interpolate = bayer_##prefix##_to_rgb48_interpolate; \
1362 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1363 srcPtr += 2 * srcStride[0];
1364 dstPtr += 2 * dstStride[0];
1367 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1368 srcPtr += 2 * srcStride[0];
1369 dstPtr += 2 * dstStride[0];
1373 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->srcW);
1375 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1384 uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
1385 uint8_t *
dstV= dst[2] + srcSliceY * dstStride[2] / 2;
1390 switch(
c->srcFormat) {
1391 #define CASE(pixfmt, prefix) \
1392 case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1393 interpolate = bayer_##prefix##_to_yv12_interpolate; \
1413 copy(srcPtr, srcStride[0],
dstY, dstU,
dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1414 srcPtr += 2 * srcStride[0];
1415 dstY += 2 * dstStride[0];
1416 dstU += dstStride[1];
1417 dstV += dstStride[1];
1421 srcPtr += 2 * srcStride[0];
1422 dstY += 2 * dstStride[0];
1423 dstU += dstStride[1];
1424 dstV += dstStride[1];
1428 copy(srcPtr, -srcStride[0],
dstY, dstU,
dstV, -dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1430 copy(srcPtr, srcStride[0],
dstY, dstU,
dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1434 #define isRGBA32(x) ( \
1435 (x) == AV_PIX_FMT_ARGB \
1436 || (x) == AV_PIX_FMT_RGBA \
1437 || (x) == AV_PIX_FMT_BGRA \
1438 || (x) == AV_PIX_FMT_ABGR \
1441 #define isRGBA64(x) ( \
1442 (x) == AV_PIX_FMT_RGBA64LE \
1443 || (x) == AV_PIX_FMT_RGBA64BE \
1444 || (x) == AV_PIX_FMT_BGRA64LE \
1445 || (x) == AV_PIX_FMT_BGRA64BE \
1448 #define isRGB48(x) ( \
1449 (x) == AV_PIX_FMT_RGB48LE \
1450 || (x) == AV_PIX_FMT_RGB48BE \
1451 || (x) == AV_PIX_FMT_BGR48LE \
1452 || (x) == AV_PIX_FMT_BGR48BE \
1461 const int srcId =
c->srcFormatBpp;
1462 const int dstId =
c->dstFormatBpp;
1465 #define IS_NOT_NE(bpp, desc) \
1466 (((bpp + 7) >> 3) == 2 && \
1467 (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1469 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1489 else if (
CONV_IS(RGB48LE, BGR48BE)
1494 if (
CONV_IS(RGB48LE, BGRA64LE)
1498 else if (
CONV_IS(RGB48LE, BGRA64BE)
1502 if (
CONV_IS(RGB48LE, RGBA64LE)
1506 else if (
CONV_IS(RGB48LE, RGBA64BE)
1511 if (
CONV_IS(RGBA64LE, BGR48LE)
1515 else if (
CONV_IS(RGBA64LE, BGR48BE)
1519 else if (
CONV_IS(RGBA64LE, RGB48LE)
1523 else if (
CONV_IS(RGBA64LE, RGB48BE)
1531 switch (srcId | (dstId << 16)) {
1548 switch (srcId | (dstId << 16)) {
1589 const int srcBpp = (
c->srcFormatBpp + 7) >> 3;
1590 const int dstBpp = (
c->dstFormatBpp + 7) >> 3;
1599 int src_bswap =
IS_NOT_NE(
c->srcFormatBpp, desc_src);
1600 int dst_bswap =
IS_NOT_NE(
c->dstFormatBpp, desc_dst);
1611 dstPtr[dstStride[0] * (srcSliceY +
i)] = 255;
1615 if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1616 !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1617 conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1618 (
srcSliceH - 1) * srcStride[0] +
c->srcW * srcBpp);
1621 dstPtr += dstStride[0] * srcSliceY;
1625 for(j=0; j<
c->srcW; j++)
1626 ((uint16_t*)
c->formatConvBuffer)[j] =
av_bswap16(((uint16_t*)srcPtr)[j]);
1627 conv(
c->formatConvBuffer, dstPtr,
c->srcW * srcBpp);
1629 conv(srcPtr, dstPtr,
c->srcW * srcBpp);
1631 for(j=0; j<
c->srcW; j++)
1632 ((uint16_t*)dstPtr)[j] =
av_bswap16(((uint16_t*)dstPtr)[j]);
1633 srcPtr += srcStride[0];
1634 dstPtr += dstStride[0];
1642 int srcStride[],
int srcSliceY,
int srcSliceH,
1643 uint8_t *dst[],
int dstStride[])
1647 dst[0] + srcSliceY * dstStride[0],
1648 dst[1] + (srcSliceY >> 1) * dstStride[1],
1649 dst[2] + (srcSliceY >> 1) * dstStride[2],
1651 dstStride[0], dstStride[1], srcStride[0],
1652 c->input_rgb2yuv_table);
1659 int srcStride[],
int srcSliceY,
int srcSliceH,
1660 uint8_t *dst[],
int dstStride[])
1663 dst[0], dstStride[0]);
1665 planar2x(
src[1], dst[1] + dstStride[1] * (srcSliceY >> 1),
c->chrSrcW,
1666 srcSliceH >> 2, srcStride[1], dstStride[1]);
1667 planar2x(
src[2], dst[2] + dstStride[2] * (srcSliceY >> 1),
c->chrSrcW,
1668 srcSliceH >> 2, srcStride[2], dstStride[2]);
1675 int srcStride[],
int srcSliceY,
1679 ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
1681 float *dstPtr = (
float *)(dst[0] + dstStride[0] * srcSliceY);
1684 for (x = 0; x <
c->srcW; ++x){
1685 dstPtr[x] =
c->uint2float_lut[srcPtr[x]];
1687 srcPtr += srcStride[0];
1688 dstPtr += dstStrideFloat;
1695 int srcStride[],
int srcSliceY,
1699 ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
1700 const float *srcPtr = (
const float *)
src[0];
1701 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1704 for (x = 0; x <
c->srcW; ++x){
1707 srcPtr += srcStrideFloat;
1708 dstPtr += dstStride[0];
1716 int srcStride[],
int srcSliceY,
int srcSliceH,
1717 uint8_t *dst[],
int dstStride[])
1719 if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
1720 memcpy(dst[0] + dstStride[0] * srcSliceY,
src[0],
srcSliceH * dstStride[0]);
1724 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1728 while (length +
c->srcW <=
FFABS(dstStride[0]) &&
1729 length +
c->srcW <=
FFABS(srcStride[0]))
1734 memcpy(dstPtr, srcPtr, length);
1735 srcPtr += srcStride[0];
1736 dstPtr += dstStride[0];
1742 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
1743 unsigned shift= src_depth-dst_depth, tmp;\
1744 if (c->dither == SWS_DITHER_NONE) {\
1745 for (i = 0; i < height; i++) {\
1746 for (j = 0; j < length-7; j+=8) {\
1747 dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
1748 dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
1749 dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
1750 dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
1751 dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
1752 dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
1753 dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
1754 dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
1756 for (; j < length; j++) {\
1757 dst[j] = dbswap(bswap(src[j])>>shift);\
1762 } else if (shiftonly) {\
1763 for (i = 0; i < height; i++) {\
1764 const uint8_t *dither= dithers[shift-1][i&7];\
1765 for (j = 0; j < length-7; j+=8) {\
1766 tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
1767 tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
1768 tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
1769 tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
1770 tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
1771 tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
1772 tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
1773 tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
1775 for (; j < length; j++) {\
1776 tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
1782 for (i = 0; i < height; i++) {\
1783 const uint8_t *dither= dithers[shift-1][i&7];\
1784 for (j = 0; j < length-7; j+=8) {\
1785 tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
1786 tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
1787 tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
1788 tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
1789 tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
1790 tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
1791 tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
1792 tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
1794 for (; j < length; j++) {\
1795 tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
1803 int srcStride[],
int srcSliceY,
int srcSliceH,
1804 uint8_t *dst[],
int dstStride[])
1809 for (plane = 0; plane < 4 && dst[plane] !=
NULL; plane++) {
1810 int length = (plane == 0 || plane == 3) ?
c->srcW :
AV_CEIL_RSHIFT(
c->srcW,
c->chrDstHSubSample);
1811 int y = (plane == 0 || plane == 3) ? srcSliceY:
AV_CEIL_RSHIFT(srcSliceY,
c->chrDstVSubSample);
1814 uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
1815 int shiftonly = plane == 1 || plane == 2 || (!
c->srcRange && plane == 0);
1818 if (plane == 1 && !dst[2])
continue;
1819 if (!
src[plane] || (plane == 1 && !
src[2])) {
1822 plane == 3, desc_dst->
comp[plane].
depth,
1823 isBE(
c->dstFormat));
1826 (plane == 3) ? 255 : 128);
1832 const int src_depth = desc_src->
comp[plane].
depth;
1833 const int dst_depth = desc_dst->
comp[plane].
depth;
1834 const uint16_t *srcPtr2 = (
const uint16_t *) srcPtr;
1835 uint16_t *dstPtr2 = (uint16_t*)dstPtr;
1837 if (dst_depth == 8) {
1838 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN){
1839 DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
1843 }
else if (src_depth == 8) {
1847 for (j = 0; j < length; j++)\
1848 w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
1850 for (j = 0; j < length; j++)\
1851 w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
1852 (srcPtr[j]>>(2*8-dst_depth)));\
1854 if(
isBE(
c->dstFormat)){
1859 dstPtr2 += dstStride[plane]/2;
1860 srcPtr += srcStride[plane];
1862 }
else if (src_depth <= dst_depth) {
1865 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN &&
1866 isBE(
c->dstFormat) == HAVE_BIGENDIAN &&
1868 unsigned shift = dst_depth - src_depth;
1870 #define FAST_COPY_UP(shift) \
1871 for (; j < length - 3; j += 4) { \
1872 uint64_t v = AV_RN64A(srcPtr2 + j); \
1873 AV_WN64A(dstPtr2 + j, v << shift); \
1876 #define FAST_COPY_UP(shift) \
1877 for (; j < length - 1; j += 2) { \
1878 uint32_t v = AV_RN32A(srcPtr2 + j); \
1879 AV_WN32A(dstPtr2 + j, v << shift); \
1888 #define COPY_UP(r,w) \
1890 for (; j < length; j++){ \
1891 unsigned int v= r(&srcPtr2[j]);\
1892 w(&dstPtr2[j], v<<(dst_depth-src_depth));\
1895 for (; j < length; j++){ \
1896 unsigned int v= r(&srcPtr2[j]);\
1897 w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
1898 (v>>(2*src_depth-dst_depth)));\
1901 if(
isBE(
c->srcFormat)){
1902 if(
isBE(
c->dstFormat)){
1908 if(
isBE(
c->dstFormat)){
1914 dstPtr2 += dstStride[plane]/2;
1915 srcPtr2 += srcStride[plane]/2;
1918 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN){
1919 if(
isBE(
c->dstFormat) == HAVE_BIGENDIAN){
1920 DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
1925 if(
isBE(
c->dstFormat) == HAVE_BIGENDIAN){
1936 for (j = 0; j < length; j++)
1937 ((uint16_t *) dstPtr)[j] =
av_bswap16(((
const uint16_t *) srcPtr)[j]);
1938 srcPtr += srcStride[plane];
1939 dstPtr += dstStride[plane];
1944 for (j = 0; j < length; j++)
1945 ((uint32_t *) dstPtr)[j] =
av_bswap32(((
const uint32_t *) srcPtr)[j]);
1946 srcPtr += srcStride[plane];
1947 dstPtr += dstStride[plane];
1949 }
else if (dstStride[plane] == srcStride[plane] &&
1950 srcStride[plane] > 0 && srcStride[plane] == length) {
1951 memcpy(dst[plane] + dstStride[plane] * y,
src[plane],
1952 height * dstStride[plane]);
1959 memcpy(dstPtr, srcPtr, length);
1960 srcPtr += srcStride[plane];
1961 dstPtr += dstStride[plane];
1970 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
1971 ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
1972 (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
1979 const int flags =
c->flags;
1980 const int dstH =
c->dstH;
1984 c->dstFormatBpp < 24 &&
2049 #define isByteRGB(f) ( \
2050 f == AV_PIX_FMT_RGB32 || \
2051 f == AV_PIX_FMT_RGB32_1 || \
2052 f == AV_PIX_FMT_RGB24 || \
2053 f == AV_PIX_FMT_BGR32 || \
2054 f == AV_PIX_FMT_BGR32_1 || \
2055 f == AV_PIX_FMT_BGR24)
2204 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
2213 c->chrDstHSubSample ==
c->chrSrcHSubSample &&
2214 c->chrDstVSubSample ==
c->chrSrcVSubSample &&
2233 int num_pixels,
const uint8_t *palette)
2237 for (
i = 0;
i < num_pixels;
i++)
2238 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i]];
2243 int num_pixels,
const uint8_t *palette)
2247 for (
i = 0;
i < num_pixels;
i++) {
2249 dst[0] = palette[
src[
i] * 4 + 0];
2250 dst[1] = palette[
src[
i] * 4 + 1];
2251 dst[2] = palette[
src[
i] * 4 + 2];