static Read * read_new_buffer( VipsImage *out, const void *buffer, size_t length, gboolean readbehind ) { Read *read; if( !(read = read_new( out, readbehind )) ) return( NULL ); read->length = length; read->buffer = buffer; png_set_read_fn( read->pPng, read, vips_png_read_buffer ); /* Catch PNG errors from png_read_info(). */ if( setjmp( png_jmpbuf( read->pPng ) ) ) return( NULL ); /* Read enough of the file that png_get_interlace_type() will start * working. */ png_read_info( read->pPng, read->pInfo ); return( read ); }
int vips__magick_read_buffer( const void *buf, const size_t len, VipsImage *out, gboolean all_frames, const char *density, int page ) { Read *read; #ifdef DEBUG printf( "magick2vips: vips__magick_read_buffer: %p %zu\n", buf, len ); #endif /*DEBUG*/ if( !(read = read_new( NULL, out, all_frames, density, page )) ) return( -1 ); #ifdef DEBUG printf( "magick2vips: calling BlobToImage() ...\n" ); #endif /*DEBUG*/ read->image = BlobToImage( read->image_info, buf, len, &read->exception ); if( !read->image ) { vips_error( "magick2vips", _( "unable to read buffer\n" "libMagick error: %s %s" ), read->exception.reason, read->exception.description ); return( -1 ); } if( parse_header( read ) ) return( -1 ); if( vips_image_generate( out, NULL, magick_fill_region, NULL, read, NULL ) ) return( -1 ); return( 0 ); }
static Read * read_new_filename( VipsImage *out, const char *name, gboolean readbehind ) { Read *read; if( !(read = read_new( out, readbehind )) ) return( NULL ); read->name = vips_strdup( VIPS_OBJECT( out ), name ); if( !(read->fp = vips__file_open_read( name, NULL, FALSE )) ) return( NULL ); /* Catch PNG errors from png_read_info(). */ if( setjmp( png_jmpbuf( read->pPng ) ) ) return( NULL ); /* Read enough of the file that png_get_interlace_type() will start * working. */ png_init_io( read->pPng, read->fp ); png_read_info( read->pPng, read->pInfo ); return( read ); }
int vips__magick_read( const char *filename, VipsImage *out, gboolean all_frames, const char *density, int page ) { Read *read; #ifdef DEBUG printf( "magick2vips: vips__magick_read: %s\n", filename ); #endif /*DEBUG*/ if( !(read = read_new( filename, out, all_frames, density, page )) ) return( -1 ); #ifdef DEBUG printf( "magick2vips: calling ReadImage() ...\n" ); #endif /*DEBUG*/ read->image = ReadImage( read->image_info, &read->exception ); if( !read->image ) { vips_error( "magick2vips", _( "unable to read file \"%s\"\n" "libMagick error: %s %s" ), filename, read->exception.reason, read->exception.description ); return( -1 ); } if( parse_header( read ) ) return( -1 ); if( vips_image_generate( out, NULL, magick_fill_region, NULL, read, NULL ) ) return( -1 ); return( 0 ); }
/* This has severe issues. See: * * http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=20017 */ int vips__magick_read_header( const char *filename, VipsImage *im ) { Read *read; #ifdef DEBUG printf( "magick2vips: vips__magick_read_header: %s\n", filename ); #endif /*DEBUG*/ if( !(read = read_new( filename, im )) ) return( -1 ); read->image = PingImage( read->image_info, &read->exception ); if( !read->image ) { vips_error( "magick2vips", _( "unable to ping file " "\"%s\"\nlibMagick error: %s %s" ), filename, read->exception.reason, read->exception.description ); return( -1 ); } if( parse_header( read ) ) return( -1 ); if( im->Xsize <= 0 || im->Ysize <= 0 ) { vips_error( "magick2vips", "%s", _( "bad image size" ) ); return( -1 ); } return( 0 ); }
static int magick2vips_header( const char *filename, IMAGE *im ) { Read *read; if( !(read = read_new( filename, im )) ) return( -1 ); read->image = PingImage( read->image_info, &read->exception ); if( !read->image ) { im_error( "im_magick2vips", _( "unable to ping file " "\"%s\"\nlibMagick error: %s %s" ), filename, read->exception.reason, read->exception.description ); return( -1 ); } if( parse_header( read ) ) return( -1 ); if( im->Xsize <= 0 || im->Ysize <= 0 ) { im_error( "im_magick2vips", "%s", _( "bad image size" ) ); return( -1 ); } return( 0 ); }
int vips__gdal_read_header( const char *filename, VipsImage *out ) { if( !read_new( filename, out ) ) return( -1 ); return( 0 ); }
int vips__webp_read_buffer( void *buf, size_t len, VipsImage *out ) { Read *read; if( !(read = read_new( NULL, buf, len )) ) { vips_error( "webp2vips", "%s", _( "unable to open buffer" ) ); return( -1 ); } if( read_image( read, out ) ) return( -1 ); return( 0 ); }
/* Read a PNG file header into a VIPS header. */ static int png2vips_header( const char *name, IMAGE *out ) { Read *read; if( !(read = read_new( name, out )) ) return( -1 ); if( png2vips( read, 1 ) ) { read_destroy( read ); return( -1 ); } read_destroy( read ); return( 0 ); }
int vips__webp_read_file( const char *filename, VipsImage *out, int shrink ) { Read *read; if( !(read = read_new( filename, NULL, 0, shrink )) ) { vips_error( "webp2vips", _( "unable to open \"%s\"" ), filename ); return( -1 ); } if( read_image( read, out ) ) return( -1 ); read_free( read ); return( 0 ); }
int vips__webp_read_buffer_header( const void *buf, size_t len, VipsImage *out, int shrink ) { Read *read; if( !(read = read_new( NULL, buf, len, shrink )) ) { vips_error( "webp2vips", "%s", _( "unable to open buffer" ) ); return( -1 ); } if( read_header( read, out ) ) return( -1 ); read_free( read ); return( 0 ); }
int vips__mat_header( const char *filename, VipsImage *out ) { Read *read; #ifdef DEBUG printf( "mat2vips_header: reading \"%s\"\n", filename ); #endif /*DEBUG*/ if( !(read = read_new( filename, out )) ) return( -1 ); if( mat2vips_get_header( read->var, read->out ) ) { read_destroy( read ); return( -1 ); } read_destroy( read ); return( 0 ); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Test groups * * Return: Success: zero * * Failure: non-zero * * Programmer: Robb Matzke * Tuesday, November 24, 1998 * * Modifications: * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl, fcpl, file; int nerrors=0; char filename[1024]; /* Reset library */ h5_reset(); fapl = h5_fileaccess(); /* * Use larger symbol table data structures to be more efficient, use * defaults to bang harder on the library for testing. */ fcpl = H5Pcreate(H5P_FILE_CREATE); #if 0 H5Pset_sym_k(fcpl, 16, 16); #endif /* Open the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl))<0) goto error; /* Perform tests */ nerrors += test_misc(file); nerrors += test_long(file); nerrors += test_large(file); nerrors += read_new(fapl); if (nerrors) goto error; /* Cleanup */ H5Fclose(file); puts("All symbol table tests passed."); h5_cleanup(FILENAME, fapl); return 0; error: puts("*** TESTS FAILED ***"); return 1; }
/** * im_mat2vips: * @filename: file to load * @out: image to write to * * Read a Matlab save file into a VIPS image. * * This operation searches the save * file for the first array variable with between 1 and 3 dimensions and loads * it as an image. It will not handle complex images. It does not handle * sparse matrices. * * See also: #VipsFormat. * * Returns: 0 on success, -1 on error. */ int im_mat2vips( const char *filename, IMAGE *out ) { Read *read; #ifdef DEBUG printf( "mat2vips: reading \"%s\"\n", filename ); #endif /*DEBUG*/ if( !(read = read_new( filename, out )) ) return( -1 ); if( mat2vips_get_header( read->var, read->out ) || mat2vips_get_data( read->mat, read->var, read->out ) ) { read_destroy( read ); return( -1 ); } read_destroy( read ); return( 0 ); }
/** * 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 ) { Read *read; #ifdef DEBUG printf( "im_png2vips: reading \"%s\"\n", name ); #endif /*DEBUG*/ if( !(read = read_new( name, out )) ) return( -1 ); if( png2vips( read, 0 ) ) { read_destroy( read ); return( -1 ); } read_destroy( read ); return( 0 ); }
/* This has severe issues. See: * * http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=20017 */ int vips__magick_read_header( const char *filename, VipsImage *im, gboolean all_frames, const char *density, int page ) { Read *read; #ifdef DEBUG printf( "vips__magick_read_header: %s\n", filename ); #endif /*DEBUG*/ if( !(read = read_new( filename, im, all_frames, density, page )) ) return( -1 ); #ifdef DEBUG printf( "vips__magick_read_header: pinging image ...\n" ); #endif /*DEBUG*/ read->image = PingImage( read->image_info, &read->exception ); if( !read->image ) { vips_error( "magick2vips", _( "unable to ping file " "\"%s\"\nlibMagick error: %s %s" ), filename, read->exception.reason, read->exception.description ); return( -1 ); } if( parse_header( read ) ) return( -1 ); if( im->Xsize <= 0 || im->Ysize <= 0 ) { vips_error( "magick2vips", "%s", _( "bad image size" ) ); return( -1 ); } /* Just a header read: we can free the read early and save an fd. */ read_free( read ); return( 0 ); }
int vips__magick_read( const char *filename, VipsImage *out ) { Read *read; #ifdef DEBUG printf( "magick2vips: vips__magick_read: %s\n", filename ); #endif /*DEBUG*/ if( !(read = read_new( filename, out )) ) return( -1 ); #ifdef HAVE_SETIMAGEOPTION /* When reading DICOM images, we want to ignore any * window_center/_width setting, since it may put pixels outside the * 0-65535 range and lose data. * * These window settings are attached as vips metadata, so our caller * can interpret them if it wants. */ SetImageOption( read->image_info, "dcm:display-range", "reset" ); #endif /*HAVE_SETIMAGEOPTION*/ read->image = ReadImage( read->image_info, &read->exception ); if( !read->image ) { vips_error( "magick2vips", _( "unable to read file \"%s\"\n" "libMagick error: %s %s" ), filename, read->exception.reason, read->exception.description ); return( -1 ); } if( parse_header( read ) ) return( -1 ); if( vips_image_generate( out, NULL, magick_fill_region, NULL, read, NULL ) ) return( -1 ); 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 ) { Read *read; if( tile_width <= 0 || tile_height <= 0 || max_tiles < -1 ) { im_error( "im_tile_cache", "%s", _( "bad parameters" ) ); return( -1 ); } 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, im_start_one, tile_cache_fill, im_stop_one, in, read ) ) return( -1 ); return( 0 ); }
int vips__gdal_read( const char *filename, VipsImage *out ) { Read *read; VipsImage *raw; VipsImage *t; VIPS_DEBUG_MSG( "vips__gdal_read: %s\n", filename ); raw = vips_image_new(); vips_object_local( out, raw ); if( !(read = read_new( filename, raw )) ) return( -1 ); if( vips_image_generate( raw, NULL, vips__gdal_generate, NULL, read, NULL ) ) return( -1 ); /* Copy to out, adding a cache. Enough tiles for a complete row, plus * 50%. */ if( vips_tilecache( raw, &t, "tile_width", read->tile_width, "tile_height", read->tile_height, "max_tiles", (int) (1.5 * (1 + raw->Xsize / read->tile_width)), "threaded", FALSE, NULL ) ) return( -1 ); if( vips_image_write( t, out ) ) { g_object_unref( t ); return( -1 ); } g_object_unref( t ); return( 0 ); }
int vips__magick_read_buffer_header( const void *buf, const size_t len, VipsImage *im, gboolean all_frames, const char *density, int page ) { Read *read; #ifdef DEBUG printf( "vips__magick_read_buffer_header: %p %zu\n", buf, len ); #endif /*DEBUG*/ if( !(read = read_new( NULL, im, all_frames, density, page )) ) return( -1 ); #ifdef DEBUG printf( "vips__magick_read_buffer_header: pinging blob ...\n" ); #endif /*DEBUG*/ read->image = PingBlob( read->image_info, buf, len, &read->exception ); if( !read->image ) { vips_error( "magick2vips", _( "unable to ping blob\n" "libMagick error: %s %s" ), read->exception.reason, read->exception.description ); return( -1 ); } if( parse_header( read ) ) return( -1 ); if( im->Xsize <= 0 || im->Ysize <= 0 ) { vips_error( "magick2vips", "%s", _( "bad image size" ) ); return( -1 ); } return( 0 ); }