diff options
author | wm4 <wm4@nowhere> | 2019-11-02 01:02:54 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2019-11-02 01:02:54 +0100 |
commit | c3cee4b9ecd2a13a35651b81158d1577c899daa1 (patch) | |
tree | afd25dc2eb68ed6ef4bcb70fd8afea5cf07ab74a /video | |
parent | bdd1e1e7ec20bc8ff7a5486d589645d9988c7c6c (diff) | |
download | mpv-c3cee4b9ecd2a13a35651b81158d1577c899daa1.tar.bz2 mpv-c3cee4b9ecd2a13a35651b81158d1577c899daa1.tar.xz |
img_format: add function to find image format by layout
This is similar to mp_imgfmt_find(), but probably a bit saner. Used by
the next commit. The previous commit is required to map this
unambiguously between all formats.
Diffstat (limited to 'video')
-rw-r--r-- | video/img_format.c | 35 | ||||
-rw-r--r-- | video/img_format.h | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/video/img_format.c b/video/img_format.c index 524fc4eea3..80838a82a2 100644 --- a/video/img_format.c +++ b/video/img_format.c @@ -463,6 +463,41 @@ bool mp_get_regular_imgfmt(struct mp_regular_imgfmt *dst, int imgfmt) return true; } +static bool regular_imgfmt_equals(struct mp_regular_imgfmt *a, + struct mp_regular_imgfmt *b) +{ + if (a->component_type != b->component_type || + a->component_size != b->component_size || + a->num_planes != b->num_planes || + a->component_pad != b->component_pad || + a->forced_csp != b->forced_csp || + a->chroma_w != b->chroma_w || + a->chroma_h != b->chroma_h) + return false; + + for (int n = 0; n < a->num_planes; n++) { + int num_comps = a->planes[n].num_components; + if (num_comps != b->planes[n].num_components) + return false; + for (int i = 0; i < num_comps; i++) { + if (a->planes[n].components[i] != b->planes[n].components[i]) + return false; + } + } + + return true; +} + +// Find a format that matches this one exactly. +int mp_find_regular_imgfmt(struct mp_regular_imgfmt *src) +{ + for (int n = IMGFMT_START + 1; n < IMGFMT_END; n++) { + struct mp_regular_imgfmt f; + if (mp_get_regular_imgfmt(&f, n) && regular_imgfmt_equals(src, &f)) + return n; + } + return 0; +} // Find a format that has the given flags set with the following configuration. int mp_imgfmt_find(int xs, int ys, int planes, int component_bits, int flags) diff --git a/video/img_format.h b/video/img_format.h index 5f097d43ff..67de42f3f4 100644 --- a/video/img_format.h +++ b/video/img_format.h @@ -150,6 +150,7 @@ struct mp_regular_imgfmt { }; bool mp_get_regular_imgfmt(struct mp_regular_imgfmt *dst, int imgfmt); +int mp_find_regular_imgfmt(struct mp_regular_imgfmt *src); enum mp_imgfmt { IMGFMT_NONE = 0, |