Commit 641526d1 authored by Adrian Johnson's avatar Adrian Johnson

jpeg: set image parameters after jpeg_set_defaults()

so the resolution does not get overwritten by the defaults.

The libjpeg documentation for jpeg_set_defaults() states: "This
routine sets all JPEG parameters to reasonable defaults, using only
the input image's color space (field in_color_space, which must
already be set in cinfo)"

Bug 45224
parent f7356a88
......@@ -53,6 +53,10 @@ bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
// Initialize libjpeg
jpeg_create_compress(&cinfo);
// Set colorspace and initialise defaults
cinfo.in_color_space = colorMode; /* colorspace of input image */
jpeg_set_defaults(&cinfo);
// Set destination file
jpeg_stdio_dest(&cinfo, f);
......@@ -62,7 +66,6 @@ bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
cinfo.density_unit = 1; // dots per inch
cinfo.X_density = hDPI;
cinfo.Y_density = vDPI;
cinfo.in_color_space = colorMode; /* colorspace of input image */
/* # of color components per pixel */
switch (colorMode) {
case JCS_GRAYSCALE:
......@@ -77,7 +80,6 @@ bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
default:
return false;
}
jpeg_set_defaults(&cinfo);
if (cinfo.in_color_space == JCS_CMYK) {
jpeg_set_colorspace(&cinfo, JCS_YCCK);
cinfo.write_JFIF_header = TRUE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment