mirror of
https://github.com/mpv-player/mpv
synced 2024-12-26 00:42:57 +00:00
Add a helper function to get the chroma scale shift and use to simplify mpi setup.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30138 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
427039acff
commit
92f20f876f
@ -79,3 +79,40 @@ const char *vo_format_name(int format)
|
||||
snprintf(unknown_format,20,"Unknown 0x%04x",format);
|
||||
return unknown_format;
|
||||
}
|
||||
|
||||
int mp_get_chroma_shift(int format, int *x_shift, int *y_shift)
|
||||
{
|
||||
int xs = 0, ys = 0;
|
||||
int err = 0;
|
||||
switch (format) {
|
||||
case IMGFMT_I420:
|
||||
case IMGFMT_IYUV:
|
||||
case IMGFMT_YV12:
|
||||
xs = 1;
|
||||
ys = 1;
|
||||
break;
|
||||
case IMGFMT_IF09:
|
||||
case IMGFMT_YVU9:
|
||||
xs = 2;
|
||||
ys = 2;
|
||||
break;
|
||||
case IMGFMT_444P:
|
||||
xs = 0;
|
||||
ys = 0;
|
||||
break;
|
||||
case IMGFMT_422P:
|
||||
xs = 1;
|
||||
ys = 0;
|
||||
break;
|
||||
case IMGFMT_411P:
|
||||
xs = 2;
|
||||
ys = 0;
|
||||
break;
|
||||
default:
|
||||
err = 1;
|
||||
break;
|
||||
}
|
||||
if (x_shift) *x_shift = xs;
|
||||
if (y_shift) *y_shift = ys;
|
||||
return err ? 0 : 8 + (16 >> (xs + ys));
|
||||
}
|
||||
|
@ -133,4 +133,11 @@ typedef struct {
|
||||
|
||||
const char *vo_format_name(int format);
|
||||
|
||||
/**
|
||||
* Calculates the scale shifts for the chroma planes for planar YUV
|
||||
*
|
||||
* \return bits-per-pixel for format if successful (i.e. format is 3 or 4-planes planar YUV), 0 otherwise
|
||||
*/
|
||||
int mp_get_chroma_shift(int format, int *x_shift, int *y_shift);
|
||||
|
||||
#endif /* MPLAYER_IMG_FORMAT_H */
|
||||
|
@ -133,51 +133,24 @@ static inline void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){
|
||||
}
|
||||
mpi->flags|=MP_IMGFLAG_YUV;
|
||||
mpi->num_planes=3;
|
||||
if (mp_get_chroma_shift(out_fmt, NULL, NULL)) {
|
||||
mpi->flags|=MP_IMGFLAG_PLANAR;
|
||||
mpi->bpp = mp_get_chroma_shift(out_fmt, &mpi->chroma_x_shift, &mpi->chroma_y_shift);
|
||||
mpi->chroma_width = mpi->width >> mpi->chroma_x_shift;
|
||||
mpi->chroma_height = mpi->height >> mpi->chroma_y_shift;
|
||||
}
|
||||
switch(out_fmt){
|
||||
case IMGFMT_I420:
|
||||
case IMGFMT_IYUV:
|
||||
mpi->flags|=MP_IMGFLAG_SWAPPED;
|
||||
case IMGFMT_YV12:
|
||||
mpi->flags|=MP_IMGFLAG_PLANAR;
|
||||
mpi->bpp=12;
|
||||
mpi->chroma_width=(mpi->width>>1);
|
||||
mpi->chroma_height=(mpi->height>>1);
|
||||
mpi->chroma_x_shift=1;
|
||||
mpi->chroma_y_shift=1;
|
||||
return;
|
||||
case IMGFMT_IF09:
|
||||
mpi->num_planes=4;
|
||||
case IMGFMT_YVU9:
|
||||
mpi->flags|=MP_IMGFLAG_PLANAR;
|
||||
mpi->bpp=9;
|
||||
mpi->chroma_width=(mpi->width>>2);
|
||||
mpi->chroma_height=(mpi->height>>2);
|
||||
mpi->chroma_x_shift=2;
|
||||
mpi->chroma_y_shift=2;
|
||||
return;
|
||||
case IMGFMT_444P:
|
||||
mpi->flags|=MP_IMGFLAG_PLANAR;
|
||||
mpi->bpp=24;
|
||||
mpi->chroma_width=(mpi->width);
|
||||
mpi->chroma_height=(mpi->height);
|
||||
mpi->chroma_x_shift=0;
|
||||
mpi->chroma_y_shift=0;
|
||||
return;
|
||||
case IMGFMT_422P:
|
||||
mpi->flags|=MP_IMGFLAG_PLANAR;
|
||||
mpi->bpp=16;
|
||||
mpi->chroma_width=(mpi->width>>1);
|
||||
mpi->chroma_height=(mpi->height);
|
||||
mpi->chroma_x_shift=1;
|
||||
mpi->chroma_y_shift=0;
|
||||
return;
|
||||
case IMGFMT_411P:
|
||||
mpi->flags|=MP_IMGFLAG_PLANAR;
|
||||
mpi->bpp=12;
|
||||
mpi->chroma_width=(mpi->width>>2);
|
||||
mpi->chroma_height=(mpi->height);
|
||||
mpi->chroma_x_shift=2;
|
||||
mpi->chroma_y_shift=0;
|
||||
return;
|
||||
case IMGFMT_Y800:
|
||||
case IMGFMT_Y8:
|
||||
|
Loading…
Reference in New Issue
Block a user