rename nearest as fill_nearest

avoid a clash with the nearest-neighbour interpolator
This commit is contained in:
John Cupitt 2017-11-01 15:06:37 +00:00
parent cdc286e9d6
commit 55e577a2fb
7 changed files with 613 additions and 612 deletions

View File

@ -32,7 +32,7 @@
- added vips_value_set_blob_free() - added vips_value_set_blob_free()
- "--size Nx" to vipsthumbnail was broken, thanks jrochkind - "--size Nx" to vipsthumbnail was broken, thanks jrochkind
- fix build with gcc 7 - fix build with gcc 7
- add vips_nearest() ... fill pixels with nearest colour - add vips_fill_nearest() ... fill pixels with nearest colour
29/8/17 started 8.5.9 29/8/17 started 8.5.9
- make --fail stop jpeg read on any libjpeg warning, thanks @mceachen - make --fail stop jpeg read on any libjpeg warning, thanks @mceachen

View File

@ -5,55 +5,11 @@
#define VIPS_ENUM_TYPES_H #define VIPS_ENUM_TYPES_H
G_BEGIN_DECLS G_BEGIN_DECLS
/* enumerations from "../../../libvips/include/vips/resample.h" */
/* enumerations from "../../../libvips/include/vips/arithmetic.h" */ GType vips_kernel_get_type (void) G_GNUC_CONST;
GType vips_operation_math_get_type (void) G_GNUC_CONST; #define VIPS_TYPE_KERNEL (vips_kernel_get_type())
#define VIPS_TYPE_OPERATION_MATH (vips_operation_math_get_type()) GType vips_size_get_type (void) G_GNUC_CONST;
GType vips_operation_math2_get_type (void) G_GNUC_CONST; #define VIPS_TYPE_SIZE (vips_size_get_type())
#define VIPS_TYPE_OPERATION_MATH2 (vips_operation_math2_get_type())
GType vips_operation_round_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_ROUND (vips_operation_round_get_type())
GType vips_operation_relational_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_RELATIONAL (vips_operation_relational_get_type())
GType vips_operation_boolean_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_BOOLEAN (vips_operation_boolean_get_type())
GType vips_operation_complex_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_COMPLEX (vips_operation_complex_get_type())
GType vips_operation_complex2_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_COMPLEX2 (vips_operation_complex2_get_type())
GType vips_operation_complexget_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_COMPLEXGET (vips_operation_complexget_get_type())
/* enumerations from "../../../libvips/include/vips/basic.h" */
GType vips_precision_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_PRECISION (vips_precision_get_type())
/* enumerations from "../../../libvips/include/vips/colour.h" */
GType vips_intent_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_INTENT (vips_intent_get_type())
GType vips_pcs_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_PCS (vips_pcs_get_type())
/* enumerations from "../../../libvips/include/vips/conversion.h" */
GType vips_extend_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_EXTEND (vips_extend_get_type())
GType vips_compass_direction_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_COMPASS_DIRECTION (vips_compass_direction_get_type())
GType vips_direction_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_DIRECTION (vips_direction_get_type())
GType vips_align_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ALIGN (vips_align_get_type())
GType vips_angle_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ANGLE (vips_angle_get_type())
GType vips_angle45_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ANGLE45 (vips_angle45_get_type())
GType vips_interesting_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_INTERESTING (vips_interesting_get_type())
GType vips_blend_mode_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_BLEND_MODE (vips_blend_mode_get_type())
/* enumerations from "../../../libvips/include/vips/convolution.h" */
GType vips_combine_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_COMBINE (vips_combine_get_type())
/* enumerations from "../../../libvips/include/vips/draw.h" */
GType vips_combine_mode_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_COMBINE_MODE (vips_combine_mode_get_type())
/* enumerations from "../../../libvips/include/vips/foreign.h" */ /* enumerations from "../../../libvips/include/vips/foreign.h" */
GType vips_foreign_flags_get_type (void) G_GNUC_CONST; GType vips_foreign_flags_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_FOREIGN_FLAGS (vips_foreign_flags_get_type()) #define VIPS_TYPE_FOREIGN_FLAGS (vips_foreign_flags_get_type())
@ -75,6 +31,43 @@ GType vips_foreign_dz_depth_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_FOREIGN_DZ_DEPTH (vips_foreign_dz_depth_get_type()) #define VIPS_TYPE_FOREIGN_DZ_DEPTH (vips_foreign_dz_depth_get_type())
GType vips_foreign_dz_container_get_type (void) G_GNUC_CONST; GType vips_foreign_dz_container_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_FOREIGN_DZ_CONTAINER (vips_foreign_dz_container_get_type()) #define VIPS_TYPE_FOREIGN_DZ_CONTAINER (vips_foreign_dz_container_get_type())
/* enumerations from "../../../libvips/include/vips/arithmetic.h" */
GType vips_operation_math_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_MATH (vips_operation_math_get_type())
GType vips_operation_math2_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_MATH2 (vips_operation_math2_get_type())
GType vips_operation_round_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_ROUND (vips_operation_round_get_type())
GType vips_operation_relational_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_RELATIONAL (vips_operation_relational_get_type())
GType vips_operation_boolean_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_BOOLEAN (vips_operation_boolean_get_type())
GType vips_operation_complex_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_COMPLEX (vips_operation_complex_get_type())
GType vips_operation_complex2_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_COMPLEX2 (vips_operation_complex2_get_type())
GType vips_operation_complexget_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_COMPLEXGET (vips_operation_complexget_get_type())
/* enumerations from "../../../libvips/include/vips/conversion.h" */
GType vips_extend_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_EXTEND (vips_extend_get_type())
GType vips_compass_direction_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_COMPASS_DIRECTION (vips_compass_direction_get_type())
GType vips_direction_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_DIRECTION (vips_direction_get_type())
GType vips_align_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ALIGN (vips_align_get_type())
GType vips_angle_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ANGLE (vips_angle_get_type())
GType vips_angle45_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ANGLE45 (vips_angle45_get_type())
GType vips_interesting_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_INTERESTING (vips_interesting_get_type())
GType vips_blend_mode_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_BLEND_MODE (vips_blend_mode_get_type())
/* enumerations from "../../../libvips/include/vips/util.h" */
GType vips_token_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_TOKEN (vips_token_get_type())
/* enumerations from "../../../libvips/include/vips/image.h" */ /* enumerations from "../../../libvips/include/vips/image.h" */
GType vips_demand_style_get_type (void) G_GNUC_CONST; GType vips_demand_style_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_DEMAND_STYLE (vips_demand_style_get_type()) #define VIPS_TYPE_DEMAND_STYLE (vips_demand_style_get_type())
@ -88,23 +81,29 @@ GType vips_coding_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_CODING (vips_coding_get_type()) #define VIPS_TYPE_CODING (vips_coding_get_type())
GType vips_access_get_type (void) G_GNUC_CONST; GType vips_access_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ACCESS (vips_access_get_type()) #define VIPS_TYPE_ACCESS (vips_access_get_type())
/* enumerations from "../../../libvips/include/vips/morphology.h" */ /* enumerations from "../../../libvips/include/vips/colour.h" */
GType vips_operation_morphology_get_type (void) G_GNUC_CONST; GType vips_intent_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_MORPHOLOGY (vips_operation_morphology_get_type()) #define VIPS_TYPE_INTENT (vips_intent_get_type())
/* enumerations from "../../../libvips/include/vips/object.h" */ GType vips_pcs_get_type (void) G_GNUC_CONST;
GType vips_argument_flags_get_type (void) G_GNUC_CONST; #define VIPS_TYPE_PCS (vips_pcs_get_type())
#define VIPS_TYPE_ARGUMENT_FLAGS (vips_argument_flags_get_type())
/* enumerations from "../../../libvips/include/vips/operation.h" */ /* enumerations from "../../../libvips/include/vips/operation.h" */
GType vips_operation_flags_get_type (void) G_GNUC_CONST; GType vips_operation_flags_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_OPERATION_FLAGS (vips_operation_flags_get_type()) #define VIPS_TYPE_OPERATION_FLAGS (vips_operation_flags_get_type())
/* enumerations from "../../../libvips/include/vips/resample.h" */ /* enumerations from "../../../libvips/include/vips/convolution.h" */
GType vips_kernel_get_type (void) G_GNUC_CONST; GType vips_combine_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_KERNEL (vips_kernel_get_type()) #define VIPS_TYPE_COMBINE (vips_combine_get_type())
GType vips_size_get_type (void) G_GNUC_CONST; /* enumerations from "../../../libvips/include/vips/morphology.h" */
#define VIPS_TYPE_SIZE (vips_size_get_type()) GType vips_operation_morphology_get_type (void) G_GNUC_CONST;
/* enumerations from "../../../libvips/include/vips/util.h" */ #define VIPS_TYPE_OPERATION_MORPHOLOGY (vips_operation_morphology_get_type())
GType vips_token_get_type (void) G_GNUC_CONST; /* enumerations from "../../../libvips/include/vips/draw.h" */
#define VIPS_TYPE_TOKEN (vips_token_get_type()) GType vips_combine_mode_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_COMBINE_MODE (vips_combine_mode_get_type())
/* enumerations from "../../../libvips/include/vips/basic.h" */
GType vips_precision_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_PRECISION (vips_precision_get_type())
/* enumerations from "../../../libvips/include/vips/object.h" */
GType vips_argument_flags_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ARGUMENT_FLAGS (vips_argument_flags_get_type())
G_END_DECLS G_END_DECLS
#endif /*VIPS_ENUM_TYPES_H*/ #endif /*VIPS_ENUM_TYPES_H*/

View File

@ -57,7 +57,7 @@ int vips_countlines( VipsImage *in, double *nolines,
__attribute__((sentinel)); __attribute__((sentinel));
int vips_labelregions( VipsImage *in, VipsImage **mask, ... ) int vips_labelregions( VipsImage *in, VipsImage **mask, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_nearest( VipsImage *in, VipsImage **out, ... ) int vips_fill_nearest( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel)); __attribute__((sentinel));
#ifdef __cplusplus #ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -136,11 +136,11 @@ vips_morphology_operation_init( void )
extern int vips_rank_get_type( void ); extern int vips_rank_get_type( void );
extern int vips_countlines_get_type( void ); extern int vips_countlines_get_type( void );
extern int vips_labelregions_get_type( void ); extern int vips_labelregions_get_type( void );
extern int vips_nearest_get_type( void ); extern int vips_fill_nearest_get_type( void );
vips_morph_get_type(); vips_morph_get_type();
vips_rank_get_type(); vips_rank_get_type();
vips_countlines_get_type(); vips_countlines_get_type();
vips_labelregions_get_type(); vips_labelregions_get_type();
vips_nearest_get_type(); vips_fill_nearest_get_type();
} }

View File

@ -60,7 +60,7 @@ typedef struct _Seed {
int octant_mask; int octant_mask;
} Seed; } Seed;
typedef struct _VipsNearest { typedef struct _VipsFillNearest {
VipsMorphology parent_instance; VipsMorphology parent_instance;
VipsImage *out; VipsImage *out;
@ -74,41 +74,41 @@ typedef struct _VipsNearest {
/* All our seed pixels. There can be a lot of these. /* All our seed pixels. There can be a lot of these.
*/ */
GArray *seeds; GArray *seeds;
} VipsNearest; } VipsFillNearest;
typedef VipsMorphologyClass VipsNearestClass; typedef VipsMorphologyClass VipsFillNearestClass;
G_DEFINE_TYPE( VipsNearest, vips_nearest, VIPS_TYPE_MORPHOLOGY ); G_DEFINE_TYPE( VipsFillNearest, vips_fill_nearest, VIPS_TYPE_MORPHOLOGY );
static void static void
vips_nearest_finalize( GObject *gobject ) vips_fill_nearest_finalize( GObject *gobject )
{ {
VipsNearest *nearest = (VipsNearest *) gobject; VipsFillNearest *nearest = (VipsFillNearest *) gobject;
#ifdef DEBUG #ifdef DEBUG
printf( "vips_nearest_finalize: " ); printf( "vips_fill_nearest_finalize: " );
vips_object_print_name( VIPS_OBJECT( gobject ) ); vips_object_print_name( VIPS_OBJECT( gobject ) );
printf( "\n" ); printf( "\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/
VIPS_FREEF( g_array_unref, nearest->seeds ); VIPS_FREEF( g_array_unref, nearest->seeds );
G_OBJECT_CLASS( vips_nearest_parent_class )->finalize( gobject ); G_OBJECT_CLASS( vips_fill_nearest_parent_class )->finalize( gobject );
} }
struct _Circle; struct _Circle;
typedef void (*VipsNearestPixel)( struct _Circle *circle, typedef void (*VipsFillNearestPixel)( struct _Circle *circle,
int x, int y, int octant ); int x, int y, int octant );
typedef struct _Circle { typedef struct _Circle {
VipsNearest *nearest; VipsFillNearest *nearest;
Seed *seed; Seed *seed;
int octant_mask; int octant_mask;
VipsNearestPixel nearest_pixel; VipsFillNearestPixel nearest_pixel;
} Circle; } Circle;
static void static void
vips_nearest_pixel( Circle *circle, int x, int y, int octant ) vips_fill_nearest_pixel( Circle *circle, int x, int y, int octant )
{ {
float *p; float *p;
float radius; float radius;
@ -145,7 +145,7 @@ vips_nearest_pixel( Circle *circle, int x, int y, int octant )
} }
static void static void
vips_nearest_pixel_clip( Circle *circle, int x, int y, int octant ) vips_fill_nearest_pixel_clip( Circle *circle, int x, int y, int octant )
{ {
if( (circle->seed->octant_mask & (1 << octant)) == 0 ) if( (circle->seed->octant_mask & (1 << octant)) == 0 )
return; return;
@ -154,11 +154,11 @@ vips_nearest_pixel_clip( Circle *circle, int x, int y, int octant )
x < circle->nearest->width && x < circle->nearest->width &&
y >= 0 && y >= 0 &&
y < circle->nearest->height ) y < circle->nearest->height )
vips_nearest_pixel( circle, x, y, octant ); vips_fill_nearest_pixel( circle, x, y, octant );
} }
static void static void
vips_nearest_scanline( VipsImage *image, vips_fill_nearest_scanline( VipsImage *image,
int y, int x1, int x2, int quadrant, void *client ) int y, int x1, int x2, int quadrant, void *client )
{ {
Circle *circle = (Circle *) client; Circle *circle = (Circle *) client;
@ -184,7 +184,7 @@ vips_nearest_scanline( VipsImage *image,
} }
static void static void
vips_nearest_grow_seed( VipsNearest *nearest, Seed *seed ) vips_fill_nearest_grow_seed( VipsFillNearest *nearest, Seed *seed )
{ {
Circle circle; Circle circle;
@ -196,12 +196,12 @@ vips_nearest_grow_seed( VipsNearest *nearest, Seed *seed )
seed->x + seed->r < nearest->width && seed->x + seed->r < nearest->width &&
seed->y - seed->r >= 0 && seed->y - seed->r >= 0 &&
seed->y + seed->r < nearest->height ) seed->y + seed->r < nearest->height )
circle.nearest_pixel = vips_nearest_pixel; circle.nearest_pixel = vips_fill_nearest_pixel;
else else
circle.nearest_pixel = vips_nearest_pixel_clip; circle.nearest_pixel = vips_fill_nearest_pixel_clip;
vips__draw_circle_direct( nearest->distance, vips__draw_circle_direct( nearest->distance,
seed->x, seed->y, seed->r, vips_nearest_scanline, &circle ); seed->x, seed->y, seed->r, vips_fill_nearest_scanline, &circle );
/* Update the action_mask for this seed. Next time, we can skip any /* Update the action_mask for this seed. Next time, we can skip any
* octants where we failed to act this time. * octants where we failed to act this time.
@ -212,16 +212,17 @@ vips_nearest_grow_seed( VipsNearest *nearest, Seed *seed )
} }
static int static int
vips_nearest_build( VipsObject *object ) vips_fill_nearest_build( VipsObject *object )
{ {
VipsMorphology *morphology = VIPS_MORPHOLOGY( object ); VipsMorphology *morphology = VIPS_MORPHOLOGY( object );
VipsNearest *nearest = (VipsNearest *) object; VipsFillNearest *nearest = (VipsFillNearest *) object;
VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 ); VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );
int ps; int ps;
int x, y, i; int x, y, i;
if( VIPS_OBJECT_CLASS( vips_nearest_parent_class )->build( object ) ) if( VIPS_OBJECT_CLASS( vips_fill_nearest_parent_class )->
build( object ) )
return( -1 ); return( -1 );
if( vips_image_wio_input( morphology->in ) ) if( vips_image_wio_input( morphology->in ) )
@ -277,7 +278,7 @@ vips_nearest_build( VipsObject *object )
/* Grow all seeds by one pixel. /* Grow all seeds by one pixel.
*/ */
for( i = 0; i < nearest->seeds->len; i++ ) for( i = 0; i < nearest->seeds->len; i++ )
vips_nearest_grow_seed( nearest, vips_fill_nearest_grow_seed( nearest,
&g_array_index( nearest->seeds, Seed, i ) ); &g_array_index( nearest->seeds, Seed, i ) );
/* Remove dead seeds. /* Remove dead seeds.
@ -297,49 +298,50 @@ vips_nearest_build( VipsObject *object )
} }
static void static void
vips_nearest_class_init( VipsNearestClass *class ) vips_fill_nearest_class_init( VipsFillNearestClass *class )
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS( class ); GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class ); VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
gobject_class->finalize = vips_nearest_finalize; gobject_class->finalize = vips_fill_nearest_finalize;
gobject_class->set_property = vips_object_set_property; gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property; gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "nearest"; vobject_class->nickname = "fill_nearest";
vobject_class->description = _( "find nearest pixel in an image" ); vobject_class->description =
vobject_class->build = vips_nearest_build; _( "fill image zeros with nearest non-zero pixel" );
vobject_class->build = vips_fill_nearest_build;
VIPS_ARG_IMAGE( class, "out", 2, VIPS_ARG_IMAGE( class, "out", 2,
_( "Out" ), _( "Out" ),
_( "Value of nearest image point" ), _( "Value of nearest non-zero pixel" ),
VIPS_ARGUMENT_REQUIRED_OUTPUT, VIPS_ARGUMENT_REQUIRED_OUTPUT,
G_STRUCT_OFFSET( VipsNearest, out ) ); G_STRUCT_OFFSET( VipsFillNearest, out ) );
VIPS_ARG_IMAGE( class, "distance", 3, VIPS_ARG_IMAGE( class, "distance", 3,
_( "Distance" ), _( "Distance" ),
_( "Distance to nearest image point" ), _( "Distance to nearest non-zero pixel" ),
VIPS_ARGUMENT_OPTIONAL_OUTPUT, VIPS_ARGUMENT_OPTIONAL_OUTPUT,
G_STRUCT_OFFSET( VipsNearest, distance ) ); G_STRUCT_OFFSET( VipsFillNearest, distance ) );
} }
static void static void
vips_nearest_init( VipsNearest *nearest ) vips_fill_nearest_init( VipsFillNearest *nearest )
{ {
} }
/** /**
* vips_nearest: (method) * vips_fill_nearest: (method)
* @in: image to test * @in: image to test
* @out: image with zero values filled with nearest pixel * @out: image with zero pixels filled with the nearest non-zero pixel
* @...: %NULL-terminated list of optional named arguments * @...: %NULL-terminated list of optional named arguments
* *
* Optional arguments: * Optional arguments:
* *
* * @distance: output image of distance to nearest image pixel * * @distance: output image of distance to nearest non-zero pixel
* *
* Flood outwards from every non-zero pixel in @in, setting pixels in @distance * Fill outwards from every non-zero pixel in @in, setting pixels in @distance
* and @value. * and @value.
* *
* At the position of zero pixels in @in, @distance contains the distance to * At the position of zero pixels in @in, @distance contains the distance to
@ -354,13 +356,13 @@ vips_nearest_init( VipsNearest *nearest )
* Returns: 0 on success, -1 on error. * Returns: 0 on success, -1 on error.
*/ */
int int
vips_nearest( VipsImage *in, VipsImage **out, ... ) vips_fill_nearest( VipsImage *in, VipsImage **out, ... )
{ {
va_list ap; va_list ap;
int result; int result;
va_start( ap, out ); va_start( ap, out );
result = vips_call_split( "nearest", ap, in, out ); result = vips_call_split( "fill_nearest", ap, in, out );
va_end( ap ); va_end( ap );
return( result ); return( result );

Binary file not shown.