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 7, 2024
1 parent 9953a19 commit 1ba3be8
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 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
if (wtiff->Q >= 90)
/* Set compression quality.
*/
jpeg_set_quality(cinfo, wtiff->Q, TRUE);

if (image->Bands != 3 ||
wtiff->Q >= 90)
/* No chroma subsample.
*/
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 {
/* Use 4:2:0 subsampling, we must set this explicitly, since some
* jpeg libraries do not enable chroma subsample by default.
*/
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 1ba3be8

Please sign in to comment.