From 47fdd3ae6d163e662cc6321f68b2a6fe1ed3a03d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 2 Dec 2011 18:21:55 +0000 Subject: [PATCH] new tiff writer builds --- TODO | 2 +- libvips/Makefile.am | 2 +- libvips/foreign/tiffsave.c | 46 ++++++++++++++++--------- libvips/foreign/vips2tiff.c | 13 +++---- libvips/include/vips/enumtypes.h | 6 ++++ libvips/include/vips/foreign.h | 2 +- libvips/iofuncs/enumtypes.c | 59 ++++++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+), 28 deletions(-) diff --git a/TODO b/TODO index 7882257c..ddc61cab 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -- dowes the tiff writer support "none" for the profile? +- does the tiff writer support "none" for the profile? diff --git a/libvips/Makefile.am b/libvips/Makefile.am index 62304d2e..2007ad5f 100644 --- a/libvips/Makefile.am +++ b/libvips/Makefile.am @@ -10,8 +10,8 @@ C_LIB = endif SUBDIRS = \ - foreign \ include \ + foreign \ arithmetic \ resample \ colour \ diff --git a/libvips/foreign/tiffsave.c b/libvips/foreign/tiffsave.c index 04939109..c8d42665 100644 --- a/libvips/foreign/tiffsave.c +++ b/libvips/foreign/tiffsave.c @@ -81,6 +81,8 @@ vips_foreign_save_tiff_build( VipsObject *object ) VipsForeignSave *save = (VipsForeignSave *) object; VipsForeignSaveTiff *tiff = (VipsForeignSaveTiff *) object; + char *p; + if( VIPS_OBJECT_CLASS( vips_foreign_save_tiff_parent_class )-> build( object ) ) return( -1 ); @@ -88,25 +90,27 @@ vips_foreign_save_tiff_build( VipsObject *object ) /* Default xres/yres to the values in the image. */ if( !vips_argument_get_assigned( object, "xres" ) ) - tiff->xres = save->read->Xres * 10.0; + tiff->xres = save->ready->Xres * 10.0; if( !vips_argument_get_assigned( object, "yres" ) ) - tiff->yres = save->read->Yres * 10.0; + tiff->yres = save->ready->Yres * 10.0; if( !vips_argument_get_assigned( object, "resunit" ) && - vips_image_get_typeof( im, VIPS_META_RESOLUTION_UNIT ) && - !im_meta_get_string( im, VIPS_META_RESOLUTION_UNIT, &p ) && + vips_image_get_typeof( save->ready, + VIPS_META_RESOLUTION_UNIT ) && + !vips_image_get_string( save->ready, + VIPS_META_RESOLUTION_UNIT, &p ) && vips_isprefix( "in", p ) ) { tiff->resunit = VIPS_FOREIGN_TIFF_RESUNIT_INCH; tiff->xres *= 2.54; tiff->yres *= 2.54; } - if( vips__tiff_write( save->ready, file->filename, + if( vips__tiff_write( save->ready, tiff->filename, tiff->compression, tiff->Q, tiff->predictor, tiff->profile, tiff->tile, tiff->tile_width, tiff->tile_height, tiff->pyramid, tiff->squash, - tiff->xres, tiff->yres, + tiff->resunit, tiff->xres, tiff->yres, tiff->bigtiff ) ) return( -1 ); @@ -115,13 +119,22 @@ vips_foreign_save_tiff_build( VipsObject *object ) static const char *tiff_suffs[] = { ".tif", ".tiff", NULL }; -#define UC VIPS_FORMAT_UCHAR - -/* Type promotion for save ... just always go to uchar. +/* 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_tiff[10] = { /* UC C US S UI I F X D DX */ - UC, UC, UC, UC, UC, UC, UC, UC, UC, UC + UC, UC, US, S, US, US, F, F, F, F }; static void @@ -129,6 +142,7 @@ vips_foreign_save_tiff_class_init( VipsForeignSaveTiffClass *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->set_property = vips_object_set_property; @@ -136,18 +150,18 @@ vips_foreign_save_tiff_class_init( VipsForeignSaveTiffClass *class ) object_class->nickname = "tiffsave"; object_class->description = _( "save image to tiff file" ); - object_class->build = vips_foreign_save_tiff_file_build; + object_class->build = vips_foreign_save_tiff_build; - foreign_class->suffs = vips__tiff_suffs; + foreign_class->suffs = tiff_suffs; - save_class->saveable = VIPS_SAVEABLE_RGB_CMYK; + save_class->saveable = VIPS_SAVEABLE_ANY; save_class->format_table = bandfmt_tiff; VIPS_ARG_STRING( class, "filename", 1, _( "Filename" ), _( "Filename to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignSaveTiffFile, filename ), + G_STRUCT_OFFSET( VipsForeignSaveTiff, filename ), NULL ); VIPS_ARG_ENUM( class, "compression", 6, @@ -184,7 +198,7 @@ vips_foreign_save_tiff_class_init( VipsForeignSaveTiffClass *class ) _( "Tile" ), _( "Write a tiled tiff" ), VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsForeignSaveTiff, tiff ), + G_STRUCT_OFFSET( VipsForeignSaveTiff, tile ), FALSE ); VIPS_ARG_INT( class, "tile_width", 11, @@ -241,7 +255,7 @@ vips_foreign_save_tiff_class_init( VipsForeignSaveTiffClass *class ) _( "Bigtiff" ), _( "Write a bigtiff image" ), VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsForeignSaveTiff, bigtif ), + G_STRUCT_OFFSET( VipsForeignSaveTiff, bigtiff ), FALSE ); } diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 7a0e688e..7d376855 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -1222,7 +1222,6 @@ make_tiff_write( IMAGE *im, const char *filename, gboolean bigtiff ) { TiffWrite *tw; - char *p, *q, *r; if( !(tw = IM_NEW( im, TiffWrite )) ) return( NULL ); @@ -1478,14 +1477,10 @@ vips__tiff_write( VipsImage *in, const char *filename, /* Make output image. If this is a pyramid, write the base image to * tmp/xx.tif rather than fred.tif. */ - if( !(tw = make_tiff_write( in, filename - tiff->compression, tiff->Q, tiff->predictor, - tiff->profile, - tiff->tile, tiff->tile_width, tiff->tile_height, - tiff->pyramid, - tiff->squash, - tiff->resunit, tiff->xres, tiff->yres, - tiff->bigtiff )) ) + if( !(tw = make_tiff_write( in, filename, + compression, Q, predictor, profile, + tile, tile_width, tile_height, pyramid, squash, + resunit, xres, yres, bigtiff )) ) return( -1 ); if( tw->pyramid ) { if( !(tw->bname = im__temp_name( "%s.tif" )) || diff --git a/libvips/include/vips/enumtypes.h b/libvips/include/vips/enumtypes.h index da662b48..aab6d7e8 100644 --- a/libvips/include/vips/enumtypes.h +++ b/libvips/include/vips/enumtypes.h @@ -11,6 +11,12 @@ GType vips_foreign_flags_get_type (void) G_GNUC_CONST; #define VIPS_TYPE_FOREIGN_FLAGS (vips_foreign_flags_get_type()) GType vips_saveable_get_type (void) G_GNUC_CONST; #define VIPS_TYPE_SAVEABLE (vips_saveable_get_type()) +GType vips_foreign_tiff_compression_get_type (void) G_GNUC_CONST; +#define VIPS_TYPE_FOREIGN_TIFF_COMPRESSION (vips_foreign_tiff_compression_get_type()) +GType vips_foreign_tiff_predictor_get_type (void) G_GNUC_CONST; +#define VIPS_TYPE_FOREIGN_TIFF_PREDICTOR (vips_foreign_tiff_predictor_get_type()) +GType vips_foreign_tiff_resunit_get_type (void) G_GNUC_CONST; +#define VIPS_TYPE_FOREIGN_TIFF_RESUNIT (vips_foreign_tiff_resunit_get_type()) /* enumerations from "../../../libvips/include/vips/arithmetic.h" */ GType vips_operation_math_get_type (void) G_GNUC_CONST; #define VIPS_TYPE_OPERATION_MATH (vips_operation_math_get_type()) diff --git a/libvips/include/vips/foreign.h b/libvips/include/vips/foreign.h index fd1b88bf..559abfe3 100644 --- a/libvips/include/vips/foreign.h +++ b/libvips/include/vips/foreign.h @@ -275,7 +275,7 @@ typedef enum { VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL = 2, VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT = 3, VIPS_FOREIGN_TIFF_PREDICTOR_LAST -} VipsForeignTiffPrediction; +} VipsForeignTiffPredictor; /** * VipsForeignTiffResunit: diff --git a/libvips/iofuncs/enumtypes.c b/libvips/iofuncs/enumtypes.c index c9fddd72..afa97c78 100644 --- a/libvips/iofuncs/enumtypes.c +++ b/libvips/iofuncs/enumtypes.c @@ -44,6 +44,65 @@ vips_saveable_get_type( void ) return( etype ); } +GType +vips_foreign_tiff_compression_get_type( void ) +{ + static GType etype = 0; + + if( etype == 0 ) { + static const GEnumValue values[] = { + {VIPS_FOREIGN_TIFF_COMPRESSION_NONE, "VIPS_FOREIGN_TIFF_COMPRESSION_NONE", "none"}, + {VIPS_FOREIGN_TIFF_COMPRESSION_JPEG, "VIPS_FOREIGN_TIFF_COMPRESSION_JPEG", "jpeg"}, + {VIPS_FOREIGN_TIFF_COMPRESSION_DEFLATE, "VIPS_FOREIGN_TIFF_COMPRESSION_DEFLATE", "deflate"}, + {VIPS_FOREIGN_TIFF_COMPRESSION_PACKBITS, "VIPS_FOREIGN_TIFF_COMPRESSION_PACKBITS", "packbits"}, + {VIPS_FOREIGN_TIFF_COMPRESSION_CCITTFAX4, "VIPS_FOREIGN_TIFF_COMPRESSION_CCITTFAX4", "ccittfax4"}, + {VIPS_FOREIGN_TIFF_COMPRESSION_LZW, "VIPS_FOREIGN_TIFF_COMPRESSION_LZW", "lzw"}, + {VIPS_FOREIGN_TIFF_COMPRESSION_LAST, "VIPS_FOREIGN_TIFF_COMPRESSION_LAST", "last"}, + {0, NULL, NULL} + }; + + etype = g_enum_register_static( "VipsForeignTiffCompression", values ); + } + + return( etype ); +} +GType +vips_foreign_tiff_predictor_get_type( void ) +{ + static GType etype = 0; + + if( etype == 0 ) { + static const GEnumValue values[] = { + {VIPS_FOREIGN_TIFF_PREDICTOR_NONE, "VIPS_FOREIGN_TIFF_PREDICTOR_NONE", "none"}, + {VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL, "VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL", "horizontal"}, + {VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT, "VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT", "float"}, + {VIPS_FOREIGN_TIFF_PREDICTOR_LAST, "VIPS_FOREIGN_TIFF_PREDICTOR_LAST", "last"}, + {0, NULL, NULL} + }; + + etype = g_enum_register_static( "VipsForeignTiffPredictor", values ); + } + + return( etype ); +} +GType +vips_foreign_tiff_resunit_get_type( void ) +{ + static GType etype = 0; + + if( etype == 0 ) { + static const GEnumValue values[] = { + {VIPS_FOREIGN_TIFF_RESUNIT_CM, "VIPS_FOREIGN_TIFF_RESUNIT_CM", "cm"}, + {VIPS_FOREIGN_TIFF_RESUNIT_INCH, "VIPS_FOREIGN_TIFF_RESUNIT_INCH", "inch"}, + {VIPS_FOREIGN_TIFF_RESUNIT_LAST, "VIPS_FOREIGN_TIFF_RESUNIT_LAST", "last"}, + {0, NULL, NULL} + }; + + etype = g_enum_register_static( "VipsForeignTiffResunit", values ); + } + + return( etype ); +} /* enumerations from "../../libvips/include/vips/conversion.h" */ GType vips_extend_get_type( void )