diff --git a/TODO b/TODO index a6410d1a..ccddffda 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,15 @@ +- im_mat2vips() needs to be exposed so we can document the matlab reader + + any others? + +- im__convert_saveable() (in im_copy.c) always makes an 8-bit image + + this means we can't save 16-bit PNG! + + + + + - how about im_invalidate_area()? we currently repaint the whole window on every paint action in nip2 :-( diff --git a/doc/reference/libvips-docs.sgml.in b/doc/reference/libvips-docs.sgml.in index b771a7e2..51203085 100644 --- a/doc/reference/libvips-docs.sgml.in +++ b/doc/reference/libvips-docs.sgml.in @@ -38,11 +38,11 @@ + VIPS operation API by section (no gtkdoc comments yet) - diff --git a/libvips/format/format.c b/libvips/format/format.c index 6071dd2e..8fed3aea 100644 --- a/libvips/format/format.c +++ b/libvips/format/format.c @@ -61,7 +61,7 @@ * transparently supported by im_open(). * * VIPS comes with loaders for TIFF, JPEG, PNG, Analyze, PPM, OpenEXR, CSV, - * RAW, VIPS and one that wraps libMagick. + * Matlab, RAW, VIPS and one that wraps libMagick. */ /** diff --git a/libvips/format/im_magick2vips.c b/libvips/format/im_magick2vips.c index eb3df9ba..fdf54b25 100644 --- a/libvips/format/im_magick2vips.c +++ b/libvips/format/im_magick2vips.c @@ -31,6 +31,8 @@ * - fix signed/unsigned warnings * 23/7/09 * - SetImageOption() is optional (to help GM) + * 4/2/10 + * - gtkdoc */ /* @@ -584,12 +586,30 @@ magick_fill_region( REGION *out, void *seq, void *a, void *b ) return( 0 ); } +/** + * im_magick2vips: + * @filename: file to load + * @out: image to write to + * + * Read in an image useing libMagick, the ImageMagick library. This library can + * read more than 80 file formats, including SVG, BMP, EPS, DICOM and many + * others. + * The reader can handle any ImageMagick image, including the float and double + * formats. It will work with any quantum size, including HDR. Any metadata + * attached to the libMagick image is copied on to the VIPS image. + * + * The reader should also work with most versions of GraphicsMagick. + * + * See also: #VipsFormat. + * + * Returns: 0 on success, -1 on error. + */ int -im_magick2vips( const char *filename, IMAGE *im ) +im_magick2vips( const char *filename, IMAGE *out ) { Read *read; - if( !(read = read_new( filename, im )) ) + if( !(read = read_new( filename, out )) ) return( -1 ); #ifdef HAVE_SETIMAGEOPTION @@ -613,9 +633,9 @@ im_magick2vips( const char *filename, IMAGE *im ) } if( parse_header( read ) || - im_poutcheck( im ) || - im_demand_hint( im, IM_SMALLTILE, NULL ) || - im_generate( im, NULL, magick_fill_region, NULL, read, NULL ) ) + im_poutcheck( out ) || + im_demand_hint( out, IM_SMALLTILE, NULL ) || + im_generate( out, NULL, magick_fill_region, NULL, read, NULL ) ) return( -1 ); return( 0 ); diff --git a/libvips/format/im_png2vips.c b/libvips/format/im_png2vips.c index 45cd1285..ef9e4bcf 100644 --- a/libvips/format/im_png2vips.c +++ b/libvips/format/im_png2vips.c @@ -14,6 +14,8 @@ * - set RGB16/GREY16 if appropriate * 28/2/09 * - small cleanups + * 4/2/10 + * - gtkdoc */ /* @@ -336,7 +338,19 @@ png2vips_header( const char *name, IMAGE *out ) return( 0 ); } -/* Read a PNG file into a VIPS image. +/** + * im_png2vips: + * @filename: file to load + * @out: image to write to + * + * Read a PNG file into a VIPS image. It can read all png images, including 8- + * and 16-bit images, 1 and 3 channel, with and without an alpha channel. + * + * There is no support for embedded ICC profiles. + * + * See also: #VipsFormat, im_vips2png(). + * + * Returns: 0 on success, -1 on error. */ int im_png2vips( const char *name, IMAGE *out ) diff --git a/libvips/format/im_ppm2vips.c b/libvips/format/im_ppm2vips.c index 1917df93..3e486014 100644 --- a/libvips/format/im_ppm2vips.c +++ b/libvips/format/im_ppm2vips.c @@ -19,6 +19,8 @@ * - use im_raw2vips() for binary read * 9/9/05 * - tiny cleanups + * 4/2/10 + * - gtkdoc */ /* @@ -433,6 +435,20 @@ isppmmmap( const char *filename ) return( !ascii && bits >= 8 ); } +/** + * im_ppm2vips: + * @filename: file to load + * @out: image to write to + * + * Read a PPM/PBM/PGM file into a VIPS image. + * It can read 1, 8, 16 and 32 bit images, colour or monochrome, + * stored in binary or in ASCII. One bit images become 8 bit VIPS images, + * with 0 and 255 for 0 and 1. + * + * See also: #VipsFormat, im_vips2ppm(). + * + * Returns: 0 on success, -1 on error. + */ int im_ppm2vips( const char *filename, IMAGE *out ) { diff --git a/libvips/format/im_raw2vips.c b/libvips/format/im_raw2vips.c index e8f50605..277d4e3d 100644 --- a/libvips/format/im_raw2vips.c +++ b/libvips/format/im_raw2vips.c @@ -1,6 +1,8 @@ /* Read raw image. Just a wrapper over im_binfile(). * * 3/8/05 + * 4/2/10 + * - gtkdoc */ /* @@ -44,6 +46,25 @@ #include #endif /*WITH_DMALLOC*/ +/** + * im_raw2vips: + * @filename: file to read + * @out: image to write to + * @width: image width in pixels + * @height: image height in pixels + * @bpp: bytes per pixel + * @offset: skip this many bytes at the start of the file + * + * This operation mmaps the file, setting @out so that access to that + * image will read from the file. + * + * Use functions like im_copy_morph() to set the pixel type, byte ordering + * and so on. + * + * See also: im_vips2raw(). + * + * Returns: 0 on success, -1 on error. + */ int im_raw2vips( const char *filename, IMAGE *out, int width, int height, int bpp, int offset ) diff --git a/libvips/format/im_tiff2vips.c b/libvips/format/im_tiff2vips.c index fc06c6be..a2c967fc 100644 --- a/libvips/format/im_tiff2vips.c +++ b/libvips/format/im_tiff2vips.c @@ -111,6 +111,8 @@ * 13/1/09 * - read strip-wise, not scanline-wise ... works with more compression / * subsampling schemes (esp. subsampled YCbCr), and it's a bit quicker + * 4/2/10 + * - gtkdoc */ /* @@ -1423,6 +1425,29 @@ istiffpyramid( const char *name ) } */ +/** + * im_tiff2vips: + * @filename: file to load + * @out: image to write to + * + * Read a TIFF file into a VIPS image. It is a full baseline TIFF 6 reader, + * with extensions for tiled images, multipage images, LAB colour space, + * pyramidal images and JPEG compression. including CMYK and YCbCr. + * + * You can embed a page number in the filename. For example: + * + * |[ + * im_tiff2vips( "fred.tif:23", out ); + * ]| + * + * Will read page 23. By default, the operation reads the first page. + * + * Any ICC profile is read out and attached to the VIPS image. + * + * See also: #VipsFormat, im_vips2tiff(). + * + * Returns: 0 on success, -1 on error. + */ int im_tiff2vips( const char *filename, IMAGE *out ) { diff --git a/libvips/format/im_tile_cache.c b/libvips/format/im_tile_cache.c index ac3a985e..74f34ed4 100644 --- a/libvips/format/im_tile_cache.c +++ b/libvips/format/im_tile_cache.c @@ -7,8 +7,10 @@ * 23/8/06 * - take ownership of reused tiles in case the cache is being shared * 13/2/07 - * - relase ownership after fillng with pixels in case we read across - * threads + * - release ownership after fillng with pixels in case we read across + * threads + * 4/2/10 + * - gtkdoc */ /* @@ -363,6 +365,29 @@ fill_region( REGION *out, void *seq, void *a, void *b ) return( 0 ); } +/** + * im_tile_cache: + * @in: input image + * @out: output image + * @tile_width: tile width + * @tile_height: tile height + * @max_tiles: maximum number of tiles to cache + * + * This operation behaves rather like im_copy() between images + * @in and @out, except that it keeps a cache of computed pixels. + * This cache is made of up to @max_tiles tiles (a value of -1 for + * means any number of tiles), and each tile is of size @tile_width + * by @tile_height pixels. Each cache tile is made with a single call to + * im_prepare(). + * + * This is a lower-level operation than im_cache() since it does no + * subdivision. It is suitable for caching the output of operations like + * im_exr2vips() on tiled images. + * + * See also: im_cache(). + * + * Returns: 0 on success, -1 on error. + */ int im_tile_cache( IMAGE *in, IMAGE *out, int tile_width, int tile_height, int max_tiles ) @@ -373,18 +398,14 @@ im_tile_cache( IMAGE *in, IMAGE *out, im_error( "im_tile_cache", "%s", _( "bad parameters" ) ); return( -1 ); } - if( im_piocheck( in, out ) ) - return( -1 ); - if( im_cp_desc( out, in ) ) - return( -1 ); - if( im_demand_hint( out, IM_SMALLTILE, in, NULL ) ) - return( -1 ); - if( !(read = read_new( in, out, - tile_width, tile_height, max_tiles )) ) - return( -1 ); - if( im_generate( out, - NULL, fill_region, NULL, read, NULL ) ) + if( im_piocheck( in, out ) || + im_cp_desc( out, in ) || + im_demand_hint( out, IM_SMALLTILE, in, NULL ) || + !(read = read_new( in, out, + tile_width, tile_height, max_tiles )) || + im_generate( out, + NULL, fill_region, NULL, read, NULL ) ) return( -1 ); return( 0 ); diff --git a/libvips/format/im_vips2jpeg.c b/libvips/format/im_vips2jpeg.c index d719593f..d66f9999 100644 --- a/libvips/format/im_vips2jpeg.c +++ b/libvips/format/im_vips2jpeg.c @@ -684,7 +684,7 @@ write_vips( Write *write, int qfac, const char *profile ) * Example: * * |[ - * im_vips2jpeg( in, "fred.jpg:99,none" out ); + * im_vips2jpeg( in, "fred.jpg:99,none" ); * ]| * * Will write "fred.jpg" at high-quality with no ICC profile. @@ -869,13 +869,24 @@ buf_dest( j_compress_ptr cinfo, IMAGE *out, char **obuf, int *olen ) buf->olen = olen; } -/* As above, but save to a buffer. The buffer is allocated relative to out. - * On success, buf is set to the output buffer and len to the size of the - * compressed image. - - FIXME ... argh, the return length should really be a size_t, but we - can't fix this now sadly - +/** + * im_vips2bufjpeg: + * @in: image to save + * @out: allocate output buffer local to this + * @qfac: JPEG quality factor + * @obuf: return output buffer here + * @olen: return output length here + * + * As im_vips2jpeg(), but save as a memory buffer. The memory is allocated + * local to @out (that is, when @out is closed the memory will be released, + * pass %NULL to release yourself). + * + * The address of the buffer is returned in @obuf, the length of the buffer in + * @olen. @olen should really be a size_t rather than an int :-( + * + * See also: #VipsFormat, im_vips2jpeg(). + * + * Returns: 0 on success, -1 on error. */ int im_vips2bufjpeg( IMAGE *in, IMAGE *out, int qfac, char **obuf, int *olen ) @@ -917,7 +928,16 @@ im_vips2bufjpeg( IMAGE *in, IMAGE *out, int qfac, char **obuf, int *olen ) return( 0 ); } -/* As above, but save as a mime jpeg on stdout. +/** + * im_vips2mimejpeg: + * @in: image to save + * @qfac: JPEG quality factor + * + * As im_vips2jpeg(), but save as a mime jpeg on stdout. + * + * See also: #VipsFormat, im_vips2jpeg(). + * + * Returns: 0 on success, -1 on error. */ int im_vips2mimejpeg( IMAGE *in, int qfac ) diff --git a/libvips/format/im_vips2png.c b/libvips/format/im_vips2png.c index 4131ebf5..9c5d4869 100644 --- a/libvips/format/im_vips2png.c +++ b/libvips/format/im_vips2png.c @@ -12,6 +12,8 @@ * - from vips_png.c * 2/11/07 * - use im_wbuffer() API for BG writes + * 4/2/10 + * - gtkdoc */ /* @@ -64,7 +66,6 @@ im_vips2png( IMAGE *in, const char *filename ) #else /*HAVE_PNG*/ #include -#include #include #include @@ -195,9 +196,9 @@ write_vips( Write *write, int compress, int interlace ) int i, nb_passes; - assert( in->BandFmt == IM_BANDFMT_UCHAR ); - assert( in->Coding == IM_CODING_NONE ); - assert( in->Bands > 0 && in->Bands < 5 ); + g_assert( in->BandFmt == IM_BANDFMT_UCHAR ); + g_assert( in->Coding == IM_CODING_NONE ); + g_assert( in->Bands > 0 && in->Bands < 5 ); /* Catch PNG errors. */ @@ -230,7 +231,7 @@ write_vips( Write *write, int compress, int interlace ) case 4: write->pInfo->color_type = PNG_COLOR_TYPE_RGB_ALPHA; break; default: - assert( 0 ); + g_assert( 0 ); } png_write_info( write->pPng, write->pInfo ); @@ -262,7 +263,52 @@ write_vips( Write *write, int compress, int interlace ) return( 0 ); } -/* Write a VIPS image to a file as PNG. +/** + * im_vips2png: + * @in: image to save + * @filename: file to write to + * + * Write a VIPS image to a file as PNG. + * + * You can embed options in the filename. They have the form: + * + * |[ + * filename.png:compression,interlace + * ]| + * + * + * + * + * compression + * Compress with this much effort (0 - 9). Default 6. + * + * + * + * + * interlace + * 0 means don't interlace (the default), 1 selects ADAM7 interlacing. Beware + * than an interlaced PNG can be up to 7 times slower to write than a + * non-interlaced image. + * + * + * + * + * There is no support for attaching ICC profiles to PNG images. + * + * The image is automatically converted to RGB, RGBA, Monochrome or Mono + + * alpha before saving. + * + * Example: + * + * |[ + * im_vips2png( in, "fred.png:0,1" ); + * ]| + * + * Will write "fred.png" with no compression and with ADAM7 interlacing. + * + * See also: #VipsFormat, im_png2vips(). + * + * Returns: 0 on success, -1 on error. */ int im_vips2png( IMAGE *in, const char *filename ) diff --git a/libvips/format/im_vips2ppm.c b/libvips/format/im_vips2ppm.c index 627f74b9..fb3d9ca1 100644 --- a/libvips/format/im_vips2ppm.c +++ b/libvips/format/im_vips2ppm.c @@ -6,6 +6,9 @@ * - tiny cleanups * 3/11/07 * - use im_wbuffer() for bg writes + * 4/2/10 + * - gtkdoc + * - cleanups */ /* @@ -226,6 +229,28 @@ write_ppm( Write *write, int ascii ) return( 0 ); } +/** + * im_vips2ppm: + * @in: image to save + * @filename: file to write to + * + * Write a VIPS image to a file as PPM. It can write 8, 16 or + * 32 bit unsigned integer images, colour or monochrome, stored as binary or + * ASCII. + * Images of more than 8 bits can only be stored in ASCII. + * + * The storage format is indicated by a filename extension, for example: + * + * |[ + * im_vips2ppm( im, "fred.ppm:ascii" ) + * ]| + * + * will write to "fred.ppm" in ascii format. The default is binary. + * + * See also: #VipsFormat, im_ppm2vips(). + * + * Returns: 0 on success, -1 on error. + */ int im_vips2ppm( IMAGE *in, const char *filename ) { @@ -259,22 +284,13 @@ im_vips2ppm( IMAGE *in, const char *filename ) "%s", _( "can't write binary >8 bit images" ) ); return( -1 ); } - if( !vips_bandfmt_isuint( in->BandFmt ) ) { - im_error( "im_vips2ppm", - "%s", _( "unsigned int formats only" ) ); + if( im_check_uint( "im_vips2ppm", in ) || + im_check_bands_1or3( "im_vips2ppm", in ) || + im_check_uncoded( "im_vips2ppm", in ) || + im_pincheck( in ) ) return( -1 ); - } - if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) { - im_error( "im_vips2ppm", - "%s", _( "uncoded or IM_CODING_LABQ only" ) ); - return( -1 ); - } - if( in->Bands != 1 && in->Bands != 3 ) { - im_error( "im_vips2ppm", "%s", _( "1 or 3 band images only" ) ); - return( -1 ); - } - if( im_pincheck( in ) || !(write = write_new( in, name )) ) + if( !(write = write_new( in, name )) ) return( -1 ); if( write_ppm( write, ascii ) ) { diff --git a/libvips/format/im_vips2raw.c b/libvips/format/im_vips2raw.c index 6285d4c8..2bb9c3e9 100644 --- a/libvips/format/im_vips2raw.c +++ b/libvips/format/im_vips2raw.c @@ -8,6 +8,8 @@ * 04/07/08 JF * - replaced FILE with plain file handlers for reducing * confusion about binary vs. non-binary file modes. + * 4/2/10 + * - gtkdoc */ @@ -37,7 +39,6 @@ #include #include -#include #include #include #include @@ -107,6 +108,18 @@ write_block( REGION *region, Rect *area, void *a, void *b ) } +/** + * im_vips2raw: + * @in: image to save + * @fd: file descriptor to write to + * + * Writes the pixels in @in to the file descriptor. It's handy for writing + * writers for other formats. + * + * See also: im_raw2vips(). + * + * Returns: 0 on success, -1 on error. + */ int im_vips2raw( IMAGE *in, int fd ) { diff --git a/libvips/format/im_vips2tiff.c b/libvips/format/im_vips2tiff.c index 4f6f13db..fe43bba9 100644 --- a/libvips/format/im_vips2tiff.c +++ b/libvips/format/im_vips2tiff.c @@ -106,6 +106,8 @@ * - allow CMYKA (thanks Doron) * 5/9/08 * - trigger eval callbacks during tile write + * 4/2/10 + * - gtkdoc */ /* @@ -1567,8 +1569,116 @@ gather_pyramid( TiffWrite *tw ) return( 0 ); } + +/** + * im_vips2tiff: + * @in: image to save + * @filename: file to write to + * + * Write a VIPS image to a file as TIFF. + * + * You can embed options in the filename. They have the form: + * + * |[ + * filename.tif:compression,layout,multi-res,format,resolution,icc + * ]| + * + * + * + * + * compression + * should be one of "none" (no compression), "jpeg" (JPEG compression), + * "deflate" (ZIP compression), "packbits" (TIFF packbits compression), + * "ccittfax4" (CCITT Group 4 fax encoding), "lzw" (Lempel-Ziv compression). + * + * "jpeg" compression can be followed by a ":" character and a JPEG quality + * level; "lzw" and "deflate" can be followed by a ":" and predictor value. + * The default compression type is "none", the default JPEG quality factor + * is 75. + * + * Predictor is not set by default. There are three predictor values recognised + * at the moment (2007, July): 1 is no prediction, 2 is a horizontal + * differencing and 3 is a floating point predictor. Refer to the libtiff + * specifications for further discussion of various predictors. In short, + * predictor helps to better compress image, especially in case of digital + * photos or scanned images and bit depths > 8. Try it to find whether it + * works for your images. + * + * JPEG compression is a good lossy compressor for photographs, packbits is + * good for 1-bit images, and deflate is the best lossless compression TIFF + * can do. LZW has patent problems and is no longer recommended. + * + * + * + * + * layout + * should be "strip" (strip layout) or "tile" (tiled layout). + * + * "tile" layout can be followed by a ":" character and the horizontal and + * vertical tile size, separated by a "x" character. The default layout is + * "strip", and the default tile size is 128 by 128 pixels. + * + * + * + * + * multi-res + * should be "flat" (single image) or "pyramid" (many images arranged in a + * pyramid). The default multi-res mode is "flat". + * + * + * + * + * format + * shoiuld be "manybit" (don't bit-reduce images) or "onebit" (one band 8 + * bit images are saved as 1 bit). The default format is "multibit". + * + * + * + * + * resolution + * should be "res_cm" (output resolution unit is pixels per centimetre) or + * "res_inch" (output resolution unit is pixels per inch). The default + * resolution unit is taken from the header field "resolution-unit" + * (#IM_META_RESOLUTION_UNIT in C). If this field is not set, then + * VIPS defaults to cm. + * + * The unit can optionally be followed by a ":" character and the + * horizontal and vertical resolution, separated by a "x" character. + * You can have a single number with no "x" and set the horizontal and + * vertical resolutions together. + * + * + * + * + * icc + * Attach this ICC profile. + * This does not affect the pixels which are written, just the way + * they are tagged. + * + * + * + * + * Example: + * + * |[ + * im_vips2jpeg( in, "fred.tif:jpeg,tile,pyramid" ); + * ]| + * + * Will write "fred.tif" as a tiled jpeg-compressed pyramid. + * + * |[ + * im_vips2jpeg( in, "fred.tif:packbits,tile,,onebit" ); + * ]| + * + * Writes a tiled one bit TIFF image (provided fred.v is a one band 8 bit + * image) compressed with packbits. + * + * See also: #VipsFormat, im_tiff2vips(). + * + * Returns: 0 on success, -1 on error. + */ int -im_vips2tiff( IMAGE *im, const char *filename ) +im_vips2tiff( IMAGE *in, const char *filename ) { TiffWrite *tw; int res; @@ -1584,24 +1694,24 @@ im_vips2tiff( IMAGE *im, const char *filename ) /* Check input image. */ - if( im_pincheck( im ) ) + if( im_pincheck( in ) ) return( -1 ); - if( im->Coding != IM_CODING_LABQ && im->Coding != IM_CODING_NONE ) { + if( in->Coding != IM_CODING_LABQ && in->Coding != IM_CODING_NONE ) { im_error( "im_vips2tiff", "%s", _( "unknown coding type" ) ); return( -1 ); } - if( im->BandFmt != IM_BANDFMT_UCHAR && - !(im->BandFmt == IM_BANDFMT_SHORT && - im->Type == IM_TYPE_LABS) && - im->BandFmt != IM_BANDFMT_USHORT && - im->BandFmt != IM_BANDFMT_FLOAT ) { + 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", _( "unsigned 8-bit int, 16-bit int, " "and 32-bit float only" ) ); return( -1 ); } - if( im->Coding == IM_CODING_NONE ) { - if( im->Bands < 1 || im->Bands > 5 ) { + if( in->Coding == IM_CODING_NONE ) { + if( in->Bands < 1 || in->Bands > 5 ) { im_error( "im_vips2tiff", "%s", _( "1 to 5 bands only" ) ); return( -1 ); @@ -1611,7 +1721,7 @@ im_vips2tiff( IMAGE *im, const char *filename ) /* Make output image. If this is a pyramid, write the base image to * fred.1.tif rather than fred.tif. */ - if( !(tw = make_tiff_write( im, filename )) ) + if( !(tw = make_tiff_write( in, filename )) ) return( -1 ); if( tw->pyramid ) { if( !(tw->bname = new_tiff_name( tw, tw->name, 1 )) || @@ -1631,7 +1741,7 @@ im_vips2tiff( IMAGE *im, const char *filename ) /* Write the TIFF header for the full-res file. */ - if( write_tiff_header( tw, tw->tif, im->Xsize, im->Ysize ) ) { + if( write_tiff_header( tw, tw->tif, in->Xsize, in->Ysize ) ) { free_tiff_write( tw ); return( -1 ); } @@ -1642,12 +1752,12 @@ im_vips2tiff( IMAGE *im, const char *filename ) * have our own loop for tile writing and so we need to call * ourselves. */ - if( im__start_eval( im ) ) { + if( im__start_eval( in ) ) { free_tiff_write( tw ); return( -1 ); } res = write_tif_tile( tw ); - im__end_eval( im ); + im__end_eval( in ); } else res = write_tif_strip( tw ); diff --git a/libvips/include/vips/check.h b/libvips/include/vips/check.h index 7ae869af..15edee98 100644 --- a/libvips/include/vips/check.h +++ b/libvips/include/vips/check.h @@ -48,10 +48,12 @@ int im_check_uncoded( const char *domain, IMAGE *im ); int im_check_coding_known( const char *domain, IMAGE *im ); int im_check_coding_same( const char *domain, IMAGE *im1, IMAGE *im2 ); int im_check_mono( const char *domain, IMAGE *im ); +int im_check_bands_1or3( const char *domain, IMAGE *in ); int im_check_bands( const char *domain, IMAGE *im, int bands ); int im_check_bands_1orn( const char *domain, IMAGE *im1, IMAGE *im2 ); int im_check_bands_same( const char *domain, IMAGE *im1, IMAGE *im2 ); int im_check_int( const char *domain, IMAGE *im ); +int im_check_uint( const char *domain, IMAGE *im ); int im_check_noncomplex( const char *domain, IMAGE *im ); int im_check_complex( const char *domain, IMAGE *im ); int im_check_format( const char *domain, IMAGE *im, VipsBandFmt fmt ); diff --git a/libvips/include/vips/format.h b/libvips/include/vips/format.h index 5f7f1360..82e9f496 100644 --- a/libvips/include/vips/format.h +++ b/libvips/include/vips/format.h @@ -125,7 +125,7 @@ int im_vips2tiff( IMAGE *in, const char *filename ); int im_tiff2vips( const char *filename, IMAGE *out ); int im_tile_cache( IMAGE *in, IMAGE *out, int tile_width, int tile_height, int max_tiles ); -int im_magick2vips( const char *filename, IMAGE * ); +int im_magick2vips( const char *filename, IMAGE *out ); int im_png2vips( const char *filename, IMAGE *out ); int im_exr2vips( const char *filename, IMAGE *out ); int im_ppm2vips( const char *filename, IMAGE *out ); diff --git a/libvips/iofuncs/check.c b/libvips/iofuncs/check.c index 90313759..56848ac5 100644 --- a/libvips/iofuncs/check.c +++ b/libvips/iofuncs/check.c @@ -638,6 +638,30 @@ im_check_bands( const char *domain, IMAGE *im, int bands ) return( 0 ); } +/** + * im_check_1or3: + * @domain: the originating domain for the error message + * @im: image to check + * + * Check that the image has either one or three bands. + * Otherwise set an error message + * and return non-zero. + * + * See also: im_error(). + * + * Returns: 0 if OK, -1 otherwise. + */ +int +im_check_bands_1or3( const char *domain, IMAGE *im ) +{ + if( im->Bands != 1 && im->Bands != 3 ) { + im_error( domain, "%s", _( "image must one or three bands" ) ); + return( -1 ); + } + + return( 0 ); +} + /** * im_check_bands_1orn: * @domain: the originating domain for the error message @@ -765,6 +789,30 @@ im_check_int( const char *domain, IMAGE *im ) return( 0 ); } +/** + * im_check_uint: + * @domain: the originating domain for the error message + * @im: image to check + * + * Check that the image is in one of the unsigned integer formats. + * Otherwise set an error message + * and return non-zero. + * + * See also: im_error(). + * + * Returns: 0 if OK, -1 otherwise. + */ +int +im_check_uint( const char *domain, IMAGE *im ) +{ + if( !vips_bandfmt_isuint( im->BandFmt ) ) { + im_error( domain, "%s", _( "image must be unsigned integer" ) ); + return( -1 ); + } + + return( 0 ); +} + /** * im_check_u8or16: * @domain: the originating domain for the error message