2009-08-16 17:00:08 +02:00
|
|
|
/* Definitions for partial image regions.
|
|
|
|
*
|
|
|
|
* J.Cupitt, 8/4/93
|
2011-03-02 22:53:32 +01:00
|
|
|
*
|
|
|
|
* 2/3/11
|
|
|
|
* - move to GObject
|
2009-08-16 17:00:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
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
|
2013-03-07 06:40:19 +01:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301 USA
|
2009-08-16 17:00:08 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-03-28 18:18:06 +02:00
|
|
|
#ifndef VIPS_REGION_H
|
|
|
|
#define VIPS_REGION_H
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2022-02-15 06:02:07 +01:00
|
|
|
#include <glib.h>
|
|
|
|
#include <glib-object.h>
|
|
|
|
#include <vips/object.h>
|
|
|
|
#include <vips/image.h>
|
|
|
|
#include <vips/rect.h>
|
|
|
|
#include <vips/private.h>
|
|
|
|
|
2009-08-16 17:00:08 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /*__cplusplus*/
|
|
|
|
|
2011-03-16 19:26:32 +01:00
|
|
|
#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 ))
|
|
|
|
|
2018-03-27 22:35:49 +02:00
|
|
|
/**
|
|
|
|
* VipsRegionShrink:
|
|
|
|
* @VIPS_REGION_SHRINK_MEAN: use the average
|
|
|
|
* @VIPS_REGION_SHRINK_MEDIAN: use the median
|
2018-03-28 12:59:17 +02:00
|
|
|
* @VIPS_REGION_SHRINK_MODE: use the mode
|
2020-01-24 18:55:11 +01:00
|
|
|
* @VIPS_REGION_SHRINK_MAX: use the maximum
|
|
|
|
* @VIPS_REGION_SHRINK_MIN: use the minimum
|
2020-01-30 17:53:18 +01:00
|
|
|
* @VIPS_REGION_SHRINK_NEAREST: use the top-left pixel
|
2018-03-27 22:35:49 +02:00
|
|
|
*
|
|
|
|
* How to calculate the output pixels when shrinking a 2x2 region.
|
|
|
|
*/
|
2018-03-27 12:15:48 +02:00
|
|
|
typedef enum {
|
|
|
|
VIPS_REGION_SHRINK_MEAN,
|
|
|
|
VIPS_REGION_SHRINK_MEDIAN,
|
2018-03-28 12:59:17 +02:00
|
|
|
VIPS_REGION_SHRINK_MODE,
|
2020-01-24 18:55:11 +01:00
|
|
|
VIPS_REGION_SHRINK_MAX,
|
|
|
|
VIPS_REGION_SHRINK_MIN,
|
2020-01-30 17:53:18 +01:00
|
|
|
VIPS_REGION_SHRINK_NEAREST,
|
2018-03-27 12:15:48 +02:00
|
|
|
VIPS_REGION_SHRINK_LAST
|
|
|
|
} VipsRegionShrink;
|
|
|
|
|
2009-08-16 17:00:08 +02:00
|
|
|
/* Sub-area of image.
|
2020-08-13 13:51:56 +02:00
|
|
|
*
|
|
|
|
* Matching typedef in basic.h.
|
2009-08-16 17:00:08 +02:00
|
|
|
*/
|
2020-08-13 13:51:56 +02:00
|
|
|
struct _VipsRegion {
|
2011-03-16 19:26:32 +01:00
|
|
|
VipsObject parent_object;
|
|
|
|
|
2009-10-07 15:03:46 +02:00
|
|
|
/*< public >*/
|
2009-08-16 17:00:08 +02:00
|
|
|
/* Users may read these two fields.
|
|
|
|
*/
|
2011-03-10 10:41:45 +01:00
|
|
|
VipsImage *im; /* Link back to parent image */
|
2011-03-17 14:05:46 +01:00
|
|
|
VipsRect valid; /* Area of parent we can see */
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2011-03-28 18:18:06 +02:00
|
|
|
/* The rest of VipsRegion is private.
|
2009-08-16 17:00:08 +02:00
|
|
|
*/
|
2009-10-07 15:03:46 +02:00
|
|
|
/*< private >*/
|
2009-08-16 17:00:08 +02:00
|
|
|
RegionType type; /* What kind of attachment */
|
2011-12-31 19:22:42 +01:00
|
|
|
VipsPel *data; /* Off here to get data */
|
2009-08-16 17:00:08 +02:00
|
|
|
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.
|
|
|
|
*/
|
2011-03-25 15:01:12 +01:00
|
|
|
VipsWindow *window;
|
2009-08-16 17:00:08 +02:00
|
|
|
|
|
|
|
/* Ref to the buffer we use for this region, if any.
|
|
|
|
*/
|
2011-03-25 15:01:12 +01:00
|
|
|
VipsBuffer *buffer;
|
2010-03-05 15:43:49 +01:00
|
|
|
|
|
|
|
/* The image this region is on has changed and caches need to be
|
|
|
|
* dropped.
|
|
|
|
*/
|
|
|
|
gboolean invalid;
|
2020-08-13 13:51:56 +02:00
|
|
|
};
|
2011-03-02 22:53:32 +01:00
|
|
|
|
2011-03-16 19:26:32 +01:00
|
|
|
typedef struct _VipsRegionClass {
|
|
|
|
VipsObjectClass parent_class;
|
|
|
|
|
|
|
|
} VipsRegionClass;
|
|
|
|
|
2016-07-13 23:39:16 +02:00
|
|
|
/* Don't put spaces around void here, it breaks gtk-doc.
|
|
|
|
*/
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2016-07-13 23:39:16 +02:00
|
|
|
GType vips_region_get_type(void);
|
2011-03-16 19:26:32 +01:00
|
|
|
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2011-06-21 23:37:53 +02:00
|
|
|
VipsRegion *vips_region_new( VipsImage *image );
|
2009-10-07 15:03:46 +02:00
|
|
|
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2017-11-17 17:30:25 +01:00
|
|
|
int vips_region_buffer( VipsRegion *reg, const VipsRect *r );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2017-11-17 17:30:25 +01:00
|
|
|
int vips_region_image( VipsRegion *reg, const VipsRect *r );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2011-03-02 22:53:32 +01:00
|
|
|
int vips_region_region( VipsRegion *reg, VipsRegion *dest,
|
2017-11-17 17:30:25 +01:00
|
|
|
const VipsRect *r, int x, int y );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2011-03-02 22:53:32 +01:00
|
|
|
int vips_region_equalsregion( VipsRegion *reg1, VipsRegion *reg2 );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2011-03-02 22:53:32 +01:00
|
|
|
int vips_region_position( VipsRegion *reg, int x, int y );
|
2009-08-16 17:00:08 +02:00
|
|
|
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2017-11-17 17:30:25 +01:00
|
|
|
void vips_region_paint( VipsRegion *reg, const VipsRect *r, int value );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2017-11-17 17:30:25 +01:00
|
|
|
void vips_region_paint_pel( VipsRegion *reg,
|
|
|
|
const VipsRect *r, const VipsPel *ink );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2011-03-02 22:53:32 +01:00
|
|
|
void vips_region_black( VipsRegion *reg );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2018-03-27 12:15:48 +02:00
|
|
|
void vips_region_copy( VipsRegion *reg, VipsRegion *dest,
|
2017-11-17 17:30:25 +01:00
|
|
|
const VipsRect *r, int x, int y );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2018-08-29 10:50:35 +02:00
|
|
|
int vips_region_shrink_method( VipsRegion *from, VipsRegion *to,
|
|
|
|
const VipsRect *target, VipsRegionShrink method );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2018-08-29 10:50:35 +02:00
|
|
|
int vips_region_shrink( VipsRegion *from, VipsRegion *to,
|
|
|
|
const VipsRect *target );
|
2010-01-27 15:40:24 +01:00
|
|
|
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2017-11-17 17:30:25 +01:00
|
|
|
int vips_region_prepare( VipsRegion *reg, const VipsRect *r );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2018-03-27 12:15:48 +02:00
|
|
|
int vips_region_prepare_to( VipsRegion *reg,
|
2017-11-17 17:30:25 +01:00
|
|
|
VipsRegion *dest, const VipsRect *r, int x, int y );
|
2011-03-03 15:49:12 +01:00
|
|
|
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2019-03-12 17:00:24 +01:00
|
|
|
VipsPel *vips_region_fetch( VipsRegion *region,
|
|
|
|
int left, int top, int width, int height, size_t *len );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2019-03-12 17:00:24 +01:00
|
|
|
int vips_region_width( VipsRegion *region );
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2019-03-12 17:00:24 +01:00
|
|
|
int vips_region_height( VipsRegion *region );
|
|
|
|
|
2022-04-16 11:58:55 +02:00
|
|
|
VIPS_API
|
2014-01-28 14:08:02 +01:00
|
|
|
void vips_region_invalidate( VipsRegion *reg );
|
|
|
|
|
2016-03-22 13:26:45 +01:00
|
|
|
/* Use this to count pixels passing through key points. Handy for spotting bad
|
|
|
|
* overcomputation.
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG_LEAK
|
|
|
|
#define VIPS_COUNT_PIXELS( R, N ) vips__region_count_pixels( R, N )
|
|
|
|
#else /*!DEBUG_LEAK*/
|
|
|
|
#define VIPS_COUNT_PIXELS( R, N )
|
|
|
|
#endif /*DEBUG_LEAK*/
|
|
|
|
|
2011-03-02 22:53:32 +01:00
|
|
|
#define VIPS_REGION_LSKIP( R ) \
|
2009-10-08 13:17:23 +02:00
|
|
|
((size_t)((R)->bpl))
|
2011-03-02 22:53:32 +01:00
|
|
|
#define VIPS_REGION_N_ELEMENTS( R ) \
|
2009-10-08 13:17:23 +02:00
|
|
|
((size_t)((R)->valid.width * (R)->im->Bands))
|
2021-04-26 16:16:20 +02:00
|
|
|
#define VIPS_REGION_SIZEOF_ELEMENT( R ) \
|
|
|
|
(VIPS_IMAGE_SIZEOF_ELEMENT( (R)->im ))
|
|
|
|
#define VIPS_REGION_SIZEOF_PEL( R ) \
|
|
|
|
(VIPS_IMAGE_SIZEOF_PEL( (R)->im ))
|
2011-03-02 22:53:32 +01:00
|
|
|
#define VIPS_REGION_SIZEOF_LINE( R ) \
|
2021-04-26 16:16:20 +02:00
|
|
|
((size_t)((R)->valid.width * VIPS_REGION_SIZEOF_PEL( R )))
|
2009-08-16 17:00:08 +02:00
|
|
|
|
|
|
|
/* If DEBUG is defined, add bounds checking.
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
2011-03-02 22:53:32 +01:00
|
|
|
#define VIPS_REGION_ADDR( R, X, Y ) \
|
2011-03-28 18:18:06 +02:00
|
|
|
( (vips_rect_includespoint( &(R)->valid, (X), (Y) ))? \
|
2011-03-02 22:53:32 +01:00
|
|
|
((R)->data + ((Y) - (R)->valid.top) * VIPS_REGION_LSKIP(R) + \
|
2021-04-26 16:16:20 +02:00
|
|
|
((X) - (R)->valid.left) * VIPS_REGION_SIZEOF_PEL( R )): \
|
2009-08-16 17:00:08 +02:00
|
|
|
(fprintf( stderr, \
|
2011-03-02 22:53:32 +01:00
|
|
|
"VIPS_REGION_ADDR: point out of bounds, " \
|
2009-08-16 17:00:08 +02:00
|
|
|
"file \"%s\", line %d\n" \
|
|
|
|
"(point x=%d, y=%d\n" \
|
2011-03-17 14:05:46 +01:00
|
|
|
" should have been within VipsRect left=%d, top=%d, " \
|
2009-08-16 17:00:08 +02:00
|
|
|
"width=%d, height=%d)\n", \
|
|
|
|
__FILE__, __LINE__, \
|
|
|
|
(X), (Y), \
|
2010-10-22 15:49:36 +02:00
|
|
|
(R)->valid.left, \
|
|
|
|
(R)->valid.top, \
|
|
|
|
(R)->valid.width, \
|
2011-12-31 19:22:42 +01:00
|
|
|
(R)->valid.height ), abort(), (VipsPel *) NULL) \
|
2009-08-16 17:00:08 +02:00
|
|
|
)
|
|
|
|
#else /*DEBUG*/
|
2011-03-02 22:53:32 +01:00
|
|
|
#define VIPS_REGION_ADDR( R, X, Y ) \
|
2010-10-22 15:49:36 +02:00
|
|
|
((R)->data + \
|
2011-03-02 22:53:32 +01:00
|
|
|
((Y)-(R)->valid.top) * VIPS_REGION_LSKIP( R ) + \
|
2021-04-26 16:16:20 +02:00
|
|
|
((X)-(R)->valid.left) * VIPS_REGION_SIZEOF_PEL( R ))
|
2009-08-16 17:00:08 +02:00
|
|
|
#endif /*DEBUG*/
|
|
|
|
|
2011-03-02 22:53:32 +01:00
|
|
|
#define VIPS_REGION_ADDR_TOPLEFT( R ) ((R)->data)
|
2009-08-16 17:00:08 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /*__cplusplus*/
|
|
|
|
|
2011-03-28 18:18:06 +02:00
|
|
|
#endif /*VIPS_REGION_H*/
|