better vips7 compat

revise the vips7 PNG wrapper to work with libspng, though performance
may be poor

thanks SkyDiverCool

https://github.com/libvips/libvips/issues/2233
This commit is contained in:
John Cupitt 2021-04-30 08:20:19 +01:00
parent 2df5768d99
commit a560d7df50
4 changed files with 21 additions and 74 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
compile
.pytest_cache
.dirstamp
a.out
*.log
*.trs

View File

@ -1,3 +1,6 @@
30/4/21 start 8.10.7
- better vips7 PNG load compatibility [SkyDiverCool]
22/12/20 start 8.10.6
- don't seek on bad file descriptors [kleisauke]
- check for null memory sources [kleisauke]

View File

@ -2,7 +2,7 @@
# also update the version number in the m4 macros below
AC_INIT([vips], [8.10.6], [vipsip@jiscmail.ac.uk])
AC_INIT([vips], [8.10.7], [vipsip@jiscmail.ac.uk])
# required for gobject-introspection
AC_PREREQ(2.62)
@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4])
# user-visible library versioning
m4_define([vips_major_version], [8])
m4_define([vips_minor_version], [10])
m4_define([vips_micro_version], [6])
m4_define([vips_micro_version], [7])
m4_define([vips_version],
[vips_major_version.vips_minor_version.vips_micro_version])
@ -38,7 +38,7 @@ VIPS_VERSION_STRING=$VIPS_VERSION-`date -u -r $srcdir/ChangeLog`
# binary interface changes not backwards compatible?: reset age to 0
LIBRARY_CURRENT=54
LIBRARY_REVISION=7
LIBRARY_REVISION=8
LIBRARY_AGE=12
# patched into include/vips/version.h

View File

@ -48,80 +48,24 @@
#include "../foreign/pforeign.h"
static int
png2vips( const char *name, IMAGE *out, gboolean header_only )
{
char filename[FILENAME_MAX];
char mode[FILENAME_MAX];
char *p, *q;
int seq;
im_filename_split( name, filename, mode );
seq = 0;
p = &mode[0];
if( (q = im_getnextoption( &p )) ) {
if( im_isprefix( "seq", q ) )
seq = 1;
}
/* We need to be compatible with the pre-sequential mode
* im_png2vips(). This returned a "t" if given a "p" image, since it
* used writeline.
*
* If we're writing the image to a "p", switch it to a "t".
*
* Don't do this for header read, since we don't want to force a
* malloc if all we are doing is looking at fields.
*/
if( !header_only &&
!seq &&
out->dtype == VIPS_IMAGE_PARTIAL ) {
if( vips__image_wio_output( out ) )
return( -1 );
}
/* spngload does not define these vips7 compat functions.
*/
#if defined(HAVE_PNG) && !defined(HAVE_SPNG)
{
VipsSource *source;
int result;
if( !(source = vips_source_new_from_file( filename )) )
return( -1 );
if( header_only )
result = vips__png_header_source( source, out );
else
result = vips__png_read_source( source, out, TRUE );
VIPS_UNREF( source );
if( result )
return( result );
}
#else
vips_error( "im_png2vips",
"%s", _( "no PNG support in your libvips" ) );
return( -1 );
#endif /*HAVE_PNG && !HAVE_SPNG*/
return( 0 );
}
int
im_png2vips( const char *name, IMAGE *out )
{
return( png2vips( name, out, FALSE ) );
}
char filename[FILENAME_MAX];
char mode[FILENAME_MAX];
VipsImage *x;
/* By having a separate header func, we get lazy.c to open via disc/mem.
*/
static int
im_png2vips_header( const char *name, IMAGE *out )
{
return( png2vips( name, out, TRUE ) );
im_filename_split( name, filename, mode );
if( vips_pngload( filename, &x, NULL ) )
return( -1 );
if( vips_image_write( x, out ) ) {
VIPS_UNREF( x );
return( -1 );
}
VIPS_UNREF( x );
return( 0 );
}
static int
@ -145,7 +89,6 @@ vips_format_png_class_init( VipsFormatPngClass *class )
object_class->description = _( "PNG" );
format_class->is_a = ispng;
format_class->header = im_png2vips_header;
format_class->load = im_png2vips;
format_class->save = im_vips2png;
format_class->suffs = png_suffs;