summaryrefslogtreecommitdiffstats
path: root/video/image_writer.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-21 19:40:33 +0100
committerwm4 <wm4@nowhere>2012-11-21 19:58:51 +0100
commit4b91861b6710e9f82618b58841e08986e965eb43 (patch)
tree88fc224a0f7b55531e04ccbea16fb904a0d11d72 /video/image_writer.c
parented01dfeff305b09f7027cb18b1f9283fb859a9c8 (diff)
downloadmpv-4b91861b6710e9f82618b58841e08986e965eb43.tar.bz2
mpv-4b91861b6710e9f82618b58841e08986e965eb43.tar.xz
video: fix bogus uses of mp_image.w/width
mp_image has this confusing distinction between the w/h and width/height fields. w/h are the actual width and height, while width/height have a very special meaning inside the video filter code: it's the actually allocated width, which is also used for stride padding. Screenshot related code abused the w/h fields to store the aspect corrected size. Some code confused the role of w/h and width/height. Fix these issues. For aspect corrected size, display_w/h are used, while width/height should never be used outside vf.c internals and related code. This also fixes an actual bug when taking screenshots of anamorphic video with vf_screenshot, as well as using vo_image with such videos.
Diffstat (limited to 'video/image_writer.c')
-rw-r--r--video/image_writer.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/video/image_writer.c b/video/image_writer.c
index 810c1598b6..570db961ca 100644
--- a/video/image_writer.c
+++ b/video/image_writer.c
@@ -102,8 +102,8 @@ static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
goto print_open_fail;
avctx->time_base = AV_TIME_BASE_Q;
- avctx->width = image->width;
- avctx->height = image->height;
+ avctx->width = image->w;
+ avctx->height = image->h;
avctx->pix_fmt = imgfmt2pixfmt(image->imgfmt);
if (ctx->writer->lavc_codec == CODEC_ID_PNG)
avctx->compression_level = ctx->opts->png_compression;
@@ -115,7 +115,7 @@ static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
goto error_exit;
}
- size_t outbuffer_size = image->width * image->height * 3 * 2;
+ size_t outbuffer_size = image->w * image->h * 3 * 2;
outbuffer = malloc(outbuffer_size);
if (!outbuffer)
goto error_exit;
@@ -173,8 +173,8 @@ static int write_jpeg(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, fp);
- cinfo.image_width = image->width;
- cinfo.image_height = image->height;
+ cinfo.image_width = image->w;
+ cinfo.image_height = image->h;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
@@ -182,11 +182,8 @@ static int write_jpeg(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
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.X_density = ctx->opts->jpeg_dpi;
+ cinfo.Y_density = ctx->opts->jpeg_dpi;
cinfo.write_Adobe_marker = TRUE;
jpeg_set_defaults(&cinfo);