summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-06 17:51:04 +0200
committerwm4 <wm4@nowhere>2012-08-06 17:51:04 +0200
commit927c58854fecc5e1dbbecb983fb87870e8433c8a (patch)
tree40a8bdd620eb73a8aec6f9c6bf34e6ecb9c98b5b
parent0a0925be824fb65a1f76350d8a1a9db04cf05dee (diff)
downloadmpv-927c58854fecc5e1dbbecb983fb87870e8433c8a.tar.bz2
mpv-927c58854fecc5e1dbbecb983fb87870e8433c8a.tar.xz
image_writer: support all JPEG specific options vo_jpeg supports
Most of these are useless or probably even dangerous. Support them anyway, because it's easy, and we want to replace vo_jpeg without any disadvantages.
-rw-r--r--image_writer.c28
-rw-r--r--image_writer.h5
2 files changed, 32 insertions, 1 deletions
diff --git a/image_writer.c b/image_writer.c
index 5987d22f99..af1002164e 100644
--- a/image_writer.c
+++ b/image_writer.c
@@ -49,6 +49,11 @@ const struct image_writer_opts image_writer_opts_defaults = {
.filetype = "png",
.png_compression = 7,
.jpeg_quality = 85,
+ .jpeg_optimize = 100,
+ .jpeg_smooth = 0,
+ .jpeg_dpi = 72,
+ .jpeg_progressive = 0,
+ .jpeg_baseline = 1,
};
#undef OPT_BASE_STRUCT
@@ -57,6 +62,11 @@ const struct image_writer_opts image_writer_opts_defaults = {
const struct m_sub_options image_writer_conf = {
.opts = (m_option_t[]) {
OPT_INTRANGE("jpeg-quality", jpeg_quality, 0, 0, 100),
+ OPT_INTRANGE("jpeg-optimize", jpeg_optimize, 0, 0, 100),
+ OPT_INTRANGE("jpeg-smooth", jpeg_smooth, 0, 0, 100),
+ OPT_INTRANGE("jpeg-dpi", jpeg_dpi, M_OPT_MIN, 1, 99999),
+ OPT_MAKE_FLAGS("jpeg-progressive", jpeg_progressive, 0),
+ OPT_MAKE_FLAGS("jpeg-baseline", jpeg_baseline, 0),
OPT_INTRANGE("png-compression", png_compression, 0, 0, 9),
OPT_STRING("filetype", filetype, 0),
{0},
@@ -168,8 +178,24 @@ static int write_jpeg(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
+ cinfo.write_JFIF_header = TRUE;
+ cinfo.JFIF_major_version = 1;
+ cinfo.JFIF_minor_version = 2;
+ cinfo.density_unit = 1; /* 0=unknown, 1=dpi, 2=dpcm */
+ /* Image DPI is determined by Y_density, so we leave that at
+ jpeg_dpi if possible and crunch X_density instead (PAR > 1) */
+ // NOTE: write_image never passes anamorphic images currently
+ cinfo.X_density = ctx->opts->jpeg_dpi*image->width/image->w;
+ cinfo.Y_density = ctx->opts->jpeg_dpi*image->height/image->h;
+ cinfo.write_Adobe_marker = TRUE;
+
jpeg_set_defaults(&cinfo);
- jpeg_set_quality(&cinfo, ctx->opts->jpeg_quality, 1);
+ jpeg_set_quality(&cinfo, ctx->opts->jpeg_quality, ctx->opts->jpeg_baseline);
+ cinfo.optimize_coding = ctx->opts->jpeg_optimize;
+ cinfo.smoothing_factor = ctx->opts->jpeg_smooth;
+
+ if (ctx->opts->jpeg_progressive)
+ jpeg_simple_progression(&cinfo);
jpeg_start_compress(&cinfo, TRUE);
diff --git a/image_writer.h b/image_writer.h
index 1253bb5d8b..fb230684d2 100644
--- a/image_writer.h
+++ b/image_writer.h
@@ -22,6 +22,11 @@ struct image_writer_opts {
char *filetype;
int png_compression;
int jpeg_quality;
+ int jpeg_optimize;
+ int jpeg_smooth;
+ int jpeg_dpi;
+ int jpeg_progressive;
+ int jpeg_baseline;
};
extern const struct image_writer_opts image_writer_opts_defaults;