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) {
233 for (
int x = 0; x <
w; x++) {
234 dst1[x] = (
src1[4 * x + 0] +
src1[4 * x + 2] +
235 src2[4 * x + 0] +
src2[4 * x + 2]) >> 2;
236 dst2[x] = (
src1[4 * x + 1] +
src1[4 * x + 3] +
237 src2[4 * x + 1] +
src2[4 * x + 3]) >> 2;
239 src1 += srcStride * 2;
240 src2 += srcStride * 2;
247 const int srcStride[],
int srcSliceY,
int srcSliceH,
248 uint8_t *
const dstParam[],
const int dstStride[])
250 uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
251 uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
254 dstParam[0], dstStride[0]);
258 src[1], srcStride[1],
c->opts.src_w / 2, srcSliceH);
261 src[1], srcStride[1],
c->opts.src_w / 2, srcSliceH);
267 const int srcStride[],
int srcSliceY,
268 int srcSliceH, uint8_t *
const dstParam8[],
269 const int dstStride[])
273 const uint16_t **
src = (
const uint16_t**)src8;
274 uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
275 uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
279 const int shift[3] = {
288 av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
289 dstStride[0] % 2 || dstStride[1] % 2));
291 for (y = 0; y < srcSliceH; y++) {
292 uint16_t *tdstY = dstY;
293 const uint16_t *tsrc0 =
src[0];
294 for (x =
c->opts.src_w; x > 0; x--) {
295 *tdstY++ = *tsrc0++ <<
shift[0];
297 src[0] += srcStride[0] / 2;
298 dstY += dstStride[0] / 2;
301 uint16_t *tdstUV = dstUV;
302 const uint16_t *tsrc1 =
src[1];
303 const uint16_t *tsrc2 =
src[2];
304 for (x =
c->opts.src_w / 2; x > 0; x--) {
305 *tdstUV++ = *tsrc1++ <<
shift[1];
306 *tdstUV++ = *tsrc2++ <<
shift[2];
308 src[1] += srcStride[1] / 2;
309 src[2] += srcStride[2] / 2;
310 dstUV += dstStride[1] / 2;
317 #if AV_HAVE_BIGENDIAN
318 #define output_pixel(p, v) do { \
319 uint16_t *pp = (p); \
323 #define output_pixel(p, v) (*p) = (v)
327 const int srcStride[],
int srcSliceY,
328 int srcSliceH, uint8_t *
const dstParam8[],
329 const int dstStride[])
332 uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
333 uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
336 av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
338 for (y = 0; y < srcSliceH; y++) {
339 uint16_t *tdstY = dstY;
340 const uint8_t *tsrc0 =
src0;
341 for (x =
c->opts.src_w; x > 0; x--) {
345 src0 += srcStride[0];
346 dstY += dstStride[0] / 2;
349 uint16_t *tdstUV = dstUV;
350 const uint8_t *tsrc1 =
src1;
351 const uint8_t *tsrc2 =
src2;
352 for (x =
c->opts.src_w / 2; x > 0; x--) {
358 src1 += srcStride[1];
359 src2 += srcStride[2];
360 dstUV += dstStride[1] / 2;
370 const int srcStride[],
int srcSliceY,
int srcSliceH,
371 uint8_t *
const dstParam[],
const int dstStride[])
373 uint8_t *
dst = dstParam[0] + dstStride[0] * srcSliceY;
376 srcStride[1], dstStride[0]);
382 const int srcStride[],
int srcSliceY,
int srcSliceH,
383 uint8_t *
const dstParam[],
const int dstStride[])
385 uint8_t *
dst = dstParam[0] + dstStride[0] * srcSliceY;
388 srcStride[1], dstStride[0]);
394 const int srcStride[],
int srcSliceY,
int srcSliceH,
395 uint8_t *
const dstParam[],
const int dstStride[])
397 uint8_t *
dst = dstParam[0] + dstStride[0] * srcSliceY;
400 srcStride[1], dstStride[0]);
406 const int srcStride[],
int srcSliceY,
int srcSliceH,
407 uint8_t *
const dstParam[],
const int dstStride[])
409 uint8_t *
dst = dstParam[0] + dstStride[0] * srcSliceY;
412 srcStride[1], dstStride[0]);
418 const int srcStride[],
int srcSliceY,
int srcSliceH,
419 uint8_t *
const dstParam[],
const int dstStride[])
421 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
422 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
423 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
425 yuyvtoyuv420(ydst, udst, vdst,
src[0],
c->opts.src_w, srcSliceH, dstStride[0],
426 dstStride[1], srcStride[0]);
429 fillPlane(dstParam[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
435 const int srcStride[],
int srcSliceY,
int srcSliceH,
436 uint8_t *
const dstParam[],
const int dstStride[])
438 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
439 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
440 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
442 yuyvtoyuv422(ydst, udst, vdst,
src[0],
c->opts.src_w, srcSliceH, dstStride[0],
443 dstStride[1], srcStride[0]);
449 const int srcStride[],
int srcSliceY,
int srcSliceH,
450 uint8_t *
const dstParam[],
const int dstStride[])
452 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
453 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
454 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
456 uyvytoyuv420(ydst, udst, vdst,
src[0],
c->opts.src_w, srcSliceH, dstStride[0],
457 dstStride[1], srcStride[0]);
460 fillPlane(dstParam[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
466 const int srcStride[],
int srcSliceY,
int srcSliceH,
467 uint8_t *
const dstParam[],
const int dstStride[])
469 uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
470 uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
471 uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
473 uyvytoyuv422(ydst, udst, vdst,
src[0],
c->opts.src_w, srcSliceH, dstStride[0],
474 dstStride[1], srcStride[0]);
480 const uint8_t *palette)
483 for (
i = 0;
i < num_pixels;
i++)
484 ((uint32_t *)
dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] | (
src[(
i << 1) + 1] << 24);
488 const uint8_t *palette)
492 for (
i = 0;
i < num_pixels;
i++)
493 ((uint32_t *)
dst)[
i] = ((
const uint32_t *) palette)[
src[
i << 1]] |
src[(
i << 1) + 1];
497 const uint8_t *palette)
501 for (
i = 0;
i < num_pixels;
i++) {
503 dst[0] = palette[
src[
i << 1] * 4 + 0];
504 dst[1] = palette[
src[
i << 1] * 4 + 1];
505 dst[2] = palette[
src[
i << 1] * 4 + 2];
511 const int srcStride[],
int srcSliceY,
int srcSliceH,
512 uint8_t *
const dst[],
const int dstStride[])
516 for (p = 0; p < 4; p++) {
517 int srcstr = srcStride[p] / 2;
518 int dststr = dstStride[p] / 2;
519 uint16_t *dstPtr = (uint16_t *)
dst[p];
520 const uint16_t *srcPtr = (
const uint16_t *)
src[p];
522 if(!dstPtr || !srcPtr)
524 dstPtr += (srcSliceY >>
c->chrDstVSubSample) * dststr;
525 for (
i = 0;
i < (srcSliceH >>
c->chrDstVSubSample);
i++) {
526 for (j = 0; j < min_stride; j++) {
538 const int srcStride[],
int srcSliceY,
int srcSliceH,
539 uint8_t *
const dst[],
const int dstStride[])
543 for (p = 0; p < 4; p++) {
544 int srcstr = srcStride[p] / 4;
545 int dststr = dstStride[p] / 4;
546 uint32_t *dstPtr = (uint32_t *)
dst[p];
547 const uint32_t *srcPtr = (
const uint32_t *)
src[p];
549 if(!dstPtr || !srcPtr)
551 dstPtr += (srcSliceY >>
c->chrDstVSubSample) * dststr;
552 for (
i = 0;
i < (srcSliceH >>
c->chrDstVSubSample);
i++) {
553 for (j = 0; j < min_stride; j++) {
566 int srcSliceY,
int srcSliceH, uint8_t *
const dst[],
567 const int dstStride[])
571 void (*
conv)(
const uint8_t *
src, uint8_t *
dst,
int num_pixels,
572 const uint8_t *palette) =
NULL;
574 uint8_t *dstPtr =
dst[0] + dstStride[0] * srcSliceY;
575 const uint8_t *srcPtr =
src[0];
586 }
else if (
usePal(srcFormat)) {
601 for (
i = 0;
i < srcSliceH;
i++) {
602 conv(srcPtr, dstPtr,
c->opts.src_w, (uint8_t *)
c->pal_rgb);
603 srcPtr += srcStride[0];
604 dstPtr += dstStride[0];
612 uint16_t *
dst[],
const int dstStride[],
int srcSliceH,
613 int src_alpha,
int swap,
int shift,
int width)
616 int dst_alpha =
dst[3] !=
NULL;
617 for (
h = 0;
h < srcSliceH;
h++) {
618 uint16_t *src_line = (uint16_t *)(
src + srcStride *
h);
621 if (src_alpha && dst_alpha) {
622 for (x = 0; x <
width; x++) {
628 }
else if (dst_alpha) {
629 for (x = 0; x <
width; x++) {
635 }
else if (src_alpha) {
636 for (x = 0; x <
width; x++) {
643 for (x = 0; x <
width; x++) {
651 if (src_alpha && dst_alpha) {
652 for (x = 0; x <
width; x++) {
658 }
else if (dst_alpha) {
659 for (x = 0; x <
width; x++) {
665 }
else if (src_alpha) {
666 for (x = 0; x <
width; x++) {
673 for (x = 0; x <
width; x++) {
681 if (src_alpha && dst_alpha) {
682 for (x = 0; x <
width; x++) {
688 }
else if (dst_alpha) {
689 for (x = 0; x <
width; x++) {
695 }
else if (src_alpha) {
696 for (x = 0; x <
width; x++) {
703 for (x = 0; x <
width; x++) {
711 if (src_alpha && dst_alpha) {
712 for (x = 0; x <
width; x++) {
718 }
else if (dst_alpha) {
719 for (x = 0; x <
width; x++) {
725 }
else if (src_alpha) {
726 for (x = 0; x <
width; x++) {
733 for (x = 0; x <
width; x++) {
740 for (
i = 0;
i < 4;
i++)
741 dst[
i] += dstStride[
i] >> 1;
746 uint16_t *
dst[],
const int dstStride[],
int srcSliceH,
747 int swap,
int bpc,
int width)
750 int dst_alpha =
dst[3] !=
NULL;
751 int scale_high = bpc - 10, scale_low = 10 - scale_high;
752 for (
h = 0;
h < srcSliceH;
h++) {
753 uint32_t *src_line = (uint32_t *)(
src + srcStride *
h);
760 for (x = 0; x <
width; x++) {
761 unsigned p =
AV_RL32(src_line);
762 component = (p >> 20) & 0x3FF;
763 dst[0][x] =
av_bswap16(component << scale_high | component >> scale_low);
764 component = (p >> 10) & 0x3FF;
765 dst[1][x] =
av_bswap16(component << scale_high | component >> scale_low);
766 component = p & 0x3FF;
767 dst[2][x] =
av_bswap16(component << scale_high | component >> scale_low);
772 for (x = 0; x <
width; x++) {
773 unsigned p =
AV_RL32(src_line);
774 component = (p >> 20) & 0x3FF;
775 dst[0][x] =
av_bswap16(component << scale_high | component >> scale_low);
776 component = (p >> 10) & 0x3FF;
777 dst[1][x] =
av_bswap16(component << scale_high | component >> scale_low);
778 component = p & 0x3FF;
779 dst[2][x] =
av_bswap16(component << scale_high | component >> scale_low);
786 for (x = 0; x <
width; x++) {
787 unsigned p =
AV_RL32(src_line);
788 component = (p >> 20) & 0x3FF;
789 dst[0][x] = component << scale_high | component >> scale_low;
790 component = (p >> 10) & 0x3FF;
791 dst[1][x] = component << scale_high | component >> scale_low;
792 component = p & 0x3FF;
793 dst[2][x] = component << scale_high | component >> scale_low;
798 for (x = 0; x <
width; x++) {
799 unsigned p =
AV_RL32(src_line);
800 component = (p >> 20) & 0x3FF;
801 dst[0][x] = component << scale_high | component >> scale_low;
802 component = (p >> 10) & 0x3FF;
803 dst[1][x] = component << scale_high | component >> scale_low;
804 component = p & 0x3FF;
805 dst[2][x] = component << scale_high | component >> scale_low;
811 for (
i = 0;
i < 4;
i++)
812 dst[
i] += dstStride[
i] >> 1;
817 const int srcStride[],
int srcSliceY,
int srcSliceH,
818 uint8_t *
const dst[],
const int dstStride[])
820 uint16_t *dst2013[] = { (uint16_t *)
dst[2], (uint16_t *)
dst[0], (uint16_t *)
dst[1], (uint16_t *)
dst[3] };
821 uint16_t *dst1023[] = { (uint16_t *)
dst[1], (uint16_t *)
dst[0], (uint16_t *)
dst[2], (uint16_t *)
dst[3] };
822 int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
823 int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
841 src_format->
name, dst_format->
name);
846 dst2013[
i] += stride2013[
i] * srcSliceY / 2;
847 dst1023[
i] += stride1023[
i] * srcSliceY / 2;
850 switch (
c->opts.src_format) {
856 dst2013, stride2013, srcSliceH,
alpha, swap,
857 16 - bpc,
c->opts.src_w);
862 dst2013, stride2013, srcSliceH, swap,
870 dst1023, stride1023, srcSliceH,
alpha, swap,
871 16 - bpc,
c->opts.src_w);
876 dst1023, stride1023, srcSliceH, swap,
881 "unsupported conversion to planar RGB %s -> %s\n",
882 src_format->
name, dst_format->
name);
889 uint8_t *
dst,
int dstStride,
int srcSliceH,
893 int src_alpha =
src[3] !=
NULL;
894 int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
895 for (
h = 0;
h < srcSliceH;
h++) {
896 uint16_t *dest = (uint16_t *)(
dst + dstStride *
h);
901 if (
alpha && !src_alpha) {
902 for (x = 0; x <
width; x++) {
904 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
906 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
908 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
911 }
else if (
alpha && src_alpha) {
912 for (x = 0; x <
width; x++) {
914 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
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);
923 for (x = 0; x <
width; x++) {
925 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
927 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
929 *dest++ =
av_bswap16(component << scale_high | component >> scale_low);
934 if (
alpha && !src_alpha) {
935 for (x = 0; x <
width; x++) {
941 }
else if (
alpha && src_alpha) {
942 for (x = 0; x <
width; x++) {
949 for (x = 0; x <
width; x++) {
957 if (
alpha && !src_alpha) {
958 for (x = 0; x <
width; x++) {
964 }
else if (
alpha && src_alpha) {
965 for (x = 0; x <
width; x++) {
972 for (x = 0; x <
width; x++) {
980 if (
alpha && !src_alpha) {
981 for (x = 0; x <
width; x++) {
982 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
983 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
984 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
987 }
else if (
alpha && src_alpha) {
988 for (x = 0; x <
width; x++) {
989 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
990 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
991 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
992 *dest++ =
src[3][x] << scale_high |
src[3][x] >> scale_low;
995 for (x = 0; x <
width; x++) {
996 *dest++ =
src[0][x] << scale_high |
src[0][x] >> scale_low;
997 *dest++ =
src[1][x] << scale_high |
src[1][x] >> scale_low;
998 *dest++ =
src[2][x] << scale_high |
src[2][x] >> scale_low;
1002 for (
i = 0;
i < 3 + src_alpha;
i++)
1003 src[
i] += srcStride[
i] >> 1;
1008 uint8_t *
dst,
int dstStride,
int srcSliceH,
1009 int swap,
int bpp,
int width)
1012 int shift = bpp - 10;
1014 for (
h = 0;
h < srcSliceH;
h++) {
1015 uint8_t *dest =
dst + dstStride *
h;
1020 for (x = 0; x <
width; x++) {
1024 AV_WL32(dest + 4 * x, (3
U << 30) + (
C0 << 20) + (
C1 << 10) +
C2);
1028 for (x = 0; x <
width; x++) {
1032 AV_WL32(dest + 4 * x, (3
U << 30) + (
C0 << 20) + (
C1 << 10) +
C2);
1036 for (
i = 0;
i < 3;
i++)
1037 src[
i] += srcStride[
i] >> 1;
1043 const int srcStride[],
int srcSliceY,
int srcSliceH,
1044 uint8_t *
const dst[],
const int dstStride[])
1046 const uint16_t *src102[] = { (uint16_t *)
src[1], (uint16_t *)
src[0], (uint16_t *)
src[2], (uint16_t *)
src[3] };
1047 const uint16_t *src201[] = { (uint16_t *)
src[2], (uint16_t *)
src[0], (uint16_t *)
src[1], (uint16_t *)
src[3] };
1048 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
1049 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1052 int bits_per_sample = src_format->
comp[0].
depth;
1063 bits_per_sample <= 8) {
1065 src_format->
name, dst_format->
name);
1068 switch (
c->opts.dst_format) {
1072 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1073 srcSliceH, 0, swap, bits_per_sample,
c->opts.src_w);
1078 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1079 srcSliceH, 0, swap, bits_per_sample,
c->opts.src_w);
1084 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1085 srcSliceH, 1, swap, bits_per_sample,
c->opts.src_w);
1090 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1091 srcSliceH, 1, swap, bits_per_sample,
c->opts.src_w);
1095 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1096 srcSliceH, swap, bits_per_sample,
c->opts.src_w);
1100 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1101 srcSliceH, swap, bits_per_sample,
c->opts.src_w);
1105 "unsupported planar RGB conversion %s -> %s\n",
1106 src_format->
name, dst_format->
name);
1113 uint8_t *
dst,
int dstStride,
int srcSliceH,
1117 for (
h = 0;
h < srcSliceH;
h++) {
1118 uint8_t *dest =
dst + dstStride *
h;
1119 for (x = 0; x <
width; x++) {
1120 *dest++ =
src[0][x];
1121 *dest++ =
src[1][x];
1122 *dest++ =
src[2][x];
1125 for (
i = 0;
i < 3;
i++)
1126 src[
i] += srcStride[
i];
1131 uint8_t *
dst,
int dstStride,
int srcSliceH,
1132 int alpha_first,
int width)
1135 for (
h = 0;
h < srcSliceH;
h++) {
1136 uint8_t *dest =
dst + dstStride *
h;
1139 for (x = 0; x <
width; x++) {
1141 *dest++ =
src[0][x];
1142 *dest++ =
src[1][x];
1143 *dest++ =
src[2][x];
1146 for (x = 0; x <
width; x++) {
1147 *dest++ =
src[0][x];
1148 *dest++ =
src[1][x];
1149 *dest++ =
src[2][x];
1154 for (
i = 0;
i < 3;
i++)
1155 src[
i] += srcStride[
i];
1160 uint8_t *
dst,
int dstStride,
int srcSliceH,
1161 int alpha_first,
int width)
1164 for (
h = 0;
h < srcSliceH;
h++) {
1165 uint8_t *dest =
dst + dstStride *
h;
1168 for (x = 0; x <
width; x++) {
1169 *dest++ =
src[3][x];
1170 *dest++ =
src[0][x];
1171 *dest++ =
src[1][x];
1172 *dest++ =
src[2][x];
1175 for (x = 0; x <
width; x++) {
1176 *dest++ =
src[0][x];
1177 *dest++ =
src[1][x];
1178 *dest++ =
src[2][x];
1179 *dest++ =
src[3][x];
1183 for (
i = 0;
i < 4;
i++)
1184 src[
i] += srcStride[
i];
1189 const int srcStride[],
int srcSliceY,
int srcSliceH,
1190 uint8_t *
const dst[],
const int dstStride[])
1192 int alpha_first = 0;
1193 const uint8_t *src102[] = {
src[1],
src[0],
src[2],
src[3] };
1194 const uint8_t *src201[] = {
src[2],
src[0],
src[1],
src[3] };
1195 int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
1196 int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1205 switch (
c->opts.dst_format) {
1208 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1209 srcSliceH,
c->opts.src_w);
1214 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1215 srcSliceH,
c->opts.src_w);
1222 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1223 srcSliceH, alpha_first,
c->opts.src_w);
1230 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1231 srcSliceH, alpha_first,
c->opts.src_w);
1236 "unsupported planar RGB conversion %s -> %s\n",
1245 const int srcStride[],
int srcSliceY,
int srcSliceH,
1246 uint8_t *
const dst[],
const int dstStride[])
1248 int alpha_first = 0;
1249 const uint8_t *src102[] = {
src[1],
src[0],
src[2] };
1250 const uint8_t *src201[] = {
src[2],
src[0],
src[1] };
1251 int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
1252 int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
1261 switch (
c->opts.dst_format) {
1264 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1265 srcSliceH,
c->opts.src_w);
1270 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1271 srcSliceH,
c->opts.src_w);
1278 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1279 srcSliceH, alpha_first,
c->opts.src_w);
1286 dst[0] + srcSliceY * dstStride[0], dstStride[0],
1287 srcSliceH, alpha_first,
c->opts.src_w);
1292 "unsupported planar RGB conversion %s -> %s\n",
1301 const uint8_t *
const src[],
const int srcStride[],
1302 int srcSliceY,
int srcSliceH,
1303 uint8_t *
const dst[],
const int dstStride[])
1306 dst[0], dstStride[0]);
1308 dst[1], dstStride[1]);
1310 dst[2], dstStride[2]);
1312 fillPlane(
dst[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
1318 uint8_t *
const dst[],
const int dstStride[],
int srcSliceH,
1319 int alpha_first,
int inc_size,
int width)
1331 for (
h = 0;
h < srcSliceH;
h++) {
1332 for (x = 0; x <
width; x++) {
1333 dest[0][x] =
src[0];
1334 dest[1][x] =
src[1];
1335 dest[2][x] =
src[2];
1339 src += srcStride -
width * inc_size;
1340 dest[0] += dstStride[0];
1341 dest[1] += dstStride[1];
1342 dest[2] += dstStride[2];
1347 const int srcStride[],
int srcSliceY,
int srcSliceH,
1348 uint8_t *
const dst[],
const int dstStride[])
1350 int alpha_first = 0;
1351 int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1352 int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1353 uint8_t *dst102[] = {
dst[1] + srcSliceY * dstStride[1],
1354 dst[0] + srcSliceY * dstStride[0],
1355 dst[2] + srcSliceY * dstStride[2] };
1356 uint8_t *dst201[] = {
dst[2] + srcSliceY * dstStride[2],
1357 dst[0] + srcSliceY * dstStride[0],
1358 dst[1] + srcSliceY * dstStride[1] };
1360 switch (
c->opts.src_format) {
1363 stride201, srcSliceH, alpha_first, 3,
c->opts.src_w);
1367 stride102, srcSliceH, alpha_first, 3,
c->opts.src_w);
1373 stride201, srcSliceH, alpha_first, 4,
c->opts.src_w);
1379 stride102, srcSliceH, alpha_first, 4,
c->opts.src_w);
1383 "unsupported planar RGB conversion %s -> %s\n",
1392 uint8_t *
const dst[],
const int dstStride[],
1393 int srcSliceH,
int width)
1403 for (
h = 0;
h < srcSliceH;
h++) {
1404 for (x = 0; x <
width; x++) {
1405 dest[0][x] =
src[x * 3 + 0];
1406 dest[1][x] =
src[x * 3 + 1];
1407 dest[2][x] =
src[x * 3 + 2];
1411 dest[0] += dstStride[0];
1412 dest[1] += dstStride[1];
1413 dest[2] += dstStride[2];
1414 dest[3] += dstStride[3];
1419 uint8_t *
const dst[],
const int dstStride[],
1420 int srcSliceH,
int alpha_first,
int width)
1430 for (
h = 0;
h < srcSliceH;
h++) {
1432 for (x = 0; x <
width; x++) {
1433 dest[0][x] =
src[x * 4 + 1];
1434 dest[1][x] =
src[x * 4 + 2];
1435 dest[2][x] =
src[x * 4 + 3];
1436 dest[3][x] =
src[x * 4 + 0];
1439 for (x = 0; x <
width; x++) {
1440 dest[0][x] =
src[x * 4 + 0];
1441 dest[1][x] =
src[x * 4 + 1];
1442 dest[2][x] =
src[x * 4 + 2];
1443 dest[3][x] =
src[x * 4 + 3];
1447 dest[0] += dstStride[0];
1448 dest[1] += dstStride[1];
1449 dest[2] += dstStride[2];
1450 dest[3] += dstStride[3];
1455 const int srcStride[],
int srcSliceY,
int srcSliceH,
1456 uint8_t *
const dst[],
const int dstStride[])
1458 int alpha_first = 0;
1459 int stride102[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
1460 int stride201[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
1461 uint8_t *dst102[] = {
dst[1] + srcSliceY * dstStride[1],
1462 dst[0] + srcSliceY * dstStride[0],
1463 dst[2] + srcSliceY * dstStride[2],
1464 dst[3] + srcSliceY * dstStride[3] };
1465 uint8_t *dst201[] = {
dst[2] + srcSliceY * dstStride[2],
1466 dst[0] + srcSliceY * dstStride[0],
1467 dst[1] + srcSliceY * dstStride[1],
1468 dst[3] + srcSliceY * dstStride[3] };
1470 switch (
c->opts.src_format) {
1473 stride201, srcSliceH,
c->opts.src_w);
1477 stride102, srcSliceH,
c->opts.src_w);
1483 stride201, srcSliceH, alpha_first,
c->opts.src_w);
1489 stride102, srcSliceH, alpha_first,
c->opts.src_w);
1493 "unsupported planar RGB conversion %s -> %s\n",
1503 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1508 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1513 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1518 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1523 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1528 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1533 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1538 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1543 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1548 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1553 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1558 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1562 const int srcStride[],
int srcSliceY,
int srcSliceH,
1563 uint8_t *
const dst[],
const int dstStride[])
1565 uint8_t *dstPtr=
dst[0] + srcSliceY * dstStride[0];
1566 const uint8_t *srcPtr=
src[0];
1568 void (*
copy) (
const uint8_t *
src,
int src_stride, uint8_t *
dst,
int dst_stride,
int width);
1571 switch(
c->opts.src_format) {
1572 #define CASE(pixfmt, prefix) \
1573 case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1574 interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1594 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1595 srcPtr += 2 * srcStride[0];
1596 dstPtr += 2 * dstStride[0];
1598 for (
i = 2;
i < srcSliceH - 2;
i += 2) {
1599 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1600 srcPtr += 2 * srcStride[0];
1601 dstPtr += 2 * dstStride[0];
1604 if (
i + 1 == srcSliceH) {
1605 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->opts.src_w);
1606 }
else if (
i < srcSliceH)
1607 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1612 const int srcStride[],
int srcSliceY,
int srcSliceH,
1613 uint8_t *
const dst[],
const int dstStride[])
1615 uint8_t *dstPtr=
dst[0] + srcSliceY * dstStride[0];
1616 const uint8_t *srcPtr=
src[0];
1618 void (*
copy) (
const uint8_t *
src,
int src_stride, uint8_t *
dst,
int dst_stride,
int width);
1621 switch(
c->opts.src_format) {
1622 #define CASE(pixfmt, prefix) \
1623 case pixfmt: copy = bayer_##prefix##_to_rgb48_copy; \
1624 interpolate = bayer_##prefix##_to_rgb48_interpolate; \
1644 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1645 srcPtr += 2 * srcStride[0];
1646 dstPtr += 2 * dstStride[0];
1648 for (
i = 2;
i < srcSliceH - 2;
i += 2) {
1649 interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1650 srcPtr += 2 * srcStride[0];
1651 dstPtr += 2 * dstStride[0];
1654 if (
i + 1 == srcSliceH) {
1655 copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0],
c->opts.src_w);
1656 }
else if (
i < srcSliceH)
1657 copy(srcPtr, srcStride[0], dstPtr, dstStride[0],
c->opts.src_w);
1662 const int srcStride[],
int srcSliceY,
int srcSliceH,
1663 uint8_t *
const dst[],
const int dstStride[])
1665 const uint8_t *srcPtr=
src[0];
1666 uint8_t *dstY=
dst[0] + srcSliceY * dstStride[0];
1667 uint8_t *dstU=
dst[1] + srcSliceY * dstStride[1] / 2;
1668 uint8_t *dstV=
dst[2] + srcSliceY * dstStride[2] / 2;
1670 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);
1673 switch(
c->opts.src_format) {
1674 #define CASE(pixfmt, prefix) \
1675 case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1676 interpolate = bayer_##prefix##_to_yv12_interpolate; \
1696 copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0],
c->opts.src_w,
c->input_rgb2yuv_table);
1697 srcPtr += 2 * srcStride[0];
1698 dstY += 2 * dstStride[0];
1699 dstU += dstStride[1];
1700 dstV += dstStride[1];
1702 for (
i = 2;
i < srcSliceH - 2;
i += 2) {
1703 interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0],
c->opts.src_w,
c->input_rgb2yuv_table);
1704 srcPtr += 2 * srcStride[0];
1705 dstY += 2 * dstStride[0];
1706 dstU += dstStride[1];
1707 dstV += dstStride[1];
1710 if (
i + 1 == srcSliceH) {
1711 copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0],
c->opts.src_w,
c->input_rgb2yuv_table);
1712 }
else if (
i < srcSliceH)
1713 copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0],
c->opts.src_w,
c->input_rgb2yuv_table);
1717 #define isRGBA32(x) ( \
1718 (x) == AV_PIX_FMT_ARGB \
1719 || (x) == AV_PIX_FMT_RGBA \
1720 || (x) == AV_PIX_FMT_BGRA \
1721 || (x) == AV_PIX_FMT_ABGR \
1724 #define isRGBA64(x) ( \
1725 (x) == AV_PIX_FMT_RGBA64LE \
1726 || (x) == AV_PIX_FMT_RGBA64BE \
1727 || (x) == AV_PIX_FMT_BGRA64LE \
1728 || (x) == AV_PIX_FMT_BGRA64BE \
1731 #define isRGB48(x) ( \
1732 (x) == AV_PIX_FMT_RGB48LE \
1733 || (x) == AV_PIX_FMT_RGB48BE \
1734 || (x) == AV_PIX_FMT_BGR48LE \
1735 || (x) == AV_PIX_FMT_BGR48BE \
1738 #define isAYUV(x) ( \
1739 (x) == AV_PIX_FMT_AYUV \
1740 || (x) == AV_PIX_FMT_VUYA \
1741 || (x) == AV_PIX_FMT_VUYX \
1742 || (x) == AV_PIX_FMT_UYVA \
1745 #define isX2RGB(x) ( \
1746 (x) == AV_PIX_FMT_X2RGB10LE \
1747 || (x) == AV_PIX_FMT_X2BGR10LE \
1751 typedef void (*
rgbConvFn) (
const uint8_t *, uint8_t *, int);
1756 const int srcId =
c->srcFormatBpp;
1757 const int dstId =
c->dstFormatBpp;
1760 #define IS_NOT_NE(bpp, desc) \
1761 (((bpp + 7) >> 3) == 2 && \
1762 (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1764 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1784 else if (
CONV_IS(RGB48LE, BGR48BE)
1789 if (
CONV_IS(RGB48LE, BGRA64LE)
1793 else if (
CONV_IS(RGB48LE, BGRA64BE)
1797 if (
CONV_IS(RGB48LE, RGBA64LE)
1801 else if (
CONV_IS(RGB48LE, RGBA64BE)
1806 if (
CONV_IS(RGBA64LE, BGR48LE)
1810 else if (
CONV_IS(RGBA64LE, BGR48BE)
1814 else if (
CONV_IS(RGBA64LE, RGB48LE)
1818 else if (
CONV_IS(RGBA64LE, RGB48BE)
1823 if (
CONV_IS(X2RGB10LE, RGB48LE)
1826 else if (
CONV_IS(X2RGB10LE, RGB48BE)
1829 else if (
CONV_IS(X2RGB10LE, BGR48LE)
1832 else if (
CONV_IS(X2RGB10LE, BGR48BE)
1835 else if (
CONV_IS(X2RGB10LE, RGBA64LE)
1838 else if (
CONV_IS(X2RGB10LE, RGBA64BE)
1841 else if (
CONV_IS(X2RGB10LE, BGRA64LE)
1844 else if (
CONV_IS(X2RGB10LE, BGRA64BE)
1861 switch (srcId | (dstId << 16)) {
1878 switch (srcId | (dstId << 16)) {
1911 int srcSliceY,
int srcSliceH, uint8_t *
const dst[],
1912 const int dstStride[])
1919 const int srcBpp = (
c->srcFormatBpp + 7) >> 3;
1920 const int dstBpp = (
c->dstFormatBpp + 7) >> 3;
1927 const uint8_t *srcPtr =
src[0];
1928 uint8_t *dstPtr =
dst[0];
1929 int src_bswap =
IS_NOT_NE(
c->srcFormatBpp, desc_src);
1930 int dst_bswap =
IS_NOT_NE(
c->dstFormatBpp, desc_dst);
1940 for (
i = 0;
i < srcSliceH;
i++)
1941 dstPtr[dstStride[0] * (srcSliceY +
i)] = 255;
1945 if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1946 !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1947 conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1948 (srcSliceH - 1) * srcStride[0] +
c->opts.src_w * srcBpp);
1951 dstPtr += dstStride[0] * srcSliceY;
1953 for (
i = 0;
i < srcSliceH;
i++) {
1955 for(j=0; j<
c->opts.src_w; j++)
1956 ((uint16_t*)
c->formatConvBuffer)[j] =
av_bswap16(((uint16_t*)srcPtr)[j]);
1957 conv(
c->formatConvBuffer, dstPtr,
c->opts.src_w * srcBpp);
1959 conv(srcPtr, dstPtr,
c->opts.src_w * srcBpp);
1961 for(j=0; j<
c->opts.src_w; j++)
1962 ((uint16_t*)dstPtr)[j] =
av_bswap16(((uint16_t*)dstPtr)[j]);
1963 srcPtr += srcStride[0];
1964 dstPtr += dstStride[0];
1972 const int srcStride[],
int srcSliceY,
int srcSliceH,
1973 uint8_t *
const dst[],
const int dstStride[])
1977 dst[0] + srcSliceY * dstStride[0],
1978 dst[1] + (srcSliceY >> 1) * dstStride[1],
1979 dst[2] + (srcSliceY >> 1) * dstStride[2],
1980 c->opts.src_w, srcSliceH,
1981 dstStride[0], dstStride[1], srcStride[0],
1982 c->input_rgb2yuv_table);
1984 fillPlane(
dst[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
1989 const int srcStride[],
int srcSliceY,
int srcSliceH,
1990 uint8_t *
const dst[],
const int dstStride[])
1993 dst[0], dstStride[0]);
1995 planar2x(
src[1],
dst[1] + dstStride[1] * (srcSliceY >> 1),
c->chrSrcW,
1996 srcSliceH >> 2, srcStride[1], dstStride[1]);
1997 planar2x(
src[2],
dst[2] + dstStride[2] * (srcSliceY >> 1),
c->chrSrcW,
1998 srcSliceH >> 2, srcStride[2], dstStride[2]);
2000 fillPlane(
dst[3], dstStride[3],
c->opts.src_w, srcSliceH, srcSliceY, 255);
2005 const int srcStride[],
int srcSliceY,
2006 int srcSliceH, uint8_t *
const dst[],
const int dstStride[])
2009 ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
2010 const uint8_t *srcPtr =
src[0];
2011 float *dstPtr = (
float *)(
dst[0] + dstStride[0] * srcSliceY);
2013 for (y = 0; y < srcSliceH; ++y){
2014 for (x = 0; x <
c->opts.src_w; ++x){
2015 dstPtr[x] =
c->uint2float_lut[srcPtr[x]];
2017 srcPtr += srcStride[0];
2018 dstPtr += dstStrideFloat;
2025 const uint8_t *
const src[],
2026 const int srcStride[],
int srcSliceY,
2027 int srcSliceH, uint8_t *
const dst[],
2028 const int dstStride[])
2031 ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
2032 const float *srcPtr = (
const float *)
src[0];
2033 uint8_t *dstPtr =
dst[0] + dstStride[0] * srcSliceY;
2035 for (y = 0; y < srcSliceH; ++y){
2036 for (x = 0; x <
c->opts.src_w; ++x){
2039 srcPtr += srcStrideFloat;
2040 dstPtr += dstStride[0];
2048 const int srcStride[],
int srcSliceY,
int srcSliceH,
2049 uint8_t *
const dst[],
const int dstStride[])
2051 if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
2052 memcpy(
dst[0] + dstStride[0] * srcSliceY,
src[0], srcSliceH * dstStride[0]);
2055 const uint8_t *srcPtr =
src[0];
2056 uint8_t *dstPtr =
dst[0] + dstStride[0] * srcSliceY;
2060 while (length +
c->opts.src_w <=
FFABS(dstStride[0]) &&
2061 length +
c->opts.src_w <=
FFABS(srcStride[0]))
2062 length +=
c->opts.src_w;
2065 for (
i = 0;
i < srcSliceH;
i++) {
2066 memcpy(dstPtr, srcPtr, length);
2067 srcPtr += srcStride[0];
2068 dstPtr += dstStride[0];
2074 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
2075 unsigned shift= src_depth-dst_depth, tmp;\
2076 if (c->opts.dither == SWS_DITHER_NONE) {\
2077 for (i = 0; i < height; i++) {\
2078 for (j = 0; j < length-7; j+=8) {\
2079 dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
2080 dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
2081 dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
2082 dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
2083 dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
2084 dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
2085 dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
2086 dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
2088 for (; j < length; j++) {\
2089 dst[j] = dbswap(bswap(src[j])>>shift);\
2094 } else if (shiftonly) {\
2095 for (i = 0; i < height; i++) {\
2096 const uint8_t *dither= dithers[shift-1][i&7];\
2097 for (j = 0; j < length-7; j+=8) {\
2098 tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
2099 tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
2100 tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
2101 tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
2102 tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
2103 tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
2104 tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
2105 tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
2107 for (; j < length; j++) {\
2108 tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
2114 for (i = 0; i < height; i++) {\
2115 const uint8_t *dither= dithers[shift-1][i&7];\
2116 for (j = 0; j < length-7; j+=8) {\
2117 tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
2118 tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
2119 tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
2120 tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
2121 tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
2122 tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
2123 tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
2124 tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
2126 for (; j < length; j++) {\
2127 tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
2135 const int srcStride[],
int srcSliceY,
int srcSliceH,
2136 uint8_t *
const dst[],
const int dstStride[])
2141 for (plane = 0; plane < 4 &&
dst[plane] !=
NULL; plane++) {
2142 int length = (plane == 0 || plane == 3) ?
c->opts.src_w :
AV_CEIL_RSHIFT(
c->opts.src_w,
c->chrDstHSubSample);
2143 int y = (plane == 0 || plane == 3) ? srcSliceY:
AV_CEIL_RSHIFT(srcSliceY,
c->chrDstVSubSample);
2144 int height = (plane == 0 || plane == 3) ? srcSliceH:
AV_CEIL_RSHIFT(srcSliceH,
c->chrDstVSubSample);
2145 const uint8_t *srcPtr =
src[plane];
2146 uint8_t *dstPtr =
dst[plane] + dstStride[plane] * y;
2147 int shiftonly = plane == 1 || plane == 2 || (!
c->opts.src_range && plane == 0);
2150 if (plane == 1 && !
dst[2])
continue;
2151 if (!
src[plane] || (plane == 1 && !
src[2])) {
2154 plane == 3, desc_dst->
comp[plane].
depth,
2155 isBE(
c->opts.dst_format));
2158 (plane == 3) ? 255 : 128);
2164 const int src_depth = desc_src->
comp[plane].
depth;
2165 const int dst_depth = desc_dst->
comp[plane].
depth;
2166 const uint16_t *srcPtr2 = (
const uint16_t *) srcPtr;
2167 uint16_t *dstPtr2 = (uint16_t*)dstPtr;
2169 if (dst_depth == 8) {
2170 if(
isBE(
c->opts.src_format) == HAVE_BIGENDIAN){
2171 DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
2175 }
else if (src_depth == 8) {
2179 for (j = 0; j < length; j++)\
2180 w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
2182 for (j = 0; j < length; j++)\
2183 w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
2184 (srcPtr[j]>>(2*8-dst_depth)));\
2186 if(
isBE(
c->opts.dst_format)){
2191 dstPtr2 += dstStride[plane]/2;
2192 srcPtr += srcStride[plane];
2194 }
else if (src_depth <= dst_depth) {
2197 if(
isBE(
c->opts.src_format) == HAVE_BIGENDIAN &&
2198 isBE(
c->opts.dst_format) == HAVE_BIGENDIAN &&
2200 unsigned shift = dst_depth - src_depth;
2202 #define FAST_COPY_UP(shift) \
2203 for (; j < length - 3; j += 4) { \
2204 uint64_t v = AV_RN64A(srcPtr2 + j); \
2205 AV_WN64A(dstPtr2 + j, v << shift); \
2208 #define FAST_COPY_UP(shift) \
2209 for (; j < length - 1; j += 2) { \
2210 uint32_t v = AV_RN32A(srcPtr2 + j); \
2211 AV_WN32A(dstPtr2 + j, v << shift); \
2220 #define COPY_UP(r,w) \
2222 for (; j < length; j++){ \
2223 unsigned int v= r(&srcPtr2[j]);\
2224 w(&dstPtr2[j], v<<(dst_depth-src_depth));\
2227 for (; j < length; j++){ \
2228 unsigned int v= r(&srcPtr2[j]);\
2229 w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
2230 (v>>(2*src_depth-dst_depth)));\
2233 if(
isBE(
c->opts.src_format)){
2234 if(
isBE(
c->opts.dst_format)){
2240 if(
isBE(
c->opts.dst_format)){
2246 dstPtr2 += dstStride[plane]/2;
2247 srcPtr2 += srcStride[plane]/2;
2250 if(
isBE(
c->opts.src_format) == HAVE_BIGENDIAN){
2251 if(
isBE(
c->opts.dst_format) == HAVE_BIGENDIAN){
2252 DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
2257 if(
isBE(
c->opts.dst_format) == HAVE_BIGENDIAN){
2265 isBE(
c->opts.src_format) !=
isBE(
c->opts.dst_format)) {
2268 for (j = 0; j < length; j++)
2269 ((uint16_t *) dstPtr)[j] =
av_bswap16(((
const uint16_t *) srcPtr)[j]);
2270 srcPtr += srcStride[plane];
2271 dstPtr += dstStride[plane];
2274 isBE(
c->opts.src_format) !=
isBE(
c->opts.dst_format)) {
2276 for (j = 0; j < length; j++)
2277 ((uint32_t *) dstPtr)[j] =
av_bswap32(((
const uint32_t *) srcPtr)[j]);
2278 srcPtr += srcStride[plane];
2279 dstPtr += dstStride[plane];
2281 }
else if (dstStride[plane] == srcStride[plane] &&
2282 srcStride[plane] > 0 && srcStride[plane] == length) {
2283 memcpy(
dst[plane] + dstStride[plane] * y,
src[plane],
2284 height * dstStride[plane]);
2291 memcpy(dstPtr, srcPtr, length);
2292 srcPtr += srcStride[plane];
2293 dstPtr += dstStride[plane];
2302 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
2303 ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
2304 (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
2311 const int flags =
c->opts.flags;
2312 const int dstH =
c->opts.dst_h;
2313 const int dstW =
c->opts.dst_w;
2316 needsDither =
isAnyRGB(dstFormat) &&
2317 c->dstFormatBpp < 24 &&
2318 (
c->dstFormatBpp <
c->srcFormatBpp || (!
isAnyRGB(srcFormat)));
2345 c->dst_slice_align = 2;
2365 c->dst_slice_align = 4;
2396 #define isByteRGB(f) ( \
2397 f == AV_PIX_FMT_RGB32 || \
2398 f == AV_PIX_FMT_RGB32_1 || \
2399 f == AV_PIX_FMT_RGB24 || \
2400 f == AV_PIX_FMT_BGR32 || \
2401 f == AV_PIX_FMT_BGR32_1 || \
2402 f == AV_PIX_FMT_BGR24)
2459 c->dst_slice_align = 2;
2466 else if (!
isBayer(dstFormat)) {
2574 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
2576 if ( srcFormat == dstFormat ||
2583 c->chrDstHSubSample ==
c->chrSrcHSubSample &&
2584 c->chrDstVSubSample ==
c->chrSrcVSubSample &&
2604 int num_pixels,
const uint8_t *palette)
2608 for (
i = 0;
i < num_pixels;
i++)
2609 ((uint32_t *)
dst)[
i] = ((
const uint32_t *) palette)[
src[
i]];
2614 int num_pixels,
const uint8_t *palette)
2618 for (
i = 0;
i < num_pixels;
i++) {
2620 dst[0] = palette[
src[
i] * 4 + 0];
2621 dst[1] = palette[
src[
i] * 4 + 1];
2622 dst[2] = palette[
src[
i] * 4 + 2];