mirror of
https://github.com/mpv-player/mpv
synced 2025-03-22 11:18:32 +00:00
fixing rgb4 & bgr4 (2 pixels per byte)
adding bg4b & rg4b (1 pixel per byte) git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9172 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
6df2ca6ea6
commit
49a3af8585
@ -6,6 +6,7 @@ char *vo_format_name(int format)
|
||||
{
|
||||
case IMGFMT_RGB1: return("RGB 1-bit");
|
||||
case IMGFMT_RGB4: return("RGB 4-bit");
|
||||
case IMGFMT_RG4B: return("RGB 4-bit per byte");
|
||||
case IMGFMT_RGB8: return("RGB 8-bit");
|
||||
case IMGFMT_RGB15: return("RGB 15-bit");
|
||||
case IMGFMT_RGB16: return("RGB 16-bit");
|
||||
@ -13,6 +14,7 @@ char *vo_format_name(int format)
|
||||
case IMGFMT_RGB32: return("RGB 32-bit");
|
||||
case IMGFMT_BGR1: return("BGR 1-bit");
|
||||
case IMGFMT_BGR4: return("BGR 4-bit");
|
||||
case IMGFMT_BG4B: return("BGR 4-bit per byte");
|
||||
case IMGFMT_BGR8: return("BGR 8-bit");
|
||||
case IMGFMT_BGR15: return("BGR 15-bit");
|
||||
case IMGFMT_BGR16: return("BGR 16-bit");
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8))
|
||||
#define IMGFMT_RGB1 (IMGFMT_RGB|1)
|
||||
#define IMGFMT_RGB4 (IMGFMT_RGB|4)
|
||||
#define IMGFMT_RG4B (IMGFMT_RGB|4|128) // RGB4 with 1 pixel per byte
|
||||
#define IMGFMT_RGB8 (IMGFMT_RGB|8)
|
||||
#define IMGFMT_RGB15 (IMGFMT_RGB|15)
|
||||
#define IMGFMT_RGB16 (IMGFMT_RGB|16)
|
||||
@ -18,6 +19,7 @@
|
||||
#define IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8))
|
||||
#define IMGFMT_BGR1 (IMGFMT_BGR|1)
|
||||
#define IMGFMT_BGR4 (IMGFMT_BGR|4)
|
||||
#define IMGFMT_BG4B (IMGFMT_BGR|4|128) // BGR4 with 1 pixel per byte
|
||||
#define IMGFMT_BGR8 (IMGFMT_BGR|8)
|
||||
#define IMGFMT_BGR15 (IMGFMT_BGR|15)
|
||||
#define IMGFMT_BGR16 (IMGFMT_BGR|16)
|
||||
@ -27,8 +29,8 @@
|
||||
#define IMGFMT_IS_RGB(fmt) (((fmt)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
|
||||
#define IMGFMT_IS_BGR(fmt) (((fmt)&IMGFMT_BGR_MASK)==IMGFMT_BGR)
|
||||
|
||||
#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&~IMGFMT_RGB_MASK)
|
||||
#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&~IMGFMT_BGR_MASK)
|
||||
#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&0x3F)
|
||||
#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&0x3F)
|
||||
|
||||
|
||||
/* Planar YUV Formats */
|
||||
|
@ -96,14 +96,14 @@ static inline void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){
|
||||
}
|
||||
mpi->num_planes=1;
|
||||
if (IMGFMT_IS_RGB(out_fmt)) {
|
||||
if (IMGFMT_RGB_DEPTH(out_fmt) < 8)
|
||||
if (IMGFMT_RGB_DEPTH(out_fmt) < 8 && !(out_fmt&128))
|
||||
mpi->bpp = IMGFMT_RGB_DEPTH(out_fmt);
|
||||
else
|
||||
mpi->bpp=(IMGFMT_RGB_DEPTH(out_fmt)+7)&(~7);
|
||||
return;
|
||||
}
|
||||
if (IMGFMT_IS_BGR(out_fmt)) {
|
||||
if (IMGFMT_BGR_DEPTH(out_fmt) < 8)
|
||||
if (IMGFMT_BGR_DEPTH(out_fmt) < 8 && !(out_fmt&128))
|
||||
mpi->bpp = IMGFMT_BGR_DEPTH(out_fmt);
|
||||
else
|
||||
mpi->bpp=(IMGFMT_BGR_DEPTH(out_fmt)+7)&(~7);
|
||||
|
@ -44,6 +44,7 @@ static int open(vf_instance_t *vf, char* args){
|
||||
if(!strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else
|
||||
if(!strcasecmp(args,"bgr8")) vf->priv->fmt=IMGFMT_BGR8; else
|
||||
if(!strcasecmp(args,"bgr4")) vf->priv->fmt=IMGFMT_BGR4; else
|
||||
if(!strcasecmp(args,"bg4b")) vf->priv->fmt=IMGFMT_BG4B; else
|
||||
if(!strcasecmp(args,"bgr1")) vf->priv->fmt=IMGFMT_BGR1; else
|
||||
if(!strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else
|
||||
if(!strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else
|
||||
@ -51,6 +52,7 @@ static int open(vf_instance_t *vf, char* args){
|
||||
if(!strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else
|
||||
if(!strcasecmp(args,"rgb8")) vf->priv->fmt=IMGFMT_RGB8; else
|
||||
if(!strcasecmp(args,"rgb4")) vf->priv->fmt=IMGFMT_RGB4; else
|
||||
if(!strcasecmp(args,"rg4b")) vf->priv->fmt=IMGFMT_RG4B; else
|
||||
if(!strcasecmp(args,"rgb1")) vf->priv->fmt=IMGFMT_RGB1; else
|
||||
{ printf("Unknown format name: '%s'\n",args);return 0;}
|
||||
} else
|
||||
|
@ -41,6 +41,8 @@ static unsigned int outfmt_list[]={
|
||||
IMGFMT_RGB8,
|
||||
IMGFMT_BGR4,
|
||||
IMGFMT_RGB4,
|
||||
IMGFMT_BG4B,
|
||||
IMGFMT_RG4B,
|
||||
IMGFMT_BGR1,
|
||||
IMGFMT_RGB1,
|
||||
// YUV:
|
||||
@ -178,7 +180,8 @@ static int config(struct vf_instance_s* vf,
|
||||
vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
|
||||
}
|
||||
break; }
|
||||
case IMGFMT_BGR4: {
|
||||
case IMGFMT_BGR4:
|
||||
case IMGFMT_BG4B: {
|
||||
int i;
|
||||
vf->priv->palette=malloc(4*16);
|
||||
for(i=0; i<16; i++){
|
||||
|
@ -517,7 +517,10 @@ static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
|
||||
}
|
||||
#endif
|
||||
if (pformat == IMGFMT_YV12) {
|
||||
yuv2rgb_init(bpp, MODE_RGB);
|
||||
if(bpp==4)
|
||||
yuv2rgb_init(bpp|128, MODE_RGB);
|
||||
else
|
||||
yuv2rgb_init(bpp, MODE_RGB);
|
||||
}
|
||||
|
||||
x_pos = (WIDTH - maxw) / 2;
|
||||
@ -748,7 +751,7 @@ static uint32_t query_format(uint32_t format) {
|
||||
case 8 : if ((format == IMGFMT_RGB8 ) || (format == IMGFMT_BGR8))
|
||||
return ((bpp_avail & BPP_8 ) ? 1 : 0);
|
||||
break;
|
||||
case 4 : if ((format == IMGFMT_RGB4 ) || (format == IMGFMT_BGR4))
|
||||
case 4 : if ((format == IMGFMT_RG4B ) || (format == IMGFMT_BG4B))
|
||||
return ((bpp_avail & BPP_4 ) ? 1 : 0);
|
||||
break;
|
||||
case 1 : if ((format == IMGFMT_RGB1 ) || (format == IMGFMT_BGR1))
|
||||
|
@ -583,6 +583,17 @@ static inline void yuv2yuvXinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilt
|
||||
break;\
|
||||
case IMGFMT_RGB4:\
|
||||
case IMGFMT_BGR4:\
|
||||
{\
|
||||
const uint8_t * const d64= dither_8x8_73 [y&7];\
|
||||
const uint8_t * const d128=dither_8x8_220[y&7];\
|
||||
func(uint8_t)\
|
||||
((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\
|
||||
+ ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\
|
||||
}\
|
||||
}\
|
||||
break;\
|
||||
case IMGFMT_RG4B:\
|
||||
case IMGFMT_BG4B:\
|
||||
{\
|
||||
const uint8_t * const d64= dither_8x8_73 [y&7];\
|
||||
const uint8_t * const d128=dither_8x8_220[y&7];\
|
||||
@ -747,6 +758,17 @@ static inline void yuv2packedXinC(SwsContext *c, int16_t *lumFilter, int16_t **l
|
||||
break;
|
||||
case IMGFMT_RGB4:
|
||||
case IMGFMT_BGR4:
|
||||
{
|
||||
const uint8_t * const d64= dither_8x8_73 [y&7];
|
||||
const uint8_t * const d128=dither_8x8_220[y&7];
|
||||
YSCALE_YUV_2_RGBX_C(uint8_t)
|
||||
((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];
|
||||
+((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMGFMT_RG4B:
|
||||
case IMGFMT_BG4B:
|
||||
{
|
||||
const uint8_t * const d64= dither_8x8_73 [y&7];
|
||||
const uint8_t * const d128=dither_8x8_220[y&7];
|
||||
|
@ -608,6 +608,118 @@ static void yuv2rgb_c_4 (uint8_t * py_1, uint8_t * py_2,
|
||||
dst_1 = _dst_1;
|
||||
dst_2 = _dst_2;
|
||||
|
||||
while (h_size--) {
|
||||
int acc;
|
||||
#define DST1_4(i) \
|
||||
Y = py_1[2*i]; \
|
||||
acc = r[Y] + g[Y] + b[Y]; \
|
||||
Y = py_1[2*i+1]; \
|
||||
acc |= (r[Y] + g[Y] + b[Y])<<4;\
|
||||
dst_1[i] = acc;
|
||||
|
||||
#define DST2_4(i) \
|
||||
Y = py_2[2*i]; \
|
||||
acc = r[Y] + g[Y] + b[Y]; \
|
||||
Y = py_2[2*i+1]; \
|
||||
acc |= (r[Y] + g[Y] + b[Y])<<4;\
|
||||
dst_2[i] = acc;
|
||||
|
||||
RGB(0);
|
||||
DST1_4(0);
|
||||
DST2_4(0);
|
||||
|
||||
RGB(1);
|
||||
DST2_4(1);
|
||||
DST1_4(1);
|
||||
|
||||
RGB(2);
|
||||
DST1_4(2);
|
||||
DST2_4(2);
|
||||
|
||||
RGB(3);
|
||||
DST2_4(3);
|
||||
DST1_4(3);
|
||||
|
||||
pu += 4;
|
||||
pv += 4;
|
||||
py_1 += 8;
|
||||
py_2 += 8;
|
||||
dst_1 += 4;
|
||||
dst_2 += 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void yuv2rgb_c_4_ordered_dither (uint8_t * py_1, uint8_t * py_2,
|
||||
uint8_t * pu, uint8_t * pv,
|
||||
void * _dst_1, void * _dst_2, int h_size, int v_pos)
|
||||
{
|
||||
int U, V, Y;
|
||||
uint8_t * r, * g, * b;
|
||||
uint8_t * dst_1, * dst_2;
|
||||
|
||||
h_size >>= 3;
|
||||
dst_1 = _dst_1;
|
||||
dst_2 = _dst_2;
|
||||
|
||||
while (h_size--) {
|
||||
const uint8_t *d64= dither_8x8_73[v_pos&7];
|
||||
const uint8_t *d128=dither_8x8_220[v_pos&7];
|
||||
int acc;
|
||||
|
||||
#define DST1bpp4(i,o) \
|
||||
Y = py_1[2*i]; \
|
||||
acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
|
||||
Y = py_1[2*i+1]; \
|
||||
acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4;\
|
||||
dst_1[i]= acc;
|
||||
|
||||
#define DST2bpp4(i,o) \
|
||||
Y = py_2[2*i]; \
|
||||
acc = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
|
||||
Y = py_2[2*i+1]; \
|
||||
acc |= (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4;\
|
||||
dst_2[i]= acc;
|
||||
|
||||
|
||||
RGB(0);
|
||||
DST1bpp4(0,0);
|
||||
DST2bpp4(0,0);
|
||||
|
||||
RGB(1);
|
||||
DST2bpp4(1,2);
|
||||
DST1bpp4(1,2);
|
||||
|
||||
RGB(2);
|
||||
DST1bpp4(2,4);
|
||||
DST2bpp4(2,4);
|
||||
|
||||
RGB(3);
|
||||
DST2bpp4(3,6);
|
||||
DST1bpp4(3,6);
|
||||
|
||||
pu += 4;
|
||||
pv += 4;
|
||||
py_1 += 8;
|
||||
py_2 += 8;
|
||||
dst_1 += 4;
|
||||
dst_2 += 4;
|
||||
}
|
||||
}
|
||||
|
||||
// This is exactly the same code as yuv2rgb_c_32 except for the types of
|
||||
// r, g, b, dst_1, dst_2
|
||||
static void yuv2rgb_c_4b (uint8_t * py_1, uint8_t * py_2,
|
||||
uint8_t * pu, uint8_t * pv,
|
||||
void * _dst_1, void * _dst_2, int h_size, int v_pos)
|
||||
{
|
||||
int U, V, Y;
|
||||
uint8_t * r, * g, * b;
|
||||
uint8_t * dst_1, * dst_2;
|
||||
|
||||
h_size >>= 3;
|
||||
dst_1 = _dst_1;
|
||||
dst_2 = _dst_2;
|
||||
|
||||
while (h_size--) {
|
||||
RGB(0);
|
||||
DST1(0);
|
||||
@ -634,7 +746,7 @@ static void yuv2rgb_c_4 (uint8_t * py_1, uint8_t * py_2,
|
||||
}
|
||||
}
|
||||
|
||||
static void yuv2rgb_c_4_ordered_dither (uint8_t * py_1, uint8_t * py_2,
|
||||
static void yuv2rgb_c_4b_ordered_dither (uint8_t * py_1, uint8_t * py_2,
|
||||
uint8_t * pu, uint8_t * pv,
|
||||
void * _dst_1, void * _dst_2, int h_size, int v_pos)
|
||||
{
|
||||
@ -650,13 +762,13 @@ static void yuv2rgb_c_4_ordered_dither (uint8_t * py_1, uint8_t * py_2,
|
||||
const uint8_t *d64= dither_8x8_73[v_pos&7];
|
||||
const uint8_t *d128=dither_8x8_220[v_pos&7];
|
||||
|
||||
#define DST1bpp4(i,o) \
|
||||
#define DST1bpp4b(i,o) \
|
||||
Y = py_1[2*i]; \
|
||||
dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
|
||||
Y = py_1[2*i+1]; \
|
||||
dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
|
||||
|
||||
#define DST2bpp4(i,o) \
|
||||
#define DST2bpp4b(i,o) \
|
||||
Y = py_2[2*i]; \
|
||||
dst_2[2*i] = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
|
||||
Y = py_2[2*i+1]; \
|
||||
@ -664,20 +776,20 @@ static void yuv2rgb_c_4_ordered_dither (uint8_t * py_1, uint8_t * py_2,
|
||||
|
||||
|
||||
RGB(0);
|
||||
DST1bpp4(0,0);
|
||||
DST2bpp4(0,0);
|
||||
DST1bpp4b(0,0);
|
||||
DST2bpp4b(0,0);
|
||||
|
||||
RGB(1);
|
||||
DST2bpp4(1,2);
|
||||
DST1bpp4(1,2);
|
||||
DST2bpp4b(1,2);
|
||||
DST1bpp4b(1,2);
|
||||
|
||||
RGB(2);
|
||||
DST1bpp4(2,4);
|
||||
DST2bpp4(2,4);
|
||||
DST1bpp4b(2,4);
|
||||
DST2bpp4b(2,4);
|
||||
|
||||
RGB(3);
|
||||
DST2bpp4(3,6);
|
||||
DST1bpp4(3,6);
|
||||
DST2bpp4b(3,6);
|
||||
DST1bpp4b(3,6);
|
||||
|
||||
pu += 4;
|
||||
pv += 4;
|
||||
@ -879,7 +991,11 @@ void *yuv2rgb_c_init (unsigned bpp, int mode, void *table_rV[256], void *table_g
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
yuv2rgb_c_internal = yuv2rgb_c_4_ordered_dither; //yuv2rgb_c_4;
|
||||
case 4|128:
|
||||
if(bpp==4)
|
||||
yuv2rgb_c_internal = yuv2rgb_c_4_ordered_dither; //yuv2rgb_c_4;
|
||||
else
|
||||
yuv2rgb_c_internal = yuv2rgb_c_4b_ordered_dither; //yuv2rgb_c_4;
|
||||
|
||||
table_start= table_121 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user