small dzsave cleanups

- rename compression_level as deflate_level to match libgsf convention
- use libgsf enums for GSF_ZIP_STORED, etc.
- configure-time checks for zip64 and deflate-level
- off-topic: rename NEED_TYPE_INIT as HAVE_TYPE_INIT for consistency
This commit is contained in:
John Cupitt 2016-06-09 09:36:37 +01:00
parent 8cd3d18caf
commit 98bceec23f
3 changed files with 42 additions and 42 deletions

View File

@ -376,7 +376,7 @@ PKG_CHECK_MODULES(THREADS, glib-2.0 >= 2.32,
# with 2.36 and after the type system inits itself # with 2.36 and after the type system inits itself
PKG_CHECK_MODULES(TYPE_INIT, glib-2.0 < 2.36, PKG_CHECK_MODULES(TYPE_INIT, glib-2.0 < 2.36,
[AC_DEFINE(NEED_TYPE_INIT,1,[define if your glib needs g_type_init().]) [AC_DEFINE(HAVE_TYPE_INIT,1,[define if your glib needs g_type_init().])
], ],
[: [:
] ]
@ -401,6 +401,16 @@ if test x"$with_gsf" != "xno"; then
with_gsf=no with_gsf=no
] ]
) )
# zip64 and deflate-level came in .31
PKG_CHECK_MODULES(GSF_ZIP64, libgsf-1 >= 1.14.31,
[AC_DEFINE(HAVE_GSF_ZIP64,1,[define if your libgsf supports zip64.])
AC_DEFINE(HAVE_GSF_DEFLATE_LEVEL,1,
[define if your libgsf supports deflate-level.])
],
[:
]
)
fi fi
AC_ARG_WITH([fftw], AC_ARG_WITH([fftw],

View File

@ -149,14 +149,6 @@
#include <vips/vips.h> #include <vips/vips.h>
#include <vips/internal.h> #include <vips/internal.h>
#define VIPS_ZIP_STORE 0
#define VIPS_ZIP_DEFLATE 8
#define VIPS_ZIP_DEFAULT_COMPRESSION -1
/* libgsf before 1.14.31 did not support deflate-level.
*/
#define vips_gsf_has_zip64 vips_gsf_has_deflate_level
/* Track this during property save. /* Track this during property save.
*/ */
typedef struct _WriteInfo { typedef struct _WriteInfo {
@ -295,11 +287,11 @@ vips__make_xml_metadata( const char *domain, VipsImage *image )
/* Round N down to P boundary. /* Round N down to P boundary.
*/ */
#define ROUND_DOWN(N,P) ((N) - ((N) % P)) #define ROUND_DOWN( N, P ) ((N) - ((N) % P))
/* Round N up to P boundary. /* Round N up to P boundary.
*/ */
#define ROUND_UP(N,P) (ROUND_DOWN( (N) + (P) - 1, (P) )) #define ROUND_UP( N, P ) (ROUND_DOWN( (N) + (P) - 1, (P) ))
/* Simple wrapper around libgsf. /* Simple wrapper around libgsf.
* *
@ -334,7 +326,7 @@ typedef struct _VipsGsfDirectory {
/* Set deflate compression level for zip container. /* Set deflate compression level for zip container.
*/ */
gint compression_level; gint deflate_level;
} VipsGsfDirectory; } VipsGsfDirectory;
@ -393,7 +385,7 @@ vips_gsf_tree_free( VipsGsfDirectory *tree )
/* Make a new tree root. /* Make a new tree root.
*/ */
static VipsGsfDirectory * static VipsGsfDirectory *
vips_gsf_tree_new( GsfOutput *out, gint compression_level ) vips_gsf_tree_new( GsfOutput *out, gint deflate_level )
{ {
VipsGsfDirectory *tree = g_new( VipsGsfDirectory, 1 ); VipsGsfDirectory *tree = g_new( VipsGsfDirectory, 1 );
@ -402,7 +394,7 @@ vips_gsf_tree_new( GsfOutput *out, gint compression_level )
tree->children = NULL; tree->children = NULL;
tree->out = out; tree->out = out;
tree->container = NULL; tree->container = NULL;
tree->compression_level = compression_level; tree->deflate_level = deflate_level;
return( tree ); return( tree );
} }
@ -439,13 +431,13 @@ vips_gsf_dir_new( VipsGsfDirectory *parent, const char *name )
dir->name = g_strdup( name ); dir->name = g_strdup( name );
dir->children = NULL; dir->children = NULL;
dir->container = NULL; dir->container = NULL;
dir->compression_level = parent->compression_level; dir->deflate_level = parent->deflate_level;
if( GSF_IS_OUTFILE_ZIP( parent->out ) ) if( GSF_IS_OUTFILE_ZIP( parent->out ) )
dir->out = gsf_outfile_new_child_full( dir->out = gsf_outfile_new_child_full(
(GsfOutfile *) parent->out, (GsfOutfile *) parent->out,
name, TRUE, name, TRUE,
"compression-level", VIPS_ZIP_STORE, "compression-level", GSF_ZIP_STORED,
NULL ); NULL );
else else
dir->out = gsf_outfile_new_child( dir->out = gsf_outfile_new_child(
@ -485,24 +477,28 @@ vips_gsf_path( VipsGsfDirectory *tree, const char *name, ... )
va_end( ap ); va_end( ap );
if( GSF_IS_OUTFILE_ZIP( dir->out ) ) { if( GSF_IS_OUTFILE_ZIP( dir->out ) ) {
if( dir->compression_level == 0 ) /* Confusingly, libgsf compression-level really means
* compression-method. They have a separate deflate-level
* property for the deflate compression level.
*/
if( dir->deflate_level == 0 )
obj = gsf_outfile_new_child_full( obj = gsf_outfile_new_child_full(
(GsfOutfile *) dir->out, (GsfOutfile *) dir->out,
name, FALSE, name, FALSE,
"compression-level", VIPS_ZIP_STORE, "compression-level", GSF_ZIP_STORED,
NULL ); NULL );
else if( dir->compression_level == VIPS_ZIP_DEFAULT_COMPRESSION ) else if( dir->deflate_level == -1 )
obj = gsf_outfile_new_child_full( obj = gsf_outfile_new_child_full(
(GsfOutfile *) dir->out, (GsfOutfile *) dir->out,
name, FALSE, name, FALSE,
"compression-level", VIPS_ZIP_DEFLATE, "compression-level", GSF_ZIP_DEFLATED,
NULL ); NULL );
else else
obj = gsf_outfile_new_child_full( obj = gsf_outfile_new_child_full(
(GsfOutfile *) dir->out, (GsfOutfile *) dir->out,
name, FALSE, name, FALSE,
"compression-level", VIPS_ZIP_DEFLATE, "compression-level", GSF_ZIP_DEFLATED,
"deflate-level", dir->compression_level, "deflate-level", dir->deflate_level,
NULL ); NULL );
} }
else else
@ -512,16 +508,6 @@ vips_gsf_path( VipsGsfDirectory *tree, const char *name, ... )
return( obj ); return( obj );
} }
/* libgsf before 1.14.31 did not support zip64.
*/
static gboolean
vips_gsf_has_zip64( void )
{
return( libgsf_major_version > 1 ||
libgsf_minor_version > 14 ||
libgsf_micro_version >= 31 );
}
typedef struct _VipsForeignSaveDz VipsForeignSaveDz; typedef struct _VipsForeignSaveDz VipsForeignSaveDz;
typedef struct _Layer Layer; typedef struct _Layer Layer;
@ -1261,7 +1247,8 @@ strip_work( VipsThreadState *state, void *a )
x = t; x = t;
} }
/* Hopefully no one will want the same metadata on all the tiles. /* Hopefully, no one will want the same metadata on all the tiles.
* Strip them.
*/ */
vips_image_set_int( x, "hide-progress", 1 ); vips_image_set_int( x, "hide-progress", 1 );
if( vips_image_write_to_buffer( x, dz->suffix, &buf, &len, if( vips_image_write_to_buffer( x, dz->suffix, &buf, &len,
@ -1295,12 +1282,12 @@ strip_work( VipsThreadState *state, void *a )
return( -1 ); return( -1 );
} }
#ifndef HAVE_GSF_ZIP64
/* Allow a 100,000 byte margin. This probably isn't enough: we don't /* Allow a 100,000 byte margin. This probably isn't enough: we don't
* include the space zip needs for the index nor anything we are * include the space zip needs for the index nor anything we are
* outputting apart from the gsf_output_write() above. * outputting apart from the gsf_output_write() above.
*/ */
if( dz->container == VIPS_FOREIGN_DZ_CONTAINER_ZIP && if( dz->container == VIPS_FOREIGN_DZ_CONTAINER_ZIP &&
!vips_gsf_has_zip64() &&
dz->bytes_written > (size_t) UINT_MAX - 100000 ) { dz->bytes_written > (size_t) UINT_MAX - 100000 ) {
g_mutex_unlock( vips__global_lock ); g_mutex_unlock( vips__global_lock );
@ -1308,6 +1295,7 @@ strip_work( VipsThreadState *state, void *a )
"%s", _( "output file too large" ) ); "%s", _( "output file too large" ) );
return( -1 ); return( -1 );
} }
#endif /*HAVE_GSF_ZIP64*/
g_mutex_unlock( vips__global_lock ); g_mutex_unlock( vips__global_lock );
@ -1905,15 +1893,17 @@ vips_foreign_save_dz_build( VipsObject *object )
*/ */
out2 = gsf_outfile_new_child_full( (GsfOutfile *) zip, out2 = gsf_outfile_new_child_full( (GsfOutfile *) zip,
dz->basename, TRUE, dz->basename, TRUE,
"compression-level", VIPS_ZIP_STORE, "compression-level", GSF_ZIP_STORED,
NULL ); NULL );
if( dz->compression > 0 && !vips_gsf_has_deflate_level() ) { #ifndef HAVE_GSF_DEFLATE_LEVEL
vips_warn( "VipsDzSave", if( dz->compression > 0 ) {
"%s", vips_warn( class->nickname, "%s",
_( "libgsf too old, using default compression" ) ); _( "deflate-level not supported, using 0" ) );
dz->compression = VIPS_ZIP_DEFAULT_COMPRESSION; dz->compression = 0;
} }
#endif
dz->tree = vips_gsf_tree_new( out2, dz->compression ); dz->tree = vips_gsf_tree_new( out2, dz->compression );
/* Note the thing that will need closing up on exit. /* Note the thing that will need closing up on exit.

View File

@ -277,11 +277,11 @@ vips_init( const char *argv0 )
return( 0 ); return( 0 );
started = TRUE; started = TRUE;
#ifdef NEED_TYPE_INIT #ifdef HAVE_TYPE_INIT
/* Before glib 2.36 you have to call this on startup. /* Before glib 2.36 you have to call this on startup.
*/ */
g_type_init(); g_type_init();
#endif /*NEED_TYPE_INIT*/ #endif /*HAVE_TYPE_INIT*/
/* Older glibs need this. /* Older glibs need this.
*/ */