/* Can be called many times. */ static int read_close( VipsImage *im, Read *read ) { read_free( read ); return( 0 ); }
static Read * read_new( const char *filename, void *data, size_t length ) { Read *read; if( !(read = VIPS_NEW( NULL, Read )) ) return( NULL ); read->filename = g_strdup( filename ); read->data = data; read->length = length; read->fd = 0; read->idec = NULL; if( read->filename ) { /* libwebp makes streaming from a file source very hard. We * have to read to a full memory buffer, then copy to out. * * mmap the input file, it's slightly quicker. */ if( (read->fd = vips__open_image_read( read->filename )) < 0 || (read->length = vips_file_length( read->fd )) < 0 || !(read->data = vips__mmap( read->fd, FALSE, read->length, 0 )) ) { read_free( read ); return( NULL ); } } WebPInitDecoderConfig( &read->config ); if( WebPGetFeatures( read->data, MINIMAL_HEADER, &read->config.input ) != VP8_STATUS_OK ) { read_free( read ); return( NULL ); } if( read->config.input.has_alpha ) read->config.output.colorspace = MODE_RGBA; else read->config.output.colorspace = MODE_RGB; read->config.options.use_threads = TRUE; return( read ); }
int vips__webp_read_file_header( 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_header( read, out ) ) { read_free( read ); 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 ) ) { read_free( read ); return( -1 ); } read_free( read ); return( 0 ); }
static Read * read_new( const char *filename, void *buf, size_t len ) { Read *read; unsigned char header[MINIMAL_HEADER]; if( !(read = VIPS_NEW( NULL, Read )) ) return( NULL ); read->filename = g_strdup( filename ); read->buf = buf; read->len = len; read->idec = NULL; WebPInitDecoderConfig( &read->config ); if( filename ) { if( vips__get_bytes( filename, header, MINIMAL_HEADER ) && WebPGetFeatures( header, MINIMAL_HEADER, &read->config.input ) != VP8_STATUS_OK ) { read_free( read ); return( NULL ); } } else { if( WebPGetFeatures( read->buf, read->len, &read->config.input ) != VP8_STATUS_OK ) { read_free( read ); return( NULL ); } } if( read->config.input.has_alpha ) read->config.output.colorspace = MODE_RGBA; else read->config.output.colorspace = MODE_RGB; read->config.options.use_threads = TRUE; return( read ); }
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 ); read_free( read ); return( 0 ); }
int vips__webp_read_file( const char *filename, VipsImage *out ) { Read *read; if( !(read = read_new( filename, NULL, 0 )) ) { vips_error( "webp2vips", _( "unable to open \"%s\"" ), filename ); return( -1 ); } if( read_image( read, out ) ) return( -1 ); read_free( read ); return( 0 ); }
void multiread_free(snd_susp_type a_susp) { read_susp_type susp = (read_susp_type) a_susp; int j; boolean active = false; /* stdputstr("multiread_free: "); */ for (j = 0; j < susp->sf_info.channels; j++) { if (susp->chan[j]) { if (susp->chan[j]->refcnt) active = true; else { susp->chan[j] = NULL; /* nyquist_printf("deactivating channel %d\n", j); */ } } } if (!active) { /* stdputstr("all channels freed, freeing susp now\n"); */ read_free(susp); } }
/* 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 ); }
static void io_read (void) { lua_Object o = lua_getparam (1); if (o == LUA_NOOBJECT) /* free format */ read_free(); else /* formatted */ { int m, dummy1, dummy2; switch (getformat(lua_check_string(1, "read"), &dummy1, &m, &dummy2)) { case 's': if (m < 0) read_until_blank(); else read_m(m); lua_pushstring(add_char(0)); break; case 'i': /* can read as float, since it makes no difference to Lua */ case 'f': { double d; int result; if (m < 0) result = fscanf(in, "%lf", &d); else { read_m(m); result = sscanf(add_char(0), "%lf", &d); } if (result == 1) lua_pushnumber(d); else lua_pushnil(); break; } } } }
static Read * read_new( const char *filename, const void *data, size_t length, int shrink ) { Read *read; if( !(read = VIPS_NEW( NULL, Read )) ) return( NULL ); read->filename = g_strdup( filename ); read->data = data; read->length = length; read->shrink = shrink; read->fd = 0; read->idec = NULL; if( read->filename ) { /* libwebp makes streaming from a file source very hard. We * have to read to a full memory buffer, then copy to out. * * mmap the input file, it's slightly quicker. */ if( (read->fd = vips__open_image_read( read->filename )) < 0 || (read->length = vips_file_length( read->fd )) < 0 || !(read->data = vips__mmap( read->fd, FALSE, read->length, 0 )) ) { read_free( read ); return( NULL ); } } WebPInitDecoderConfig( &read->config ); if( WebPGetFeatures( read->data, MINIMAL_HEADER, &read->config.input ) != VP8_STATUS_OK ) { read_free( read ); return( NULL ); } if( read->config.input.has_alpha ) read->config.output.colorspace = MODE_RGBA; else read->config.output.colorspace = MODE_RGB; read->config.options.use_threads = 1; read->width = read->config.input.width / read->shrink; read->height = read->config.input.height / read->shrink; if( read->width == 0 || read->height == 0 ) { vips_error( "webp", "%s", _( "bad setting for shrink" ) ); return( NULL ); } if( read->shrink > 1 ) { read->config.options.use_scaling = 1; read->config.options.scaled_width = read->width; read->config.options.scaled_height = read->height; } return( read ); }