Rename pngsave colors/colours, quantize/quantise

This commit is contained in:
Felix Bünemann 2018-06-19 21:32:44 +02:00
parent c63d7f7373
commit 1e68b3a486
5 changed files with 46 additions and 46 deletions

View File

@ -1393,7 +1393,7 @@ support webp metadata: $with_libwebpmux
text rendering with pangoft2: $with_pangoft2 text rendering with pangoft2: $with_pangoft2
file import/export with libpng: $with_png file import/export with libpng: $with_png
(requires libpng-1.2.9 or later) (requires libpng-1.2.9 or later)
support 8bpp PNG quantization: $with_imagequant support 8bpp PNG quantisation: $with_imagequant
file import/export with libtiff: $with_tiff file import/export with libtiff: $with_tiff
file import/export with giflib: $with_giflib file import/export with giflib: $with_giflib
file import/export with libjpeg: $with_jpeg file import/export with libjpeg: $with_jpeg

View File

@ -197,11 +197,11 @@ int vips__png_header_buffer( const void *buffer, size_t length, VipsImage *out )
int vips__png_write( VipsImage *in, const char *filename, int vips__png_write( VipsImage *in, const char *filename,
int compress, int interlace, const char *profile, int compress, int interlace, const char *profile,
VipsForeignPngFilter filter, gboolean strip, int colors, int Q, double dither ); VipsForeignPngFilter filter, gboolean strip, int colours, int Q, double dither );
int vips__png_write_buf( VipsImage *in, int vips__png_write_buf( VipsImage *in,
void **obuf, size_t *olen, int compression, int interlace, void **obuf, size_t *olen, int compression, int interlace,
const char *profile, VipsForeignPngFilter filter, gboolean strip, const char *profile, VipsForeignPngFilter filter, gboolean strip,
int colors, int Q, double dither ); int colours, int Q, double dither );
/* Map WEBP metadata names to vips names. /* Map WEBP metadata names to vips names.
*/ */

View File

@ -60,7 +60,7 @@ typedef struct _VipsForeignSavePng {
gboolean interlace; gboolean interlace;
char *profile; char *profile;
VipsForeignPngFilter filter; VipsForeignPngFilter filter;
int colors; int colours;
int Q; int Q;
double dither; double dither;
} VipsForeignSavePng; } VipsForeignSavePng;
@ -136,16 +136,16 @@ vips_foreign_save_png_class_init( VipsForeignSavePngClass *class )
VIPS_TYPE_FOREIGN_PNG_FILTER, VIPS_TYPE_FOREIGN_PNG_FILTER,
VIPS_FOREIGN_PNG_FILTER_ALL ); VIPS_FOREIGN_PNG_FILTER_ALL );
VIPS_ARG_INT( class, "colors", 13, VIPS_ARG_INT( class, "colours", 13,
_( "Colors" ), _( "Colours" ),
_( "Number of palette entries" ), _( "Max number of palette colours" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSavePng, colors ), G_STRUCT_OFFSET( VipsForeignSavePng, colours ),
2, 256, 256 ); 2, 256, 256 );
VIPS_ARG_INT( class, "Q", 14, VIPS_ARG_INT( class, "Q", 14,
_( "Quality" ), _( "Quality" ),
_( "Quantization quality" ), _( "Quantisation quality" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSavePng, Q ), G_STRUCT_OFFSET( VipsForeignSavePng, Q ),
0, 100, 100 ); 0, 100, 100 );
@ -164,7 +164,7 @@ vips_foreign_save_png_init( VipsForeignSavePng *png )
{ {
png->compression = 6; png->compression = 6;
png->filter = VIPS_FOREIGN_PNG_FILTER_ALL; png->filter = VIPS_FOREIGN_PNG_FILTER_ALL;
png->colors = 0; png->colours = 0;
png->Q = 100; png->Q = 100;
png->dither = 1.0; png->dither = 1.0;
} }
@ -193,7 +193,7 @@ vips_foreign_save_png_file_build( VipsObject *object )
if( vips__png_write( save->ready, if( vips__png_write( save->ready,
png_file->filename, png->compression, png->interlace, png_file->filename, png->compression, png->interlace,
png->profile, png->filter, save->strip, png->colors, png->Q, png->profile, png->filter, save->strip, png->colours, png->Q,
png->dither ) ) png->dither ) )
return( -1 ); return( -1 );
@ -253,7 +253,7 @@ vips_foreign_save_png_buffer_build( VipsObject *object )
if( vips__png_write_buf( save->ready, &obuf, &olen, if( vips__png_write_buf( save->ready, &obuf, &olen,
png->compression, png->interlace, png->profile, png->filter, png->compression, png->interlace, png->profile, png->filter,
save->strip, png->colors, png->Q, png->dither ) ) save->strip, png->colours, png->Q, png->dither ) )
return( -1 ); return( -1 );
/* vips__png_write_buf() makes a buffer that needs g_free(), not /* vips__png_write_buf() makes a buffer that needs g_free(), not
@ -306,8 +306,8 @@ vips_foreign_save_png_buffer_init( VipsForeignSavePngBuffer *buffer )
* * @interlace: interlace image * * @interlace: interlace image
* * @profile: ICC profile to embed * * @profile: ICC profile to embed
* * @filter: #VipsForeignPngFilter row filter flag(s) * * @filter: #VipsForeignPngFilter row filter flag(s)
* * @colors: enable 8bpp quantization with max n colors * * @colours: enable 8bpp quantisation with max n colours
* * @Q: quality for 8bpp quantization (does not exceed @colors) * * @Q: quality for 8bpp quantisation (does not exceed @colours)
* * @dither: amount of dithering for 8bpp quantization * * @dither: amount of dithering for 8bpp quantization
* *
* Write a VIPS image to a file as PNG. * Write a VIPS image to a file as PNG.
@ -335,8 +335,8 @@ vips_foreign_save_png_buffer_init( VipsForeignSavePngBuffer *buffer )
* alpha before saving. Images with more than one byte per band element are * alpha before saving. Images with more than one byte per band element are
* saved as 16-bit PNG, others are saved as 8-bit PNG. * saved as 16-bit PNG, others are saved as 8-bit PNG.
* *
* If @colors is given, it limits the maximum number of colors in the image * If @colours is given, it limits the maximum number of colours in the image
* and the source image will be quantized down to an 8-Bit one band indexed * and the source image will be quantised down to an 8-Bit one band indexed
* image with palette based alpha transparency. Similar to JPEG the quality * image with palette based alpha transparency. Similar to JPEG the quality
* can be controlled with the @Q parameter and the amount of Floyd-Steinberg * can be controlled with the @Q parameter and the amount of Floyd-Steinberg
* dithering is set with @dither. * dithering is set with @dither.

View File

@ -883,8 +883,8 @@ write_png_block( VipsRegion *region, VipsRect *area, void *a )
#ifdef HAVE_IMAGEQUANT #ifdef HAVE_IMAGEQUANT
static int static int
quantize_image( VipsImage *in, VipsImage *out, VipsImage *palette_out, quantise_image( VipsImage *in, VipsImage *out, VipsImage *palette_out,
int colors, int Q, double dither ) int colours, int Q, double dither )
{ {
/* Ensure input is sRGB. */ /* Ensure input is sRGB. */
if( in->Type != VIPS_INTERPRETATION_sRGB) { if( in->Type != VIPS_INTERPRETATION_sRGB) {
@ -909,51 +909,51 @@ quantize_image( VipsImage *in, VipsImage *out, VipsImage *palette_out,
in = memory; in = memory;
liq_attr *attr = liq_attr_create(); liq_attr *attr = liq_attr_create();
liq_set_max_colors( attr, colors ); liq_set_max_colors( attr, colours );
liq_set_quality( attr, 0, Q ); liq_set_quality( attr, 0, Q );
liq_image *input_image = liq_image_create_rgba( attr, liq_image *input_image = liq_image_create_rgba( attr,
VIPS_IMAGE_ADDR( in, 0, 0 ), in->Xsize, in->Ysize, 0 ); VIPS_IMAGE_ADDR( in, 0, 0 ), in->Xsize, in->Ysize, 0 );
liq_result *quantization_result; liq_result *quantisation_result;
if ( liq_image_quantize( input_image, attr, &quantization_result ) ) { if ( liq_image_quantize( input_image, attr, &quantisation_result ) ) {
liq_result_destroy( quantization_result ); liq_result_destroy( quantisation_result );
liq_image_destroy( input_image ); liq_image_destroy( input_image );
liq_attr_destroy( attr ); liq_attr_destroy( attr );
VIPS_UNREF( memory ); VIPS_UNREF( memory );
return( -1 ); return( -1 );
} }
liq_set_dithering_level( quantization_result, (float) dither ); liq_set_dithering_level( quantisation_result, (float) dither );
vips_image_init_fields( out, in->Xsize, in->Ysize, 1, VIPS_FORMAT_UCHAR, vips_image_init_fields( out, in->Xsize, in->Ysize, 1, VIPS_FORMAT_UCHAR,
VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W, 1.0, 1.0 ); VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W, 1.0, 1.0 );
if( vips_image_write_prepare( out ) ) { if( vips_image_write_prepare( out ) ) {
liq_result_destroy( quantization_result ); liq_result_destroy( quantisation_result );
liq_image_destroy( input_image ); liq_image_destroy( input_image );
liq_attr_destroy( attr ); liq_attr_destroy( attr );
VIPS_UNREF( memory ); VIPS_UNREF( memory );
return( -1 ); return( -1 );
} }
if( liq_write_remapped_image( quantization_result, input_image, if( liq_write_remapped_image( quantisation_result, input_image,
VIPS_IMAGE_ADDR( out, 0, 0 ), VIPS_IMAGE_N_PELS( out ) ) ) { VIPS_IMAGE_ADDR( out, 0, 0 ), VIPS_IMAGE_N_PELS( out ) ) ) {
liq_result_destroy( quantization_result ); liq_result_destroy( quantisation_result );
liq_image_destroy( input_image ); liq_image_destroy( input_image );
liq_attr_destroy( attr ); liq_attr_destroy( attr );
VIPS_UNREF( memory ); VIPS_UNREF( memory );
return( -1 ); return( -1 );
} }
const liq_palette *palette = liq_get_palette( quantization_result ); const liq_palette *palette = liq_get_palette( quantisation_result );
vips_image_init_fields( palette_out, palette->count, 1, 4, vips_image_init_fields( palette_out, palette->count, 1, 4,
VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB,
1.0, 1.0 ); 1.0, 1.0 );
if( vips_image_write_prepare( palette_out ) ) { if( vips_image_write_prepare( palette_out ) ) {
liq_result_destroy( quantization_result ); liq_result_destroy( quantisation_result );
liq_image_destroy( input_image ); liq_image_destroy( input_image );
liq_attr_destroy( attr ); liq_attr_destroy( attr );
VIPS_UNREF( memory ); VIPS_UNREF( memory );
@ -969,7 +969,7 @@ quantize_image( VipsImage *in, VipsImage *out, VipsImage *palette_out,
p[3] = palette->entries[i].a; p[3] = palette->entries[i].a;
} }
liq_result_destroy( quantization_result ); liq_result_destroy( quantisation_result );
liq_image_destroy( input_image ); liq_image_destroy( input_image );
liq_attr_destroy( attr ); liq_attr_destroy( attr );
VIPS_UNREF( memory ); VIPS_UNREF( memory );
@ -983,7 +983,7 @@ quantize_image( VipsImage *in, VipsImage *out, VipsImage *palette_out,
static int static int
write_vips( Write *write, write_vips( Write *write,
int compress, int interlace, const char *profile, int compress, int interlace, const char *profile,
VipsForeignPngFilter filter, gboolean strip, int colors, int Q, VipsForeignPngFilter filter, gboolean strip, int colours, int Q,
double dither ) double dither )
{ {
VipsImage *in = write->in; VipsImage *in = write->in;
@ -1045,16 +1045,16 @@ write_vips( Write *write,
} }
#ifdef HAVE_IMAGEQUANT #ifdef HAVE_IMAGEQUANT
/* Enable image quantization to paletted 8bpp PNG if colors is set. /* Enable image quantisation to paletted 8bpp PNG if colours is set.
*/ */
if( colors ) { if( colours ) {
g_assert( colors >= 2 && colors <= 256 ); g_assert( colours >= 2 && colours <= 256 );
bit_depth = 8; bit_depth = 8;
color_type = PNG_COLOR_TYPE_PALETTE; color_type = PNG_COLOR_TYPE_PALETTE;
} }
#else #else
if( colors ) if( colours )
g_warning( "%s", _( "ignoring colors" ) ); g_warning( "%s", _( "ignoring colours" ) );
#endif #endif
interlace_type = interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE; interlace_type = interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
@ -1110,14 +1110,14 @@ write_vips( Write *write,
} }
#ifdef HAVE_IMAGEQUANT #ifdef HAVE_IMAGEQUANT
if( colors ) { if( colours ) {
VipsImage *quantized = vips_image_new_memory(); VipsImage *quantised = vips_image_new_memory();
VipsImage *palette = vips_image_new_memory(); VipsImage *palette = vips_image_new_memory();
if( quantize_image( in, quantized, palette, colors, Q, if( quantise_image( in, quantised, palette, colours, Q,
dither ) ) { dither ) ) {
vips_error( "vips2png", vips_error( "vips2png",
"%s", _( "quantization failed" ) ); "%s", _( "quantisation failed" ) );
VIPS_UNREF( quantized ); VIPS_UNREF( quantised );
VIPS_UNREF( palette ); VIPS_UNREF( palette );
return( -1 ); return( -1 );
} }
@ -1164,7 +1164,7 @@ write_vips( Write *write,
VIPS_UNREF( palette ); VIPS_UNREF( palette );
VIPS_UNREF( write->memory ); VIPS_UNREF( write->memory );
write->memory = quantized; write->memory = quantised;
in = write->memory; in = write->memory;
} }
#endif #endif
@ -1202,7 +1202,7 @@ int
vips__png_write( VipsImage *in, const char *filename, vips__png_write( VipsImage *in, const char *filename,
int compress, int interlace, const char *profile, int compress, int interlace, const char *profile,
VipsForeignPngFilter filter, gboolean strip, VipsForeignPngFilter filter, gboolean strip,
int colors, int Q, double dither ) int colours, int Q, double dither )
{ {
Write *write; Write *write;
@ -1222,7 +1222,7 @@ vips__png_write( VipsImage *in, const char *filename,
/* Convert it! /* Convert it!
*/ */
if( write_vips( write, if( write_vips( write,
compress, interlace, profile, filter, strip, colors, Q, compress, interlace, profile, filter, strip, colours, Q,
dither ) ) { dither ) ) {
vips_error( "vips2png", vips_error( "vips2png",
_( "unable to write \"%s\"" ), filename ); _( "unable to write \"%s\"" ), filename );
@ -1251,7 +1251,7 @@ int
vips__png_write_buf( VipsImage *in, vips__png_write_buf( VipsImage *in,
void **obuf, size_t *olen, int compression, int interlace, void **obuf, size_t *olen, int compression, int interlace,
const char *profile, VipsForeignPngFilter filter, gboolean strip, const char *profile, VipsForeignPngFilter filter, gboolean strip,
int colors, int Q, double dither ) int colours, int Q, double dither )
{ {
Write *write; Write *write;
@ -1263,7 +1263,7 @@ vips__png_write_buf( VipsImage *in,
/* Convert it! /* Convert it!
*/ */
if( write_vips( write, if( write_vips( write,
compression, interlace, profile, filter, strip, colors, Q, compression, interlace, profile, filter, strip, colours, Q,
dither ) ) { dither ) ) {
vips_error( "vips2png", vips_error( "vips2png",
"%s", _( "unable to write to buffer" ) ); "%s", _( "unable to write to buffer" ) );

View File

@ -197,7 +197,7 @@ fi
if test_supported pngload; then if test_supported pngload; then
test_format $image png 0 test_format $image png 0
test_format $image png 0 [compression=9,interlace=1] test_format $image png 0 [compression=9,interlace=1]
test_format $image png 90 [colors=256,Q=100,dither=0,compression=9,interlace=1] test_format $image png 90 [colours=256,Q=100,dither=0,compression=9,interlace=1]
fi fi
if test_supported jpegload; then if test_supported jpegload; then
test_format $image jpg 90 test_format $image jpg 90