示例#1
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 );
}
示例#2
0
文件: jpeg2vips.c 项目: jieah/libvips
/* Set input to a file.
 */
static int
readjpeg_file( ReadJpeg *jpeg, const char *filename )
{
    jpeg->filename = g_strdup( filename );
    if( !(jpeg->eman.fp = vips__file_open_read( filename, NULL, FALSE )) )
        return( -1 );
    jpeg_stdio_src( &jpeg->cinfo, jpeg->eman.fp );

    return( 0 );
}
示例#3
0
文件: csv.c 项目: songfj/libvips
VipsImage *
vips__matrix_read( const char *filename )
{
    FILE *fp;
    VipsImage *out;

    if( !(fp = vips__file_open_read( filename, NULL, TRUE )) )
        return( NULL );
    out = vips__matrix_read_file( fp );
    fclose( fp );

    return( out );
}
示例#4
0
int
vips__csv_read_header( const char *filename, VipsImage *out,
	int skip, int lines, const char *whitespace, const char *separator )
{
	FILE *fp;

	if( !(fp = vips__file_open_read( filename, NULL, TRUE )) ) 
		return( -1 );
	if( read_csv( fp, out, skip, lines, whitespace, separator, FALSE ) ) {
		fclose( fp );
		return( -1 );
	}
	fclose( fp );

	return( 0 );
}
示例#5
0
文件: util.c 项目: ashishof77/libvips
/* Load from a filename as a string. Used for things like reading in ICC
 * profiles, ie. binary objects.
 */
char *
vips__file_read_name( const char *filename, const char *fallback_dir, 
	unsigned int *length_out )
{
	FILE *fp;
	char *buffer;

        if( !(fp = vips__file_open_read( filename, fallback_dir, FALSE )) ) 
		return( NULL );
	if( !(buffer = vips__file_read( fp, filename, length_out )) ) {
		fclose( fp );
		return( NULL );
	}
	fclose( fp );

	return( buffer );
}
示例#6
0
int
vips__ppm_load( const char *filename, VipsImage *out )
{
        FILE *fp;

	/* Note that we open in binary mode. If this is a binary PPM, we need
	 * to be able to mmap it.
	 */
	if( !(fp = vips__file_open_read( filename, NULL, FALSE )) ) 
                return( -1 );
	if( parse_ppm( fp, filename, out ) ) {
		fclose( fp );
		return( -1 );
	}
	fclose( fp );

	return( 0 );
}
示例#7
0
int
vips__ppm_header( const char *filename, VipsImage *out )
{
        FILE *fp;
	int bits;
	int ascii;
	int msb_first;

	if( !(fp = vips__file_open_read( filename, NULL, FALSE )) ) 
                return( -1 );
	if( read_header( fp, out, &bits, &ascii, &msb_first ) ) {
		fclose( fp );
		return( -1 );
	}

	fclose( fp );

	return( 0 );
}
示例#8
0
/* Get the header from an matrix file. 
 *
 * Also read the first line and make sure there are the right number of
 * entries. 
 */
int
vips__matrix_read_header( const char *filename,
	int *width, int *height, double *scale, double *offset )
{
	char whitemap[256];
	int i;
	char *p;
	FILE *fp;
	int ch;
	double d;

	for( i = 0; i < 256; i++ ) 
		whitemap[i] = 0;
	for( p = WHITESPACE; *p; p++ )
		whitemap[(int) *p] = 1;

	if( !(fp = vips__file_open_read( filename, NULL, TRUE )) ) 
		return( -1 );
	if( vips__matrix_header( whitemap, fp,
		width, height, scale, offset ) ) {  
		fclose( fp );
		return( -1 );
	}

	for( i = 0; i < *width; i++ ) {
		ch = read_ascii_double( fp, whitemap, &d );

		if( ch ) {
			fclose( fp );
			vips_error( "mask2vips", "%s", _( "line too short" ) );
			return( -1 );
		}
	}

	/* Deliberately don't check for line too long.
	 */

	fclose( fp );

	return( 0 );
}
示例#9
0
VipsImage * 
vips__matrix_read( const char *filename )
{
	char whitemap[256];
	int i;
	char *p;
	FILE *fp;
	int width;
	int height;
	double scale;
	double offset;
	VipsImage *out; 

	for( i = 0; i < 256; i++ ) 
		whitemap[i] = 0;
	for( p = WHITESPACE; *p; p++ )
		whitemap[(int) *p] = 1;

	if( !(fp = vips__file_open_read( filename, NULL, TRUE )) ) 
		return( NULL );
	if( vips__matrix_header( whitemap, fp,
		&width, &height, &scale, &offset ) ) {  
		fclose( fp );
		return( NULL );
	}

	if( !(out = vips_image_new_matrix( width, height )) )
		return( NULL );
	vips_image_set_double( out, "scale", scale ); 
	vips_image_set_double( out, "offset", offset ); 

	if( vips__matrix_body( whitemap, out, fp ) ) {
		g_object_unref( out );
		fclose( fp );
		return( NULL );
	}
	fclose( fp );

	return( out ); 
}
示例#10
0
/* Can this PPM file be read with a mmap?
 */
static int
isppmmmap( const char *filename )
{
	VipsImage *im;
        FILE *fp;
	int bits;
	int ascii;
	int msb_first;

	if( !(fp = vips__file_open_read( filename, NULL, FALSE )) ) 
                return( -1 );

	im = vips_image_new(); 
	if( read_header( fp, im, &bits, &ascii, &msb_first ) ) {
		g_object_unref( im );
		fclose( fp );

		return( 0 );
	}
	g_object_unref( im );
	fclose( fp );

	return( !ascii && bits >= 8 );
}