Skip to content

Commit

Permalink
jpegsave: sync with tiffsave
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Sep 21, 2024
1 parent 4a1d854 commit d6f971f
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions libvips/foreign/vips2jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,29 +667,19 @@ set_cinfo(struct jpeg_compress_struct *cinfo,
if (progressive)
jpeg_simple_progression(cinfo);

if (in->Bands != 3 ||
subsample_mode == VIPS_FOREIGN_SUBSAMPLE_OFF ||
(subsample_mode == VIPS_FOREIGN_SUBSAMPLE_AUTO &&
qfac >= 90))
/* No chroma subsample.
*/
for (int i = 0; i < in->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.
*/
/* We must set chroma subsampling explicitly since some libjpegs do not
* enable this by default.
*/
for (int i = 0; i < in->Bands; i++) {
cinfo->comp_info[i].h_samp_factor = 1;
cinfo->comp_info[i].v_samp_factor = 1;
}
if (in->Bands == 3 &&
(subsample_mode == VIPS_FOREIGN_SUBSAMPLE_ON ||
(subsample_mode == VIPS_FOREIGN_SUBSAMPLE_AUTO &&
qfac < 90))) {
cinfo->comp_info[0].h_samp_factor = 2;
cinfo->comp_info[0].v_samp_factor = 2;

/* Rest should have sampling factors 1,1.
*/
for (int i = 1; i < in->Bands; i++) {
cinfo->comp_info[i].h_samp_factor = 1;
cinfo->comp_info[i].v_samp_factor = 1;
}
}

/* Only write the JFIF headers if we have no EXIF.
Expand Down

0 comments on commit d6f971f

Please sign in to comment.