From 4de99d9c0c1451db8a11c4f8173352e932844f14 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 6 Aug 2012 17:47:28 +0200 Subject: image_writer: allow specifying pixel formats for image writers --- image_writer.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/image_writer.c b/image_writer.c index 6501e2d8bd..3aca95d963 100644 --- a/image_writer.c +++ b/image_writer.c @@ -59,6 +59,7 @@ struct image_writer_ctx { struct img_writer { const char *file_ext; int (*write)(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp); + int *pixfmts; }; static int write_png(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp) @@ -207,7 +208,6 @@ int write_image(struct mp_image *image, const struct mp_csp_details *csp, const struct image_writer_opts *opts, const char *filename) { struct mp_image *allocated_image = NULL; - const int destfmt = IMGFMT_RGB24; struct image_writer_opts defs = image_writer_opts_defaults; bool is_anamorphic = image->w != image->width || image->h != image->height; @@ -215,7 +215,18 @@ int write_image(struct mp_image *image, const struct mp_csp_details *csp, opts = &defs; const struct img_writer *writer = get_writer(opts); - struct image_writer_ctx ctx = { opts }; + struct image_writer_ctx ctx = { opts, writer }; + int destfmt = IMGFMT_RGB24; + + if (writer->pixfmts) { + destfmt = writer->pixfmts[0]; // default to first pixel format + for (int *fmt = writer->pixfmts; *fmt; fmt++) { + if (*fmt == image->imgfmt) { + destfmt = *fmt; + break; + } + } + } if (image->imgfmt != destfmt || is_anamorphic) { struct mp_image *dst = alloc_mpi(image->w, image->h, destfmt); -- cgit v1.2.3