44 {117504, 138453, 13954, 34903},
45 {117504, 138453, 13954, 34903},
46 {104597, 132201, 25675, 53279},
47 {104597, 132201, 25675, 53279},
48 {104448, 132798, 24759, 53109},
49 {104597, 132201, 25675, 53279},
50 {104597, 132201, 25675, 53279},
51 {117579, 136230, 16907, 35559}
56 if (colorspace > 7 || colorspace < 0)
61 #define LOADCHROMA(i) \
64 r = (void *)c->table_rV[V]; \
65 g = (void *)(c->table_gU[U] + c->table_gV[V]); \
66 b = (void *)c->table_bU[U];
68 #define PUTRGB(dst,src,i) \
70 dst[2*i ] = r[Y] + g[Y] + b[Y]; \
72 dst[2*i+1] = r[Y] + g[Y] + b[Y];
74 #define PUTRGB24(dst,src,i) \
76 dst[6*i+0] = r[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = b[Y]; \
78 dst[6*i+3] = r[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = b[Y];
80 #define PUTBGR24(dst,src,i) \
82 dst[6*i+0] = b[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = r[Y]; \
84 dst[6*i+3] = b[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = r[Y];
86 #define PUTRGBA(dst,ysrc,asrc,i,s) \
88 dst[2*i ] = r[Y] + g[Y] + b[Y] + (asrc[2*i ]<<s); \
90 dst[2*i+1] = r[Y] + g[Y] + b[Y] + (asrc[2*i+1]<<s);
92 #define PUTRGB48(dst,src,i) \
94 dst[12*i+ 0] = dst[12*i+ 1] = r[Y]; \
95 dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \
96 dst[12*i+ 4] = dst[12*i+ 5] = b[Y]; \
98 dst[12*i+ 6] = dst[12*i+ 7] = r[Y]; \
99 dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
100 dst[12*i+10] = dst[12*i+11] = b[Y];
102 #define PUTBGR48(dst,src,i) \
104 dst[12*i+ 0] = dst[12*i+ 1] = b[Y]; \
105 dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \
106 dst[12*i+ 4] = dst[12*i+ 5] = r[Y]; \
108 dst[12*i+ 6] = dst[12*i+ 7] = b[Y]; \
109 dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
110 dst[12*i+10] = dst[12*i+11] = r[Y];
112 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
113 static int func_name(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, \
114 int srcSliceH, uint8_t* dst[], int dstStride[]) \
118 if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {\
122 for (y=0; y<srcSliceH; y+=2) {\
123 dst_type *dst_1 = (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\
124 dst_type *dst_2 = (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
125 dst_type av_unused *r, *b;\
127 const uint8_t *py_1 = src[0] + y*srcStride[0];\
128 const uint8_t *py_2 = py_1 + srcStride[0];\
129 const uint8_t *pu = src[1] + (y>>1)*srcStride[1];\
130 const uint8_t *pv = src[2] + (y>>1)*srcStride[2];\
131 const uint8_t av_unused *pa_1, *pa_2;\
132 unsigned int h_size = c->dstW>>3;\
134 pa_1 = src[3] + y*srcStride[3];\
135 pa_2 = pa_1 + srcStride[3];\
141 #define ENDYUV2RGBLINE(dst_delta)\
150 int av_unused Y, U, V;\
152 #define ENDYUV2RGBFUNC()\
158 #define CLOSEYUV2RGBFUNC(dst_delta)\
159 ENDYUV2RGBLINE(dst_delta)\
370 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
372 #define PUTRGB12(dst,src,i,o) \
374 dst[2*i] = r[Y+d16[0+o]] + g[Y+d16[0+o]] + b[Y+d16[0+o]]; \
376 dst[2*i+1] = r[Y+d16[1+o]] + g[Y+d16[1+o]] + b[Y+d16[1+o]];
396 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
399 #define PUTRGB8(dst,src,i,o) \
401 dst[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \
403 dst[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
422 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
427 #define PUTRGB4D(dst,src,i,o) \
429 acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
431 acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4; \
451 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
455 #define PUTRGB4DB(dst,src,i,o) \
457 dst[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
459 dst[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
478 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
483 #define PUTRGB1(out,src,i,o) \
485 out+= out + g[Y+d128[0+o]]; \
487 out+= out + g[Y+d128[1+o]];
526 switch (c->dstFormat) {
556 static void fill_table(uint8_t* table[256],
const int elemsize,
const int inc,
void *y_tab)
560 uint8_t *y_table = y_tab;
562 y_table -= elemsize * (inc >> 9);
564 for (i = 0; i < 256; i++) {
565 table[i] = y_table + elemsize * (cb >> 16);
570 static void fill_gv_table(
int table[256],
const int elemsize,
const int inc)
574 int off = -(inc >> 9);
576 for (i = 0; i < 256; i++) {
577 table[i] = elemsize * (off + (cb >> 16));
584 int r= (f + (1<<15))>>16;
585 if (r<-0x7FFF)
return 0x8000;
586 else if (r> 0x7FFF)
return 0x7FFF;
616 int i, base, rbase, gbase, bbase, abase, needAlpha;
617 const int yoffs = fullRange ? 384 : 326;
619 int64_t crv = inv_table[0];
620 int64_t cbu = inv_table[1];
621 int64_t cgu = -inv_table[2];
622 int64_t cgv = -inv_table[3];
632 crv = (crv*224) / 255;
633 cbu = (cbu*224) / 255;
634 cgu = (cgu*224) / 255;
635 cgv = (cgv*224) / 255;
645 c->
uOffset= 0x0400040004000400LL;
646 c->
vOffset= 0x0400040004000400LL;
662 crv = ((crv << 16) + 0x8000) / cy;
663 cbu = ((cbu << 16) + 0x8000) / cy;
664 cgu = ((cgu << 16) + 0x8000) / cy;
665 cgv = ((cgv << 16) + 0x8000) / cy;
673 yb = -(384<<16) - oy;
674 for (i = 0; i < 1024-110; i++) {
675 y_table[i+110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
683 rbase = isRgb ? 3 : 0;
685 bbase = isRgb ? 0 : 3;
688 yb = -(384<<16) - oy;
689 for (i = 0; i < 1024-110; i++) {
690 int yval = av_clip_uint8((yb + 0x8000) >> 16);
691 y_table[i+110 ] = (yval >> 7) << rbase;
692 y_table[i+ 37+1024] = ((yval + 43) / 85) << gbase;
693 y_table[i+110+2048] = (yval >> 7) << bbase;
702 rbase = isRgb ? 5 : 0;
703 gbase = isRgb ? 2 : 3;
704 bbase = isRgb ? 0 : 6;
707 yb = -(384<<16) - oy;
708 for (i = 0; i < 1024-38; i++) {
709 int yval = av_clip_uint8((yb + 0x8000) >> 16);
710 y_table[i+16 ] = ((yval + 18) / 36) << rbase;
711 y_table[i+16+1024] = ((yval + 18) / 36) << gbase;
712 y_table[i+37+2048] = ((yval + 43) / 85) << bbase;
721 rbase = isRgb ? 8 : 0;
723 bbase = isRgb ? 0 : 8;
726 yb = -(384<<16) - oy;
727 for (i = 0; i < 1024; i++) {
728 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
729 y_table16[i ] = (yval >> 4) << rbase;
730 y_table16[i+1024] = (yval >> 4) << gbase;
731 y_table16[i+2048] = (yval >> 4) << bbase;
735 for (i = 0; i < 1024*3; i++)
744 rbase = isRgb ? bpp - 5 : 0;
746 bbase = isRgb ? 0 : (bpp - 5);
749 yb = -(384<<16) - oy;
750 for (i = 0; i < 1024; i++) {
751 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
752 y_table16[i ] = (yval >> 3) << rbase;
753 y_table16[i+1024] = (yval >> (18 - bpp)) << gbase;
754 y_table16[i+2048] = (yval >> 3) << bbase;
758 for (i = 0; i < 1024*3; i++)
769 yb = -(384<<16) - oy;
770 for (i = 0; i < 1024; i++) {
771 y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
781 rbase = base + (isRgb ? 16 : 0);
783 bbase = base + (isRgb ? 0 : 16);
786 abase = (base + 24) & 31;
789 yb = -(384<<16) - oy;
790 for (i = 0; i < 1024; i++) {
791 unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
792 y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255u << abase));
793 y_table32[i+1024] = yval << gbase;
794 y_table32[i+2048] = yval << bbase;