From c46f4b15e02741b727a197780e3d58011572bb23 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 26 Jan 2018 15:36:43 +0000 Subject: [PATCH] dzsave to szi sets extension correctly see https://github.com/jcupitt/libvips/issues/852 --- ChangeLog | 1 + libvips/foreign/dzsave.c | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc079a8d..9a79527e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 23/12/17 started 8.7.0 - add magicksave, save image with libMagick [dlemstra] +- dzsave to szi sets suffix correctly [martinweihrauch] 5/1/18 started 8.6.2 - vips_sink_screen() keeps a ref to the input image ... stops a rare race diff --git a/libvips/foreign/dzsave.c b/libvips/foreign/dzsave.c index 44d3ed82..98f4c014 100644 --- a/libvips/foreign/dzsave.c +++ b/libvips/foreign/dzsave.c @@ -527,6 +527,11 @@ struct _VipsForeignSaveDz { */ VipsPel *ink; + /* TRUE if we are writing a .szi file. These are zips with a few + * extra files inside. + */ + gboolean write_szi; + }; typedef VipsForeignSaveClass VipsForeignSaveDzClass; @@ -1857,9 +1862,11 @@ vips_foreign_save_dz_build( VipsObject *object ) /* Output to a file or memory? */ if( dz->dirname ) { - vips_snprintf( name, VIPS_PATH_MAX, "%s/%s.zip", - dz->dirname, dz->basename ); - if( !(dz->out = gsf_output_stdio_new( name, &error )) ) { + const char *suffix = dz->write_szi ? "szi" : "zip"; + vips_snprintf( name, VIPS_PATH_MAX, "%s/%s.%s", + dz->dirname, dz->basename, suffix ); + if( !(dz->out = + gsf_output_stdio_new( name, &error )) ) { vips_g_error( &error ); return( -1 ); } @@ -2176,11 +2183,17 @@ vips_foreign_save_dz_file_build( VipsObject *object ) * container. */ if( (p = strrchr( dz->basename, '.' )) ) { - if( !vips_object_argument_isset( object, "container" ) ) + if( !vips_object_argument_isset( object, "container" ) ) { if( strcasecmp( p + 1, "zip" ) == 0 || strcasecmp( p + 1, "szi" ) == 0 ) dz->container = VIPS_FOREIGN_DZ_CONTAINER_ZIP; + /* Note we are building a .szi object. + */ + if( strcasecmp( p + 1, "szi" ) == 0 ) + dz->write_szi = TRUE; + } + /* Remove any legal suffix. We don't remove all suffixes * since we might be writing to a dirname with a dot in. */