From ccf894c738cbeb8252f6634c3df18f7370d4a31f Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 17 Dec 2017 11:54:24 +0100 Subject: [PATCH] Added quality option. --- libvips/foreign/magick2vips.c | 19 +++++++++++-------- libvips/foreign/magicksave.c | 23 ++++++++++++++++++++--- libvips/foreign/pforeign.h | 4 ++-- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/libvips/foreign/magick2vips.c b/libvips/foreign/magick2vips.c index f6d02ac2..90c02bed 100644 --- a/libvips/foreign/magick2vips.c +++ b/libvips/foreign/magick2vips.c @@ -1033,7 +1033,8 @@ write_close( VipsImage *im, Write *write ) } static Write * -write_new( VipsImage *im, const char *filename, const char *format ) +write_new( VipsImage *im, const char *filename, const char *format, + const size_t quality ) { Write *write; static int inited = 0; @@ -1107,9 +1108,7 @@ write_new( VipsImage *im, const char *filename, const char *format ) vips_strncpy( write->image_info->magick, format, MaxPathExtent ); if ( filename ) { - va_list ap; - - (void) vips_snprintf( write->image_info->filename, + (void) vips_snprintf( write->image_info->filename, MaxPathExtent, "%s:%s", format, filename ); } } @@ -1118,6 +1117,10 @@ write_new( VipsImage *im, const char *filename, const char *format ) filename, MaxPathExtent ); } + if ( quality > 0 ) { + write->image_info->quality = quality; + } + write->exception = AcquireExceptionInfo(); if( !write->exception) { write_free(write); @@ -1250,11 +1253,11 @@ magick_write_images_buf( Write *write, void **obuf, size_t *olen ) int vips__magick_write( VipsImage *im, const char *filename, - const char *format ) + const char *format, const size_t quality ) { Write *write; - if( !(write = write_new( im, filename, format )) ) + if( !(write = write_new( im, filename, format, quality )) ) return( -1 ); if ( magick_create_images( write ) ) { @@ -1279,11 +1282,11 @@ vips__magick_write( VipsImage *im, const char *filename, int vips__magick_write_buf( VipsImage *im, void **obuf, size_t *olen, - const char *format ) + const char *format, const size_t quality ) { Write *write; - if( !(write = write_new( im, NULL, format )) ) + if( !(write = write_new( im, NULL, format, quality )) ) return( -1 ); if ( magick_create_images( write ) ) { diff --git a/libvips/foreign/magicksave.c b/libvips/foreign/magicksave.c index 4361e5af..e57fa6ef 100644 --- a/libvips/foreign/magicksave.c +++ b/libvips/foreign/magicksave.c @@ -99,6 +99,7 @@ typedef struct _VipsForeignSaveMagickFile { char *filename; char *format; + int quality; } VipsForeignSaveMagickFile; @@ -118,7 +119,8 @@ vips_foreign_save_magick_file_build( VipsObject *object ) build( object ) ) return( -1 ); - if( vips__magick_write( save->ready, file->filename, file->format ) ) + if( vips__magick_write( save->ready, file->filename, file->format, + file->quality ) ) return( -1 ); return( 0 ); @@ -152,6 +154,13 @@ vips_foreign_save_magick_file_class_init( G_STRUCT_OFFSET( VipsForeignSaveMagickFile, format ), NULL ); + VIPS_ARG_INT( class, "quality", 3, + _( "Quality" ), + _( "Quality to use" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsForeignSaveMagickFile, quality ), + 0, 100, 0 ); + } static void @@ -166,6 +175,7 @@ typedef struct _VipsForeignSaveMagickBuffer { */ VipsArea *buf; char *format; + int quality; } VipsForeignSaveMagickBuffer; @@ -190,7 +200,7 @@ vips_foreign_save_magick_buffer_build( VipsObject *object ) return( -1 ); if( vips__magick_write_buf( save->ready, &obuf, &olen, - buffer->format ) ) + buffer->format, buffer->quality ) ) return( -1 ); /* obuf is a g_free() buffer, not vips_free(). @@ -226,8 +236,15 @@ vips_foreign_save_magick_buffer_class_init( VipsForeignSaveMagickBufferClass *cl _( "Format" ), _( "Format to save in" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignSaveMagickFile, format ), + G_STRUCT_OFFSET( VipsForeignSaveMagickBuffer, format ), NULL ); + + VIPS_ARG_INT( class, "quality", 3, + _( "Quality" ), + _( "Quality to use" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsForeignSaveMagickBuffer, quality ), + 0, 100, 0 ); } static void diff --git a/libvips/foreign/pforeign.h b/libvips/foreign/pforeign.h index f6471f47..cae6540c 100644 --- a/libvips/foreign/pforeign.h +++ b/libvips/foreign/pforeign.h @@ -133,9 +133,9 @@ int vips__magick_read_buffer_header( const void *buf, const size_t len, VipsImage *out, const char *density, int page, int n ); int vips__magick_write( VipsImage *in, const char *filename, - const char *format ); + const char *format, const size_t quality ); int vips__magick_write_buf( VipsImage *in, void **obuf, size_t *olen, - const char *format ); + const char *format, const size_t quality ); extern const char *vips__mat_suffs[];