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,},
118 uint8_t *ptr = plane +
stride * y;
127 uint8_t *dst,
int dstStride)
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;
297 const uint8_t *tsrc0 =
src[0];
298 for (x =
c->srcW; x > 0; x--) {
302 src[0] += srcStride[0];
303 dstY += dstStride[0] / 2;
306 uint16_t *tdstUV = dstUV;
307 const uint8_t *tsrc1 =
src[1];
308 const uint8_t *tsrc2 =
src[2];
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]);
437 const uint8_t *palette)
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);
445 const uint8_t *palette)
449 for (
i = 0;
i < num_pixels;
i++)
450 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] |
src[(
i << 1) + 1];
454 const uint8_t *palette)
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++) {
523 int srcSliceY,
int srcSliceH, uint8_t *dst[],
528 void (*
conv)(
const uint8_t *
src, uint8_t *dst,
int num_pixels,
529 const uint8_t *palette) =
NULL;
531 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
532 const uint8_t *srcPtr =
src[0];
559 conv(srcPtr, dstPtr,
c->srcW, (uint8_t *)
c->pal_rgb);
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);
763 uint8_t *dst,
int dstStride,
int srcSliceH,
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);
942 uint8_t *dst,
int dstStride,
int srcSliceH,
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];
960 uint8_t *dst,
int dstStride,
int srcSliceH,
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];
989 uint8_t *dst,
int dstStride,
int srcSliceH,
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;
1022 const uint8_t *src102[] = {
src[1],
src[0],
src[2],
src[3] };
1023 const uint8_t *src201[] = {
src[2],
src[0],
src[1],
src[3] };
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;
1078 const uint8_t *src102[] = {
src[1],
src[0],
src[2] };
1079 const uint8_t *src201[] = {
src[2],
src[0],
src[1] };
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",
1130 const uint8_t *
src[],
int srcStride[],
1132 uint8_t *dst[],
int dstStride[])
1135 dst[0], dstStride[0]);
1137 dst[1], dstStride[1]);
1139 dst[2], dstStride[2]);
1147 uint8_t *dst[],
int dstStride[],
int srcSliceH,
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
1281 int srcSliceH, uint8_t* dst[],
int dstStride[])
1283 uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1284 const uint8_t *srcPtr=
src[0];
1286 void (*
copy) (
const uint8_t *
src,
int src_stride, uint8_t *dst,
int dst_stride,
int width);
1287 void (*
interpolate)(
const uint8_t *
src,
int src_stride, uint8_t *dst,
int dst_stride,
int width);
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);
1330 int srcSliceH, uint8_t* dst[],
int dstStride[])
1332 uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1333 const uint8_t *srcPtr=
src[0];
1335 void (*
copy) (
const uint8_t *
src,
int src_stride, uint8_t *dst,
int dst_stride,
int width);
1336 void (*
interpolate)(
const uint8_t *
src,
int src_stride, uint8_t *dst,
int dst_stride,
int width);
1338 switch(
c->srcFormat) {
1339 #define CASE(pixfmt, prefix) \
1340 case pixfmt: copy = bayer_##prefix##_to_rgb48_copy; \
1341 interpolate = bayer_##prefix##_to_rgb48_interpolate; \
1361 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1362 srcPtr += 2 * srcStride[0];
1363 dstPtr += 2 * dstStride[0];
1366 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1367 srcPtr += 2 * srcStride[0];
1368 dstPtr += 2 * dstStride[0];
1372 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->srcW);
1374 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1379 int srcSliceH, uint8_t* dst[],
int dstStride[])
1381 const uint8_t *srcPtr=
src[0];
1382 uint8_t *
dstY= dst[0] + srcSliceY * dstStride[0];
1383 uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
1384 uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
1389 switch(
c->srcFormat) {
1390 #define CASE(pixfmt, prefix) \
1391 case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1392 interpolate = bayer_##prefix##_to_yv12_interpolate; \
1412 copy(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1413 srcPtr += 2 * srcStride[0];
1414 dstY += 2 * dstStride[0];
1415 dstU += dstStride[1];
1416 dstV += dstStride[1];
1419 interpolate(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1420 srcPtr += 2 * srcStride[0];
1421 dstY += 2 * dstStride[0];
1422 dstU += dstStride[1];
1423 dstV += dstStride[1];
1427 copy(srcPtr, -srcStride[0],
dstY, dstU, dstV, -dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1429 copy(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1433 #define isRGBA32(x) ( \
1434 (x) == AV_PIX_FMT_ARGB \
1435 || (x) == AV_PIX_FMT_RGBA \
1436 || (x) == AV_PIX_FMT_BGRA \
1437 || (x) == AV_PIX_FMT_ABGR \
1440 #define isRGBA64(x) ( \
1441 (x) == AV_PIX_FMT_RGBA64LE \
1442 || (x) == AV_PIX_FMT_RGBA64BE \
1443 || (x) == AV_PIX_FMT_BGRA64LE \
1444 || (x) == AV_PIX_FMT_BGRA64BE \
1447 #define isRGB48(x) ( \
1448 (x) == AV_PIX_FMT_RGB48LE \
1449 || (x) == AV_PIX_FMT_RGB48BE \
1450 || (x) == AV_PIX_FMT_BGR48LE \
1451 || (x) == AV_PIX_FMT_BGR48BE \
1460 const int srcId =
c->srcFormatBpp;
1461 const int dstId =
c->dstFormatBpp;
1464 #define IS_NOT_NE(bpp, desc) \
1465 (((bpp + 7) >> 3) == 2 && \
1466 (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1468 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1488 else if (
CONV_IS(RGB48LE, BGR48BE)
1493 if (
CONV_IS(RGB48LE, BGRA64LE)
1497 else if (
CONV_IS(RGB48LE, BGRA64BE)
1501 if (
CONV_IS(RGB48LE, RGBA64LE)
1505 else if (
CONV_IS(RGB48LE, RGBA64BE)
1510 if (
CONV_IS(RGBA64LE, BGR48LE)
1514 else if (
CONV_IS(RGBA64LE, BGR48BE)
1518 else if (
CONV_IS(RGBA64LE, RGB48LE)
1522 else if (
CONV_IS(RGBA64LE, RGB48BE)
1530 switch (srcId | (dstId << 16)) {
1547 switch (srcId | (dstId << 16)) {
1580 int srcSliceY,
int srcSliceH, uint8_t *dst[],
1588 const int srcBpp = (
c->srcFormatBpp + 7) >> 3;
1589 const int dstBpp = (
c->dstFormatBpp + 7) >> 3;
1596 const uint8_t *srcPtr =
src[0];
1597 uint8_t *dstPtr = dst[0];
1598 int src_bswap =
IS_NOT_NE(
c->srcFormatBpp, desc_src);
1599 int dst_bswap =
IS_NOT_NE(
c->dstFormatBpp, desc_dst);
1610 dstPtr[dstStride[0] * (srcSliceY +
i)] = 255;
1614 if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1615 !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1616 conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1617 (
srcSliceH - 1) * srcStride[0] +
c->srcW * srcBpp);
1620 dstPtr += dstStride[0] * srcSliceY;
1624 for(j=0; j<
c->srcW; j++)
1625 ((uint16_t*)
c->formatConvBuffer)[j] =
av_bswap16(((uint16_t*)srcPtr)[j]);
1626 conv(
c->formatConvBuffer, dstPtr,
c->srcW * srcBpp);
1628 conv(srcPtr, dstPtr,
c->srcW * srcBpp);
1630 for(j=0; j<
c->srcW; j++)
1631 ((uint16_t*)dstPtr)[j] =
av_bswap16(((uint16_t*)dstPtr)[j]);
1632 srcPtr += srcStride[0];
1633 dstPtr += dstStride[0];
1641 int srcStride[],
int srcSliceY,
int srcSliceH,
1642 uint8_t *dst[],
int dstStride[])
1646 dst[0] + srcSliceY * dstStride[0],
1647 dst[1] + (srcSliceY >> 1) * dstStride[1],
1648 dst[2] + (srcSliceY >> 1) * dstStride[2],
1650 dstStride[0], dstStride[1], srcStride[0],
1651 c->input_rgb2yuv_table);
1658 int srcStride[],
int srcSliceY,
int srcSliceH,
1659 uint8_t *dst[],
int dstStride[])
1662 dst[0], dstStride[0]);
1664 planar2x(
src[1], dst[1] + dstStride[1] * (srcSliceY >> 1),
c->chrSrcW,
1665 srcSliceH >> 2, srcStride[1], dstStride[1]);
1666 planar2x(
src[2], dst[2] + dstStride[2] * (srcSliceY >> 1),
c->chrSrcW,
1667 srcSliceH >> 2, srcStride[2], dstStride[2]);
1674 int srcStride[],
int srcSliceY,
1675 int srcSliceH, uint8_t *dst[],
int dstStride[])
1678 ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
1679 const uint8_t *srcPtr =
src[0];
1680 float *dstPtr = (
float *)(dst[0] + dstStride[0] * srcSliceY);
1683 for (x = 0; x <
c->srcW; ++x){
1684 dstPtr[x] =
c->uint2float_lut[srcPtr[x]];
1686 srcPtr += srcStride[0];
1687 dstPtr += dstStrideFloat;
1694 int srcStride[],
int srcSliceY,
1695 int srcSliceH, uint8_t* dst[],
int dstStride[])
1698 ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
1699 const float *srcPtr = (
const float *)
src[0];
1700 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1703 for (x = 0; x <
c->srcW; ++x){
1706 srcPtr += srcStrideFloat;
1707 dstPtr += dstStride[0];
1715 int srcStride[],
int srcSliceY,
int srcSliceH,
1716 uint8_t *dst[],
int dstStride[])
1718 if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
1719 memcpy(dst[0] + dstStride[0] * srcSliceY,
src[0],
srcSliceH * dstStride[0]);
1722 const uint8_t *srcPtr =
src[0];
1723 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1727 while (length +
c->srcW <=
FFABS(dstStride[0]) &&
1728 length +
c->srcW <=
FFABS(srcStride[0]))
1733 memcpy(dstPtr, srcPtr, length);
1734 srcPtr += srcStride[0];
1735 dstPtr += dstStride[0];
1741 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
1742 unsigned shift= src_depth-dst_depth, tmp;\
1743 if (c->dither == SWS_DITHER_NONE) {\
1744 for (i = 0; i < height; i++) {\
1745 for (j = 0; j < length-7; j+=8) {\
1746 dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
1747 dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
1748 dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
1749 dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
1750 dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
1751 dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
1752 dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
1753 dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
1755 for (; j < length; j++) {\
1756 dst[j] = dbswap(bswap(src[j])>>shift);\
1761 } else if (shiftonly) {\
1762 for (i = 0; i < height; i++) {\
1763 const uint8_t *dither= dithers[shift-1][i&7];\
1764 for (j = 0; j < length-7; j+=8) {\
1765 tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
1766 tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
1767 tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
1768 tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
1769 tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
1770 tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
1771 tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
1772 tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
1774 for (; j < length; j++) {\
1775 tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
1781 for (i = 0; i < height; i++) {\
1782 const uint8_t *dither= dithers[shift-1][i&7];\
1783 for (j = 0; j < length-7; j+=8) {\
1784 tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
1785 tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
1786 tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
1787 tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
1788 tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
1789 tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
1790 tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
1791 tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
1793 for (; j < length; j++) {\
1794 tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
1802 int srcStride[],
int srcSliceY,
int srcSliceH,
1803 uint8_t *dst[],
int dstStride[])
1808 for (plane = 0; plane < 4 && dst[plane] !=
NULL; plane++) {
1809 int length = (plane == 0 || plane == 3) ?
c->srcW :
AV_CEIL_RSHIFT(
c->srcW,
c->chrDstHSubSample);
1810 int y = (plane == 0 || plane == 3) ? srcSliceY:
AV_CEIL_RSHIFT(srcSliceY,
c->chrDstVSubSample);
1812 const uint8_t *srcPtr =
src[plane];
1813 uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
1814 int shiftonly = plane == 1 || plane == 2 || (!
c->srcRange && plane == 0);
1817 if (plane == 1 && !dst[2])
continue;
1818 if (!
src[plane] || (plane == 1 && !
src[2])) {
1821 plane == 3, desc_dst->
comp[plane].
depth,
1822 isBE(
c->dstFormat));
1825 (plane == 3) ? 255 : 128);
1831 const int src_depth = desc_src->
comp[plane].
depth;
1832 const int dst_depth = desc_dst->
comp[plane].
depth;
1833 const uint16_t *srcPtr2 = (
const uint16_t *) srcPtr;
1834 uint16_t *dstPtr2 = (uint16_t*)dstPtr;
1836 if (dst_depth == 8) {
1837 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN){
1838 DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
1842 }
else if (src_depth == 8) {
1846 for (j = 0; j < length; j++)\
1847 w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
1849 for (j = 0; j < length; j++)\
1850 w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
1851 (srcPtr[j]>>(2*8-dst_depth)));\
1853 if(
isBE(
c->dstFormat)){
1858 dstPtr2 += dstStride[plane]/2;
1859 srcPtr += srcStride[plane];
1861 }
else if (src_depth <= dst_depth) {
1864 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN &&
1865 isBE(
c->dstFormat) == HAVE_BIGENDIAN &&
1867 unsigned shift = dst_depth - src_depth;
1869 #define FAST_COPY_UP(shift) \
1870 for (; j < length - 3; j += 4) { \
1871 uint64_t v = AV_RN64A(srcPtr2 + j); \
1872 AV_WN64A(dstPtr2 + j, v << shift); \
1875 #define FAST_COPY_UP(shift) \
1876 for (; j < length - 1; j += 2) { \
1877 uint32_t v = AV_RN32A(srcPtr2 + j); \
1878 AV_WN32A(dstPtr2 + j, v << shift); \
1887 #define COPY_UP(r,w) \
1889 for (; j < length; j++){ \
1890 unsigned int v= r(&srcPtr2[j]);\
1891 w(&dstPtr2[j], v<<(dst_depth-src_depth));\
1894 for (; j < length; j++){ \
1895 unsigned int v= r(&srcPtr2[j]);\
1896 w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
1897 (v>>(2*src_depth-dst_depth)));\
1900 if(
isBE(
c->srcFormat)){
1901 if(
isBE(
c->dstFormat)){
1907 if(
isBE(
c->dstFormat)){
1913 dstPtr2 += dstStride[plane]/2;
1914 srcPtr2 += srcStride[plane]/2;
1917 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN){
1918 if(
isBE(
c->dstFormat) == HAVE_BIGENDIAN){
1919 DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
1924 if(
isBE(
c->dstFormat) == HAVE_BIGENDIAN){
1935 for (j = 0; j < length; j++)
1936 ((uint16_t *) dstPtr)[j] =
av_bswap16(((
const uint16_t *) srcPtr)[j]);
1937 srcPtr += srcStride[plane];
1938 dstPtr += dstStride[plane];
1943 for (j = 0; j < length; j++)
1944 ((uint32_t *) dstPtr)[j] =
av_bswap32(((
const uint32_t *) srcPtr)[j]);
1945 srcPtr += srcStride[plane];
1946 dstPtr += dstStride[plane];
1948 }
else if (dstStride[plane] == srcStride[plane] &&
1949 srcStride[plane] > 0 && srcStride[plane] == length) {
1950 memcpy(dst[plane] + dstStride[plane] * y,
src[plane],
1951 height * dstStride[plane]);
1958 memcpy(dstPtr, srcPtr, length);
1959 srcPtr += srcStride[plane];
1960 dstPtr += dstStride[plane];
1969 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
1970 ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
1971 (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
1978 const int flags =
c->flags;
1979 const int dstH =
c->dstH;
1980 const int dstW =
c->dstW;
1984 c->dstFormatBpp < 24 &&
2012 c->dst_slice_align = 2;
2032 c->dst_slice_align = 4;
2051 #define isByteRGB(f) ( \
2052 f == AV_PIX_FMT_RGB32 || \
2053 f == AV_PIX_FMT_RGB32_1 || \
2054 f == AV_PIX_FMT_RGB24 || \
2055 f == AV_PIX_FMT_BGR32 || \
2056 f == AV_PIX_FMT_BGR32_1 || \
2057 f == AV_PIX_FMT_BGR24)
2098 c->dst_slice_align = 2;
2207 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
2216 c->chrDstHSubSample ==
c->chrSrcHSubSample &&
2217 c->chrDstVSubSample ==
c->chrSrcVSubSample &&
2237 int num_pixels,
const uint8_t *palette)
2241 for (
i = 0;
i < num_pixels;
i++)
2242 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i]];
2247 int num_pixels,
const uint8_t *palette)
2251 for (
i = 0;
i < num_pixels;
i++) {
2253 dst[0] = palette[
src[
i] * 4 + 0];
2254 dst[1] = palette[
src[
i] * 4 + 1];
2255 dst[2] = palette[
src[
i] * 4 + 2];