remove setbuf

... and start on sink*().
This commit is contained in:
John Cupitt 2011-03-01 22:07:48 +00:00
parent 7257c5426a
commit be134f4b82
7 changed files with 59 additions and 133 deletions

View File

@ -17,7 +17,6 @@ libiofuncs_la_SOURCES = \
im_histlin.c \
im_mapfile.c \
im_prepare.c \
im_setbuf.c \
im_setupout.c \
im_guess_prefix.c \
sinkmemory.c \

View File

@ -1,13 +1,4 @@
/* @(#) Function which copies IMAGE descriptor image2 to image1;
* @(#) data, fd and filename are not copied
* @(#) used to make programs simpler by copying most parameters
* @(#)
* @(#) int
* @(#) im_cp_desc( image1, image2 )
* @(#) IMAGE *image1, *image2;
* @(#)
* @(#) Returns 0 on success or -1 on fail.
* @(#)
/* copy iamge descriptors
*
* Copyright: Nicos Dessipris
* Written on: 09/02/1990

View File

@ -143,6 +143,14 @@ im__link_mapp( IMAGE *im, VSListMap2Fn fn, int *serial, void *a, void *b )
(VSListMap4Fn) im__link_mapp, fn, serial, a, b ) );
}
static void *
im__link_map_cb( VipsImage *image, GSList **images )
{
*images = g_slist_prepend( *images, image );
return( NULL );
}
/* Apply a function to an image and all downstream images, direct and indirect.
*/
void *
@ -150,21 +158,29 @@ im__link_map( IMAGE *im, VSListMap2Fn fn, void *a, void *b )
{
static int serial = 0;
/* Invalidate callbacks might do anything, including removing images
GSList *images;
GSList *p;
void *result;
/* The function might do anything, including removing images
* or invalidating other images, so we can't trigger them from within
* the image loop. Instead we collect a list of image to invalidate
* and trigger them all in one go, checking that they are not
* invalidated.
* the image loop. Instead we collect a list of images, ref them,
* run the functions, and unref.
*/
/* im__link_mapp() needs to make the list, ref all the images, call
* the callbacks, then unref and free the list.
*/
FIXME
serial += 1;
return( im__link_mapp( im, fn, &serial, a, b ) );
images = NULL;
im__link_mapp( im,
(VSListMap2Fn) im__link_map_cb, &serial, &images, NULL );
for( p = images; p; p = p->next )
g_object_ref( p->data );
result = im_slist_map2( images, fn, a, b );
for( p = images; p; p = p->next )
g_object_unref( p->data );
g_slist_free( images );
return( result );
}
/* Given two im_demand_type, return the most restrictive.

View File

@ -1,74 +0,0 @@
/* @(#) im_setbuf: initialise a buffer IMAGE
* @(#) Initialise the data pointer of the image descriptor to an arbitrary
* @(#) non NULL value and copies the file_name onto the filename of the
* @(#) image structure.
* @(#)
* @(#) Right call:
* @(#) IMAGE *im_setbuf(file_name)
* @(#) char *file_name;
* @(#)
*
* Copyright: Nicos Dessipris
* Written on: 13/02/1990
* Modified on : 25/04/1990 KM, 20/03/1991 ND
* 16/4/93 J.Cupitt
* - support for type field added
*/
/*
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 <vips/vips.h>
#include <vips/internal.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
IMAGE *
im_setbuf( const char *file_name )
{
IMAGE *im;
if( !(im = im_init( file_name )) )
return( NULL );
im->dtype = IM_SETBUF;
/* Set demand style. Allow the most permissive sort.
*/
im->dhint = IM_ANY;
return( im );
}

View File

@ -91,7 +91,7 @@ im_setupout( IMAGE *im )
g_assert( !im_image_sanity( im ) );
if( im->Xsize <= 0 || im->Ysize <= 0 || im->Bands <= 0 ) {
im_error( "im_setupout",
vips_error( "im_setupout",
"%s", _( "bad dimensions" ) );
return( -1 );
}
@ -101,7 +101,7 @@ im_setupout( IMAGE *im )
*/
im->Bbits = im_bits_of_fmt( im->BandFmt );
if( im->dtype == IM_PARTIAL ) {
if( im->dtype == VIPS_IMAGE_PARTIAL ) {
/* Make it into a im_setbuf() image.
*/
#ifdef DEBUG_IO
@ -109,33 +109,33 @@ im_setupout( IMAGE *im )
im->filename );
#endif /*DEBUG_IO*/
im->dtype = IM_SETBUF;
im->dtype = VIPS_IMAGE_SETBUF;
}
switch( im->dtype ) {
case IM_MMAPINRW:
case IM_SETBUF_FOREIGN:
case VIPS_IMAGE_MMAPINRW:
case VIPS_IMAGE_SETBUF_FOREIGN:
/* No action.
*/
break;
case IM_SETBUF:
case VIPS_IMAGE_SETBUF:
/* Allocate memory.
*/
if( im->data ) {
/* Sanity failure!
*/
im_error( "im_setupout",
vips_error( "im_setupout",
"%s", _( "called twice!" ) );
return( -1 );
}
if( !(im->data = im_malloc( NULL,
IM_IMAGE_SIZEOF_LINE( im ) * im->Ysize )) )
VIPS_IMAGE_SIZEOF_LINE( im ) * im->Ysize )) )
return( -1 );
break;
case IM_OPENOUT:
case VIPS_IMAGE_OPENOUT:
{
/* Don't use im->sizeof_header here, but we know we're
* writing a VIPS image anyway.
@ -143,7 +143,7 @@ im_setupout( IMAGE *im )
unsigned char header[IM_SIZEOF_HEADER];
if( (im->fd = open( im->filename, MODE, 0666 )) < 0 ) {
im_error( "im_setupout",
vips_error( "im_setupout",
_( "unable to write to \"%s\"" ),
im->filename );
return( -1 );
@ -156,7 +156,7 @@ im_setupout( IMAGE *im )
}
default:
im_error( "im_setupout",
vips_error( "im_setupout",
"%s", _( "bad image descriptor" ) );
return( -1 );
}

View File

@ -75,7 +75,7 @@ typedef struct _Sink {
static void
sink_free( Sink *sink )
{
IM_FREEF( im_region_free, sink->all );
VIPS_FREEF( im_region_free, sink->all );
}
static int

View File

@ -208,7 +208,7 @@ tile_free( Tile *tile )
{
VIPS_DEBUG_MSG_AMBER( "tile_free\n" );
IM_FREEF( im_region_free, tile->region );
VIPS_FREEF( im_region_free, tile->region );
im_free( tile );
return( NULL );
@ -236,10 +236,10 @@ render_free( Render *render )
g_mutex_free( render->lock );
im_slist_map2( render->all, (VSListMap2Fn) tile_free, NULL, NULL );
IM_FREEF( g_slist_free, render->all );
VIPS_FREEF( g_slist_free, render->all );
render->ntiles = 0;
IM_FREEF( g_slist_free, render->dirty );
IM_FREEF( g_hash_table_destroy, render->tiles );
VIPS_FREEF( g_slist_free, render->dirty );
VIPS_FREEF( g_hash_table_destroy, render->tiles );
im_free( render );
@ -536,7 +536,7 @@ render_thread_create( void )
render_thread_main, NULL,
IM__DEFAULT_STACK_SIZE, TRUE, FALSE,
G_THREAD_PRIORITY_NORMAL, NULL )) ) {
im_error( "im_render",
vips_error( "im_render",
"%s", _( "unable to create thread" ) );
return( -1 );
}
@ -594,7 +594,7 @@ render_new( VipsImage *in, VipsImage *out, VipsImage *mask,
/* Don't use auto-free for render, we do our own lifetime management
* with _ref() and _unref().
*/
if( !(render = IM_NEW( NULL, Render )) )
if( !(render = VIPS_NEW( NULL, Render )) )
return( NULL );
render->ref_count = 1;
@ -622,19 +622,12 @@ render_new( VipsImage *in, VipsImage *out, VipsImage *mask,
/* Both out and mask must close before we can free the render.
*/
if( im_add_close_callback( out,
(im_callback_fn) render_close_cb, render, NULL ) ) {
(void) render_unref( render );
return( NULL );
}
g_signal_connect( out, "close",
G_CALLBACK( render_close_cb ), render );
if( mask ) {
if( im_add_close_callback( mask,
(im_callback_fn) render_close_cb, render, NULL ) ) {
(void) render_unref( render );
return( NULL );
}
g_signal_connect( mask, "close",
G_CALLBACK( render_close_cb ), render );
render_ref( render );
}
@ -659,7 +652,7 @@ tile_new( Render *render )
/* Don't use auto-free: we need to make sure we free the tile after
* Render.
*/
if( !(tile = IM_NEW( NULL, Tile )) )
if( !(tile = VIPS_NEW( NULL, Tile )) )
return( NULL );
tile->render = render;
@ -884,7 +877,7 @@ tile_copy( Tile *tile, REGION *to )
* zero.
*/
if( tile->painted && !tile->region->invalid ) {
int len = IM_IMAGE_SIZEOF_PEL( to->im ) * ovlap.width;
int len = VIPS_IMAGE_SIZEOF_PEL( to->im ) * ovlap.width;
VIPS_DEBUG_MSG( "tile_copy: "
"copying calculated pixels for %p %dx%d\n",
@ -1087,24 +1080,25 @@ vips_sink_screen( VipsImage *in, VipsImage *out, VipsImage *mask,
if( tile_width <= 0 || tile_height <= 0 ||
max_tiles < -1 ) {
im_error( "vips_sink_screen", "%s", _( "bad parameters" ) );
vips_error( "vips_sink_screen", "%s", _( "bad parameters" ) );
return( -1 );
}
if( im_piocheck( in, out ) ||
im_cp_desc( out, in ) ||
im_demand_hint( out, IM_SMALLTILE, in, NULL ) )
im_demand_hint( out, VIPS_DEMAND_STYLE_SMALLTILE, in, NULL ) )
return( -1 );
if( mask ) {
if( im_poutcheck( mask ) ||
im_cp_desc( mask, in ) ||
im_demand_hint( mask, IM_SMALLTILE, in, NULL ) )
im_demand_hint( mask,
VIPS_DEMAND_STYLE_SMALLTILE, in, NULL ) )
return( -1 );
mask->Bands = 1;
mask->BandFmt = IM_BANDFMT_UCHAR;
mask->Type = IM_TYPE_B_W;
mask->Coding = IM_CODING_NONE;
mask->BandFmt = VIPS_FORMAT_UCHAR;
mask->Type = VIPS_INTERPRETATION_B_W;
mask->Coding = VIPS_CODING_NONE;
}
if( !(render = render_new( in, out, mask,