Changes based on review
This commit is contained in:
parent
091bb853dd
commit
bd9c97feed
@ -132,7 +132,7 @@ typedef struct _VipsForeignLoadGif {
|
|||||||
gboolean has_transparency;
|
gboolean has_transparency;
|
||||||
gboolean has_colour;
|
gboolean has_colour;
|
||||||
|
|
||||||
/* Delays between frames (in miliseconds).
|
/* Delays between frames (in milliseconds).
|
||||||
*/
|
*/
|
||||||
int *delays;
|
int *delays;
|
||||||
|
|
||||||
@ -519,9 +519,9 @@ vips_foreign_load_gif_scan_extension( VipsForeignLoadGif *gif )
|
|||||||
gif->has_transparency = TRUE;
|
gif->has_transparency = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( gif->n_pages % 64 == 0 ) {
|
if( gif->n_pages % 64 == 0 )
|
||||||
gif->delays = (int *) g_realloc( gif->delays, (gif->n_pages + 64) * sizeof(int) );
|
gif->delays = (int *) g_realloc( gif->delays, (gif->n_pages + 64) * sizeof(int) );
|
||||||
}
|
|
||||||
gif->delays[gif->n_pages] = (extension[2] | (extension[3] << 8)) * 10;
|
gif->delays[gif->n_pages] = (extension[2] | (extension[3] << 8)) * 10;
|
||||||
|
|
||||||
while( extension != NULL )
|
while( extension != NULL )
|
||||||
@ -575,11 +575,11 @@ vips_foreign_load_gif_set_header( VipsForeignLoadGif *gif, VipsImage *image )
|
|||||||
vips_image_set_int( image, "gif-loop", gif->loop );
|
vips_image_set_int( image, "gif-loop", gif->loop );
|
||||||
|
|
||||||
if( gif->delays ) {
|
if( gif->delays ) {
|
||||||
vips_image_set_int( image, "gif-delay", VIPS_RINT( gif->delays[0] / 10.0 ) );
|
vips_image_set_int( image,
|
||||||
|
"gif-delay", VIPS_RINT( gif->delays[0] / 10.0 ) );
|
||||||
vips_image_set_array_int( image, "delay", gif->delays, gif->n_pages );
|
vips_image_set_array_int( image, "delay", gif->delays, gif->n_pages );
|
||||||
} else {
|
} else
|
||||||
vips_image_set_int( image, "gif-delay", 4 );
|
vips_image_set_int( image, "gif-delay", 4 );
|
||||||
}
|
|
||||||
|
|
||||||
if( gif->comment )
|
if( gif->comment )
|
||||||
vips_image_set_string( image, "gif-comment", gif->comment );
|
vips_image_set_string( image, "gif-comment", gif->comment );
|
||||||
|
@ -70,6 +70,8 @@ typedef struct _VipsForeignSaveMagick {
|
|||||||
Image *current_image;
|
Image *current_image;
|
||||||
|
|
||||||
int page_height;
|
int page_height;
|
||||||
|
int *delays;
|
||||||
|
int delays_length;
|
||||||
|
|
||||||
/* The position of current_image in the output.
|
/* The position of current_image in the output.
|
||||||
*/
|
*/
|
||||||
@ -111,9 +113,8 @@ vips_foreign_save_magick_next_image( VipsForeignSaveMagick *magick )
|
|||||||
|
|
||||||
Image *image;
|
Image *image;
|
||||||
int number;
|
int number;
|
||||||
int *numbers;
|
|
||||||
int numbers_length;
|
|
||||||
const char *str;
|
const char *str;
|
||||||
|
int page_index;
|
||||||
|
|
||||||
g_assert( !magick->current_image );
|
g_assert( !magick->current_image );
|
||||||
|
|
||||||
@ -143,11 +144,13 @@ vips_foreign_save_magick_next_image( VipsForeignSaveMagick *magick )
|
|||||||
im->Xsize, magick->page_height, magick->exception ) )
|
im->Xsize, magick->page_height, magick->exception ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
if( vips_image_get_typeof( im, "delay" ) &&
|
/* Delay must be converted from milliseconds into centiseconds
|
||||||
!vips_image_get_array_int( im, "delay", &numbers, &numbers_length ) ) {
|
* as GIF image requires centiseconds.
|
||||||
int page_index = magick->position.top / magick->page_height;
|
*/
|
||||||
if( page_index < numbers_length )
|
if ( magick->delays != NULL) {
|
||||||
image->delay = (size_t) VIPS_RINT( numbers[page_index] / 10.0 );
|
page_index = magick->position.top / magick->page_height;
|
||||||
|
if( page_index < magick->delays_length )
|
||||||
|
image->delay = (size_t) 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):
|
||||||
@ -343,6 +346,12 @@ vips_foreign_save_magick_build( VipsObject *object )
|
|||||||
|
|
||||||
magick->page_height = vips_image_get_page_height( im );
|
magick->page_height = vips_image_get_page_height( im );
|
||||||
|
|
||||||
|
if( vips_image_get_typeof( im, "delay" ) &&
|
||||||
|
vips_image_get_array_int( im,
|
||||||
|
"delay", &magick->delays, &magick->delays_length ) ) {
|
||||||
|
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 ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
@ -308,7 +308,8 @@ get_array_int( VipsImage *image, const char *field, int* n )
|
|||||||
static int
|
static int
|
||||||
extract_delay( int index, int *delays, int delays_length, int default_delay )
|
extract_delay( int index, int *delays, int delays_length, int default_delay )
|
||||||
{
|
{
|
||||||
if( delays == NULL || index > delays_length ) return( default_delay );
|
if( delays == NULL || index > delays_length )
|
||||||
|
return( default_delay );
|
||||||
return( delays[index] );
|
return( delays[index] );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,6 +352,7 @@ write_webp_anim( VipsWebPWrite *write, VipsImage *image, int page_height )
|
|||||||
for( top = 0; top < image->Ysize; top += page_height ) {
|
for( top = 0; top < image->Ysize; top += page_height ) {
|
||||||
VipsImage *x;
|
VipsImage *x;
|
||||||
WebPPicture pic;
|
WebPPicture pic;
|
||||||
|
int page_index;
|
||||||
|
|
||||||
if( vips_crop( image, &x,
|
if( vips_crop( image, &x,
|
||||||
0, top, image->Xsize, page_height, NULL ) )
|
0, top, image->Xsize, page_height, NULL ) )
|
||||||
@ -373,7 +375,7 @@ write_webp_anim( VipsWebPWrite *write, VipsImage *image, int page_height )
|
|||||||
|
|
||||||
WebPPictureFree( &pic );
|
WebPPictureFree( &pic );
|
||||||
|
|
||||||
int page_index = top / page_height;
|
page_index = top / page_height;
|
||||||
timestamp_ms += extract_delay( page_index, delays, delays_length, default_delay );
|
timestamp_ms += extract_delay( page_index, delays, delays_length, default_delay );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +358,7 @@ read_free( Read *read )
|
|||||||
|
|
||||||
VIPS_FREEF( vips_tracked_close, read->fd );
|
VIPS_FREEF( vips_tracked_close, read->fd );
|
||||||
VIPS_FREE( read->filename );
|
VIPS_FREE( read->filename );
|
||||||
|
VIPS_FREE( read->delays );
|
||||||
VIPS_FREE( read );
|
VIPS_FREE( read );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
@ -475,24 +476,21 @@ read_header( Read *read, VipsImage *out )
|
|||||||
VIPS_META_PAGE_HEIGHT, read->frame_height );
|
VIPS_META_PAGE_HEIGHT, read->frame_height );
|
||||||
|
|
||||||
if ( read->frame_count > 1) {
|
if ( read->frame_count > 1) {
|
||||||
read->delays = (int *) g_malloc( read->frame_count * sizeof(int) );
|
int i;
|
||||||
|
read->delays = (int *) g_malloc0( read->frame_count * sizeof(int) );
|
||||||
|
|
||||||
for( int i = 0; i < read->frame_count; i++ ) {
|
for( i = 0; i < read->frame_count; i++ ) {
|
||||||
if( WebPDemuxGetFrame( read->demux, i + 1, &iter ) ) {
|
if( WebPDemuxGetFrame( read->demux, i + 1, &iter ) )
|
||||||
read->delays[i] = iter.duration;
|
read->delays[i] = iter.duration;
|
||||||
} else {
|
|
||||||
read->delays[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
for( int i = 0; i < read->frame_count; i++ ) {
|
for( i = 0; i < read->frame_count; i++ ) {
|
||||||
printf( "webp2vips: frame = %d; duration = %d\n", i + 1, read->delays[i] );
|
printf( "webp2vips: frame = %d; duration = %d\n", i + 1, read->delays[i] );
|
||||||
}
|
}
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
vips_image_set_array_int( out, "delay", read->delays, read->frame_count );
|
vips_image_set_array_int( out, "delay", read->delays, read->frame_count );
|
||||||
g_free( read->delays );
|
|
||||||
|
|
||||||
/* webp uses ms for delays, gif uses centiseconds.
|
/* webp uses ms for delays, gif uses centiseconds.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user