parent
2abb0f8d99
commit
cfe34cacd2
|
@ -32,16 +32,33 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef VIPS_REGION_H
|
#ifndef IM_REGION_H
|
||||||
#define VIPS_REGION_H
|
#define IM_REGION_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
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 _VipsRegion {
|
typedef struct _VipsRegion {
|
||||||
|
VipsObject parent_object;
|
||||||
|
|
||||||
/*< public >*/
|
/*< public >*/
|
||||||
/* Users may read these two fields.
|
/* Users may read these two fields.
|
||||||
*/
|
*/
|
||||||
|
@ -75,9 +92,14 @@ typedef struct _VipsRegion {
|
||||||
gboolean invalid;
|
gboolean invalid;
|
||||||
} VipsRegion;
|
} VipsRegion;
|
||||||
|
|
||||||
void vips_region_free( VipsRegion *region );
|
typedef struct _VipsRegionClass {
|
||||||
|
VipsObjectClass parent_class;
|
||||||
|
|
||||||
|
} VipsRegionClass;
|
||||||
|
|
||||||
|
GType vips_region_get_type( void );
|
||||||
|
|
||||||
VipsRegion *vips_region_new( VipsImage *im );
|
VipsRegion *vips_region_new( VipsImage *im );
|
||||||
void vips_region_print( VipsRegion *region, VipsBuf *buf );
|
|
||||||
|
|
||||||
int vips_region_buffer( VipsRegion *reg, Rect *r );
|
int vips_region_buffer( VipsRegion *reg, Rect *r );
|
||||||
int vips_region_image( VipsRegion *reg, Rect *r );
|
int vips_region_image( VipsRegion *reg, Rect *r );
|
||||||
|
@ -142,4 +164,4 @@ int vips_region_prepare_many( VipsRegion **reg, Rect *r );
|
||||||
}
|
}
|
||||||
#endif /*__cplusplus*/
|
#endif /*__cplusplus*/
|
||||||
|
|
||||||
#endif /*VIPS_REGION_H*/
|
#endif /*IM_REGION_H*/
|
||||||
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
/* Definitions for partial image regions.
|
||||||
|
*
|
||||||
|
* J.Cupitt, 8/4/93
|
||||||
|
*
|
||||||
|
* 2/3/11
|
||||||
|
* - move to GObject
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
This file is part of VIPS.
|
||||||
|
|
||||||
|
VIPS is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VIPS_REGION_H
|
||||||
|
#define VIPS_REGION_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /*__cplusplus*/
|
||||||
|
|
||||||
|
/* Sub-area of image.
|
||||||
|
*/
|
||||||
|
typedef struct _VipsRegion {
|
||||||
|
/*< public >*/
|
||||||
|
/* Users may read these two fields.
|
||||||
|
*/
|
||||||
|
VipsImage *im; /* Link back to parent image */
|
||||||
|
Rect valid; /* Area of parent we can see */
|
||||||
|
|
||||||
|
/* The rest of REGION is private.
|
||||||
|
*/
|
||||||
|
/*< private >*/
|
||||||
|
RegionType type; /* What kind of attachment */
|
||||||
|
char *data; /* Off here to get data */
|
||||||
|
int bpl; /* Bytes-per-line for data */
|
||||||
|
void *seq; /* Sequence we are using to fill region */
|
||||||
|
|
||||||
|
/* The thread that made this region. Used to assert() test that
|
||||||
|
* regions are not being shared between threads.
|
||||||
|
*/
|
||||||
|
GThread *thread;
|
||||||
|
|
||||||
|
/* Ref to the window we use for this region, if any.
|
||||||
|
*/
|
||||||
|
im_window_t *window;
|
||||||
|
|
||||||
|
/* Ref to the buffer we use for this region, if any.
|
||||||
|
*/
|
||||||
|
im_buffer_t *buffer;
|
||||||
|
|
||||||
|
/* The image this region is on has changed and caches need to be
|
||||||
|
* dropped.
|
||||||
|
*/
|
||||||
|
gboolean invalid;
|
||||||
|
} VipsRegion;
|
||||||
|
|
||||||
|
void vips_region_free( VipsRegion *region );
|
||||||
|
VipsRegion *vips_region_new( VipsImage *im );
|
||||||
|
void vips_region_print( VipsRegion *region, VipsBuf *buf );
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
int vips_region_prepare( VipsRegion *reg, Rect *r );
|
||||||
|
int vips_region_prepare_to( VipsRegion *reg,
|
||||||
|
VipsRegion *dest, Rect *r, int x, int y );
|
||||||
|
int vips_region_prepare_many( VipsRegion **reg, Rect *r );
|
||||||
|
|
||||||
|
/* Macros on REGIONs.
|
||||||
|
* VIPS_REGION_LSKIP() add to move down line
|
||||||
|
* VIPS_REGION_N_ELEMENTS() number of elements across region
|
||||||
|
* VIPS_REGION_SIZEOF_LINE() sizeof width of region
|
||||||
|
* VIPS_REGION_ADDR() address of pixel in region
|
||||||
|
*/
|
||||||
|
#define VIPS_REGION_LSKIP( R ) \
|
||||||
|
((size_t)((R)->bpl))
|
||||||
|
#define VIPS_REGION_N_ELEMENTS( R ) \
|
||||||
|
((size_t)((R)->valid.width * (R)->im->Bands))
|
||||||
|
#define VIPS_REGION_SIZEOF_LINE( R ) \
|
||||||
|
((size_t)((R)->valid.width * VIPS_IMAGE_SIZEOF_PEL( (R)->im) ))
|
||||||
|
|
||||||
|
/* If DEBUG is defined, add bounds checking.
|
||||||
|
*/
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define VIPS_REGION_ADDR( R, X, Y ) \
|
||||||
|
( (im_rect_includespoint( &(R)->valid, (X), (Y) ))? \
|
||||||
|
((R)->data + ((Y) - (R)->valid.top) * VIPS_REGION_LSKIP(R) + \
|
||||||
|
((X) - (R)->valid.left) * VIPS_IMAGE_SIZEOF_PEL((R)->im)): \
|
||||||
|
(fprintf( stderr, \
|
||||||
|
"VIPS_REGION_ADDR: point out of bounds, " \
|
||||||
|
"file \"%s\", line %d\n" \
|
||||||
|
"(point x=%d, y=%d\n" \
|
||||||
|
" should have been within Rect left=%d, top=%d, " \
|
||||||
|
"width=%d, height=%d)\n", \
|
||||||
|
__FILE__, __LINE__, \
|
||||||
|
(X), (Y), \
|
||||||
|
(R)->valid.left, \
|
||||||
|
(R)->valid.top, \
|
||||||
|
(R)->valid.width, \
|
||||||
|
(R)->valid.height ), abort(), (char *) NULL) \
|
||||||
|
)
|
||||||
|
#else /*DEBUG*/
|
||||||
|
#define VIPS_REGION_ADDR( R, X, Y ) \
|
||||||
|
((R)->data + \
|
||||||
|
((Y)-(R)->valid.top) * VIPS_REGION_LSKIP( R ) + \
|
||||||
|
((X)-(R)->valid.left) * VIPS_IMAGE_SIZEOF_PEL( (R)->im ))
|
||||||
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
|
#define VIPS_REGION_ADDR_TOPLEFT( R ) ((R)->data)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /*__cplusplus*/
|
||||||
|
|
||||||
|
#endif /*VIPS_REGION_H*/
|
|
@ -0,0 +1,167 @@
|
||||||
|
/* Definitions for partial image regions.
|
||||||
|
*
|
||||||
|
* J.Cupitt, 8/4/93
|
||||||
|
*
|
||||||
|
* 2/3/11
|
||||||
|
* - move to GObject
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
This file is part of VIPS.
|
||||||
|
|
||||||
|
VIPS is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef IM_REGION_H
|
||||||
|
#define IM_REGION_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#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.
|
||||||
|
*/
|
||||||
|
typedef struct _VipsRegion {
|
||||||
|
VipsObject parent_object;
|
||||||
|
|
||||||
|
/*< public >*/
|
||||||
|
/* Users may read these two fields.
|
||||||
|
*/
|
||||||
|
VipsImage *im; /* Link back to parent image */
|
||||||
|
Rect valid; /* Area of parent we can see */
|
||||||
|
|
||||||
|
/* The rest of REGION is private.
|
||||||
|
*/
|
||||||
|
/*< private >*/
|
||||||
|
RegionType type; /* What kind of attachment */
|
||||||
|
char *data; /* Off here to get data */
|
||||||
|
int bpl; /* Bytes-per-line for data */
|
||||||
|
void *seq; /* Sequence we are using to fill region */
|
||||||
|
|
||||||
|
/* The thread that made this region. Used to assert() test that
|
||||||
|
* regions are not being shared between threads.
|
||||||
|
*/
|
||||||
|
GThread *thread;
|
||||||
|
|
||||||
|
/* Ref to the window we use for this region, if any.
|
||||||
|
*/
|
||||||
|
im_window_t *window;
|
||||||
|
|
||||||
|
/* Ref to the buffer we use for this region, if any.
|
||||||
|
*/
|
||||||
|
im_buffer_t *buffer;
|
||||||
|
|
||||||
|
/* The image this region is on has changed and caches need to be
|
||||||
|
* dropped.
|
||||||
|
*/
|
||||||
|
gboolean invalid;
|
||||||
|
} VipsRegion;
|
||||||
|
|
||||||
|
typedef struct _VipsRegionClass {
|
||||||
|
VipsObjectClass parent_class;
|
||||||
|
|
||||||
|
} VipsRegionClass;
|
||||||
|
|
||||||
|
GType vips_region_get_type( void );
|
||||||
|
|
||||||
|
VipsRegion *vips_region_new( VipsImage *im );
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
int vips_region_prepare( VipsRegion *reg, Rect *r );
|
||||||
|
int vips_region_prepare_to( VipsRegion *reg,
|
||||||
|
VipsRegion *dest, Rect *r, int x, int y );
|
||||||
|
int vips_region_prepare_many( VipsRegion **reg, Rect *r );
|
||||||
|
|
||||||
|
/* Macros on REGIONs.
|
||||||
|
* VIPS_REGION_LSKIP() add to move down line
|
||||||
|
* VIPS_REGION_N_ELEMENTS() number of elements across region
|
||||||
|
* VIPS_REGION_SIZEOF_LINE() sizeof width of region
|
||||||
|
* VIPS_REGION_ADDR() address of pixel in region
|
||||||
|
*/
|
||||||
|
#define VIPS_REGION_LSKIP( R ) \
|
||||||
|
((size_t)((R)->bpl))
|
||||||
|
#define VIPS_REGION_N_ELEMENTS( R ) \
|
||||||
|
((size_t)((R)->valid.width * (R)->im->Bands))
|
||||||
|
#define VIPS_REGION_SIZEOF_LINE( R ) \
|
||||||
|
((size_t)((R)->valid.width * VIPS_IMAGE_SIZEOF_PEL( (R)->im) ))
|
||||||
|
|
||||||
|
/* If DEBUG is defined, add bounds checking.
|
||||||
|
*/
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define VIPS_REGION_ADDR( R, X, Y ) \
|
||||||
|
( (im_rect_includespoint( &(R)->valid, (X), (Y) ))? \
|
||||||
|
((R)->data + ((Y) - (R)->valid.top) * VIPS_REGION_LSKIP(R) + \
|
||||||
|
((X) - (R)->valid.left) * VIPS_IMAGE_SIZEOF_PEL((R)->im)): \
|
||||||
|
(fprintf( stderr, \
|
||||||
|
"VIPS_REGION_ADDR: point out of bounds, " \
|
||||||
|
"file \"%s\", line %d\n" \
|
||||||
|
"(point x=%d, y=%d\n" \
|
||||||
|
" should have been within Rect left=%d, top=%d, " \
|
||||||
|
"width=%d, height=%d)\n", \
|
||||||
|
__FILE__, __LINE__, \
|
||||||
|
(X), (Y), \
|
||||||
|
(R)->valid.left, \
|
||||||
|
(R)->valid.top, \
|
||||||
|
(R)->valid.width, \
|
||||||
|
(R)->valid.height ), abort(), (char *) NULL) \
|
||||||
|
)
|
||||||
|
#else /*DEBUG*/
|
||||||
|
#define VIPS_REGION_ADDR( R, X, Y ) \
|
||||||
|
((R)->data + \
|
||||||
|
((Y)-(R)->valid.top) * VIPS_REGION_LSKIP( R ) + \
|
||||||
|
((X)-(R)->valid.left) * VIPS_IMAGE_SIZEOF_PEL( (R)->im ))
|
||||||
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
|
#define VIPS_REGION_ADDR_TOPLEFT( R ) ((R)->data)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /*__cplusplus*/
|
||||||
|
|
||||||
|
#endif /*IM_REGION_H*/
|
|
@ -180,7 +180,7 @@ extern "C" {
|
||||||
#define im_prepare vips_region_prepare
|
#define im_prepare vips_region_prepare
|
||||||
#define im_prepare_to vips_region_prepare_to
|
#define im_prepare_to vips_region_prepare_to
|
||||||
#define im_region_create vips_region_new
|
#define im_region_create vips_region_new
|
||||||
#define im_region_free vips_region_free
|
#define im_region_free g_object_unref
|
||||||
#define im_region_region vips_region_region
|
#define im_region_region vips_region_region
|
||||||
#define im_region_buffer vips_region_buffer
|
#define im_region_buffer vips_region_buffer
|
||||||
#define im_region_black vips_region_black
|
#define im_region_black vips_region_black
|
||||||
|
|
|
@ -149,7 +149,7 @@ im_stop_one( void *seq, void *a, void *b )
|
||||||
{
|
{
|
||||||
VipsRegion *reg = (VipsRegion *) seq;
|
VipsRegion *reg = (VipsRegion *) seq;
|
||||||
|
|
||||||
vips_region_free( reg );
|
g_object_unref( reg );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ im_stop_many( void *seq, void *a, void *b )
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i = 0; ar[i]; i++ )
|
for( i = 0; ar[i]; i++ )
|
||||||
vips_region_free( ar[i] );
|
g_object_unref( ar[i] );
|
||||||
im_free( (char *) ar );
|
im_free( (char *) ar );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -979,7 +979,7 @@ build_args( im_function *fn, im_object *vargv, int argc, char **argv )
|
||||||
static void
|
static void
|
||||||
region_local_image_cb( VipsImage *main, VipsRegion *reg )
|
region_local_image_cb( VipsImage *main, VipsRegion *reg )
|
||||||
{
|
{
|
||||||
vips_region_free( reg );
|
g_object_unref( reg );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a region on sub, closed by callback on main.
|
/* Make a region on sub, closed by callback on main.
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
/* A version of VipsRegion which ran on top of vipsobject ... sadly we had
|
||||||
|
* many mysterious segvs argh
|
||||||
|
*
|
||||||
|
* keep this code around for testing and reference
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Make and destroy partial image regions.
|
/* Make and destroy partial image regions.
|
||||||
*
|
*
|
||||||
* J.Cupitt, 8/4/93.
|
* J.Cupitt, 8/4/93.
|
||||||
|
@ -74,7 +82,6 @@
|
||||||
#define DEBUG_ENVIRONMENT 1
|
#define DEBUG_ENVIRONMENT 1
|
||||||
#define DEBUG_CREATE
|
#define DEBUG_CREATE
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
#define DEBUG_VIPS
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
@ -179,12 +186,25 @@
|
||||||
* Returns: The address of the top-left pixel in the region.
|
* Returns: The address of the top-left pixel in the region.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef DEBUG
|
/* Properties.
|
||||||
/* Track all regions here for debugging.
|
|
||||||
*/
|
*/
|
||||||
static GSList *vips__region_all = NULL;
|
enum {
|
||||||
#endif /*DEBUG*/
|
PROP_IMAGE = 1,
|
||||||
|
PROP_LAST
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE( VipsRegion, vips_region, VIPS_TYPE_OBJECT );
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_region_finalize( GObject *gobject )
|
||||||
|
{
|
||||||
|
#ifdef VIPS_DEBUG
|
||||||
|
VIPS_DEBUG_MSG( "vips_region_finalize: " );
|
||||||
|
vips_object_print( VIPS_OBJECT( gobject ) );
|
||||||
|
#endif /*VIPS_DEBUG*/
|
||||||
|
|
||||||
|
G_OBJECT_CLASS( vips_region_parent_class )->finalize( gobject );
|
||||||
|
}
|
||||||
|
|
||||||
/* Call a start function if no sequence is running on this VipsRegion.
|
/* Call a start function if no sequence is running on this VipsRegion.
|
||||||
*/
|
*/
|
||||||
|
@ -251,14 +271,18 @@ vips_region_reset( VipsRegion *region )
|
||||||
region->invalid = FALSE;
|
region->invalid = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
vips_region_free( VipsRegion *region )
|
vips_region_dispose( GObject *gobject )
|
||||||
{
|
{
|
||||||
|
VipsRegion *region = VIPS_REGION( gobject );
|
||||||
VipsImage *image = region->im;
|
VipsImage *image = region->im;
|
||||||
|
|
||||||
g_assert( image );
|
#ifdef VIPS_DEBUG
|
||||||
|
VIPS_DEBUG_MSG( "vips_region_dispose: " );
|
||||||
|
vips_object_print( VIPS_OBJECT( gobject ) );
|
||||||
|
#endif /*VIPS_DEBUG*/
|
||||||
|
|
||||||
VIPS_DEBUG_MSG( "vips_region_free: %p\n", region );
|
vips_object_preclose( VIPS_OBJECT( gobject ) );
|
||||||
|
|
||||||
/* Stop this sequence.
|
/* Stop this sequence.
|
||||||
*/
|
*/
|
||||||
|
@ -274,23 +298,16 @@ vips_region_free( VipsRegion *region )
|
||||||
image->regions = g_slist_remove( image->regions, region );
|
image->regions = g_slist_remove( image->regions, region );
|
||||||
g_mutex_unlock( image->sslock );
|
g_mutex_unlock( image->sslock );
|
||||||
region->im = NULL;
|
region->im = NULL;
|
||||||
|
|
||||||
g_object_unref( image );
|
g_object_unref( image );
|
||||||
|
|
||||||
im_free( region );
|
G_OBJECT_CLASS( vips_region_parent_class )->dispose( gobject );
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
g_mutex_lock( vips__global_lock );
|
|
||||||
g_assert( g_slist_find( vips__region_all, region ) );
|
|
||||||
vips__region_all = g_slist_remove( vips__region_all, region );
|
|
||||||
printf( "%d regions in vips\n", g_slist_length( vips__region_all ) );
|
|
||||||
g_mutex_unlock( vips__global_lock );
|
|
||||||
#endif /*DEBUG*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
vips_region_print( VipsRegion *region, VipsBuf *buf )
|
vips_region_print( VipsObject *object, VipsBuf *buf )
|
||||||
{
|
{
|
||||||
|
VipsRegion *region = VIPS_REGION( object );
|
||||||
|
|
||||||
vips_buf_appendf( buf, "VipsRegion: %p, ", region );
|
vips_buf_appendf( buf, "VipsRegion: %p, ", region );
|
||||||
vips_buf_appendf( buf, "im = %p, ", region->im );
|
vips_buf_appendf( buf, "im = %p, ", region->im );
|
||||||
vips_buf_appendf( buf, "valid.left = %d, ", region->valid.left );
|
vips_buf_appendf( buf, "valid.left = %d, ", region->valid.left );
|
||||||
|
@ -305,6 +322,8 @@ vips_region_print( VipsRegion *region, VipsBuf *buf )
|
||||||
vips_buf_appendf( buf, "window = %p, ", region->window );
|
vips_buf_appendf( buf, "window = %p, ", region->window );
|
||||||
vips_buf_appendf( buf, "buffer = %p\n", region->buffer );
|
vips_buf_appendf( buf, "buffer = %p\n", region->buffer );
|
||||||
vips_buf_appendf( buf, "invalid = %d\n", region->invalid );
|
vips_buf_appendf( buf, "invalid = %d\n", region->invalid );
|
||||||
|
|
||||||
|
VIPS_OBJECT_CLASS( vips_region_parent_class )->print( object, buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If a region is being created in one thread (eg. the main thread) and then
|
/* If a region is being created in one thread (eg. the main thread) and then
|
||||||
|
@ -364,38 +383,16 @@ vips__region_no_ownership( VipsRegion *region )
|
||||||
g_mutex_unlock( region->im->sslock );
|
g_mutex_unlock( region->im->sslock );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int
|
||||||
* vips_region_new:
|
vips_region_build( VipsObject *object )
|
||||||
* @image: image to create this region on
|
|
||||||
*
|
|
||||||
* Create a region. #VipsRegion s start out empty, you need to call
|
|
||||||
* vips_region_prepare() to fill them with pixels.
|
|
||||||
*
|
|
||||||
* See also: vips_region_free(), vips_region_prepare().
|
|
||||||
*/
|
|
||||||
VipsRegion *
|
|
||||||
vips_region_new( VipsImage *image )
|
|
||||||
{
|
{
|
||||||
VipsRegion *region;
|
VipsRegion *region = VIPS_REGION( object );
|
||||||
|
VipsImage *image = region->im;
|
||||||
|
|
||||||
if( !(region = VIPS_NEW( NULL, VipsRegion )) )
|
VIPS_DEBUG_MSG( "vips_region_build: %p\n", region );
|
||||||
return( NULL );
|
|
||||||
VIPS_DEBUG_MSG( "vips_region_new: %p\n", region );
|
|
||||||
|
|
||||||
region->im = image;
|
if( VIPS_OBJECT_CLASS( vips_region_parent_class )->build( object ) )
|
||||||
g_object_ref( image );
|
return( -1 );
|
||||||
region->type = VIPS_REGION_NONE;
|
|
||||||
region->valid.left = 0;
|
|
||||||
region->valid.top = 0;
|
|
||||||
region->valid.width = 0;
|
|
||||||
region->valid.height = 0;
|
|
||||||
region->data = NULL;
|
|
||||||
region->bpl = 0;
|
|
||||||
region->seq = NULL;
|
|
||||||
region->thread = NULL;
|
|
||||||
region->window = NULL;
|
|
||||||
region->buffer = NULL;
|
|
||||||
region->invalid = FALSE;
|
|
||||||
|
|
||||||
vips__region_take_ownership( region );
|
vips__region_take_ownership( region );
|
||||||
|
|
||||||
|
@ -405,14 +402,55 @@ vips_region_new( VipsImage *image )
|
||||||
image->regions = g_slist_prepend( image->regions, region );
|
image->regions = g_slist_prepend( image->regions, region );
|
||||||
g_mutex_unlock( image->sslock );
|
g_mutex_unlock( image->sslock );
|
||||||
|
|
||||||
#ifdef DEBUG
|
return( 0 );
|
||||||
g_mutex_lock( vips__global_lock );
|
}
|
||||||
vips__region_all = g_slist_prepend( vips__region_all, region );
|
|
||||||
printf( "%d regions in vips\n", g_slist_length( vips__region_all ) );
|
|
||||||
g_mutex_unlock( vips__global_lock );
|
|
||||||
#endif /*DEBUG*/
|
|
||||||
|
|
||||||
return( region );
|
static void
|
||||||
|
vips_region_class_init( VipsRegionClass *class )
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||||
|
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
|
||||||
|
|
||||||
|
gobject_class->finalize = vips_region_finalize;
|
||||||
|
gobject_class->dispose = vips_region_dispose;
|
||||||
|
|
||||||
|
vobject_class->print = vips_region_print;
|
||||||
|
vobject_class->build = vips_region_build;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_region_init( VipsRegion *region )
|
||||||
|
{
|
||||||
|
region->type = VIPS_REGION_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vips_region_new:
|
||||||
|
* @image: image to create this region on
|
||||||
|
*
|
||||||
|
* Create a region. #VipsRegion s start out empty, you need to call
|
||||||
|
* vips_region_prepare() to fill them with pixels.
|
||||||
|
*
|
||||||
|
* See also: vips_region_prepare().
|
||||||
|
*/
|
||||||
|
VipsRegion *
|
||||||
|
vips_region_new( VipsImage *image )
|
||||||
|
{
|
||||||
|
VipsRegion *region;
|
||||||
|
|
||||||
|
region = VIPS_REGION( g_object_new( VIPS_TYPE_REGION, NULL ) );
|
||||||
|
|
||||||
|
/* We can't use the property system, we need to be very threaded.
|
||||||
|
*/
|
||||||
|
region->im = image;
|
||||||
|
g_object_ref( image );
|
||||||
|
|
||||||
|
if( vips_object_build( VIPS_OBJECT( region ) ) ) {
|
||||||
|
VIPS_UNREF( region );
|
||||||
|
return( NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( region );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Region should be a pixel buffer. On return, check
|
/* Region should be a pixel buffer. On return, check
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -131,7 +131,7 @@ sink_thread_state_dispose( GObject *gobject )
|
||||||
Sink *sink = (Sink *) ((VipsThreadState *) state)->a;
|
Sink *sink = (Sink *) ((VipsThreadState *) state)->a;
|
||||||
|
|
||||||
sink_call_stop( sink, state );
|
sink_call_stop( sink, state );
|
||||||
VIPS_FREEF( vips_region_free, state->reg );
|
VIPS_UNREF( state->reg );
|
||||||
|
|
||||||
G_OBJECT_CLASS( sink_thread_state_parent_class )->dispose( gobject );
|
G_OBJECT_CLASS( sink_thread_state_parent_class )->dispose( gobject );
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ wbuffer_free( WriteBuffer *wbuffer )
|
||||||
wbuffer->thread = NULL;
|
wbuffer->thread = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIPS_FREEF( vips_region_free, wbuffer->region );
|
VIPS_UNREF( wbuffer->region );
|
||||||
im_semaphore_destroy( &wbuffer->go );
|
im_semaphore_destroy( &wbuffer->go );
|
||||||
im_semaphore_destroy( &wbuffer->nwrite );
|
im_semaphore_destroy( &wbuffer->nwrite );
|
||||||
im_semaphore_destroy( &wbuffer->done );
|
im_semaphore_destroy( &wbuffer->done );
|
||||||
|
|
|
@ -75,7 +75,7 @@ typedef struct _Sink {
|
||||||
static void
|
static void
|
||||||
sink_free( Sink *sink )
|
sink_free( Sink *sink )
|
||||||
{
|
{
|
||||||
VIPS_FREEF( vips_region_free, sink->all );
|
VIPS_UNREF( sink->all );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -208,7 +208,7 @@ tile_free( Tile *tile )
|
||||||
{
|
{
|
||||||
VIPS_DEBUG_MSG_AMBER( "tile_free\n" );
|
VIPS_DEBUG_MSG_AMBER( "tile_free\n" );
|
||||||
|
|
||||||
VIPS_FREEF( vips_region_free, tile->region );
|
VIPS_UNREF( tile->region );
|
||||||
im_free( tile );
|
im_free( tile );
|
||||||
|
|
||||||
return( NULL );
|
return( NULL );
|
||||||
|
@ -962,7 +962,7 @@ image_stop( void *seq, void *a, void *b )
|
||||||
{
|
{
|
||||||
VipsRegion *reg = (VipsRegion *) seq;
|
VipsRegion *reg = (VipsRegion *) seq;
|
||||||
|
|
||||||
vips_region_free( reg );
|
g_object_unref( reg );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,7 +255,7 @@ vips_thread_state_dispose( GObject *gobject )
|
||||||
|
|
||||||
VIPS_DEBUG_MSG( "vips_thread_state_dispose:\n" );
|
VIPS_DEBUG_MSG( "vips_thread_state_dispose:\n" );
|
||||||
|
|
||||||
VIPS_FREEF( vips_region_free, state->reg );
|
VIPS_UNREF( state->reg );
|
||||||
|
|
||||||
G_OBJECT_CLASS( vips_thread_state_parent_class )->dispose( gobject );
|
G_OBJECT_CLASS( vips_thread_state_parent_class )->dispose( gobject );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue