From d12f8e200aa28e5091b57d318b12ba9bf9ef83da Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 26 Aug 2017 16:26:37 +0100 Subject: [PATCH] support tiffsave_buffer pyramids add support for tiff pyramid save to memory, thanks bubba see https://github.com/jcupitt/libvips/issues/702 --- ChangeLog | 1 + libvips/foreign/tiff.c | 26 +++++++++++++++++++++++--- libvips/foreign/vips2tiff.c | 14 ++++++++++++-- libvips/iofuncs/dbuf.c | 4 ++-- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc35ebc8..bcbf9bb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ - add vips_find_trim(), search for non-background areas - remove lcms1 support, it had bitrotted - `join` tagged as seq +- support tiffsave_buffer for pyramids, thanks bubba 2/8/17 started 8.5.8 - fix transparency detection in merge, thanks Haida diff --git a/libvips/foreign/tiff.c b/libvips/foreign/tiff.c index 232409c1..e6900cea 100644 --- a/libvips/foreign/tiff.c +++ b/libvips/foreign/tiff.c @@ -2,6 +2,9 @@ * * 14/10/16 * - from vips2tiff.c + * + * 26/8/17 + * - add openout_read, to help tiffsave_buffer for pyramids */ /* @@ -309,9 +312,26 @@ typedef struct _VipsTiffOpenoutBuffer { static tsize_t openout_buffer_read( thandle_t st, tdata_t data, tsize_t size ) { - g_assert_not_reached(); - - return( 0 ); + VipsTiffOpenoutBuffer *buffer = (VipsTiffOpenoutBuffer *) st; + + off_t write_point; + size_t available; + unsigned char *from; + + write_point = vips_dbuf_tell( &buffer->dbuf ); + from = vips_dbuf_get_write( &buffer->dbuf, &available ); + vips_dbuf_seek( &buffer->dbuf, write_point, SEEK_SET ); + + if( available < size ) { + vips_error( "openout_buffer_read", + "%s", _( "read beyond end of buffer" ) ); + return( 0 ); + } + + memcpy( data, from, size ); + + vips_dbuf_seek( &buffer->dbuf, size, SEEK_CUR ); + return( size ); } static tsize_t diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 2e11472e..d28d5b5b 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -171,6 +171,8 @@ * 29/1/17 * - enable bigtiff automatically for large, uncompressed writes, thanks * AndreasSchmid1 + * 26/8/17 + * - support pyramid creation to buffer, thanks bubba */ /* @@ -1665,8 +1667,16 @@ wtiff_gather( Wtiff *wtiff ) printf( "Appending layer %s ...\n", layer->lname ); #endif /*DEBUG*/ - if( !(in = vips__tiff_openin( layer->lname )) ) - return( -1 ); + if( layer->lname ) { + if( !(in = vips__tiff_openin( layer->lname )) ) + return( -1 ); + } + else { + if( !(in = vips__tiff_openin_buffer( wtiff->im, + layer->buf, layer->len )) ) + return( -1 ); + } + if( wtiff_copy_tiff( wtiff, wtiff->layer->tif, in ) ) { TIFFClose( in ); return( -1 ); diff --git a/libvips/iofuncs/dbuf.c b/libvips/iofuncs/dbuf.c index 2bf9db8a..aecba6da 100644 --- a/libvips/iofuncs/dbuf.c +++ b/libvips/iofuncs/dbuf.c @@ -299,10 +299,10 @@ vips_dbuf_truncate( VipsDbuf *dbuf ) } /** - * vips_dbuf_truncate: + * vips_dbuf_tell: * @dbuf: the buffer * - * Truncate the data so that it ends at the write point. No memory is freed. + * Returns: the current write point */ off_t vips_dbuf_tell( VipsDbuf *dbuf )