tiff buffer loader supports get_flags

the tiff buffer loader was not setting any flags, so seq was using a
temp file (for example)

see https://github.com/jcupitt/libvips/issues/590
This commit is contained in:
John Cupitt 2017-01-27 10:32:47 +00:00
parent ec093100fb
commit 94434c2359
4 changed files with 50 additions and 3 deletions

View File

@ -1479,7 +1479,7 @@ vips_foreign_save_class_init( VipsForeignSaveClass *class )
object_class->nickname = "filesave"; object_class->nickname = "filesave";
object_class->description = _( "file savers" ); object_class->description = _( "file savers" );
/* All savers are seqential by definition. Things like tiled tiff /* All savers are sequential by definition. Things like tiled tiff
* write and interlaced png write, which are not, add extra caches * write and interlaced png write, which are not, add extra caches
* on their input. * on their input.
*/ */

View File

@ -69,9 +69,12 @@ int vips__tiff_read_header( const char *filename, VipsImage *out,
int page, int n, gboolean autorotate ); int page, int n, gboolean autorotate );
int vips__tiff_read( const char *filename, VipsImage *out, int vips__tiff_read( const char *filename, VipsImage *out,
int page, int n, gboolean autorotate, gboolean readbehind ); int page, int n, gboolean autorotate, gboolean readbehind );
gboolean vips__istifftiled( const char *filename );
gboolean vips__istiff_buffer( const void *buf, size_t len );
gboolean vips__istiff( const char *filename ); gboolean vips__istiff( const char *filename );
gboolean vips__istifftiled( const char *filename );
gboolean vips__istiff_buffer( const void *buf, size_t len );
gboolean vips__istifftiled_buffer( const void *buf, size_t len );
int vips__tiff_read_header_buffer( const void *buf, size_t len, VipsImage *out, int vips__tiff_read_header_buffer( const void *buf, size_t len, VipsImage *out,
int page, int n, gboolean autorotate ); int page, int n, gboolean autorotate );

View File

@ -2352,4 +2352,29 @@ vips__tiff_read_buffer( const void *buf, size_t len,
return( 0 ); return( 0 );
} }
gboolean
vips__istifftiled_buffer( const void *buf, size_t len )
{
VipsImage *im;
TIFF *tif;
gboolean tiled;
vips__tiff_init();
im = vips_image_new();
if( !(tif = vips__tiff_openin_buffer( im, buf, len )) ) {
g_object_unref( im );
vips_error_clear();
return( FALSE );
}
tiled = TIFFIsTiled( tif );
TIFFClose( tif );
g_object_unref( im );
return( tiled );
}
#endif /*HAVE_TIFF*/ #endif /*HAVE_TIFF*/

View File

@ -2,6 +2,8 @@
* *
* 5/12/11 * 5/12/11
* - from tiffload.c * - from tiffload.c
* 27/1/17
* - add get_flags for buffer loader
*/ */
/* /*
@ -244,6 +246,22 @@ typedef VipsForeignLoadTiffClass VipsForeignLoadTiffBufferClass;
G_DEFINE_TYPE( VipsForeignLoadTiffBuffer, vips_foreign_load_tiff_buffer, G_DEFINE_TYPE( VipsForeignLoadTiffBuffer, vips_foreign_load_tiff_buffer,
vips_foreign_load_tiff_get_type() ); vips_foreign_load_tiff_get_type() );
static VipsForeignFlags
vips_foreign_load_tiff_buffer_get_flags( VipsForeignLoad *load )
{
VipsForeignLoadTiffBuffer *buffer = (VipsForeignLoadTiffBuffer *) load;
VipsForeignFlags flags;
flags = 0;
if( vips__istifftiled_buffer( buffer->buf->data, buffer->buf->length ) )
flags |= VIPS_FOREIGN_PARTIAL;
else
flags |= VIPS_FOREIGN_SEQUENTIAL;
return( flags );
}
static int static int
vips_foreign_load_tiff_buffer_header( VipsForeignLoad *load ) vips_foreign_load_tiff_buffer_header( VipsForeignLoad *load )
{ {
@ -288,6 +306,7 @@ vips_foreign_load_tiff_buffer_class_init(
object_class->description = _( "load tiff from buffer" ); object_class->description = _( "load tiff from buffer" );
load_class->is_a_buffer = vips__istiff_buffer; load_class->is_a_buffer = vips__istiff_buffer;
load_class->get_flags = vips_foreign_load_tiff_file_get_flags;
load_class->header = vips_foreign_load_tiff_buffer_header; load_class->header = vips_foreign_load_tiff_buffer_header;
load_class->load = vips_foreign_load_tiff_buffer_load; load_class->load = vips_foreign_load_tiff_buffer_load;