Skip to content

Commit

Permalink
tiffsave: sync with jpegsave
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Apr 5, 2024
1 parent 50c041c commit a0a4b37
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions libvips/foreign/vips2tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,21 +682,32 @@ wtiff_compress_jpeg_header(Wtiff *wtiff,

jpeg_set_defaults(cinfo);

// disable chroma subsample for high Q
/* Set compression quality.
*/
jpeg_set_quality(cinfo, wtiff->Q, TRUE);

/* Disable chroma subsample for high Q.
*/
if (wtiff->Q >= 90)
for (int i = 0; i < image->Bands; i++) {
cinfo->comp_info[i].h_samp_factor = 1;
cinfo->comp_info[i].v_samp_factor = 1;
}
else if (image->Bands > 1) {
/* Use 4:2:0 subsampling, but only if the image has more than
* 1 band, since sampling factors are actually meaningless with
* greyscale JPEG files.
*/
cinfo->comp_info[0].h_samp_factor = 2;
cinfo->comp_info[0].v_samp_factor = 2;

// use RGB mode (no chroma subsample) for high Q RGB images
if (wtiff->Q >= 90 &&
image->Bands == 3)
jpeg_set_colorspace(cinfo, JCS_RGB);

/* Set compression quality. Must be called after setting params above.
*/
jpeg_set_quality(cinfo, wtiff->Q, TRUE);
/* Rest should have sampling factors 1,1.
*/
for (int i = 1; i < image->Bands; i++) {
cinfo->comp_info[i].h_samp_factor = 1;
cinfo->comp_info[i].v_samp_factor = 1;
}
}

// Avoid writing the JFIF APP0 marker.
cinfo->write_JFIF_header = FALSE;
Expand Down

0 comments on commit a0a4b37

Please sign in to comment.