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;
126 int srcSliceY,
int srcSliceH,
int width,
127 uint8_t *
dst,
int dstStride)
129 dst += dstStride * srcSliceY;
130 if (dstStride == srcStride && srcStride > 0) {
131 memcpy(
dst,
src, srcSliceH * dstStride);
134 for (
i = 0;
i < srcSliceH;
i++) {
143 const int srcStride[],
int srcSliceY,
144 int srcSliceH, uint8_t *
const dstParam[],
145 const int dstStride[])
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 const int srcStride[],
int srcSliceY,
164 int srcSliceH, uint8_t *
const dstParam[],
165 const int dstStride[])
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 const int srcStride[],
int srcSliceY,
185 int srcSliceH, uint8_t *
const dstParam[],
186 const int dstStride[])
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 const int srcStride[],
int srcSliceY,
205 int srcSliceH, uint8_t *
const dstParam[],
206 const int dstStride[])
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 uint8_t *dst2,
int dstStride2,
226 const uint8_t *
src,
int srcStride,
230 const uint8_t *
src2 =
src + srcStride;
232 for (
int y = 0; y <
h; y += 2) {
235 for (
int x = 0; x <
w; x++) {
236 dst1[x] = (
src1[4 * x + 0] +
src1[4 * x + 2] +
237 src2[4 * x + 0] +
src2[4 * x + 2]) >> 2;
238 dst2[x] = (
src1[4 * x + 1] +
src1[4 * x + 3] +
239 src2[4 * x + 1] +
src2[4 * x + 3]) >> 2;
241 src1 += srcStride * 2;
242 src2 += srcStride * 2;
249 const int srcStride[],
int srcSliceY,
int srcSliceH,
250 uint8_t *
const dstParam[],
const int dstStride[])
252 uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
253 uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
256 dstParam[0], dstStride[0]);
260 src[1], srcStride[1],
c->opts.src_w / 2, srcSliceH);
263 src[1], srcStride[1],
c->opts.src_w / 2, srcSliceH);
269 const int srcStride[],
int srcSliceY,
270 int srcSliceH, uint8_t *
const dstParam8[],
271 const int dstStride[])
275 const uint16_t **
src = (
const uint16_t**)src8;
276 uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
277 uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
281 const int shift[3] = {
290 av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
291 dstStride[0] % 2 || dstStride[1] % 2));
293 for (y = 0; y < srcSliceH; y++) {
294 uint16_t *tdstY = dstY;
295 const uint16_t *tsrc0 =
src[0];
296 for (x =
c->opts.src_w; x > 0; x--) {
297 *tdstY++ = *tsrc0++ <<
shift[0];
299 src[0] += srcStride[0] / 2;
300 dstY += dstStride[0] / 2;
303 uint16_t *tdstUV = dstUV;
304 const uint16_t *tsrc1 =
src[1];
305 const uint16_t *tsrc2 =
src[2];
306 for (x =
c->opts.src_w / 2; x > 0; x--) {
307 *tdstUV++ = *tsrc1++ <<
shift[1];
308 *tdstUV++ = *tsrc2++ <<
shift[2];
310 src[1] += srcStride[1] / 2;
311 src[2] += srcStride[2] / 2;
312 dstUV += dstStride[1] / 2;
319 #if AV_HAVE_BIGENDIAN
320 #define output_pixel(p, v) do { \
321 uint16_t *pp = (p); \
325 #define output_pixel(p, v) (*p) = (v)
329 const int srcStride[],
int srcSliceY,
330 int srcSliceH, uint8_t *
const dstParam8[],
331 const int dstStride[])
334 uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
335 uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
338 av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
340 for (y = 0; y < srcSliceH; y++) {
341 uint16_t *tdstY = dstY;
342 const uint8_t *tsrc0 =
src0;
343 for (x =
c->opts.src_w; x > 0; x--) {
347 src0 += srcStride[0];
348 dstY += dstStride[0] / 2;
351 uint16_t *tdstUV = dstUV;
352 const uint8_t *tsrc1 =
src1;
353 const uint8_t *tsrc2 =
src2;
354 for (x =
c->opts.src_w / 2; x > 0; x--) {
360 src1 += srcStride[1];
361 src2 += srcStride[2];
362 dstUV += dstStride[1] / 2;
372 const int srcStride[],
int srcSliceY,
int srcSliceH,
373 uint8_t *
const dstParam[],
const int dstStride[])
375 uint8_t *
dst = dstParam[0] + dstStride[0] * srcSliceY;
378 srcStride[1], dstStride[0]);
384 const int srcStride[],
int srcSliceY,
int srcSliceH,
385 uint8_t *
const dstParam[],
const int dstStride[])
387 uint8_t *
dst = dstParam[0] + dstStride[0] * srcSliceY;
390 srcStride[1], dstStride[0]);
396 const int srcStride[],
int srcSliceY,
int srcSliceH,
397 uint8_t *
const dstParam[],
const int dstStride[])
399 uint8_t *
dst = dstParam[0] + dstStride[0] * srcSliceY;
402 srcStride[1], dstStride[0]);
408 const int srcStride[],
int srcSliceY,
int srcSliceH,
409 uint8_t *
const dstParam[],
const int dstStride[])
411 uint8_t *
dst = dstParam[0] + dstStride[0] * srcSliceY;
414 srcStride[1], dstStride[0]);
420 const int srcStride[],
int srcSliceY,
int srcSliceH,
421 uint8_t *
const dstParam[],
const int dstStride[])
423 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
424 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
425 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
427 yuyvtoyuv420(ydst, udst, vdst,
src[0],
c->opts.src_w, srcSliceH, dstStride[0],
428 dstStride[1], srcStride[0]);
431 fillPlane(dstParam[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
437 const int srcStride[],
int srcSliceY,
int srcSliceH,
438 uint8_t *
const dstParam[],
const int dstStride[])
440 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
441 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
442 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
444 yuyvtoyuv422(ydst, udst, vdst,
src[0],
c->opts.src_w, srcSliceH, dstStride[0],
445 dstStride[1], srcStride[0]);
451 const int srcStride[],
int srcSliceY,
int srcSliceH,
452 uint8_t *
const dstParam[],
const int dstStride[])
454 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
455 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
456 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
458 uyvytoyuv420(ydst, udst, vdst,
src[0],
c->opts.src_w, srcSliceH, dstStride[0],
459 dstStride[1], srcStride[0]);
462 fillPlane(dstParam[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
468 const int srcStride[],
int srcSliceY,
int srcSliceH,
469 uint8_t *
const dstParam[],
const int dstStride[])
471 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
472 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
473 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
475 uyvytoyuv422(ydst, udst, vdst,
src[0],
c->opts.src_w, srcSliceH, dstStride[0],
476 dstStride[1], srcStride[0]);
482 const uint8_t *palette)
485 for (
i = 0;
i < num_pixels;
i++)
486 ((uint32_t *)
dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] | (
src[(
i << 1) + 1] << 24);
490 const uint8_t *palette)
494 for (
i = 0;
i < num_pixels;
i++)
495 ((uint32_t *)
dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] |
src[(
i << 1) + 1];
499 const uint8_t *palette)
503 for (
i = 0;
i < num_pixels;
i++) {
505 dst[0] = palette[
src[
i << 1] * 4 + 0];
506 dst[1] = palette[
src[
i << 1] * 4 + 1];
507 dst[2] = palette[
src[
i << 1] * 4 + 2];
513 const int srcStride[],
int srcSliceY,
int srcSliceH,
514 uint8_t *
const dst[],
const int dstStride[])
518 for (p = 0; p < 4; p++) {
519 int srcstr = srcStride[p] / 2;
520 int dststr = dstStride[p] / 2;
521 uint16_t *dstPtr = (uint16_t *)
dst[p];
522 const uint16_t *srcPtr = (
const uint16_t *)
src[p];
524 if(!dstPtr || !srcPtr)
526 dstPtr += (srcSliceY >>
c->chrDstVSubSample) * dststr;
527 for (
i = 0;
i < (srcSliceH >>
c->chrDstVSubSample);
i++) {
528 for (j = 0; j < min_stride; j++) {
540 const int srcStride[],
int srcSliceY,
int srcSliceH,
541 uint8_t *
const dst[],
const int dstStride[])
545 for (p = 0; p < 4; p++) {
546 int srcstr = srcStride[p] / 4;
547 int dststr = dstStride[p] / 4;
548 uint32_t *dstPtr = (uint32_t *)
dst[p];
549 const uint32_t *srcPtr = (
const uint32_t *)
src[p];
551 if(!dstPtr || !srcPtr)
553 dstPtr += (srcSliceY >>
c->chrDstVSubSample) * dststr;
554 for (
i = 0;
i < (srcSliceH >>
c->chrDstVSubSample);
i++) {
555 for (j = 0; j < min_stride; j++) {
568 int srcSliceY,
int srcSliceH, uint8_t *
const dst[],
569 const int dstStride[])
573 void (*
conv)(
const uint8_t *
src, uint8_t *
dst,
int num_pixels,
574 const uint8_t *palette) =
NULL;
576 uint8_t *dstPtr =
dst[0] + dstStride[0] * srcSliceY;
577 const uint8_t *srcPtr =
src[0];
588 }
else if (
usePal(srcFormat)) {
603 for (
i = 0;
i < srcSliceH;
i++) {
604 conv(srcPtr, dstPtr,
c->opts.src_w, (uint8_t *)
c->pal_rgb);
605 srcPtr += srcStride[0];
606 dstPtr += dstStride[0];
614 uint16_t *
dst[],
const int dstStride[],
int srcSliceH,
615 int src_alpha,
int swap,
int shift,
int width)
618 int dst_alpha =
dst[3] !=
NULL;
619 for (
h = 0;
h < srcSliceH;
h++) {
620 uint16_t *src_line = (uint16_t *)(
src + srcStride *
h);
623 if (src_alpha && dst_alpha) {
624 for (x = 0; x <
width; x++) {
630 }
else if (dst_alpha) {
631 for (x = 0; x <
width; x++) {
637 }
else if (src_alpha) {
638 for (x = 0; x <
width; x++) {
645 for (x = 0; x <
width; x++) {
653 if (src_alpha && dst_alpha) {
654 for (x = 0; x <
width; x++) {
660 }
else if (dst_alpha) {
661 for (x = 0; x <
width; x++) {
667 }
else if (src_alpha) {
668 for (x = 0; x <
width; x++) {
675 for (x = 0; x <
width; x++) {
683 if (src_alpha && dst_alpha) {
684 for (x = 0; x <
width; x++) {
690 }
else if (dst_alpha) {
691 for (x = 0; x <
width; x++) {
697 }
else if (src_alpha) {
698 for (x = 0; x <
width; x++) {
705 for (x = 0; x <
width; x++) {
713 if (src_alpha && dst_alpha) {
714 for (x = 0; x <
width; x++) {
720 }
else if (dst_alpha) {
721 for (x = 0; x <
width; x++) {
727 }
else if (src_alpha) {
728 for (x = 0; x <
width; x++) {
735 for (x = 0; x <
width; x++) {
742 for (
i = 0;
i < 4;
i++)
743 dst[
i] += dstStride[
i] >> 1;
748 uint16_t *
dst[],
const int dstStride[],
int srcSliceH,
749 int swap,
int bpc,
int width)
752 int dst_alpha =
dst[3] !=
NULL;
753 int scale_high = bpc - 10, scale_low = 10 - scale_high;
754 for (
h = 0;
h < srcSliceH;
h++) {
755 uint32_t *src_line = (uint32_t *)(
src + srcStride *
h);
762 for (x = 0; x <
width; x++) {
763 unsigned p =
AV_RL32(src_line);
764 component = (p >> 20) & 0x3FF;
765 dst[0][x] =
av_bswap16(component << scale_high | component >> scale_low);
766 component = (p >> 10) & 0x3FF;
767 dst[1][x] =
av_bswap16(component << scale_high | component >> scale_low);
768 component = p & 0x3FF;
769 dst[2][x] =
av_bswap16(component << scale_high | component >> scale_low);
774 for (x = 0; x <
width; x++) {
775 unsigned p =
AV_RL32(src_line);
776 component = (p >> 20) & 0x3FF;
777 dst[0][x] =
av_bswap16(component << scale_high | component >> scale_low);
778 component = (p >> 10) & 0x3FF;
779 dst[1][x] =
av_bswap16(component << scale_high | component >> scale_low);
780 component = p & 0x3FF;
781 dst[2][x] =
av_bswap16(component << scale_high | component >> scale_low);
788 for (x = 0; x <
width; x++) {
789 unsigned p =
AV_RL32(src_line);
790 component = (p >> 20) & 0x3FF;
791 dst[0][x] = component << scale_high | component >> scale_low;
792 component = (p >> 10) & 0x3FF;
793 dst[1][x] = component << scale_high | component >> scale_low;
794 component = p & 0x3FF;
795 dst[2][x] = component << scale_high | component >> scale_low;
800 for (x = 0; x <
width; x++) {
801 unsigned p =
AV_RL32(src_line);
802 component = (p >> 20) & 0x3FF;
803 dst[0][x] = component << scale_high | component >> scale_low;
804 component = (p >> 10) & 0x3FF;
805 dst[1][x] = component << scale_high | component >> scale_low;
806 component = p & 0x3FF;
807 dst[2][x] = component << scale_high | component >> scale_low;
813 for (
i = 0;
i < 4;
i++)
814 dst[
i] += dstStride[
i] >> 1;
819 const int srcStride[],
int srcSliceY,
int srcSliceH,
820 uint8_t *
const dst[],
const int dstStride[])
822 uint16_t *dst2013[] = { (uint16_t *)
dst[2], (uint16_t *)
dst[0], (uint16_t *)
dst[1], (uint16_t *)
dst[3] };
823 uint16_t *dst1023[] = { (uint16_t *)
dst[1], (uint16_t *)
dst[0], (uint16_t *)
dst[2], (uint16_t *)
dst[3] };
824 int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
825 int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
843 src_format->
name, dst_format->
name);
848 dst2013[
i] += stride2013[
i] * srcSliceY / 2;
849 dst1023[
i] += stride1023[
i] * srcSliceY / 2;
852 switch (
c->opts.src_format) {
858 dst2013, stride2013, srcSliceH,
alpha, swap,
859 16 - bpc,
c->opts.src_w);
864 dst2013, stride2013, srcSliceH, swap,
872 dst1023, stride1023, srcSliceH,
alpha, swap,
873 16 - bpc,
c->opts.src_w);
878 dst1023, stride1023, srcSliceH, swap,
883 "unsupported conversion to planar RGB %s -> %s\n",
884 src_format->
name, dst_format->
name);
891 uint8_t *
dst,
int dstStride,
int srcSliceH,
895 int src_alpha =
src[3] !=
NULL;
896 int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
897 for (
h = 0;
h < srcSliceH;
h++) {
898 uint16_t *dest = (uint16_t *)(
dst + dstStride *
h);
903 if (
alpha && !src_alpha) {
904 for (x = 0; x <
width; x++) {
906 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
908 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
910 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
913 }
else if (
alpha && src_alpha) {
914 for (x = 0; x <
width; x++) {
916 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
918 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
920 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
922 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
925 for (x = 0; x <
width; x++) {
927 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
929 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
931 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
936 if (
alpha && !src_alpha) {
937 for (x = 0; x <
width; x++) {
943 }
else if (
alpha && src_alpha) {
944 for (x = 0; x <
width; x++) {
951 for (x = 0; x <
width; x++) {
959 if (
alpha && !src_alpha) {
960 for (x = 0; x <
width; x++) {
966 }
else if (
alpha && src_alpha) {
967 for (x = 0; x <
width; x++) {
974 for (x = 0; x <
width; x++) {
982 if (
alpha && !src_alpha) {
983 for (x = 0; x <
width; x++) {
984 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
985 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
986 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
989 }
else if (
alpha && src_alpha) {
990 for (x = 0; x <
width; x++) {
991 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
992 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
993 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
994 *dest++ =
src[3][x] << scale_high |
src[3][x] >> scale_low;
997 for (x = 0; x <
width; x++) {
998 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
999 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
1000 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
1004 for (
i = 0;
i < 3 + src_alpha;
i++)
1005 src[
i] += srcStride[
i] >> 1;
1010 uint8_t *
dst,
int dstStride,
int srcSliceH,
1011 int swap,
int bpp,
int width)
1014 int shift = bpp - 10;
1016 for (
h = 0;
h < srcSliceH;
h++) {
1017 uint8_t *dest =
dst + dstStride *
h;
1022 for (x = 0; x <
width; x++) {
1026 AV_WL32(dest + 4 * x, (3
U << 30) + (
C0 << 20) + (
C1 << 10) +
C2);
1030 for (x = 0; x <
width; x++) {
1034 AV_WL32(dest + 4 * x, (3
U << 30) + (
C0 << 20) + (
C1 << 10) +
C2);
1038 for (
i = 0;
i < 3;
i++)
1039 src[
i] += srcStride[
i] >> 1;
1045 const int srcStride[],
int srcSliceY,
int srcSliceH,
1046 uint8_t *
const dst[],
const int dstStride[])
1048 const uint16_t *src102[] = { (uint16_t *)
src[1], (uint16_t *)
src[0], (uint16_t *)
src[2], (uint16_t *)
src[3] };
1049 const uint16_t *src201[] = { (uint16_t *)
src[2], (uint16_t *)
src[0], (uint16_t *)
src[1], (uint16_t *)
src[3] };
1050 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
1051 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1054 int bits_per_sample = src_format->
comp[0].
depth;
1065 bits_per_sample <= 8) {
1067 src_format->
name, dst_format->
name);
1070 switch (
c->opts.dst_format) {
1074 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1075 srcSliceH, 0, swap, bits_per_sample,
c->opts.src_w);
1080 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1081 srcSliceH, 0, swap, bits_per_sample,
c->opts.src_w);
1086 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1087 srcSliceH, 1, swap, bits_per_sample,
c->opts.src_w);
1092 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1093 srcSliceH, 1, swap, bits_per_sample,
c->opts.src_w);
1097 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1098 srcSliceH, swap, bits_per_sample,
c->opts.src_w);
1102 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1103 srcSliceH, swap, bits_per_sample,
c->opts.src_w);
1107 "unsupported planar RGB conversion %s -> %s\n",
1108 src_format->
name, dst_format->
name);
1115 uint8_t *
dst,
int dstStride,
int srcSliceH,
1119 for (
h = 0;
h < srcSliceH;
h++) {
1120 uint8_t *dest =
dst + dstStride *
h;
1121 for (x = 0; x <
width; x++) {
1122 *dest++ =
src[0][x];
1123 *dest++ =
src[1][x];
1124 *dest++ =
src[2][x];
1127 for (
i = 0;
i < 3;
i++)
1128 src[
i] += srcStride[
i];
1133 uint8_t *
dst,
int dstStride,
int srcSliceH,
1134 int alpha_first,
int width)
1137 for (
h = 0;
h < srcSliceH;
h++) {
1138 uint8_t *dest =
dst + dstStride *
h;
1141 for (x = 0; x <
width; x++) {
1143 *dest++ =
src[0][x];
1144 *dest++ =
src[1][x];
1145 *dest++ =
src[2][x];
1148 for (x = 0; x <
width; x++) {
1149 *dest++ =
src[0][x];
1150 *dest++ =
src[1][x];
1151 *dest++ =
src[2][x];
1156 for (
i = 0;
i < 3;
i++)
1157 src[
i] += srcStride[
i];
1162 uint8_t *
dst,
int dstStride,
int srcSliceH,
1163 int alpha_first,
int width)
1166 for (
h = 0;
h < srcSliceH;
h++) {
1167 uint8_t *dest =
dst + dstStride *
h;
1170 for (x = 0; x <
width; x++) {
1171 *dest++ =
src[3][x];
1172 *dest++ =
src[0][x];
1173 *dest++ =
src[1][x];
1174 *dest++ =
src[2][x];
1177 for (x = 0; x <
width; x++) {
1178 *dest++ =
src[0][x];
1179 *dest++ =
src[1][x];
1180 *dest++ =
src[2][x];
1181 *dest++ =
src[3][x];
1185 for (
i = 0;
i < 4;
i++)
1186 src[
i] += srcStride[
i];
1191 const int srcStride[],
int srcSliceY,
int srcSliceH,
1192 uint8_t *
const dst[],
const int dstStride[])
1194 int alpha_first = 0;
1195 const uint8_t *src102[] = {
src[1],
src[0],
src[2],
src[3] };
1196 const uint8_t *src201[] = {
src[2],
src[0],
src[1],
src[3] };
1197 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
1198 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1207 switch (
c->opts.dst_format) {
1210 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1211 srcSliceH,
c->opts.src_w);
1216 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1217 srcSliceH,
c->opts.src_w);
1224 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1225 srcSliceH, alpha_first,
c->opts.src_w);
1232 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1233 srcSliceH, alpha_first,
c->opts.src_w);
1238 "unsupported planar RGB conversion %s -> %s\n",
1247 const int srcStride[],
int srcSliceY,
int srcSliceH,
1248 uint8_t *
const dst[],
const int dstStride[])
1250 int alpha_first = 0;
1251 const uint8_t *src102[] = {
src[1],
src[0],
src[2] };
1252 const uint8_t *src201[] = {
src[2],
src[0],
src[1] };
1253 int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
1254 int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
1263 switch (
c->opts.dst_format) {
1266 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1267 srcSliceH,
c->opts.src_w);
1272 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1273 srcSliceH,
c->opts.src_w);
1280 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1281 srcSliceH, alpha_first,
c->opts.src_w);
1288 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1289 srcSliceH, alpha_first,
c->opts.src_w);
1294 "unsupported planar RGB conversion %s -> %s\n",
1303 const uint8_t *
const src[],
const int srcStride[],
1304 int srcSliceY,
int srcSliceH,
1305 uint8_t *
const dst[],
const int dstStride[])
1308 dst[0], dstStride[0]);
1310 dst[1], dstStride[1]);
1312 dst[2], dstStride[2]);
1314 fillPlane(
dst[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
1320 uint8_t *
const dst[],
const int dstStride[],
int srcSliceH,
1321 int alpha_first,
int inc_size,
int width)
1333 for (
h = 0;
h < srcSliceH;
h++) {
1334 for (x = 0; x <
width; x++) {
1335 dest[0][x] =
src[0];
1336 dest[1][x] =
src[1];
1337 dest[2][x] =
src[2];
1341 src += srcStride -
width * inc_size;
1342 dest[0] += dstStride[0];
1343 dest[1] += dstStride[1];
1344 dest[2] += dstStride[2];
1349 const int srcStride[],
int srcSliceY,
int srcSliceH,
1350 uint8_t *
const dst[],
const int dstStride[])
1352 int alpha_first = 0;
1353 int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1354 int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1355 uint8_t *dst102[] = {
dst[1] + srcSliceY * dstStride[1],
1356 dst[0] + srcSliceY * dstStride[0],
1357 dst[2] + srcSliceY * dstStride[2] };
1358 uint8_t *dst201[] = {
dst[2] + srcSliceY * dstStride[2],
1359 dst[0] + srcSliceY * dstStride[0],
1360 dst[1] + srcSliceY * dstStride[1] };
1362 switch (
c->opts.src_format) {
1365 stride201, srcSliceH, alpha_first, 3,
c->opts.src_w);
1369 stride102, srcSliceH, alpha_first, 3,
c->opts.src_w);
1375 stride201, srcSliceH, alpha_first, 4,
c->opts.src_w);
1381 stride102, srcSliceH, alpha_first, 4,
c->opts.src_w);
1385 "unsupported planar RGB conversion %s -> %s\n",
1394 uint8_t *
const dst[],
const int dstStride[],
1395 int srcSliceH,
int width)
1405 for (
h = 0;
h < srcSliceH;
h++) {
1406 for (x = 0; x <
width; x++) {
1407 dest[0][x] =
src[x * 3 + 0];
1408 dest[1][x] =
src[x * 3 + 1];
1409 dest[2][x] =
src[x * 3 + 2];
1413 dest[0] += dstStride[0];
1414 dest[1] += dstStride[1];
1415 dest[2] += dstStride[2];
1416 dest[3] += dstStride[3];
1421 uint8_t *
const dst[],
const int dstStride[],
1422 int srcSliceH,
int alpha_first,
int width)
1432 for (
h = 0;
h < srcSliceH;
h++) {
1434 for (x = 0; x <
width; x++) {
1435 dest[0][x] =
src[x * 4 + 1];
1436 dest[1][x] =
src[x * 4 + 2];
1437 dest[2][x] =
src[x * 4 + 3];
1438 dest[3][x] =
src[x * 4 + 0];
1441 for (x = 0; x <
width; x++) {
1442 dest[0][x] =
src[x * 4 + 0];
1443 dest[1][x] =
src[x * 4 + 1];
1444 dest[2][x] =
src[x * 4 + 2];
1445 dest[3][x] =
src[x * 4 + 3];
1449 dest[0] += dstStride[0];
1450 dest[1] += dstStride[1];
1451 dest[2] += dstStride[2];
1452 dest[3] += dstStride[3];
1457 const int srcStride[],
int srcSliceY,
int srcSliceH,
1458 uint8_t *
const dst[],
const int dstStride[])
1460 int alpha_first = 0;
1461 int stride102[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
1462 int stride201[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
1463 uint8_t *dst102[] = {
dst[1] + srcSliceY * dstStride[1],
1464 dst[0] + srcSliceY * dstStride[0],
1465 dst[2] + srcSliceY * dstStride[2],
1466 dst[3] + srcSliceY * dstStride[3] };
1467 uint8_t *dst201[] = {
dst[2] + srcSliceY * dstStride[2],
1468 dst[0] + srcSliceY * dstStride[0],
1469 dst[1] + srcSliceY * dstStride[1],
1470 dst[3] + srcSliceY * dstStride[3] };
1472 switch (
c->opts.src_format) {
1475 stride201, srcSliceH,
c->opts.src_w);
1479 stride102, srcSliceH,
c->opts.src_w);
1485 stride201, srcSliceH, alpha_first,
c->opts.src_w);
1491 stride102, srcSliceH, alpha_first,
c->opts.src_w);
1495 "unsupported planar RGB conversion %s -> %s\n",
1505 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1510 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1515 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1520 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1525 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1530 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1535 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1540 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1545 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1550 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1555 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1560 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1564 const int srcStride[],
int srcSliceY,
int srcSliceH,
1565 uint8_t *
const dst[],
const int dstStride[])
1567 uint8_t *dstPtr=
dst[0] + srcSliceY * dstStride[0];
1568 const uint8_t *srcPtr=
src[0];
1570 void (*
copy) (
const uint8_t *
src,
int src_stride, uint8_t *
dst,
int dst_stride,
int width);
1573 switch(
c->opts.src_format) {
1574 #define CASE(pixfmt, prefix) \
1575 case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1576 interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1596 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1597 srcPtr += 2 * srcStride[0];
1598 dstPtr += 2 * dstStride[0];
1600 for (
i = 2;
i < srcSliceH - 2;
i += 2) {
1601 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1602 srcPtr += 2 * srcStride[0];
1603 dstPtr += 2 * dstStride[0];
1606 if (
i + 1 == srcSliceH) {
1607 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->opts.src_w);
1608 }
else if (
i < srcSliceH)
1609 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1614 const int srcStride[],
int srcSliceY,
int srcSliceH,
1615 uint8_t *
const dst[],
const int dstStride[])
1617 uint8_t *dstPtr=
dst[0] + srcSliceY * dstStride[0];
1618 const uint8_t *srcPtr=
src[0];
1620 void (*
copy) (
const uint8_t *
src,
int src_stride, uint8_t *
dst,
int dst_stride,
int width);
1623 switch(
c->opts.src_format) {
1624 #define CASE(pixfmt, prefix) \
1625 case pixfmt: copy = bayer_##prefix##_to_rgb48_copy; \
1626 interpolate = bayer_##prefix##_to_rgb48_interpolate; \
1646 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1647 srcPtr += 2 * srcStride[0];
1648 dstPtr += 2 * dstStride[0];
1650 for (
i = 2;
i < srcSliceH - 2;
i += 2) {
1651 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1652 srcPtr += 2 * srcStride[0];
1653 dstPtr += 2 * dstStride[0];
1656 if (
i + 1 == srcSliceH) {
1657 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->opts.src_w);
1658 }
else if (
i < srcSliceH)
1659 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1664 const int srcStride[],
int srcSliceY,
int srcSliceH,
1665 uint8_t *
const dst[],
const int dstStride[])
1667 const uint8_t *srcPtr=
src[0];
1668 uint8_t *dstY=
dst[0] + srcSliceY * dstStride[0];
1669 uint8_t *dstU=
dst[1] + srcSliceY * dstStride[1] / 2;
1670 uint8_t *dstV=
dst[2] + srcSliceY * dstStride[2] / 2;
1672 void (*
copy) (
const uint8_t *
src,
int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV,
int luma_stride,
int width,
const int32_t *
rgb2yuv);
1675 switch(
c->opts.src_format) {
1676 #define CASE(pixfmt, prefix) \
1677 case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1678 interpolate = bayer_##prefix##_to_yv12_interpolate; \
1698 copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0],
c->opts.src_w,
c->input_rgb2yuv_table);
1699 srcPtr += 2 * srcStride[0];
1700 dstY += 2 * dstStride[0];
1701 dstU += dstStride[1];
1702 dstV += dstStride[1];
1704 for (
i = 2;
i < srcSliceH - 2;
i += 2) {
1705 interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0],
c->opts.src_w,
c->input_rgb2yuv_table);
1706 srcPtr += 2 * srcStride[0];
1707 dstY += 2 * dstStride[0];
1708 dstU += dstStride[1];
1709 dstV += dstStride[1];
1712 if (
i + 1 == srcSliceH) {
1713 copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0],
c->opts.src_w,
c->input_rgb2yuv_table);
1714 }
else if (
i < srcSliceH)
1715 copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0],
c->opts.src_w,
c->input_rgb2yuv_table);
1719 #define isRGBA32(x) ( \
1720 (x) == AV_PIX_FMT_ARGB \
1721 || (x) == AV_PIX_FMT_RGBA \
1722 || (x) == AV_PIX_FMT_BGRA \
1723 || (x) == AV_PIX_FMT_ABGR \
1726 #define isRGBA64(x) ( \
1727 (x) == AV_PIX_FMT_RGBA64LE \
1728 || (x) == AV_PIX_FMT_RGBA64BE \
1729 || (x) == AV_PIX_FMT_BGRA64LE \
1730 || (x) == AV_PIX_FMT_BGRA64BE \
1733 #define isRGB48(x) ( \
1734 (x) == AV_PIX_FMT_RGB48LE \
1735 || (x) == AV_PIX_FMT_RGB48BE \
1736 || (x) == AV_PIX_FMT_BGR48LE \
1737 || (x) == AV_PIX_FMT_BGR48BE \
1740 #define isAYUV(x) ( \
1741 (x) == AV_PIX_FMT_AYUV \
1742 || (x) == AV_PIX_FMT_VUYA \
1743 || (x) == AV_PIX_FMT_VUYX \
1744 || (x) == AV_PIX_FMT_UYVA \
1747 #define isX2RGB(x) ( \
1748 (x) == AV_PIX_FMT_X2RGB10LE \
1749 || (x) == AV_PIX_FMT_X2BGR10LE \
1753 typedef void (*
rgbConvFn) (
const uint8_t *, uint8_t *, int);
1758 const int srcId =
c->srcFormatBpp;
1759 const int dstId =
c->dstFormatBpp;
1762 #define IS_NOT_NE(bpp, desc) \
1763 (((bpp + 7) >> 3) == 2 && \
1764 (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1766 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1786 else if (
CONV_IS(RGB48LE, BGR48BE)
1791 if (
CONV_IS(RGB48LE, BGRA64LE)
1795 else if (
CONV_IS(RGB48LE, BGRA64BE)
1799 if (
CONV_IS(RGB48LE, RGBA64LE)
1803 else if (
CONV_IS(RGB48LE, RGBA64BE)
1808 if (
CONV_IS(RGBA64LE, BGR48LE)
1812 else if (
CONV_IS(RGBA64LE, BGR48BE)
1816 else if (
CONV_IS(RGBA64LE, RGB48LE)
1820 else if (
CONV_IS(RGBA64LE, RGB48BE)
1825 if (
CONV_IS(X2RGB10LE, RGB48LE)
1828 else if (
CONV_IS(X2RGB10LE, RGB48BE)
1831 else if (
CONV_IS(X2RGB10LE, BGR48LE)
1834 else if (
CONV_IS(X2RGB10LE, BGR48BE)
1837 else if (
CONV_IS(X2RGB10LE, RGBA64LE)
1840 else if (
CONV_IS(X2RGB10LE, RGBA64BE)
1843 else if (
CONV_IS(X2RGB10LE, BGRA64LE)
1846 else if (
CONV_IS(X2RGB10LE, BGRA64BE)
1863 switch (srcId | (dstId << 16)) {
1880 switch (srcId | (dstId << 16)) {
1913 int srcSliceY,
int srcSliceH, uint8_t *
const dst[],
1914 const int dstStride[])
1921 const int srcBpp = (
c->srcFormatBpp + 7) >> 3;
1922 const int dstBpp = (
c->dstFormatBpp + 7) >> 3;
1929 const uint8_t *srcPtr =
src[0];
1930 uint8_t *dstPtr =
dst[0];
1931 int src_bswap =
IS_NOT_NE(
c->srcFormatBpp, desc_src);
1932 int dst_bswap =
IS_NOT_NE(
c->dstFormatBpp, desc_dst);
1942 for (
i = 0;
i < srcSliceH;
i++)
1943 dstPtr[dstStride[0] * (srcSliceY +
i)] = 255;
1947 if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1948 !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1949 conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1950 (srcSliceH - 1) * srcStride[0] +
c->opts.src_w * srcBpp);
1953 dstPtr += dstStride[0] * srcSliceY;
1955 for (
i = 0;
i < srcSliceH;
i++) {
1957 for(j=0; j<
c->opts.src_w; j++)
1958 ((uint16_t*)
c->formatConvBuffer)[j] =
av_bswap16(((uint16_t*)srcPtr)[j]);
1959 conv(
c->formatConvBuffer, dstPtr,
c->opts.src_w * srcBpp);
1961 conv(srcPtr, dstPtr,
c->opts.src_w * srcBpp);
1963 for(j=0; j<
c->opts.src_w; j++)
1964 ((uint16_t*)dstPtr)[j] =
av_bswap16(((uint16_t*)dstPtr)[j]);
1965 srcPtr += srcStride[0];
1966 dstPtr += dstStride[0];
1974 const int srcStride[],
int srcSliceY,
int srcSliceH,
1975 uint8_t *
const dst[],
const int dstStride[])
1979 dst[0] + srcSliceY * dstStride[0],
1980 dst[1] + (srcSliceY >> 1) * dstStride[1],
1981 dst[2] + (srcSliceY >> 1) * dstStride[2],
1982 c->opts.src_w, srcSliceH,
1983 dstStride[0], dstStride[1], srcStride[0],
1984 c->input_rgb2yuv_table);
1986 fillPlane(
dst[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
1991 const int srcStride[],
int srcSliceY,
int srcSliceH,
1992 uint8_t *
const dst[],
const int dstStride[])
1995 dst[0], dstStride[0]);
1997 planar2x(
src[1],
dst[1] + dstStride[1] * (srcSliceY >> 1),
c->chrSrcW,
1998 srcSliceH >> 2, srcStride[1], dstStride[1]);
1999 planar2x(
src[2],
dst[2] + dstStride[2] * (srcSliceY >> 1),
c->chrSrcW,
2000 srcSliceH >> 2, srcStride[2], dstStride[2]);
2002 fillPlane(
dst[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
2007 const int srcStride[],
int srcSliceY,
2008 int srcSliceH, uint8_t *
const dst[],
const int dstStride[])
2011 ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
2012 const uint8_t *srcPtr =
src[0];
2013 float *dstPtr = (
float *)(
dst[0] + dstStride[0] * srcSliceY);
2015 for (y = 0; y < srcSliceH; ++y){
2016 for (x = 0; x <
c->opts.src_w; ++x){
2017 dstPtr[x] =
c->uint2float_lut[srcPtr[x]];
2019 srcPtr += srcStride[0];
2020 dstPtr += dstStrideFloat;
2027 const uint8_t *
const src[],
2028 const int srcStride[],
int srcSliceY,
2029 int srcSliceH, uint8_t *
const dst[],
2030 const int dstStride[])
2033 ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
2034 const float *srcPtr = (
const float *)
src[0];
2035 uint8_t *dstPtr =
dst[0] + dstStride[0] * srcSliceY;
2037 for (y = 0; y < srcSliceH; ++y){
2038 for (x = 0; x <
c->opts.src_w; ++x){
2041 srcPtr += srcStrideFloat;
2042 dstPtr += dstStride[0];
2050 const int srcStride[],
int srcSliceY,
int srcSliceH,
2051 uint8_t *
const dst[],
const int dstStride[])
2053 if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
2054 memcpy(
dst[0] + dstStride[0] * srcSliceY,
src[0], srcSliceH * dstStride[0]);
2057 const uint8_t *srcPtr =
src[0];
2058 uint8_t *dstPtr =
dst[0] + dstStride[0] * srcSliceY;
2062 while (length +
c->opts.src_w <=
FFABS(dstStride[0]) &&
2063 length +
c->opts.src_w <=
FFABS(srcStride[0]))
2064 length +=
c->opts.src_w;
2067 for (
i = 0;
i < srcSliceH;
i++) {
2068 memcpy(dstPtr, srcPtr, length);
2069 srcPtr += srcStride[0];
2070 dstPtr += dstStride[0];
2076 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
2077 unsigned shift= src_depth-dst_depth, tmp;\
2078 unsigned bias = 1 << (shift - 1);\
2079 if (c->opts.dither == SWS_DITHER_NONE) {\
2080 for (i = 0; i < height; i++) {\
2081 for (j = 0; j < length-7; j+=8) {\
2082 tmp = (bswap(src[j+0]) + bias)>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
2083 tmp = (bswap(src[j+1]) + bias)>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
2084 tmp = (bswap(src[j+2]) + bias)>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
2085 tmp = (bswap(src[j+3]) + bias)>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
2086 tmp = (bswap(src[j+4]) + bias)>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
2087 tmp = (bswap(src[j+5]) + bias)>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
2088 tmp = (bswap(src[j+6]) + bias)>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
2089 tmp = (bswap(src[j+7]) + bias)>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
2091 for (; j < length; j++) {\
2092 tmp = (bswap(src[j]) + bias)>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
2097 } else if (shiftonly) {\
2098 for (i = 0; i < height; i++) {\
2099 const uint8_t *dither= dithers[shift-1][i&7];\
2100 for (j = 0; j < length-7; j+=8) {\
2101 tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
2102 tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
2103 tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
2104 tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
2105 tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
2106 tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
2107 tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
2108 tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
2110 for (; j < length; j++) {\
2111 tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
2117 for (i = 0; i < height; i++) {\
2118 const uint8_t *dither= dithers[shift-1][i&7];\
2119 for (j = 0; j < length-7; j+=8) {\
2120 tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
2121 tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
2122 tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
2123 tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
2124 tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
2125 tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
2126 tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
2127 tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
2129 for (; j < length; j++) {\
2130 tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
2138 const int srcStride[],
int srcSliceY,
int srcSliceH,
2139 uint8_t *
const dst[],
const int dstStride[])
2144 for (plane = 0; plane < 4 &&
dst[plane] !=
NULL; plane++) {
2145 int length = (plane == 0 || plane == 3) ?
c->opts.src_w :
AV_CEIL_RSHIFT(
c->opts.src_w,
c->chrDstHSubSample);
2146 int y = (plane == 0 || plane == 3) ? srcSliceY:
AV_CEIL_RSHIFT(srcSliceY,
c->chrDstVSubSample);
2147 int height = (plane == 0 || plane == 3) ? srcSliceH:
AV_CEIL_RSHIFT(srcSliceH,
c->chrDstVSubSample);
2148 const uint8_t *srcPtr =
src[plane];
2149 uint8_t *dstPtr =
dst[plane] + dstStride[plane] * y;
2150 int shiftonly = plane == 1 || plane == 2 || (!
c->opts.src_range && plane == 0);
2159 plane == 3, desc_dst->
comp[plane].
depth,
2160 isBE(
c->opts.dst_format));
2163 (plane == 3) ? 255 : 128);
2169 const int src_depth = desc_src->
comp[plane].
depth;
2170 const int dst_depth = desc_dst->
comp[plane].
depth;
2171 const uint16_t *srcPtr2 = (
const uint16_t *) srcPtr;
2172 uint16_t *dstPtr2 = (uint16_t*)dstPtr;
2174 if (dst_depth == 8) {
2176 if(
isBE(
c->opts.src_format) == HAVE_BIGENDIAN){
2177 DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
2181 }
else if (src_depth == 8) {
2185 for (j = 0; j < length; j++)\
2186 w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
2188 for (j = 0; j < length; j++)\
2189 w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
2190 (srcPtr[j]>>(2*8-dst_depth)));\
2192 if(
isBE(
c->opts.dst_format)){
2197 dstPtr2 += dstStride[plane]/2;
2198 srcPtr += srcStride[plane];
2200 }
else if (src_depth <= dst_depth) {
2203 if(
isBE(
c->opts.src_format) == HAVE_BIGENDIAN &&
2204 isBE(
c->opts.dst_format) == HAVE_BIGENDIAN &&
2206 unsigned shift = dst_depth - src_depth;
2208 #define FAST_COPY_UP(shift) \
2209 for (; j < length - 3; j += 4) { \
2210 uint64_t v = AV_RN64A(srcPtr2 + j); \
2211 AV_WN64A(dstPtr2 + j, v << shift); \
2214 #define FAST_COPY_UP(shift) \
2215 for (; j < length - 1; j += 2) { \
2216 uint32_t v = AV_RN32A(srcPtr2 + j); \
2217 AV_WN32A(dstPtr2 + j, v << shift); \
2226 #define COPY_UP(r,w) \
2228 for (; j < length; j++){ \
2229 unsigned int v= r(&srcPtr2[j]);\
2230 w(&dstPtr2[j], v<<(dst_depth-src_depth));\
2233 for (; j < length; j++){ \
2234 unsigned int v= r(&srcPtr2[j]);\
2235 w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
2236 (v>>(2*src_depth-dst_depth)));\
2239 if(
isBE(
c->opts.src_format)){
2240 if(
isBE(
c->opts.dst_format)){
2246 if(
isBE(
c->opts.dst_format)){
2252 dstPtr2 += dstStride[plane]/2;
2253 srcPtr2 += srcStride[plane]/2;
2256 if(
isBE(
c->opts.src_format) == HAVE_BIGENDIAN){
2257 if(
isBE(
c->opts.dst_format) == HAVE_BIGENDIAN){
2258 DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
2263 if(
isBE(
c->opts.dst_format) == HAVE_BIGENDIAN){
2271 isBE(
c->opts.src_format) !=
isBE(
c->opts.dst_format)) {
2274 for (j = 0; j < length; j++)
2275 ((uint16_t *) dstPtr)[j] =
av_bswap16(((
const uint16_t *) srcPtr)[j]);
2276 srcPtr += srcStride[plane];
2277 dstPtr += dstStride[plane];
2280 isBE(
c->opts.src_format) !=
isBE(
c->opts.dst_format)) {
2282 for (j = 0; j < length; j++)
2283 ((uint32_t *) dstPtr)[j] =
av_bswap32(((
const uint32_t *) srcPtr)[j]);
2284 srcPtr += srcStride[plane];
2285 dstPtr += dstStride[plane];
2287 }
else if (dstStride[plane] == srcStride[plane] &&
2288 srcStride[plane] > 0 && srcStride[plane] == length) {
2289 memcpy(
dst[plane] + dstStride[plane] * y,
src[plane],
2290 height * dstStride[plane]);
2297 memcpy(dstPtr, srcPtr, length);
2298 srcPtr += srcStride[plane];
2299 dstPtr += dstStride[plane];
2308 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
2309 ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
2310 (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
2317 const int flags =
c->opts.flags;
2318 const int dstH =
c->opts.dst_h;
2319 const int dstW =
c->opts.dst_w;
2322 needsDither =
isAnyRGB(dstFormat) &&
2323 c->dstFormatBpp < 24 &&
2324 (
c->dstFormatBpp <
c->srcFormatBpp || (!
isAnyRGB(srcFormat)));
2351 c->dst_slice_align = 2;
2371 c->dst_slice_align = 4;
2402 #define isByteRGB(f) ( \
2403 f == AV_PIX_FMT_RGB32 || \
2404 f == AV_PIX_FMT_RGB32_1 || \
2405 f == AV_PIX_FMT_RGB24 || \
2406 f == AV_PIX_FMT_BGR32 || \
2407 f == AV_PIX_FMT_BGR32_1 || \
2408 f == AV_PIX_FMT_BGR24)
2465 c->dst_slice_align = 2;
2472 else if (!
isBayer(dstFormat)) {
2580 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
2582 if ( srcFormat == dstFormat ||
2589 c->chrDstHSubSample ==
c->chrSrcHSubSample &&
2590 c->chrDstVSubSample ==
c->chrSrcVSubSample &&
2610 int num_pixels,
const uint8_t *palette)
2614 for (
i = 0;
i < num_pixels;
i++)
2615 ((uint32_t *)
dst)[
i] = ((
const uint32_t *) palette)[
src[
i]];
2620 int num_pixels,
const uint8_t *palette)
2624 for (
i = 0;
i < num_pixels;
i++) {
2626 dst[0] = palette[
src[
i] * 4 + 0];
2627 dst[1] = palette[
src[
i] * 4 + 1];
2628 dst[2] = palette[
src[
i] * 4 + 2];