Added quality option.

This commit is contained in:
Dirk Lemstra 2017-12-17 11:54:24 +01:00
parent c7992bf6d9
commit ccf894c738
3 changed files with 33 additions and 13 deletions

View File

@ -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,8 +1108,6 @@ 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,
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 ) ) {

View File

@ -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

View File

@ -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[];