reformatting for vips2webp
- move a couple of small functions inline for simplicity - mark "gif-delay" as deprecated - minor reformatting
This commit is contained in:
parent
777c360774
commit
515bf68f46
@ -22,8 +22,8 @@
|
|||||||
* - init pages to 0 before load
|
* - init pages to 0 before load
|
||||||
* 14/2/19
|
* 14/2/19
|
||||||
* - rework as a sequential loader ... simpler, much lower mem use
|
* - rework as a sequential loader ... simpler, much lower mem use
|
||||||
* 6/7/19
|
* 6/7/19 [deftomat]
|
||||||
* - support array of delays
|
* - support array of delays
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
* - write with a single call to vips_sink_disc()
|
* - write with a single call to vips_sink_disc()
|
||||||
* 29/6/19
|
* 29/6/19
|
||||||
* - support "strip" option
|
* - support "strip" option
|
||||||
|
* 6/7/19 [deftomat]
|
||||||
|
* - support array of delays
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -147,10 +149,11 @@ vips_foreign_save_magick_next_image( VipsForeignSaveMagick *magick )
|
|||||||
/* Delay must be converted from milliseconds into centiseconds
|
/* Delay must be converted from milliseconds into centiseconds
|
||||||
* as GIF image requires centiseconds.
|
* as GIF image requires centiseconds.
|
||||||
*/
|
*/
|
||||||
if ( magick->delays != NULL) {
|
if( magick->delays ) {
|
||||||
page_index = magick->position.top / magick->page_height;
|
page_index = magick->position.top / magick->page_height;
|
||||||
if( page_index < magick->delays_length )
|
if( page_index < magick->delays_length )
|
||||||
image->delay = (size_t) VIPS_RINT( magick->delays[page_index] / 10.0 );
|
image->delay =
|
||||||
|
VIPS_RINT( magick->delays[page_index] / 10.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ImageMagick uses iterations like this (at least in gif save):
|
/* ImageMagick uses iterations like this (at least in gif save):
|
||||||
@ -348,9 +351,8 @@ vips_foreign_save_magick_build( VipsObject *object )
|
|||||||
|
|
||||||
if( vips_image_get_typeof( im, "delay" ) &&
|
if( vips_image_get_typeof( im, "delay" ) &&
|
||||||
vips_image_get_array_int( im,
|
vips_image_get_array_int( im,
|
||||||
"delay", &magick->delays, &magick->delays_length ) ) {
|
"delay", &magick->delays, &magick->delays_length ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
|
||||||
|
|
||||||
if( vips_sink_disc( im,
|
if( vips_sink_disc( im,
|
||||||
vips_foreign_save_magick_write_block, magick ) )
|
vips_foreign_save_magick_write_block, magick ) )
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
* - target libwebp 0.5+ and remove some ifdefs
|
* - target libwebp 0.5+ and remove some ifdefs
|
||||||
* - add animated webp write
|
* - add animated webp write
|
||||||
* - use libwebpmux instead of our own thing, phew
|
* - use libwebpmux instead of our own thing, phew
|
||||||
|
* 6/7/19 [deftomat]
|
||||||
|
* - support array of delays
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -275,61 +277,16 @@ write_webp_single( VipsWebPWrite *write, VipsImage *image )
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a defaulted int value.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
get_int( VipsImage *image, const char *field, int default_value )
|
|
||||||
{
|
|
||||||
int value;
|
|
||||||
|
|
||||||
if( vips_image_get_typeof( image, field ) &&
|
|
||||||
!vips_image_get_int( image, field, &value ) )
|
|
||||||
return( value );
|
|
||||||
|
|
||||||
return( default_value );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get an image field as an array of ints.
|
|
||||||
*/
|
|
||||||
static int*
|
|
||||||
get_array_int( VipsImage *image, const char *field, int* n )
|
|
||||||
{
|
|
||||||
int *value;
|
|
||||||
|
|
||||||
if( vips_image_get_typeof( image, field ) &&
|
|
||||||
!vips_image_get_array_int( image, field, &value, n ) )
|
|
||||||
return( value );
|
|
||||||
|
|
||||||
return( NULL );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns a delay on a given index or the default delay.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
extract_delay( int index, const int *delays, int delays_length,
|
|
||||||
int default_delay )
|
|
||||||
{
|
|
||||||
if( delays == NULL ||
|
|
||||||
index > delays_length )
|
|
||||||
return( default_delay );
|
|
||||||
|
|
||||||
return( delays[index] );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write a set of animated frames into write->memory_writer.
|
/* Write a set of animated frames into write->memory_writer.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
write_webp_anim( VipsWebPWrite *write, VipsImage *image, int page_height )
|
write_webp_anim( VipsWebPWrite *write, VipsImage *image, int page_height )
|
||||||
{
|
{
|
||||||
/* 100ms is the webp default. gif-delay is in centiseconds (the GIF
|
|
||||||
* standard).
|
|
||||||
*/
|
|
||||||
const int default_delay = 10 * get_int( image, "gif-delay", 10 );
|
|
||||||
int delays_length;
|
|
||||||
const int *delays = get_array_int( image, "delay", &delays_length );
|
|
||||||
|
|
||||||
WebPAnimEncoderOptions anim_config;
|
WebPAnimEncoderOptions anim_config;
|
||||||
WebPData webp_data;
|
WebPData webp_data;
|
||||||
|
int gif_delay;
|
||||||
|
int *delay;
|
||||||
|
int delay_length;
|
||||||
int top;
|
int top;
|
||||||
int timestamp_ms;
|
int timestamp_ms;
|
||||||
|
|
||||||
@ -351,6 +308,20 @@ write_webp_anim( VipsWebPWrite *write, VipsImage *image, int page_height )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* There might just be the old gif-delay field. This is centiseconds.
|
||||||
|
*/
|
||||||
|
gif_delay = 4;
|
||||||
|
if( vips_image_get_typeof( image, "gif-delay" ) &&
|
||||||
|
vips_image_get_int( image, "gif-delay", &gif_delay ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
/* New images have an array of ints instead.
|
||||||
|
*/
|
||||||
|
if( vips_image_get_typeof( image, "delay" ) &&
|
||||||
|
vips_image_get_array_int( image, "delay",
|
||||||
|
&delay, &delay_length ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
timestamp_ms = 0;
|
timestamp_ms = 0;
|
||||||
for( top = 0; top < image->Ysize; top += page_height ) {
|
for( top = 0; top < image->Ysize; top += page_height ) {
|
||||||
VipsImage *x;
|
VipsImage *x;
|
||||||
@ -379,7 +350,11 @@ write_webp_anim( VipsWebPWrite *write, VipsImage *image, int page_height )
|
|||||||
WebPPictureFree( &pic );
|
WebPPictureFree( &pic );
|
||||||
|
|
||||||
page_index = top / page_height;
|
page_index = top / page_height;
|
||||||
timestamp_ms += extract_delay( page_index, delays, delays_length, default_delay );
|
if( delay &&
|
||||||
|
page_index < delay_length )
|
||||||
|
timestamp_ms += delay[page_index];
|
||||||
|
else
|
||||||
|
timestamp_ms += gif_delay * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Closes encoder and add last frame delay.
|
/* Closes encoder and add last frame delay.
|
||||||
@ -462,8 +437,14 @@ vips_webp_add_chunks( VipsWebPWrite *write, VipsImage *image )
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if( vips_image_get_typeof( image, "gif-loop" ) )
|
if( vips_image_get_typeof( image, "gif-loop" ) ) {
|
||||||
vips_webp_set_count( write, get_int( image, "gif-loop", 0 ) );
|
int gif_loop;
|
||||||
|
|
||||||
|
if( vips_image_get_int( image, "gif-loop", &gif_loop ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
vips_webp_set_count( write, gif_loop );
|
||||||
|
}
|
||||||
|
|
||||||
for( i = 0; i < vips__n_webp_names; i++ ) {
|
for( i = 0; i < vips__n_webp_names; i++ ) {
|
||||||
const char *vips_name = vips__webp_names[i].vips;
|
const char *vips_name = vips__webp_names[i].vips;
|
||||||
|
@ -1222,7 +1222,8 @@ vips_image_remove( VipsImage *image, const char *name )
|
|||||||
/* Deprecated header fields we hide from _map.
|
/* Deprecated header fields we hide from _map.
|
||||||
*/
|
*/
|
||||||
static const char *vips_image_header_deprecated[] = {
|
static const char *vips_image_header_deprecated[] = {
|
||||||
"ipct-data"
|
"ipct-data",
|
||||||
|
"gif-delay"
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
|
Loading…
Reference in New Issue
Block a user