/** * im_vips2raw: * @in: image to save * @fd: file descriptor to write to * * Writes the pixels in @in to the file descriptor. It's handy for writing * writers for other formats. * * See also: #VipsFormat, im_raw2vips(). * * Returns: 0 on success, -1 on error. */ int im_vips2raw( IMAGE *in, int fd ) { Write *write; if( im_pincheck( in ) || !(write = write_new( in, fd )) ) return( -1 ); if( vips_sink_disc( in, write_block, write ) ) { write_destroy( write ); return( -1 ); } write_destroy( write ); return( 0 ); }
/* 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 ); }
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_buf( VipsImage *in, void **obuf, size_t *olen, int compression, int interlace, const char *profile, VipsForeignPngFilter filter ) { WriteBuf *wbuf; Write *write; if( !(wbuf = write_buf_new()) ) return( -1 ); if( !(write = write_new( in )) ) { write_buf_free( wbuf ); return( -1 ); } png_set_write_fn( write->pPng, wbuf, user_write_data, NULL ); /* Convert it! */ if( write_vips( write, compression, interlace, profile, filter ) ) { write_buf_free( wbuf ); vips_error( "vips2png", "%s", _( "unable to write to buffer" ) ); return( -1 ); } write_finish( write ); *obuf = wbuf->buf; wbuf->buf = NULL; if( olen ) *olen = wbuf->len; write_buf_free( wbuf ); 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__tiff_write( VipsImage *in, const char *filename, VipsForeignTiffCompression compression, int Q, VipsForeignTiffPredictor predictor, char *profile, gboolean tile, int tile_width, int tile_height, gboolean pyramid, gboolean squash, gboolean miniswhite, VipsForeignTiffResunit resunit, double xres, double yres, gboolean bigtiff, gboolean rgbjpeg, gboolean properties, gboolean strip ) { Write *write; #ifdef DEBUG printf( "tiff2vips: libtiff version is \"%s\"\n", TIFFGetVersion() ); #endif /*DEBUG*/ vips__tiff_init(); if( vips_check_coding_known( "vips2tiff", in ) ) return( -1 ); /* Make output image. */ if( !(write = write_new( in, filename, compression, Q, predictor, profile, tile, tile_width, tile_height, pyramid, squash, miniswhite, resunit, xres, yres, bigtiff, rgbjpeg, properties, strip )) ) return( -1 ); if( vips_sink_disc( write->im, write_strip, write ) ) { write_free( write ); return( -1 ); } if( !TIFFWriteDirectory( write->layer->tif ) ) return( -1 ); if( write->pyramid ) { /* Free lower pyramid resources ... this will TIFFClose() (but * not delete) the smaller layers ready for us to read from * them again. */ if( write->layer->below ) pyramid_free( write->layer->below ); /* Append smaller layers to the main file. */ if( write_gather( write ) ) { write_free( write ); return( -1 ); } } write_free( write ); return( 0 ); }
/** * im_vips2jpeg: * @in: image to save * @filename: file to write to * * Write a VIPS image to a file as JPEG. * * You can embed options in the filename. They have the form: * * |[ * filename.jpg:<emphasis>compression</emphasis>,<emphasis>profile</emphasis> * ]| * * <itemizedlist> * <listitem> * <para> * <emphasis>compression</emphasis> * Compress with this quality factor. Default 75. * </para> * </listitem> * <listitem> * <para> * <emphasis>profile</emphasis> * Attach this ICC profile. For example, "fred.jpg:,/home/john/srgb.icc" will * embed the profile stored in the file "/home/john/srgb.icc" in the JPEG * image. This does not affect the pixels which are written, just the way * they are tagged. You can use the special string "none" to mean * "don't attach a profile". * </para> * </listitem> * </itemizedlist> * * If no profile is specified in the save string and the VIPS header * contains an ICC profile named IM_META_ICC_NAME ("icc-profile-data"), the * profile from the VIPS header will be attached. * * The image is automatically converted to RGB, Monochrome or CMYK before * saving. Any metadata attached to the image is saved as EXIF, if possible. * * Example: * * |[ * im_vips2jpeg( in, "fred.jpg:99,none" ); * ]| * * Will write "fred.jpg" at high-quality with no ICC profile. * * See also: #VipsFormat, im_jpeg2vips(). * * Returns: 0 on success, -1 on error. */ int im_vips2jpeg( IMAGE *in, const char *filename ) { Write *write; int qfac = 75; char *profile = NULL; char *p, *q; char name[FILENAME_MAX]; char mode[FILENAME_MAX]; char buf[FILENAME_MAX]; /* Parse mode from filename. */ im_filename_split( filename, name, mode ); strcpy( buf, mode ); p = &buf[0]; if( (q = im_getnextoption( &p )) ) { if( strcmp( q, "" ) != 0 ) qfac = atoi( mode ); } if( (q = im_getnextoption( &p )) ) { if( strcmp( q, "" ) != 0 ) profile = q; } if( (q = im_getnextoption( &p )) ) { im_error( "im_vips2jpeg", _( "unknown extra options \"%s\"" ), q ); return( -1 ); } 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 = im__file_open_write( name, FALSE )) ) { write_destroy( write ); return( -1 ); } jpeg_stdio_dest( &write->cinfo, write->eman.fp ); /* Convert! */ if( write_vips( write, qfac, profile ) ) { write_destroy( write ); return( -1 ); } write_destroy( write ); return( 0 ); }