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,},
126 int srcSliceY,
int srcSliceH,
int width,
129 dst += dstStride * srcSliceY;
130 if (dstStride == srcStride && srcStride > 0) {
131 memcpy(dst,
src, srcSliceH * dstStride);
134 for (
i = 0;
i < srcSliceH;
i++) {
143 int srcStride[],
int srcSliceY,
144 int srcSliceH,
uint8_t *dstParam[],
147 uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2;
149 copyPlane(
src[0], srcStride[0], srcSliceY, srcSliceH,
c->srcW,
150 dstParam[0], dstStride[0]);
154 srcStride[1], srcStride[2], dstStride[1]);
157 srcStride[2], srcStride[1], dstStride[1]);
163 int srcStride[],
int srcSliceY,
164 int srcSliceH,
uint8_t *dstParam[],
167 uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
168 uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
170 copyPlane(
src[0], srcStride[0], srcSliceY, srcSliceH,
c->srcW,
171 dstParam[0], dstStride[0]);
175 srcStride[1], dstStride[1], dstStride[2]);
178 srcStride[1], dstStride[2], dstStride[1]);
184 int srcStride[],
int srcSliceY,
185 int srcSliceH,
uint8_t *dstParam[],
188 uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY;
190 copyPlane(
src[0], srcStride[0], srcSliceY, srcSliceH,
c->srcW,
191 dstParam[0], dstStride[0]);
195 srcStride[1], srcStride[2], dstStride[1]);
198 srcStride[2], srcStride[1], dstStride[1]);
204 int srcStride[],
int srcSliceY,
205 int srcSliceH,
uint8_t *dstParam[],
208 uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY;
209 uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY;
211 copyPlane(
src[0], srcStride[0], srcSliceY, srcSliceH,
c->srcW,
212 dstParam[0], dstStride[0]);
216 srcStride[1], dstStride[1], dstStride[2]);
219 srcStride[1], dstStride[2], dstStride[1]);
225 int srcStride[],
int srcSliceY,
226 int srcSliceH,
uint8_t *dstParam8[],
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));
249 for (y = 0; y < srcSliceH; y++) {
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,
286 int srcSliceH,
uint8_t *dstParam8[],
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));
295 for (y = 0; y < srcSliceH; y++) {
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]);
386 fillPlane(dstParam[3], dstStride[3],
c->srcW, srcSliceH, srcSliceY, 255);
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]);
417 fillPlane(dstParam[3], dstStride[3],
c->srcW, srcSliceH, srcSliceY, 255);
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;
482 for (
i = 0;
i < (srcSliceH >>
c->chrDstVSubSample);
i++) {
483 for (j = 0; j < min_stride; j++) {
495 int srcSliceY,
int srcSliceH,
uint8_t *dst[],
503 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
530 for (
i = 0;
i < srcSliceH;
i++) {
532 srcPtr += srcStride[0];
533 dstPtr += dstStride[0];
541 uint16_t *dst[],
int dstStride[],
int srcSliceH,
542 int src_alpha,
int swap,
int shift,
int width)
545 int dst_alpha = dst[3] !=
NULL;
546 for (
h = 0;
h < srcSliceH;
h++) {
547 uint16_t *src_line = (uint16_t *)(
src + srcStride *
h);
550 if (src_alpha && dst_alpha) {
551 for (x = 0; x <
width; x++) {
557 }
else if (dst_alpha) {
558 for (x = 0; x <
width; x++) {
564 }
else if (src_alpha) {
565 for (x = 0; x <
width; x++) {
572 for (x = 0; x <
width; x++) {
580 if (src_alpha && dst_alpha) {
581 for (x = 0; x <
width; x++) {
587 }
else if (dst_alpha) {
588 for (x = 0; x <
width; x++) {
594 }
else if (src_alpha) {
595 for (x = 0; x <
width; x++) {
602 for (x = 0; x <
width; x++) {
610 if (src_alpha && dst_alpha) {
611 for (x = 0; x <
width; x++) {
617 }
else if (dst_alpha) {
618 for (x = 0; x <
width; x++) {
624 }
else if (src_alpha) {
625 for (x = 0; x <
width; x++) {
632 for (x = 0; x <
width; x++) {
640 if (src_alpha && dst_alpha) {
641 for (x = 0; x <
width; x++) {
642 dst[0][x] = *src_line++ >>
shift;
643 dst[1][x] = *src_line++ >>
shift;
644 dst[2][x] = *src_line++ >>
shift;
645 dst[3][x] = *src_line++ >>
shift;
647 }
else if (dst_alpha) {
648 for (x = 0; x <
width; x++) {
649 dst[0][x] = *src_line++ >>
shift;
650 dst[1][x] = *src_line++ >>
shift;
651 dst[2][x] = *src_line++ >>
shift;
654 }
else if (src_alpha) {
655 for (x = 0; x <
width; x++) {
656 dst[0][x] = *src_line++ >>
shift;
657 dst[1][x] = *src_line++ >>
shift;
658 dst[2][x] = *src_line++ >>
shift;
662 for (x = 0; x <
width; x++) {
663 dst[0][x] = *src_line++ >>
shift;
664 dst[1][x] = *src_line++ >>
shift;
665 dst[2][x] = *src_line++ >>
shift;
669 for (
i = 0;
i < 4;
i++)
670 dst[
i] += dstStride[
i] >> 1;
675 int srcStride[],
int srcSliceY,
int srcSliceH,
676 uint8_t *dst[],
int dstStride[])
678 uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
679 uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
680 int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
681 int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
699 src_format->
name, dst_format->
name);
704 dst2013[
i] += stride2013[
i] * srcSliceY / 2;
705 dst1023[
i] += stride1023[
i] * srcSliceY / 2;
708 switch (
c->srcFormat) {
714 dst2013, stride2013, srcSliceH,
alpha, swap,
722 dst1023, stride1023, srcSliceH,
alpha, swap,
727 "unsupported conversion to planar RGB %s -> %s\n",
728 src_format->
name, dst_format->
name);
735 uint8_t *dst,
int dstStride,
int srcSliceH,
739 int src_alpha =
src[3] !=
NULL;
740 int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
741 for (
h = 0;
h < srcSliceH;
h++) {
742 uint16_t *dest = (uint16_t *)(dst + dstStride *
h);
747 if (
alpha && !src_alpha) {
748 for (x = 0; x <
width; x++) {
750 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
752 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
754 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
757 }
else if (
alpha && src_alpha) {
758 for (x = 0; x <
width; x++) {
760 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
762 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
764 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
766 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
769 for (x = 0; x <
width; x++) {
771 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
773 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
775 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
780 if (
alpha && !src_alpha) {
781 for (x = 0; x <
width; x++) {
787 }
else if (
alpha && src_alpha) {
788 for (x = 0; x <
width; x++) {
795 for (x = 0; x <
width; x++) {
803 if (
alpha && !src_alpha) {
804 for (x = 0; x <
width; x++) {
810 }
else if (
alpha && src_alpha) {
811 for (x = 0; x <
width; x++) {
818 for (x = 0; x <
width; x++) {
826 if (
alpha && !src_alpha) {
827 for (x = 0; x <
width; x++) {
828 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
829 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
830 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
833 }
else if (
alpha && src_alpha) {
834 for (x = 0; x <
width; x++) {
835 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
836 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
837 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
838 *dest++ =
src[3][x] << scale_high |
src[3][x] >> scale_low;
841 for (x = 0; x <
width; x++) {
842 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
843 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
844 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
848 for (
i = 0;
i < 3 + src_alpha;
i++)
849 src[
i] += srcStride[
i] >> 1;
854 int srcStride[],
int srcSliceY,
int srcSliceH,
855 uint8_t *dst[],
int dstStride[])
857 const uint16_t *src102[] = { (uint16_t *)
src[1], (uint16_t *)
src[0], (uint16_t *)
src[2], (uint16_t *)
src[3] };
858 const uint16_t *src201[] = { (uint16_t *)
src[2], (uint16_t *)
src[0], (uint16_t *)
src[1], (uint16_t *)
src[3] };
859 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
860 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
863 int bits_per_sample = src_format->
comp[0].
depth;
874 bits_per_sample <= 8) {
876 src_format->
name, dst_format->
name);
879 switch (
c->dstFormat) {
883 dst[0] + srcSliceY * dstStride[0], dstStride[0],
884 srcSliceH, 0, swap, bits_per_sample,
c->srcW);
889 dst[0] + srcSliceY * dstStride[0], dstStride[0],
890 srcSliceH, 0, swap, bits_per_sample,
c->srcW);
895 dst[0] + srcSliceY * dstStride[0], dstStride[0],
896 srcSliceH, 1, swap, bits_per_sample,
c->srcW);
901 dst[0] + srcSliceY * dstStride[0], dstStride[0],
902 srcSliceH, 1, swap, bits_per_sample,
c->srcW);
906 "unsupported planar RGB conversion %s -> %s\n",
907 src_format->
name, dst_format->
name);
914 uint8_t *dst,
int dstStride,
int srcSliceH,
918 for (
h = 0;
h < srcSliceH;
h++) {
919 uint8_t *dest = dst + dstStride *
h;
920 for (x = 0; x <
width; x++) {
926 for (
i = 0;
i < 3;
i++)
927 src[
i] += srcStride[
i];
932 uint8_t *dst,
int dstStride,
int srcSliceH,
933 int alpha_first,
int width)
936 for (
h = 0;
h < srcSliceH;
h++) {
937 uint8_t *dest = dst + dstStride *
h;
940 for (x = 0; x <
width; x++) {
947 for (x = 0; x <
width; x++) {
955 for (
i = 0;
i < 3;
i++)
956 src[
i] += srcStride[
i];
961 uint8_t *dst,
int dstStride,
int srcSliceH,
962 int alpha_first,
int width)
965 for (
h = 0;
h < srcSliceH;
h++) {
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 < 4;
i++)
985 src[
i] += srcStride[
i];
990 int srcStride[],
int srcSliceY,
int srcSliceH,
991 uint8_t *dst[],
int dstStride[])
996 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
997 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1006 switch (
c->dstFormat) {
1009 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1010 srcSliceH,
c->srcW);
1015 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1016 srcSliceH,
c->srcW);
1023 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1024 srcSliceH, alpha_first,
c->srcW);
1031 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1032 srcSliceH, alpha_first,
c->srcW);
1037 "unsupported planar RGB conversion %s -> %s\n",
1046 int srcStride[],
int srcSliceY,
int srcSliceH,
1047 uint8_t *dst[],
int dstStride[])
1049 int alpha_first = 0;
1052 int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
1053 int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
1062 switch (
c->dstFormat) {
1065 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1066 srcSliceH,
c->srcW);
1071 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1072 srcSliceH,
c->srcW);
1079 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1080 srcSliceH, alpha_first,
c->srcW);
1087 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1088 srcSliceH, alpha_first,
c->srcW);
1093 "unsupported planar RGB conversion %s -> %s\n",
1103 int srcSliceY,
int srcSliceH,
1104 uint8_t *dst[],
int dstStride[])
1106 copyPlane(
src[0], srcStride[0], srcSliceY, srcSliceH,
c->srcW,
1107 dst[0], dstStride[0]);
1108 copyPlane(
src[1], srcStride[1], srcSliceY, srcSliceH,
c->srcW,
1109 dst[1], dstStride[1]);
1110 copyPlane(
src[2], srcStride[2], srcSliceY, srcSliceH,
c->srcW,
1111 dst[2], dstStride[2]);
1113 fillPlane(dst[3], dstStride[3],
c->srcW, srcSliceH, srcSliceY, 255);
1119 uint8_t *dst[],
int dstStride[],
int srcSliceH,
1120 int alpha_first,
int inc_size,
int width)
1132 for (
h = 0;
h < srcSliceH;
h++) {
1133 for (x = 0; x <
width; x++) {
1134 dest[0][x] =
src[0];
1135 dest[1][x] =
src[1];
1136 dest[2][x] =
src[2];
1140 src += srcStride -
width * inc_size;
1141 dest[0] += dstStride[0];
1142 dest[1] += dstStride[1];
1143 dest[2] += dstStride[2];
1148 int srcStride[],
int srcSliceY,
int srcSliceH,
1149 uint8_t *dst[],
int dstStride[])
1151 int alpha_first = 0;
1152 int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1153 int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1154 uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
1155 dst[0] + srcSliceY * dstStride[0],
1156 dst[2] + srcSliceY * dstStride[2] };
1157 uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
1158 dst[0] + srcSliceY * dstStride[0],
1159 dst[1] + srcSliceY * dstStride[1] };
1161 switch (
c->srcFormat) {
1164 stride201, srcSliceH, alpha_first, 3,
c->srcW);
1168 stride102, srcSliceH, alpha_first, 3,
c->srcW);
1174 stride201, srcSliceH, alpha_first, 4,
c->srcW);
1180 stride102, srcSliceH, alpha_first, 4,
c->srcW);
1184 "unsupported planar RGB conversion %s -> %s\n",
1194 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1199 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1204 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1209 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1214 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1219 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1224 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1229 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1234 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1239 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1244 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1249 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1253 int srcSliceH,
uint8_t* dst[],
int dstStride[])
1255 uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1261 switch(
c->srcFormat) {
1262 #define CASE(pixfmt, prefix) \
1263 case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1264 interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1284 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1285 srcPtr += 2 * srcStride[0];
1286 dstPtr += 2 * dstStride[0];
1288 for (
i = 2;
i < srcSliceH - 2;
i += 2) {
1289 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1290 srcPtr += 2 * srcStride[0];
1291 dstPtr += 2 * dstStride[0];
1294 if (
i + 1 == srcSliceH) {
1295 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->srcW);
1296 }
else if (
i < srcSliceH)
1297 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->srcW);
1302 int srcSliceH,
uint8_t* dst[],
int dstStride[])
1306 uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
1307 uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
1312 switch(
c->srcFormat) {
1313 #define CASE(pixfmt, prefix) \
1314 case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1315 interpolate = bayer_##prefix##_to_yv12_interpolate; \
1335 copy(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1336 srcPtr += 2 * srcStride[0];
1337 dstY += 2 * dstStride[0];
1338 dstU += dstStride[1];
1339 dstV += dstStride[1];
1341 for (
i = 2;
i < srcSliceH - 2;
i += 2) {
1342 interpolate(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1343 srcPtr += 2 * srcStride[0];
1344 dstY += 2 * dstStride[0];
1345 dstU += dstStride[1];
1346 dstV += dstStride[1];
1349 if (
i + 1 == srcSliceH) {
1350 copy(srcPtr, -srcStride[0],
dstY, dstU, dstV, -dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1351 }
else if (
i < srcSliceH)
1352 copy(srcPtr, srcStride[0],
dstY, dstU, dstV, dstStride[0],
c->srcW,
c->input_rgb2yuv_table);
1356 #define isRGBA32(x) ( \
1357 (x) == AV_PIX_FMT_ARGB \
1358 || (x) == AV_PIX_FMT_RGBA \
1359 || (x) == AV_PIX_FMT_BGRA \
1360 || (x) == AV_PIX_FMT_ABGR \
1363 #define isRGBA64(x) ( \
1364 (x) == AV_PIX_FMT_RGBA64LE \
1365 || (x) == AV_PIX_FMT_RGBA64BE \
1366 || (x) == AV_PIX_FMT_BGRA64LE \
1367 || (x) == AV_PIX_FMT_BGRA64BE \
1370 #define isRGB48(x) ( \
1371 (x) == AV_PIX_FMT_RGB48LE \
1372 || (x) == AV_PIX_FMT_RGB48BE \
1373 || (x) == AV_PIX_FMT_BGR48LE \
1374 || (x) == AV_PIX_FMT_BGR48BE \
1383 const int srcId =
c->srcFormatBpp;
1384 const int dstId =
c->dstFormatBpp;
1387 #define IS_NOT_NE(bpp, desc) \
1388 (((bpp + 7) >> 3) == 2 && \
1389 (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1391 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1411 else if (
CONV_IS(RGB48LE, BGR48BE)
1416 if (
CONV_IS(RGB48LE, BGRA64LE)
1420 else if (
CONV_IS(RGB48LE, BGRA64BE)
1424 if (
CONV_IS(RGB48LE, RGBA64LE)
1428 else if (
CONV_IS(RGB48LE, RGBA64BE)
1433 if (
CONV_IS(RGBA64LE, BGR48LE)
1437 else if (
CONV_IS(RGBA64LE, BGR48BE)
1441 else if (
CONV_IS(RGBA64LE, RGB48LE)
1445 else if (
CONV_IS(RGBA64LE, RGB48BE)
1453 switch (srcId | (dstId << 16)) {
1470 switch (srcId | (dstId << 16)) {
1503 int srcSliceY,
int srcSliceH,
uint8_t *dst[],
1511 const int srcBpp = (
c->srcFormatBpp + 7) >> 3;
1512 const int dstBpp = (
c->dstFormatBpp + 7) >> 3;
1521 int src_bswap =
IS_NOT_NE(
c->srcFormatBpp, desc_src);
1522 int dst_bswap =
IS_NOT_NE(
c->dstFormatBpp, desc_dst);
1532 for (
i = 0;
i < srcSliceH;
i++)
1533 dstPtr[dstStride[0] * (srcSliceY +
i)] = 255;
1537 if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1538 !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1539 conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1540 (srcSliceH - 1) * srcStride[0] +
c->srcW * srcBpp);
1543 dstPtr += dstStride[0] * srcSliceY;
1545 for (
i = 0;
i < srcSliceH;
i++) {
1547 for(j=0; j<
c->srcW; j++)
1548 ((uint16_t*)
c->formatConvBuffer)[j] =
av_bswap16(((uint16_t*)srcPtr)[j]);
1549 conv(
c->formatConvBuffer, dstPtr,
c->srcW * srcBpp);
1551 conv(srcPtr, dstPtr,
c->srcW * srcBpp);
1553 for(j=0; j<
c->srcW; j++)
1554 ((uint16_t*)dstPtr)[j] =
av_bswap16(((uint16_t*)dstPtr)[j]);
1555 srcPtr += srcStride[0];
1556 dstPtr += dstStride[0];
1564 int srcStride[],
int srcSliceY,
int srcSliceH,
1565 uint8_t *dst[],
int dstStride[])
1569 dst[0] + srcSliceY * dstStride[0],
1570 dst[1] + (srcSliceY >> 1) * dstStride[1],
1571 dst[2] + (srcSliceY >> 1) * dstStride[2],
1573 dstStride[0], dstStride[1], srcStride[0],
1574 c->input_rgb2yuv_table);
1576 fillPlane(dst[3], dstStride[3],
c->srcW, srcSliceH, srcSliceY, 255);
1581 int srcStride[],
int srcSliceY,
int srcSliceH,
1582 uint8_t *dst[],
int dstStride[])
1584 copyPlane(
src[0], srcStride[0], srcSliceY, srcSliceH,
c->srcW,
1585 dst[0], dstStride[0]);
1587 planar2x(
src[1], dst[1] + dstStride[1] * (srcSliceY >> 1),
c->chrSrcW,
1588 srcSliceH >> 2, srcStride[1], dstStride[1]);
1589 planar2x(
src[2], dst[2] + dstStride[2] * (srcSliceY >> 1),
c->chrSrcW,
1590 srcSliceH >> 2, srcStride[2], dstStride[2]);
1592 fillPlane(dst[3], dstStride[3],
c->srcW, srcSliceH, srcSliceY, 255);
1597 int srcStride[],
int srcSliceY,
1598 int srcSliceH,
uint8_t *dst[],
int dstStride[])
1601 ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
1603 float *dstPtr = (
float *)(dst[0] + dstStride[0] * srcSliceY);
1605 for (y = 0; y < srcSliceH; ++y){
1606 for (x = 0; x <
c->srcW; ++x){
1607 dstPtr[x] =
c->uint2float_lut[srcPtr[x]];
1609 srcPtr += srcStride[0];
1610 dstPtr += dstStrideFloat;
1617 int srcStride[],
int srcSliceY,
1618 int srcSliceH,
uint8_t* dst[],
int dstStride[])
1621 ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
1622 const float *srcPtr = (
const float *)
src[0];
1623 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1625 for (y = 0; y < srcSliceH; ++y){
1626 for (x = 0; x <
c->srcW; ++x){
1627 dstPtr[x] = av_clip_uint8(
lrintf(255.0
f * srcPtr[x]));
1629 srcPtr += srcStrideFloat;
1630 dstPtr += dstStride[0];
1638 int srcStride[],
int srcSliceY,
int srcSliceH,
1639 uint8_t *dst[],
int dstStride[])
1641 if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
1642 memcpy(dst[0] + dstStride[0] * srcSliceY,
src[0], srcSliceH * dstStride[0]);
1646 uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1655 for (
i = 0;
i < srcSliceH;
i++) {
1656 memcpy(dstPtr, srcPtr,
length);
1657 srcPtr += srcStride[0];
1658 dstPtr += dstStride[0];
1664 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
1665 unsigned shift= src_depth-dst_depth, tmp;\
1666 if (c->dither == SWS_DITHER_NONE) {\
1667 for (i = 0; i < height; i++) {\
1668 for (j = 0; j < length-7; j+=8) {\
1669 dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
1670 dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
1671 dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
1672 dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
1673 dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
1674 dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
1675 dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
1676 dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
1678 for (; j < length; j++) {\
1679 dst[j] = dbswap(bswap(src[j])>>shift);\
1684 } else if (shiftonly) {\
1685 for (i = 0; i < height; i++) {\
1686 const uint8_t *dither= dithers[shift-1][i&7];\
1687 for (j = 0; j < length-7; j+=8) {\
1688 tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
1689 tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
1690 tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
1691 tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
1692 tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
1693 tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
1694 tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
1695 tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
1697 for (; j < length; j++) {\
1698 tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
1704 for (i = 0; i < height; i++) {\
1705 const uint8_t *dither= dithers[shift-1][i&7];\
1706 for (j = 0; j < length-7; j+=8) {\
1707 tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
1708 tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
1709 tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
1710 tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
1711 tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
1712 tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
1713 tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
1714 tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
1716 for (; j < length; j++) {\
1717 tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
1725 int srcStride[],
int srcSliceY,
int srcSliceH,
1726 uint8_t *dst[],
int dstStride[])
1742 if (
plane == 1 && !dst[2])
continue;
1747 isBE(
c->dstFormat));
1750 (
plane == 3) ? 255 : 128);
1758 const uint16_t *srcPtr2 = (
const uint16_t *) srcPtr;
1759 uint16_t *dstPtr2 = (uint16_t*)dstPtr;
1761 if (dst_depth == 8) {
1762 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN){
1767 }
else if (src_depth == 8) {
1771 for (j = 0; j < length; j++)\
1772 w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
1774 for (j = 0; j < length; j++)\
1775 w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
1776 (srcPtr[j]>>(2*8-dst_depth)));\
1778 if(
isBE(
c->dstFormat)){
1783 dstPtr2 += dstStride[
plane]/2;
1784 srcPtr += srcStride[
plane];
1786 }
else if (src_depth <= dst_depth) {
1789 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN &&
1790 isBE(
c->dstFormat) == HAVE_BIGENDIAN &&
1792 unsigned shift = dst_depth - src_depth;
1794 #define FAST_COPY_UP(shift) \
1795 for (; j < length - 3; j += 4) { \
1796 uint64_t v = AV_RN64A(srcPtr2 + j); \
1797 AV_WN64A(dstPtr2 + j, v << shift); \
1800 #define FAST_COPY_UP(shift) \
1801 for (; j < length - 1; j += 2) { \
1802 uint32_t v = AV_RN32A(srcPtr2 + j); \
1803 AV_WN32A(dstPtr2 + j, v << shift); \
1812 #define COPY_UP(r,w) \
1814 for (; j < length; j++){ \
1815 unsigned int v= r(&srcPtr2[j]);\
1816 w(&dstPtr2[j], v<<(dst_depth-src_depth));\
1819 for (; j < length; j++){ \
1820 unsigned int v= r(&srcPtr2[j]);\
1821 w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
1822 (v>>(2*src_depth-dst_depth)));\
1825 if(
isBE(
c->srcFormat)){
1826 if(
isBE(
c->dstFormat)){
1832 if(
isBE(
c->dstFormat)){
1838 dstPtr2 += dstStride[
plane]/2;
1839 srcPtr2 += srcStride[
plane]/2;
1842 if(
isBE(
c->srcFormat) == HAVE_BIGENDIAN){
1843 if(
isBE(
c->dstFormat) == HAVE_BIGENDIAN){
1849 if(
isBE(
c->dstFormat) == HAVE_BIGENDIAN){
1860 for (j = 0; j <
length; j++)
1861 ((uint16_t *) dstPtr)[j] =
av_bswap16(((
const uint16_t *) srcPtr)[j]);
1862 srcPtr += srcStride[
plane];
1863 dstPtr += dstStride[
plane];
1868 for (j = 0; j <
length; j++)
1869 ((uint32_t *) dstPtr)[j] =
av_bswap32(((
const uint32_t *) srcPtr)[j]);
1870 srcPtr += srcStride[
plane];
1871 dstPtr += dstStride[
plane];
1873 }
else if (dstStride[
plane] == srcStride[
plane] &&
1883 memcpy(dstPtr, srcPtr,
length);
1884 srcPtr += srcStride[
plane];
1885 dstPtr += dstStride[
plane];
1894 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
1895 ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
1896 (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
1903 const int flags =
c->flags;
1904 const int dstH =
c->dstH;
1908 c->dstFormatBpp < 24 &&
1973 #define isByteRGB(f) ( \
1974 f == AV_PIX_FMT_RGB32 || \
1975 f == AV_PIX_FMT_RGB32_1 || \
1976 f == AV_PIX_FMT_RGB24 || \
1977 f == AV_PIX_FMT_BGR32 || \
1978 f == AV_PIX_FMT_BGR32_1 || \
1979 f == AV_PIX_FMT_BGR24)
2120 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
2129 c->chrDstHSubSample ==
c->chrSrcHSubSample &&
2130 c->chrDstVSubSample ==
c->chrSrcVSubSample &&
2149 int num_pixels,
const uint8_t *palette)
2153 for (
i = 0;
i < num_pixels;
i++)
2154 ((uint32_t *) dst)[
i] = ((
const uint32_t *) palette)[
src[
i]];
2159 int num_pixels,
const uint8_t *palette)
2163 for (
i = 0;
i < num_pixels;
i++) {
2165 dst[0] = palette[
src[
i] * 4 + 0];
2166 dst[1] = palette[
src[
i] * 4 + 1];
2167 dst[2] = palette[
src[
i] * 4 + 2];