rename Rect as VipsRect

move Rect to the new Vips namespace, add gtkdoc comments, add back
compat stuff
This commit is contained in:
John Cupitt 2011-03-17 13:05:46 +00:00
parent cfe34cacd2
commit ac801dd1fc
21 changed files with 330 additions and 245 deletions

2
TODO
View File

@ -1,3 +1,5 @@
- add FITS and MATLAB write
- rename Rect to VipsRect - rename Rect to VipsRect

View File

@ -28,6 +28,7 @@
<xi:include href="xml/error.xml"/> <xi:include href="xml/error.xml"/>
<xi:include href="xml/memory.xml"/> <xi:include href="xml/memory.xml"/>
<xi:include href="xml/buf.xml"/> <xi:include href="xml/buf.xml"/>
<xi:include href="xml/rect.xml"/>
</chapter> </chapter>
<chapter> <chapter>
@ -58,7 +59,6 @@
<xi:include href="xml/util.xml"/> <xi:include href="xml/util.xml"/>
<xi:include href="xml/version.xml"/> <xi:include href="xml/version.xml"/>
<xi:include href="xml/type.xml"/> <xi:include href="xml/type.xml"/>
<xi:include href="xml/rect.xml"/>
<xi:include href="xml/semaphore.xml"/> <xi:include href="xml/semaphore.xml"/>
<xi:include href="xml/dispatch.xml"/> <xi:include href="xml/dispatch.xml"/>
</chapter> </chapter>

View File

@ -146,10 +146,10 @@ int im_render_fade( IMAGE *in, IMAGE *out, IMAGE *mask,
int width, int height, int max, int width, int height, int max,
int fps, int steps, int fps, int steps,
int priority, int priority,
void (*notify)( IMAGE *, Rect *, void * ), void *client ); void (*notify)( IMAGE *, VipsRect *, void * ), void *client );
int im_render( IMAGE *in, IMAGE *out, IMAGE *mask, int im_render( IMAGE *in, IMAGE *out, IMAGE *mask,
int width, int height, int max, int width, int height, int max,
void (*notify)( IMAGE *, Rect *, void * ), void *client ); void (*notify)( IMAGE *, VipsRect *, void * ), void *client );
int im_cooc_matrix( IMAGE *im, IMAGE *m, int im_cooc_matrix( IMAGE *im, IMAGE *m,
int xp, int yp, int xs, int ys, int dx, int dy, int flag ); int xp, int yp, int xs, int ys, int dx, int dy, int flag );
@ -251,7 +251,7 @@ int im_rank_raw( IMAGE *in, IMAGE *out, int xsize, int ysize, int order );
int im_circle( IMAGE *im, int cx, int cy, int radius, int intensity ); int im_circle( IMAGE *im, int cx, int cy, int radius, int intensity );
int im_line( IMAGE *, int, int, int, int, int ); int im_line( IMAGE *, int, int, int, int, int );
int im_segment( IMAGE *test, IMAGE *mask, int *segments ); int im_segment( IMAGE *test, IMAGE *mask, int *segments );
int im_paintrect( IMAGE *im, Rect *r, PEL *ink ); int im_paintrect( IMAGE *im, VipsRect *r, PEL *ink );
int im_insertplace( IMAGE *main, IMAGE *sub, int x, int y ); int im_insertplace( IMAGE *main, IMAGE *sub, int x, int y );
int im_flood_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ); int im_flood_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink );
@ -259,22 +259,22 @@ int im_flood_blob_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink );
int im_flood_other_copy( IMAGE *test, IMAGE *mark, IMAGE *out, int im_flood_other_copy( IMAGE *test, IMAGE *mark, IMAGE *out,
int x, int y, int serial ); int x, int y, int serial );
int im_flood( IMAGE *im, int x, int y, PEL *ink, Rect *dout ); int im_flood( IMAGE *im, int x, int y, PEL *ink, VipsRect *dout );
int im_flood_blob( IMAGE *im, int x, int y, PEL *ink, Rect *dout ); int im_flood_blob( IMAGE *im, int x, int y, PEL *ink, VipsRect *dout );
int im_flood_other( IMAGE *test, IMAGE *mark, int im_flood_other( IMAGE *test, IMAGE *mark,
int x, int y, int serial, Rect *dout ); int x, int y, int serial, VipsRect *dout );
int im_fastline( IMAGE *im, int x1, int y1, int x2, int y2, PEL *pel ); int im_fastline( IMAGE *im, int x1, int y1, int x2, int y2, PEL *pel );
int im_fastlineuser( IMAGE *im, int im_fastlineuser( IMAGE *im,
int x1, int y1, int x2, int y2, int x1, int y1, int x2, int y2,
int (*fn)(), void *client1, void *client2, void *client3 ); int (*fn)(), void *client1, void *client2, void *client3 );
int im_plotmask( IMAGE *im, int ix, int iy, PEL *ink, PEL *mask, Rect *r ); int im_plotmask( IMAGE *im, int ix, int iy, PEL *ink, PEL *mask, VipsRect *r );
int im_readpoint( IMAGE *im, int x, int y, PEL *pel ); int im_readpoint( IMAGE *im, int x, int y, PEL *pel );
int im_plotpoint( IMAGE *im, int x, int y, PEL *pel ); int im_plotpoint( IMAGE *im, int x, int y, PEL *pel );
int im_smudge( IMAGE *image, int ix, int iy, Rect *r ); int im_smudge( IMAGE *image, int ix, int iy, VipsRect *r );
int im_smear( IMAGE *im, int ix, int iy, Rect *r ); int im_smear( IMAGE *im, int ix, int iy, VipsRect *r );
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -82,7 +82,7 @@ int im_wrapmany( VipsImage **in, VipsImage *out,
int im_render_priority( VipsImage *in, VipsImage *out, VipsImage *mask, int im_render_priority( VipsImage *in, VipsImage *out, VipsImage *mask,
int width, int height, int max, int width, int height, int max,
int priority, int priority,
void (*notify)( VipsImage *, Rect *, void * ), void *client ); void (*notify)( VipsImage *, VipsRect *, void * ), void *client );
int im_cache( VipsImage *in, VipsImage *out, int width, int height, int max ); int im_cache( VipsImage *in, VipsImage *out, int width, int height, int max );
int im_setupout( VipsImage *im ); int im_setupout( VipsImage *im );

View File

@ -324,7 +324,7 @@ extern const size_t vips__image_sizeof_bandformat[];
"VIPS_IMAGE_ADDR: point out of bounds, " \ "VIPS_IMAGE_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 VipsRect left=%d, top=%d, " \
"width=%d, height=%d)\n", \ "width=%d, height=%d)\n", \
__FILE__, __LINE__, \ __FILE__, __LINE__, \
(X), (Y), \ (X), (Y), \

View File

@ -53,10 +53,10 @@ int im_draw_line( VipsImage *image, int x1, int y1, int x2, int y2, PEL *ink );
int im_lineset( VipsImage *in, VipsImage *out, VipsImage *mask, VipsImage *ink, int im_lineset( VipsImage *in, VipsImage *out, VipsImage *mask, VipsImage *ink,
int n, int *x1v, int *y1v, int *x2v, int *y2v ); int n, int *x1v, int *y1v, int *x2v, int *y2v );
int im_draw_flood( VipsImage *image, int x, int y, PEL *ink, Rect *dout ); int im_draw_flood( VipsImage *image, int x, int y, PEL *ink, VipsRect *dout );
int im_draw_flood_blob( VipsImage *image, int x, int y, PEL *ink, Rect *dout ); int im_draw_flood_blob( VipsImage *image, int x, int y, PEL *ink, VipsRect *dout );
int im_draw_flood_other( VipsImage *image, VipsImage *test, int im_draw_flood_other( VipsImage *image, VipsImage *test,
int x, int y, int serial, Rect *dout ); int x, int y, int serial, VipsRect *dout );
int im_draw_mask( VipsImage *image, int im_draw_mask( VipsImage *image,
VipsImage *mask_im, int x, int y, PEL *ink ); VipsImage *mask_im, int x, int y, PEL *ink );

View File

@ -103,7 +103,7 @@ typedef struct im__buffer_t {
int ref_count; /* # of regions referencing us */ int ref_count; /* # of regions referencing us */
struct _VipsImage *im; /* VipsImage we are attached to */ struct _VipsImage *im; /* VipsImage we are attached to */
Rect area; /* Area this pixel buffer covers */ VipsRect area; /* Area this pixel buffer covers */
gboolean done; /* Calculated and in cache */ gboolean done; /* Calculated and in cache */
im_buffer_cache_t *cache; im_buffer_cache_t *cache;
char *buf; /* Private malloc() area */ char *buf; /* Private malloc() area */
@ -113,10 +113,10 @@ typedef struct im__buffer_t {
void im_buffer_done( im_buffer_t *buffer ); void im_buffer_done( im_buffer_t *buffer );
void im_buffer_undone( im_buffer_t *buffer ); void im_buffer_undone( im_buffer_t *buffer );
void im_buffer_unref( im_buffer_t *buffer ); void im_buffer_unref( im_buffer_t *buffer );
im_buffer_t *im_buffer_new( struct _VipsImage *im, Rect *area ); im_buffer_t *im_buffer_new( struct _VipsImage *im, VipsRect *area );
im_buffer_t *im_buffer_ref( struct _VipsImage *im, Rect *area ); im_buffer_t *im_buffer_ref( struct _VipsImage *im, VipsRect *area );
im_buffer_t *im_buffer_unref_ref( im_buffer_t *buffer, im_buffer_t *im_buffer_unref_ref( im_buffer_t *buffer,
struct _VipsImage *im, Rect *area ); struct _VipsImage *im, VipsRect *area );
void im_buffer_print( im_buffer_t *buffer ); void im_buffer_print( im_buffer_t *buffer );
/* Sections of region.h that are private to VIPS. /* Sections of region.h that are private to VIPS.
@ -150,7 +150,6 @@ void vips__region_take_ownership( struct _VipsRegion *reg );
void vips__region_check_ownership( struct _VipsRegion *reg ); void vips__region_check_ownership( struct _VipsRegion *reg );
void vips__region_no_ownership( struct _VipsRegion *reg ); void vips__region_no_ownership( struct _VipsRegion *reg );
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 vips__region_start( struct _VipsRegion *reg ); int vips__region_start( struct _VipsRegion *reg );
@ -158,7 +157,7 @@ void vips__region_stop( struct _VipsRegion *reg );
typedef int (*VipsRegionFillFn)( struct _VipsRegion *, void * ); typedef int (*VipsRegionFillFn)( struct _VipsRegion *, void * );
int vips_region_fill( struct _VipsRegion *reg, int vips_region_fill( struct _VipsRegion *reg,
Rect *r, VipsRegionFillFn fn, void *a ); VipsRect *r, VipsRegionFillFn fn, void *a );
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -27,41 +27,40 @@
*/ */
#ifndef IM_RECT_H #ifndef VIPS_RECT_H
#define IM_RECT_H #define VIPS_RECT_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /*__cplusplus*/ #endif /*__cplusplus*/
/* A rectangle. typedef struct _VipsRect {
*/ /*< public >*/
typedef struct _Rect {
int left; int left;
int top; int top;
int width; int width;
int height; int height;
} Rect; } VipsRect;
#define IM_RECT_RIGHT(R) ((R)->left + (R)->width) #define VIPS_RECT_RIGHT(R) ((R)->left + (R)->width)
#define IM_RECT_BOTTOM(R) ((R)->top + (R)->height) #define VIPS_RECT_BOTTOM(R) ((R)->top + (R)->height)
#define IM_RECT_HCENTRE(R) ((R)->left + (R)->width / 2) #define VIPS_RECT_HCENTRE(R) ((R)->left + (R)->width / 2)
#define IM_RECT_VCENTRE(R) ((R)->top + (R)->height / 2) #define VIPS_RECT_VCENTRE(R) ((R)->top + (R)->height / 2)
/* Rectangle algebra functions. gboolean vips_rect_isempty( const VipsRect *r );
*/ gboolean vips_rect_includespoint( const VipsRect *r, int x, int y );
void im_rect_marginadjust( Rect *r, int n ); gboolean vips_rect_includesrect( const VipsRect *r1, const VipsRect *r2 );
int im_rect_includespoint( Rect *r, int x, int y ); gboolean vips_rect_equalsrect( const VipsRect *r1, const VipsRect *r2 );
int im_rect_includesrect( Rect *r1, Rect *r2 ); void vips_rect_marginadjust( VipsRect *r, int n );
void im_rect_intersectrect( Rect *r1, Rect *r2, Rect *r3 ); void vips_rect_intersectrect( const VipsRect *r1, const VipsRect *r2,
int im_rect_isempty( Rect *r ); VipsRect *out );
void im_rect_unionrect( Rect *r1, Rect *r2, Rect *r3 ); void vips_rect_unionrect( const VipsRect *r1, const VipsRect *r2,
int im_rect_equalsrect( Rect *r1, Rect *r2 ); VipsRect *out );
Rect *im_rect_dup( Rect *r ); VipsRect *vips_rect_dup( const VipsRect *r );
void im_rect_normalise( Rect *r ); void vips_rect_normalise( VipsRect *r );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /*__cplusplus*/ #endif /*__cplusplus*/
#endif /*IM_RECT_H*/ #endif /*VIPS_RECT_H*/

View File

@ -63,7 +63,7 @@ typedef struct _VipsRegion {
/* Users may read these two fields. /* Users may read these two fields.
*/ */
VipsImage *im; /* Link back to parent image */ VipsImage *im; /* Link back to parent image */
Rect valid; /* Area of parent we can see */ VipsRect valid; /* Area of parent we can see */
/* The rest of REGION is private. /* The rest of REGION is private.
*/ */
@ -101,22 +101,22 @@ GType vips_region_get_type( void );
VipsRegion *vips_region_new( VipsImage *im ); VipsRegion *vips_region_new( VipsImage *im );
int vips_region_buffer( VipsRegion *reg, Rect *r ); int vips_region_buffer( VipsRegion *reg, VipsRect *r );
int vips_region_image( VipsRegion *reg, Rect *r ); int vips_region_image( VipsRegion *reg, VipsRect *r );
int vips_region_region( VipsRegion *reg, VipsRegion *dest, int vips_region_region( VipsRegion *reg, VipsRegion *dest,
Rect *r, int x, int y ); VipsRect *r, int x, int y );
int vips_region_equalsregion( VipsRegion *reg1, VipsRegion *reg2 ); int vips_region_equalsregion( VipsRegion *reg1, VipsRegion *reg2 );
int vips_region_position( VipsRegion *reg, int x, int y ); int vips_region_position( VipsRegion *reg, int x, int y );
void vips_region_paint( VipsRegion *reg, Rect *r, int value ); void vips_region_paint( VipsRegion *reg, VipsRect *r, int value );
void vips_region_black( VipsRegion *reg ); void vips_region_black( VipsRegion *reg );
void vips_region_copy( VipsRegion *reg, VipsRegion *dest, void vips_region_copy( VipsRegion *reg, VipsRegion *dest,
Rect *r, int x, int y ); VipsRect *r, int x, int y );
int vips_region_prepare( VipsRegion *reg, Rect *r ); int vips_region_prepare( VipsRegion *reg, VipsRect *r );
int vips_region_prepare_to( VipsRegion *reg, int vips_region_prepare_to( VipsRegion *reg,
VipsRegion *dest, Rect *r, int x, int y ); VipsRegion *dest, VipsRect *r, int x, int y );
int vips_region_prepare_many( VipsRegion **reg, Rect *r ); int vips_region_prepare_many( VipsRegion **reg, VipsRect *r );
/* Macros on REGIONs. /* Macros on REGIONs.
* VIPS_REGION_LSKIP() add to move down line * VIPS_REGION_LSKIP() add to move down line
@ -142,7 +142,7 @@ int vips_region_prepare_many( VipsRegion **reg, Rect *r );
"VIPS_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 VipsRect left=%d, top=%d, " \
"width=%d, height=%d)\n", \ "width=%d, height=%d)\n", \
__FILE__, __LINE__, \ __FILE__, __LINE__, \
(X), (Y), \ (X), (Y), \

View File

@ -76,7 +76,7 @@ typedef struct _VipsThreadState {
/* Neither used nor set, do what you like with them. /* Neither used nor set, do what you like with them.
*/ */
Rect pos; VipsRect pos;
int x, y; int x, y;
/* The client data passed to the enclosing vips_threadpool_run(). /* The client data passed to the enclosing vips_threadpool_run().
@ -126,7 +126,7 @@ 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)( VipsRegion *region, Rect *area, void *a ); typedef int (*VipsRegionWrite)( VipsRegion *region, VipsRect *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 );
@ -140,7 +140,7 @@ int vips_sink_tile( VipsImage *im,
VipsStart start, VipsGenerate generate, VipsStop stop, VipsStart start, VipsGenerate generate, VipsStop stop,
void *a, void *b ); void *a, void *b );
typedef void (*VipsSinkNotify)( VipsImage *im, Rect *rect, void *a ); typedef void (*VipsSinkNotify)( VipsImage *im, VipsRect *rect, void *a );
int vips_sink_screen( VipsImage *in, VipsImage *out, VipsImage *mask, int vips_sink_screen( VipsImage *in, VipsImage *out, VipsImage *mask,
int tile_width, int tile_height, int max_tiles, int tile_width, int tile_height, int max_tiles,
int priority, int priority,

View File

@ -33,12 +33,12 @@ typedef struct {
/* Area of input we can use. This can be smaller than the real input /* Area of input we can use. This can be smaller than the real input
* image: we expand the input to add extra pixels for interpolation. * image: we expand the input to add extra pixels for interpolation.
*/ */
Rect iarea; VipsRect iarea;
/* The area of the output we've been asked to generate. left/top can /* The area of the output we've been asked to generate. left/top can
* be negative. * be negative.
*/ */
Rect oarea; VipsRect oarea;
/* The transform. /* The transform.
*/ */
@ -60,9 +60,9 @@ void im__transform_forward_point( const Transformation *trn,
void im__transform_invert_point( const Transformation *trn, void im__transform_invert_point( const Transformation *trn,
const double x, const double y, double *ox, double *oy ); const double x, const double y, double *ox, double *oy );
void im__transform_forward_rect( const Transformation *trn, void im__transform_forward_rect( const Transformation *trn,
const Rect *in, Rect *out ); const VipsRect *in, VipsRect *out );
void im__transform_invert_rect( const Transformation *trn, void im__transform_invert_rect( const Transformation *trn,
const Rect *in, Rect *out ); const VipsRect *in, VipsRect *out );
void im__transform_set_area( Transformation * ); void im__transform_set_area( Transformation * );

View File

@ -246,6 +246,22 @@ VipsCoding im_char2Coding( const char *str );
VipsImageType im_char2dtype( const char *str ); VipsImageType im_char2dtype( const char *str );
VipsDemandStyle im_char2dhint( const char *str ); VipsDemandStyle im_char2dhint( const char *str );
#define Rect VipsRect
#define IM_RECT_RIGHT VIPS_RECT_RIGHT
#define IM_RECT_BOTTOM VIPS_RECT_BOTTOM
#define IM_RECT_HCENTRE VIPS_RECT_HCENTRE
#define IM_RECT_VCENTRE VIPS_RECT_VCENTRE
#define im_rect_marginadjust vips_rect_marginadjust
#define im_rect_includespoint vips_rect_includespoint
#define im_rect_includesrect vips_rect_includesrect
#define im_rect_intersectrect vips_rect_intersectrect
#define im_rect_isempty vips_rect_isempty
#define im_rect_unionrect vips_rect_unionrect
#define im_rect_equalsrect vips_rect_equalsrect
#define im_rect_dup vips_rect_dup
#define im_rect_normalise vips_rect_normalise
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /*__cplusplus*/ #endif /*__cplusplus*/

View File

@ -293,7 +293,7 @@ im_buffer_unref( im_buffer_t *buffer )
/* Make a new buffer. /* Make a new buffer.
*/ */
im_buffer_t * im_buffer_t *
im_buffer_new( IMAGE *im, Rect *area ) im_buffer_new( IMAGE *im, VipsRect *area )
{ {
im_buffer_t *buffer; im_buffer_t *buffer;
@ -331,7 +331,7 @@ im_buffer_new( IMAGE *im, Rect *area )
} }
static int static int
buffer_move( im_buffer_t *buffer, Rect *area ) buffer_move( im_buffer_t *buffer, VipsRect *area )
{ {
IMAGE *im = buffer->im; IMAGE *im = buffer->im;
size_t new_bsize; size_t new_bsize;
@ -357,19 +357,19 @@ buffer_move( im_buffer_t *buffer, Rect *area )
/* Find an existing buffer that encloses area and return a ref. /* Find an existing buffer that encloses area and return a ref.
*/ */
static im_buffer_t * static im_buffer_t *
buffer_find( IMAGE *im, Rect *r ) buffer_find( IMAGE *im, VipsRect *r )
{ {
im_buffer_cache_t *cache = buffer_cache_get(); im_buffer_cache_t *cache = buffer_cache_get();
im_buffer_cache_list_t *cache_list; im_buffer_cache_list_t *cache_list;
im_buffer_t *buffer; im_buffer_t *buffer;
GSList *p; GSList *p;
Rect *area; VipsRect *area;
cache_list = g_hash_table_lookup( cache->hash, im ); cache_list = g_hash_table_lookup( cache->hash, im );
p = cache_list ? cache_list->buffers : NULL; p = cache_list ? cache_list->buffers : NULL;
/* This needs to be quick :-( don't use /* This needs to be quick :-( don't use
* im_slist_map2()/im_rect_includesrect(), do the search inline. * im_slist_map2()/vips_rect_includesrect(), do the search inline.
* *
* FIXME we return the first enclosing buffer, perhaps we should * FIXME we return the first enclosing buffer, perhaps we should
* search for the largest? * search for the largest?
@ -406,7 +406,7 @@ buffer_find( IMAGE *im, Rect *r )
/* Return a ref to a buffer that encloses area. /* Return a ref to a buffer that encloses area.
*/ */
im_buffer_t * im_buffer_t *
im_buffer_ref( IMAGE *im, Rect *area ) im_buffer_ref( IMAGE *im, VipsRect *area )
{ {
im_buffer_t *buffer; im_buffer_t *buffer;
@ -423,7 +423,7 @@ im_buffer_ref( IMAGE *im, Rect *area )
* buffer we return might or might not be done. * buffer we return might or might not be done.
*/ */
im_buffer_t * im_buffer_t *
im_buffer_unref_ref( im_buffer_t *old_buffer, IMAGE *im, Rect *area ) im_buffer_unref_ref( im_buffer_t *old_buffer, IMAGE *im, VipsRect *area )
{ {
im_buffer_t *buffer; im_buffer_t *buffer;
@ -432,7 +432,7 @@ im_buffer_unref_ref( im_buffer_t *old_buffer, IMAGE *im, Rect *area )
/* Is the current buffer OK? /* Is the current buffer OK?
*/ */
if( old_buffer && if( old_buffer &&
im_rect_includesrect( &old_buffer->area, area ) ) vips_rect_includesrect( &old_buffer->area, area ) )
return( old_buffer ); return( old_buffer );
/* Does the new area already have a buffer? /* Does the new area already have a buffer?

View File

@ -311,7 +311,7 @@ im_allocate_input_array( IMAGE *out, ... )
/* A write function for VIPS images. Just write() the pixel data. /* A write function for VIPS images. Just write() the pixel data.
*/ */
static int static int
write_vips( VipsRegion *region, Rect *area, void *a, void *b ) write_vips( VipsRegion *region, VipsRect *area, void *a, void *b )
{ {
size_t nwritten, count; size_t nwritten, count;
void *buf; void *buf;

View File

@ -708,7 +708,7 @@ open_lazy_generate( VipsRegion *or, void *seq, void *a, void *b )
{ {
VipsRegion *ir = (VipsRegion *) seq; VipsRegion *ir = (VipsRegion *) seq;
Rect *r = &or->valid; VipsRect *r = &or->valid;
/* Ask for input we need. /* Ask for input we need.
*/ */

View File

@ -2,6 +2,10 @@
* this. * this.
* *
* J. Cupitt, 8/4/93. * J. Cupitt, 8/4/93.
*
* 17/3/11
* - move to vips_ prefix
* - gtk-doc comments
*/ */
/* /*
@ -44,30 +48,38 @@
#endif /*WITH_DMALLOC*/ #endif /*WITH_DMALLOC*/
/** /**
* Rect: * SECTION: rect
* @short_description: the VIPS rectangle class
* @stability: Stable
* @see_also: <link linkend="libvips-region">region</link>
* @include: vips/vips.h
*
* The #VipsRect class and associated types and macros.
*/
/**
* VipsRect:
* @left: left edge of rectangle * @left: left edge of rectangle
* @top: top edge of rectangle * @top: top edge of rectangle
* @width: width of rectangle * @width: width of rectangle
* @height: height of rectangle * @height: height of rectangle
* *
* A #Rect is a rectangular area of pixels. * A #VipsRect is a rectangular area of pixels. This is a struct for
* performing simple rectangle algebra.
*/ */
/* Move the margins of a rect. +1 means out one pixel. /**
* vips_rect_includespoint:
* @r: rectangle to test
* @x: position to test for
* @y: position to test for
*
* Does @r contain point (@x, @y)?
*
* Returns: %TRUE if @r contains (@x, @y).
*/ */
void gboolean
im_rect_marginadjust( Rect *r, int n ) vips_rect_includespoint( const VipsRect *r, int x, int y )
{
r->left -= n;
r->top -= n;
r->width += 2 * n;
r->height += 2 * n;
}
/* Does rect contain a point?
*/
int
im_rect_includespoint( Rect *r, int x, int y )
{ {
return( r->left <= x && return( r->left <= x &&
r->top <= y && r->top <= y &&
@ -75,10 +87,31 @@ im_rect_includespoint( Rect *r, int x, int y )
r->top + r->height > y ); r->top + r->height > y );
} }
/* Is r2 a subset of r1? /**
* vips_rect_isempty:
* @r: rectangle to test
*
* Is @r empty? ie. zero width or height.
*
* Returns: %TRUE if @r contains no pixels.
*/ */
int gboolean
im_rect_includesrect( Rect *r1, Rect *r2 ) vips_rect_isempty( const VipsRect *r )
{
return( r->width <= 0 || r->height <= 0 );
}
/**
* vips_rect_includesrect:
* @r1: outer rectangle
* @r2: inner rectangle
*
* Is @r2 a subset of @r1?
*
* Returns: %TRUE if @r2 is a subset of @r1.
*/
gboolean
vips_rect_includesrect( const VipsRect *r1, const VipsRect *r2 )
{ {
return( r1->left <= r2->left && return( r1->left <= r2->left &&
r1->top <= r2->top && r1->top <= r2->top &&
@ -86,85 +119,121 @@ im_rect_includesrect( Rect *r1, Rect *r2 )
r1->top + r1->height >= r2->top + r2->height ); r1->top + r1->height >= r2->top + r2->height );
} }
/* Fill r3 with the intersection of r1 and r2. r3 can equal r1 or r2. /**
* vips_rect_equalsrect:
* @r1: first rectangle
* @r2: second rectangle
*
* Is @r1 equal to @r2?
*
* Returns: %TRUE if @r1 is equal to @r2.
*/ */
void gboolean
im_rect_intersectrect( Rect *r1, Rect *r2, Rect *r3 ) vips_rect_equalsrect( const VipsRect *r1, const VipsRect *r2 )
{
int left = VIPS_MAX( r1->left, r2->left );
int top = VIPS_MAX( r1->top, r2->top );
int right = VIPS_MIN( IM_RECT_RIGHT( r1 ), IM_RECT_RIGHT( r2 ) );
int bottom = VIPS_MIN( IM_RECT_BOTTOM( r1 ), IM_RECT_BOTTOM( r2 ) );
int width = VIPS_MAX( 0, right - left );
int height = VIPS_MAX( 0, bottom - top );
r3->left = left;
r3->top = top;
r3->width = width;
r3->height = height;
}
/* Is a rect empty? ie. zero width or height.
*/
int
im_rect_isempty( Rect *r )
{
return( r->width <= 0 || r->height <= 0 );
}
/* Fill r3 with the set union of r1 and r2. Can't do this very well, as can
* only have rectangular areas. Just set to smallest box that encloses both r1
* and r2. If either is empty, can just return the other.
*/
void
im_rect_unionrect( Rect *r1, Rect *r2, Rect *r3 )
{
if( im_rect_isempty( r1 ) )
*r3 = *r2;
else if( im_rect_isempty( r2 ) )
*r3 = *r1;
else {
int left = VIPS_MIN( r1->left, r2->left );
int top = VIPS_MIN( r1->top, r2->top );
int width = VIPS_MAX( IM_RECT_RIGHT( r1 ),
IM_RECT_RIGHT( r2 ) ) - left;
int height = VIPS_MAX( IM_RECT_BOTTOM( r1 ),
IM_RECT_BOTTOM( r2 ) )- top;
r3->left = left;
r3->top = top;
r3->width = width;
r3->height = height;
}
}
/* Test for equality.
*/
int
im_rect_equalsrect( Rect *r1, Rect *r2 )
{ {
return( r1->left == r2->left && r1->top == r2->top && return( r1->left == r2->left && r1->top == r2->top &&
r1->width == r2->width && r1->height == r2->height ); r1->width == r2->width && r1->height == r2->height );
} }
/* DUP a rect. /**
* vips_rect_marginadjust:
* @r: rectangle to adjust
* @n: enlarge by
*
* Enlarge @r by @n. +1 means out one pixel.
*/ */
Rect * void
im_rect_dup( Rect *r ) vips_rect_marginadjust( VipsRect *r, int n )
{
r->left -= n;
r->top -= n;
r->width += 2 * n;
r->height += 2 * n;
}
/**
* vips_rect_intersectrect:
* @r1: input rectangle 1
* @r2: input rectangle 2
* @out: output rectangle
*
* Fill @out with the intersection of @r1 and @r2. @out can equal @r1 or @r2.
*/
void
vips_rect_intersectrect( const VipsRect *r1, const VipsRect *r2, VipsRect *out )
{
int left = VIPS_MAX( r1->left, r2->left );
int top = VIPS_MAX( r1->top, r2->top );
int right = VIPS_MIN( VIPS_RECT_RIGHT( r1 ), VIPS_RECT_RIGHT( r2 ) );
int bottom = VIPS_MIN( VIPS_RECT_BOTTOM( r1 ), VIPS_RECT_BOTTOM( r2 ) );
int width = VIPS_MAX( 0, right - left );
int height = VIPS_MAX( 0, bottom - top );
out->left = left;
out->top = top;
out->width = width;
out->height = height;
}
/**
* vips_rect_unionrect:
* @r1: input rectangle 1
* @r2: input rectangle 2
* @out: output rectangle
*
* Fill @out with the bounding box of @r1 and @r2. @out can equal @r1 or @r2.
*/
void
vips_rect_unionrect( const VipsRect *r1, const VipsRect *r2, VipsRect *out )
{
if( vips_rect_isempty( r1 ) )
*out = *r2;
else if( vips_rect_isempty( r2 ) )
*out = *r1;
else {
int left = VIPS_MIN( r1->left, r2->left );
int top = VIPS_MIN( r1->top, r2->top );
int width = VIPS_MAX( VIPS_RECT_RIGHT( r1 ),
VIPS_RECT_RIGHT( r2 ) ) - left;
int height = VIPS_MAX( VIPS_RECT_BOTTOM( r1 ),
VIPS_RECT_BOTTOM( r2 ) )- top;
out->left = left;
out->top = top;
out->width = width;
out->height = height;
}
}
/**
* vips_rect_dup:
* @r: rectangle to duplicate
*
* Duplicate a rect to the heap. You need to free the result with vips_free().
*
* Returns: a pointer to copy of @r allocated on the heap.
*/
VipsRect *
vips_rect_dup( const VipsRect *r )
{ {
Rect *out = VIPS_NEW( NULL, Rect ); VipsRect *out;
if( !out ) if( !(out = VIPS_NEW( NULL, VipsRect )) )
return( NULL ); return( NULL );
*out = *r; *out = *r;
return( out ); return( out );
} }
/* Make sure width and height are >0. /**
* vips_rect_normalise:
* @r: rect to normalise
*
* Make sure width and height are >0 by moving the origin and flipping the
* rect.
*/ */
void void
im_rect_normalise( Rect *r ) vips_rect_normalise( VipsRect *r )
{ {
if( r->width < 0 ) { if( r->width < 0 ) {
r->left += r->width; r->left += r->width;

View File

@ -133,7 +133,7 @@
/** /**
* VipsRegion: * VipsRegion:
* @im: the #VipsImage that this region is defined on * @im: the #VipsImage that this region is defined on
* @valid: the #Rect of pixels that this region represents * @valid: the #VipsRect of pixels that this region represents
* *
* A small part of a #VipsImage. @valid holds the left/top/width/height of the * A small part of a #VipsImage. @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.
@ -169,7 +169,7 @@
* @Y: y coordinate * @Y: y coordinate
* *
* This macro returns a pointer to a pixel in a region. The (x, y) coordinates * This macro returns a pointer to a pixel in a region. The (x, y) coordinates
* need to be within the #Rect (@R->valid). * need to be within the #VipsRect (@R->valid).
* *
* If DEBUG is defined, you get a version that checks bounds for you. * If DEBUG is defined, you get a version that checks bounds for you.
* *
@ -461,7 +461,7 @@ vips_region_new( VipsImage *image )
/** /**
* vips_region_buffer: * vips_region_buffer:
* @reg: region to operate upon * @reg: region to operate upon
* @r: #Rect of pixels you need to be able to address * @r: #VipsRect of pixels you need to be able to address
* *
* The region is transformed so that at least @r pixels are available as a * The region is transformed so that at least @r pixels are available as a
* memory buffer. * memory buffer.
@ -469,12 +469,12 @@ vips_region_new( VipsImage *image )
* Returns: 0 on success, or -1 for error. * Returns: 0 on success, or -1 for error.
*/ */
int int
vips_region_buffer( VipsRegion *reg, Rect *r ) vips_region_buffer( VipsRegion *reg, VipsRect *r )
{ {
VipsImage *im = reg->im; VipsImage *im = reg->im;
Rect image; VipsRect image;
Rect clipped; VipsRect clipped;
vips__region_check_ownership( reg ); vips__region_check_ownership( reg );
@ -484,11 +484,11 @@ vips_region_buffer( VipsRegion *reg, Rect *r )
image.left = 0; image.left = 0;
image.width = im->Xsize; image.width = im->Xsize;
image.height = im->Ysize; image.height = im->Ysize;
im_rect_intersectrect( r, &image, &clipped ); vips_rect_intersectrect( r, &image, &clipped );
/* Test for empty. /* Test for empty.
*/ */
if( im_rect_isempty( &clipped ) ) { if( vips_rect_isempty( &clipped ) ) {
vips_error( "VipsRegion", vips_error( "VipsRegion",
"%s", _( "valid clipped to nothing" ) ); "%s", _( "valid clipped to nothing" ) );
return( -1 ); return( -1 );
@ -528,7 +528,7 @@ vips_region_buffer( VipsRegion *reg, Rect *r )
/** /**
* vips_region_image: * vips_region_image:
* @reg: region to operate upon * @reg: region to operate upon
* @r: #Rect of pixels you need to be able to address * @r: #VipsRect of pixels you need to be able to address
* *
* The region is transformed so that at least @r pixels are available directly * The region is transformed so that at least @r pixels are available directly
* from the image. The image needs to be a memory buffer or represent a file * from the image. The image needs to be a memory buffer or represent a file
@ -537,10 +537,10 @@ vips_region_buffer( VipsRegion *reg, Rect *r )
* Returns: 0 on success, or -1 for error. * Returns: 0 on success, or -1 for error.
*/ */
int int
vips_region_image( VipsRegion *reg, Rect *r ) vips_region_image( VipsRegion *reg, VipsRect *r )
{ {
Rect image; VipsRect image;
Rect clipped; VipsRect clipped;
/* Sanity check. /* Sanity check.
*/ */
@ -552,11 +552,11 @@ vips_region_image( VipsRegion *reg, Rect *r )
image.left = 0; image.left = 0;
image.width = reg->im->Xsize; image.width = reg->im->Xsize;
image.height = reg->im->Ysize; image.height = reg->im->Ysize;
im_rect_intersectrect( r, &image, &clipped ); vips_rect_intersectrect( r, &image, &clipped );
/* Test for empty. /* Test for empty.
*/ */
if( im_rect_isempty( &clipped ) ) { if( vips_rect_isempty( &clipped ) ) {
vips_error( "VipsRegion", vips_error( "VipsRegion",
"%s", _( "valid clipped to nothing" ) ); "%s", _( "valid clipped to nothing" ) );
return( -1 ); return( -1 );
@ -615,7 +615,7 @@ vips_region_image( VipsRegion *reg, Rect *r )
* vips_region_region: * vips_region_region:
* @reg: region to operate upon * @reg: region to operate upon
* @dest: region to connect to * @dest: region to connect to
* @r: #Rect of pixels you need to be able to address * @r: #VipsRect of pixels you need to be able to address
* @x: postion of @r in @dest * @x: postion of @r in @dest
* @y: postion of @r in @dest * @y: postion of @r in @dest
* *
@ -636,13 +636,13 @@ vips_region_image( VipsRegion *reg, Rect *r )
* Returns: 0 on success, or -1 for error. * Returns: 0 on success, or -1 for error.
*/ */
int int
vips_region_region( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y ) vips_region_region( VipsRegion *reg, VipsRegion *dest, VipsRect *r, int x, int y )
{ {
Rect image; VipsRect image;
Rect wanted; VipsRect wanted;
Rect clipped; VipsRect clipped;
Rect clipped2; VipsRect clipped2;
Rect final; VipsRect final;
/* Sanity check. /* Sanity check.
*/ */
@ -669,7 +669,7 @@ vips_region_region( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y )
image.left = 0; image.left = 0;
image.width = reg->im->Xsize; image.width = reg->im->Xsize;
image.height = reg->im->Ysize; image.height = reg->im->Ysize;
im_rect_intersectrect( r, &image, &clipped ); vips_rect_intersectrect( r, &image, &clipped );
/* Translate to dest's coordinate space and clip against the available /* Translate to dest's coordinate space and clip against the available
* pixels. * pixels.
@ -681,7 +681,7 @@ vips_region_region( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y )
/* Test that dest->valid is large enough. /* Test that dest->valid is large enough.
*/ */
if( !im_rect_includesrect( &dest->valid, &wanted ) ) { if( !vips_rect_includesrect( &dest->valid, &wanted ) ) {
vips_error( "VipsRegion", vips_error( "VipsRegion",
"%s", _( "dest too small" ) ); "%s", _( "dest too small" ) );
return( -1 ); return( -1 );
@ -689,7 +689,7 @@ vips_region_region( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y )
/* Clip against the available pixels. /* Clip against the available pixels.
*/ */
im_rect_intersectrect( &wanted, &dest->valid, &clipped2 ); vips_rect_intersectrect( &wanted, &dest->valid, &clipped2 );
/* Translate back to reg's coordinate space and set as valid. /* Translate back to reg's coordinate space and set as valid.
*/ */
@ -700,7 +700,7 @@ vips_region_region( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y )
/* Test for empty. /* Test for empty.
*/ */
if( im_rect_isempty( &final ) ) { if( vips_rect_isempty( &final ) ) {
vips_error( "VipsRegion", vips_error( "VipsRegion",
"%s", _( "valid clipped to nothing" ) ); "%s", _( "valid clipped to nothing" ) );
return( -1 ); return( -1 );
@ -736,7 +736,7 @@ int
vips_region_equalsregion( VipsRegion *reg1, VipsRegion *reg2 ) vips_region_equalsregion( VipsRegion *reg1, VipsRegion *reg2 )
{ {
return( reg1->im == reg2->im && return( reg1->im == reg2->im &&
im_rect_equalsrect( &reg1->valid, &reg2->valid ) && vips_rect_equalsrect( &reg1->valid, &reg2->valid ) &&
reg1->data == reg2->data ); reg1->data == reg2->data );
} }
@ -756,7 +756,7 @@ vips_region_equalsregion( VipsRegion *reg1, VipsRegion *reg2 )
int int
vips_region_position( VipsRegion *reg, int x, int y ) vips_region_position( VipsRegion *reg, int x, int y )
{ {
Rect req, image, clipped; VipsRect req, image, clipped;
/* Clip! /* Clip!
*/ */
@ -768,8 +768,8 @@ vips_region_position( VipsRegion *reg, int x, int y )
req.left = x; req.left = x;
req.width = reg->valid.width; req.width = reg->valid.width;
req.height = reg->valid.height; req.height = reg->valid.height;
im_rect_intersectrect( &image, &req, &clipped ); vips_rect_intersectrect( &image, &req, &clipped );
if( x < 0 || y < 0 || im_rect_isempty( &clipped ) ) { if( x < 0 || y < 0 || vips_rect_isempty( &clipped ) ) {
vips_error( "VipsRegion", "%s", _( "bad position" ) ); vips_error( "VipsRegion", "%s", _( "bad position" ) );
return( -1 ); return( -1 );
} }
@ -781,7 +781,7 @@ vips_region_position( VipsRegion *reg, int x, int y )
} }
int int
vips_region_fill( VipsRegion *reg, Rect *r, VipsRegionFillFn fn, void *a ) vips_region_fill( VipsRegion *reg, VipsRect *r, VipsRegionFillFn fn, void *a )
{ {
g_assert( reg->im->dtype == VIPS_IMAGE_PARTIAL ); g_assert( reg->im->dtype == VIPS_IMAGE_PARTIAL );
g_assert( reg->im->generate ); g_assert( reg->im->generate );
@ -819,12 +819,12 @@ vips_region_fill( VipsRegion *reg, Rect *r, VipsRegionFillFn fn, void *a )
* See also: vips_region_black(). * See also: vips_region_black().
*/ */
void void
vips_region_paint( VipsRegion *reg, Rect *r, int value ) vips_region_paint( VipsRegion *reg, VipsRect *r, int value )
{ {
Rect ovl; VipsRect ovl;
im_rect_intersectrect( r, &reg->valid, &ovl ); vips_rect_intersectrect( r, &reg->valid, &ovl );
if( !im_rect_isempty( &ovl ) ) { if( !vips_rect_isempty( &ovl ) ) {
PEL *q = (PEL *) VIPS_REGION_ADDR( reg, ovl.left, ovl.top ); PEL *q = (PEL *) VIPS_REGION_ADDR( reg, ovl.left, ovl.top );
int wd = ovl.width * VIPS_IMAGE_SIZEOF_PEL( reg->im ); int wd = ovl.width * VIPS_IMAGE_SIZEOF_PEL( reg->im );
int ls = VIPS_REGION_LSKIP( reg ); int ls = VIPS_REGION_LSKIP( reg );
@ -855,7 +855,7 @@ vips_region_black( VipsRegion *reg )
* vips_region_copy: * vips_region_copy:
* @reg: source region * @reg: source region
* @dest: destination region * @dest: destination region
* @r: #Rect of pixels you need to copy * @r: #VipsRect of pixels you need to copy
* @x: postion of @r in @dest * @x: postion of @r in @dest
* @y: postion of @r in @dest * @y: postion of @r in @dest
* *
@ -866,7 +866,7 @@ vips_region_black( VipsRegion *reg )
* See also: vips_region_paint(). * See also: vips_region_paint().
*/ */
void void
vips_region_copy( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y ) vips_region_copy( VipsRegion *reg, VipsRegion *dest, VipsRect *r, int x, int y )
{ {
int z; int z;
int len = VIPS_IMAGE_SIZEOF_PEL( reg->im ) * r->width; int len = VIPS_IMAGE_SIZEOF_PEL( reg->im ) * r->width;
@ -878,7 +878,7 @@ vips_region_copy( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y )
#ifdef DEBUG #ifdef DEBUG
/* Find the area we will write to in dest. /* Find the area we will write to in dest.
*/ */
Rect output; VipsRect output;
printf( "vips_region_copy: sanity check\n" ); printf( "vips_region_copy: sanity check\n" );
@ -889,11 +889,11 @@ vips_region_copy( VipsRegion *reg, VipsRegion *dest, Rect *r, int x, int y )
/* Must be inside dest->valid. /* Must be inside dest->valid.
*/ */
g_assert( im_rect_includesrect( &dest->valid, &output ) ); g_assert( vips_rect_includesrect( &dest->valid, &output ) );
/* Check the area we are reading from in reg. /* Check the area we are reading from in reg.
*/ */
g_assert( im_rect_includesrect( &reg->valid, r ) ); g_assert( vips_rect_includesrect( &reg->valid, r ) );
/* PEL size must be the same. /* PEL size must be the same.
*/ */
@ -932,7 +932,7 @@ vips_region_generate( VipsRegion *reg )
/** /**
* vips_region_prepare: * vips_region_prepare:
* @reg: region to prepare * @reg: region to prepare
* @r: #Rect of pixels you need to be able to address * @r: #VipsRect of pixels you need to be able to address
* *
* vips_region_prepare() fills @reg with pixels. After calling, * vips_region_prepare() fills @reg with pixels. After calling,
* you can address at least the area @r with VIPS_REGION_ADDR() and get * you can address at least the area @r with VIPS_REGION_ADDR() and get
@ -952,11 +952,11 @@ vips_region_generate( VipsRegion *reg )
* Returns: 0 on success, or -1 on error. * Returns: 0 on success, or -1 on error.
*/ */
int int
vips_region_prepare( VipsRegion *reg, Rect *r ) vips_region_prepare( VipsRegion *reg, VipsRect *r )
{ {
VipsImage *im = reg->im; VipsImage *im = reg->im;
Rect save = *r; VipsRect save = *r;
vips__region_check_ownership( reg ); vips__region_check_ownership( reg );
@ -971,13 +971,13 @@ vips_region_prepare( VipsRegion *reg, Rect *r )
* save as well to make sure we don't fail the assert due to that. * save as well to make sure we don't fail the assert due to that.
*/ */
{ {
Rect image; VipsRect image;
image.left = 0; image.left = 0;
image.top = 0; image.top = 0;
image.width = reg->im->Xsize; image.width = reg->im->Xsize;
image.height = reg->im->Ysize; image.height = reg->im->Ysize;
im_rect_intersectrect( &save, &image, &save ); vips_rect_intersectrect( &save, &image, &save );
} }
#ifdef DEBUG #ifdef DEBUG
@ -1015,7 +1015,7 @@ vips_region_prepare( VipsRegion *reg, Rect *r )
/* valid should now include all the pixels that were asked for. /* valid should now include all the pixels that were asked for.
*/ */
g_assert( im_rect_includesrect( &reg->valid, &save ) ); g_assert( vips_rect_includesrect( &reg->valid, &save ) );
return( 0 ); return( 0 );
} }
@ -1025,7 +1025,7 @@ vips_region_prepare( VipsRegion *reg, Rect *r )
*/ */
static int static int
vips_region_prepare_to_generate( VipsRegion *reg, vips_region_prepare_to_generate( VipsRegion *reg,
VipsRegion *dest, Rect *r, int x, int y ) VipsRegion *dest, VipsRect *r, int x, int y )
{ {
IMAGE *im = reg->im; IMAGE *im = reg->im;
char *p; char *p;
@ -1061,7 +1061,7 @@ vips_region_prepare_to_generate( VipsRegion *reg,
* vips_region_prepare_to: * vips_region_prepare_to:
* @reg: region to prepare * @reg: region to prepare
* @dest: region to write to * @dest: region to write to
* @r: #Rect of pixels you need to be able to address * @r: #VipsRect of pixels you need to be able to address
* @x: postion of @r in @dest * @x: postion of @r in @dest
* @y: postion of @r in @dest * @y: postion of @r in @dest
* *
@ -1084,14 +1084,14 @@ vips_region_prepare_to_generate( VipsRegion *reg,
*/ */
int int
vips_region_prepare_to( VipsRegion *reg, vips_region_prepare_to( VipsRegion *reg,
VipsRegion *dest, Rect *r, int x, int y ) VipsRegion *dest, VipsRect *r, int x, int y )
{ {
VipsImage *im = reg->im; VipsImage *im = reg->im;
Rect image; VipsRect image;
Rect wanted; VipsRect wanted;
Rect clipped; VipsRect clipped;
Rect clipped2; VipsRect clipped2;
Rect final; VipsRect final;
if( vips_image_get_kill( im ) ) if( vips_image_get_kill( im ) )
return( -1 ); return( -1 );
@ -1114,7 +1114,7 @@ vips_region_prepare_to( VipsRegion *reg,
image.left = 0; image.left = 0;
image.width = reg->im->Xsize; image.width = reg->im->Xsize;
image.height = reg->im->Ysize; image.height = reg->im->Ysize;
im_rect_intersectrect( r, &image, &clipped ); vips_rect_intersectrect( r, &image, &clipped );
g_assert( clipped.left == r->left ); g_assert( clipped.left == r->left );
g_assert( clipped.top == r->top ); g_assert( clipped.top == r->top );
@ -1126,12 +1126,12 @@ vips_region_prepare_to( VipsRegion *reg,
/* Test that dest->valid is large enough. /* Test that dest->valid is large enough.
*/ */
if( !im_rect_includesrect( &dest->valid, &wanted ) ) { if( !vips_rect_includesrect( &dest->valid, &wanted ) ) {
vips_error( "im_prepare_to", "%s", _( "dest too small" ) ); vips_error( "im_prepare_to", "%s", _( "dest too small" ) );
return( -1 ); return( -1 );
} }
im_rect_intersectrect( &wanted, &dest->valid, &clipped2 ); vips_rect_intersectrect( &wanted, &dest->valid, &clipped2 );
/* Translate back to reg's coordinate space and set as valid. /* Translate back to reg's coordinate space and set as valid.
*/ */
@ -1143,7 +1143,7 @@ vips_region_prepare_to( VipsRegion *reg,
x = clipped2.left; x = clipped2.left;
y = clipped2.top; y = clipped2.top;
if( im_rect_isempty( &final ) ) { if( vips_rect_isempty( &final ) ) {
vips_error( "im_prepare_to", vips_error( "im_prepare_to",
"%s", _( "valid clipped to nothing" ) ); "%s", _( "valid clipped to nothing" ) );
return( -1 ); return( -1 );
@ -1214,7 +1214,7 @@ vips_region_prepare_to( VipsRegion *reg,
} }
int int
vips_region_prepare_many( VipsRegion **reg, Rect *r ) vips_region_prepare_many( VipsRegion **reg, VipsRect *r )
{ {
for( ; *reg; ++reg ) for( ; *reg; ++reg )
if( vips_region_prepare( *reg, r ) ) if( vips_region_prepare( *reg, r ) )

View File

@ -238,7 +238,7 @@ sink_allocate( VipsThreadState *state, void *a, gboolean *stop )
{ {
Sink *sink = (Sink *) a; Sink *sink = (Sink *) a;
Rect image, tile; VipsRect image, tile;
/* Is the state x/y OK? New line or maybe all done. /* Is the state x/y OK? New line or maybe all done.
*/ */
@ -263,7 +263,7 @@ sink_allocate( VipsThreadState *state, void *a, gboolean *stop )
tile.top = sink->y; tile.top = sink->y;
tile.width = sink->tile_width; tile.width = sink->tile_width;
tile.height = sink->tile_height; tile.height = sink->tile_height;
im_rect_intersectrect( &image, &tile, &state->pos ); vips_rect_intersectrect( &image, &tile, &state->pos );
/* Move state on. /* Move state on.
*/ */

View File

@ -71,7 +71,7 @@ typedef struct _WriteBuffer {
struct _Write *write; struct _Write *write;
VipsRegion *region; /* Pixels */ VipsRegion *region; /* Pixels */
Rect area; /* Part of image this region covers */ VipsRect area; /* Part of image this region covers */
im_semaphore_t go; /* Start bg thread loop */ im_semaphore_t go; /* Start bg thread loop */
im_semaphore_t nwrite; /* Number of threads writing to region */ im_semaphore_t nwrite; /* Number of threads writing to region */
im_semaphore_t done; /* Bg thread has done write */ im_semaphore_t done; /* Bg thread has done write */
@ -298,7 +298,7 @@ wbuffer_flush( Write *write )
static int static int
wbuffer_position( WriteBuffer *wbuffer, int top, int height ) wbuffer_position( WriteBuffer *wbuffer, int top, int height )
{ {
Rect image, area; VipsRect image, area;
int result; int result;
image.left = 0; image.left = 0;
@ -311,7 +311,7 @@ wbuffer_position( WriteBuffer *wbuffer, int top, int height )
area.width = wbuffer->write->im->Xsize; area.width = wbuffer->write->im->Xsize;
area.height = height; area.height = height;
im_rect_intersectrect( &area, &image, &wbuffer->area ); vips_rect_intersectrect( &area, &image, &wbuffer->area );
/* The workers take turns to move the buffers. /* The workers take turns to move the buffers.
*/ */
@ -339,8 +339,8 @@ wbuffer_allocate_fn( VipsThreadState *state, void *a, gboolean *stop )
WriteThreadState *wstate = (WriteThreadState *) state; WriteThreadState *wstate = (WriteThreadState *) state;
Write *write = (Write *) a; Write *write = (Write *) a;
Rect image; VipsRect image;
Rect tile; VipsRect tile;
VIPS_DEBUG_MSG( "wbuffer_allocate_fn:\n" ); VIPS_DEBUG_MSG( "wbuffer_allocate_fn:\n" );
@ -351,7 +351,7 @@ wbuffer_allocate_fn( VipsThreadState *state, void *a, gboolean *stop )
write->x = 0; write->x = 0;
write->y += write->tile_height; write->y += write->tile_height;
if( write->y >= IM_RECT_BOTTOM( &write->buf->area ) ) { if( write->y >= VIPS_RECT_BOTTOM( &write->buf->area ) ) {
/* Block until the last write is done, then set write /* Block until the last write is done, then set write
* of the front buffer going. * of the front buffer going.
*/ */
@ -393,7 +393,7 @@ wbuffer_allocate_fn( VipsThreadState *state, void *a, gboolean *stop )
tile.top = write->y; tile.top = write->y;
tile.width = write->tile_width; tile.width = write->tile_width;
tile.height = write->tile_height; tile.height = write->tile_height;
im_rect_intersectrect( &image, &tile, &state->pos ); vips_rect_intersectrect( &image, &tile, &state->pos );
wstate->buf = write->buf; wstate->buf = write->buf;
/* Add to the number of writers on the buffer. /* Add to the number of writers on the buffer.

View File

@ -81,7 +81,7 @@ sink_free( Sink *sink )
static int static int
sink_init( Sink *sink, VipsImage *im ) sink_init( Sink *sink, VipsImage *im )
{ {
Rect all; VipsRect all;
sink->im = im; sink->im = im;
sink->x = 0; sink->x = 0;
@ -109,7 +109,7 @@ sink_allocate( VipsThreadState *state, void *a, gboolean *stop )
{ {
Sink *sink = (Sink *) a; Sink *sink = (Sink *) a;
Rect image, tile; VipsRect image, tile;
/* Is the state x/y OK? New line or maybe all done. /* Is the state x/y OK? New line or maybe all done.
*/ */
@ -134,7 +134,7 @@ sink_allocate( VipsThreadState *state, void *a, gboolean *stop )
tile.top = sink->y; tile.top = sink->y;
tile.width = sink->tile_width; tile.width = sink->tile_width;
tile.height = sink->tile_height; tile.height = sink->tile_height;
im_rect_intersectrect( &image, &tile, &state->pos ); vips_rect_intersectrect( &image, &tile, &state->pos );
/* Move state on. /* Move state on.
*/ */

View File

@ -87,7 +87,7 @@ static int render_num_renders = 0;
typedef struct { typedef struct {
struct _Render *render; struct _Render *render;
Rect area; /* Place here (unclipped) */ VipsRect area; /* Place here (unclipped) */
VipsRegion *region; /* VipsRegion with the pixels */ VipsRegion *region; /* VipsRegion with the pixels */
/* The tile contains calculated pixels. Though the region may have been /* The tile contains calculated pixels. Though the region may have been
@ -549,7 +549,7 @@ render_thread_create( void )
static guint static guint
tile_hash( gconstpointer key ) tile_hash( gconstpointer key )
{ {
Rect *rect = (Rect *) key; VipsRect *rect = (VipsRect *) key;
int x = rect->left / rect->width; int x = rect->left / rect->width;
int y = rect->top / rect->height; int y = rect->top / rect->height;
@ -560,8 +560,8 @@ tile_hash( gconstpointer key )
static gboolean static gboolean
tile_equal( gconstpointer a, gconstpointer b ) tile_equal( gconstpointer a, gconstpointer b )
{ {
Rect *rect1 = (Rect *) a; VipsRect *rect1 = (VipsRect *) a;
Rect *rect2 = (Rect *) b; VipsRect *rect2 = (VipsRect *) b;
return( rect1->left == rect2->left && return( rect1->left == rect2->left &&
rect1->top == rect2->top ); rect1->top == rect2->top );
@ -680,7 +680,7 @@ tile_new( Render *render )
/* Search the cache for a tile by position. /* Search the cache for a tile by position.
*/ */
static Tile * static Tile *
render_tile_lookup( Render *render, Rect *area ) render_tile_lookup( Render *render, VipsRect *area )
{ {
return( (Tile *) g_hash_table_lookup( render->tiles, area ) ); return( (Tile *) g_hash_table_lookup( render->tiles, area ) );
} }
@ -688,7 +688,7 @@ render_tile_lookup( Render *render, Rect *area )
/* Add a new tile to the table. /* Add a new tile to the table.
*/ */
static void static void
render_tile_add( Tile *tile, Rect *area ) render_tile_add( Tile *tile, VipsRect *area )
{ {
Render *render = tile->render; Render *render = tile->render;
@ -710,7 +710,7 @@ render_tile_add( Tile *tile, Rect *area )
/* Move a tile to a new position. /* Move a tile to a new position.
*/ */
static void static void
render_tile_move( Tile *tile, Rect *area ) render_tile_move( Tile *tile, VipsRect *area )
{ {
Render *render = tile->render; Render *render = tile->render;
@ -784,7 +784,7 @@ tile_queue( Tile *tile, VipsRegion *reg )
} }
static void static void
tile_test_clean_ticks( Rect *key, Tile *value, Tile **best ) tile_test_clean_ticks( VipsRect *key, Tile *value, Tile **best )
{ {
if( value->painted ) if( value->painted )
if( !*best || value->ticks < (*best)->ticks ) if( !*best || value->ticks < (*best)->ticks )
@ -814,7 +814,7 @@ render_tile_get_painted( Render *render )
* or if we've no threads or no notify, calculate immediately. * or if we've no threads or no notify, calculate immediately.
*/ */
static Tile * static Tile *
render_tile_request( Render *render, VipsRegion *reg, Rect *area ) render_tile_request( Render *render, VipsRegion *reg, VipsRect *area )
{ {
Tile *tile; Tile *tile;
@ -866,13 +866,13 @@ render_tile_request( Render *render, VipsRegion *reg, Rect *area )
static void static void
tile_copy( Tile *tile, VipsRegion *to ) tile_copy( Tile *tile, VipsRegion *to )
{ {
Rect ovlap; VipsRect ovlap;
int y; int y;
/* Find common pixels. /* Find common pixels.
*/ */
im_rect_intersectrect( &tile->area, &to->valid, &ovlap ); vips_rect_intersectrect( &tile->area, &to->valid, &ovlap );
g_assert( !im_rect_isempty( &ovlap ) ); g_assert( !vips_rect_isempty( &ovlap ) );
/* If the tile is painted, copy over the pixels. Otherwise, fill with /* If the tile is painted, copy over the pixels. Otherwise, fill with
* zero. * zero.
@ -884,7 +884,7 @@ tile_copy( Tile *tile, VipsRegion *to )
"copying calculated pixels for %p %dx%d\n", "copying calculated pixels for %p %dx%d\n",
tile, tile->area.left, tile->area.top ); tile, tile->area.left, tile->area.top );
for( y = ovlap.top; y < IM_RECT_BOTTOM( &ovlap ); y++ ) { for( y = ovlap.top; y < VIPS_RECT_BOTTOM( &ovlap ); y++ ) {
PEL *p = (PEL *) VIPS_REGION_ADDR( tile->region, PEL *p = (PEL *) VIPS_REGION_ADDR( tile->region,
ovlap.left, y ); ovlap.left, y );
PEL *q = (PEL *) VIPS_REGION_ADDR( to, ovlap.left, y ); PEL *q = (PEL *) VIPS_REGION_ADDR( to, ovlap.left, y );
@ -914,7 +914,7 @@ image_fill( VipsRegion *out, void *seq, void *a, void *b )
{ {
Render *render = (Render *) a; Render *render = (Render *) a;
VipsRegion *reg = (VipsRegion *) seq; VipsRegion *reg = (VipsRegion *) seq;
Rect *r = &out->valid; VipsRect *r = &out->valid;
int x, y; int x, y;
/* Find top left of tiles we need. /* Find top left of tiles we need.
@ -935,9 +935,9 @@ image_fill( VipsRegion *out, void *seq, void *a, void *b )
*/ */
for( y = ys; y < IM_RECT_BOTTOM( r ); y += render->tile_height ) for( y = ys; y < VIPS_RECT_BOTTOM( r ); y += render->tile_height )
for( x = xs; x < IM_RECT_RIGHT( r ); x += render->tile_width ) { for( x = xs; x < VIPS_RECT_RIGHT( r ); x += render->tile_width ) {
Rect area; VipsRect area;
Tile *tile; Tile *tile;
area.left = x; area.left = x;
@ -974,7 +974,7 @@ mask_fill( VipsRegion *out, void *seq, void *a, void *b )
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
Render *render = (Render *) a; Render *render = (Render *) a;
Rect *r = &out->valid; VipsRect *r = &out->valid;
int x, y; int x, y;
/* Find top left of tiles we need. /* Find top left of tiles we need.
@ -988,9 +988,9 @@ mask_fill( VipsRegion *out, void *seq, void *a, void *b )
g_mutex_lock( render->lock ); g_mutex_lock( render->lock );
for( y = ys; y < IM_RECT_BOTTOM( r ); y += render->tile_height ) for( y = ys; y < VIPS_RECT_BOTTOM( r ); y += render->tile_height )
for( x = xs; x < IM_RECT_RIGHT( r ); x += render->tile_width ) { for( x = xs; x < VIPS_RECT_RIGHT( r ); x += render->tile_width ) {
Rect area; VipsRect area;
Tile *tile; Tile *tile;
int value; int value;
@ -1047,8 +1047,8 @@ mask_fill( VipsRegion *out, void *seq, void *a, void *b )
* *
* Calls to vips_region_prepare() on @out return immediately and hold * Calls to vips_region_prepare() on @out return immediately and hold
* whatever is * whatever is
* currently in cache for that #Rect (check @mask to see which parts of the * currently in cache for that #VipsRect (check @mask to see which parts of the
* #Rect are valid). Any pixels in the #Rect which are not in cache are added * #VipsRect are valid). Any pixels in the #VipsRect which are not in cache are added
* to a queue, and the @notify callback will trigger when those pixels are * to a queue, and the @notify callback will trigger when those pixels are
* ready. * ready.
* *