remove im_setupout
The now-useless im_setupout() is toast
This commit is contained in:
parent
0b9189b2ef
commit
0497fa0737
@ -80,6 +80,9 @@ typedef int (*im__fftproc_fn)( VipsImage *, VipsImage *, VipsImage * );
|
||||
/* iofuncs
|
||||
*/
|
||||
int vips_image_open_input( VipsImage *image );
|
||||
int vips_image_open_output( VipsImage *image );
|
||||
|
||||
int vips__image_write_prepare( VipsImage *image );
|
||||
|
||||
int im_mapfile( VipsImage * );
|
||||
int im_mapfilerw( VipsImage * );
|
||||
|
@ -175,6 +175,7 @@ extern "C" {
|
||||
xsize, ysize, bands, bandfmt, coding, \
|
||||
type, xres, yres )
|
||||
|
||||
#define im_setupout( IM ) (0)
|
||||
#define im_writeline( Y, IM, P ) vips_image_write_line( IM, Y, P )
|
||||
|
||||
#define im_prepare vips_region_prepare
|
||||
|
@ -13,7 +13,6 @@ libiofuncs_la_SOURCES = \
|
||||
im_demand_hint.c \
|
||||
im_generate.c \
|
||||
im_mapfile.c \
|
||||
im_setupout.c \
|
||||
sinkmemory.c \
|
||||
sinkscreen.c \
|
||||
sinkdisc.c \
|
||||
|
@ -419,7 +419,7 @@ im_generate( IMAGE *im,
|
||||
|
||||
/* Get output ready.
|
||||
*/
|
||||
if( im_setupout( im ) )
|
||||
if( vips__image_write_prepare( im ) )
|
||||
return( -1 );
|
||||
|
||||
/* Attach callbacks.
|
||||
|
@ -1,165 +0,0 @@
|
||||
/* get an image ready for im_writeline()
|
||||
*
|
||||
* Copyright: Nicos Dessipris
|
||||
* Written on: 16/01/1990
|
||||
* Modified on : 04/04/1990, 28/02/1991
|
||||
* 15/4/93 JC
|
||||
* - partial image support added
|
||||
* 18/6/93 JC
|
||||
* - ANSIfied
|
||||
* 4/7/01 JC
|
||||
* - OPENOUT open delayed until here
|
||||
* 21/8/01 ruven
|
||||
* - stat/file needed
|
||||
* 22/8/05
|
||||
* * - less stupid header write
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file is part of VIPS.
|
||||
|
||||
VIPS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_SYS_FILE_H
|
||||
#include <sys/file.h>
|
||||
#endif /*HAVE_SYS_FILE_H*/
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
#include <vips/debug.h>
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif /*WITH_DMALLOC*/
|
||||
|
||||
/* Open mode for write ... on some systems, have to set BINARY too.
|
||||
*/
|
||||
#ifdef BINARY_OPEN
|
||||
#define MODE (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)
|
||||
#else
|
||||
#define MODE (O_WRONLY | O_CREAT | O_TRUNC)
|
||||
#endif /*BINARY_OPEN*/
|
||||
|
||||
/**
|
||||
* im_setupout:
|
||||
* @im: image to prepare for writing
|
||||
*
|
||||
* This call gets the #IMAGE ready for scanline-based writing with
|
||||
* im_writeline(). You need to have set all the image fields, such as @Xsize
|
||||
* and @BandFmt, before calling this.
|
||||
*
|
||||
* See also: im_writeline(), im_generate(), im_initdesc(), im_cp_desc().
|
||||
*
|
||||
* Returns: 0 on success, or -1 on error.
|
||||
*/
|
||||
int
|
||||
im_setupout( IMAGE *im )
|
||||
{
|
||||
g_assert( vips_object_sanity( VIPS_OBJECT( im ) ) );
|
||||
|
||||
if( im->Xsize <= 0 || im->Ysize <= 0 || im->Bands <= 0 ) {
|
||||
vips_error( "im_setupout",
|
||||
"%s", _( "bad dimensions" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* We don't use this, but make sure it's set in case any old binaries
|
||||
* are expectiing it.
|
||||
*/
|
||||
im->Bbits = vips_format_sizeof( im->BandFmt ) << 3;
|
||||
|
||||
if( im->dtype == VIPS_IMAGE_PARTIAL ) {
|
||||
/* Make it into a im_setbuf() image.
|
||||
*/
|
||||
#ifdef DEBUG_IO
|
||||
printf( "im_setupout: old-style output for %s\n",
|
||||
im->filename );
|
||||
#endif /*DEBUG_IO*/
|
||||
|
||||
im->dtype = VIPS_IMAGE_SETBUF;
|
||||
}
|
||||
|
||||
switch( im->dtype ) {
|
||||
case VIPS_IMAGE_MMAPINRW:
|
||||
case VIPS_IMAGE_SETBUF_FOREIGN:
|
||||
/* No action.
|
||||
*/
|
||||
break;
|
||||
|
||||
case VIPS_IMAGE_SETBUF:
|
||||
/* Allocate memory.
|
||||
*/
|
||||
if( im->data ) {
|
||||
/* Sanity failure!
|
||||
*/
|
||||
vips_error( "im_setupout",
|
||||
"%s", _( "called twice!" ) );
|
||||
return( -1 );
|
||||
}
|
||||
if( !(im->data = im_malloc( NULL,
|
||||
VIPS_IMAGE_SIZEOF_LINE( im ) * im->Ysize )) )
|
||||
return( -1 );
|
||||
|
||||
break;
|
||||
|
||||
case VIPS_IMAGE_OPENOUT:
|
||||
{
|
||||
/* Don't use im->sizeof_header here, but we know we're
|
||||
* writing a VIPS image anyway.
|
||||
*/
|
||||
unsigned char header[IM_SIZEOF_HEADER];
|
||||
|
||||
if( (im->fd = open( im->filename, MODE, 0666 )) < 0 ) {
|
||||
vips_error( "im_setupout",
|
||||
_( "unable to write to \"%s\"" ),
|
||||
im->filename );
|
||||
return( -1 );
|
||||
}
|
||||
if( im__write_header_bytes( im, header ) ||
|
||||
im__write( im->fd, header, IM_SIZEOF_HEADER ) )
|
||||
return( -1 );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
vips_error( "im_setupout",
|
||||
"%s", _( "bad image descriptor" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
@ -1766,6 +1766,65 @@ vips_image_new_array( VipsImage *parent, VipsImage **images, int n )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Get the image ready for writing. This can get called many
|
||||
* times. Used by im_generate() and vips_image_write_line().
|
||||
*/
|
||||
int
|
||||
vips__image_write_prepare( VipsImage *image )
|
||||
{
|
||||
g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) );
|
||||
|
||||
if( image->Xsize <= 0 ||
|
||||
image->Ysize <= 0 ||
|
||||
image->Bands <= 0 ) {
|
||||
vips_error( "VipsImage", "%s", _( "bad dimensions" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* We don't use this, but make sure it's set in case any old programs
|
||||
* are expecting it.
|
||||
*/
|
||||
image->Bbits = vips_format_sizeof( image->BandFmt ) << 3;
|
||||
|
||||
if( image->dtype == VIPS_IMAGE_PARTIAL ) {
|
||||
/* Make it into a im_setbuf() image.
|
||||
*/
|
||||
VIPS_DEBUG_MSG( "vips__image_write_prepare: "
|
||||
"old-style output for %s\n", image->filename );
|
||||
|
||||
image->dtype = VIPS_IMAGE_SETBUF;
|
||||
}
|
||||
|
||||
switch( image->dtype ) {
|
||||
case VIPS_IMAGE_MMAPINRW:
|
||||
case VIPS_IMAGE_SETBUF_FOREIGN:
|
||||
break;
|
||||
|
||||
case VIPS_IMAGE_SETBUF:
|
||||
/* Allocate memory.
|
||||
*/
|
||||
if( !image->data )
|
||||
if( !(image->data = im_malloc( NULL,
|
||||
VIPS_IMAGE_SIZEOF_IMAGE( image ))) )
|
||||
return( -1 );
|
||||
|
||||
break;
|
||||
|
||||
case VIPS_IMAGE_OPENOUT:
|
||||
if( vips_image_open_output( image ) )
|
||||
return( -1 );
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
vips_error( "im_setupout",
|
||||
"%s", _( "bad image descriptor" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_image_write_line:
|
||||
* @image: image to write to
|
||||
@ -1787,8 +1846,10 @@ vips_image_write_line( VipsImage *image, int ypos, PEL *linebuffer )
|
||||
|
||||
/* Is this the start of eval?
|
||||
*/
|
||||
if( ypos == 0 )
|
||||
if( ypos == 0 ) {
|
||||
vips__image_write_prepare( image );
|
||||
vips_image_preeval( image );
|
||||
}
|
||||
|
||||
/* Possible cases for output: FILE or SETBUF.
|
||||
*/
|
||||
|
@ -124,8 +124,8 @@
|
||||
|
||||
/* Sort of open for read for image files. Shared with im_binfile().
|
||||
*/
|
||||
int
|
||||
im__open_image_file( const char *filename )
|
||||
static int
|
||||
vips_open_image_read( const char *filename )
|
||||
{
|
||||
int fd;
|
||||
|
||||
@ -137,9 +137,8 @@ im__open_image_file( const char *filename )
|
||||
/* Open read-write failed. Fall back to open read-only.
|
||||
*/
|
||||
if( (fd = open( filename, MODE_READONLY )) == -1 ) {
|
||||
vips_error( "im__open_image_file",
|
||||
_( "unable to open \"%s\", %s" ),
|
||||
filename, strerror( errno ) );
|
||||
vips_error_system( errno, "vips_open_image_read",
|
||||
_( "unable to open \"%s\"" ), filename );
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
@ -913,13 +912,13 @@ vips_image_open_input( VipsImage *image )
|
||||
gint64 rsize;
|
||||
|
||||
image->dtype = VIPS_IMAGE_OPENIN;
|
||||
if( (image->fd = im__open_image_file( image->filename )) == -1 )
|
||||
if( (image->fd = vips_open_image_read( image->filename )) == -1 )
|
||||
return( -1 );
|
||||
if( read( image->fd, header, IM_SIZEOF_HEADER ) != IM_SIZEOF_HEADER ||
|
||||
im__read_header_bytes( image, header ) ) {
|
||||
vips_error( "vips_open_input",
|
||||
_( "unable to read header for \"%s\", %s" ),
|
||||
image->filename, strerror( errno ) );
|
||||
vips_error_system( errno, "vips_open_input",
|
||||
_( "unable to read header for \"%s\"" ),
|
||||
image->filename );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
@ -950,3 +949,28 @@ vips_image_open_input( VipsImage *image )
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
vips_image_open_output( VipsImage *image )
|
||||
{
|
||||
if( image->fd == -1 ) {
|
||||
/* Don't use im->sizeof_header here, but we know we're
|
||||
* writing a VIPS image anyway.
|
||||
*/
|
||||
unsigned char header[IM_SIZEOF_HEADER];
|
||||
|
||||
if( (image->fd = open( image->filename,
|
||||
MODE_WRITE, 0666 )) < 0 ) {
|
||||
vips_error_system( errno, "vips_image_open_output",
|
||||
_( "unable to write to \"%s\"" ),
|
||||
image->filename );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( im__write_header_bytes( image, header ) ||
|
||||
im__write( image->fd, header, IM_SIZEOF_HEADER ) )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user