From f27f681f1b30478caafc24a0b63fb09a92f1ab2a Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 14 Feb 2021 11:29:22 +0000 Subject: [PATCH] improve pngsave compression for palette images set pngsave default filter to none for palette images, since they usually have low local correlation --- libvips/foreign/pngsave.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libvips/foreign/pngsave.c b/libvips/foreign/pngsave.c index 3ba85477..fcbdd112 100644 --- a/libvips/foreign/pngsave.c +++ b/libvips/foreign/pngsave.c @@ -136,6 +136,13 @@ vips_foreign_save_png_build( VipsObject *object ) if( !vips_object_argument_isset( object, "bitdepth" ) ) png->bitdepth = in->BandFmt == VIPS_FORMAT_UCHAR ? 8 : 16; + /* Filtering usually reduces the compression ratio for palette images, + * so default off. + */ + if( !vips_object_argument_isset( object, "filter" ) && + png->palette ) + png->filter = VIPS_FOREIGN_PNG_FILTER_NONE; + /* If this is a RGB or RGBA image and a low bit depth has been * requested, enable palettization. */ @@ -476,7 +483,8 @@ vips_foreign_save_png_buffer_init( VipsForeignSavePngBuffer *buffer ) * profile from the VIPS header will be attached. * * Use @filter to specify one or more filters (instead of adaptive filtering), - * see #VipsForeignPngFilter. + * see #VipsForeignPngFilter. @filter defaults to NONE for palette images, + * since they generally have very low local correlation. * * The image is automatically converted to RGB, RGBA, Monochrome or Mono + * alpha before saving. Images with more than one byte per band element are