Skip to content

Commit 8effeb9

Browse files
authored
heifsave: improve alpha channel detection (#4394)
1 parent 68d859f commit 8effeb9

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- improve performance of vips_shrink() [kleisauke]
1212
- svgload: add support for custom CSS via stylesheet option [lovell]
1313
- heifload: `unlimited` flag removes all limits (requires libheif 1.19.0+) [lovell]
14+
- heifsave: improve alpha channel detection [lovell]
1415

1516
8.16.1
1617

libvips/foreign/heifsave.c

+5-14
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ vips_foreign_save_heif_write_page(VipsForeignSaveHeif *heif, int page)
289289
#endif /*HAVE_HEIF_COLOR_PROFILE*/
290290

291291
options = heif_encoding_options_alloc();
292-
if (vips_image_hasalpha(save->ready))
293-
options->save_alpha_channel = 1;
292+
options->save_alpha_channel = save->ready->Bands > 3;
294293

295294
#ifdef HAVE_HEIF_ENCODING_OPTIONS_OUTPUT_NCLX_PROFILE
296295
/* Matrix coefficients have to be identity (CICP x/y/0) in lossless
@@ -517,6 +516,7 @@ vips_foreign_save_heif_build(VipsObject *object)
517516
char *chroma;
518517
const struct heif_encoder_descriptor *out_encoder;
519518
const struct heif_encoder_parameter *const *param;
519+
gboolean has_alpha;
520520

521521
if (VIPS_OBJECT_CLASS(vips_foreign_save_heif_parent_class)-> build(object))
522522
return -1;
@@ -677,34 +677,25 @@ vips_foreign_save_heif_build(VipsObject *object)
677677
heif->page_width = save->ready->Xsize;
678678
heif->page_height = vips_image_get_page_height(save->ready);
679679
heif->n_pages = save->ready->Ysize / heif->page_height;
680+
has_alpha = save->ready->Bands > 3;
680681

681682
if (heif->page_width > 16384 || heif->page_height > 16384) {
682683
vips_error("heifsave", _("image too large"));
683684
return -1;
684685
}
685686

686-
/* Reject multiband images.
687-
*/
688-
if (save->ready->Type == VIPS_INTERPRETATION_MULTIBAND) {
689-
vips_error("heifsave", _("Unsupported interpretation: %s"),
690-
vips_enum_nick(VIPS_TYPE_INTERPRETATION,
691-
save->ready->Type));
692-
return -1;
693-
}
694-
695687
/* Make a heif image the size of a page. We send sink_disc() output
696688
* here and write a frame each time it fills.
697689
*/
698690
#ifdef DEBUG
699691
printf("vips_foreign_save_heif_build:\n");
700692
printf("\twidth = %d\n", heif->page_width);
701693
printf("\theight = %d\n", heif->page_height);
702-
printf("\talpha = %d\n", vips_image_hasalpha(save->ready));
694+
printf("\talpha = %d\n", has_alpha);
703695
#endif /*DEBUG*/
704696
error = heif_image_create(heif->page_width, heif->page_height,
705697
heif_colorspace_RGB,
706-
vips__heif_chroma(heif->bitdepth,
707-
vips_image_hasalpha(save->ready)),
698+
vips__heif_chroma(heif->bitdepth, has_alpha),
708699
&heif->img);
709700
if (error.code) {
710701
vips__heif_error(&error);

0 commit comments

Comments
 (0)