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. --- DOCS/man/en/options.rst | 7 +- core/cfg-mplayer.h | 2 +- core/m_option.c | 35 ++++ core/m_option.h | 3 + core/mp_common.h | 3 + demux/demux_mng.c | 5 +- demux/demux_rawvideo.c | 81 +++++--- demux/stheader.h | 1 + etc/codecs.conf | 9 + stream/tv.c | 45 ++--- stream/tvi_bsdbt848.c | 6 +- stream/tvi_def.h | 12 +- stream/tvi_dummy.c | 7 +- stream/tvi_v4l2.c | 98 +++++----- 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 +++- 52 files changed, 695 insertions(+), 695 deletions(-) create mode 100644 video/img_fourcc.h diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 936f3b3293..c629d35046 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1605,10 +1605,11 @@ :sqcif|qcif|cif|4cif|pal|ntsc: set standard image size :w=: image width in pixels :h=: image height in pixels - :i420|yv12|yuy2|y8: set colorspace :format=: colorspace (fourcc) in hex or string - constant. Use ``--rawvideo=format=help`` - for a list of possible strings. + constant. + :mp-format=: colorspace by internal video format + Use ``--rawvideo=mp-format=help`` + for a list of possible formats. :size=: frame size in Bytes *EXAMPLE*: diff --git a/core/cfg-mplayer.h b/core/cfg-mplayer.h index 9627a25140..0aef77ae70 100644 --- a/core/cfg-mplayer.h +++ b/core/cfg-mplayer.h @@ -107,7 +107,7 @@ const m_option_t tvopts_conf[]={ {"width", &stream_tv_defaults.width, CONF_TYPE_INT, 0, 0, 4096, NULL}, {"height", &stream_tv_defaults.height, CONF_TYPE_INT, 0, 0, 4096, NULL}, {"input", &stream_tv_defaults.input, CONF_TYPE_INT, 0, 0, 20, NULL}, - {"outfmt", &stream_tv_defaults.outfmt, CONF_TYPE_IMGFMT, 0, 0, 0, NULL}, + {"outfmt", &stream_tv_defaults.outfmt, CONF_TYPE_FOURCC, 0, 0, 0, NULL}, {"fps", &stream_tv_defaults.fps, CONF_TYPE_FLOAT, 0, 0, 100.0, NULL}, {"channels", &stream_tv_defaults.channels, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, {"brightness", &stream_tv_defaults.brightness, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL}, diff --git a/core/m_option.c b/core/m_option.c index 7ea25c25b0..82f6265124 100644 --- a/core/m_option.c +++ b/core/m_option.c @@ -1203,6 +1203,41 @@ const m_option_type_t m_option_type_imgfmt = { .copy = copy_opt, }; +static int parse_fourcc(const m_option_t *opt, struct bstr name, + struct bstr param, void *dst) +{ + if (param.len == 0) + return M_OPT_MISSING_PARAM; + + unsigned int value; + + if (param.len == 4) { + uint8_t *s = param.start; + value = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); + } else { + bstr rest; + value = bstrtoll(param, &rest, 16); + if (rest.len != 0) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Option %.*s: invalid FourCC: '%.*s'\n", + BSTR_P(name), BSTR_P(param)); + return M_OPT_INVALID; + } + } + + if (dst) + *((unsigned int *)dst) = value; + + return 1; +} + +const m_option_type_t m_option_type_fourcc = { + .name = "FourCC", + .size = sizeof(unsigned int), + .parse = parse_fourcc, + .copy = copy_opt, +}; + #include "audio/format.h" static int parse_afmt(const m_option_t *opt, struct bstr name, diff --git a/core/m_option.h b/core/m_option.h index 20bcfba1c2..f6c346521a 100644 --- a/core/m_option.h +++ b/core/m_option.h @@ -53,6 +53,7 @@ extern const m_option_type_t m_option_type_print_func_param; extern const m_option_type_t m_option_type_subconfig; extern const m_option_type_t m_option_type_subconfig_struct; extern const m_option_type_t m_option_type_imgfmt; +extern const m_option_type_t m_option_type_fourcc; extern const m_option_type_t m_option_type_afmt; extern const m_option_type_t m_option_type_color; @@ -177,6 +178,7 @@ struct m_sub_options { #define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig) #define CONF_TYPE_STRING_LIST (&m_option_type_string_list) #define CONF_TYPE_IMGFMT (&m_option_type_imgfmt) +#define CONF_TYPE_FOURCC (&m_option_type_fourcc) #define CONF_TYPE_AFMT (&m_option_type_afmt) #define CONF_TYPE_SPAN (&m_option_type_span) #define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list) @@ -198,6 +200,7 @@ union m_option_value { char *string; char **string_list; int imgfmt; + unsigned int fourcc; int afmt; m_span_t span; m_obj_settings_t *obj_settings_list; diff --git a/core/mp_common.h b/core/mp_common.h index 184cea2a32..0ee14ab484 100644 --- a/core/mp_common.h +++ b/core/mp_common.h @@ -28,6 +28,9 @@ // both int64_t and double should be able to represent this exactly #define MP_NOPTS_VALUE (-1LL<<63) +#define MP_CONCAT_(a, b) a ## b +#define MP_CONCAT(a, b) MP_CONCAT_(a, b) + #define ROUND(x) ((int)((x) < 0 ? (x) - 0.5 : (x) + 0.5)) extern const char *mplayer_version; diff --git a/demux/demux_mng.c b/demux/demux_mng.c index 1d21d9d218..74f633d64e 100644 --- a/demux/demux_mng.c +++ b/demux/demux_mng.c @@ -31,7 +31,7 @@ #include "stream/stream.h" #include "demux.h" #include "stheader.h" -#include "video/img_format.h" +#include "video/img_fourcc.h" #define MNG_SUPPORT_READ #define MNG_SUPPORT_DISPLAY @@ -437,7 +437,8 @@ static demuxer_t * demux_mng_open(demuxer_t * demuxer) sh_video->ds = demuxer->video; // set format of pixels in video packets - sh_video->format = IMGFMT_RGB32; + sh_video->format = MP_FOURCC_RAWVIDEO; + sh_video->imgfmt = MP_FOURCC_RGB32; // set framerate to some value (MNG does not have a fixed framerate) sh_video->fps = 5.0f; diff --git a/demux/demux_rawvideo.c b/demux/demux_rawvideo.c index 68dc270e44..47d32f933e 100644 --- a/demux/demux_rawvideo.c +++ b/demux/demux_rawvideo.c @@ -30,8 +30,10 @@ #include "stheader.h" #include "video/img_format.h" +#include "video/img_fourcc.h" -static int format = IMGFMT_I420; +static int format = MP_FOURCC_I420; +static int mp_format; static int size_id = 0; static int width = 0; static int height = 0; @@ -51,15 +53,8 @@ const m_option_t demux_rawvideo_opts[] = { { "16cif", &size_id, CONF_TYPE_FLAG,0,0,7, NULL }, { "sif", &size_id, CONF_TYPE_FLAG,0,0,8, NULL }, // format: - { "format", &format, CONF_TYPE_IMGFMT, 0, 0 , 0, NULL }, - // below options are obsolete - { "i420", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_I420, NULL }, - { "yv12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YV12, NULL }, - { "nv12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_NV12, NULL }, - { "hm12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_HM12, NULL }, - { "yuy2", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YUY2, NULL }, - { "uyvy", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_UYVY, NULL }, - { "y8", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_Y8, NULL }, + { "format", &format, CONF_TYPE_FOURCC, 0, 0 , 0, NULL }, + { "mp-format", &mp_format, CONF_TYPE_IMGFMT, 0, 0 , 0, NULL }, // misc: { "fps", &fps, CONF_TYPE_FLOAT,CONF_RANGE,0.001,1000, NULL }, { "size", &imgsize, CONF_TYPE_INT, CONF_RANGE, 1 , 8192*8192*4, NULL }, @@ -86,30 +81,58 @@ static demuxer_t* demux_rawvideo_open(demuxer_t* demuxer) { return 0; } - if(!imgsize) - switch(format){ - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_NV12: - case IMGFMT_HM12: - case IMGFMT_YV12: imgsize=width*height+2*(width>>1)*(height>>1);break; - case IMGFMT_YUY2: - case IMGFMT_UYVY: imgsize=width*height*2;break; - case IMGFMT_Y800: - case IMGFMT_Y8: imgsize=width*height;break; - default: - if (IMGFMT_IS_RGB(format)) - imgsize = width * height * ((IMGFMT_RGB_DEPTH(format) + 7) >> 3); - else if (IMGFMT_IS_BGR(format)) - imgsize = width * height * ((IMGFMT_BGR_DEPTH(format) + 7) >> 3); - else { + int tag, fmt; + if (mp_format) { + tag = MP_FOURCC_IMGFMT; + fmt = mp_format; + if (!imgsize) { + struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(mp_format); + for (int p = 0; p < desc.num_planes; p++) { + imgsize += ((width >> desc.xs[p]) * (height >> desc.ys[p]) * + desc.bpp[p] + 7) / 8; + } + } + } else { + tag = MP_FOURCC_RAWVIDEO; + fmt = format; + } + + if (!imgsize) { + int bpp = 0; + switch(format){ + case MP_FOURCC_I420: case MP_FOURCC_IYUV: + case MP_FOURCC_NV12: case MP_FOURCC_NV21: + case MP_FOURCC_HM12: + case MP_FOURCC_YV12: + bpp = 12; + break; + case MP_FOURCC_RGB12: case MP_FOURCC_BGR12: + case MP_FOURCC_RGB15: case MP_FOURCC_BGR15: + case MP_FOURCC_RGB16: case MP_FOURCC_BGR16: + case MP_FOURCC_YUY2: case MP_FOURCC_UYVY: + bpp = 16; + break; + case MP_FOURCC_RGB8: case MP_FOURCC_BGR8: + case MP_FOURCC_Y800: case MP_FOURCC_Y8: + bpp = 8; + break; + case MP_FOURCC_RGB24: case MP_FOURCC_BGR24: + bpp = 24; + break; + case MP_FOURCC_RGB32: case MP_FOURCC_BGR32: + bpp = 32; + break; + } + if (!bpp) { mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: img size not specified and unknown format!\n"); return 0; - } + } + imgsize = width * height * bpp / 8; } sh_video = new_sh_video(demuxer,0); - sh_video->format=format; + sh_video->format=tag; + sh_video->imgfmt=fmt; sh_video->fps=fps; sh_video->frametime=1.0/fps; sh_video->disp_w=width; diff --git a/demux/stheader.h b/demux/stheader.h index 4745e452d5..97d079f4e6 100644 --- a/demux/stheader.h +++ b/demux/stheader.h @@ -154,6 +154,7 @@ typedef struct sh_video { int disp_w, disp_h; // display size (filled by demuxer) int colorspace; // mp_csp int color_range; // mp_csp_levels + int imgfmt; // raw video image format // output driver/filters: (set by libmpcodecs core) unsigned int outfmt; struct vf_instance *vfilter; // video filter chain diff --git a/etc/codecs.conf b/etc/codecs.conf index 46f87e1cd6..ba00957a94 100644 --- a/etc/codecs.conf +++ b/etc/codecs.conf @@ -1430,6 +1430,15 @@ videocodec ffrawy800 driver ffmpeg dll rawvideo +; used by some demuxers (demux_rawvideo.c, demux_mng.c, stream/tv.c) +videocodec ffrawvideo + info "RAW video" + status working + fourcc MPrv + fourcc MPvf ; internal mpv FourCC for demux_rawvideo + driver ffmpeg + dll rawvideo + ;============================================================================= ; AUDIO CODECS ;============================================================================= diff --git a/stream/tv.c b/stream/tv.c index e5e64dd636..a9bc535cee 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -42,7 +42,7 @@ #include "demux/stheader.h" #include "audio/format.h" -#include "video/img_format.h" +#include "video/img_fourcc.h" #include "libavutil/avstring.h" #include "osdep/timer.h" @@ -409,14 +409,14 @@ static int open_tv(tvi_handle_t *tvh) int i; const tvi_functions_t *funcs = tvh->functions; static const int tv_fmt_list[] = { - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_UYVY, - IMGFMT_YUY2, - IMGFMT_RGB32, - IMGFMT_RGB24, - IMGFMT_RGB16, - IMGFMT_RGB15 + MP_FOURCC_YV12, + MP_FOURCC_I420, + MP_FOURCC_UYVY, + MP_FOURCC_YUY2, + MP_FOURCC_RGB32, + MP_FOURCC_RGB24, + MP_FOURCC_RGB16, + MP_FOURCC_RGB15 }; if (funcs->control(tvh->priv, TVI_CONTROL_IS_VIDEO, 0) != TVI_CONTROL_TRUE) @@ -437,16 +437,16 @@ static int open_tv(tvi_handle_t *tvh) { switch(tvh->tv_param->outfmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_UYVY: - case IMGFMT_YUY2: - case IMGFMT_RGB32: - case IMGFMT_RGB24: - case IMGFMT_BGR32: - case IMGFMT_BGR24: - case IMGFMT_BGR16: - case IMGFMT_BGR15: + case MP_FOURCC_YV12: + case MP_FOURCC_I420: + case MP_FOURCC_UYVY: + case MP_FOURCC_YUY2: + case MP_FOURCC_RGB32: + case MP_FOURCC_RGB24: + case MP_FOURCC_BGR32: + case MP_FOURCC_BGR24: + case MP_FOURCC_BGR16: + case MP_FOURCC_BGR15: break; default: mp_tmsg(MSGT_TV, MSGL_ERR, @@ -715,9 +715,10 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer) sh_video = new_sh_video(demuxer, 0); /* get IMAGE FORMAT */ - funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &sh_video->format); -// if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format)) -// sh_video->format = 0x0; + int fourcc; + funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &fourcc); + sh_video->format = MP_FOURCC_RAWVIDEO; + sh_video->imgfmt = fourcc; /* set FPS and FRAMETIME */ diff --git a/stream/tvi_bsdbt848.c b/stream/tvi_bsdbt848.c index 19d68dd899..4f101ee74f 100644 --- a/stream/tvi_bsdbt848.c +++ b/stream/tvi_bsdbt848.c @@ -79,7 +79,7 @@ #endif #include "audio/format.h" -#include "video/img_format.h" +#include "video/img_fourcc.h" #include "tv.h" #include "core/mp_msg.h" @@ -450,14 +450,14 @@ static int control(priv_t *priv, int cmd, void *arg) } case TVI_CONTROL_VID_GET_FORMAT: - *(int *)arg = IMGFMT_UYVY; + *(int *)arg = MP_FOURCC_UYVY; return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_SET_FORMAT: { int req_fmt = *(int *)arg; - if(req_fmt != IMGFMT_UYVY) return TVI_CONTROL_FALSE; + if(req_fmt != MP_FOURCC_UYVY) return TVI_CONTROL_FALSE; return TVI_CONTROL_TRUE; } diff --git a/stream/tvi_def.h b/stream/tvi_def.h index 367f2adb35..959237aa04 100644 --- a/stream/tvi_def.h +++ b/stream/tvi_def.h @@ -21,7 +21,7 @@ #include /* malloc */ #include /* memset */ -#include "video/img_format.h" +#include "video/img_fourcc.h" #include "tv.h" static int init(priv_t *priv); @@ -54,17 +54,17 @@ static inline void fill_blank_frame(char* buffer,int len,int fmt){ // RGB(0,0,255) <-> YVU(41,110,240) switch(fmt){ - case IMGFMT_YV12: + case MP_FOURCC_YV12: memset(buffer, 41,4*len/6); //Y memset(buffer+4*len/6, 110,len/6);//V memset(buffer+5*len/6, 240,len/6);//U break; - case IMGFMT_I420: + case MP_FOURCC_I420: memset(buffer, 41,4*len/6); //Y memset(buffer+4*len/6, 240,len/6);//U memset(buffer+5*len/6, 110,len/6);//V break; - case IMGFMT_UYVY: + case MP_FOURCC_UYVY: for(i=0;i -#include "video/img_format.h" +#include "video/img_fourcc.h" #include "tv.h" static tvi_handle_t *tvi_init_dummy(tv_param_t* tv_param); @@ -74,14 +74,13 @@ static int control(priv_t *priv, int cmd, void *arg) case TVI_CONTROL_IS_VIDEO: return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_GET_FORMAT: -// *(int *)arg = IMGFMT_YV12; - *(int *)arg = IMGFMT_YV12; + *(int *)arg = MP_FOURCC_YV12; return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_SET_FORMAT: { // int req_fmt = *(int *)arg; int req_fmt = *(int *)arg; - if (req_fmt != IMGFMT_YV12) + if (req_fmt != MP_FOURCC_YV12) return TVI_CONTROL_FALSE; return TVI_CONTROL_TRUE; } diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c index 14313d0966..abe455d8bf 100644 --- a/stream/tvi_v4l2.c +++ b/stream/tvi_v4l2.c @@ -56,7 +56,7 @@ known issues: #include #endif #include "core/mp_msg.h" -#include "video/img_format.h" +#include "video/img_fourcc.h" #include "audio/format.h" #include "tv.h" #include "audio_in.h" @@ -180,27 +180,27 @@ static void *video_grabber(void *data); Only few of the fourccs are the same in v4l2 and mplayer: - IMGFMT_YVU9 == V4L2_PIX_FMT_YVU410 - IMGFMT_YV12 == V4L2_PIX_FMT_YVU420 - IMGFMT_NV12 == V4L2_PIX_FMT_NV12 - IMGFMT_422P == V4L2_PIX_FMT_YUV422P - IMGFMT_411P == V4L2_PIX_FMT_YUV411P - IMGFMT_UYVY == V4L2_PIX_FMT_UYVY - IMGFMT_Y41P == V4L2_PIX_FMT_Y41P + MP_FOURCC_YVU9 == V4L2_PIX_FMT_YVU410 + MP_FOURCC_YV12 == V4L2_PIX_FMT_YVU420 + MP_FOURCC_NV12 == V4L2_PIX_FMT_NV12 + MP_FOURCC_422P == V4L2_PIX_FMT_YUV422P + MP_FOURCC_411P == V4L2_PIX_FMT_YUV411P + MP_FOURCC_UYVY == V4L2_PIX_FMT_UYVY + MP_FOURCC_Y41P == V4L2_PIX_FMT_Y41P This may be an useful translation table for some others: - IMGFMT_RGB8 == V4L2_PIX_FMT_RGB332 - IMGFMT_BGR15 == V4L2_PIX_FMT_RGB555 - IMGFMT_BGR16 == V4L2_PIX_FMT_RGB565 - IMGFMT_RGB24 == V4L2_PIX_FMT_RGB24 - IMGFMT_RGB32 == V4L2_PIX_FMT_RGB32 - IMGFMT_BGR24 == V4L2_PIX_FMT_BGR24 - IMGFMT_BGR32 == V4L2_PIX_FMT_BGR32 - IMGFMT_Y800 == V4L2_PIX_FMT_GREY - IMGFMT_IF09 == V4L2_PIX_FMT_YUV410 - IMGFMT_I420 == V4L2_PIX_FMT_YUV420 - IMGFMT_YUY2 == V4L2_PIX_FMT_YUYV + MP_FOURCC_RGB8 == V4L2_PIX_FMT_RGB332 + MP_FOURCC_BGR15 == V4L2_PIX_FMT_RGB555 + MP_FOURCC_BGR16 == V4L2_PIX_FMT_RGB565 + MP_FOURCC_RGB24 == V4L2_PIX_FMT_RGB24 + MP_FOURCC_RGB32 == V4L2_PIX_FMT_RGB32 + MP_FOURCC_BGR24 == V4L2_PIX_FMT_BGR24 + MP_FOURCC_BGR32 == V4L2_PIX_FMT_BGR32 + MP_FOURCC_Y800 == V4L2_PIX_FMT_GREY + MP_FOURCC_YUV9 == V4L2_PIX_FMT_YUV410 + MP_FOURCC_I420 == V4L2_PIX_FMT_YUV420 + MP_FOURCC_YUY2 == V4L2_PIX_FMT_YUYV \**********************************************************************/ @@ -210,20 +210,20 @@ static void *video_grabber(void *data); static int fcc_mp2vl(int fcc) { switch (fcc) { - case IMGFMT_RGB8: return V4L2_PIX_FMT_RGB332; - case IMGFMT_BGR15: return V4L2_PIX_FMT_RGB555; - case IMGFMT_BGR16: return V4L2_PIX_FMT_RGB565; - case IMGFMT_RGB24: return V4L2_PIX_FMT_RGB24; - case IMGFMT_RGB32: return V4L2_PIX_FMT_RGB32; - case IMGFMT_BGR24: return V4L2_PIX_FMT_BGR24; - case IMGFMT_BGR32: return V4L2_PIX_FMT_BGR32; - case IMGFMT_Y800: return V4L2_PIX_FMT_GREY; - case IMGFMT_IF09: return V4L2_PIX_FMT_YUV410; - case IMGFMT_I420: return V4L2_PIX_FMT_YUV420; - case IMGFMT_YUY2: return V4L2_PIX_FMT_YUYV; - case IMGFMT_YV12: return V4L2_PIX_FMT_YVU420; - case IMGFMT_UYVY: return V4L2_PIX_FMT_UYVY; - case IMGFMT_MJPEG: return V4L2_PIX_FMT_MJPEG; + case MP_FOURCC_RGB8: return V4L2_PIX_FMT_RGB332; + case MP_FOURCC_BGR15: return V4L2_PIX_FMT_RGB555; + case MP_FOURCC_BGR16: return V4L2_PIX_FMT_RGB565; + case MP_FOURCC_RGB24: return V4L2_PIX_FMT_RGB24; + case MP_FOURCC_RGB32: return V4L2_PIX_FMT_RGB32; + case MP_FOURCC_BGR24: return V4L2_PIX_FMT_BGR24; + case MP_FOURCC_BGR32: return V4L2_PIX_FMT_BGR32; + case MP_FOURCC_Y800: return V4L2_PIX_FMT_GREY; + case MP_FOURCC_YUV9: return V4L2_PIX_FMT_YUV410; + case MP_FOURCC_I420: return V4L2_PIX_FMT_YUV420; + case MP_FOURCC_YUY2: return V4L2_PIX_FMT_YUYV; + case MP_FOURCC_YV12: return V4L2_PIX_FMT_YVU420; + case MP_FOURCC_UYVY: return V4L2_PIX_FMT_UYVY; + case MP_FOURCC_MJPEG: return V4L2_PIX_FMT_MJPEG; } return fcc; } @@ -234,20 +234,20 @@ static int fcc_mp2vl(int fcc) static int fcc_vl2mp(int fcc) { switch (fcc) { - case V4L2_PIX_FMT_RGB332: return IMGFMT_RGB8; - case V4L2_PIX_FMT_RGB555: return IMGFMT_BGR15; - case V4L2_PIX_FMT_RGB565: return IMGFMT_BGR16; - case V4L2_PIX_FMT_RGB24: return IMGFMT_RGB24; - case V4L2_PIX_FMT_RGB32: return IMGFMT_RGB32; - case V4L2_PIX_FMT_BGR24: return IMGFMT_BGR24; - case V4L2_PIX_FMT_BGR32: return IMGFMT_BGR32; - case V4L2_PIX_FMT_GREY: return IMGFMT_Y800; - case V4L2_PIX_FMT_YUV410: return IMGFMT_IF09; - case V4L2_PIX_FMT_YUV420: return IMGFMT_I420; - case V4L2_PIX_FMT_YVU420: return IMGFMT_YV12; - case V4L2_PIX_FMT_YUYV: return IMGFMT_YUY2; - case V4L2_PIX_FMT_UYVY: return IMGFMT_UYVY; - case V4L2_PIX_FMT_MJPEG: return IMGFMT_MJPEG; + case V4L2_PIX_FMT_RGB332: return MP_FOURCC_RGB8; + case V4L2_PIX_FMT_RGB555: return MP_FOURCC_BGR15; + case V4L2_PIX_FMT_RGB565: return MP_FOURCC_BGR16; + case V4L2_PIX_FMT_RGB24: return MP_FOURCC_RGB24; + case V4L2_PIX_FMT_RGB32: return MP_FOURCC_RGB32; + case V4L2_PIX_FMT_BGR24: return MP_FOURCC_BGR24; + case V4L2_PIX_FMT_BGR32: return MP_FOURCC_BGR32; + case V4L2_PIX_FMT_GREY: return MP_FOURCC_Y800; + case V4L2_PIX_FMT_YUV410: return MP_FOURCC_YUV9; + case V4L2_PIX_FMT_YUV420: return MP_FOURCC_I420; + case V4L2_PIX_FMT_YVU420: return MP_FOURCC_YV12; + case V4L2_PIX_FMT_YUYV: return MP_FOURCC_YUY2; + case V4L2_PIX_FMT_UYVY: return MP_FOURCC_UYVY; + case V4L2_PIX_FMT_MJPEG: return MP_FOURCC_MJPEG; } return fcc; } @@ -1252,9 +1252,9 @@ static int init(priv_t *priv) if (ioctl(priv->video_fd, VIDIOC_ENUM_FMT, &fmtdesc) < 0) { break; } - mp_msg(MSGT_TV, MSGL_V, " Format %-6s (%2d bits, %s): %s\n", + mp_msg(MSGT_TV, MSGL_V, " Format %-6s (%2d bits, %s)\n", pixfmt2name(fmtdesc.pixelformat), pixfmt2depth(fmtdesc.pixelformat), - fmtdesc.description, vo_format_name(fcc_vl2mp(fmtdesc.pixelformat))); + fmtdesc.description); } mp_msg(MSGT_TV, MSGL_INFO, " Current format: %s\n", pixfmt2name(priv->format.fmt.pix.pixelformat)); 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