im_vips2tiff becomes a stub

also, make '=true' at the end of bool options optional
This commit is contained in:
John Cupitt 2011-12-04 11:06:21 +00:00
parent c61ba6f481
commit b0eed26962
6 changed files with 179 additions and 1699 deletions

8
TODO
View File

@ -1,15 +1,9 @@
- bool args should let you skip the '=', eg.
vips copy x.jpg x.tif[tile,tile-width=1024]
- "header fred.png" does not work, since header uses im_open() which uses
VipsForeign
- make the old format/vips.c into a stub as well?
move format/* to deprecated

View File

@ -70,6 +70,16 @@ typedef struct _VipsForeignSaveTiff {
gboolean bigtiff;
} VipsForeignSaveTiff;
int vips__tiff_write( VipsImage *in, const char *filename,
VipsForeignTiffCompression compression, int Q,
VipsForeignTiffPredictor predictor,
char *profile,
gboolean tile, int tile_width, int tile_height,
gboolean pyramid,
gboolean squash,
VipsForeignTiffResunit resunit, double xres, double yres,
gboolean bigtiff );
typedef VipsForeignSaveClass VipsForeignSaveTiffClass;
G_DEFINE_TYPE( VipsForeignSaveTiff, vips_foreign_save_tiff,

View File

@ -124,8 +124,8 @@
* 23/11/11
* - set reduced-resolution subfile type on pyramid layers
* 2/12/11
* - turn into a write fn ready to be called from a class
* - allow "none" as a profile name
* - make into a simple function call ready to be wrapped as a new-style
* VipsForeign class
*/
/*
@ -154,7 +154,7 @@
*/
/* Turn on IM_REGION_ADDR() range checks, don't delete intermediates.
/*
#define DEBUG
*/
@ -169,7 +169,6 @@
#include <unistd.h>
#endif /*HAVE_UNISTD_H*/
#include <string.h>
#include <assert.h>
#include <vips/vips.h>
#include <vips/internal.h>
@ -268,7 +267,7 @@ tiff_openout( TiffWrite *tw, const char *name )
#endif /*DEBUG*/
if( !(tif = TIFFOpen( name, mode )) ) {
im_error( "im_vips2tiff",
im_error( "vips2tiff",
_( "unable to open \"%s\" for output" ), name );
return( NULL );
}
@ -284,7 +283,7 @@ tiff_openin( const char *name )
TIFF *tif;
if( !(tif = TIFFOpen( name, "r" )) ) {
im_error( "im_vips2tiff",
im_error( "vips2tiff",
_( "unable to open \"%s\" for input" ), name );
return( NULL );
}
@ -397,7 +396,7 @@ embed_profile_file( TIFF *tif, const char *profile )
im_free( buffer );
#ifdef DEBUG
printf( "im_vips2tiff: attached profile \"%s\"\n", profile );
printf( "vips2tiff: attached profile \"%s\"\n", profile );
#endif /*DEBUG*/
return( 0 );
@ -416,7 +415,7 @@ embed_profile_meta( TIFF *tif, IMAGE *im )
TIFFSetField( tif, TIFFTAG_ICCPROFILE, data_length, data );
#ifdef DEBUG
printf( "im_vips2tiff: attached profile from meta\n" );
printf( "vips2tiff: attached profile from meta\n" );
#endif /*DEBUG*/
return( 0 );
@ -545,7 +544,7 @@ write_tiff_header( TiffWrite *tw, TIFF *tif, int width, int height )
break;
default:
assert( 0 );
g_assert( 0 );
}
TIFFSetField( tif, TIFFTAG_PHOTOMETRIC, photometric );
@ -693,8 +692,9 @@ find_new_tile( PyramidLayer *layer )
/* Out of space!
*/
im_error( "im_vips2tiff", "%s", _( "layer buffer exhausted -- "
"try making TIFF output tiles smaller" ) );
im_error( "vips2tiff",
"%s", _( "layer buffer exhausted -- "
"try making TIFF output tiles smaller" ) );
return( -1 );
}
@ -901,7 +901,7 @@ shrink_region( REGION *from, Rect *area,
SHRINK_TYPE_FLOAT( double ); break;
default:
assert( 0 );
g_assert( 0 );
}
}
}
@ -924,7 +924,7 @@ save_tile( TiffWrite *tw, TIFF *tif, PEL *tbuf, REGION *reg, Rect *area )
/* Write to TIFF! easy.
*/
if( TIFFWriteTile( tif, tbuf, area->left, area->top, 0, 0 ) < 0 ) {
im_error( "im_vips2tiff", "%s", _( "TIFF write tile failed" ) );
im_error( "vips2tiff", "%s", _( "TIFF write tile failed" ) );
return( -1 );
}
@ -999,7 +999,7 @@ new_tile( PyramidLayer *layer, REGION *tile, Rect *area )
else
bit = PYR_TL;
if( layer->tiles[t].bits & bit ) {
im_error( "im_vips2tiff",
im_error( "vips2tiff",
"%s", _( "internal error #9876345" ) );
return( -1 );
}
@ -1252,13 +1252,14 @@ make_tiff_write( IMAGE *im, const char *filename,
if( (tw->tilew & 0xf) != 0 ||
(tw->tileh & 0xf) != 0 ) {
im_error( "im_vips2tiff", "%s", _( "tile size not a "
"multiple of 16" ) );
im_error( "vips2tiff",
"%s", _( "tile size not a multiple of 16" ) );
return( NULL );
}
if( !tw->tile && tw->pyramid ) {
im_warn( "im_vips2tiff", "%s", _( "can't have strip pyramid -- "
im_warn( "vips2tiff",
"%s", _( "can't have strip pyramid -- "
"enabling tiling" ) );
tw->tile = 1;
}
@ -1268,7 +1269,7 @@ make_tiff_write( IMAGE *im, const char *filename,
if( tw->pyramid ) {
if( im->Coding == IM_CODING_NONE &&
vips_bandfmt_iscomplex( im->BandFmt ) ) {
im_error( "im_vips2tiff",
im_error( "vips2tiff",
"%s", _( "can only pyramid LABQ and "
"non-complex images" ) );
return( NULL );
@ -1285,8 +1286,8 @@ make_tiff_write( IMAGE *im, const char *filename,
}
if( tw->onebit && tw->compression == COMPRESSION_JPEG ) {
im_warn( "im_vips2tiff", "%s", _( "can't have 1-bit JPEG -- "
"disabling JPEG" ) );
im_warn( "vips2tiff",
"%s", _( "can't have 1-bit JPEG -- disabling JPEG" ) );
tw->compression = COMPRESSION_NONE;
}
@ -1457,22 +1458,22 @@ vips__tiff_write( VipsImage *in, const char *filename,
/* Check input image.
*/
if( im_pincheck( in ) ||
im_check_coding_known( "im_vips2tiff", in ) )
im_check_coding_known( "vips2tiff", in ) )
return( -1 );
if( in->BandFmt != IM_BANDFMT_UCHAR &&
!(in->BandFmt == IM_BANDFMT_SHORT &&
in->Type == IM_TYPE_LABS) &&
in->BandFmt != IM_BANDFMT_USHORT &&
in->BandFmt != IM_BANDFMT_FLOAT ) {
im_error( "im_vips2tiff", "%s",
im_error( "vips2tiff", "%s",
_( "unsigned 8-bit int, 16-bit int, "
"and 32-bit float only" ) );
return( -1 );
}
if( in->Coding == IM_CODING_NONE ) {
if( in->Bands < 1 || in->Bands > 5 ) {
im_error( "im_vips2tiff", "%s",
_( "1 to 5 bands only" ) );
im_error( "vips2tiff",
"%s", _( "1 to 5 bands only" ) );
return( -1 );
}
}

File diff suppressed because it is too large Load Diff

View File

@ -225,17 +225,24 @@ const char *vips_foreign_find_save( const char *filename );
/* Read/write an image convenience functions.
*/
int vips_foreign_read( const char *filename, VipsImage **out, ... );
int vips_foreign_write( VipsImage *in, const char *filename, ... );
int vips_foreign_read( const char *filename, VipsImage **out, ... )
__attribute__((sentinel));
int vips_foreign_write( VipsImage *in, const char *filename, ... )
__attribute__((sentinel));
void vips_foreign_operation_init( void );
int vips_jpegload( const char *filename, VipsImage **out, ... );
int vips_jpegload_buffer( void *buf, size_t len, VipsImage **out, ... );
int vips_jpegload( const char *filename, VipsImage **out, ... )
__attribute__((sentinel));
int vips_jpegload_buffer( void *buf, size_t len, VipsImage **out, ... )
__attribute__((sentinel));
int vips_jpegsave( VipsImage *in, const char *filename, ... );
int vips_jpegsave_buffer( VipsImage *in, void **buf, size_t *len, ... );
int vips_jpegsave_mime( VipsImage *in, ... );
int vips_jpegsave( VipsImage *in, const char *filename, ... )
__attribute__((sentinel));
int vips_jpegsave_buffer( VipsImage *in, void **buf, size_t *len, ... )
__attribute__((sentinel));
int vips_jpegsave_mime( VipsImage *in, ... )
__attribute__((sentinel));
/**
* VipsForeignTiffCompression:
@ -268,7 +275,8 @@ typedef enum {
* @VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL: horizontal differenceing
* @VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT: float predictor
*
* The predictor can help deflate and lzw compression.
* The predictor can help deflate and lzw compression. The values are fixed by
* the tiff library.
*/
typedef enum {
VIPS_FOREIGN_TIFF_PREDICTOR_NONE = 1,
@ -290,15 +298,8 @@ typedef enum {
VIPS_FOREIGN_TIFF_RESUNIT_LAST
} VipsForeignTiffResunit;
int vips__tiff_write( VipsImage *in, const char *filename,
VipsForeignTiffCompression compression, int Q,
VipsForeignTiffPredictor predictor,
char *profile,
gboolean tile, int tile_width, int tile_height,
gboolean pyramid,
gboolean squash,
VipsForeignTiffResunit resunit, double xres, double yres,
gboolean bigtiff );
int vips_tiffsave( VipsImage *in, const char *filename, ... )
__attribute__((sentinel));
#ifdef __cplusplus
}

View File

@ -1519,25 +1519,13 @@ vips_argument_is_required( VipsObject *object,
return( NULL );
}
/* Set the first unassigned required input arg to the string.
/* Find the first unassigned required input arg.
*/
int
vips_object_set_required( VipsObject *object, const char *value )
static GParamSpec *
vips_object_find_required( VipsObject *object )
{
GParamSpec *pspec;
if( !(pspec = vips_argument_map( object,
vips_argument_is_required, NULL, NULL )) ) {
vips_error( "VipsObject",
_( "no unset required arguments for %s" ), value );
return( -1 );
}
if( vips_object_set_argument_from_string( object,
g_param_spec_get_name( pspec ), value ) )
return( -1 );
return( 0 );
return( (GParamSpec *) vips_argument_map( object,
vips_argument_is_required, NULL, NULL ) );
}
VipsObject *
@ -1571,6 +1559,9 @@ vips_object_set_args( VipsObject *object, const char *p )
VipsToken token;
char string[PATH_MAX];
char string2[PATH_MAX];
GParamSpec *pspec;
VipsArgumentClass *argument_class;
VipsArgumentInstance *argument_instance;
do {
if( !(p = vips__token_need( p, VIPS_TOKEN_STRING,
@ -1593,10 +1584,30 @@ vips_object_set_args( VipsObject *object, const char *p )
string2, PATH_MAX )) )
return( -1 );
}
else {
if( vips_object_set_required( object, string ) )
else if( g_object_class_find_property(
G_OBJECT_GET_CLASS( object ), string ) &&
!vips_object_get_argument( object, string,
&pspec, &argument_class, &argument_instance ) &&
(argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) &&
(argument_class->flags & VIPS_ARGUMENT_INPUT) &&
!argument_instance->assigned &&
G_IS_PARAM_SPEC_BOOLEAN( pspec ) ) {
/* The string is the name of an unassigned optional
* input boolean ... set it!
*/
g_object_set( object, string, TRUE, NULL );
}
else if( (pspec = vips_object_find_required( object )) ) {
if( vips_object_set_argument_from_string( object,
g_param_spec_get_name( pspec ), string ) )
return( -1 );
}
else {
vips_error( "VipsObject",
_( "no unset required arguments for %s" ),
string );
return( -1 );
}
/* Now must be a , or a ).
*/