Merge remote-tracking branch 'origin/dzsave'

Conflicts:
	ChangeLog
This commit is contained in:
John Cupitt 2012-03-26 22:12:19 +01:00
commit d930b69161
9 changed files with 788 additions and 1 deletions

View File

@ -3,6 +3,7 @@
- sanity-check PNG read geometry
- nearest-neighbor interpolation rounds coordinates to nearest instead of
rounding down (thanks Nicolas)
- add dzsave, save in deep zoom format
13/3/12 started 7.28.2
- xres/yres tiffsave args were broken

View File

@ -501,3 +501,66 @@ $2])
CPPFLAGS="$save_CPPFLAGS"
])
dnl @synopsis AC_FUNC_MKDIR
dnl
dnl Check whether mkdir() is mkdir or _mkdir, and whether it takes one
dnl or two arguments.
dnl
dnl This macro can define HAVE_MKDIR, HAVE__MKDIR, and
dnl MKDIR_TAKES_ONE_ARG, which are expected to be used as follows:
dnl
dnl #if HAVE_MKDIR
dnl # if MKDIR_TAKES_ONE_ARG
dnl /* MinGW32 */
dnl # define mkdir(a, b) mkdir(a)
dnl # endif
dnl #else
dnl # if HAVE__MKDIR
dnl /* plain Windows 32 */
dnl # define mkdir(a, b) _mkdir(a)
dnl # else
dnl # error "Don't know how to create a directory on this system."
dnl # endif
dnl #endif
dnl
dnl @category C
dnl @author Alexandre Duret-Lutz <adl@gnu.org>
dnl @version 2003-12-28
dnl @license GPLWithACException
AC_DEFUN([AC_FUNC_MKDIR],
[AC_CHECK_FUNCS([mkdir _mkdir])
AC_CACHE_CHECK([whether mkdir takes one argument],
[ac_cv_mkdir_takes_one_arg],
[AC_TRY_COMPILE([
#include <sys/stat.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
], [mkdir (".");],
[ac_cv_mkdir_takes_one_arg=yes], [ac_cv_mkdir_takes_one_arg=no])])
if test x"$ac_cv_mkdir_takes_one_arg" = xyes; then
AC_DEFINE([MKDIR_TAKES_ONE_ARG], 1,
[Define if mkdir takes only one argument.])
fi
])
dnl Note:
dnl =====
dnl I have not implemented the following suggestion because I don't have
dnl access to such a broken environment to test the macro. So I'm just
dnl appending the comments here in case you have, and want to fix
dnl AC_FUNC_MKDIR that way.
dnl
dnl |Thomas E. Dickey (dickey@herndon4.his.com) said:
dnl | it doesn't cover the problem areas (compilers that mistreat mkdir
dnl | may prototype it in dir.h and dirent.h, for instance).
dnl |
dnl |Alexandre:
dnl | Would it be sufficient to check for these headers and #include
dnl | them in the AC_TRY_COMPILE block? (and is AC_HEADER_DIRENT
dnl | suitable for this?)
dnl |
dnl |Thomas:
dnl | I think that might be a good starting point (with the set of recommended
dnl | ifdef's and includes for AC_HEADER_DIRENT, of course).

View File

@ -305,6 +305,7 @@ AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_FUNC_MKDIR
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([getcwd gettimeofday getwd memset munmap putenv realpath strcasecmp strchr strcspn strdup strerror strrchr strspn vsnprintf realpath mkstemp mktemp random rand sysconf atexit])
AC_CHECK_LIB(m,cbrt,[AC_DEFINE(HAVE_CBRT,1,[have cbrt() in libm.])])

View File

@ -13,6 +13,7 @@ libforeign_la_SOURCES = \
csv.c \
csvload.c \
csvsave.c \
dzsave.c \
rawload.c \
rawsave.c \
vipsload.c \

632
libvips/foreign/dzsave.c Normal file
View File

@ -0,0 +1,632 @@
/* save to deep zoom format
*
* 21/3/12
* - from the tiff pyramid writer
- need to copy overlap down strips
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
/*
#define DEBUG_VERBOSE
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vips/vips.h>
typedef struct _VipsForeignSaveDz VipsForeignSaveDz;
typedef struct _Layer Layer;
/* A layer in the pyramid.
*/
struct _Layer {
VipsForeignSaveDz *dz;
VipsImage *image; /* The image we build */
VipsRegion *strip; /* The current strip of pixels */
VipsRegion *copy; /* Pixels we copy to the next strip */
int sub; /* Subsample factor for this layer */
int n; /* Layer number ... 0 for smallest */
Layer *below; /* Tiles go to here */
Layer *above; /* Tiles come from here */
};
struct _VipsForeignSaveDz {
VipsForeignSave parent_object;
/* Directory to create and write to.
*/
char *dirname;
char *suffix;
int overlap;
int tile_width;
int tile_height;
Layer *layer; /* x2 shrink pyr layer */
};
typedef VipsForeignSaveClass VipsForeignSaveDzClass;
G_DEFINE_TYPE( VipsForeignSaveDz, vips_foreign_save_dz,
VIPS_TYPE_FOREIGN_SAVE );
/* Free a pyramid.
*/
static void
layer_free( Layer *layer )
{
VIPS_FREEF( g_object_unref, layer->strip );
VIPS_FREEF( g_object_unref, layer->copy );
VIPS_FREEF( g_object_unref, layer->image );
VIPS_FREEF( layer_free, layer->below );
}
static void
vips_foreign_save_dz_dispose( GObject *gobject )
{
VipsForeignSaveDz *dz = (VipsForeignSaveDz *) gobject;
VIPS_FREEF( layer_free, dz->layer );
G_OBJECT_CLASS( vips_foreign_save_dz_parent_class )->dispose( gobject );
}
/* Build a pyramid.
*/
static Layer *
pyramid_build( VipsForeignSaveDz *dz, Layer *above, int w, int h )
{
VipsForeignSave *save = VIPS_FOREIGN_SAVE( dz );
Layer *layer = VIPS_NEW( dz, Layer );
VipsRect strip;
layer->dz = dz;
layer->image = NULL;
layer->strip = NULL;
layer->copy = NULL;
if( !above )
/* Top of pyramid.
*/
layer->sub = 1;
else
layer->sub = above->sub * 2;
layer->below = NULL;
layer->above = above;
layer->image = vips_image_new();
if( vips_image_copy_fields( layer->image, save->ready ) ) {
layer_free( layer );
return( NULL );
}
layer->image->Xsize = w;
layer->image->Ysize = h;
layer->strip = vips_region_new( layer->image );
layer->copy = vips_region_new( layer->image );
/* The regions will get used in the bg thread callback, so make sure
* we don't own them.
*/
vips__region_no_ownership( layer->strip );
vips__region_no_ownership( layer->copy );
/* Build a line of tiles here.
*/
strip.left = 0;
strip.top = 0;
strip.width = w;
strip.height = dz->tile_height + dz->overlap;
if( vips_region_buffer( layer->strip, &strip ) ) {
layer_free( layer );
return( NULL );
}
if( w > dz->tile_width ||
h > dz->tile_height ) {
if( !(layer->below = pyramid_build( dz,
layer, w / 2, h / 2 )) ) {
layer_free( layer );
return( NULL );
}
layer->n = layer->below->n + 1;
}
else
layer->n = 0;
return( layer );
}
static int
pyramid_mkdir( VipsForeignSaveDz *dz )
{
Layer *layer;
if( vips_existsf( "%s", dz->dirname ) ) {
vips_error( "dzsave",
_( "Directory \"%s\" exists" ), dz->dirname );
return( -1 );
}
if( vips_mkdirf( "%s", dz->dirname ) )
return( -1 );
for( layer = dz->layer; layer; layer = layer->below )
if( vips_mkdirf( "%s/%d", dz->dirname, layer->n ) )
return( -1 );
return( 0 );
}
/* Shrink a region by a factor of two, writing the result to a specified
* offset in another region. VIPS_CODING_LABQ only.
*/
static void
shrink_region_labpack( VipsRegion *from, VipsRegion *to )
{
int ls = VIPS_REGION_LSKIP( from );
int x, y;
VipsRect target;
/* Calculate output size and position.
*/
target.left = from->valid.left / 2;
target.top = from->valid.top / 2;
target.width = from->valid.width / 2;
target.height = from->valid.height / 2;
for( y = 0; y < target.height; y++ ) {
VipsPel *p = VIPS_REGION_ADDR( from,
from->valid.left, from->valid.top + y * 2 );
VipsPel *q = VIPS_REGION_ADDR( to,
target.left, target.top + y );
/* Ignore the extra bits for speed.
*/
for( x = 0; x < target.width; x++ ) {
signed char *sp = (signed char *) p;
unsigned char *up = (unsigned char *) p;
int l = up[0] + up[4] +
up[ls] + up[ls + 4];
int a = sp[1] + sp[5] +
sp[ls + 1] + sp[ls + 5];
int b = sp[2] + sp[6] +
sp[ls + 2] + sp[ls + 6];
q[0] = l >> 2;
q[1] = a >> 2;
q[2] = b >> 2;
q[3] = 0;
q += 4;
p += 8;
}
}
}
#define SHRINK_TYPE_INT( TYPE ) \
for( x = 0; x < target.width; x++ ) { \
TYPE *tp = (TYPE *) p; \
TYPE *tp1 = (TYPE *) (p + ls); \
TYPE *tq = (TYPE *) q; \
\
for( z = 0; z < nb; z++ ) { \
int tot = tp[z] + tp[z + nb] + \
tp1[z] + tp1[z + nb]; \
\
tq[z] = tot >> 2; \
} \
\
/* Move on two pels in input. \
*/ \
p += ps << 1; \
q += ps; \
}
#define SHRINK_TYPE_FLOAT( TYPE ) \
for( x = 0; x < target.width; x++ ) { \
TYPE *tp = (TYPE *) p; \
TYPE *tp1 = (TYPE *) (p + ls); \
TYPE *tq = (TYPE *) q; \
\
for( z = 0; z < nb; z++ ) { \
double tot = tp[z] + tp[z + nb] + \
tp1[z] + tp1[z + nb]; \
\
tq[z] = tot / 4; \
} \
\
/* Move on two pels in input. \
*/ \
p += ps << 1; \
q += ps; \
}
/* Shrink a region by a factor of two, writing the result to a specified
* offset in another region. n-band, non-complex.
*/
static void
shrink_region( VipsRegion *from, VipsRegion *to )
{
int ls = VIPS_REGION_LSKIP( from );
int ps = VIPS_IMAGE_SIZEOF_PEL( from->im );
int nb = from->im->Bands;
int x, y, z;
VipsRect target;
/* Calculate output size and position.
*/
target.left = from->valid.left / 2;
target.top = from->valid.top / 2;
target.width = from->valid.width / 2;
target.height = from->valid.height / 2;
for( y = 0; y < target.height; y++ ) {
VipsPel *p = VIPS_REGION_ADDR( from,
from->valid.left, from->valid.top + y * 2 );
VipsPel *q = VIPS_REGION_ADDR( to,
target.left, target.top + y );
/* Process this line of pels.
*/
switch( from->im->BandFmt ) {
case VIPS_FORMAT_UCHAR:
SHRINK_TYPE_INT( unsigned char ); break;
case VIPS_FORMAT_CHAR:
SHRINK_TYPE_INT( signed char ); break;
case VIPS_FORMAT_USHORT:
SHRINK_TYPE_INT( unsigned short ); break;
case VIPS_FORMAT_SHORT:
SHRINK_TYPE_INT( signed short ); break;
case VIPS_FORMAT_UINT:
SHRINK_TYPE_INT( unsigned int ); break;
case VIPS_FORMAT_INT:
SHRINK_TYPE_INT( signed int ); break;
case VIPS_FORMAT_FLOAT:
SHRINK_TYPE_FLOAT( float ); break;
case VIPS_FORMAT_DOUBLE:
SHRINK_TYPE_FLOAT( double ); break;
default:
g_assert( 0 );
}
}
}
/* Write a line of tiles.
*/
static int
strip_save( Layer *layer )
{
VipsForeignSaveDz *dz = layer->dz;
VipsRegion *strip = layer->strip;
int y = strip->valid.top / dz->tile_height;
VipsImage *image;
int x;
if( !(image = vips_image_new_from_memory(
VIPS_REGION_ADDR( strip, 0, strip->valid.top ),
strip->valid.width, strip->valid.height,
strip->im->Bands, strip->im->BandFmt )) )
return( -1 );
for( x = 0; x < strip->valid.width / dz->tile_width; x++ ) {
VipsImage *extr;
VipsRect tile;
char str[1000];
VipsBuf buf = VIPS_BUF_STATIC( str );
tile.left = x * dz->tile_width;
tile.top = strip->valid.top;
tile.width = dz->tile_width + dz->overlap;
tile.height = dz->tile_height + dz->overlap;
vips_rect_intersectrect( &tile, &strip->valid, &tile );
/* Extract relative to the strip top-left corner.
*/
if( vips_extract_area( image, &extr,
tile.left, 0, tile.width, tile.height, NULL ) ) {
g_object_unref( image );
return( -1 );
}
vips_buf_appendf( &buf, "%s/%d/%d_%d%s",
dz->dirname, layer->n,
x, y,
dz->suffix );
if( vips_image_write_to_file( extr, vips_buf_all( &buf ) ) ) {
g_object_unref( image );
g_object_unref( extr );
return( -1 );
}
g_object_unref( extr );
}
g_object_unref( image );
return( 0 );
}
/* A new strip of pixels has arrived!
* - write
* - shrink to the layer below
* - if that's filled, recurse
* - move our strip down ready for more stuff, copying the overlap
*/
static int
strip_arrived( Layer *layer )
{
VipsForeignSaveDz *dz = layer->dz;
VipsForeignSave *save = VIPS_FOREIGN_SAVE( dz );
Layer *below = layer->below;
VipsRect target;
VipsRect new_strip;
VipsRect overlap;
if( strip_save( layer ) )
return( -1 );
/* The pixels we can make on the layer below.
*/
target.left = layer->strip->valid.left / 2;
target.top = layer->strip->valid.top / 2;
target.width = layer->strip->valid.width / 2;
target.height = layer->strip->valid.height / 2;
/* Can have empty strips if this is a 1-pixel high thing at the end.
*/
if( !vips_rect_isempty( &target ) &&
below ) {
/* Shrink into place.
*/
if( save->ready->Coding == VIPS_CODING_NONE )
shrink_region( layer->strip, below->strip );
else
shrink_region_labpack( layer->strip, below->strip );
/* If we've filled the strip of the layer below, recurse.
*/
if( VIPS_RECT_BOTTOM( &target ) ==
VIPS_RECT_BOTTOM( &below->strip->valid ) &&
strip_arrived( below ) )
return( -1 );
}
/* Move our strip down the image.
*/
new_strip.left = 0;
new_strip.top = layer->strip->valid.top + layer->strip->valid.height;
new_strip.width = layer->image->Xsize;
new_strip.height = dz->tile_height + dz->overlap;
vips_rect_intersectrect( &new_strip, &layer->strip->valid, &overlap );
if( !vips_rect_isempty( &overlap ) ) {
/* There are some pixels we need to copy over.
*/
if( vips_region_buffer( layer->copy, &overlap ) )
return( -1 );
vips_region_copy( layer->strip, layer->copy,
&overlap, overlap.left, overlap.top );
}
if( vips_region_buffer( layer->strip, &new_strip ) )
return( -1 );
if( !vips_rect_isempty( &overlap ) )
vips_region_copy( layer->copy, layer->strip,
&overlap, overlap.left, overlap.top );
return( 0 );
}
/* Another strip of image pixels from vips_sink_disc(). Recursively write
* down the pyramid.
*/
static int
pyramid_strip( VipsRegion *region, VipsRect *area, void *a )
{
VipsForeignSaveDz *dz = (VipsForeignSaveDz *) a;
int y;
y = 0;
while( y < area->height ) {
VipsRect overlap;
/* Write what we can into the current top strip.
*/
vips_rect_intersectrect( area, &dz->layer->strip->valid,
&overlap );
vips_region_copy( region, dz->layer->strip,
&overlap, overlap.left, overlap.top );
/* If we've filled the strip, write.
*/
if( VIPS_RECT_BOTTOM( &overlap ) ==
VIPS_RECT_BOTTOM( &dz->layer->strip->valid ) &&
strip_arrived( dz->layer ) )
return( -1 );
y += overlap.height;
}
return( 0 );
}
static int
vips_foreign_save_dz_build( VipsObject *object )
{
VipsForeignSave *save = (VipsForeignSave *) object;
VipsForeignSaveDz *dz = (VipsForeignSaveDz *) object;
if( VIPS_OBJECT_CLASS( vips_foreign_save_dz_parent_class )->
build( object ) )
return( -1 );
/* When we do the /2 shrink we need to be sure that we won't get any
* left-over scan lines.
*/
if( dz->overlap % 2 != 0 ||
dz->tile_width % 2 != 0 ||
dz->tile_height % 2 != 0 ) {
vips_error( "dzsave",
"%s", _( "tile width, height and overlap must all "
"be even" ) );
return( -1 );
}
if( dz->overlap >= dz->tile_width ||
dz->overlap >= dz->tile_height ) {
vips_error( "dzsave",
"%s", _( "overlap must be less than tile "
"width and height" ) ) ;
return( -1 );
}
/* Build the skeleton of the image pyramid.
*/
if( !(dz->layer = pyramid_build( dz,
NULL, save->ready->Xsize, save->ready->Ysize )) )
return( -1 );
if( pyramid_mkdir( dz ) )
return( -1 );
if( vips_sink_disc( save->ready, pyramid_strip, dz ) )
return( -1 );
return( 0 );
}
/* Save a bit of typing.
*/
#define UC VIPS_FORMAT_UCHAR
#define C VIPS_FORMAT_CHAR
#define US VIPS_FORMAT_USHORT
#define S VIPS_FORMAT_SHORT
#define UI VIPS_FORMAT_UINT
#define I VIPS_FORMAT_INT
#define F VIPS_FORMAT_FLOAT
#define X VIPS_FORMAT_COMPLEX
#define D VIPS_FORMAT_DOUBLE
#define DX VIPS_FORMAT_DPCOMPLEX
static int bandfmt_dz[10] = {
/* UC C US S UI I F X D DX */
UC, C, US, S, UI, I, F, F, D, D
};
const char *dz_suffs[] = { ".dz", NULL };
static void
vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsForeignClass *foreign_class = (VipsForeignClass *) class;
VipsForeignSaveClass *save_class = (VipsForeignSaveClass *) class;
gobject_class->dispose = vips_foreign_save_dz_dispose;
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
object_class->nickname = "dzsave";
object_class->description = _( "save image to deep zoom format" );
object_class->build = vips_foreign_save_dz_build;
foreign_class->suffs = dz_suffs;
save_class->saveable = VIPS_SAVEABLE_ANY;
save_class->format_table = bandfmt_dz;
save_class->coding[VIPS_CODING_LABQ] = TRUE;
VIPS_ARG_STRING( class, "dirname", 1,
_( "Directory name" ),
_( "Directory name to save to" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, dirname ),
NULL );
VIPS_ARG_STRING( class, "suffix", 9,
_( "suffix" ),
_( "Filename suffix for tiles" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, suffix ),
".jpg" );
VIPS_ARG_INT( class, "overlap", 10,
_( "Overlap" ),
_( "Tile overlap in pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, overlap ),
0, 1024, 0 );
VIPS_ARG_INT( class, "tile_width", 11,
_( "Tile width" ),
_( "Tile width in pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, tile_width ),
1, 1024, 128 );
VIPS_ARG_INT( class, "tile_height", 12,
_( "Tile height" ),
_( "Tile height in pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, tile_height ),
1, 1024, 128 );
}
static void
vips_foreign_save_dz_init( VipsForeignSaveDz *dz )
{
VIPS_SETSTR( dz->suffix, ".jpg" );
dz->overlap = 0;
dz->tile_width = 128;
dz->tile_height = 128;
}

View File

@ -1574,6 +1574,7 @@ vips_foreign_operation_init( void )
extern GType vips_foreign_save_raw_get_type( void );
extern GType vips_foreign_save_raw_fd_get_type( void );
extern GType vips_foreign_load_magick_get_type( void );
extern GType vips_foreign_save_dz_get_type( void );
vips_foreign_load_rad_get_type();
vips_foreign_save_rad_get_type();
@ -1587,6 +1588,7 @@ vips_foreign_operation_init( void )
vips_foreign_save_raw_fd_get_type();
vips_foreign_load_vips_get_type();
vips_foreign_save_vips_get_type();
vips_foreign_save_dz_get_type();
#ifdef HAVE_PNG
vips_foreign_load_png_get_type();
@ -2299,3 +2301,45 @@ vips_matload( const char *filename, VipsImage **out, ... )
return( result );
}
/**
* vips_dzsave:
* @in: image to save
* @dirname: directory to save to
* @...: %NULL-terminated list of optional named arguments
*
* Optional arguments:
*
* @suffix: suffix for tile tiles (default ".jpg")
* @overlap; set tile overlap
* @tile_width; set tile size
* @tile_height; set tile size
*
* Save an image to a deep zoom - style directory tree.
*
* The image is shrunk in a series of x2 reductions until it fits within a
* tile. Each layer is written out to a separate subdirectory of @dirname,
* with directory "0" holding the smallest, single tile image.
*
* Each tile is written as a separate file named as "@x_@y@suffix", where @x
* and @y are the tile coordinates, with (0, 0) as the top-left tile.
*
* You can set @suffix to something like ".jpg[Q=85]" to set the tile write
* options.
*
* See also: vips_tiffsave().
*
* Returns: 0 on success, -1 on error.
*/
int
vips_dzsave( VipsImage *in, const char *dirname, ... )
{
va_list ap;
int result;
va_start( ap, dirname );
result = vips_call_split( "dzsave", ap, in, dirname );
va_end( ap );
return( result );
}

View File

@ -126,6 +126,8 @@
* 2/12/11
* - make into a simple function call ready to be wrapped as a new-style
* VipsForeign class
* 21/3/12
* - bump max layer buffer up
*/
/*
@ -182,7 +184,7 @@
/* Max no of tiles we buffer in a layer. Enough to buffer a line of 64x64
* tiles on a 100k pixel across image.
*/
#define MAX_LAYER_BUFFER (1000)
#define MAX_LAYER_BUFFER (10000)
/* Bits we OR together for quadrants in a tile.
*/

View File

@ -205,6 +205,8 @@ int vips__seek( int fd, gint64 pos );
int vips__ftruncate( int fd, gint64 pos );
int vips_existsf( const char *name, ... )
__attribute__((format(printf, 1, 2)));
int vips_mkdirf( const char *name, ... )
__attribute__((format(printf, 1, 2)));
FILE *vips_popenf( const char *fmt, const char *mode, ... )
__attribute__((format(printf, 1, 3)));

View File

@ -1168,6 +1168,47 @@ vips_popenf( const char *fmt, const char *mode, ... )
return( fp );
}
/* Handle broken mkdirs()
*/
#if HAVE_MKDIR
# if MKDIR_TAKES_ONE_ARG
/* Mingw32 */
# define mkdir(a,b) mkdir(a)
# endif
#else
# ifdef HAVE__MKDIR
/* plain Win32 */
# include <direct.h>
# define mkdir(a,b) _mkdir(a)
# else
# error "Don't know how to create a directory on this system."
# endif
#endif
/* Make a directory.
*/
int
vips_mkdirf( const char *name, ... )
{
va_list ap;
char buf1[PATH_MAX];
va_start( ap, name );
(void) vips_vsnprintf( buf1, PATH_MAX - 1, name, ap );
va_end( ap );
/* Try that.
*/
if( mkdir( buf1, 0755 ) ) {
vips_error( "mkdirf",
_( "unable to create directory \"%s\", %s" ),
buf1, strerror( errno ) );
return( -1 );
}
return( 0 );
}
/* Break a command-line argument into tokens separated by whitespace.
*
* Strings can't be adjacent, so "hello world" (without quotes) is a single