コード例 #1
0
ファイル: ppm.c プロジェクト: FlavioFalcao/libvips
static void
write_destroy( Write *write )
{
	VIPS_FREEF( fclose, write->fp );
	VIPS_FREE( write->name );

	vips_free( write );
}
コード例 #2
0
ファイル: matlab.c プロジェクト: achanda101/libvips
static void
read_destroy( Read *read )
{
	VIPS_FREE( read->filename );
	VIPS_FREEF( Mat_VarFree, read->var );
	VIPS_FREEF( Mat_Close, read->mat );

	vips_free( read );
}
コード例 #3
0
ファイル: analyze2vips.c プロジェクト: alon/libvips
static struct dsr *
read_header( const char *header )
{
	struct dsr *d;
	unsigned int len;

	if( !(d = (struct dsr *) vips__file_read_name( header, NULL, &len )) )
		return( NULL );

	if( len != sizeof( struct dsr ) ) {
		vips_error( "analyze2vips", 
			"%s", _( "header file size incorrect" ) );
		vips_free( d );
		return( NULL );
	}

	/* Ouch! Should check at configure time I guess.
	 */
	g_assert( sizeof( struct dsr ) == 348 );

	/* dsr headers are always SPARC byte order (MSB first). Do we need to 
	 * swap?
	 */
	if( !vips_amiMSBfirst() ) {
		int i;

		for( i = 0; i < VIPS_NUMBER( dsr_header ); i++ ) {
			unsigned char *p;


			switch( dsr_header[i].type ) {
			case SHORT:
				p = &G_STRUCT_MEMBER( unsigned char, d, 
					dsr_header[i].offset );
				vips__copy_2byte( TRUE, p, p );
				break;

			case INT:
			case FLOAT: 
				p = &G_STRUCT_MEMBER( unsigned char, d, 
					dsr_header[i].offset );
				vips__copy_4byte( TRUE, p, p );
				break;

			case BYTE:
			case STRING:
				break;

			default:
				g_assert( 0 );
			}
		}
	}
コード例 #4
0
ファイル: type.c プロジェクト: alon/libvips
/* Transform a blob to a save string and back.
 */
static void
transform_blob_save_string( const GValue *src_value, GValue *dest_value )
{
	void *blob;
	size_t blob_length;
	char *b64;

	blob = vips_value_get_blob( src_value, &blob_length );
	if( (b64 = vips__b64_encode( blob, blob_length )) ) {
		vips_value_set_save_string( dest_value, b64 );
		vips_free( b64 );
	}
}
コード例 #5
0
ファイル: tilecache.c プロジェクト: alon/libvips
static void
tile_destroy( Tile *tile )
{
	VipsTileCache *cache = tile->cache;

	cache->tiles = g_slist_remove( cache->tiles, tile );
	cache->ntiles -= 1;
	g_assert( cache->ntiles >= 0 );
	tile->cache = NULL;

	VIPS_UNREF( tile->region );

	vips_free( tile );
}
コード例 #6
0
/* Embed an ICC profile from a file.
 */
static int
embed_profile_file( TIFF *tif, const char *profile )
{
	char *buffer;
	size_t length;

	if( !(buffer = vips__file_read_name( profile, VIPS_ICC_DIR, &length )) )
		return( -1 );
	TIFFSetField( tif, TIFFTAG_ICCPROFILE, length, buffer );
	vips_free( buffer );

#ifdef DEBUG
	printf( "vips2tiff: attached profile \"%s\"\n", profile );
#endif /*DEBUG*/

	return( 0 );
}
コード例 #7
0
ファイル: window.c プロジェクト: Jondeen/libvips
static int
vips_window_free( VipsWindow *window )
{
	assert( window->ref_count == 0 );

#ifdef DEBUG
	printf( "** vips_window_free: window top = %d, height = %d (%p)\n",
		window->top, window->height, window );
#endif /*DEBUG*/

	if( vips_window_unmap( window ) )
		return( -1 );

	window->im = NULL;

	vips_free( window );

	return( 0 );
}
コード例 #8
0
ファイル: util.c プロジェクト: ashishof77/libvips
/* Load up a file as a string.
 */
char *
vips__file_read( FILE *fp, const char *filename, unsigned int *length_out )
{
        long len;
	size_t read;
        char *str;

        /* Find length.
         */
        fseek( fp, 0L, 2 );
        len = ftell( fp );
	if( len > 20 * 1024 * 1024 ) {
		/* Seems crazy!
		 */
                vips_error( "vips__file_read", 
			_( "\"%s\" too long" ), filename );
                return( NULL );
        }

	if( len == -1 ) {
		int size;

		/* Can't get length: read in chunks and realloc() to end of
		 * file.
		 */
		str = NULL;
		len = 0;
		size = 0;
		do {
			size += 1024;
			if( !(str = realloc( str, size )) ) {
				vips_error( "vips__file_read", 
					"%s", _( "out of memory" ) );
				return( NULL );
			}

			/* -1 to allow space for an extra NULL we add later.
			 */
			read = fread( str + len, sizeof( char ), 
				(size - len - 1) / sizeof( char ),
				fp );
			len += read;
		} while( !feof( fp ) );

#ifdef DEBUG
		printf( "read %ld bytes from unseekable stream\n", len );
#endif /*DEBUG*/
	}
	else {
		/* Allocate memory and fill.    
		 */
		if( !(str = vips_malloc( NULL, len + 1 )) )
			return( NULL );
		rewind( fp );
		read = fread( str, sizeof( char ), (size_t) len, fp );
		if( read != (size_t) len ) {
			vips_free( str );
			vips_error( "vips__file_read", 
				_( "error reading from file \"%s\"" ), 
				filename );
			return( NULL );
		}
	}

	str[len] = '\0';

	if( length_out )
		*length_out = len;

        return( str );
}
コード例 #9
0
ファイル: util.c プロジェクト: ashishof77/libvips
static void
vips_slist_free_all_cb( void * thing, void * dummy )
{
	vips_free( thing );
}
コード例 #10
0
/* Copy a TIFF file ... we know we wrote it, so just copy the tags we know 
 * we might have set.
 */
static int
write_copy_tiff( Write *write, TIFF *out, TIFF *in )
{
	uint32 i32;
	uint16 i16;
	float f;
	tdata_t buf;
	ttile_t tile;
	ttile_t n;

	/* All the fields we might have set.
	 */
	CopyField( TIFFTAG_IMAGEWIDTH, i32 );
	CopyField( TIFFTAG_IMAGELENGTH, i32 );
	CopyField( TIFFTAG_PLANARCONFIG, i16 );
	CopyField( TIFFTAG_ORIENTATION, i16 );
	CopyField( TIFFTAG_XRESOLUTION, f );
	CopyField( TIFFTAG_YRESOLUTION, f );
	CopyField( TIFFTAG_RESOLUTIONUNIT, i16 );
	CopyField( TIFFTAG_COMPRESSION, i16 );
	CopyField( TIFFTAG_SAMPLESPERPIXEL, i16 );
	CopyField( TIFFTAG_BITSPERSAMPLE, i16 );
	CopyField( TIFFTAG_PHOTOMETRIC, i16 );
	CopyField( TIFFTAG_ORIENTATION, i16 );
	CopyField( TIFFTAG_TILEWIDTH, i32 );
	CopyField( TIFFTAG_TILELENGTH, i32 );
	CopyField( TIFFTAG_ROWSPERSTRIP, i32 );
	CopyField( TIFFTAG_SUBFILETYPE, i32 );

	if( write->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) 
		TIFFSetField( out, TIFFTAG_PREDICTOR, write->predictor );

	/* TIFFTAG_JPEGQUALITY is a pesudo-tag, so we can't copy it.
	 * Set explicitly from Write.
	 */
	if( write->compression == COMPRESSION_JPEG ) {
		TIFFSetField( out, TIFFTAG_JPEGQUALITY, write->jpqual );

		/* Only for three-band, 8-bit images.
		 */
		if( write->im->Bands == 3 &&
			write->im->BandFmt == VIPS_FORMAT_UCHAR ) { 
			/* Enable rgb->ycbcr conversion in the jpeg write. 
			 */
			if( !write->rgbjpeg &&
				write->jpqual < 90 ) 
				TIFFSetField( out, 
					TIFFTAG_JPEGCOLORMODE, 
						JPEGCOLORMODE_RGB );

			/* And we want ycbcr expanded to rgb on read. Otherwise
			 * TIFFTileSize() will give us the size of a chrominance
			 * subsampled tile.
			 */
			TIFFSetField( in, 
				TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB );
		}
	}

	/* We can't copy profiles or xmp :( Set again from Write.
	 */
	if( !write->strip ) 
		if( write_embed_profile( write, out ) ||
			write_embed_xmp( write, out ) ||
			write_embed_ipct( write, out ) ||
			write_embed_photoshop( write, out ) ||
			write_embed_imagedescription( write, out ) )
			return( -1 );

	buf = vips_malloc( NULL, TIFFTileSize( in ) );
	n = TIFFNumberOfTiles( in );
	for( tile = 0; tile < n; tile++ ) {
		tsize_t len;

		/* It'd be good to use TIFFReadRawTile()/TIFFWriteRawTile() 
		 * here to save compression/decompression, but sadly it seems
		 * not to work :-( investigate at some point.
		 */
		len = TIFFReadEncodedTile( in, tile, buf, -1 );
		if( len < 0 ||
			TIFFWriteEncodedTile( out, tile, buf, len ) < 0 ) {
			vips_free( buf );
			return( -1 );
		}
	}
	vips_free( buf );

	return( 0 );
}