void VImage::write_to_buffer( const char *suffix, void **buf, size_t *size, VOption *options ) { char filename[VIPS_PATH_MAX]; char option_string[VIPS_PATH_MAX]; const char *operation_name; VipsBlob *blob; vips__filename_split8( suffix, filename, option_string ); if( !(operation_name = vips_foreign_find_save_buffer( filename )) ) { delete options; throw VError(); } call_option_string( operation_name, option_string, (options ? options : VImage::option())-> set( "in", *this )-> set( "buffer", &blob ) ); if( blob ) { if( buf ) { *buf = VIPS_AREA( blob )->data; VIPS_AREA( blob )->free_fn = NULL; } if( size ) *size = VIPS_AREA( blob )->length; vips_area_unref( VIPS_AREA( blob ) ); } }
VImage VImage::new_from_buffer( void *buf, size_t len, const char *option_string, VOption *options ) { const char *operation_name; VipsBlob *blob; VImage out; if( !(operation_name = vips_foreign_find_load_buffer( buf, len )) ) { delete options; throw( VError() ); } /* We don't take a copy of the data or free it. */ blob = vips_blob_new( NULL, buf, len ); options = (options ? options : VImage::option())-> set( "buffer", blob )-> set( "out", &out ); vips_area_unref( VIPS_AREA( blob ) ); call_option_string( operation_name, option_string, options ); return( out ); }
static int vips_draw_rect_build( VipsObject *object ) { VipsDraw *draw = VIPS_DRAW( object ); VipsDrawink *drawink = VIPS_DRAWINK( object ); VipsArea *ink = VIPS_AREA( drawink->ink ); VipsDrawRect *draw_rect = (VipsDrawRect *) object; int left = draw_rect->left; int top = draw_rect->top; int width = draw_rect->width; int height = draw_rect->height; VipsRect image; VipsRect rect; VipsRect clip; if( VIPS_OBJECT_CLASS( vips_draw_rect_parent_class )->build( object ) ) return( -1 ); /* Also use a solid fill for very narrow unfilled rects. */ if( !draw_rect->fill && width > 2 && height > 2 ) return( vips_draw_rect( draw->image, ink->data, ink->n, left, top, width, 1, NULL ) || vips_draw_rect( draw->image, ink->data, ink->n, left + width - 1, top, 1, height, NULL ) || vips_draw_rect( draw->image, ink->data, ink->n, left, top + height - 1, width, 1, NULL ) || vips_draw_rect( draw->image, ink->data, ink->n, left, top, 1, height, NULL ) ); image.left = 0; image.top = 0; image.width = draw->image->Xsize; image.height = draw->image->Ysize; rect.left = left; rect.top = top; rect.width = width; rect.height = height; vips_rect_intersectrect( &rect, &image, &clip ); if( !vips_rect_isempty( &clip ) ) { VipsPel *to = VIPS_IMAGE_ADDR( draw->image, clip.left, clip.top ); VipsPel *q; int x, y; /* We plot the first line pointwise, then memcpy() it for the * subsequent lines. */ q = to; for( x = 0; x < clip.width; x++ ) { vips__drawink_pel( drawink, q ); q += draw->psize; } q = to + draw->lsize; for( y = 1; y < clip.height; y++ ) { memcpy( q, to, clip.width * draw->psize ); q += draw->lsize; } } return( 0 ); }