summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-10 17:38:54 +0100
committerwm4 <wm4@nowhere>2020-02-10 17:38:54 +0100
commita841fe9484c203ca3492d8a5f88f60f8534c853b (patch)
tree864986e4100aefe521ed496c8b9208595262496f
parentcca02e51efd9e1b1e6c9b6002ff51dc076d30b8b (diff)
downloadmpv-a841fe9484c203ca3492d8a5f88f60f8534c853b.tar.bz2
mpv-a841fe9484c203ca3492d8a5f88f60f8534c853b.tar.xz
img_format: add gray/alpha planar formats
The zimg wrapper "needs" these formats as intermediary when repacking the normal gray/alpha packed format. The packed format is used by the png decoder and encoder, and is thus interesting. Unfortunately, mpv-only formats are a mess right now, because all the existing code is focused around using the FFmpeg metadata for pixel formats. This should be improved, but not now, so make the mess worse. This commit doesn't add support for it to the zimg wrapper yet.
-rw-r--r--test/ref/img_formats.txt14
-rw-r--r--video/img_format.c72
-rw-r--r--video/img_format.h4
3 files changed, 88 insertions, 2 deletions
diff --git a/test/ref/img_formats.txt b/test/ref/img_formats.txt
index f73b83bdd5..73b0efc91b 100644
--- a/test/ref/img_formats.txt
+++ b/test/ref/img_formats.txt
@@ -1039,6 +1039,20 @@ ya8: [GENERIC] ctype=uint
AVD: name=ya8 chroma=0:0 flags=0x80 [alpha]
0: p=0 st=2 o=0 sh=0 d=8
1: p=0 st=2 o=1 sh=0 d=8
+yap16: ctype=uint
+ Legacy desc: [ba][yuvp][yuv][le]
+ planes=2, chroma=0:0 align=1:1 bits=16 cbits=16
+ {2/16/[0:0] 2/16/[0:0] 0/0/[0:0] 0/0/[0:0] }
+ Regular: planes=2 compbytes=2 bitpad=0 chroma=1x1 ctype=uint
+ 0: {1}
+ 1: {4}
+yap8: ctype=uint
+ Legacy desc: [ba][yuvp][yuv][le]
+ planes=2, chroma=0:0 align=1:1 bits=8 cbits=8
+ {1/8/[0:0] 1/8/[0:0] 0/0/[0:0] 0/0/[0:0] }
+ Regular: planes=2 compbytes=1 bitpad=0 chroma=1x1 ctype=uint
+ 0: {1}
+ 1: {4}
yuv410p: [GENERIC] ctype=uint
Legacy desc: [ba][yuvp][yuv][le][be]
planes=3, chroma=2:2 align=4:4 bits=8 cbits=8
diff --git a/video/img_format.c b/video/img_format.c
index 57da094d39..a21ba6f9cb 100644
--- a/video/img_format.c
+++ b/video/img_format.c
@@ -37,6 +37,8 @@ static const struct mp_imgfmt_entry mp_imgfmt_list[] = {
// not in ffmpeg
{"vdpau_output", IMGFMT_VDPAU_OUTPUT},
{"rgb30", IMGFMT_RGB30},
+ {"yap8", IMGFMT_YAP8},
+ {"yap16", IMGFMT_YAP16},
// FFmpeg names have an annoying "_vld" suffix
{"videotoolbox", IMGFMT_VIDEOTOOLBOX},
{"vaapi", IMGFMT_VAAPI},
@@ -121,6 +123,34 @@ static struct mp_imgfmt_desc mp_only_imgfmt_desc(int mpfmt)
.plane_bits = 30,
.component_bits = 10,
};
+ case IMGFMT_YAP8:
+ return (struct mp_imgfmt_desc) {
+ .id = mpfmt,
+ .avformat = AV_PIX_FMT_NONE,
+ .flags = MP_IMGFLAG_BYTE_ALIGNED | MP_IMGFLAG_NE | MP_IMGFLAG_YUV |
+ MP_IMGFLAG_YUV_P,
+ .num_planes = 2,
+ .align_x = 1,
+ .align_y = 1,
+ .bytes = {1, 1},
+ .bpp = {8, 8},
+ .plane_bits = 8,
+ .component_bits = 8,
+ };
+ case IMGFMT_YAP16:
+ return (struct mp_imgfmt_desc) {
+ .id = mpfmt,
+ .avformat = AV_PIX_FMT_NONE,
+ .flags = MP_IMGFLAG_BYTE_ALIGNED | MP_IMGFLAG_NE | MP_IMGFLAG_YUV |
+ MP_IMGFLAG_YUV_P,
+ .num_planes = 2,
+ .align_x = 1,
+ .align_y = 1,
+ .bytes = {2, 2},
+ .bpp = {16, 16},
+ .plane_bits = 16,
+ .component_bits = 16,
+ };
}
return (struct mp_imgfmt_desc) {0};
}
@@ -336,7 +366,9 @@ enum mp_csp mp_imgfmt_get_forced_csp(int imgfmt)
enum mp_component_type mp_imgfmt_get_component_type(int imgfmt)
{
- if (imgfmt == IMGFMT_RGB30)
+ if (imgfmt == IMGFMT_RGB30 ||
+ imgfmt == IMGFMT_YAP8 ||
+ imgfmt == IMGFMT_YAP16)
return MP_COMPONENT_TYPE_UINT;
const AVPixFmtDescriptor *pixdesc =
@@ -363,6 +395,39 @@ static bool is_native_endian(const AVPixFmtDescriptor *pixdesc)
return pixdesc && (is_le != !!(pixdesc->flags & AV_PIX_FMT_FLAG_BE));
}
+static bool mp_only_regular_imgfmt(struct mp_regular_imgfmt *dst, int imgfmt)
+{
+ switch (imgfmt) {
+ case IMGFMT_YAP8:
+ *dst = (struct mp_regular_imgfmt) {
+ .component_type = MP_COMPONENT_TYPE_UINT,
+ .component_size = 1,
+ .num_planes = 2,
+ .planes = {
+ {.num_components = 1, .components = {1}},
+ {.num_components = 1, .components = {4}},
+ },
+ .chroma_w = 1,
+ .chroma_h = 1,
+ };
+ return true;
+ case IMGFMT_YAP16:
+ *dst = (struct mp_regular_imgfmt) {
+ .component_type = MP_COMPONENT_TYPE_UINT,
+ .component_size = 2,
+ .num_planes = 2,
+ .planes = {
+ {.num_components = 1, .components = {1}},
+ {.num_components = 1, .components = {4}},
+ },
+ .chroma_w = 1,
+ .chroma_h = 1,
+ };
+ return true;
+ }
+ return false;
+}
+
bool mp_get_regular_imgfmt(struct mp_regular_imgfmt *dst, int imgfmt)
{
struct mp_regular_imgfmt res = {0};
@@ -370,7 +435,10 @@ bool mp_get_regular_imgfmt(struct mp_regular_imgfmt *dst, int imgfmt)
const AVPixFmtDescriptor *pixdesc =
av_pix_fmt_desc_get(imgfmt2pixfmt(imgfmt));
- if (!pixdesc || (pixdesc->flags & AV_PIX_FMT_FLAG_BITSTREAM) ||
+ if (!pixdesc)
+ return mp_only_regular_imgfmt(dst, imgfmt);
+
+ if ((pixdesc->flags & AV_PIX_FMT_FLAG_BITSTREAM) ||
(pixdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) ||
(pixdesc->flags & AV_PIX_FMT_FLAG_PAL) ||
pixdesc->nb_components < 1 ||
diff --git a/video/img_format.h b/video/img_format.h
index 2df16ef095..61d9e02107 100644
--- a/video/img_format.h
+++ b/video/img_format.h
@@ -151,6 +151,10 @@ enum mp_imgfmt {
IMGFMT_Y8,
IMGFMT_Y16,
+ // Planar gray/alpha.
+ IMGFMT_YAP8,
+ IMGFMT_YAP16,
+
// Packed YUV formats (components are byte-accessed)
IMGFMT_UYVY, // U Y0 V Y1