video: add image format test program

This commit is contained in:
wm4 2014-11-04 23:52:29 +01:00
parent 7333bc6536
commit 5fc29e459f
1 changed files with 63 additions and 0 deletions

View File

@ -260,3 +260,66 @@ int mp_imgfmt_find_yuv_planar(int xs, int ys, int planes, int component_bits)
}
return 0;
}
#if 0
#include <libavutil/frame.h>
#include "sws_utils.h"
int main(int argc, char **argv)
{
const AVPixFmtDescriptor *avd = av_pix_fmt_desc_next(NULL);
for (; avd; avd = av_pix_fmt_desc_next(avd)) {
enum AVPixelFormat fmt = av_pix_fmt_desc_get_id(avd);
if (fmt == AV_PIX_FMT_YUVJ420P || fmt == AV_PIX_FMT_YUVJ422P ||
fmt == AV_PIX_FMT_YUVJ444P || fmt == AV_PIX_FMT_YUVJ440P)
continue;
printf("%s (%d)", avd->name, (int)fmt);
int mpfmt = pixfmt2imgfmt(fmt);
bool generic = mpfmt >= IMGFMT_AVPIXFMT_START &&
mpfmt < IMGFMT_AVPIXFMT_END;
printf(" mp=%d%s\n ", mpfmt, generic ? " [GENERIC]" : "");
struct mp_imgfmt_desc d = mp_imgfmt_get_desc(mpfmt);
if (d.id)
assert(d.avformat == fmt);
#define FLAG(t, c) if (d.flags & (t)) printf("[%s]", c);
FLAG(MP_IMGFLAG_BYTE_ALIGNED, "BA")
FLAG(MP_IMGFLAG_ALPHA, "a")
FLAG(MP_IMGFLAG_PLANAR, "P")
FLAG(MP_IMGFLAG_YUV_P, "YUVP")
FLAG(MP_IMGFLAG_YUV, "yuv")
FLAG(MP_IMGFLAG_RGB, "rgb")
FLAG(MP_IMGFLAG_XYZ, "xyz")
FLAG(MP_IMGFLAG_LE, "le")
FLAG(MP_IMGFLAG_BE, "be")
FLAG(MP_IMGFLAG_PAL, "pal")
FLAG(MP_IMGFLAG_HWACCEL, "hw")
printf("\n");
printf(" planes=%d, chroma=%d:%d align=%d:%d bits=%d\n", d.num_planes,
d.chroma_xs, d.chroma_ys, d.align_x, d.align_y, d.plane_bits);
printf(" {");
for (int n = 0; n < MP_MAX_PLANES; n++)
printf("%d/%d/[%d:%d] ", d.bytes[n], d.bpp[n], d.xs[n], d.ys[n]);
printf("}\n");
if (mpfmt && !(d.flags & MP_IMGFLAG_HWACCEL) && fmt != AV_PIX_FMT_UYYVYY411)
{
AVFrame *fr = av_frame_alloc();
fr->format = fmt;
fr->width = 128;
fr->height = 128;
int err = av_frame_get_buffer(fr, SWS_MIN_BYTE_ALIGN);
assert(err >= 0);
struct mp_image *mpi = mp_image_alloc(mpfmt, fr->width, fr->height);
assert(mpi);
// A rather fuzzy test, which might fail even if there's no bug.
for (int n = 0; n < 4; n++) {
assert(!!mpi->planes[n] == !!fr->data[n]);
assert(mpi->stride[n] == fr->linesize[n]);
}
talloc_free(mpi);
av_frame_free(&fr);
}
}
}
#endif