add @background arg to save
used to flatten A out of images, if necessary vipsthumbnail rtd-img.png -o x.jpg[background=255]
This commit is contained in:
parent
2ec0a8b87e
commit
b21c47b1c5
@ -4,6 +4,7 @@
|
|||||||
- add vips_resize()
|
- add vips_resize()
|
||||||
- return of vips_init(), but just for bindings
|
- return of vips_init(), but just for bindings
|
||||||
- revised type.c to make it more binding-friendly
|
- revised type.c to make it more binding-friendly
|
||||||
|
- add @background arg to save: the colour to flatten against
|
||||||
|
|
||||||
8/9/14 started 7.40.9
|
8/9/14 started 7.40.9
|
||||||
- support jfif resunit "none"
|
- support jfif resunit "none"
|
||||||
|
@ -82,7 +82,7 @@ typedef struct _VipsEmbed {
|
|||||||
VipsImage *in;
|
VipsImage *in;
|
||||||
|
|
||||||
VipsExtend extend;
|
VipsExtend extend;
|
||||||
VipsArea *background;
|
VipsArrayDouble *background;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int width;
|
int width;
|
||||||
@ -362,7 +362,8 @@ vips_embed_build( VipsObject *object )
|
|||||||
|
|
||||||
if( !(embed->ink = vips__vector_to_ink(
|
if( !(embed->ink = vips__vector_to_ink(
|
||||||
class->nickname, embed->in,
|
class->nickname, embed->in,
|
||||||
embed->background->data, NULL, embed->background->n )) )
|
VIPS_AREA( embed->background )->data, NULL,
|
||||||
|
VIPS_AREA( embed->background )->n )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
if( !vips_object_argument_isset( object, "extend" ) &&
|
if( !vips_object_argument_isset( object, "extend" ) &&
|
||||||
@ -614,9 +615,7 @@ static void
|
|||||||
vips_embed_init( VipsEmbed *embed )
|
vips_embed_init( VipsEmbed *embed )
|
||||||
{
|
{
|
||||||
embed->extend = VIPS_EXTEND_BLACK;
|
embed->extend = VIPS_EXTEND_BLACK;
|
||||||
embed->background =
|
embed->background = vips_array_double_newv( 1, 0.0 );
|
||||||
vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), 1 );
|
|
||||||
((double *) (embed->background->data))[0] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +61,7 @@ typedef struct _VipsFlatten {
|
|||||||
|
|
||||||
/* Background colour.
|
/* Background colour.
|
||||||
*/
|
*/
|
||||||
VipsArea *background;
|
VipsArrayDouble *background;
|
||||||
|
|
||||||
/* The [double] converted to the input image format.
|
/* The [double] converted to the input image format.
|
||||||
*/
|
*/
|
||||||
@ -319,8 +319,9 @@ vips_flatten_build( VipsObject *object )
|
|||||||
/* Is the background black? We have a special path for this.
|
/* Is the background black? We have a special path for this.
|
||||||
*/
|
*/
|
||||||
black = TRUE;
|
black = TRUE;
|
||||||
for( i = 0; i < flatten->background->n; i++ )
|
for( i = 0; i < VIPS_AREA( flatten->background )->n; i++ )
|
||||||
if( ((double *) flatten->background->data)[i] != 0.0 ) {
|
if( vips_array_double_get( flatten->background, NULL )[i] !=
|
||||||
|
0.0 ) {
|
||||||
black = FALSE;
|
black = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -336,8 +337,8 @@ vips_flatten_build( VipsObject *object )
|
|||||||
*/
|
*/
|
||||||
if( !(flatten->ink = vips__vector_to_ink( class->nickname,
|
if( !(flatten->ink = vips__vector_to_ink( class->nickname,
|
||||||
conversion->out,
|
conversion->out,
|
||||||
flatten->background->data, NULL,
|
VIPS_AREA( flatten->background )->data, NULL,
|
||||||
flatten->background->n )) )
|
VIPS_AREA( flatten->background )->n )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
if( vips_image_generate( conversion->out,
|
if( vips_image_generate( conversion->out,
|
||||||
@ -384,9 +385,7 @@ vips_flatten_class_init( VipsFlattenClass *class )
|
|||||||
static void
|
static void
|
||||||
vips_flatten_init( VipsFlatten *flatten )
|
vips_flatten_init( VipsFlatten *flatten )
|
||||||
{
|
{
|
||||||
flatten->background =
|
flatten->background = vips_array_double_newv( 1, 0.0 );
|
||||||
vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), 1 );
|
|
||||||
((double *) (flatten->background->data))[0] = 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -397,7 +396,7 @@ vips_flatten_init( VipsFlatten *flatten )
|
|||||||
*
|
*
|
||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
* @background: colour for new pixels
|
* @background: #VipsArrayDouble colour for new pixels
|
||||||
*
|
*
|
||||||
* Take the last band of @in as an alpha and use it to blend the
|
* Take the last band of @in as an alpha and use it to blend the
|
||||||
* remaining channels with @background.
|
* remaining channels with @background.
|
||||||
|
@ -1146,7 +1146,9 @@ vips_foreign_convert_saveable( VipsForeignSave *save )
|
|||||||
class->saveable == VIPS_SAVEABLE_RGB_CMYK) ) {
|
class->saveable == VIPS_SAVEABLE_RGB_CMYK) ) {
|
||||||
VipsImage *out;
|
VipsImage *out;
|
||||||
|
|
||||||
if( vips_flatten( in, &out, 0, NULL ) ) {
|
if( vips_flatten( in, &out,
|
||||||
|
"background", save->background,
|
||||||
|
NULL ) ) {
|
||||||
g_object_unref( in );
|
g_object_unref( in );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
@ -1414,11 +1416,19 @@ vips_foreign_save_class_init( VipsForeignSaveClass *class )
|
|||||||
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||||
G_STRUCT_OFFSET( VipsForeignSave, strip ),
|
G_STRUCT_OFFSET( VipsForeignSave, strip ),
|
||||||
FALSE );
|
FALSE );
|
||||||
|
|
||||||
|
VIPS_ARG_BOXED( class, "background", 101,
|
||||||
|
_( "Background" ),
|
||||||
|
_( "Background value" ),
|
||||||
|
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsForeignSave, background ),
|
||||||
|
VIPS_TYPE_ARRAY_DOUBLE );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vips_foreign_save_init( VipsForeignSave *object )
|
vips_foreign_save_init( VipsForeignSave *save )
|
||||||
{
|
{
|
||||||
|
save->background = vips_array_double_newv( 1, 0.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Can we write this filename with this file?
|
/* Can we write this filename with this file?
|
||||||
|
@ -256,10 +256,15 @@ typedef enum {
|
|||||||
typedef struct _VipsForeignSave {
|
typedef struct _VipsForeignSave {
|
||||||
VipsForeign parent_object;
|
VipsForeign parent_object;
|
||||||
|
|
||||||
/* Dont't attach metadata.
|
/* Don't attach metadata.
|
||||||
*/
|
*/
|
||||||
gboolean strip;
|
gboolean strip;
|
||||||
|
|
||||||
|
/* If flattening out alpha, the background colour to use. Default to
|
||||||
|
* 0 (black).
|
||||||
|
*/
|
||||||
|
VipsArrayDouble *background;
|
||||||
|
|
||||||
/*< public >*/
|
/*< public >*/
|
||||||
|
|
||||||
/* The image we are to save, as supplied by our caller.
|
/* The image we are to save, as supplied by our caller.
|
||||||
|
Loading…
Reference in New Issue
Block a user