fix up png restart
hopefully ... we needed a png_init_io() as well
This commit is contained in:
parent
2d374c3114
commit
120ba3289c
@ -208,6 +208,10 @@ read_open_input( Read *read )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
if( read->seek_position != -1 )
|
if( read->seek_position != -1 )
|
||||||
fseek( read->fp, read->seek_position, SEEK_SET );
|
fseek( read->fp, read->seek_position, SEEK_SET );
|
||||||
|
|
||||||
|
/* Just takes a copy of the fp.
|
||||||
|
*/
|
||||||
|
png_init_io( read->pPng, read->fp );
|
||||||
}
|
}
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
@ -324,7 +328,6 @@ read_new_filename( VipsImage *out, const char *name, gboolean fail )
|
|||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
png_init_io( read->pPng, read->fp );
|
|
||||||
read_info( read );
|
read_info( read );
|
||||||
|
|
||||||
return( read );
|
return( read );
|
||||||
|
@ -343,29 +343,52 @@ vips__iswebp( const char *filename )
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
read_minimise( Read *read )
|
read_mmap( Read *read )
|
||||||
{
|
{
|
||||||
WebPDemuxReleaseIterator( &read->iter );
|
if( read->filename &&
|
||||||
VIPS_UNREF( read->frame );
|
read->fd < 0 ) {
|
||||||
VIPS_FREEF( WebPDemuxDelete, read->demux );
|
if( (read->fd = vips__open_image_read( read->filename )) < 0 )
|
||||||
WebPFreeDecBuffer( &read->config.output );
|
return( -1 );
|
||||||
|
if( read->length < 0 &&
|
||||||
if( read->fd > 0 &&
|
(read->length = vips_file_length( read->fd )) < 0 )
|
||||||
read->data &&
|
return( -1 );
|
||||||
read->length > 0 ) {
|
if( !(read->data =
|
||||||
vips__munmap( read->data, read->length );
|
vips__mmap( read->fd, FALSE, read->length, 0 )) ) {
|
||||||
read->data = NULL;
|
return( -1 );
|
||||||
read->length = 0;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VIPS_FREEF( vips_tracked_close, read->fd );
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
read_munmap( Read *read )
|
||||||
|
{
|
||||||
|
if( read->fd >= 0 ) {
|
||||||
|
if( read->data &&
|
||||||
|
read->length > 0 ) {
|
||||||
|
vips__munmap( read->data, read->length );
|
||||||
|
read->data = NULL;
|
||||||
|
read->length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( read->fd >= 0 ) {
|
||||||
|
vips_tracked_close( read->fd );
|
||||||
|
read->fd = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
read_free( Read *read )
|
read_free( Read *read )
|
||||||
{
|
{
|
||||||
read_minimise( read );
|
read_munmap( read );
|
||||||
|
|
||||||
|
WebPDemuxReleaseIterator( &read->iter );
|
||||||
|
VIPS_UNREF( read->frame );
|
||||||
|
VIPS_FREEF( WebPDemuxDelete, read->demux );
|
||||||
|
WebPFreeDecBuffer( &read->config.output );
|
||||||
|
|
||||||
VIPS_FREE( read->filename );
|
VIPS_FREE( read->filename );
|
||||||
VIPS_FREE( read->delays );
|
VIPS_FREE( read->delays );
|
||||||
@ -383,33 +406,22 @@ read_new( const char *filename, const void *data, size_t length,
|
|||||||
if( !(read = VIPS_NEW( NULL, Read )) )
|
if( !(read = VIPS_NEW( NULL, Read )) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
|
|
||||||
read->filename = g_strdup( filename );
|
if( filename )
|
||||||
|
read->filename = g_strdup( filename );
|
||||||
read->data = data;
|
read->data = data;
|
||||||
read->length = length;
|
read->length = length;
|
||||||
read->page = page;
|
read->page = page;
|
||||||
read->n = n;
|
read->n = n;
|
||||||
read->scale = scale;
|
read->scale = scale;
|
||||||
read->delays = NULL;
|
read->delays = NULL;
|
||||||
read->fd = 0;
|
read->fd = -1;
|
||||||
read->demux = NULL;
|
read->demux = NULL;
|
||||||
read->frame = NULL;
|
read->frame = NULL;
|
||||||
read->dispose_method = WEBP_MUX_DISPOSE_NONE;
|
read->dispose_method = WEBP_MUX_DISPOSE_NONE;
|
||||||
read->frame_no = 0;
|
read->frame_no = 0;
|
||||||
|
|
||||||
if( read->filename ) {
|
if( read_mmap( read ) )
|
||||||
/* libwebp makes streaming from a file source very hard. We
|
return( NULL );
|
||||||
* have to read to a full memory buffer, then copy to out.
|
|
||||||
*
|
|
||||||
* mmap the input file, it's slightly quicker.
|
|
||||||
*/
|
|
||||||
if( (read->fd = vips__open_image_read( read->filename )) < 0 ||
|
|
||||||
(read->length = vips_file_length( read->fd )) < 0 ||
|
|
||||||
!(read->data = vips__mmap( read->fd,
|
|
||||||
FALSE, read->length, 0 )) ) {
|
|
||||||
read_free( read );
|
|
||||||
return( NULL );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WebPInitDecoderConfig( &read->config );
|
WebPInitDecoderConfig( &read->config );
|
||||||
read->config.options.use_threads = 1;
|
read->config.options.use_threads = 1;
|
||||||
@ -605,7 +617,7 @@ vips__webp_read_file_header( const char *filename, VipsImage *out,
|
|||||||
{
|
{
|
||||||
Read *read;
|
Read *read;
|
||||||
|
|
||||||
if( !(read = read_new( filename, NULL, 0, page, n, scale )) ) {
|
if( !(read = read_new( filename, NULL, -1, page, n, scale )) ) {
|
||||||
vips_error( "webp2vips",
|
vips_error( "webp2vips",
|
||||||
_( "unable to open \"%s\"" ), filename );
|
_( "unable to open \"%s\"" ), filename );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
@ -769,6 +781,9 @@ read_webp_generate( VipsRegion *or,
|
|||||||
|
|
||||||
g_assert( r->height == 1 );
|
g_assert( r->height == 1 );
|
||||||
|
|
||||||
|
if( read_mmap( read ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
while( read->frame_no < frame ) {
|
while( read->frame_no < frame ) {
|
||||||
if( read_next_frame( read ) )
|
if( read_next_frame( read ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
@ -806,7 +821,7 @@ read_webp_generate( VipsRegion *or,
|
|||||||
static void
|
static void
|
||||||
read_minimise_cb( VipsObject *object, Read *read )
|
read_minimise_cb( VipsObject *object, Read *read )
|
||||||
{
|
{
|
||||||
read_minimise( read );
|
read_munmap( read );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -837,7 +852,7 @@ vips__webp_read_file( const char *filename, VipsImage *out,
|
|||||||
{
|
{
|
||||||
Read *read;
|
Read *read;
|
||||||
|
|
||||||
if( !(read = read_new( filename, NULL, 0, page, n, scale )) ) {
|
if( !(read = read_new( filename, NULL, -1, page, n, scale )) ) {
|
||||||
vips_error( "webp2vips",
|
vips_error( "webp2vips",
|
||||||
_( "unable to open \"%s\"" ), filename );
|
_( "unable to open \"%s\"" ), filename );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
@ -26,3 +26,7 @@ fi
|
|||||||
if test_supported pngload; then
|
if test_supported pngload; then
|
||||||
./test_descriptors $test_images/sample.png
|
./test_descriptors $test_images/sample.png
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test_supported webpload; then
|
||||||
|
./test_descriptors $test_images/1.webp
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user