yet more cleanups

just util.c left now, woo
This commit is contained in:
John Cupitt 2011-03-28 14:57:43 +01:00
parent b13872f111
commit c7b74f620f
14 changed files with 161 additions and 175 deletions

43
TODO
View File

@ -1,3 +1,6 @@
- work though headers making sure old im_ stuff is gone
- add MATLAB write
- need a way to make the vips.1 etc. man pages
@ -49,46 +52,6 @@
- why is im_setupout() necessary for WIO output? couldn't writeline call it if
it's not been called?
equally, could pincheck/poutcheck/outcheck be made optional?
im_region_create() could call pincheck for you, for example
though would this cause problems with threading? we need to incheck
from the main thread, not from a worker during pipeline build
open_lazy does a pincheck to rewind the disc conversion, but that could be
removed
incheck is necessary to make ->data valid I suppose, though perhaps
IM_IMAGE_ADDR() could call it for you
- perhaps replace all these with a single call:
int im_setup( IMAGE *im, VipsStyle style );
typedef enum VipsStyle {
VIPS_STYLE_PARTIAL,
VIPS_STYLE_WHOLE
};
and set read or write with:
int im_inputs( IMAGE *im, ... )
int im_output( IMAGE *im, ... )
this is all done for us by the new vips8 API though, don't bother changing
this now
- perspective transform with a matrix ... base it on the Lenz transformer, but
partial

View File

@ -22,6 +22,8 @@ libdeprecated_la_SOURCES = \
im_setbox.c \
rename.c \
vips7compat.c \
dispatch_types.c \
package.c \
im_bernd.c \
im_thresh.c \
im_slice.c \

View File

@ -83,29 +83,24 @@ int vips__open_image_read( const char *filename );
int vips_image_open_input( VipsImage *image );
int vips_image_open_output( VipsImage *image );
VipsImage *im_open_header( const char * );
int im_unmapfile( VipsImage * );
void im__read_4byte( int msb_first, unsigned char *to, unsigned char **from );
void im__read_2byte( int msb_first, unsigned char *to, unsigned char **from );
void im__write_4byte( unsigned char **to, unsigned char *from );
void im__write_2byte( unsigned char **to, unsigned char *from );
void vips__read_4byte( int msb_first, unsigned char *to, unsigned char **from );
void vips__read_2byte( int msb_first, unsigned char *to, unsigned char **from );
void vips__write_4byte( unsigned char **to, unsigned char *from );
void vips__write_2byte( unsigned char **to, unsigned char *from );
int vips__has_extension_block( VipsImage *im );
void *vips__read_extension_block( VipsImage *im, int *size );
int vips__write_extension_block( VipsImage *im, void *buf, int size );
int vips__writehist( VipsImage *image );
int vips__read_header_bytes( VipsImage *im, unsigned char *from );
int vips__write_header_bytes( VipsImage *im, unsigned char *to );
int im__ftruncate( int fd, gint64 pos );
int im__seek( int fd, gint64 pos );
int im__get_bytes( const char *filename, unsigned char buf[], int len );
gint64 im__image_pixel_length( VipsImage *im );
int im__open_image_file( const char * );
void im__format_init( void );
void im__type_init( void );
int im__read_header_bytes( VipsImage *im, unsigned char *from );
int im__write_header_bytes( VipsImage *im, unsigned char *to );
int im__has_extension_block( VipsImage *im );
void *im__read_extension_block( VipsImage *im, int *size );
int im__write_extension_block( VipsImage *im, void *buf, int size );
int im__writehist( VipsImage *image );
void im__tiff_register( void );
void im__jpeg_register( void );

View File

@ -48,14 +48,14 @@ typedef struct {
GMutex *mutex;
GCond *cond;
} im_semaphore_t;
} VipsSemaphore;
int im_semaphore_up( im_semaphore_t *s );
int im_semaphore_down( im_semaphore_t *s );
int im_semaphore_upn( im_semaphore_t *s, int n );
int im_semaphore_downn( im_semaphore_t *s, int n );
void im_semaphore_destroy( im_semaphore_t *s );
void im_semaphore_init( im_semaphore_t *s, int v, char *name );
int vips_semaphore_up( VipsSemaphore *s );
int vips_semaphore_down( VipsSemaphore *s );
int vips_semaphore_upn( VipsSemaphore *s, int n );
int vips_semaphore_downn( VipsSemaphore *s, int n );
void vips_semaphore_destroy( VipsSemaphore *s );
void vips_semaphore_init( VipsSemaphore *s, int v, char *name );
#ifdef __cplusplus
}

View File

@ -403,6 +403,29 @@ int im_wrapmany( VipsImage **in, VipsImage *out,
#define im_meta_set_blob vips_image_set_blob
#define im_meta_get_blob vips_image_get_blob
#define im_semaphore_t VipsSemaphore
#define im_semaphore_up vips_semaphore_up
#define im_semaphore_down vips_semaphore_down
#define im_semaphore_upn vips_semaphore_upn
#define im_semaphore_downn vips_semaphore_downn
#define im_semaphore_destroy vips_semaphore_destroy
#define im_semaphore_init vips_semaphore_init
#define im__open_image_read vips__open_image_read
#define im_image_open_input vips_image_open_input
#define im_image_open_output vips_image_open_output
#define im__read_4byte vips__read_4byte
#define im__read_2byte vips__read_2byte
#define im__write_4byte vips__write_4byte
#define im__write_2byte vips__write_2byte
#define im__has_extension_block vips__has_extension_block
#define im__read_extension_block vips__read_extension_block
#define im__write_extension_block vips__write_extension_block
#define im__writehist vips__writehist
#define im__read_header_bytes vips__read_header_bytes
#define im__write_header_bytes vips__write_header_bytes
#ifdef __cplusplus
}
#endif /*__cplusplus*/

View File

@ -5,7 +5,6 @@ libiofuncs_la_SOURCES = \
object.c \
base64.h \
base64.c \
dispatch_types.c \
error.c \
image.c \
vips.c \
@ -17,7 +16,6 @@ libiofuncs_la_SOURCES = \
sinkdisc.c \
sinkscreen.c \
memory.c \
package.c \
header.c \
region.c \
rect.c \

View File

@ -386,7 +386,7 @@ vips_image_finalize( GObject *gobject )
VIPS_DEBUG_MSG( "vips_image_finalize: closing output file\n" );
if( image->dtype == VIPS_IMAGE_OPENOUT )
(void) im__writehist( image );
(void) vips__writehist( image );
if( close( image->fd ) == -1 )
vips_error( "VipsImage",
_( "unable to close fd for %s" ),
@ -1425,7 +1425,8 @@ void
vips_image_set_progress( VipsImage *image, gboolean progress )
{
if( progress && !image->progress_signal ) {
VIPS_DEBUG_MSG( "vips_image_set_kill: %s\n", image->filename );
VIPS_DEBUG_MSG( "vips_image_set_progress: %s\n",
image->filename );
image->progress_signal = image;
}
else
@ -1918,7 +1919,7 @@ vips_image_write_line( VipsImage *image, int ypos, PEL *linebuffer )
/* Trigger evaluation callbacks for this image.
*/
vips_image_eval( image, image->Xsize, 1 );
if( im__test_kill( image ) )
if( vips_image_get_kill( image ) )
return( -1 );
/* Is this the end of eval?

View File

@ -6,6 +6,8 @@
* - return(0) missing from tidy_thread_info()
* 4/8/99 RP JC
* - reorganised for POSIX
* 28/3/11
* - moved to vips_ namespace
*/
/*
@ -56,7 +58,7 @@
#endif /*WITH_DMALLOC*/
void
im_semaphore_init( im_semaphore_t *s, int v, char *name )
vips_semaphore_init( VipsSemaphore *s, int v, char *name )
{
s->v = v;
s->name = name;
@ -67,7 +69,7 @@ im_semaphore_init( im_semaphore_t *s, int v, char *name )
}
void
im_semaphore_destroy( im_semaphore_t *s )
vips_semaphore_destroy( VipsSemaphore *s )
{
#ifdef HAVE_THREADS
VIPS_FREEF( g_mutex_free, s->mutex );
@ -79,7 +81,7 @@ im_semaphore_destroy( im_semaphore_t *s )
* a change.
*/
int
im_semaphore_upn( im_semaphore_t *s, int n )
vips_semaphore_upn( VipsSemaphore *s, int n )
{
int value_after_op;
@ -94,7 +96,7 @@ im_semaphore_upn( im_semaphore_t *s, int n )
#endif /*HAVE_THREADS*/
#ifdef DEBUG_IO
printf( "im_semaphore_upn(\"%s\",%d) = %d\n",
printf( "vips_semaphore_upn(\"%s\",%d) = %d\n",
s->name, n, value_after_op );
if( value_after_op > 1 )
im_errormsg( "up over 1!" );
@ -106,15 +108,15 @@ im_semaphore_upn( im_semaphore_t *s, int n )
/* Increment the semaphore.
*/
int
im_semaphore_up( im_semaphore_t *s )
vips_semaphore_up( VipsSemaphore *s )
{
return( im_semaphore_upn( s, 1 ) );
return( vips_semaphore_upn( s, 1 ) );
}
/* Wait for sem>n, then subtract n.
*/
int
im_semaphore_downn( im_semaphore_t *s, int n )
vips_semaphore_downn( VipsSemaphore *s, int n )
{
int value_after_op;
@ -130,17 +132,17 @@ im_semaphore_downn( im_semaphore_t *s, int n )
#endif /*HAVE_THREADS*/
#ifdef DEBUG_IO
printf( "im_semaphore_downn(\"%s\",%d): %d\n",
printf( "vips_semaphore_downn(\"%s\",%d): %d\n",
s->name, n, value_after_op );
#endif /*DEBUG_IO*/
return( value_after_op );
}
/* Wait for sem>0, then decrement.
/* Wait for sem > 0, then decrement.
*/
int
im_semaphore_down( im_semaphore_t *s )
vips_semaphore_down( VipsSemaphore *s )
{
return( im_semaphore_downn( s, 1 ) );
return( vips_semaphore_downn( s, 1 ) );
}

View File

@ -74,9 +74,9 @@ typedef struct _WriteBuffer {
VipsRegion *region; /* Pixels */
VipsRect area; /* Part of image this region covers */
im_semaphore_t go; /* Start bg thread loop */
im_semaphore_t nwrite; /* Number of threads writing to region */
im_semaphore_t done; /* Bg thread has done write */
VipsSemaphore go; /* Start bg thread loop */
VipsSemaphore nwrite; /* Number of threads writing to region */
VipsSemaphore done; /* Bg thread has done write */
int write_errno; /* Save write errors here */
GThread *thread; /* BG writer thread */
gboolean kill; /* Set to ask thread to exit */
@ -149,7 +149,7 @@ wbuffer_free( WriteBuffer *wbuffer )
*/
if( wbuffer->thread ) {
wbuffer->kill = TRUE;
im_semaphore_up( &wbuffer->go );
vips_semaphore_up( &wbuffer->go );
/* Return value is always NULL (see wbuffer_write_thread).
*/
@ -160,9 +160,9 @@ wbuffer_free( WriteBuffer *wbuffer )
}
VIPS_UNREF( wbuffer->region );
im_semaphore_destroy( &wbuffer->go );
im_semaphore_destroy( &wbuffer->nwrite );
im_semaphore_destroy( &wbuffer->done );
vips_semaphore_destroy( &wbuffer->go );
vips_semaphore_destroy( &wbuffer->nwrite );
vips_semaphore_destroy( &wbuffer->done );
vips_free( wbuffer );
}
@ -189,20 +189,20 @@ wbuffer_write_thread( void *data )
for(;;) {
/* Wait to be told to write.
*/
im_semaphore_down( &wbuffer->go );
vips_semaphore_down( &wbuffer->go );
if( wbuffer->kill )
break;
/* Now block until the last worker finishes on this buffer.
*/
im_semaphore_downn( &wbuffer->nwrite, 0 );
vips_semaphore_downn( &wbuffer->nwrite, 0 );
wbuffer_write( wbuffer );
/* Signal write complete.
*/
im_semaphore_up( &wbuffer->done );
vips_semaphore_up( &wbuffer->done );
}
return( NULL );
@ -218,9 +218,9 @@ wbuffer_new( Write *write )
return( NULL );
wbuffer->write = write;
wbuffer->region = NULL;
im_semaphore_init( &wbuffer->go, 0, "go" );
im_semaphore_init( &wbuffer->nwrite, 0, "nwrite" );
im_semaphore_init( &wbuffer->done, 0, "done" );
vips_semaphore_init( &wbuffer->go, 0, "go" );
vips_semaphore_init( &wbuffer->nwrite, 0, "nwrite" );
vips_semaphore_init( &wbuffer->done, 0, "done" );
wbuffer->write_errno = 0;
wbuffer->thread = NULL;
wbuffer->kill = FALSE;
@ -260,7 +260,7 @@ wbuffer_flush( Write *write )
* before we can set this buffer writing or we'll lose output ordering.
*/
if( write->buf->area.top > 0 ) {
im_semaphore_down( &write->buf_back->done );
vips_semaphore_down( &write->buf_back->done );
/* Previous write suceeded?
*/
@ -274,7 +274,7 @@ wbuffer_flush( Write *write )
/* Set the background writer going for this buffer.
*/
#ifdef HAVE_THREADS
im_semaphore_up( &write->buf->go );
vips_semaphore_up( &write->buf->go );
#else
/* No threads? Write ourselves synchronously.
*/
@ -390,7 +390,7 @@ wbuffer_allocate_fn( VipsThreadState *state, void *a, gboolean *stop )
/* Add to the number of writers on the buffer.
*/
im_semaphore_upn( &write->buf->nwrite, -1 );
vips_semaphore_upn( &write->buf->nwrite, -1 );
/* Move state on.
*/
@ -414,7 +414,7 @@ wbuffer_work_fn( VipsThreadState *state, void *a )
/* Tell the bg write thread we've left.
*/
im_semaphore_upn( &wstate->buf->nwrite, 1 );
vips_semaphore_upn( &wstate->buf->nwrite, 1 );
return( 0 );
}
@ -506,7 +506,7 @@ vips_sink_disc( VipsImage *im, VipsRegionWrite write_fn, void *a )
* the final write went through or not.
*/
if( !result )
im_semaphore_down( &write.buf->done );
vips_semaphore_down( &write.buf->done );
vips_image_posteval( im );

View File

@ -169,7 +169,7 @@ static GThread *render_thread = NULL;
/* Number of renders with dirty tiles. render_thread queues up on this.
*/
static im_semaphore_t render_dirty_sem;
static VipsSemaphore render_dirty_sem;
/* All the renders with dirty tiles.
*/
@ -225,7 +225,7 @@ render_free( Render *render )
if( g_slist_find( render_dirty_all, render ) ) {
render_dirty_all = g_slist_remove( render_dirty_all, render );
/* We could im_semaphore_upn( &render_dirty_sem, -1 ), but
/* We could vips_semaphore_upn( &render_dirty_sem, -1 ), but
* what's the point. We'd just wake up the bg thread
* for no reason.
*/
@ -289,7 +289,7 @@ render_dirty_get( void )
/* Wait for a render with dirty tiles.
*/
im_semaphore_down( &render_dirty_sem );
vips_semaphore_down( &render_dirty_sem );
g_mutex_lock( render_dirty_lock );
@ -469,7 +469,7 @@ render_dirty_put( Render *render )
"reschedule\n" );
render_reschedule = TRUE;
im_semaphore_up( &render_dirty_sem );
vips_semaphore_up( &render_dirty_sem );
}
}
@ -529,7 +529,7 @@ render_thread_create( void )
if( !render_dirty_lock ) {
render_dirty_lock = g_mutex_new();
im_semaphore_init( &render_dirty_sem, 0, "render_dirty_sem" );
vips_semaphore_init( &render_dirty_sem, 0, "render_dirty_sem" );
}
if( !render_thread && have_threads ) {

View File

@ -367,11 +367,11 @@ typedef struct _VipsThreadpool {
/* The caller blocks here until all threads finish.
*/
im_semaphore_t finish;
VipsSemaphore finish;
/* Workers up this for every loop to make the main thread tick.
*/
im_semaphore_t tick;
VipsSemaphore tick;
/* Set this to abort evaluation early with an error.
*/
@ -549,7 +549,7 @@ vips_thread_main_loop( void *a )
*/
for(;;) {
vips_thread_work_unit( thr );
im_semaphore_up( &pool->tick );
vips_semaphore_up( &pool->tick );
if( pool->stop || pool->error )
break;
@ -557,7 +557,7 @@ vips_thread_main_loop( void *a )
/* We are exiting: tell the main thread.
*/
im_semaphore_up( &pool->finish );
vips_semaphore_up( &pool->finish );
return( NULL );
}
@ -644,8 +644,8 @@ vips_threadpool_free( VipsThreadpool *pool )
vips_threadpool_kill_threads( pool );
VIPS_FREEF( g_mutex_free, pool->allocate_lock );
im_semaphore_destroy( &pool->finish );
im_semaphore_destroy( &pool->tick );
vips_semaphore_destroy( &pool->finish );
vips_semaphore_destroy( &pool->tick );
return( 0 );
}
@ -671,8 +671,8 @@ vips_threadpool_new( VipsImage *im )
pool->allocate_lock = g_mutex_new();
pool->nthr = im_concurrency_get();
pool->thr = NULL;
im_semaphore_init( &pool->finish, 0, "finish" );
im_semaphore_init( &pool->tick, 0, "tick" );
vips_semaphore_init( &pool->finish, 0, "finish" );
vips_semaphore_init( &pool->tick, 0, "tick" );
pool->stop = FALSE;
pool->error = FALSE;
@ -852,7 +852,7 @@ vips_threadpool_run( VipsImage *im,
#ifdef HAVE_THREADS
/* Wait for a tick from a worker.
*/
im_semaphore_down( &pool->tick );
vips_semaphore_down( &pool->tick );
#else
/* No threads, do the work ourselves in the main thread.
*/
@ -874,7 +874,7 @@ vips_threadpool_run( VipsImage *im,
/* Wait for them all to hit finish.
*/
im_semaphore_downn( &pool->finish, pool->nthr );
vips_semaphore_downn( &pool->finish, pool->nthr );
/* Return 0 for success.
*/

View File

@ -15,6 +15,8 @@
* 14/2/11
* - renamed to vips.c from im_open_vips.c, some stuff chopped out for
* image.c ... this file now just does read / write to disc
* 28/3/11
* - moved to vips_ namespace
*/
/*
@ -122,15 +124,15 @@
*/
#define NAMESPACE "http://www.vips.ecs.soton.ac.uk/vips"
/* Sort of open for read for image files. Shared with im_binfile().
/* Open for read for image files.
*/
int
vips__open_image_read( const char *filename )
{
int fd;
/* Try to open read-write, so that calls to im_makerw() will work.
* When we later mmap this file, we set read-only, so there
/* Try to open read-write, so that calls to vips_image_inplace() will
* work. When we later mmap this file, we set read-only, so there
* is little danger of scrubbing over files we own.
*/
if( (fd = open( filename, MODE_READWRITE )) == -1 ) {
@ -150,8 +152,8 @@ vips__open_image_read( const char *filename )
* it's sometimes only 32 bits (eg. on many windows build environments) and we
* want to always be 64 bit.
*/
gint64
im__image_pixel_length( VipsImage *image )
static gint64
image_pixel_length( VipsImage *image )
{
gint64 psize;
@ -173,7 +175,7 @@ im__image_pixel_length( VipsImage *image )
/* Read short/int/float LSB and MSB first.
*/
void
im__read_4byte( int msb_first, unsigned char *to, unsigned char **from )
vips__read_4byte( int msb_first, unsigned char *to, unsigned char **from )
{
unsigned char *p = *from;
int out;
@ -188,7 +190,7 @@ im__read_4byte( int msb_first, unsigned char *to, unsigned char **from )
}
void
im__read_2byte( int msb_first, unsigned char *to, unsigned char **from )
vips__read_2byte( int msb_first, unsigned char *to, unsigned char **from )
{
int out;
unsigned char *p = *from;
@ -205,14 +207,14 @@ im__read_2byte( int msb_first, unsigned char *to, unsigned char **from )
/* We always write in native byte order.
*/
void
im__write_4byte( unsigned char **to, unsigned char *from )
vips__write_4byte( unsigned char **to, unsigned char *from )
{
*((guint32 *) *to) = *((guint32 *) from);
*to += 4;
}
void
im__write_2byte( unsigned char **to, unsigned char *from )
vips__write_2byte( unsigned char **to, unsigned char *from )
{
*((guint16 *) *to) = *((guint16 *) from);
*to += 2;
@ -227,43 +229,43 @@ typedef struct _FieldIO {
} FieldIO;
static FieldIO fields[] = {
{ G_STRUCT_OFFSET( IMAGE, Xsize ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Ysize ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Bands ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Bbits ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, BandFmt ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Coding ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Type ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Xres ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Yres ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Length ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Compression ),
im__read_2byte, im__write_2byte },
{ G_STRUCT_OFFSET( IMAGE, Level ),
im__read_2byte, im__write_2byte },
{ G_STRUCT_OFFSET( IMAGE, Xoffset ),
im__read_4byte, im__write_4byte },
{ G_STRUCT_OFFSET( IMAGE, Yoffset ),
im__read_4byte, im__write_4byte }
{ G_STRUCT_OFFSET( VipsImage, Xsize ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Ysize ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Bands ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Bbits ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, BandFmt ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Coding ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Type ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Xres ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Yres ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Length ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Compression ),
vips__read_2byte, vips__write_2byte },
{ G_STRUCT_OFFSET( VipsImage, Level ),
vips__read_2byte, vips__write_2byte },
{ G_STRUCT_OFFSET( VipsImage, Xoffset ),
vips__read_4byte, vips__write_4byte },
{ G_STRUCT_OFFSET( VipsImage, Yoffset ),
vips__read_4byte, vips__write_4byte }
};
int
im__read_header_bytes( IMAGE *im, unsigned char *from )
vips__read_header_bytes( VipsImage *im, unsigned char *from )
{
int msb_first;
int i;
im__read_4byte( 1, (unsigned char *) &im->magic, &from );
vips__read_4byte( 1, (unsigned char *) &im->magic, &from );
if( im->magic != VIPS_MAGIC_INTEL &&
im->magic != VIPS_MAGIC_SPARC ) {
vips_error( "VipsImage", _( "\"%s\" is not a VIPS image" ),
@ -285,7 +287,7 @@ im__read_header_bytes( IMAGE *im, unsigned char *from )
}
int
im__write_header_bytes( IMAGE *im, unsigned char *to )
vips__write_header_bytes( VipsImage *im, unsigned char *to )
{
guint32 magic;
int i;
@ -337,11 +339,11 @@ read_chunk( int fd, gint64 offset, size_t length )
/* Does it look like an image has an extension block?
*/
int
im__has_extension_block( IMAGE *im )
vips__has_extension_block( VipsImage *im )
{
gint64 psize;
psize = im__image_pixel_length( im );
psize = image_pixel_length( im );
g_assert( im->file_length > 0 );
return( im->file_length - psize > 0 );
@ -350,12 +352,12 @@ im__has_extension_block( IMAGE *im )
/* Read everything after the pixels into memory.
*/
void *
im__read_extension_block( IMAGE *im, int *size )
vips__read_extension_block( VipsImage *im, int *size )
{
gint64 psize;
void *buf;
psize = im__image_pixel_length( im );
psize = image_pixel_length( im );
g_assert( im->file_length > 0 );
if( im->file_length - psize > 10 * 1024 * 1024 ) {
vips_error( "VipsImage",
@ -371,7 +373,7 @@ im__read_extension_block( IMAGE *im, int *size )
*size = im->file_length - psize;
#ifdef DEBUG
printf( "im__read_extension_block: read %d bytes from %s\n",
printf( "vips__read_extension_block: read %d bytes from %s\n",
(int) (im->file_length - psize), im->filename );
printf( "data: \"%s\"\n", (char *) buf );
#endif /*DEBUG*/
@ -389,14 +391,14 @@ im__read_extension_block( IMAGE *im, int *size )
*/
static xmlDoc *
read_xml( IMAGE *im )
read_xml( VipsImage *im )
{
void *buf;
int size;
xmlDoc *doc;
xmlNode *node;
if( !(buf = im__read_extension_block( im, &size )) )
if( !(buf = vips__read_extension_block( im, &size )) )
return( NULL );
if( !(doc = xmlParseMemory( buf, size )) ) {
vips_free( buf );
@ -452,7 +454,7 @@ get_sprop( xmlNode *xnode, const char *name, char *buf, int sz )
/* Chop history into lines, add each one as a refstring.
*/
static void
set_history( IMAGE *im, char *history )
set_history( VipsImage *im, char *history )
{
GSList *history_list;
char *p, *q;
@ -481,7 +483,7 @@ set_history( IMAGE *im, char *history )
/* Load header fields.
*/
static int
rebuild_header_builtin( IMAGE *im, xmlNode *i )
rebuild_header_builtin( VipsImage *im, xmlNode *i )
{
char name[256];
@ -504,7 +506,7 @@ rebuild_header_builtin( IMAGE *im, xmlNode *i )
/* Load meta fields.
*/
static int
rebuild_header_meta( IMAGE *im, xmlNode *i )
rebuild_header_meta( VipsImage *im, xmlNode *i )
{
char name[256];
char type[256];
@ -549,7 +551,7 @@ rebuild_header_meta( IMAGE *im, xmlNode *i )
}
static xmlDoc *
get_xml( IMAGE *im )
get_xml( VipsImage *im )
{
if( vips_image_get_typeof( im, VIPS_META_XML ) ) {
xmlDoc *doc;
@ -566,7 +568,7 @@ get_xml( IMAGE *im )
/* Rebuild header fields that depend on stuff saved in xml.
*/
static int
rebuild_header( IMAGE *im )
rebuild_header( VipsImage *im )
{
xmlDoc *doc;
@ -601,14 +603,14 @@ rebuild_header( IMAGE *im )
* and read it in.
*/
static int
im__readhist( IMAGE *im )
readhist( VipsImage *im )
{
/* Junk any old xml meta.
*/
if( vips_image_get_typeof( im, VIPS_META_XML ) )
vips_image_set_area( im, VIPS_META_XML, NULL, NULL );
if( im__has_extension_block( im ) ) {
if( vips__has_extension_block( im ) ) {
xmlDoc *doc;
if( !(doc = read_xml( im )) )
@ -702,7 +704,7 @@ save_fields_meta( VipsMeta *meta, xmlNode *node )
}
static int
save_fields( IMAGE *im, xmlNode *node )
save_fields( VipsImage *im, xmlNode *node )
{
xmlNode *this;
@ -726,12 +728,12 @@ save_fields( IMAGE *im, xmlNode *node )
}
int
im__write_extension_block( IMAGE *im, void *buf, int size )
vips__write_extension_block( VipsImage *im, void *buf, int size )
{
gint64 length;
gint64 psize;
psize = im__image_pixel_length( im );
psize = image_pixel_length( im );
if( (length = im_file_length( im->fd )) == -1 )
return( -1 );
if( length - psize < 0 ) {
@ -746,7 +748,7 @@ im__write_extension_block( IMAGE *im, void *buf, int size )
return( -1 );
#ifdef DEBUG
printf( "im__write_extension_block: written %d bytes of XML to %s\n",
printf( "vips__write_extension_block: written %d bytes of XML to %s\n",
size, im->filename );
#endif /*DEBUG*/
@ -829,7 +831,7 @@ prettify_tree( xmlDoc *xdoc )
/* Append XML to output fd.
*/
int
im__writehist( IMAGE *im )
vips__writehist( VipsImage *im )
{
xmlDoc *doc;
char namespace[256];
@ -863,7 +865,7 @@ im__writehist( IMAGE *im )
return( -1 );
}
if( im__write_extension_block( im, dump, dump_size ) ) {
if( vips__write_extension_block( im, dump, dump_size ) ) {
xmlFreeDoc( doc );
xmlFree( dump );
return( -1 );
@ -915,7 +917,7 @@ vips_image_open_input( VipsImage *image )
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__read_header_bytes( image, header ) ) {
vips_error_system( errno, "VipsImage",
_( "unable to read header for \"%s\"" ),
image->filename );
@ -924,7 +926,7 @@ vips_image_open_input( VipsImage *image )
/* Predict and check the file size.
*/
psize = im__image_pixel_length( image );
psize = image_pixel_length( image );
if( (rsize = im_file_length( image->fd )) == -1 )
return( -1 );
image->file_length = rsize;
@ -941,7 +943,7 @@ vips_image_open_input( VipsImage *image )
* fails (due to eg. corrupted XML) because it's probably mostly
* harmless.
*/
if( im__readhist( image ) ) {
if( readhist( image ) ) {
vips_warn( "VipsImage", _( "error reading XML: %s" ),
vips_error_buffer() );
vips_error_clear();
@ -967,7 +969,7 @@ vips_image_open_output( VipsImage *image )
return( -1 );
}
if( im__write_header_bytes( image, header ) ||
if( vips__write_header_bytes( image, header ) ||
im__write( image->fd, header, IM_SIZEOF_HEADER ) )
return( -1 );
}