From 8751a0e261c0c7150874f78b23c7f1d3539883b5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 23 Dec 2012 20:03:30 +0100 Subject: video: decouple internal pixel formats from FourCCs mplayer's video chain traditionally used FourCCs for pixel formats. For example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the string 'YV12' interpreted as unsigned int. Additionally, it used to encode information into the numeric values of some formats. The RGB formats had their bit depth and endian encoded into the least significant byte. Extended planar formats (420P10 etc.) had chroma shift, endian, and component bit depth encoded. (This has been removed in recent commits.) Replace the FourCC mess with a simple enum. Remove all the redundant formats like YV12/I420/IYUV. Replace some image format names by something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P. Add img_fourcc.h, which contains the old IDs for code that actually uses FourCCs. Change the way demuxers, that output raw video, identify the video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to request the rawvideo decoder, and sh_video->imgfmt specifies the pixel format. Like the previous hack, this is supposed to avoid the need for a complete codecs.cfg entry per format, or other lookup tables. (Note that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT raw video, but this is still considered better than adding a raw video decoder - even if trivial, it would be full of annoying lookup tables.) The TV code has not been tested. Some corrective changes regarding endian and other image format flags creep in. --- video/decode/lavc.h | 1 - video/decode/vd_lavc.c | 19 +- video/filter/vf_crop.c | 8 +- video/filter/vf_delogo.c | 10 +- video/filter/vf_divtc.c | 7 +- video/filter/vf_down3dright.c | 8 +- video/filter/vf_eq.c | 9 +- video/filter/vf_expand.c | 2 +- video/filter/vf_format.c | 2 +- video/filter/vf_gradfun.c | 13 +- video/filter/vf_hqdn3d.c | 13 +- video/filter/vf_ilpack.c | 8 +- video/filter/vf_mirror.c | 3 +- video/filter/vf_noformat.c | 2 +- video/filter/vf_noise.c | 10 +- video/filter/vf_pp.c | 10 +- video/filter/vf_pullup.c | 4 +- video/filter/vf_rotate.c | 10 +- video/filter/vf_scale.c | 39 ++-- video/filter/vf_sub.c | 12 +- video/filter/vf_swapuv.c | 11 +- video/filter/vf_unsharp.c | 10 +- video/filter/vf_yadif.c | 5 +- video/fmt-conversion.c | 58 +++--- video/image_writer.c | 8 +- video/img_format.c | 217 +++++++++------------- video/img_format.h | 422 +++++++++++++++++++----------------------- video/img_fourcc.h | 57 ++++++ video/out/gl_common.c | 10 +- video/out/vo.h | 2 +- video/out/vo_corevideo.m | 4 +- video/out/vo_direct3d.c | 12 +- video/out/vo_opengl.c | 2 +- video/out/vo_opengl_old.c | 4 +- video/out/vo_sdl.c | 12 +- video/out/vo_vdpau.c | 12 +- video/out/vo_x11.c | 4 +- video/out/vo_xv.c | 36 +++- 38 files changed, 500 insertions(+), 576 deletions(-) create mode 100644 video/img_fourcc.h (limited to 'video') diff --git a/video/decode/lavc.h b/video/decode/lavc.h index a355f61310..df3f97ef87 100644 --- a/video/decode/lavc.h +++ b/video/decode/lavc.h @@ -21,7 +21,6 @@ typedef struct ffmpeg_ctx { double inv_qp_sum; AVRational last_sample_aspect_ratio; enum AVDiscard skip_frame; - int rawvideo_fmt; AVCodec *software_fallback; struct FramePool *dr1_buffer_pool; struct mp_image_pool *non_dr1_pool; diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index 24c3ba4e36..bf4cd42ba3 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -244,7 +244,6 @@ static int init(sh_video_t *sh) AVCodec *lavc_codec = NULL; ctx = sh->context = talloc_zero(NULL, vd_ffmpeg_ctx); - ctx->rawvideo_fmt = PIX_FMT_NONE; ctx->non_dr1_pool = talloc_steal(ctx, mp_image_pool_new(16)); if (sh->codec->dll) { @@ -264,10 +263,6 @@ static int init(sh_video_t *sh) uninit(sh); return 0; } - } else if (!IMGFMT_IS_HWACCEL(sh->format)) { - ctx->rawvideo_fmt = imgfmt2pixfmt(sh->format); - if (ctx->rawvideo_fmt != PIX_FMT_NONE) - lavc_codec = avcodec_find_decoder_by_name("rawvideo"); } if (!lavc_codec) { uninit(sh); @@ -358,11 +353,7 @@ static int init_avctx(sh_video_t *sh, AVCodec *lavc_codec, struct hwdec *hwdec) if (lavc_param->gray) avctx->flags |= CODEC_FLAG_GRAY; avctx->flags2 |= lavc_param->fast; - if (ctx->rawvideo_fmt == PIX_FMT_NONE) { - avctx->codec_tag = sh->format; - } else { - avctx->pix_fmt = ctx->rawvideo_fmt; - } + avctx->codec_tag = sh->format; if (sh->gsh->lavf_codec_tag) avctx->codec_tag = sh->gsh->lavf_codec_tag; avctx->stream_codec_tag = sh->video.fccHandler; @@ -440,6 +431,14 @@ static int init_avctx(sh_video_t *sh, AVCodec *lavc_codec, struct hwdec *hwdec) } break; + case MKTAG('M', 'P', 'v', 'f'): + avctx->codec_tag = 0; + avctx->pix_fmt = imgfmt2pixfmt(sh->imgfmt); + break; + case MKTAG('M', 'P', 'r', 'v'): + avctx->codec_tag = sh->imgfmt; + break; + default: if (!sh->bih || sh->bih->biSize <= sizeof(*sh->bih)) break; diff --git a/video/filter/vf_crop.c b/video/filter/vf_crop.c index 692d05bcc9..c1cb069a81 100644 --- a/video/filter/vf_crop.c +++ b/video/filter/vf_crop.c @@ -54,18 +54,14 @@ static int config(struct vf_instance *vf, if(!IMGFMT_IS_RGB(outfmt) && !IMGFMT_IS_BGR(outfmt)){ switch(outfmt){ case IMGFMT_444P: - case IMGFMT_Y800: case IMGFMT_Y8: break; - case IMGFMT_YVU9: - case IMGFMT_IF09: + case IMGFMT_410P: vf->priv->crop_y&=~3; case IMGFMT_411P: vf->priv->crop_x&=~3; break; - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: vf->priv->crop_y&=~1; default: vf->priv->crop_x&=~1; diff --git a/video/filter/vf_delogo.c b/video/filter/vf_delogo.c index f709aad4d0..346eb468f5 100644 --- a/video/filter/vf_delogo.c +++ b/video/filter/vf_delogo.c @@ -207,18 +207,14 @@ static void uninit(struct vf_instance *vf){ static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: return vf_next_query_format(vf,vf->priv->outfmt); } return 0; } static const unsigned int fmt_list[]={ - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, 0 }; @@ -306,7 +302,7 @@ static int vf_open(vf_instance_t *vf, char *args){ fix_band(vf->priv); // check csp: - vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); + vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P); if(!vf->priv->outfmt) { uninit(vf); diff --git a/video/filter/vf_divtc.c b/video/filter/vf_divtc.c index dadccf9a9b..19b23ac481 100644 --- a/video/filter/vf_divtc.c +++ b/video/filter/vf_divtc.c @@ -577,11 +577,10 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) { switch(fmt) { - case IMGFMT_444P: case IMGFMT_IYUV: case IMGFMT_RGB24: + case IMGFMT_444P: case IMGFMT_RGB24: case IMGFMT_422P: case IMGFMT_UYVY: case IMGFMT_BGR24: - case IMGFMT_411P: case IMGFMT_YUY2: case IMGFMT_IF09: - case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_YVU9: - case IMGFMT_IUYV: case IMGFMT_Y800: case IMGFMT_Y8: + case IMGFMT_411P: case IMGFMT_YUYV: case IMGFMT_410P: + case IMGFMT_420P: case IMGFMT_Y8: return vf_next_query_format(vf,fmt); } diff --git a/video/filter/vf_down3dright.c b/video/filter/vf_down3dright.c index b1835cd26b..21616a4ad2 100644 --- a/video/filter/vf_down3dright.c +++ b/video/filter/vf_down3dright.c @@ -114,7 +114,7 @@ static int config(struct vf_instance *vf, { /* FIXME - also support UYVY output? */ return vf_next_config(vf, width * vf->priv->scalew, - height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_YV12); + height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_420P); } @@ -122,10 +122,8 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) { /* FIXME - really any YUV 4:2:0 input format should work */ switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_IYUV: - case IMGFMT_I420: - return vf_next_query_format(vf, IMGFMT_YV12); + case IMGFMT_420P: + return vf_next_query_format(vf, IMGFMT_420P); } return 0; } diff --git a/video/filter/vf_eq.c b/video/filter/vf_eq.c index cfbe7ea17e..76a8b2bc99 100644 --- a/video/filter/vf_eq.c +++ b/video/filter/vf_eq.c @@ -425,16 +425,13 @@ static int query_format (vf_instance_t *vf, unsigned fmt) { switch (fmt) { - case IMGFMT_YVU9: - case IMGFMT_IF09: - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_Y800: case IMGFMT_Y8: case IMGFMT_444P: case IMGFMT_422P: + case IMGFMT_440P: + case IMGFMT_420P: case IMGFMT_411P: + case IMGFMT_410P: return vf_next_query_format (vf, fmt); } diff --git a/video/filter/vf_expand.c b/video/filter/vf_expand.c index 5ce5db16bd..f8ebbd0b18 100644 --- a/video/filter/vf_expand.c +++ b/video/filter/vf_expand.c @@ -66,7 +66,7 @@ static int config(struct vf_instance *vf, struct MPOpts *opts = vf->opts; mp_image_t test_mpi; mp_image_setfmt(&test_mpi, outfmt); - if (outfmt == IMGFMT_IF09 || !test_mpi.bpp) return 0; + if (test_mpi.num_planes > 3 || !test_mpi.bpp) return 0; vf->priv->exp_x = vf->priv->cfg_exp_x; vf->priv->exp_y = vf->priv->cfg_exp_y; vf->priv->exp_w = vf->priv->cfg_exp_w; diff --git a/video/filter/vf_format.c b/video/filter/vf_format.c index 8abbd9b054..71e3ad7669 100644 --- a/video/filter/vf_format.c +++ b/video/filter/vf_format.c @@ -35,7 +35,7 @@ static struct vf_priv_s { unsigned int fmt; unsigned int outfmt; } const vf_priv_dflt = { - IMGFMT_YUY2, + IMGFMT_YUYV, 0 }; diff --git a/video/filter/vf_gradfun.c b/video/filter/vf_gradfun.c index b9d07bc907..b3c0702375 100644 --- a/video/filter/vf_gradfun.c +++ b/video/filter/vf_gradfun.c @@ -321,20 +321,15 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) static int query_format(struct vf_instance *vf, unsigned int fmt) { switch (fmt){ - case IMGFMT_YVU9: - case IMGFMT_IF09: - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_CLPL: - case IMGFMT_Y800: - case IMGFMT_Y8: case IMGFMT_NV12: case IMGFMT_NV21: + case IMGFMT_Y8: case IMGFMT_444P: case IMGFMT_422P: + case IMGFMT_440P: + case IMGFMT_420P: case IMGFMT_411P: - case IMGFMT_HM12: + case IMGFMT_410P: return vf_next_query_format(vf,fmt); } return 0; diff --git a/video/filter/vf_hqdn3d.c b/video/filter/vf_hqdn3d.c index 1ec0cc5c66..4f49f12715 100644 --- a/video/filter/vf_hqdn3d.c +++ b/video/filter/vf_hqdn3d.c @@ -245,13 +245,12 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_YVU9: - case IMGFMT_444P: - case IMGFMT_422P: - case IMGFMT_411P: + case IMGFMT_444P: + case IMGFMT_422P: + case IMGFMT_440P: + case IMGFMT_420P: + case IMGFMT_411P: + case IMGFMT_410P: return vf_next_query_format(vf, fmt); } return 0; diff --git a/video/filter/vf_ilpack.c b/video/filter/vf_ilpack.c index 73f816cb9e..f153a4b7d0 100644 --- a/video/filter/vf_ilpack.c +++ b/video/filter/vf_ilpack.c @@ -389,7 +389,7 @@ static int config(struct vf_instance *vf, unsigned int flags, unsigned int outfmt) { /* FIXME - also support UYVY output? */ - return vf_next_config(vf, width, height, d_width, d_height, flags, IMGFMT_YUY2); + return vf_next_config(vf, width, height, d_width, d_height, flags, IMGFMT_YUYV); } @@ -397,10 +397,8 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) { /* FIXME - really any YUV 4:2:0 input format should work */ switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_IYUV: - case IMGFMT_I420: - return vf_next_query_format(vf,IMGFMT_YUY2); + case IMGFMT_420P: + return vf_next_query_format(vf,IMGFMT_YUYV); } return 0; } diff --git a/video/filter/vf_mirror.c b/video/filter/vf_mirror.c index b826ee46f7..56fc2ebb3d 100644 --- a/video/filter/vf_mirror.c +++ b/video/filter/vf_mirror.c @@ -50,8 +50,7 @@ static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcst dst[x*4+3]=src[1+(w2-x-1)*4]; } break; } - case IMGFMT_YUY2: - case IMGFMT_YVYU: { + case IMGFMT_YUYV: { // packed YUV is tricky. U,V are 32bpp while Y is 16bpp: int w2=w>>1; for(x=0;xpriv->outfmt); } return 0; @@ -391,9 +389,7 @@ static void parse(FilterParam *fp, char* args){ } static const unsigned int fmt_list[]={ - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, 0 }; @@ -412,7 +408,7 @@ static int vf_open(vf_instance_t *vf, char *args){ } // check csp: - vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); + vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P); if(!vf->priv->outfmt) { uninit(vf); diff --git a/video/filter/vf_pp.c b/video/filter/vf_pp.c index 8a6b1cf172..157dc3e068 100644 --- a/video/filter/vf_pp.c +++ b/video/filter/vf_pp.c @@ -72,11 +72,9 @@ static void uninit(struct vf_instance *vf){ static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt){ - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: case IMGFMT_444P: case IMGFMT_422P: + case IMGFMT_420P: case IMGFMT_411P: return vf_next_query_format(vf,fmt); } @@ -133,9 +131,7 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) extern int divx_quality; static const unsigned int fmt_list[]={ - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, IMGFMT_444P, IMGFMT_422P, IMGFMT_411P, @@ -155,7 +151,7 @@ static int vf_open(vf_instance_t *vf, char *args){ vf->priv->context=NULL; // check csp: - vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); + vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P); if(!vf->priv->outfmt) return 0; // no csp match :( char *name = args ? args : "de"; diff --git a/video/filter/vf_pullup.c b/video/filter/vf_pullup.c index 45e80b6b57..0a6e4c6b25 100644 --- a/video/filter/vf_pullup.c +++ b/video/filter/vf_pullup.c @@ -224,9 +224,7 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) { /* FIXME - support more formats */ switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_IYUV: - case IMGFMT_I420: + case IMGFMT_420P: return vf_next_query_format(vf, fmt); } return 0; diff --git a/video/filter/vf_rotate.c b/video/filter/vf_rotate.c index f44c874c1f..d6d2d0df85 100644 --- a/video/filter/vf_rotate.c +++ b/video/filter/vf_rotate.c @@ -111,14 +111,10 @@ static int query_format(struct vf_instance *vf, unsigned int fmt){ if(IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt)) return vf_next_query_format(vf, fmt); // we can support only symmetric (chroma_x_shift==chroma_y_shift) YUV formats: switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_YVU9: -// case IMGFMT_IF09: case IMGFMT_Y8: - case IMGFMT_Y800: - case IMGFMT_444P: + case IMGFMT_444P: + case IMGFMT_420P: + case IMGFMT_410P: return vf_next_query_format(vf, fmt); } return 0; diff --git a/video/filter/vf_scale.c b/video/filter/vf_scale.c index a10825ee56..ca06436dd5 100644 --- a/video/filter/vf_scale.c +++ b/video/filter/vf_scale.c @@ -87,8 +87,7 @@ static const unsigned int outfmt_list[]={ IMGFMT_422P10_BE, IMGFMT_422P9_LE, IMGFMT_422P9_BE, - IMGFMT_YV12, - IMGFMT_I420, + IMGFMT_420P, IMGFMT_420P16_LE, IMGFMT_420P16_BE, IMGFMT_420P14_LE, @@ -99,14 +98,12 @@ static const unsigned int outfmt_list[]={ IMGFMT_420P10_BE, IMGFMT_420P9_LE, IMGFMT_420P9_BE, - IMGFMT_420A, - IMGFMT_IYUV, - IMGFMT_YVU9, - IMGFMT_IF09, + IMGFMT_420AP, + IMGFMT_410P, IMGFMT_411P, IMGFMT_NV12, IMGFMT_NV21, - IMGFMT_YUY2, + IMGFMT_YUYV, IMGFMT_UYVY, IMGFMT_440P, // RGB and grayscale (Y8 and Y800): @@ -119,24 +116,22 @@ static const unsigned int outfmt_list[]={ IMGFMT_BGR24, IMGFMT_RGB24, IMGFMT_GBRP, - IMGFMT_RGB48LE, - IMGFMT_RGB48BE, + IMGFMT_RGB48_LE, + IMGFMT_RGB48_BE, IMGFMT_BGR16, IMGFMT_RGB16, IMGFMT_BGR15, IMGFMT_RGB15, IMGFMT_BGR12, IMGFMT_RGB12, - IMGFMT_Y800, IMGFMT_Y8, IMGFMT_BGR8, IMGFMT_RGB8, IMGFMT_BGR4, IMGFMT_RGB4, - IMGFMT_BG4B, - IMGFMT_RG4B, - IMGFMT_BGR1, - IMGFMT_RGB1, + IMGFMT_RGB4_BYTE, + IMGFMT_BGR4_BYTE, + IMGFMT_MONO, 0 }; @@ -147,13 +142,13 @@ static const unsigned int outfmt_list[]={ * fast assembler implementation. */ static int preferred_conversions[][2] = { - {IMGFMT_YUY2, IMGFMT_UYVY}, - {IMGFMT_YUY2, IMGFMT_422P}, - {IMGFMT_UYVY, IMGFMT_YUY2}, + {IMGFMT_YUYV, IMGFMT_UYVY}, + {IMGFMT_YUYV, IMGFMT_422P}, + {IMGFMT_UYVY, IMGFMT_YUYV}, {IMGFMT_UYVY, IMGFMT_422P}, - {IMGFMT_422P, IMGFMT_YUY2}, + {IMGFMT_422P, IMGFMT_YUYV}, {IMGFMT_422P, IMGFMT_UYVY}, - {IMGFMT_420P10, IMGFMT_YV12}, + {IMGFMT_420P10, IMGFMT_420P}, {IMGFMT_GBRP, IMGFMT_BGR24}, {IMGFMT_GBRP, IMGFMT_RGB24}, {IMGFMT_GBRP, IMGFMT_BGR32}, @@ -277,13 +272,11 @@ static int config(struct vf_instance *vf, // calculate the missing parameters: switch(best) { - case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */ - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: /* YV12 needs w & h rounded to 2 */ case IMGFMT_NV12: case IMGFMT_NV21: vf->priv->h = (vf->priv->h + 1) & ~1; - case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */ + case IMGFMT_YUYV: /* YUY2 needs w rounded to 2 */ case IMGFMT_UYVY: vf->priv->w = (vf->priv->w + 1) & ~1; } diff --git a/video/filter/vf_sub.c b/video/filter/vf_sub.c index 96100801ff..8cda9f5e79 100644 --- a/video/filter/vf_sub.c +++ b/video/filter/vf_sub.c @@ -61,8 +61,6 @@ static int config(struct vf_instance *vf, unsigned int flags, unsigned int outfmt) { struct MPOpts *opts = vf->opts; - if (outfmt == IMGFMT_IF09) - return 0; vf->priv->outh = height + vf->priv->opt_top_margin + vf->priv->opt_bottom_margin; @@ -178,9 +176,7 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) static int query_format(struct vf_instance *vf, unsigned int fmt) { switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: return vf_next_query_format(vf, vf->priv->outfmt); } return 0; @@ -209,15 +205,13 @@ static void uninit(struct vf_instance *vf) } static const unsigned int fmt_list[] = { - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, 0 }; static int vf_open(vf_instance_t *vf, char *args) { - vf->priv->outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12); + vf->priv->outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_420P); if (!vf->priv->outfmt) { uninit(vf); return 0; diff --git a/video/filter/vf_swapuv.c b/video/filter/vf_swapuv.c index 5e879ff557..a9083ccaa8 100644 --- a/video/filter/vf_swapuv.c +++ b/video/filter/vf_swapuv.c @@ -42,13 +42,12 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_YVU9: case IMGFMT_444P: - case IMGFMT_422P: - case IMGFMT_411P: + case IMGFMT_422P: + case IMGFMT_440P: + case IMGFMT_420P: + case IMGFMT_411P: + case IMGFMT_410P: return vf_next_query_format(vf, fmt); } return 0; diff --git a/video/filter/vf_unsharp.c b/video/filter/vf_unsharp.c index c3150b9a33..dcca82df5b 100644 --- a/video/filter/vf_unsharp.c +++ b/video/filter/vf_unsharp.c @@ -206,9 +206,7 @@ static void uninit( struct vf_instance *vf ) { static int query_format( struct vf_instance *vf, unsigned int fmt ) { switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: return vf_next_query_format( vf, vf->priv->outfmt ); } return 0; @@ -241,9 +239,7 @@ static void parse( FilterParam *fp, char* args ) { //===========================================================================// static const unsigned int fmt_list[] = { - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, 0 }; @@ -279,7 +275,7 @@ static int vf_open( vf_instance_t *vf, char *args ) { } // check csp: - vf->priv->outfmt = vf_match_csp( &vf->next, fmt_list, IMGFMT_YV12 ); + vf->priv->outfmt = vf_match_csp( &vf->next, fmt_list, IMGFMT_420P ); if( !vf->priv->outfmt ) { uninit( vf ); return 0; // no csp match :( diff --git a/video/filter/vf_yadif.c b/video/filter/vf_yadif.c index 4e53ef168c..10ce6d9e8e 100644 --- a/video/filter/vf_yadif.c +++ b/video/filter/vf_yadif.c @@ -477,10 +477,7 @@ static void uninit(struct vf_instance *vf){ //===========================================================================// static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt){ - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_Y800: + case IMGFMT_420P: case IMGFMT_Y8: return vf_next_query_format(vf,fmt); } diff --git a/video/fmt-conversion.c b/video/fmt-conversion.c index 6a45713f7c..cf3aaa7452 100644 --- a/video/fmt-conversion.c +++ b/video/fmt-conversion.c @@ -29,52 +29,47 @@ static const struct { {IMGFMT_ARGB, PIX_FMT_ARGB}, {IMGFMT_BGRA, PIX_FMT_BGRA}, {IMGFMT_BGR24, PIX_FMT_BGR24}, - {IMGFMT_BGR16BE, PIX_FMT_RGB565BE}, - {IMGFMT_BGR16LE, PIX_FMT_RGB565LE}, - {IMGFMT_BGR15BE, PIX_FMT_RGB555BE}, - {IMGFMT_BGR15LE, PIX_FMT_RGB555LE}, - {IMGFMT_BGR12BE, PIX_FMT_RGB444BE}, - {IMGFMT_BGR12LE, PIX_FMT_RGB444LE}, + {IMGFMT_BGR16_BE, PIX_FMT_RGB565BE}, + {IMGFMT_BGR16_LE, PIX_FMT_RGB565LE}, + {IMGFMT_BGR15_BE, PIX_FMT_RGB555BE}, + {IMGFMT_BGR15_LE, PIX_FMT_RGB555LE}, + {IMGFMT_BGR12_BE, PIX_FMT_RGB444BE}, + {IMGFMT_BGR12_LE, PIX_FMT_RGB444LE}, {IMGFMT_BGR8, PIX_FMT_RGB8}, {IMGFMT_BGR4, PIX_FMT_RGB4}, - {IMGFMT_BGR1, PIX_FMT_MONOBLACK}, - {IMGFMT_RGB1, PIX_FMT_MONOBLACK}, - {IMGFMT_RG4B, PIX_FMT_BGR4_BYTE}, - {IMGFMT_BG4B, PIX_FMT_RGB4_BYTE}, - {IMGFMT_RGB48LE, PIX_FMT_RGB48LE}, - {IMGFMT_RGB48BE, PIX_FMT_RGB48BE}, + {IMGFMT_MONO, PIX_FMT_MONOBLACK}, + {IMGFMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE}, + {IMGFMT_BGR4_BYTE, PIX_FMT_RGB4_BYTE}, + {IMGFMT_RGB48_LE, PIX_FMT_RGB48LE}, + {IMGFMT_RGB48_BE, PIX_FMT_RGB48BE}, {IMGFMT_ABGR, PIX_FMT_ABGR}, {IMGFMT_RGBA, PIX_FMT_RGBA}, {IMGFMT_RGB24, PIX_FMT_RGB24}, - {IMGFMT_RGB16BE, PIX_FMT_BGR565BE}, - {IMGFMT_RGB16LE, PIX_FMT_BGR565LE}, - {IMGFMT_RGB15BE, PIX_FMT_BGR555BE}, - {IMGFMT_RGB15LE, PIX_FMT_BGR555LE}, - {IMGFMT_RGB12BE, PIX_FMT_BGR444BE}, - {IMGFMT_RGB12LE, PIX_FMT_BGR444LE}, + {IMGFMT_RGB16_BE, PIX_FMT_BGR565BE}, + {IMGFMT_RGB16_LE, PIX_FMT_BGR565LE}, + {IMGFMT_RGB15_BE, PIX_FMT_BGR555BE}, + {IMGFMT_RGB15_LE, PIX_FMT_BGR555LE}, + {IMGFMT_RGB12_BE, PIX_FMT_BGR444BE}, + {IMGFMT_RGB12_LE, PIX_FMT_BGR444LE}, {IMGFMT_RGB8, PIX_FMT_BGR8}, {IMGFMT_RGB4, PIX_FMT_BGR4}, {IMGFMT_PAL8, PIX_FMT_PAL8}, {IMGFMT_GBRP, PIX_FMT_GBRP}, - {IMGFMT_YUY2, PIX_FMT_YUYV422}, + {IMGFMT_YUYV, PIX_FMT_YUYV422}, {IMGFMT_UYVY, PIX_FMT_UYVY422}, {IMGFMT_NV12, PIX_FMT_NV12}, {IMGFMT_NV21, PIX_FMT_NV21}, - {IMGFMT_Y800, PIX_FMT_GRAY8}, {IMGFMT_Y8, PIX_FMT_GRAY8}, - {IMGFMT_Y16LE, PIX_FMT_GRAY16LE}, - {IMGFMT_Y16BE, PIX_FMT_GRAY16BE}, - {IMGFMT_YVU9, PIX_FMT_YUV410P}, - {IMGFMT_IF09, PIX_FMT_YUV410P}, - {IMGFMT_YV12, PIX_FMT_YUV420P}, - {IMGFMT_I420, PIX_FMT_YUV420P}, - {IMGFMT_IYUV, PIX_FMT_YUV420P}, + {IMGFMT_Y16_LE, PIX_FMT_GRAY16LE}, + {IMGFMT_Y16_BE, PIX_FMT_GRAY16BE}, + {IMGFMT_410P, PIX_FMT_YUV410P}, + {IMGFMT_420P, PIX_FMT_YUV420P}, {IMGFMT_411P, PIX_FMT_YUV411P}, {IMGFMT_422P, PIX_FMT_YUV422P}, {IMGFMT_444P, PIX_FMT_YUV444P}, {IMGFMT_440P, PIX_FMT_YUV440P}, - {IMGFMT_420A, PIX_FMT_YUVA420P}, + {IMGFMT_420AP, PIX_FMT_YUVA420P}, {IMGFMT_420P16_LE, PIX_FMT_YUV420P16LE}, {IMGFMT_420P16_BE, PIX_FMT_YUV420P16BE}, @@ -95,10 +90,9 @@ static const struct { {IMGFMT_444P16_LE, PIX_FMT_YUV444P16LE}, {IMGFMT_444P16_BE, PIX_FMT_YUV444P16BE}, - // YUVJ are YUV formats that use the full Y range and not just - // 16 - 235 (see colorspaces.txt). - // Currently they are all treated the same way. - {IMGFMT_YV12, PIX_FMT_YUVJ420P}, + // YUVJ are YUV formats that use the full Y range. Decoder color range + // information is used instead. Deprecated in ffmpeg. + {IMGFMT_420P, PIX_FMT_YUVJ420P}, {IMGFMT_422P, PIX_FMT_YUVJ422P}, {IMGFMT_444P, PIX_FMT_YUVJ444P}, {IMGFMT_440P, PIX_FMT_YUVJ440P}, diff --git a/video/image_writer.c b/video/image_writer.c index 8d3b746ef7..3a25e91b07 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -215,16 +215,16 @@ static const struct img_writer img_writers[] = { { "ppm", write_lavc, .lavc_codec = CODEC_ID_PPM }, { "pgm", write_lavc, .lavc_codec = CODEC_ID_PGM, - .pixfmts = (int[]) { IMGFMT_Y800, 0 }, + .pixfmts = (int[]) { IMGFMT_Y8, 0 }, }, { "pgmyuv", write_lavc, .lavc_codec = CODEC_ID_PGMYUV, - .pixfmts = (int[]) { IMGFMT_YV12, 0 }, + .pixfmts = (int[]) { IMGFMT_420P, 0 }, }, { "tga", write_lavc, .lavc_codec = CODEC_ID_TARGA, - .pixfmts = (int[]) { IMGFMT_BGR24, IMGFMT_BGRA, IMGFMT_BGR15LE, - IMGFMT_Y800, 0}, + .pixfmts = (int[]) { IMGFMT_BGR24, IMGFMT_BGRA, IMGFMT_BGR15_LE, + IMGFMT_Y8, 0}, }, #ifdef CONFIG_JPEG { "jpg", write_jpeg }, diff --git a/video/img_format.c b/video/img_format.c index e540dd24cf..bf75ba8a18 100644 --- a/video/img_format.c +++ b/video/img_format.c @@ -17,133 +17,87 @@ */ #include +#include #include #include -#include "config.h" #include "video/img_format.h" #include "video/mp_image.h" #include "video/fmt-conversion.h" -#include +#define FMT(string, id) \ + {string, id}, + +#define FMT_ENDIAN(string, id) \ + {string, id}, \ + {string "le", MP_CONCAT(id, _LE)}, \ + {string "be", MP_CONCAT(id, _BE)}, \ struct mp_imgfmt_entry mp_imgfmt_list[] = { - {"444p16le", IMGFMT_444P16_LE}, - {"444p16be", IMGFMT_444P16_BE}, - {"444p14le", IMGFMT_444P14_LE}, - {"444p14be", IMGFMT_444P14_BE}, - {"444p12le", IMGFMT_444P12_LE}, - {"444p12be", IMGFMT_444P12_BE}, - {"444p10le", IMGFMT_444P10_LE}, - {"444p10be", IMGFMT_444P10_BE}, - {"444p9le", IMGFMT_444P9_LE}, - {"444p9be", IMGFMT_444P9_BE}, - {"422p16le", IMGFMT_422P16_LE}, - {"422p16be", IMGFMT_422P16_BE}, - {"422p14le", IMGFMT_422P14_LE}, - {"422p14be", IMGFMT_422P14_BE}, - {"422p12le", IMGFMT_422P12_LE}, - {"422p12be", IMGFMT_422P12_BE}, - {"422p10le", IMGFMT_422P10_LE}, - {"422p10be", IMGFMT_422P10_BE}, - {"422p9le", IMGFMT_422P9_LE}, - {"422p9be", IMGFMT_422P9_BE}, - {"420p16le", IMGFMT_420P16_LE}, - {"420p16be", IMGFMT_420P16_BE}, - {"420p14le", IMGFMT_420P14_LE}, - {"420p14be", IMGFMT_420P14_BE}, - {"420p12le", IMGFMT_420P12_LE}, - {"420p12be", IMGFMT_420P12_BE}, - {"420p10le", IMGFMT_420P10_LE}, - {"420p10be", IMGFMT_420P10_BE}, - {"420p9le", IMGFMT_420P9_LE}, - {"420p9be", IMGFMT_420P9_BE}, - {"444p16", IMGFMT_444P16}, - {"444p14", IMGFMT_444P14}, - {"444p12", IMGFMT_444P12}, - {"444p10", IMGFMT_444P10}, - {"444p9", IMGFMT_444P9}, - {"422p16", IMGFMT_422P16}, - {"422p14", IMGFMT_422P14}, - {"422p12", IMGFMT_422P12}, - {"422p10", IMGFMT_422P10}, - {"420p14", IMGFMT_420P14}, - {"420p12", IMGFMT_420P12}, - {"420p10", IMGFMT_420P10}, - {"420p9", IMGFMT_420P9}, - {"420p16", IMGFMT_420P16}, - {"420a", IMGFMT_420A}, - {"444p", IMGFMT_444P}, - {"422p", IMGFMT_422P}, - {"411p", IMGFMT_411P}, - {"440p", IMGFMT_440P}, - {"yuy2", IMGFMT_YUY2}, - {"yvyu", IMGFMT_YVYU}, - {"uyvy", IMGFMT_UYVY}, - {"yvu9", IMGFMT_YVU9}, - {"if09", IMGFMT_IF09}, - {"yv12", IMGFMT_YV12}, - {"i420", IMGFMT_I420}, - {"iyuv", IMGFMT_IYUV}, - {"clpl", IMGFMT_CLPL}, - {"hm12", IMGFMT_HM12}, - {"y800", IMGFMT_Y800}, - {"y8", IMGFMT_Y8}, - {"y16ne", IMGFMT_Y16}, - {"y16le", IMGFMT_Y16LE}, - {"y16be", IMGFMT_Y16BE}, - {"nv12", IMGFMT_NV12}, - {"nv21", IMGFMT_NV21}, - {"bgr24", IMGFMT_BGR24}, - {"bgr32", IMGFMT_BGR32}, - {"bgr16", IMGFMT_BGR16}, - {"bgr15", IMGFMT_BGR15}, - {"bgr12", IMGFMT_BGR12}, - {"bgr8", IMGFMT_BGR8}, - {"bgr4", IMGFMT_BGR4}, - {"bg4b", IMGFMT_BG4B}, - {"bgr1", IMGFMT_BGR1}, - {"rgb48be", IMGFMT_RGB48BE}, - {"rgb48le", IMGFMT_RGB48LE}, - {"rgb48ne", IMGFMT_RGB48NE}, - {"rgb24", IMGFMT_RGB24}, - {"rgb32", IMGFMT_RGB32}, - {"rgb16", IMGFMT_RGB16}, - {"rgb15", IMGFMT_RGB15}, - {"rgb12", IMGFMT_RGB12}, - {"rgb8", IMGFMT_RGB8}, - {"pal8", IMGFMT_PAL8}, - {"rgb4", IMGFMT_RGB4}, - {"rg4b", IMGFMT_RG4B}, - {"rgb1", IMGFMT_RGB1}, - {"rgba", IMGFMT_RGBA}, - {"argb", IMGFMT_ARGB}, - {"bgra", IMGFMT_BGRA}, - {"abgr", IMGFMT_ABGR}, - {"bgr0", IMGFMT_BGR0}, - {"gbrp", IMGFMT_GBRP}, - {"mjpeg", IMGFMT_MJPEG}, - {"mjpg", IMGFMT_MJPEG}, - {"vdpau_h264", IMGFMT_VDPAU_H264}, - {"vdpau_mpeg1", IMGFMT_VDPAU_MPEG1}, - {"vdpau_mpeg2", IMGFMT_VDPAU_MPEG2}, - {"vdpau_mpeg4", IMGFMT_VDPAU_MPEG4}, - {"vdpau_wmv3", IMGFMT_VDPAU_WMV3}, - {"vdpau_vc1", IMGFMT_VDPAU_VC1}, + FMT("y8", IMGFMT_Y8) + FMT_ENDIAN("y16", IMGFMT_Y16) + FMT("yuyv", IMGFMT_YUYV) + FMT("uyvy", IMGFMT_UYVY) + FMT("nv12", IMGFMT_NV12) + FMT("nv21", IMGFMT_NV21) + FMT("444p", IMGFMT_444P) + FMT("422p", IMGFMT_422P) + FMT("440p", IMGFMT_440P) + FMT("420p", IMGFMT_420P) + FMT("yv12", IMGFMT_420P) // old alias for UI + FMT("411p", IMGFMT_411P) + FMT("410p", IMGFMT_410P) + FMT_ENDIAN("444p16", IMGFMT_444P16) + FMT_ENDIAN("444p14", IMGFMT_444P14) + FMT_ENDIAN("444p12", IMGFMT_444P12) + FMT_ENDIAN("444p10", IMGFMT_444P10) + FMT_ENDIAN("444p9", IMGFMT_444P9) + FMT_ENDIAN("422p16", IMGFMT_422P16) + FMT_ENDIAN("422p14", IMGFMT_422P14) + FMT_ENDIAN("422p12", IMGFMT_422P12) + FMT_ENDIAN("422p10", IMGFMT_422P10) + FMT_ENDIAN("422p9", IMGFMT_422P9) + FMT_ENDIAN("420p16", IMGFMT_420P16) + FMT_ENDIAN("420p14", IMGFMT_420P14) + FMT_ENDIAN("420p12", IMGFMT_420P12) + FMT_ENDIAN("420p10", IMGFMT_420P10) + FMT_ENDIAN("420p9", IMGFMT_420P9) + FMT("420ap", IMGFMT_420AP) + FMT("argb", IMGFMT_ARGB) + FMT("bgra", IMGFMT_BGRA) + FMT("bgr0", IMGFMT_BGR0) + FMT("abgr", IMGFMT_ABGR) + FMT("rgba", IMGFMT_RGBA) + FMT("rgb32", IMGFMT_RGB32) + FMT("bgr32", IMGFMT_BGR32) + FMT("bgr24", IMGFMT_BGR24) + FMT("rgb24", IMGFMT_RGB24) + FMT_ENDIAN("rgb48", IMGFMT_RGB48) + FMT("rgb8", IMGFMT_RGB8) + FMT("bgr8", IMGFMT_BGR8) + FMT("rgb4_byte", IMGFMT_RGB4_BYTE) + FMT("bgr4_byte", IMGFMT_BGR4_BYTE) + FMT("rgb4", IMGFMT_RGB4) + FMT("bgr4", IMGFMT_BGR4) + FMT("mono", IMGFMT_MONO) + FMT_ENDIAN("rgb12", IMGFMT_RGB12) + FMT_ENDIAN("rgb15", IMGFMT_RGB15) + FMT_ENDIAN("rgb16", IMGFMT_RGB16) + FMT_ENDIAN("bgr12", IMGFMT_BGR12) + FMT_ENDIAN("bgr15", IMGFMT_BGR15) + FMT_ENDIAN("bgr16", IMGFMT_BGR16) + FMT("pal8", IMGFMT_PAL8) + FMT("gbrp", IMGFMT_GBRP) + FMT("vdpau_mpeg1", IMGFMT_VDPAU_MPEG1) + FMT("vdpau_mpeg2", IMGFMT_VDPAU_MPEG2) + FMT("vdpau_h264", IMGFMT_VDPAU_H264) + FMT("vdpau_wmv3", IMGFMT_VDPAU_WMV3) + FMT("vdpau_vc1", IMGFMT_VDPAU_VC1) + FMT("vdpau_mpeg4", IMGFMT_VDPAU_MPEG4) {0} }; -const char *vo_format_name(int format) -{ - const char *name = mp_imgfmt_to_name(format); - if (name) - return name; - static char unknown_format[20]; - 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 *component_bits) { @@ -162,12 +116,6 @@ int mp_get_chroma_shift(int format, int *x_shift, int *y_shift, unsigned int mp_imgfmt_from_name(bstr name, bool allow_hwaccel) { - if (bstr_startswith0(name, "0x")) { - bstr rest; - unsigned int fmt = bstrtoll(name, &rest, 16); - if (rest.len == 0) - return fmt; - } for(struct mp_imgfmt_entry *p = mp_imgfmt_list; p->name; ++p) { if(!bstrcasecmp0(name, p->name)) { if (!allow_hwaccel && IMGFMT_IS_HWACCEL(p->fmt)) @@ -241,8 +189,15 @@ static struct mp_imgfmt_desc get_avutil_fmt(enum PixelFormat fmt) desc.num_planes++; } - if (desc.bpp[0] <= 8 || !(pd->flags & PIX_FMT_BE)) - desc.flags |= MP_IMGFLAG_NE; + // Packed RGB formats are the only formats that have less than 8 bits per + // component, and still require endian dependent access. + if (pd->comp[0].depth_minus1 + 1 <= 8 && + !(mpfmt >= IMGFMT_RGB12_LE || mpfmt <= IMGFMT_BGR16_BE)) + { + desc.flags |= MP_IMGFLAG_LE | MP_IMGFLAG_BE; + } else { + desc.flags |= (pd->flags & PIX_FMT_BE) ? MP_IMGFLAG_BE : MP_IMGFLAG_LE; + } desc.plane_bits = planedepth[0]; @@ -297,20 +252,15 @@ static struct mp_imgfmt_desc get_avutil_fmt(enum PixelFormat fmt) // compatibility with old mp_image_setfmt() switch (desc.id) { - case IMGFMT_I420: - case IMGFMT_IYUV: - desc.flags |= MP_IMGFLAG_SWAPPED; // completely pointless - break; case IMGFMT_UYVY: desc.flags |= MP_IMGFLAG_SWAPPED; // for vf_mpi_clear() /* fallthrough */ - case IMGFMT_YUY2: + case IMGFMT_YUYV: desc.chroma_ys = 1; // ??? break; case IMGFMT_Y8: - case IMGFMT_Y800: - case IMGFMT_Y16LE: - case IMGFMT_Y16BE: + case IMGFMT_Y16_LE: + case IMGFMT_Y16_BE: // probably for vo_opengl, and possibly more code using Y8 desc.chroma_xs = desc.chroma_ys = 31; break; @@ -324,7 +274,6 @@ static struct mp_imgfmt_desc get_avutil_fmt(enum PixelFormat fmt) break; case IMGFMT_RGB4: case IMGFMT_BGR4: - case IMGFMT_BGR1: desc.flags ^= MP_IMGFLAG_SWAPPED; // ??? break; case IMGFMT_BGR0: @@ -335,6 +284,12 @@ static struct mp_imgfmt_desc get_avutil_fmt(enum PixelFormat fmt) if (pd->flags & PIX_FMT_HWACCEL) desc.chroma_xs = desc.chroma_ys = 0; + if (!(pd->flags & PIX_FMT_HWACCEL) && !(pd->flags & PIX_FMT_BITSTREAM)) { + desc.flags |= MP_IMGFLAG_BYTE_ALIGNED; + for (int p = 0; p < desc.num_planes; p++) + desc.bytes[p] = desc.bpp[p] / 8; + } + for (int p = 0; p < desc.num_planes; p++) { desc.xs[p] = (p == 1 || p == 2) ? desc.chroma_xs : 0; desc.ys[p] = (p == 1 || p == 2) ? desc.chroma_ys : 0; diff --git a/video/img_format.h b/video/img_format.h index 48780cc694..1f617b573b 100644 --- a/video/img_format.h +++ b/video/img_format.h @@ -19,12 +19,20 @@ #ifndef MPLAYER_IMG_FORMAT_H #define MPLAYER_IMG_FORMAT_H +#include #include -#include "config.h" #include "core/bstr.h" +#if BYTE_ORDER == BIG_ENDIAN +#define MP_SELECT_LE_BE(LE, BE) BE +#else +#define MP_SELECT_LE_BE(LE, BE) LE +#endif + #define MP_MAX_PLANES 4 +// All pixels start in byte boundaries +#define MP_IMGFLAG_BYTE_ALIGNED 0x1 // set if (possibly) alpha is included (might be not definitive for packed RGB) #define MP_IMGFLAG_ALPHA 0x80 // set if number of planes > 1 @@ -33,14 +41,18 @@ #define MP_IMGFLAG_YUV 0x200 // set if it's swapped (BGR or YVU) plane/byteorder #define MP_IMGFLAG_SWAPPED 0x400 -// set if the format is standard YUV format: +// set if the format is in a standard YUV format: // - planar and yuv colorspace // - chroma shift 0-2 // - 1-4 planes (1: gray, 2: gray/alpha, 3: yuv, 4: yuv/alpha) // - 8-16 bit per pixel/plane, all planes have same depth #define MP_IMGFLAG_YUV_P 0x1000 -// set if format is in native endian, or <= 8 bit per pixel/plane -#define MP_IMGFLAG_NE 0x2000 +// set if in little endian, or endian independent +#define MP_IMGFLAG_LE 0x2000 +// set if in big endian, or endian independent +#define MP_IMGFLAG_BE 0x4000 +// set if in native (host) endian, or endian independent +#define MP_IMGFLAG_NE MP_SELECT_LE_BE(MP_IMGFLAG_LE, MP_IMGFLAG_BE) #define MP_IMGFLAG_FMT_MASK 0x3FFF @@ -49,92 +61,181 @@ struct mp_imgfmt_desc { int avformat; // AV_PIX_FMT_* (or AV_PIX_FMT_NONE) const char *name; // e.g. "420p16" int flags; // MP_IMGFLAG_* bitfield - int num_planes; - int chroma_xs, chroma_ys; // chroma shift (i.e. log2 of chroma pixel size) - int avg_bpp; - int bpp[MP_MAX_PLANES]; - int plane_bits; // number of bits in use for plane 0 + int8_t num_planes; + int8_t chroma_xs, chroma_ys; // chroma shift (i.e. log2 of chroma pixel size) + int8_t avg_bpp; + int8_t bytes[MP_MAX_PLANES]; // bytes per pixel (MP_IMGFLAG_BYTE_ALIGNED) + int8_t bpp[MP_MAX_PLANES]; // bits per pixel + int8_t plane_bits; // number of bits in use for plane 0 // chroma shifts per plane (provided for convenience with planar formats) - int xs[MP_MAX_PLANES]; - int ys[MP_MAX_PLANES]; + int8_t xs[MP_MAX_PLANES]; + int8_t ys[MP_MAX_PLANES]; }; struct mp_imgfmt_desc mp_imgfmt_get_desc(unsigned int out_fmt); -/* RGB/BGR Formats */ - -#define IMGFMT_RGB_MASK 0xFFFFFF00 -#define IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8)) -#define IMGFMT_RGB1 (IMGFMT_RGB|1) -#define IMGFMT_RGB4 (IMGFMT_RGB|4) -#define IMGFMT_RGB4_CHAR (IMGFMT_RGB|4|128) // RGB4 with 1 pixel per byte -#define IMGFMT_RGB8 (IMGFMT_RGB|8) -#define IMGFMT_RGB12 (IMGFMT_RGB|12) -#define IMGFMT_RGB15 (IMGFMT_RGB|15) -#define IMGFMT_RGB16 (IMGFMT_RGB|16) -#define IMGFMT_RGB24 (IMGFMT_RGB|24) -#define IMGFMT_RGB32 (IMGFMT_RGB|32) -#define IMGFMT_RGB48LE (IMGFMT_RGB|48) -#define IMGFMT_RGB48BE (IMGFMT_RGB|48|128) - -#define IMGFMT_BGR_MASK 0xFFFFFF00 -#define IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8)) -#define IMGFMT_BGR1 (IMGFMT_BGR|1) -#define IMGFMT_BGR4 (IMGFMT_BGR|4) -#define IMGFMT_BGR4_CHAR (IMGFMT_BGR|4|128) // BGR4 with 1 pixel per byte -#define IMGFMT_BGR8 (IMGFMT_BGR|8) -#define IMGFMT_BGR12 (IMGFMT_BGR|12) -#define IMGFMT_BGR15 (IMGFMT_BGR|15) -#define IMGFMT_BGR16 (IMGFMT_BGR|16) -#define IMGFMT_BGR24 (IMGFMT_BGR|24) -#define IMGFMT_BGR32 (IMGFMT_BGR|32) - -#define IMGFMT_GBRP (('G'<<24)|('B'<<16)|('R'<<8)|24) - -#if BYTE_ORDER == BIG_ENDIAN -#define IMGFMT_ABGR IMGFMT_RGB32 -#define IMGFMT_BGRA (IMGFMT_RGB32|128) -#define IMGFMT_ARGB IMGFMT_BGR32 -#define IMGFMT_RGBA (IMGFMT_BGR32|128) -#define IMGFMT_RGB48NE IMGFMT_RGB48BE -#define IMGFMT_RGB12BE IMGFMT_RGB12 -#define IMGFMT_RGB12LE (IMGFMT_RGB12|128) -#define IMGFMT_RGB15BE IMGFMT_RGB15 -#define IMGFMT_RGB15LE (IMGFMT_RGB15|128) -#define IMGFMT_RGB16BE IMGFMT_RGB16 -#define IMGFMT_RGB16LE (IMGFMT_RGB16|128) -#define IMGFMT_BGR12BE IMGFMT_BGR12 -#define IMGFMT_BGR12LE (IMGFMT_BGR12|128) -#define IMGFMT_BGR15BE IMGFMT_BGR15 -#define IMGFMT_BGR15LE (IMGFMT_BGR15|128) -#define IMGFMT_BGR16BE IMGFMT_BGR16 -#define IMGFMT_BGR16LE (IMGFMT_BGR16|128) -#else -#define IMGFMT_ABGR (IMGFMT_BGR32|128) -#define IMGFMT_BGRA IMGFMT_BGR32 -#define IMGFMT_ARGB (IMGFMT_RGB32|128) -#define IMGFMT_RGBA IMGFMT_RGB32 -#define IMGFMT_RGB48NE IMGFMT_RGB48LE -#define IMGFMT_RGB12BE (IMGFMT_RGB12|128) -#define IMGFMT_RGB12LE IMGFMT_RGB12 -#define IMGFMT_RGB15BE (IMGFMT_RGB15|128) -#define IMGFMT_RGB15LE IMGFMT_RGB15 -#define IMGFMT_RGB16BE (IMGFMT_RGB16|128) -#define IMGFMT_RGB16LE IMGFMT_RGB16 -#define IMGFMT_BGR12BE (IMGFMT_BGR12|128) -#define IMGFMT_BGR12LE IMGFMT_BGR12 -#define IMGFMT_BGR15BE (IMGFMT_BGR15|128) -#define IMGFMT_BGR15LE IMGFMT_BGR15 -#define IMGFMT_BGR16BE (IMGFMT_BGR16|128) -#define IMGFMT_BGR16LE IMGFMT_BGR16 -#endif - -/* old names for compatibility */ -#define IMGFMT_RG4B IMGFMT_RGB4_CHAR -#define IMGFMT_BG4B IMGFMT_BGR4_CHAR - -// AV_PIX_FMT_BGR0 -#define IMGFMT_BGR0 0x1DC70000 +enum mp_imgfmt { + IMGFMT_NONE = 0, + + // Offset to make confusing with ffmpeg formats harder + IMGFMT_START = 1000, + + // Planar YUV formats + + IMGFMT_444P, // 1x1 + IMGFMT_422P, // 2x1 + IMGFMT_440P, // 1x2 + IMGFMT_420P, // 2x2 + IMGFMT_411P, // 4x1 + IMGFMT_410P, // 4x4 + + // YUV formats with 2 bytes per plane-pixel. Formats with 9-15 bits pad the + // most significant bits with 0 (use shifts to expand them to 16 bits). + + IMGFMT_444P16_LE, + IMGFMT_444P16_BE, + IMGFMT_444P14_LE, + IMGFMT_444P14_BE, + IMGFMT_444P12_LE, + IMGFMT_444P12_BE, + IMGFMT_444P10_LE, + IMGFMT_444P10_BE, + IMGFMT_444P9_LE, + IMGFMT_444P9_BE, + + IMGFMT_422P16_LE, + IMGFMT_422P16_BE, + IMGFMT_422P14_LE, + IMGFMT_422P14_BE, + IMGFMT_422P12_LE, + IMGFMT_422P12_BE, + IMGFMT_422P10_LE, + IMGFMT_422P10_BE, + IMGFMT_422P9_LE, + IMGFMT_422P9_BE, + + IMGFMT_420P16_LE, + IMGFMT_420P16_BE, + IMGFMT_420P14_LE, + IMGFMT_420P14_BE, + IMGFMT_420P12_LE, + IMGFMT_420P12_BE, + IMGFMT_420P10_LE, + IMGFMT_420P10_BE, + IMGFMT_420P9_LE, + IMGFMT_420P9_BE, + + // Planar YUV with alpha (4th plane) + IMGFMT_420AP, + + // Gray + IMGFMT_Y8, + IMGFMT_Y16_LE, + IMGFMT_Y16_BE, + + // Packed YUV formats (components are byte-accessed) + IMGFMT_YUYV, // Y0 U Y1 V + IMGFMT_UYVY, // U Y0 V Y1 + + // Y plane + packed plane for chroma + IMGFMT_NV12, + IMGFMT_NV21, + + // RGB/BGR Formats + + // Byte accessed (low address to high address) + IMGFMT_ARGB, + IMGFMT_BGRA, + IMGFMT_BGR0, + IMGFMT_ABGR, + IMGFMT_RGBA, + IMGFMT_BGR24, + IMGFMT_RGB24, + IMGFMT_RGB48_LE, + IMGFMT_RGB48_BE, + + // Accessed with bit-shifts (components ordered from LSB to MSB) + IMGFMT_RGB8, // r3 g3 b2 + IMGFMT_BGR8, + IMGFMT_RGB4_BYTE, // r1 g2 b1 with 1 pixel per byte + IMGFMT_BGR4_BYTE, + IMGFMT_RGB4, // r1 g2 b1, bit-packed + IMGFMT_BGR4, + IMGFMT_MONO, // 1 bit per pixel, bit-packed + + // Accessed with bit-shifts after endian-swapping the uint16_t pixel + IMGFMT_RGB12_LE, // 4r 4g 4b 4a (LSB to MSB) + IMGFMT_RGB12_BE, + IMGFMT_RGB15_LE, // 5r 5g 5b 1a + IMGFMT_RGB15_BE, + IMGFMT_RGB16_LE, // 5r 6g 5b + IMGFMT_RGB16_BE, + IMGFMT_BGR12_LE, // 4b 4r 4g 4a + IMGFMT_BGR12_BE, + IMGFMT_BGR15_LE, // 5b 5g 5r 1a + IMGFMT_BGR15_BE, + IMGFMT_BGR16_LE, // 5b 6g 5r + IMGFMT_BGR16_BE, + + IMGFMT_PAL8, // Palette entries are IMGFMT_BGR32 + + // Planar RGB (planes are shuffled: plane 0 is G, etc.) + IMGFMT_GBRP, + + // Hardware acclerated formats. Plane data points to special data + // structures, instead of pixel data. + + IMGFMT_VDPAU_MPEG1, + IMGFMT_VDPAU_MPEG2, + IMGFMT_VDPAU_H264, + IMGFMT_VDPAU_WMV3, + IMGFMT_VDPAU_VC1, + IMGFMT_VDPAU_MPEG4, + + IMGFMT_VDPAU_FIRST = IMGFMT_VDPAU_MPEG1, + IMGFMT_VDPAU_LAST = IMGFMT_VDPAU_MPEG4, + + IMGFMT_END, + + // Redundant format aliases for native endian access + // For all formats that have _LE/_BE, define a native-endian entry without + // the suffix. + + // The IMGFMT_RGB32 and IMGFMT_BGR32 formats provide bit-shift access to + // normally byte-accessed formats: + // IMGFMT_RGB32 = r | (g << 8) | (b << 16) | (a << 24) + // IMGFMT_BGR32 = b | (g << 8) | (r << 16) | (a << 24) + IMGFMT_RGB32 = MP_SELECT_LE_BE(IMGFMT_RGBA, IMGFMT_ABGR), + IMGFMT_BGR32 = MP_SELECT_LE_BE(IMGFMT_BGRA, IMGFMT_ARGB), + + IMGFMT_RGB12 = MP_SELECT_LE_BE(IMGFMT_RGB12_LE, IMGFMT_RGB12_BE), + IMGFMT_RGB15 = MP_SELECT_LE_BE(IMGFMT_RGB15_LE, IMGFMT_RGB15_BE), + IMGFMT_RGB16 = MP_SELECT_LE_BE(IMGFMT_RGB16_LE, IMGFMT_RGB16_BE), + IMGFMT_BGR12 = MP_SELECT_LE_BE(IMGFMT_BGR12_LE, IMGFMT_BGR12_BE), + IMGFMT_BGR15 = MP_SELECT_LE_BE(IMGFMT_BGR15_LE, IMGFMT_BGR15_BE), + IMGFMT_BGR16 = MP_SELECT_LE_BE(IMGFMT_BGR16_LE, IMGFMT_BGR16_BE), + IMGFMT_RGB48 = MP_SELECT_LE_BE(IMGFMT_RGB48_LE, IMGFMT_RGB48_BE), + + IMGFMT_444P16 = MP_SELECT_LE_BE(IMGFMT_444P16_LE, IMGFMT_444P16_BE), + IMGFMT_444P14 = MP_SELECT_LE_BE(IMGFMT_444P14_LE, IMGFMT_444P14_BE), + IMGFMT_444P12 = MP_SELECT_LE_BE(IMGFMT_444P12_LE, IMGFMT_444P12_BE), + IMGFMT_444P10 = MP_SELECT_LE_BE(IMGFMT_444P10_LE, IMGFMT_444P10_BE), + IMGFMT_444P9 = MP_SELECT_LE_BE(IMGFMT_444P9_LE, IMGFMT_444P9_BE), + + IMGFMT_422P16 = MP_SELECT_LE_BE(IMGFMT_422P16_LE, IMGFMT_422P16_BE), + IMGFMT_422P14 = MP_SELECT_LE_BE(IMGFMT_422P14_LE, IMGFMT_422P14_BE), + IMGFMT_422P12 = MP_SELECT_LE_BE(IMGFMT_422P12_LE, IMGFMT_422P12_BE), + IMGFMT_422P10 = MP_SELECT_LE_BE(IMGFMT_422P10_LE, IMGFMT_422P10_BE), + IMGFMT_422P9 = MP_SELECT_LE_BE(IMGFMT_422P9_LE, IMGFMT_422P9_BE), + + IMGFMT_420P16 = MP_SELECT_LE_BE(IMGFMT_420P16_LE, IMGFMT_420P16_BE), + IMGFMT_420P14 = MP_SELECT_LE_BE(IMGFMT_420P14_LE, IMGFMT_420P14_BE), + IMGFMT_420P12 = MP_SELECT_LE_BE(IMGFMT_420P12_LE, IMGFMT_420P12_BE), + IMGFMT_420P10 = MP_SELECT_LE_BE(IMGFMT_420P10_LE, IMGFMT_420P10_BE), + IMGFMT_420P9 = MP_SELECT_LE_BE(IMGFMT_420P9_LE, IMGFMT_420P9_BE), + + IMGFMT_Y16 = MP_SELECT_LE_BE(IMGFMT_Y16_LE, IMGFMT_Y16_BE), +}; static inline bool IMGFMT_IS_RGB(unsigned int fmt) { @@ -152,172 +253,31 @@ static inline bool IMGFMT_IS_BGR(unsigned int fmt) #define IMGFMT_RGB_DEPTH(fmt) (mp_imgfmt_get_desc(fmt).plane_bits) #define IMGFMT_BGR_DEPTH(fmt) (mp_imgfmt_get_desc(fmt).plane_bits) -// AV_PIX_FMT_GRAY16LE -#define IMGFMT_Y16LE 0x1DC70001 -// AV_PIX_FMT_GRAY16BE -#define IMGFMT_Y16BE 0x1DC70002 -// AV_PIX_FMT_PAL8 -#define IMGFMT_PAL8 0x1DC70003 - #if BYTE_ORDER == BIG_ENDIAN -#define IMGFMT_Y16 IMGFMT_Y16BE -#else -#define IMGFMT_Y16 IMGFMT_Y16LE -#endif - -/* Planar YUV Formats */ - -#define IMGFMT_YVU9 0x39555659 -#define IMGFMT_IF09 0x39304649 -#define IMGFMT_YV12 0x32315659 -#define IMGFMT_I420 0x30323449 -#define IMGFMT_IYUV 0x56555949 -#define IMGFMT_CLPL 0x4C504C43 -#define IMGFMT_Y800 0x30303859 -#define IMGFMT_Y8 0x20203859 -#define IMGFMT_NV12 0x3231564E -#define IMGFMT_NV21 0x3132564E - -/* unofficial Planar Formats, FIXME if official 4CC exists */ -#define IMGFMT_444P 0x50343434 -#define IMGFMT_422P 0x50323234 -#define IMGFMT_411P 0x50313134 -#define IMGFMT_440P 0x50303434 -#define IMGFMT_HM12 0x32314D48 - -// 4:2:0 planar with alpha -#define IMGFMT_420A 0x41303234 - -#define IMGFMT_444P16_LE 0x51343434 -#define IMGFMT_444P16_BE 0x34343451 -#define IMGFMT_444P10_LE 0x52343434 -#define IMGFMT_444P10_BE 0x34343452 -#define IMGFMT_444P9_LE 0x53343434 -#define IMGFMT_444P9_BE 0x34343453 -#define IMGFMT_444P12_LE 0x54343434 -#define IMGFMT_444P12_BE 0x34343454 -#define IMGFMT_444P14_LE 0x55343434 -#define IMGFMT_444P14_BE 0x34343455 -#define IMGFMT_422P16_LE 0x51323234 -#define IMGFMT_422P16_BE 0x34323251 -#define IMGFMT_422P10_LE 0x52323234 -#define IMGFMT_422P10_BE 0x34323252 -#define IMGFMT_422P9_LE 0x53323234 -#define IMGFMT_422P9_BE 0x34323253 -#define IMGFMT_422P12_LE 0x54323234 -#define IMGFMT_422P12_BE 0x34323254 -#define IMGFMT_422P14_LE 0x55323234 -#define IMGFMT_422P14_BE 0x34323255 -#define IMGFMT_420P16_LE 0x51303234 -#define IMGFMT_420P16_BE 0x34323051 -#define IMGFMT_420P10_LE 0x52303234 -#define IMGFMT_420P10_BE 0x34323052 -#define IMGFMT_420P9_LE 0x53303234 -#define IMGFMT_420P9_BE 0x34323053 -#define IMGFMT_420P12_LE 0x54303234 -#define IMGFMT_420P12_BE 0x34323054 -#define IMGFMT_420P14_LE 0x55303234 -#define IMGFMT_420P14_BE 0x34323055 -#if BYTE_ORDER == BIG_ENDIAN -#define IMGFMT_444P16 IMGFMT_444P16_BE -#define IMGFMT_444P14 IMGFMT_444P14_BE -#define IMGFMT_444P12 IMGFMT_444P12_BE -#define IMGFMT_444P10 IMGFMT_444P10_BE -#define IMGFMT_444P9 IMGFMT_444P9_BE -#define IMGFMT_422P16 IMGFMT_422P16_BE -#define IMGFMT_422P14 IMGFMT_422P14_BE -#define IMGFMT_422P12 IMGFMT_422P12_BE -#define IMGFMT_422P10 IMGFMT_422P10_BE -#define IMGFMT_422P9 IMGFMT_422P9_BE -#define IMGFMT_420P16 IMGFMT_420P16_BE -#define IMGFMT_420P14 IMGFMT_420P14_BE -#define IMGFMT_420P12 IMGFMT_420P12_BE -#define IMGFMT_420P10 IMGFMT_420P10_BE -#define IMGFMT_420P9 IMGFMT_420P9_BE #define IMGFMT_IS_YUVP16_NE(fmt) IMGFMT_IS_YUVP16_BE(fmt) #else -#define IMGFMT_444P16 IMGFMT_444P16_LE -#define IMGFMT_444P14 IMGFMT_444P14_LE -#define IMGFMT_444P12 IMGFMT_444P12_LE -#define IMGFMT_444P10 IMGFMT_444P10_LE -#define IMGFMT_444P9 IMGFMT_444P9_LE -#define IMGFMT_422P16 IMGFMT_422P16_LE -#define IMGFMT_422P14 IMGFMT_422P14_LE -#define IMGFMT_422P12 IMGFMT_422P12_LE -#define IMGFMT_422P10 IMGFMT_422P10_LE -#define IMGFMT_422P9 IMGFMT_422P9_LE -#define IMGFMT_420P16 IMGFMT_420P16_LE -#define IMGFMT_420P14 IMGFMT_420P14_LE -#define IMGFMT_420P12 IMGFMT_420P12_LE -#define IMGFMT_420P10 IMGFMT_420P10_LE -#define IMGFMT_420P9 IMGFMT_420P9_LE #define IMGFMT_IS_YUVP16_NE(fmt) IMGFMT_IS_YUVP16_LE(fmt) #endif // These functions are misnamed - they actually match 9 to 16 bits (inclusive) static inline bool IMGFMT_IS_YUVP16_LE(int fmt) { struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt); - bool le_is_ne = BYTE_ORDER == LITTLE_ENDIAN; return (desc.flags & MP_IMGFLAG_YUV_P) && desc.plane_bits > 8 && - (le_is_ne == !!(desc.flags & MP_IMGFLAG_NE)); + (desc.flags & MP_IMGFLAG_LE); } static inline bool IMGFMT_IS_YUVP16_BE(int fmt) { struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt); - bool be_is_ne = BYTE_ORDER == BIG_ENDIAN; return (desc.flags & MP_IMGFLAG_YUV_P) && desc.plane_bits > 8 && - (be_is_ne == !!(desc.flags & MP_IMGFLAG_NE)); + (desc.flags & MP_IMGFLAG_BE); } #define IMGFMT_IS_YUVP16(fmt) (IMGFMT_IS_YUVP16_LE(fmt) || IMGFMT_IS_YUVP16_BE(fmt)) -/* Packed YUV Formats */ - -#define IMGFMT_IUYV 0x56595549 // Interlaced UYVY -#define IMGFMT_IY41 0x31435949 // Interlaced Y41P -#define IMGFMT_IYU1 0x31555949 -#define IMGFMT_IYU2 0x32555949 -#define IMGFMT_UYVY 0x59565955 -#define IMGFMT_UYNV 0x564E5955 // Exactly same as UYVY -#define IMGFMT_cyuv 0x76757963 // upside-down UYVY -#define IMGFMT_Y422 0x32323459 // Exactly same as UYVY -#define IMGFMT_YUY2 0x32595559 -#define IMGFMT_YUNV 0x564E5559 // Exactly same as YUY2 -#define IMGFMT_YVYU 0x55595659 -#define IMGFMT_Y41P 0x50313459 -#define IMGFMT_Y211 0x31313259 -#define IMGFMT_Y41T 0x54313459 // Y41P, Y lsb = transparency -#define IMGFMT_Y42T 0x54323459 // UYVY, Y lsb = transparency -#define IMGFMT_V422 0x32323456 // upside-down UYVY? -#define IMGFMT_V655 0x35353656 -#define IMGFMT_CLJR 0x524A4C43 -#define IMGFMT_YUVP 0x50565559 // 10-bit YUYV -#define IMGFMT_UYVP 0x50565955 // 10-bit UYVY - -/* Compressed Formats */ -#define IMGFMT_MJPEG (('M')|('J'<<8)|('P'<<16)|('G'<<24)) - -// VDPAU specific format. -#define IMGFMT_VDPAU 0x1DC80000 -#define IMGFMT_VDPAU_MASK 0xFFFF0000 -#define IMGFMT_IS_VDPAU(fmt) (((fmt)&IMGFMT_VDPAU_MASK)==IMGFMT_VDPAU) -#define IMGFMT_VDPAU_MPEG1 (IMGFMT_VDPAU|0x01) -#define IMGFMT_VDPAU_MPEG2 (IMGFMT_VDPAU|0x02) -#define IMGFMT_VDPAU_H264 (IMGFMT_VDPAU|0x03) -#define IMGFMT_VDPAU_WMV3 (IMGFMT_VDPAU|0x04) -#define IMGFMT_VDPAU_VC1 (IMGFMT_VDPAU|0x05) -#define IMGFMT_VDPAU_MPEG4 (IMGFMT_VDPAU|0x06) +#define IMGFMT_IS_VDPAU(fmt) \ + (((fmt) >= IMGFMT_VDPAU_FIRST) && ((fmt) <= IMGFMT_VDPAU_LAST)) #define IMGFMT_IS_HWACCEL(fmt) IMGFMT_IS_VDPAU(fmt) -typedef struct { - void* data; - int size; - int id; // stream id. usually 0x1E0 - int timestamp; // pts, 90000 Hz counter based -} vo_mpegpes_t; - -const char *vo_format_name(int format); - /** * Calculates the scale shifts for the chroma planes for planar YUV * @@ -336,4 +296,6 @@ extern struct mp_imgfmt_entry mp_imgfmt_list[]; unsigned int mp_imgfmt_from_name(bstr name, bool allow_hwaccel); const char *mp_imgfmt_to_name(unsigned int fmt); +#define vo_format_name mp_imgfmt_to_name + #endif /* MPLAYER_IMG_FORMAT_H */ diff --git a/video/img_fourcc.h b/video/img_fourcc.h new file mode 100644 index 0000000000..fecb13f297 --- /dev/null +++ b/video/img_fourcc.h @@ -0,0 +1,57 @@ +#ifndef MPV_IMG_FOURCC_H +#define MPV_IMG_FOURCC_H + +#include + +#define MP_FOURCC(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((unsigned)(d)<<24)) + +#if BYTE_ORDER == BIG_ENDIAN +#define MP_FOURCC_E(a,b,c,d) MP_FOURCC(a,b,c,d) +#else +#define MP_FOURCC_E(a,b,c,d) MP_FOURCC(d,c,b,a) +#endif + +#define MP_FOURCC_RGB8 MP_FOURCC_E(8, 'B', 'G', 'R') +#define MP_FOURCC_RGB12 MP_FOURCC_E(12, 'B', 'G', 'R') +#define MP_FOURCC_RGB15 MP_FOURCC_E(15, 'B', 'G', 'R') +#define MP_FOURCC_RGB16 MP_FOURCC_E(16, 'B', 'G', 'R') +#define MP_FOURCC_RGB24 MP_FOURCC_E(24, 'B', 'G', 'R') +#define MP_FOURCC_RGB32 MP_FOURCC_E('A', 'B', 'G', 'R') + +#define MP_FOURCC_BGR8 MP_FOURCC_E(8, 'R', 'G', 'B') +#define MP_FOURCC_BGR12 MP_FOURCC_E(12, 'R', 'G', 'B') +#define MP_FOURCC_BGR15 MP_FOURCC_E(15, 'R', 'G', 'B') +#define MP_FOURCC_BGR16 MP_FOURCC_E(16, 'R', 'G', 'B') +#define MP_FOURCC_BGR24 MP_FOURCC_E(24, 'R', 'G', 'B') +#define MP_FOURCC_BGR32 MP_FOURCC_E('A', 'R', 'G', 'B') + +#define MP_FOURCC_YVU9 MP_FOURCC('Y', 'U', 'V', '9') +#define MP_FOURCC_YUV9 MP_FOURCC('Y', 'V', 'U', '9') +#define MP_FOURCC_YV12 MP_FOURCC('Y', 'V', '1', '2') +#define MP_FOURCC_I420 MP_FOURCC('I', '4', '2', '0') +#define MP_FOURCC_IYUV MP_FOURCC('I', 'Y', 'U', 'V') +#define MP_FOURCC_Y800 MP_FOURCC('Y', '8', '0', '0') +#define MP_FOURCC_Y8 MP_FOURCC('Y', '8', ' ', ' ') +#define MP_FOURCC_NV12 MP_FOURCC('N', 'V', '1', '2') +#define MP_FOURCC_NV21 MP_FOURCC('N', 'V', '2', '1') + +#define MP_FOURCC_UYVY MP_FOURCC('U', 'Y', 'V', 'Y') +#define MP_FOURCC_YUY2 MP_FOURCC('Y', 'U', 'Y', '2') + +#define MP_FOURCC_MJPEG MP_FOURCC('M', 'J', 'P', 'G') + +/* mplayer internal FourCCs + * see codecs.conf/vd_lavc.c + */ + +// lavc raw video decoder uses fourcc specified in sh_video->imgfmt +#define MP_FOURCC_RAWVIDEO MP_FOURCC('M', 'P', 'r', 'v') + +// lavc raw video decoder uses image format (IMGFMT_*) in sh_video->imgfmt +#define MP_FOURCC_IMGFMT MP_FOURCC('M', 'P', 'v', 'f') + +// NOTE: no "HM12" decoder exists, as vd_hmblck has been removed +// likely breaks video with some TV cards +#define MP_FOURCC_HM12 0x32314D48 + +#endif diff --git a/video/out/gl_common.c b/video/out/gl_common.c index b7b30702a6..697b1bbbbc 100644 --- a/video/out/gl_common.c +++ b/video/out/gl_common.c @@ -141,13 +141,13 @@ int glFindFormat(uint32_t fmt, int have_texture_rg, int *bpp, GLint *gl_texfmt, else if (IMGFMT_IS_YUVP16_BE(fmt)) fmt = IMGFMT_420P16_BE; else - fmt = IMGFMT_YV12; + fmt = IMGFMT_420P; } *bpp = IMGFMT_IS_BGR(fmt) ? IMGFMT_BGR_DEPTH(fmt) : IMGFMT_RGB_DEPTH(fmt); *gl_texfmt = 3; switch (fmt) { - case IMGFMT_RGB48NE: + case IMGFMT_RGB48: *gl_format = GL_RGB; *gl_type = GL_UNSIGNED_SHORT; break; @@ -167,9 +167,8 @@ int glFindFormat(uint32_t fmt, int have_texture_rg, int *bpp, GLint *gl_texfmt, *gl_format = have_texture_rg ? GL_RED : GL_LUMINANCE; *gl_type = GL_UNSIGNED_SHORT; break; - case IMGFMT_YV12: + case IMGFMT_420P: supported = 0; // no native YV12 support - case IMGFMT_Y800: case IMGFMT_Y8: *gl_texfmt = 1; *bpp = 8; @@ -177,9 +176,6 @@ int glFindFormat(uint32_t fmt, int have_texture_rg, int *bpp, GLint *gl_texfmt, *gl_type = GL_UNSIGNED_BYTE; break; case IMGFMT_UYVY: - // IMGFMT_YUY2 would be more logical for the _REV format, - // but gives clearly swapped colors. - case IMGFMT_YVYU: *gl_texfmt = GL_YCBCR_MESA; *bpp = 16; *gl_format = GL_YCBCR_MESA; diff --git a/video/out/vo.h b/video/out/vo.h index eb55417f4c..73eb19c8d7 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -156,7 +156,7 @@ struct vo_driver { /* * Whether the given image format is supported and config() will succeed. - * format: fourcc of pixel format + * format: one of IMGFMT_* * returns: 0 on not supported, otherwise a bitmask of VFCAP_* values */ int (*query_format)(struct vo *vo, uint32_t format); diff --git a/video/out/vo_corevideo.m b/video/out/vo_corevideo.m index 5e1ecf25a7..a31a2bd7b1 100644 --- a/video/out/vo_corevideo.m +++ b/video/out/vo_corevideo.m @@ -248,7 +248,7 @@ static int query_format(struct vo *vo, uint32_t format) const int flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD; switch (format) { - case IMGFMT_YUY2: + case IMGFMT_YUYV: p->pixelFormat = kYUVSPixelFormat; return flags; @@ -346,7 +346,7 @@ static int get_image_fmt(struct vo *vo) { struct priv *p = vo->priv; switch (p->pixelFormat) { - case kYUVSPixelFormat: return IMGFMT_YUY2; + case kYUVSPixelFormat: return IMGFMT_YUYV; case k24RGBPixelFormat: return IMGFMT_RGB24; case k32ARGBPixelFormat: return IMGFMT_ARGB; case k32BGRAPixelFormat: return IMGFMT_BGRA; diff --git a/video/out/vo_direct3d.c b/video/out/vo_direct3d.c index 51caaf2be9..6dbf1d3d59 100644 --- a/video/out/vo_direct3d.c +++ b/video/out/vo_direct3d.c @@ -202,12 +202,12 @@ struct fmt_entry { static const struct fmt_entry fmt_table[] = { // planar YUV - {IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')}, - {IMGFMT_I420, MAKEFOURCC('I','4','2','0')}, - {IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')}, - {IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')}, + {IMGFMT_420P, MAKEFOURCC('Y','V','1','2')}, + {IMGFMT_420P, MAKEFOURCC('I','4','2','0')}, + {IMGFMT_420P, MAKEFOURCC('I','Y','U','V')}, + {IMGFMT_410P, MAKEFOURCC('Y','V','U','9')}, // packed YUV - {IMGFMT_YUY2, D3DFMT_YUY2}, + {IMGFMT_YUYV, D3DFMT_YUY2}, {IMGFMT_UYVY, D3DFMT_UYVY}, // packed RGB {IMGFMT_BGR32, D3DFMT_X8R8G8B8}, @@ -1460,7 +1460,7 @@ static int control(struct vo *vo, uint32_t request, void *data) * @param d_height Screen (destination) height * @param options Options bitmap * @param format Movie colorspace format (using MPlayer's - * defines, e.g. IMGFMT_YUY2) + * defines, e.g. IMGFMT_YUYV) * @return 0 on success, VO_ERROR on failure */ static int config(struct vo *vo, uint32_t width, uint32_t height, diff --git a/video/out/vo_opengl.c b/video/out/vo_opengl.c index 665e008178..d0c435c59a 100644 --- a/video/out/vo_opengl.c +++ b/video/out/vo_opengl.c @@ -237,7 +237,7 @@ struct fmt_entry { }; static const struct fmt_entry mp_to_gl_formats[] = { - {IMGFMT_RGB48NE, GL_RGB16, GL_RGB, 16, GL_UNSIGNED_SHORT}, + {IMGFMT_RGB48, GL_RGB16, GL_RGB, 16, GL_UNSIGNED_SHORT}, {IMGFMT_RGB24, GL_RGB, GL_RGB, 8, GL_UNSIGNED_BYTE}, {IMGFMT_RGBA, GL_RGBA, GL_RGBA, 8, GL_UNSIGNED_BYTE}, {IMGFMT_RGB15, GL_RGBA, GL_RGBA, 5, GL_UNSIGNED_SHORT_1_5_5_5_REV}, diff --git a/video/out/vo_opengl_old.c b/video/out/vo_opengl_old.c index 6605876226..de38fcb067 100644 --- a/video/out/vo_opengl_old.c +++ b/video/out/vo_opengl_old.c @@ -831,9 +831,9 @@ static int query_format(struct vo *vo, uint32_t format) return caps; // HACK, otherwise we get only b&w with some filters (e.g. -vf eq) // ideally MPlayer should be fixed instead not to use Y800 when it has the choice - if (!p->use_yuv && (format == IMGFMT_Y8 || format == IMGFMT_Y800)) + if (!p->use_yuv && (format == IMGFMT_Y8)) return 0; - if (!p->use_ycbcr && (format == IMGFMT_UYVY || format == IMGFMT_YVYU)) + if (!p->use_ycbcr && (format == IMGFMT_UYVY)) return 0; if (p->many_fmts && glFindFormat(format, p->have_texture_rg, NULL, NULL, NULL, NULL)) diff --git a/video/out/vo_sdl.c b/video/out/vo_sdl.c index c3ed3c6774..d760aff50c 100644 --- a/video/out/vo_sdl.c +++ b/video/out/vo_sdl.c @@ -54,11 +54,11 @@ struct formatmap_entry { int is_rgba; }; const struct formatmap_entry formats[] = { - {SDL_PIXELFORMAT_YV12, IMGFMT_YV12, 0}, - {SDL_PIXELFORMAT_IYUV, IMGFMT_IYUV, 0}, - {SDL_PIXELFORMAT_YUY2, IMGFMT_YUY2, 0}, + {SDL_PIXELFORMAT_YV12, IMGFMT_420P, 0}, + {SDL_PIXELFORMAT_IYUV, IMGFMT_420P, 0}, + {SDL_PIXELFORMAT_YUY2, IMGFMT_YUYV, 0}, {SDL_PIXELFORMAT_UYVY, IMGFMT_UYVY, 0}, - {SDL_PIXELFORMAT_YVYU, IMGFMT_YVYU, 0}, + //{SDL_PIXELFORMAT_YVYU, IMGFMT_YVYU, 0}, #if BYTE_ORDER == BIG_ENDIAN {SDL_PIXELFORMAT_RGBX8888, IMGFMT_RGBA, 0}, // has no alpha -> bad for OSD {SDL_PIXELFORMAT_BGRX8888, IMGFMT_BGRA, 0}, // has no alpha -> bad for OSD @@ -172,6 +172,7 @@ struct priv { int renderer_index; SDL_RendererInfo renderer_info; SDL_Texture *tex; + int tex_swapped; mp_image_t texmpi; mp_image_t *ssmpi; struct mp_rect src_rect; @@ -427,6 +428,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, return -1; } + vc->tex_swapped = texfmt == SDL_PIXELFORMAT_YV12; vc->tex = SDL_CreateTexture(vc->renderer, texfmt, SDL_TEXTUREACCESS_STREAMING, width, height); if (!vc->tex) { @@ -878,7 +880,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) texmpi->planes[0] = pixels; texmpi->stride[0] = pitch; if (texmpi->num_planes == 3) { - if (texmpi->imgfmt == IMGFMT_YV12) { + if (vc->tex_swapped) { texmpi->planes[2] = ((Uint8 *) texmpi->planes[0] + texmpi->h * pitch); texmpi->stride[2] = pitch / 2; diff --git a/video/out/vo_vdpau.c b/video/out/vo_vdpau.c index 4