static int write_blank( VipsForeignSaveDz *dz ) { VipsImage *x, *t; int n; VipsArea *ones; double *d; int i; void *buf; size_t len; GsfOutput *out; if( vips_black( &x, dz->tile_size, dz->tile_size, NULL ) ) return( -1 ); vips_area_get_data( (VipsArea *) dz->background, NULL, &n, NULL, NULL ); ones = vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), n ); d = (double *) vips_area_get_data( ones, NULL, NULL, NULL, NULL ); for( i = 0; i < n; i++ ) d[i] = 1.0; if( vips_linear( x, &t, d, (double *) vips_area_get_data( (VipsArea *) dz->background, NULL, NULL, NULL, NULL ), n, NULL ) ) { vips_area_unref( ones ); g_object_unref( x ); return( -1 ); } vips_area_unref( ones ); g_object_unref( x ); x = t; if( vips_pngsave_buffer( x, &buf, &len, NULL ) ) { g_object_unref( x ); return( -1 ); } g_object_unref( x ); out = vips_gsf_path( dz->tree, "blank.png", NULL ); gsf_output_write( out, len, buf ); gsf_output_close( out ); g_object_unref( out ); g_free( buf ); return( 0 ); }
int im_vips2bufpng( IMAGE *in, IMAGE *out, int compression, int interlace, char **obuf, size_t *olen ) { if( vips_pngsave_buffer( in, (void **) obuf, olen, "compression", compression, "interlace", interlace, NULL ) ) return( -1 ); if( out ) im_add_callback( out, "close", (im_callback_fn) vips_free, obuf, NULL ); return( 0 ); }
static VALUE png_buf_internal(VALUE obj, VALUE compression, VALUE interlace) { char *buf; size_t length; GetImg(obj, data, im); #if ATLEAST_VIPS( 7, 28 ) if (vips_pngsave_buffer(im, &buf, &length, "compression", NUM2INT(compression), "interlace", NUM2INT(interlace), NULL)) vips_lib_error(); #elif ATLEAST_VIPS( 7, 23 ) if (im_vips2bufpng(im, NULL, NUM2INT(compression), NUM2INT(interlace), &buf, &length)) vips_lib_error(); #else rb_raise(eVIPSError, "This method is not implemented in your version of VIPS"); #endif return rb_tainted_str_new(buf, length); }