summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-06 17:47:28 +0200
committerwm4 <wm4@nowhere>2012-08-06 17:47:28 +0200
commit4de99d9c0c1451db8a11c4f8173352e932844f14 (patch)
tree79a959ddafe333920e01d24a2199fc8c4b4db3bb
parente7da13ed86f4bdd11ae98104d21962fadc7e6aae (diff)
downloadmpv-4de99d9c0c1451db8a11c4f8173352e932844f14.tar.bz2
mpv-4de99d9c0c1451db8a11c4f8173352e932844f14.tar.xz
image_writer: allow specifying pixel formats for image writers
-rw-r--r--image_writer.c15
1 files 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);