Ejemplo n.º 1
0
int
vips__ppm_save( VipsImage *in, const char *filename, gboolean ascii )
{
	Write *write;

	if( vips_check_uintorf( "vips2ppm", in ) || 
		vips_check_bands_1or3( "vips2ppm", in ) || 
		vips_check_uncoded( "vips2ppm", in ) || 
		vips_image_pio_input( in ) )
		return( -1 );

	/* We can only write >8 bit binary images in float.
	 */
	if( vips_format_sizeof( in->BandFmt ) > 1 && 
		!ascii && 
		in->BandFmt != VIPS_FORMAT_FLOAT ) {
		vips_error( "vips2ppm", 
			"%s", _( "binary >8 bit images must be float" ) );
		return( -1 );
	}

	if( !(write = write_new( in, filename )) )
		return( -1 );

	if( write_ppm( write, ascii ) ) {
		write_destroy( write );
		return( -1 );
	}
	write_destroy( write );

	return( 0 );
}
Ejemplo n.º 2
0
static Write *
write_new( IMAGE *in )
{
	Write *write;

	if( !(write = IM_NEW( NULL, Write )) )
		return( NULL );
	memset( write, 0, sizeof( Write ) );

	if( !(write->in = im__convert_saveable( in, 
		IM__RGB_CMYK, bandfmt_jpeg )) ) {
		im_error( "im_vips2jpeg", 
			"%s", _( "unable to convert to saveable format" ) );
		write_destroy( write );
		return( NULL );
	} 
	write->row_pointer = NULL;
        write->cinfo.err = jpeg_std_error( &write->eman.pub );
	write->eman.pub.error_exit = new_error_exit;
	write->eman.pub.output_message = new_output_message;
	write->eman.fp = NULL;
	write->profile_bytes = NULL;
	write->profile_length = 0;
	write->inverted = NULL;

        return( write );
}
Ejemplo n.º 3
0
/**
 * 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 );
}
Ejemplo n.º 4
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 );
}
Ejemplo n.º 5
0
static Write *
write_new( IMAGE *in, int fd )
{
  Write *write;

  if( !(write = IM_NEW( NULL, Write )) )
    return( NULL );

  write->in = in;
  write->fd = fd;
  
  if( !write->fd ) {
    write_destroy( write );
    return( NULL );
  }
  
  return( write );
}
Ejemplo n.º 6
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 );
}
Ejemplo n.º 7
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 );
}