[vlc-devel] [PATCH] Added fallback support for set_alpha_mode for libpng (fallback required for libpng < 1.5.4)
Diogo Silva
dbtdsilva at gmail.com
Sat Apr 15 06:42:12 CEST 2017
It was required to add fallback support, png_set_alpha_mode was only added
in version 1.5.4.
The fallback was implemented by converting the pixels with any alpha by a
background color, black. The color is the same used for representing
alpha when it exists in VLC.
---
modules/codec/png.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/modules/codec/png.c b/modules/codec/png.c
index 75f3ad440b..c4b6898cfa 100644
--- a/modules/codec/png.c
+++ b/modules/codec/png.c
@@ -261,8 +261,6 @@ static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
if( i_color_type == PNG_COLOR_TYPE_GRAY ||
i_color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
png_set_gray_to_rgb( p_png );
- if( i_color_type & PNG_COLOR_MASK_ALPHA )
- png_set_alpha_mode( p_png, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR );
/* Strip to 8 bits per channel */
if( i_bit_depth == 16 ) png_set_strip_16( p_png );
@@ -276,6 +274,18 @@ static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
p_dec->fmt_out.i_codec = VLC_CODEC_RGB24;
}
+ if ( i_color_type & PNG_COLOR_MASK_ALPHA ) {
+#if PNG_LIBPNG_VER >= 10504
+ png_set_alpha_mode( p_png, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR );
+#else
+ /* Fallback - Older version does not allow to specify alpha encoding */
+ /* png_color_16 - index (unused), red, green, blue, gray (unused) */
+ png_color_16 black_bg = { 0xf, 0x00, 0x00, 0x00, 0xff };
+ png_set_background( p_png, &black_bg,
+ PNG_BACKGROUND_GAMMA_SCREEN, 0.0, 1.0 );
+ p_dec->fmt_out.i_codec = VLC_CODEC_RGB24;
+#endif
+ }
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
goto error;
--
2.12.2
More information about the vlc-devel
mailing list