@@ -640,9 +640,8 @@ vips_thumbnail_build( VipsObject *object )
640
640
*/
641
641
VipsInterpretation input_interpretation ;
642
642
643
- /* TRUE if we've premultiplied and need to unpremultiply.
643
+ /* The format we need to revert to after unpremultiply.
644
644
*/
645
- gboolean have_premultiplied ;
646
645
VipsBandFormat unpremultiplied_format ;
647
646
648
647
#ifdef DEBUG
@@ -778,19 +777,19 @@ vips_thumbnail_build( VipsObject *object )
778
777
vshrink = (double ) in -> Ysize / target_image_height ;
779
778
}
780
779
780
+ /* vips_premultiply() makes a float image, so when we unpremultiply
781
+ * below we must cast back to the original format. Use NOTSET to
782
+ * meran no pre/unmultiply.
783
+ */
784
+ unpremultiplied_format = VIPS_FORMAT_NOTSET ;
785
+
781
786
/* If there's an alpha, we have to premultiply before shrinking. See
782
787
* https://github.com/libvips/libvips/issues/291
783
788
*/
784
- have_premultiplied = FALSE;
785
789
if ( vips_image_hasalpha ( in ) &&
786
790
hshrink != 1.0 &&
787
791
vshrink != 1.0 ) {
788
- /* vips_premultiply() makes a float image. When we
789
- * vips_unpremultiply() below, we need to cast back to the
790
- * pre-premultiplied format.
791
- */
792
792
g_info ( "premultiplying alpha" );
793
- have_premultiplied = TRUE;
794
793
unpremultiplied_format = in -> BandFmt ;
795
794
796
795
if ( vips_premultiply ( in , & t [3 ], NULL ) )
@@ -804,7 +803,7 @@ vips_thumbnail_build( VipsObject *object )
804
803
return ( -1 );
805
804
in = t [4 ];
806
805
807
- if ( have_premultiplied ) {
806
+ if ( unpremultiplied_format != VIPS_FORMAT_NOTSET ) {
808
807
g_info ( "unpremultiplying alpha" );
809
808
if ( vips_unpremultiply ( in , & t [5 ], NULL ) ||
810
809
vips_cast ( t [5 ], & t [6 ], unpremultiplied_format , NULL ) )
0 commit comments