half-way though moving REGION

init / dest / type need to be done
This commit is contained in:
John Cupitt 2011-03-02 21:53:32 +00:00
parent 6b9ddf6f54
commit 3d55a7876c
9 changed files with 171 additions and 142 deletions

View File

@ -38,11 +38,11 @@ extern "C" {
/* IMAGE functions which use regions. /* IMAGE functions which use regions.
*/ */
int im_prepare( REGION *reg, Rect *r ); int im_prepare( VipsRegion *reg, Rect *r );
int im_prepare_to( REGION *reg, REGION *dest, Rect *r, int x, int y ); int im_prepare_to( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y );
typedef void *(*im_start_fn)( IMAGE *out, void *a, void *b ); typedef void *(*im_start_fn)( IMAGE *out, void *a, void *b );
typedef int (*im_generate_fn)( REGION *out, void *seq, void *a, void *b ); typedef int (*im_generate_fn)( VipsRegion *out, void *seq, void *a, void *b );
typedef int (*im_stop_fn)( void *seq, void *a, void *b ); typedef int (*im_stop_fn)( void *seq, void *a, void *b );
void *im_start_one( IMAGE *out, void *a, void *b ); void *im_start_one( IMAGE *out, void *a, void *b );

View File

@ -2,6 +2,8 @@
* *
* 7/7/09 * 7/7/09
* - from vips.h * - from vips.h
* 2/3/11
* - move to GObject
*/ */
/* /*

View File

@ -61,7 +61,7 @@ typedef struct _VipsInterpolate {
* interpolate the value at position (x, y) in "in". * interpolate the value at position (x, y) in "in".
*/ */
typedef void (*VipsInterpolateMethod)( VipsInterpolate *interpolate, typedef void (*VipsInterpolateMethod)( VipsInterpolate *interpolate,
PEL *out, REGION *in, double x, double y ); PEL *out, VipsRegion *in, double x, double y );
typedef struct _VipsInterpolateClass { typedef struct _VipsInterpolateClass {
VipsObjectClass parent_class; VipsObjectClass parent_class;
@ -88,7 +88,7 @@ typedef struct _VipsInterpolateClass {
GType vips_interpolate_get_type( void ); GType vips_interpolate_get_type( void );
void vips_interpolate( VipsInterpolate *interpolate, void vips_interpolate( VipsInterpolate *interpolate,
PEL *out, REGION *in, double x, double y ); PEL *out, VipsRegion *in, double x, double y );
VipsInterpolateMethod vips_interpolate_get_method( VipsInterpolate *interpolate ); VipsInterpolateMethod vips_interpolate_get_method( VipsInterpolate *interpolate );
int vips_interpolate_get_window_size( VipsInterpolate *interpolate ); int vips_interpolate_get_window_size( VipsInterpolate *interpolate );
int vips_interpolate_get_window_offset( VipsInterpolate *interpolate ); int vips_interpolate_get_window_offset( VipsInterpolate *interpolate );

View File

@ -125,11 +125,11 @@ void im_buffer_print( im_buffer_t *buffer );
/* Region types. /* Region types.
*/ */
typedef enum region_type { typedef enum region_type {
IM_REGION_NONE, VIPS_REGION_NONE,
IM_REGION_BUFFER, /* a pixel buffer */ VIPS_REGION_BUFFER, /* a pixel buffer */
IM_REGION_OTHER_REGION, /* memory on another region */ VIPS_REGION_OTHER_REGION, /* memory on another region */
IM_REGION_OTHER_IMAGE, /* memory on another image */ VIPS_REGION_OTHER_IMAGE,/* memory on another image */
IM_REGION_WINDOW /* mmap() buffer on fd on another image */ VIPS_REGION_WINDOW /* mmap() buffer on fd on another image */
} RegionType; } RegionType;
/* Private to iofuncs: the size of the `tiles' requested by im_generate() /* Private to iofuncs: the size of the `tiles' requested by im_generate()
@ -145,22 +145,22 @@ typedef enum region_type {
/* Functions on regions. /* Functions on regions.
*/ */
struct _REGION; struct _VipsRegion;
void im__region_take_ownership( struct _REGION *reg ); void im__region_take_ownership( struct _VipsRegion *reg );
void im__region_check_ownership( struct _REGION *reg ); void im__region_check_ownership( struct _VipsRegion *reg );
void im__region_no_ownership( struct _REGION *reg ); void im__region_no_ownership( struct _VipsRegion *reg );
void im__copy_region( struct _REGION *reg, struct _REGION *dest, Rect *r, int x, int y ); void im__copy_region( struct _VipsRegion *reg, struct _VipsRegion *dest, Rect *r, int x, int y );
void im__find_demand_size( struct _VipsImage *im, int *pw, int *ph ); void im__find_demand_size( struct _VipsImage *im, int *pw, int *ph );
int im__call_start( struct _REGION *reg ); int im__call_start( struct _VipsRegion *reg );
void im__call_stop( struct _REGION *reg ); void im__call_stop( struct _VipsRegion *reg );
typedef int (*im_region_fill_fn)( struct _REGION *, void * ); typedef int (*im_region_fill_fn)( struct _VipsRegion *, void * );
int im_region_fill( struct _REGION *reg, Rect *r, im_region_fill_fn fn, void *a ); int im_region_fill( struct _VipsRegion *reg, Rect *r, im_region_fill_fn fn, void *a );
void im_region_print( struct _REGION *region ); void im_region_print( struct _VipsRegion *region );
int im_prepare_many( struct _REGION **reg, Rect *r ); int im_prepare_many( struct _VipsRegion **reg, Rect *r );
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,6 +1,9 @@
/* Definitions for partial image regions. /* Definitions for partial image regions.
* *
* J.Cupitt, 8/4/93 * J.Cupitt, 8/4/93
*
* 2/3/11
* - move to GObject
*/ */
/* /*
@ -36,9 +39,26 @@
extern "C" { extern "C" {
#endif /*__cplusplus*/ #endif /*__cplusplus*/
#define VIPS_TYPE_REGION (vips_region_get_type())
#define VIPS_REGION( obj ) \
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
VIPS_TYPE_REGION, VipsRegion ))
#define VIPS_REGION_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_CAST( (klass), \
VIPS_TYPE_REGION, VipsRegionClass))
#define VIPS_IS_REGION( obj ) \
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_REGION ))
#define VIPS_IS_REGION_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_REGION ))
#define VIPS_REGION_GET_CLASS( obj ) \
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
VIPS_TYPE_REGION, VipsRegionClass ))
/* Sub-area of image. /* Sub-area of image.
*/ */
typedef struct _REGION { typedef struct _VipsRegion {
VipsObject parent_object;
/*< public >*/ /*< public >*/
/* Users may read these two fields. /* Users may read these two fields.
*/ */
@ -70,43 +90,49 @@ typedef struct _REGION {
* dropped. * dropped.
*/ */
gboolean invalid; gboolean invalid;
} REGION; } VipsRegion;
REGION *im_region_create( IMAGE *im ); typedef struct _VipsRegionClass {
void im_region_free( REGION *reg ); VipsObjectClass parent_class;
int im_region_buffer( REGION *reg, Rect *r ); } VipsRegionClass;
int im_region_image( REGION *reg, Rect *r );
int im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y );
int im_region_equalsregion( REGION *reg1, REGION *reg2 );
int im_region_position( REGION *reg, int x, int y );
void im_region_paint( REGION *reg, Rect *r, int value ); VipsRegion *vips_region_new( VipsImage *im );
void im_region_black( REGION *reg );
void im_region_copy( REGION *reg, REGION *dest, Rect *r, int x, int y ); int vips_region_buffer( VipsRegion *reg, Rect *r );
int vips_region_image( VipsRegion *reg, Rect *r );
int vips_region_region( VipsRegion *reg, VipsRegion *dest,
Rect *r, int x, int y );
int vips_region_equalsregion( VipsRegion *reg1, VipsRegion *reg2 );
int vips_region_position( VipsRegion *reg, int x, int y );
void vips_region_paint( VipsRegion *reg, Rect *r, int value );
void vips_region_black( VipsRegion *reg );
void vips_region_copy( VipsRegion *reg, VipsRegion *dest,
Rect *r, int x, int y );
/* Macros on REGIONs. /* Macros on REGIONs.
* IM_REGION_LSKIP() add to move down line * VIPS_REGION_LSKIP() add to move down line
* IM_REGION_N_ELEMENTS() number of elements across region * VIPS_REGION_N_ELEMENTS() number of elements across region
* IM_REGION_SIZEOF_LINE() sizeof width of region * VIPS_REGION_SIZEOF_LINE() sizeof width of region
* IM_REGION_ADDR() address of pixel in region * VIPS_REGION_ADDR() address of pixel in region
*/ */
#define IM_REGION_LSKIP(R) \ #define VIPS_REGION_LSKIP( R ) \
((size_t)((R)->bpl)) ((size_t)((R)->bpl))
#define IM_REGION_N_ELEMENTS(R) \ #define VIPS_REGION_N_ELEMENTS( R ) \
((size_t)((R)->valid.width * (R)->im->Bands)) ((size_t)((R)->valid.width * (R)->im->Bands))
#define IM_REGION_SIZEOF_LINE(R) \ #define VIPS_REGION_SIZEOF_LINE( R ) \
((size_t)((R)->valid.width * VIPS_IMAGE_SIZEOF_PEL((R)->im))) ((size_t)((R)->valid.width * VIPS_IMAGE_SIZEOF_PEL( (R)->im) ))
/* If DEBUG is defined, add bounds checking. /* If DEBUG is defined, add bounds checking.
*/ */
#ifdef DEBUG #ifdef DEBUG
#define IM_REGION_ADDR(R,X,Y) \ #define VIPS_REGION_ADDR( R, X, Y ) \
( (im_rect_includespoint( &(R)->valid, (X), (Y) ))? \ ( (im_rect_includespoint( &(R)->valid, (X), (Y) ))? \
((R)->data + ((Y) - (R)->valid.top) * IM_REGION_LSKIP(R) + \ ((R)->data + ((Y) - (R)->valid.top) * VIPS_REGION_LSKIP(R) + \
((X) - (R)->valid.left) * VIPS_IMAGE_SIZEOF_PEL((R)->im)): \ ((X) - (R)->valid.left) * VIPS_IMAGE_SIZEOF_PEL((R)->im)): \
(fprintf( stderr, \ (fprintf( stderr, \
"IM_REGION_ADDR: point out of bounds, " \ "VIPS_REGION_ADDR: point out of bounds, " \
"file \"%s\", line %d\n" \ "file \"%s\", line %d\n" \
"(point x=%d, y=%d\n" \ "(point x=%d, y=%d\n" \
" should have been within Rect left=%d, top=%d, " \ " should have been within Rect left=%d, top=%d, " \
@ -119,13 +145,13 @@ void im_region_copy( REGION *reg, REGION *dest, Rect *r, int x, int y );
(R)->valid.height ), abort(), (char *) NULL) \ (R)->valid.height ), abort(), (char *) NULL) \
) )
#else /*DEBUG*/ #else /*DEBUG*/
#define IM_REGION_ADDR(R,X,Y) \ #define VIPS_REGION_ADDR( R, X, Y ) \
((R)->data + \ ((R)->data + \
((Y)-(R)->valid.top) * IM_REGION_LSKIP(R) + \ ((Y)-(R)->valid.top) * VIPS_REGION_LSKIP( R ) + \
((X)-(R)->valid.left) * VIPS_IMAGE_SIZEOF_PEL((R)->im)) ((X)-(R)->valid.left) * VIPS_IMAGE_SIZEOF_PEL( (R)->im ))
#endif /*DEBUG*/ #endif /*DEBUG*/
#define IM_REGION_ADDR_TOPLEFT(R) ( (R)->data ) #define VIPS_REGION_ADDR_TOPLEFT( R ) ((R)->data)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -72,7 +72,7 @@ typedef struct _VipsThreadState {
/* This region is created and destroyed by the threadpool for the /* This region is created and destroyed by the threadpool for the
* use of the worker. * use of the worker.
*/ */
REGION *reg; VipsRegion *reg;
/* Neither used nor set, do what you like with them. /* Neither used nor set, do what you like with them.
*/ */
@ -126,11 +126,11 @@ int vips_threadpool_run( VipsImage *im,
void vips_get_tile_size( VipsImage *im, void vips_get_tile_size( VipsImage *im,
int *tile_width, int *tile_height, int *nlines ); int *tile_width, int *tile_height, int *nlines );
typedef int (*VipsRegionWrite)( REGION *region, Rect *area, void *a ); typedef int (*VipsRegionWrite)( VipsRegion *region, Rect *area, void *a );
int vips_sink_disc( VipsImage *im, VipsRegionWrite write_fn, void *a ); int vips_sink_disc( VipsImage *im, VipsRegionWrite write_fn, void *a );
typedef void *(*VipsStart)( VipsImage *out, void *a, void *b ); typedef void *(*VipsStart)( VipsImage *out, void *a, void *b );
typedef int (*VipsGenerate)( REGION *out, void *seq, void *a, void *b ); typedef int (*VipsGenerate)( VipsRegion *out, void *seq, void *a, void *b );
typedef int (*VipsStop)( void *seq, void *a, void *b ); typedef int (*VipsStop)( void *seq, void *a, void *b );
int vips_sink( VipsImage *im, int vips_sink( VipsImage *im,
VipsStart start, VipsGenerate generate, VipsStop stop, VipsStart start, VipsGenerate generate, VipsStop stop,

View File

@ -139,16 +139,16 @@ im_header_int( IMAGE *im, const char *field, int *out )
{ {
int i; int i;
for( i = 0; i < IM_NUMBER( int_field ); i++ ) for( i = 0; i < VIPS_NUMBER( int_field ); i++ )
if( strcmp( field, int_field[i].field ) == 0 ) { if( strcmp( field, int_field[i].field ) == 0 ) {
*out = G_STRUCT_MEMBER( int, im, *out = G_STRUCT_MEMBER( int, im,
int_field[i].offset ); int_field[i].offset );
break; break;
} }
if( i == IM_NUMBER( int_field ) && if( i == VIPS_NUMBER( int_field ) &&
im_meta_get_int( im, field, out ) ) { im_meta_get_int( im, field, out ) ) {
im_error( "im_header_int", vips_error( "im_header_int",
_( "no such int field \"%s\"" ), field ); _( "no such int field \"%s\"" ), field );
return( -1 ); return( -1 );
} }
@ -175,16 +175,16 @@ im_header_double( IMAGE *im, const char *field, double *out )
{ {
int i; int i;
for( i = 0; i < IM_NUMBER( double_field ); i++ ) for( i = 0; i < VIPS_NUMBER( double_field ); i++ )
if( strcmp( field, double_field[i].field ) == 0 ) { if( strcmp( field, double_field[i].field ) == 0 ) {
*out = G_STRUCT_MEMBER( float, im, *out = G_STRUCT_MEMBER( float, im,
double_field[i].offset ); double_field[i].offset );
break; break;
} }
if( i == IM_NUMBER( double_field ) && if( i == VIPS_NUMBER( double_field ) &&
im_meta_get_double( im, field, out ) ) { im_meta_get_double( im, field, out ) ) {
im_error( "im_header_double", vips_error( "im_header_double",
_( "no such double field \"%s\"" ), field ); _( "no such double field \"%s\"" ), field );
return( -1 ); return( -1 );
} }
@ -211,16 +211,16 @@ im_header_string( IMAGE *im, const char *field, char **out )
{ {
int i; int i;
for( i = 0; i < IM_NUMBER( string_field ); i++ ) for( i = 0; i < VIPS_NUMBER( string_field ); i++ )
if( strcmp( field, string_field[i].field ) == 0 ) { if( strcmp( field, string_field[i].field ) == 0 ) {
*out = G_STRUCT_MEMBER( char *, im, *out = G_STRUCT_MEMBER( char *, im,
string_field[i].offset ); string_field[i].offset );
break; break;
} }
if( i == IM_NUMBER( string_field ) && if( i == VIPS_NUMBER( string_field ) &&
im_meta_get_string( im, field, out ) ) { im_meta_get_string( im, field, out ) ) {
im_error( "im_header_string", vips_error( "im_header_string",
_( "no such string field \"%s\"" ), field ); _( "no such string field \"%s\"" ), field );
return( -1 ); return( -1 );
} }
@ -291,13 +291,13 @@ im_header_get_typeof( IMAGE *im, const char *field )
int i; int i;
GType type; GType type;
for( i = 0; i < IM_NUMBER( int_field ); i++ ) for( i = 0; i < VIPS_NUMBER( int_field ); i++ )
if( strcmp( field, int_field[i].field ) == 0 ) if( strcmp( field, int_field[i].field ) == 0 )
return( G_TYPE_INT ); return( G_TYPE_INT );
for( i = 0; i < IM_NUMBER( double_field ); i++ ) for( i = 0; i < VIPS_NUMBER( double_field ); i++ )
if( strcmp( field, double_field[i].field ) == 0 ) if( strcmp( field, double_field[i].field ) == 0 )
return( G_TYPE_DOUBLE ); return( G_TYPE_DOUBLE );
for( i = 0; i < IM_NUMBER( string_field ); i++ ) for( i = 0; i < VIPS_NUMBER( string_field ); i++ )
if( strcmp( field, string_field[i].field ) == 0 ) if( strcmp( field, string_field[i].field ) == 0 )
return( G_TYPE_STRING ); return( G_TYPE_STRING );
if( (type = im_meta_get_typeof( im, field )) ) if( (type = im_meta_get_typeof( im, field )) )
@ -335,7 +335,7 @@ im_header_get_typeof( IMAGE *im, const char *field )
* return( -1 ); * return( -1 );
* *
* if( G_VALUE_TYPE( &value ) != G_TYPE_DOUBLE ) { * if( G_VALUE_TYPE( &value ) != G_TYPE_DOUBLE ) {
* im_error( "mydomain", _( "field \"%s\" is of type %s, not double" ), * vips_error( "mydomain", _( "field \"%s\" is of type %s, not double" ),
* field, g_type_name( G_VALUE_TYPE( &value ) ) ); * field, g_type_name( G_VALUE_TYPE( &value ) ) );
* g_value_unset( &value ); * g_value_unset( &value );
* return( -1 ); * return( -1 );
@ -356,7 +356,7 @@ im_header_get( IMAGE *im, const char *field, GValue *value_copy )
{ {
int i; int i;
for( i = 0; i < IM_NUMBER( int_field ); i++ ) for( i = 0; i < VIPS_NUMBER( int_field ); i++ )
if( strcmp( field, int_field[i].field ) == 0 ) { if( strcmp( field, int_field[i].field ) == 0 ) {
g_value_init( value_copy, G_TYPE_INT ); g_value_init( value_copy, G_TYPE_INT );
g_value_set_int( value_copy, g_value_set_int( value_copy,
@ -365,7 +365,7 @@ im_header_get( IMAGE *im, const char *field, GValue *value_copy )
return( 0 ); return( 0 );
} }
for( i = 0; i < IM_NUMBER( double_field ); i++ ) for( i = 0; i < VIPS_NUMBER( double_field ); i++ )
if( strcmp( field, double_field[i].field ) == 0 ) { if( strcmp( field, double_field[i].field ) == 0 ) {
g_value_init( value_copy, G_TYPE_DOUBLE ); g_value_init( value_copy, G_TYPE_DOUBLE );
g_value_set_double( value_copy, g_value_set_double( value_copy,
@ -374,7 +374,7 @@ im_header_get( IMAGE *im, const char *field, GValue *value_copy )
return( 0 ); return( 0 );
} }
for( i = 0; i < IM_NUMBER( string_field ); i++ ) for( i = 0; i < VIPS_NUMBER( string_field ); i++ )
if( strcmp( field, string_field[i].field ) == 0 ) { if( strcmp( field, string_field[i].field ) == 0 ) {
g_value_init( value_copy, G_TYPE_STRING ); g_value_init( value_copy, G_TYPE_STRING );
g_value_set_static_string( value_copy, g_value_set_static_string( value_copy,
@ -418,7 +418,7 @@ im_header_map( IMAGE *im, im_header_map_fn fn, void *a )
GValue value = { 0 }; GValue value = { 0 };
void *result; void *result;
for( i = 0; i < IM_NUMBER( int_field ); i++ ) { for( i = 0; i < VIPS_NUMBER( int_field ); i++ ) {
im_header_get( im, int_field[i].field, &value ); im_header_get( im, int_field[i].field, &value );
result = fn( im, int_field[i].field, &value, a ); result = fn( im, int_field[i].field, &value, a );
g_value_unset( &value ); g_value_unset( &value );
@ -427,7 +427,7 @@ im_header_map( IMAGE *im, im_header_map_fn fn, void *a )
return( result ); return( result );
} }
for( i = 0; i < IM_NUMBER( double_field ); i++ ) { for( i = 0; i < VIPS_NUMBER( double_field ); i++ ) {
im_header_get( im, double_field[i].field, &value ); im_header_get( im, double_field[i].field, &value );
result = fn( im, double_field[i].field, &value, a ); result = fn( im, double_field[i].field, &value, a );
g_value_unset( &value ); g_value_unset( &value );
@ -436,7 +436,7 @@ im_header_map( IMAGE *im, im_header_map_fn fn, void *a )
return( result ); return( result );
} }
for( i = 0; i < IM_NUMBER( string_field ); i++ ) { for( i = 0; i < VIPS_NUMBER( string_field ); i++ ) {
im_header_get( im, string_field[i].field, &value ); im_header_get( im, string_field[i].field, &value );
result = fn( im, string_field[i].field, &value, a ); result = fn( im, string_field[i].field, &value, a );
g_value_unset( &value ); g_value_unset( &value );

View File

@ -94,7 +94,8 @@ vips_image_write_line( VipsImage *image, int ypos, PEL *linebuffer )
switch( image->dtype ) { switch( image->dtype ) {
case VIPS_IMAGE_SETBUF: case VIPS_IMAGE_SETBUF:
case VIPS_IMAGE_SETBUF_FOREIGN: case VIPS_IMAGE_SETBUF_FOREIGN:
memcpy( IM_IMAGE_ADDR( image, 0, ypos ), linebuffer, linesize ); memcpy( VIPS_IMAGE_ADDR( image, 0, ypos ),
linebuffer, linesize );
break; break;
case VIPS_IMAGE_OPENOUT: case VIPS_IMAGE_OPENOUT:

View File

@ -111,7 +111,7 @@
* <link linkend="libvips-generate">generate</link> * <link linkend="libvips-generate">generate</link>
* @include: vips/vips.h * @include: vips/vips.h
* *
* A #REGION is a small part of an image and some pixels. You use regions to * A #VipsRegion is a small part of an image and some pixels. You use regions to
* read pixels out of images without having to have the whole image in memory * read pixels out of images without having to have the whole image in memory
* at once. * at once.
* *
@ -129,40 +129,40 @@
*/ */
/** /**
* REGION: * VipsRegion:
* @im: the #IMAGE that this region is defined on * @im: the #IMAGE that this region is defined on
* @valid: the #Rect of pixels that this region represents * @valid: the #Rect of pixels that this region represents
* *
* A small part of an #IMAGE. @valid holds the left/top/width/height of the * A small part of an #IMAGE. @valid holds the left/top/width/height of the
* area of pixels that are available from the region. * area of pixels that are available from the region.
* *
* See also: IM_REGION_ADDR(), im_region_create(), im_prepare(). * See also: VIPS_REGION_ADDR(), im_region_create(), im_prepare().
*/ */
/** /**
* IM_REGION_LSKIP: * VIPS_REGION_LSKIP:
* @R: a #REGION * @R: a #VipsRegion
* *
* Returns: The number of bytes to add to move down a scanline. * Returns: The number of bytes to add to move down a scanline.
*/ */
/** /**
* IM_REGION_N_ELEMENTS: * VIPS_REGION_N_ELEMENTS:
* @R: a #REGION * @R: a #VipsRegion
* *
* Returns: The number of band elements across a region. * Returns: The number of band elements across a region.
*/ */
/** /**
* IM_REGION_SIZEOF_LINE: * VIPS_REGION_SIZEOF_LINE:
* @R: a #REGION * @R: a #VipsRegion
* *
* Returns: The number of bytes across a region. * Returns: The number of bytes across a region.
*/ */
/** /**
* IM_REGION_ADDR: * VIPS_REGION_ADDR:
* @R: a #REGION * @R: a #VipsRegion
* @X: x coordinate * @X: x coordinate
* @Y: y coordinate * @Y: y coordinate
* *
@ -175,10 +175,10 @@
*/ */
/** /**
* IM_REGION_ADDR_TOPLEFT: * VIPS_REGION_ADDR_TOPLEFT:
* @R: a #REGION * @R: a #VipsRegion
* *
* This macro returns a pointer to the top-left pixel in the #REGION, that is, * This macro returns a pointer to the top-left pixel in the #VipsRegion, that is,
* the pixel at (@R->valid.left, @R->valid.top). * the pixel at (@R->valid.left, @R->valid.top).
* *
* Returns: The address of the top-left pixel in the region. * Returns: The address of the top-left pixel in the region.
@ -190,10 +190,10 @@
static GSList *im__regions_all = NULL; static GSList *im__regions_all = NULL;
#endif /*DEBUG*/ #endif /*DEBUG*/
/* Call a start function if no sequence is running on this REGION. /* Call a start function if no sequence is running on this VipsRegion.
*/ */
int int
im__call_start( REGION *reg ) im__call_start( VipsRegion *reg )
{ {
IMAGE *im = reg->im; IMAGE *im = reg->im;
@ -215,11 +215,11 @@ im__call_start( REGION *reg )
return( 0 ); return( 0 );
} }
/* Call a stop function if a sequence is running in this REGION. No error /* Call a stop function if a sequence is running in this VipsRegion. No error
* return is possible, really. * return is possible, really.
*/ */
void void
im__call_stop( REGION *reg ) im__call_stop( VipsRegion *reg )
{ {
IMAGE *im = reg->im; IMAGE *im = reg->im;
int res; int res;
@ -245,7 +245,7 @@ im__call_stop( REGION *reg )
* im__region_no_ownership() before we can call this. * im__region_no_ownership() before we can call this.
*/ */
void void
im__region_take_ownership( REGION *reg ) im__region_take_ownership( VipsRegion *reg )
{ {
/* Lock so that there's a memory barrier with the thread doing the /* Lock so that there's a memory barrier with the thread doing the
* im__region_no_ownership() before us. * im__region_no_ownership() before us.
@ -269,7 +269,7 @@ im__region_take_ownership( REGION *reg )
} }
void void
im__region_check_ownership( REGION *reg ) im__region_check_ownership( VipsRegion *reg )
{ {
if( reg->thread ) { if( reg->thread ) {
g_assert( reg->thread == g_thread_self() ); g_assert( reg->thread == g_thread_self() );
@ -282,7 +282,7 @@ im__region_check_ownership( REGION *reg )
* this thread's buffer cache. * this thread's buffer cache.
*/ */
void void
im__region_no_ownership( REGION *reg ) im__region_no_ownership( VipsRegion *reg )
{ {
g_mutex_lock( reg->im->sslock ); g_mutex_lock( reg->im->sslock );
@ -299,19 +299,19 @@ im__region_no_ownership( REGION *reg )
* im_region_create: * im_region_create:
* @im: image to create this region on * @im: image to create this region on
* *
* Create a region. #REGION s start out empty, you need to call im_prepare() to * Create a region. #VipsRegion s start out empty, you need to call im_prepare() to
* fill them with pixels. * fill them with pixels.
* *
* See also: im_prepare(), im_region_free(). * See also: im_prepare(), im_region_free().
*/ */
REGION * VipsRegion *
im_region_create( IMAGE *im ) im_region_create( IMAGE *im )
{ {
REGION *reg; VipsRegion *reg;
g_assert( !im_image_sanity( im ) ); g_assert( !im_image_sanity( im ) );
if( !(reg = VIPS_NEW( NULL, REGION )) ) if( !(reg = VIPS_NEW( NULL, VipsRegion )) )
return( NULL ); return( NULL );
reg->im = im; reg->im = im;
@ -319,7 +319,7 @@ im_region_create( IMAGE *im )
reg->valid.top = 0; reg->valid.top = 0;
reg->valid.width = 0; reg->valid.width = 0;
reg->valid.height = 0; reg->valid.height = 0;
reg->type = IM_REGION_NONE; reg->type = VIPS_REGION_NONE;
reg->data = NULL; reg->data = NULL;
reg->bpl = 0; reg->bpl = 0;
reg->seq = NULL; reg->seq = NULL;
@ -349,7 +349,7 @@ im_region_create( IMAGE *im )
/* Free any resources we have. /* Free any resources we have.
*/ */
static void static void
im_region_reset( REGION *reg ) im_region_reset( VipsRegion *reg )
{ {
VIPS_FREEF( im_window_unref, reg->window ); VIPS_FREEF( im_window_unref, reg->window );
VIPS_FREEF( im_buffer_unref, reg->buffer ); VIPS_FREEF( im_buffer_unref, reg->buffer );
@ -358,15 +358,15 @@ im_region_reset( REGION *reg )
/** /**
* im_region_free: * im_region_free:
* @reg: #REGION to free * @reg: #VipsRegion to free
* *
* Free a region and any resources it holds. * Free a region and any resources it holds.
* *
* If @im has previously been closed, then freeing the last #REGION on @in can * If @im has previously been closed, then freeing the last #VipsRegion on @in can
* cause @im to finally be freed as well. * cause @im to finally be freed as well.
*/ */
void void
im_region_free( REGION *reg ) im_region_free( VipsRegion *reg )
{ {
IMAGE *im; IMAGE *im;
@ -430,9 +430,9 @@ im_region_free( REGION *reg )
* Returns: 0 on success, or -1 for error. * Returns: 0 on success, or -1 for error.
*/ */
int int
im_region_buffer( REGION *reg, Rect *r ) im_region_buffer( VipsRegion *reg, Rect *r )
{ {
IMAGE *im = reg->im; VipsImage *im = reg->im;
Rect image; Rect image;
Rect clipped; Rect clipped;
@ -479,8 +479,8 @@ im_region_buffer( REGION *reg, Rect *r )
/* Init new stuff. /* Init new stuff.
*/ */
reg->valid = reg->buffer->area; reg->valid = reg->buffer->area;
reg->bpl = IM_IMAGE_SIZEOF_PEL( im ) * reg->buffer->area.width; reg->bpl = VIPS_IMAGE_SIZEOF_PEL( im ) * reg->buffer->area.width;
reg->type = IM_REGION_BUFFER; reg->type = VIPS_REGION_BUFFER;
reg->data = reg->buffer->buf; reg->data = reg->buffer->buf;
return( 0 ); return( 0 );
@ -498,7 +498,7 @@ im_region_buffer( REGION *reg, Rect *r )
* Returns: 0 on success, or -1 for error. * Returns: 0 on success, or -1 for error.
*/ */
int int
im_region_image( REGION *reg, Rect *r ) im_region_image( VipsRegion *reg, Rect *r )
{ {
Rect image; Rect image;
Rect clipped; Rect clipped;
@ -532,16 +532,16 @@ im_region_image( REGION *reg, Rect *r )
* incompletely calculated memory buffer. Just set valid to r. * incompletely calculated memory buffer. Just set valid to r.
*/ */
reg->valid = clipped; reg->valid = clipped;
reg->bpl = IM_IMAGE_SIZEOF_LINE( reg->im ); reg->bpl = VIPS_IMAGE_SIZEOF_LINE( reg->im );
reg->data = reg->im->data + reg->data = reg->im->data +
(gint64) clipped.top * IM_IMAGE_SIZEOF_LINE( reg->im ) + clipped.top * VIPS_IMAGE_SIZEOF_LINE( reg->im ) +
clipped.left * IM_IMAGE_SIZEOF_PEL( reg->im ); clipped.left * VIPS_IMAGE_SIZEOF_PEL( reg->im );
reg->type = IM_REGION_OTHER_IMAGE; reg->type = VIPS_REGION_OTHER_IMAGE;
} }
else if( reg->im->dtype == IM_OPENIN ) { else if( reg->im->dtype == VIPS_IMAGE_OPENIN ) {
/* No complete image data ... but we can use a rolling window. /* No complete image data ... but we can use a rolling window.
*/ */
if( reg->type != IM_REGION_WINDOW || !reg->window || if( reg->type != VIPS_REGION_WINDOW || !reg->window ||
reg->window->top > clipped.top || reg->window->top > clipped.top ||
reg->window->top + reg->window->height < reg->window->top + reg->window->height <
clipped.top + clipped.height ) { clipped.top + clipped.height ) {
@ -551,7 +551,7 @@ im_region_image( REGION *reg, Rect *r )
clipped.top, clipped.height )) ) clipped.top, clipped.height )) )
return( -1 ); return( -1 );
reg->type = IM_REGION_WINDOW; reg->type = VIPS_REGION_WINDOW;
} }
/* Note the area the window actually represents. /* Note the area the window actually represents.
@ -560,7 +560,7 @@ im_region_image( REGION *reg, Rect *r )
reg->valid.top = reg->window->top; reg->valid.top = reg->window->top;
reg->valid.width = reg->im->Xsize; reg->valid.width = reg->im->Xsize;
reg->valid.height = reg->window->height; reg->valid.height = reg->window->height;
reg->bpl = IM_IMAGE_SIZEOF_LINE( reg->im ); reg->bpl = VIPS_IMAGE_SIZEOF_LINE( reg->im );
reg->data = reg->window->data; reg->data = reg->window->data;
} }
else { else {
@ -580,7 +580,7 @@ im_region_image( REGION *reg, Rect *r )
* @x: postion of @r in @dest * @x: postion of @r in @dest
* @y: postion of @r in @dest * @y: postion of @r in @dest
* *
* Make IM_REGION_ADDR() on @reg go to @dest instead. * Make VIPS_REGION_ADDR() on @reg go to @dest instead.
* *
* @r is the part of @reg which you want to be able to address (this * @r is the part of @reg which you want to be able to address (this
* effectively becomes the valid field), (@x, @y) is the top LH corner of the * effectively becomes the valid field), (@x, @y) is the top LH corner of the
@ -597,7 +597,7 @@ im_region_image( REGION *reg, Rect *r )
* Returns: 0 on success, or -1 for error. * Returns: 0 on success, or -1 for error.
*/ */
int int
im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y ) im_region_region( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y )
{ {
Rect image; Rect image;
Rect wanted; Rect wanted;
@ -608,8 +608,8 @@ im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y )
/* Sanity check. /* Sanity check.
*/ */
if( !dest->data || if( !dest->data ||
IM_IMAGE_SIZEOF_PEL( dest->im ) != VIPS_IMAGE_SIZEOF_PEL( dest->im ) !=
IM_IMAGE_SIZEOF_PEL( reg->im ) ) { VIPS_IMAGE_SIZEOF_PEL( reg->im ) ) {
vips_error( "im_region_region", vips_error( "im_region_region",
"%s", _( "inappropriate region type" ) ); "%s", _( "inappropriate region type" ) );
return( -1 ); return( -1 );
@ -672,8 +672,8 @@ im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y )
im_region_reset( reg ); im_region_reset( reg );
reg->valid = final; reg->valid = final;
reg->bpl = dest->bpl; reg->bpl = dest->bpl;
reg->data = IM_REGION_ADDR( dest, clipped2.left, clipped2.top ); reg->data = VIPS_REGION_ADDR( dest, clipped2.left, clipped2.top );
reg->type = IM_REGION_OTHER_REGION; reg->type = VIPS_REGION_OTHER_REGION;
return( 0 ); return( 0 );
} }
@ -686,15 +686,15 @@ im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y )
* Do two regions point to the same piece of image? ie. * Do two regions point to the same piece of image? ie.
* *
* |[ * |[
* IM_REGION_ADDR( reg1, x, y ) == IM_REGION_ADDR( reg2, x, y ) && * VIPS_REGION_ADDR( reg1, x, y ) == VIPS_REGION_ADDR( reg2, x, y ) &&
* *IM_REGION_ADDR( reg1, x, y ) == * *VIPS_REGION_ADDR( reg1, x, y ) ==
* *IM_REGION_ADDR( reg2, x, y ) for all x, y, reg1, reg2. * *VIPS_REGION_ADDR( reg2, x, y ) for all x, y, reg1, reg2.
* ]| * ]|
* *
* Returns: non-zero on equality. * Returns: non-zero on equality.
*/ */
int int
im_region_equalsregion( REGION *reg1, REGION *reg2 ) im_region_equalsregion( VipsRegion *reg1, VipsRegion *reg2 )
{ {
return( reg1->im == reg2->im && return( reg1->im == reg2->im &&
im_rect_equalsrect( &reg1->valid, &reg2->valid ) && im_rect_equalsrect( &reg1->valid, &reg2->valid ) &&
@ -715,7 +715,7 @@ im_region_equalsregion( REGION *reg1, REGION *reg2 )
* Returns: 0 on success, or -1 for error. * Returns: 0 on success, or -1 for error.
*/ */
int int
im_region_position( REGION *reg, int x, int y ) im_region_position( VipsRegion *reg, int x, int y )
{ {
Rect req, image, clipped; Rect req, image, clipped;
@ -742,9 +742,9 @@ im_region_position( REGION *reg, int x, int y )
} }
int int
im_region_fill( REGION *reg, Rect *r, im_region_fill_fn fn, void *a ) im_region_fill( VipsRegion *reg, Rect *r, im_region_fill_fn fn, void *a )
{ {
g_assert( reg->im->dtype == IM_PARTIAL ); g_assert( reg->im->dtype == VIPS_IMAGE_PARTIAL );
g_assert( reg->im->generate ); g_assert( reg->im->generate );
/* Should have local memory. /* Should have local memory.
@ -774,9 +774,9 @@ im_region_fill( REGION *reg, Rect *r, im_region_fill_fn fn, void *a )
* Print out interesting fields from @reg. Handy for debug. * Print out interesting fields from @reg. Handy for debug.
*/ */
void void
im_region_print( REGION *reg ) im_region_print( VipsRegion *reg )
{ {
printf( "REGION: %p, ", reg ); printf( "VipsRegion: %p, ", reg );
printf( "im = %p, ", reg->im ); printf( "im = %p, ", reg->im );
printf( "valid.left = %d, ", reg->valid.left ); printf( "valid.left = %d, ", reg->valid.left );
printf( "valid.top = %d, ", reg->valid.top ); printf( "valid.top = %d, ", reg->valid.top );
@ -805,15 +805,15 @@ im_region_print( REGION *reg )
* See also: im_region_black(). * See also: im_region_black().
*/ */
void void
im_region_paint( REGION *reg, Rect *r, int value ) im_region_paint( VipsRegion *reg, Rect *r, int value )
{ {
Rect ovl; Rect ovl;
im_rect_intersectrect( r, &reg->valid, &ovl ); im_rect_intersectrect( r, &reg->valid, &ovl );
if( !im_rect_isempty( &ovl ) ) { if( !im_rect_isempty( &ovl ) ) {
PEL *q = (PEL *) IM_REGION_ADDR( reg, ovl.left, ovl.top ); PEL *q = (PEL *) VIPS_REGION_ADDR( reg, ovl.left, ovl.top );
int wd = ovl.width * IM_IMAGE_SIZEOF_PEL( reg->im ); int wd = ovl.width * VIPS_IMAGE_SIZEOF_PEL( reg->im );
int ls = IM_REGION_LSKIP( reg ); int ls = VIPS_REGION_LSKIP( reg );
int y; int y;
for( y = 0; y < ovl.height; y++ ) { for( y = 0; y < ovl.height; y++ ) {
@ -832,7 +832,7 @@ im_region_paint( REGION *reg, Rect *r, int value )
* See also: im_region_paint(). * See also: im_region_paint().
*/ */
void void
im_region_black( REGION *reg ) im_region_black( VipsRegion *reg )
{ {
im_region_paint( reg, &reg->valid, 0 ); im_region_paint( reg, &reg->valid, 0 );
} }
@ -852,14 +852,14 @@ im_region_black( REGION *reg )
* See also: im_region_paint(). * See also: im_region_paint().
*/ */
void void
im_region_copy( REGION *reg, REGION *dest, Rect *r, int x, int y ) im_region_copy( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y )
{ {
int z; int z;
int len = IM_IMAGE_SIZEOF_PEL( reg->im ) * r->width; int len = VIPS_IMAGE_SIZEOF_PEL( reg->im ) * r->width;
char *p = IM_REGION_ADDR( reg, r->left, r->top ); char *p = VIPS_REGION_ADDR( reg, r->left, r->top );
char *q = IM_REGION_ADDR( dest, x, y ); char *q = VIPS_REGION_ADDR( dest, x, y );
int plsk = IM_REGION_LSKIP( reg ); int plsk = VIPS_REGION_LSKIP( reg );
int qlsk = IM_REGION_LSKIP( dest ); int qlsk = VIPS_REGION_LSKIP( dest );
#ifdef DEBUG #ifdef DEBUG
/* Find the area we will write to in dest. /* Find the area we will write to in dest.
@ -883,8 +883,8 @@ im_region_copy( REGION *reg, REGION *dest, Rect *r, int x, int y )
/* PEL size must be the same. /* PEL size must be the same.
*/ */
g_assert( IM_IMAGE_SIZEOF_PEL( reg->im ) == g_assert( VIPS_IMAGE_SIZEOF_PEL( reg->im ) ==
IM_IMAGE_SIZEOF_PEL( dest->im ) ); VIPS_IMAGE_SIZEOF_PEL( dest->im ) );
#endif /*DEBUG*/ #endif /*DEBUG*/
for( z = 0; z < r->height; z++ ) { for( z = 0; z < r->height; z++ ) {