static void vips_thread_profile_save( VipsThreadProfile *profile ) { g_mutex_lock( vips__global_lock ); VIPS_DEBUG_MSG( "vips_thread_profile_save: %s\n", profile->name ); if( !vips__thread_fp ) { vips__thread_fp = vips__file_open_write( "vips-profile.txt", TRUE ); if( !vips__thread_fp ) { g_mutex_unlock( vips__global_lock ); g_warning( "unable to create profile log" ); return; } printf( "recording profile in vips-profile.txt\n" ); } fprintf( vips__thread_fp, "thread: %s (%p)\n", profile->name, profile ); g_hash_table_foreach( profile->gates, vips_thread_profile_save_cb, vips__thread_fp ); vips_thread_profile_save_gate( profile->memory, vips__thread_fp ); g_mutex_unlock( vips__global_lock ); }
int vips__matrix_write( VipsImage *in, const char *filename ) { VipsImage *mask; FILE *fp; int x, y; if( vips_check_matrix( "vips2mask", in, &mask ) ) return( -1 ); if( !(fp = vips__file_open_write( filename, TRUE )) ) { g_object_unref( mask ); return( -1 ); } fprintf( fp, "%d %d ", mask->Xsize, mask->Ysize ); if( vips_image_get_typeof( mask, "scale" ) && vips_image_get_typeof( mask, "offset" ) ) fprintf( fp, "%g %g ", vips_image_get_scale( mask ), vips_image_get_offset( mask ) ); fprintf( fp, "\n" ); for( y = 0; y < mask->Ysize; y++ ) { for( x = 0; x < mask->Xsize; x++ ) fprintf( fp, "%g ", *VIPS_MATRIX( mask, x, y ) ); fprintf( fp, "\n" ); } g_object_unref( mask ); fclose( fp ); return( 0 ); }
int vips__csv_write( VipsImage *in, const char *filename, const char *separator ) { FILE *fp; VipsImage *memory; if( vips_check_mono( "vips2csv", in ) || vips_check_uncoded( "vips2csv", in ) || !(memory = vips_image_copy_memory( in )) ) return( -1 ); if( !(fp = vips__file_open_write( filename, TRUE )) ) { VIPS_UNREF( memory ); return( -1 ); } if( vips2csv( memory, fp, separator ) ) { fclose( fp ); VIPS_UNREF( memory ); return( -1 ); } fclose( fp ); VIPS_UNREF( memory ); return( 0 ); }
int vips__matrix_write( VipsImage *in, const char *filename ) { FILE *fp; int result; if( !(fp = vips__file_open_write( filename, TRUE )) ) return( -1 ); result = vips__matrix_write_file( in, fp ); fclose( fp ); return( result ); }
/* Write an image to a jpeg file. */ int vips__jpeg_write_file( VipsImage *in, const char *filename, int Q, const char *profile, gboolean optimize_coding, gboolean progressive, gboolean strip, gboolean no_subsample, gboolean trellis_quant, gboolean overshoot_deringing, gboolean optimize_scans, int quant_table ) { Write *write; if( !(write = write_new( in )) ) return( -1 ); if( setjmp( write->eman.jmp ) ) { /* Here for longjmp() from new_error_exit(). */ write_destroy( write ); return( -1 ); } /* Can't do this in write_new(), has to be after we've made the * setjmp(). */ jpeg_create_compress( &write->cinfo ); /* Make output. */ if( !(write->eman.fp = vips__file_open_write( filename, FALSE )) ) { write_destroy( write ); return( -1 ); } jpeg_stdio_dest( &write->cinfo, write->eman.fp ); /* Convert! */ if( write_vips( write, Q, profile, optimize_coding, progressive, strip, no_subsample, trellis_quant, overshoot_deringing, optimize_scans, quant_table ) ) { write_destroy( write ); return( -1 ); } write_destroy( write ); return( 0 ); }
static Write * write_new( VipsImage *in, const char *name ) { Write *write; if( !(write = VIPS_NEW( NULL, Write )) ) return( NULL ); write->in = in; write->name = vips_strdup( NULL, name ); write->fp = vips__file_open_write( name, FALSE ); if( !write->name || !write->fp ) { write_destroy( write ); return( NULL ); } return( write ); }
int vips__csv_write( VipsImage *in, const char *filename, const char *separator ) { FILE *fp; if( vips_check_mono( "vips2csv", in ) || vips_check_uncoded( "vips2csv", in ) || vips_image_wio_input( in ) ) return( -1 ); if( !(fp = vips__file_open_write( filename, TRUE )) ) return( -1 ); if( vips2csv( in, fp, separator ) ) { fclose( fp ); return( -1 ); } fclose( fp ); return( 0 ); }
int vips__png_write( VipsImage *in, const char *filename, int compress, int interlace, const char *profile, VipsForeignPngFilter filter, gboolean strip, gboolean palette, int colours, int Q, double dither ) { Write *write; #ifdef DEBUG printf( "vips__png_write: writing \"%s\"\n", filename ); #endif /*DEBUG*/ if( !(write = write_new( in )) ) return( -1 ); /* Make output. */ if( !(write->fp = vips__file_open_write( filename, FALSE )) ) return( -1 ); png_init_io( write->pPng, write->fp ); /* Convert it! */ if( write_vips( write, compress, interlace, profile, filter, strip, palette, colours, Q, dither ) ) { vips_error( "vips2png", _( "unable to write \"%s\"" ), filename ); return( -1 ); } write_finish( write ); #ifdef DEBUG printf( "vips__png_write: done\n" ); #endif /*DEBUG*/ return( 0 ); }
int vips__png_write( VipsImage *in, const char *filename, int compress, int interlace ) { Write *write; #ifdef DEBUG printf( "vips__png_write: writing \"%s\"\n", filename ); #endif /*DEBUG*/ if( !(write = write_new( in )) ) return( -1 ); /* Make output. */ if( !(write->fp = vips__file_open_write( filename, FALSE )) ) return( -1 ); png_init_io( write->pPng, write->fp ); /* Convert it! */ if( write_vips( write, compress, interlace ) ) { vips_error( "vips2png", _( "unable to write \"%s\"" ), filename ); return( -1 ); } write_finish( write ); #ifdef DEBUG printf( "vips__png_write: done\n" ); #endif /*DEBUG*/ return( 0 ); }
int vips__webp_write_file( VipsImage *in, const char *filename, int Q, gboolean lossless ) { size_t len; uint8_t *buffer; FILE *fp; if( vips_image_wio_input( in ) ) return( -1 ); if( lossless ) { webp_encoder_lossless encoder; if( in->Bands == 4 ) encoder = WebPEncodeLosslessRGBA; else encoder = WebPEncodeLosslessRGB; if( !(len = encoder( VIPS_IMAGE_ADDR( in, 0, 0 ), in->Xsize, in->Ysize, VIPS_IMAGE_SIZEOF_LINE( in ), &buffer )) ) { vips_error( "vips2webp", "%s", _( "unable to encode" ) ); return( -1 ); } } else { webp_encoder encoder; if( in->Bands == 4 ) encoder = WebPEncodeRGBA; else encoder = WebPEncodeRGB; if( !(len = encoder( VIPS_IMAGE_ADDR( in, 0, 0 ), in->Xsize, in->Ysize, VIPS_IMAGE_SIZEOF_LINE( in ), Q, &buffer )) ) { vips_error( "vips2webp", "%s", _( "unable to encode" ) ); return( -1 ); } } if( !(fp = vips__file_open_write( filename, FALSE )) ) { free( buffer ); return( -1 ); } if( vips__file_write( buffer, len, 1, fp ) ) { fclose( fp ); free( buffer ); return( -1 ); } fclose( fp ); free( buffer ); return( 0 ); }