Revert "remove readbehind"

This reverts commit cb83918a3f.
This commit is contained in:
John Cupitt 2017-02-27 10:24:56 +00:00
parent b08e8cba78
commit 98f5421c10
13 changed files with 81 additions and 49 deletions

2
TODO
View File

@ -12,7 +12,9 @@
same for fatstrip ... would it be less than tile-height?
the readbehind option to many loaders is no longer needed
check pforeign.h
- vips linecache has access there twice!

View File

@ -111,7 +111,7 @@ jpeg2vips( const char *name, IMAGE *out, gboolean header_only )
#ifdef HAVE_JPEG
if( vips__jpeg_read_file( filename, out,
header_only, shrink, fail_on_warn, FALSE ) )
header_only, shrink, fail_on_warn, TRUE, FALSE ) )
return( -1 );
#else
vips_error( "im_jpeg2vips",

View File

@ -87,7 +87,7 @@ png2vips( const char *name, IMAGE *out, gboolean header_only )
return( -1 );
}
else {
if( vips__png_read( filename, out ) )
if( vips__png_read( filename, out, TRUE ) )
return( -1 );
}
#else

View File

@ -98,7 +98,7 @@ tiff2vips( const char *name, IMAGE *out, gboolean header_only )
return( -1 );
}
else {
if( vips__tiff_read( filename, out, page, 1, FALSE ) )
if( vips__tiff_read( filename, out, page, 1, FALSE, TRUE ) )
return( -1 );
}
#else

View File

@ -152,6 +152,10 @@ typedef struct _ReadJpeg {
*/
gboolean fail;
/* Use a read behind buffer.
*/
gboolean readbehind;
/* Used for file input only.
*/
char *filename;
@ -212,7 +216,8 @@ readjpeg_close( VipsObject *object, ReadJpeg *jpeg )
}
static ReadJpeg *
readjpeg_new( VipsImage *out, int shrink, gboolean fail, gboolean autorotate )
readjpeg_new( VipsImage *out,
int shrink, gboolean fail, gboolean readbehind, gboolean autorotate )
{
ReadJpeg *jpeg;
@ -222,6 +227,7 @@ readjpeg_new( VipsImage *out, int shrink, gboolean fail, gboolean autorotate )
jpeg->out = out;
jpeg->shrink = shrink;
jpeg->fail = fail;
jpeg->readbehind = readbehind;
jpeg->filename = NULL;
jpeg->cinfo.err = jpeg_std_error( &jpeg->eman.pub );
jpeg->eman.pub.error_exit = vips__new_error_exit;
@ -738,12 +744,13 @@ vips__jpeg_read( ReadJpeg *jpeg, VipsImage *out, gboolean header_only )
*/
int
vips__jpeg_read_file( const char *filename, VipsImage *out,
gboolean header_only, int shrink, gboolean fail, gboolean autorotate )
gboolean header_only, int shrink, gboolean fail, gboolean readbehind,
gboolean autorotate )
{
ReadJpeg *jpeg;
if( !(jpeg = readjpeg_new( out,
shrink, fail, autorotate )) )
shrink, fail, readbehind, autorotate )) )
return( -1 );
/* Here for longjmp() from vips__new_error_exit() during startup.
@ -944,12 +951,13 @@ readjpeg_buffer (ReadJpeg *jpeg, const void *buf, size_t len)
int
vips__jpeg_read_buffer( const void *buf, size_t len, VipsImage *out,
gboolean header_only, int shrink, int fail, gboolean autorotate )
gboolean header_only, int shrink, int fail, gboolean readbehind,
gboolean autorotate )
{
ReadJpeg *jpeg;
if( !(jpeg = readjpeg_new( out,
shrink, fail, autorotate )) )
shrink, fail, readbehind, autorotate )) )
return( -1 );
if( setjmp( jpeg->eman.jmp ) )

View File

@ -182,7 +182,7 @@ vips_foreign_load_jpeg_file_header( VipsForeignLoad *load )
VipsForeignLoadJpegFile *file = (VipsForeignLoadJpegFile *) load;
if( vips__jpeg_read_file( file->filename, load->out,
TRUE, jpeg->shrink, load->fail, jpeg->autorotate ) )
TRUE, jpeg->shrink, load->fail, FALSE, jpeg->autorotate ) )
return( -1 );
return( 0 );
@ -195,7 +195,8 @@ vips_foreign_load_jpeg_file_load( VipsForeignLoad *load )
VipsForeignLoadJpegFile *file = (VipsForeignLoadJpegFile *) load;
if( vips__jpeg_read_file( file->filename, load->real,
FALSE, jpeg->shrink, load->fail, jpeg->autorotate ) )
FALSE, jpeg->shrink, load->fail,
load->access == VIPS_ACCESS_SEQUENTIAL, jpeg->autorotate ) )
return( -1 );
return( 0 );
@ -261,7 +262,8 @@ vips_foreign_load_jpeg_buffer_header( VipsForeignLoad *load )
VipsForeignLoadJpegBuffer *buffer = (VipsForeignLoadJpegBuffer *) load;
if( vips__jpeg_read_buffer( buffer->buf->data, buffer->buf->length,
load->out, TRUE, jpeg->shrink, load->fail, jpeg->autorotate ) )
load->out, TRUE, jpeg->shrink, load->fail, FALSE,
jpeg->autorotate ) )
return( -1 );
return( 0 );
@ -274,7 +276,8 @@ vips_foreign_load_jpeg_buffer_load( VipsForeignLoad *load )
VipsForeignLoadJpegBuffer *buffer = (VipsForeignLoadJpegBuffer *) load;
if( vips__jpeg_read_buffer( buffer->buf->data, buffer->buf->length,
load->real, FALSE, jpeg->shrink, load->fail, jpeg->autorotate ) )
load->real, FALSE, jpeg->shrink, load->fail,
load->access == VIPS_ACCESS_SEQUENTIAL, jpeg->autorotate ) )
return( -1 );
return( 0 );

View File

@ -68,7 +68,7 @@ int vips__tiff_write_buf( VipsImage *in,
int vips__tiff_read_header( const char *filename, VipsImage *out,
int page, int n, gboolean autorotate );
int vips__tiff_read( const char *filename, VipsImage *out,
int page, int n, gboolean autorotate );
int page, int n, gboolean autorotate, gboolean readbehind );
gboolean vips__istiff( const char *filename );
gboolean vips__istifftiled( const char *filename );
@ -79,7 +79,7 @@ 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 page, int n, gboolean autorotate );
int vips__tiff_read_buffer( const void *buf, size_t len, VipsImage *out,
int page, int n, gboolean autorotate );
int page, int n, gboolean autorotate, gboolean readbehind );
extern const char *vips__foreign_tiff_suffs[];
@ -149,7 +149,7 @@ int vips__ppm_save( VipsImage *in, const char *filename,
int vips__rad_israd( const char *filename );
int vips__rad_header( const char *filename, VipsImage *out );
int vips__rad_load( const char *filename, VipsImage *out );
int vips__rad_load( const char *filename, VipsImage *out, gboolean readbehind );
int vips__rad_save( VipsImage *in, const char *filename );
int vips__rad_save_buf( VipsImage *in, void **obuf, size_t *olen );
@ -172,18 +172,21 @@ int vips__jpeg_write_buffer( VipsImage *in,
int vips__isjpeg_buffer( const void *buf, size_t len );
int vips__isjpeg( const char *filename );
int vips__jpeg_read_file( const char *name, VipsImage *out,
gboolean header_only, int shrink, gboolean fail, gboolean autorotate );
gboolean header_only, int shrink, gboolean fail, gboolean readbehind,
gboolean autorotate );
int vips__jpeg_read_buffer( const void *buf, size_t len, VipsImage *out,
gboolean header_only, int shrink, int fail, gboolean autorotate );
gboolean header_only, int shrink, int fail, gboolean readbehind,
gboolean autorotate );
int vips__png_header( const char *name, VipsImage *out );
int vips__png_read( const char *name, VipsImage *out );
int vips__png_read( const char *name, VipsImage *out, gboolean readbehind );
gboolean vips__png_ispng_buffer( const void *buf, size_t len );
int vips__png_ispng( const char *filename );
gboolean vips__png_isinterlaced( const char *filename );
gboolean vips__png_isinterlaced_buffer( const void *buffer, size_t length );
extern const char *vips__png_suffs[];
int vips__png_read_buffer( const void *buffer, size_t length, VipsImage *out );
int vips__png_read_buffer( const void *buffer, size_t length,
VipsImage *out, gboolean readbehind );
int vips__png_header_buffer( const void *buffer, size_t length,
VipsImage *out );

View File

@ -106,7 +106,8 @@ vips_foreign_load_png_load( VipsForeignLoad *load )
{
VipsForeignLoadPng *png = (VipsForeignLoadPng *) load;
if( vips__png_read( png->filename, load->real ) )
if( vips__png_read( png->filename, load->real,
load->access == VIPS_ACCESS_SEQUENTIAL ) )
return( -1 );
return( 0 );
@ -201,7 +202,7 @@ vips_foreign_load_png_buffer_load( VipsForeignLoad *load )
VipsForeignLoadPngBuffer *buffer = (VipsForeignLoadPngBuffer *) load;
if( vips__png_read_buffer( buffer->buf->data, buffer->buf->length,
load->real ) )
load->real, load->access == VIPS_ACCESS_SEQUENTIAL ) )
return( -1 );
return( 0 );

View File

@ -1134,7 +1134,7 @@ rad2vips_generate( VipsRegion *or,
}
int
vips__rad_load( const char *filename, VipsImage *out )
vips__rad_load( const char *filename, VipsImage *out, gboolean readbehind )
{
VipsImage **t = (VipsImage **)
vips_object_local_array( VIPS_OBJECT( out ), 3 );

View File

@ -100,7 +100,8 @@ vips_foreign_load_rad_load( VipsForeignLoad *load )
{
VipsForeignLoadRad *rad = (VipsForeignLoadRad *) load;
if( vips__rad_load( rad->filename, load->real ) )
if( vips__rad_load( rad->filename, load->real,
load->access == VIPS_ACCESS_SEQUENTIAL ) )
return( -1 );
return( 0 );

View File

@ -274,6 +274,7 @@ typedef struct _Rtiff {
int page;
int n;
gboolean autorotate;
gboolean readbehind;
/* The TIFF we read.
*/
@ -1964,7 +1965,8 @@ rtiff_close( VipsObject *object, Rtiff *rtiff )
}
static Rtiff *
rtiff_new( VipsImage *out, int page, int n, gboolean autorotate )
rtiff_new( VipsImage *out,
int page, int n, gboolean autorotate, gboolean readbehind )
{
Rtiff *rtiff;
@ -1976,6 +1978,7 @@ rtiff_new( VipsImage *out, int page, int n, gboolean autorotate )
rtiff->page = page;
rtiff->n = n;
rtiff->autorotate = autorotate;
rtiff->readbehind = readbehind;
rtiff->tiff = NULL;
rtiff->current_page = -1;
rtiff->sfn = NULL;
@ -2180,11 +2183,11 @@ rtiff_header_read_all( Rtiff *rtiff )
static Rtiff *
rtiff_new_filename( const char *filename, VipsImage *out,
int page, int n, gboolean autorotate )
int page, int n, gboolean autorotate, gboolean readbehind )
{
Rtiff *rtiff;
if( !(rtiff = rtiff_new( out, page, n, autorotate )) ||
if( !(rtiff = rtiff_new( out, page, n, autorotate, readbehind )) ||
!(rtiff->tiff = vips__tiff_openin( filename )) ||
rtiff_header_read_all( rtiff ) )
return( NULL );
@ -2196,11 +2199,11 @@ rtiff_new_filename( const char *filename, VipsImage *out,
static Rtiff *
rtiff_new_buffer( const void *buf, size_t len, VipsImage *out,
int page, int n, gboolean autorotate )
int page, int n, gboolean autorotate, gboolean readbehind )
{
Rtiff *rtiff;
if( !(rtiff = rtiff_new( out, page, n, autorotate )) ||
if( !(rtiff = rtiff_new( out, page, n, autorotate, readbehind )) ||
!(rtiff->tiff = vips__tiff_openin_buffer( out, buf, len )) ||
rtiff_header_read_all( rtiff ) )
return( NULL );
@ -2231,7 +2234,7 @@ istiffpyramid( const char *name )
int
vips__tiff_read( const char *filename, VipsImage *out,
int page, int n, gboolean autorotate )
int page, int n, gboolean autorotate, gboolean readbehind )
{
Rtiff *rtiff;
@ -2242,7 +2245,8 @@ vips__tiff_read( const char *filename, VipsImage *out,
vips__tiff_init();
if( !(rtiff = rtiff_new_filename( filename, out, page, n, autorotate )) )
if( !(rtiff = rtiff_new_filename( filename,
out, page, n, autorotate, readbehind )) )
return( -1 );
if( rtiff->header.tiled ) {
@ -2288,7 +2292,8 @@ vips__tiff_read_header( const char *filename, VipsImage *out,
vips__tiff_init();
if( !(rtiff = rtiff_new_filename( filename, out, page, n, autorotate )) )
if( !(rtiff = rtiff_new_filename( filename, out,
page, n, autorotate, FALSE )) )
return( -1 );
if( rtiff_set_header( rtiff, out ) )
@ -2356,7 +2361,8 @@ vips__tiff_read_header_buffer( const void *buf, size_t len, VipsImage *out,
vips__tiff_init();
if( !(rtiff = rtiff_new_buffer( buf, len, out, page, n, autorotate )) )
if( !(rtiff = rtiff_new_buffer( buf, len, out,
page, n, autorotate, FALSE )) )
return( -1 );
if( rtiff_set_header( rtiff, out ) )
@ -2369,7 +2375,8 @@ vips__tiff_read_header_buffer( const void *buf, size_t len, VipsImage *out,
int
vips__tiff_read_buffer( const void *buf, size_t len,
VipsImage *out, int page, int n, gboolean autorotate )
VipsImage *out, int page, int n, gboolean autorotate,
gboolean readbehind )
{
Rtiff *rtiff;
@ -2380,7 +2387,8 @@ vips__tiff_read_buffer( const void *buf, size_t len,
vips__tiff_init();
if( !(rtiff = rtiff_new_buffer( buf, len, out, page, n, autorotate )) )
if( !(rtiff = rtiff_new_buffer( buf, len, out,
page, n, autorotate, readbehind )) )
return( -1 );
if( rtiff->header.tiled ) {

View File

@ -183,7 +183,8 @@ vips_foreign_load_tiff_file_load( VipsForeignLoad *load )
VipsForeignLoadTiffFile *file = (VipsForeignLoadTiffFile *) load;
if( vips__tiff_read( file->filename, load->real,
tiff->page, tiff->n, tiff->autorotate ) )
tiff->page, tiff->n, tiff->autorotate,
load->access == VIPS_ACCESS_SEQUENTIAL ) )
return( -1 );
return( 0 );
@ -283,7 +284,8 @@ vips_foreign_load_tiff_buffer_load( VipsForeignLoad *load )
if( vips__tiff_read_buffer(
buffer->buf->data, buffer->buf->length, load->real,
tiff->page, tiff->n, tiff->autorotate ) )
tiff->page, tiff->n, tiff->autorotate,
load->access == VIPS_ACCESS_SEQUENTIAL ) )
return( -1 );
return( 0 );

View File

@ -138,6 +138,7 @@ user_warning_function( png_structp png_ptr, png_const_charp warning_msg )
typedef struct {
char *name;
VipsImage *out;
gboolean readbehind;
int y_pos;
png_structp pPng;
@ -174,7 +175,7 @@ read_close_cb( VipsImage *out, Read *read )
}
static Read *
read_new( VipsImage *out )
read_new( VipsImage *out, gboolean readbehind )
{
Read *read;
@ -182,6 +183,7 @@ read_new( VipsImage *out )
return( NULL );
read->name = NULL;
read->readbehind = readbehind;
read->out = out;
read->y_pos = 0;
read->pPng = NULL;
@ -219,11 +221,11 @@ read_new( VipsImage *out )
}
static Read *
read_new_filename( VipsImage *out, const char *name )
read_new_filename( VipsImage *out, const char *name, gboolean readbehind )
{
Read *read;
if( !(read = read_new( out )) )
if( !(read = read_new( out, readbehind )) )
return( NULL );
read->name = vips_strdup( VIPS_OBJECT( out ), name );
@ -426,7 +428,7 @@ vips__png_header( const char *name, VipsImage *out )
{
Read *read;
if( !(read = read_new_filename( out, name )) ||
if( !(read = read_new_filename( out, name, FALSE )) ||
png2vips_header( read, out ) )
return( -1 );
@ -555,7 +557,7 @@ vips__png_isinterlaced( const char *filename )
int interlace_type;
image = vips_image_new();
if( !(read = read_new_filename( image, filename )) ) {
if( !(read = read_new_filename( image, filename, FALSE )) ) {
g_object_unref( image );
return( -1 );
}
@ -599,7 +601,7 @@ png2vips_image( Read *read, VipsImage *out )
}
int
vips__png_read( const char *filename, VipsImage *out )
vips__png_read( const char *filename, VipsImage *out, gboolean readbehind )
{
Read *read;
@ -607,7 +609,7 @@ vips__png_read( const char *filename, VipsImage *out )
printf( "vips__png_read: reading \"%s\"\n", filename );
#endif /*DEBUG*/
if( !(read = read_new_filename( out, filename )) ||
if( !(read = read_new_filename( out, filename, readbehind )) ||
png2vips_image( read, out ) )
return( -1 );
@ -654,11 +656,12 @@ vips_png_read_buffer( png_structp pPng, png_bytep data, png_size_t length )
}
static Read *
read_new_buffer( VipsImage *out, const void *buffer, size_t length )
read_new_buffer( VipsImage *out, const void *buffer, size_t length,
gboolean readbehind )
{
Read *read;
if( !(read = read_new( out )) )
if( !(read = read_new( out, readbehind )) )
return( NULL );
read->length = length;
@ -684,7 +687,7 @@ vips__png_header_buffer( const void *buffer, size_t length, VipsImage *out )
{
Read *read;
if( !(read = read_new_buffer( out, buffer, length )) ||
if( !(read = read_new_buffer( out, buffer, length, FALSE )) ||
png2vips_header( read, out ) )
return( -1 );
@ -692,11 +695,12 @@ vips__png_header_buffer( const void *buffer, size_t length, VipsImage *out )
}
int
vips__png_read_buffer( const void *buffer, size_t length, VipsImage *out )
vips__png_read_buffer( const void *buffer, size_t length, VipsImage *out,
gboolean readbehind )
{
Read *read;
if( !(read = read_new_buffer( out, buffer, length )) ||
if( !(read = read_new_buffer( out, buffer, length, readbehind )) ||
png2vips_image( read, out ) )
return( -1 );
@ -715,7 +719,7 @@ vips__png_isinterlaced_buffer( const void *buffer, size_t length )
image = vips_image_new();
if( !(read = read_new_buffer( image, buffer, length )) ) {
if( !(read = read_new_buffer( image, buffer, length, FALSE )) ) {
g_object_unref( image );
return( -1 );
}