Skip to content

Commit

Permalink
add a vips7 interface to the deepzoom writer
Browse files Browse the repository at this point in the history
  • Loading branch information
jcupitt committed Jun 11, 2013
1 parent 3bffb2a commit 55bfa92
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 70 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- version bump
- oops, VImage.PIL_mode_from_vips() failed for CMYK, thanks Alessandro
- fix no-pango build
- add im_vips2dz(): run the deepzoom writer from vips7

12/3/13 started 7.33.0
- vipsthumbnail lets you specify the sharpening mask
Expand Down
1 change: 1 addition & 0 deletions libvips/deprecated/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ libdeprecated_la_SOURCES = \
im_vips2png.c \
im_vips2ppm.c \
im_vips2tiff.c \
im_vips2dz.c \
matlab.c \
radiance.c \
raw.c
Expand Down
27 changes: 27 additions & 0 deletions libvips/deprecated/format_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ static im_function jpeg2vips_desc = {
jpeg2vips_args /* Arg list */
};

static int
vips2dz_vec( im_object *argv )
{
IMAGE *in = argv[0];
char *out = argv[1];

if( im_vips2dz( in, out ) )
return( -1 );

return( 0 );
}

static im_arg_desc vips2dz_args[] = {
IM_INPUT_IMAGE( "in" ),
IM_INPUT_STRING( "out" )
};

static im_function vips2dz_desc = {
"im_vips2dz", /* Name */
"save as deepzoom", /* Description */
0, /* Flags */
vips2dz_vec, /* Dispatch function */
IM_NUMBER( vips2dz_args ), /* Size of arg list */
vips2dz_args /* Arg list */
};

static int
vips2jpeg_vec( im_object *argv )
{
Expand Down Expand Up @@ -425,6 +451,7 @@ static im_function *list[] = {
&analyze2vips_desc,
&tiff2vips_desc,
&vips2csv_desc,
&vips2dz_desc,
&vips2jpeg_desc,
&vips2mimejpeg_desc,
&vips2png_desc,
Expand Down
100 changes: 100 additions & 0 deletions libvips/deprecated/im_vips2dz.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* vips7 compat stub for vips_dzsave()
*
* 11/6/13
* - from im_vips2tiff()
*/

/*
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., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/

/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/

/* Turn on IM_REGION_ADDR() range checks, don't delete intermediates.
#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>

int
im_vips2dz( IMAGE *in, const char *filename )
{
char *p, *q;
char name[FILENAME_MAX];
char mode[FILENAME_MAX];
char buf[FILENAME_MAX];

VipsForeignDzLayout layout = VIPS_FOREIGN_DZ_LAYOUT_DZ;
char *suffix = ".jpeg";
int overlap = 0;
int tile_size = 256;
VipsForeignDzDepth depth = VIPS_FOREIGN_DZ_DEPTH_1PIXEL;
gboolean centre = FALSE;
VipsAngle angle = VIPS_ANGLE_0;

im_filename_split( filename, name, mode );
strcpy( buf, mode );
p = &buf[0];
if( (q = im_getnextoption( &p )) )
layout = vips_enum_from_nick( "im_vips2dz",
VIPS_TYPE_FOREIGN_DZ_LAYOUT, q );
if( (q = im_getnextoption( &p )) )
suffix = g_strdup( q );
if( (q = im_getnextoption( &p )) )
overlap = atoi( q );
if( (q = im_getnextoption( &p )) )
tile_size = atoi( q );
if( (q = im_getnextoption( &p )) )
depth = vips_enum_from_nick( "im_vips2dz",
VIPS_TYPE_FOREIGN_DZ_DEPTH, q );
if( (q = im_getnextoption( &p )) ) {
if( im_isprefix( "cen", q ) )
centre = TRUE;
}
if( (q = im_getnextoption( &p )) )
angle = vips_enum_from_nick( "im_vips2dz",
VIPS_TYPE_ANGLE, q );

if( vips_dzsave( in, name,
"layout", layout,
"suffix", suffix,
"overlap", overlap,
"tile_size", tile_size,
"depth", depth,
"centre", centre,
"angle", angle,
NULL ) )
return( -1 );

return( 0 );
}
4 changes: 2 additions & 2 deletions libvips/foreign/dzsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
_( "Filename suffix for tiles" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, suffix ),
".jpg" );
".jpeg" );

VIPS_ARG_INT( class, "overlap", 10,
_( "Overlap" ),
Expand Down Expand Up @@ -1392,7 +1392,7 @@ vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
VIPS_ARG_STRING( class, "dirname", 1,
_( "Base name" ),
_( "Base name to save to" ),
VIPS_ARGUMENT_REQUIRED_INPUT | VIPS_ARGUMENT_DEPRECATED,
VIPS_ARGUMENT_OPTIONAL_INPUT | VIPS_ARGUMENT_DEPRECATED,
G_STRUCT_OFFSET( VipsForeignSaveDz, basename ),
NULL );

Expand Down
2 changes: 2 additions & 0 deletions libvips/include/vips/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ int im_vips2rad( VipsImage *in, const char *filename );
int im_fits2vips( const char *filename, VipsImage *out );
int im_vips2fits( VipsImage *in, const char *filename );

int im_vips2dz( VipsImage *in, const char *filename );

#ifdef __cplusplus
}
#endif /*__cplusplus*/
Expand Down
1 change: 1 addition & 0 deletions libvips/include/vips/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ G_STMT_START { \

const char *vips_enum_string( GType enm, int value );
const char *vips_enum_nick( GType enm, int value );
int vips_enum_from_nick( const char *domain, GType type, const char *str );

gboolean vips_slist_equal( GSList *l1, GSList *l2 );
void *vips_slist_map2( GSList *list, VipsSListMap2Fn fn, void *a, void *b );
Expand Down
38 changes: 5 additions & 33 deletions libvips/iofuncs/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1439,29 +1439,6 @@ vips_object_class_install_argument( VipsObjectClass *object_class,
#endif /*DEBUG*/
}

/* Make a bad-enum error. A common and fiddly case.
*/
static void
vips_enum_error( VipsObjectClass *class, GType otype, const char *value )
{
GEnumClass *genum = G_ENUM_CLASS( g_type_class_ref( otype ) );
int i;
char str[1000];
VipsBuf buf = VIPS_BUF_STATIC( str );

/* -1 since we always have a "last" member.
*/
for( i = 0; i < genum->n_values - 1; i++ ) {
if( i > 0 )
vips_buf_appends( &buf, ", " );
vips_buf_appends( &buf, genum->values[i].value_nick );
}

vips_error( class->nickname, _( "enum '%s' has no member '%s', "
"should be one of: %s" ),
g_type_name( otype ), value, vips_buf_all( &buf ) );
}

static void
vips_object_no_value( VipsObject *object, const char *name )
{
Expand Down Expand Up @@ -1644,24 +1621,19 @@ vips_object_set_argument_from_string( VipsObject *object,
g_value_set_double( &gvalue, d );
}
else if( G_IS_PARAM_SPEC_ENUM( pspec ) ) {
GEnumValue *enum_value;
int i;

if( !value ) {
vips_object_no_value( object, name );
return( -1 );
}

if( !(enum_value = g_enum_get_value_by_name(
g_type_class_ref( otype ), value )) ) {
if( !(enum_value = g_enum_get_value_by_nick(
g_type_class_ref( otype ), value )) ) {
vips_enum_error( class, otype, value );
return( -1 );
}
}
if( (i = vips_enum_from_nick( class->nickname,
otype, value )) < 0 )
return( -1 );

g_value_init( &gvalue, otype );
g_value_set_enum( &gvalue, enum_value->value );
g_value_set_enum( &gvalue, i );
}
else if( G_IS_PARAM_SPEC_FLAGS( pspec ) ) {
/* Hard to set from a symbolic name. Just take an int.
Expand Down
2 changes: 1 addition & 1 deletion libvips/iofuncs/operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ vips_call( const char *operation_name, ... )

#ifdef VIPS_DEBUG
VIPS_DEBUG_MSG( "where:\n" );
vips_object_print( VIPS_OBJECT( operation ) );
vips_object_print_dump( VIPS_OBJECT( operation ) );
#endif /*VIPS_DEBUG*/

/* We have to break the va_list into separate required and optional
Expand Down
36 changes: 36 additions & 0 deletions libvips/iofuncs/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,3 +1653,39 @@ vips_enum_nick( GType enm, int v )

return( value->value_nick );
}

int
vips_enum_from_nick( const char *domain, GType type, const char *nick )
{
GTypeClass *class;
GEnumClass *genum;
GEnumValue *enum_value;
int i;
char str[1000];
VipsBuf buf = VIPS_BUF_STATIC( str );

if( !(class = g_type_class_ref( type )) ) {
vips_error( domain, "%s", _( "no such enum type" ) );
return( -1 );
}
genum = G_ENUM_CLASS( class );

if( (enum_value = g_enum_get_value_by_name( genum, nick )) )
return( enum_value->value );
if( (enum_value = g_enum_get_value_by_nick( genum, nick )) )
return( enum_value->value );

/* -1 since we always have a "last" member.
*/
for( i = 0; i < genum->n_values - 1; i++ ) {
if( i > 0 )
vips_buf_appends( &buf, ", " );
vips_buf_appends( &buf, genum->values[i].value_nick );
}

vips_error( domain, _( "enum '%s' has no member '%s', "
"should be one of: %s" ),
g_type_name( type ), nick, vips_buf_all( &buf ) );

return( -1 );
}

0 comments on commit 55bfa92

Please sign in to comment.