added im_draw_rect(), deprecated im_paintrect()
This commit is contained in:
parent
de026e0750
commit
39a6a2c0b3
@ -22,6 +22,7 @@
|
|||||||
- copy iconv.m4 and friends in bootstrap, thanks Mike
|
- copy iconv.m4 and friends in bootstrap, thanks Mike
|
||||||
- moved the stupid _copy() versions of the inplace ops to deprecated, since
|
- moved the stupid _copy() versions of the inplace ops to deprecated, since
|
||||||
nip2 can call inplace ops directly now
|
nip2 can call inplace ops directly now
|
||||||
|
- added im_draw_rect(), moved im_paintrect() to deprecated
|
||||||
|
|
||||||
12/5/10 started 7.22.2
|
12/5/10 started 7.22.2
|
||||||
- the conditional image of ifthenelse can be any format, a (!=0) is added if
|
- the conditional image of ifthenelse can be any format, a (!=0) is added if
|
||||||
|
8
TODO
8
TODO
@ -4,6 +4,14 @@
|
|||||||
|
|
||||||
- use im__inplace_base() in more places
|
- use im__inplace_base() in more places
|
||||||
|
|
||||||
|
- consider:
|
||||||
|
|
||||||
|
if( im_check_vector( "im__vector_to_ink", n, im ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
n must be 1 or im->Bands ... but what about n > 1 and im->Bands == 1?
|
||||||
|
|
||||||
|
look at im_lintra_vec(), what happens here?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <vips/vips.h>
|
#include <vips/vips.h>
|
||||||
|
#include <vips/internal.h>
|
||||||
|
|
||||||
#ifdef WITH_DMALLOC
|
#ifdef WITH_DMALLOC
|
||||||
#include <dmalloc.h>
|
#include <dmalloc.h>
|
||||||
@ -1274,12 +1275,8 @@ flood_blob_copy_vec( im_object *argv )
|
|||||||
|
|
||||||
PEL *ink;
|
PEL *ink;
|
||||||
|
|
||||||
if( dv->n != in->Bands ) {
|
if( !(ink = im__vector_to_ink( "im_flood_blob_copy",
|
||||||
im_error( "im_flood_blob_copy",
|
in, dv->n, dv->vec )) )
|
||||||
"%s", _( "bad vector length" ) );
|
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
if( !(ink = im__vector_to_ink( in, dv->vec )) )
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( im_flood_blob_copy( in, out, start_x, start_y, ink ) );
|
return( im_flood_blob_copy( in, out, start_x, start_y, ink ) );
|
||||||
@ -1319,12 +1316,8 @@ flood_copy_vec( im_object *argv )
|
|||||||
|
|
||||||
PEL *ink;
|
PEL *ink;
|
||||||
|
|
||||||
if( dv->n != in->Bands ) {
|
if( !(ink = im__vector_to_ink( "im_flood_copy",
|
||||||
im_error( "im_flood_copy",
|
in, dv->n, dv->vec )) )
|
||||||
"%s", _( "bad vector length" ) );
|
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
if( !(ink = im__vector_to_ink( in, dv->vec )) )
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( im_flood_copy( in, out, start_x, start_y, ink ) );
|
return( im_flood_copy( in, out, start_x, start_y, ink ) );
|
||||||
|
@ -506,3 +506,10 @@ im_flood_other_copy( IMAGE *test, IMAGE *mark, IMAGE *out,
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
im_paintrect( IMAGE *im, Rect *r, PEL *ink )
|
||||||
|
{
|
||||||
|
return( im_draw_rect( im,
|
||||||
|
r->left, r->top, r->width, r->height, 1, ink ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -231,6 +231,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_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 );
|
||||||
int im_flood_blob_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink );
|
int im_flood_blob_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink );
|
||||||
|
@ -40,9 +40,12 @@ extern "C" {
|
|||||||
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, Rect *r );
|
||||||
int im_smear( IMAGE *im, int ix, int iy, Rect *r );
|
int im_smear( IMAGE *im, int ix, int iy, Rect *r );
|
||||||
int im_smudge( IMAGE *im, int ix, int iy, Rect *r );
|
int im_smudge( IMAGE *im, int ix, int iy, Rect *r );
|
||||||
int im_paintrect( IMAGE *im, Rect *r, PEL *ink );
|
|
||||||
|
int im_draw_rect( IMAGE *image,
|
||||||
|
int left, int top, int width, int height, int fill, PEL *ink );
|
||||||
int im_draw_circle( IMAGE *im,
|
int im_draw_circle( IMAGE *im,
|
||||||
int cx, int cy, int radius, gboolean fill, PEL *ink );
|
int cx, int cy, int radius, gboolean fill, 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_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,
|
||||||
|
@ -277,7 +277,7 @@ int im__fmaskcir( IMAGE *out, VipsMaskType flag, va_list ap );
|
|||||||
/* inplace
|
/* inplace
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PEL *im__vector_to_ink( IMAGE *im, double *vec );
|
PEL *im__vector_to_ink( const char *domain, IMAGE *im, int n, double *vec );
|
||||||
IMAGE *im__inplace_base( const char *domain,
|
IMAGE *im__inplace_base( const char *domain,
|
||||||
IMAGE *main, IMAGE *sub, IMAGE *out );
|
IMAGE *main, IMAGE *sub, IMAGE *out );
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
noinst_LTLIBRARIES = libinplace.la
|
noinst_LTLIBRARIES = libinplace.la
|
||||||
|
|
||||||
libinplace_la_SOURCES = \
|
libinplace_la_SOURCES = \
|
||||||
im_circle.c \
|
im_draw_circle.c \
|
||||||
flood.c \
|
flood.c \
|
||||||
im_insertplace.c \
|
im_insertplace.c \
|
||||||
im_paintrect.c \
|
im_draw_rect.c \
|
||||||
im_plotmask.c \
|
im_plotmask.c \
|
||||||
inplace_dispatch.c \
|
inplace_dispatch.c \
|
||||||
line_draw.c \
|
line_draw.c \
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
/* @(#) Fill Rect r of image im with pels of colour ink. r can be any size and
|
/* Fill Rect r of image im with pels of colour ink.
|
||||||
* @(#) any position, we clip against the image size.
|
|
||||||
* @(#)
|
|
||||||
* @(#) int
|
|
||||||
* @(#) im_paintrect( IMAGE *im, Rect *r, PEL *ink )
|
|
||||||
* @(#)
|
|
||||||
* @(#)
|
|
||||||
*
|
*
|
||||||
* Copyright: J. Cupitt
|
* Copyright: J. Cupitt
|
||||||
* Written: 15/06/1992
|
* Written: 15/06/1992
|
||||||
@ -17,6 +11,10 @@
|
|||||||
* 6/3/10
|
* 6/3/10
|
||||||
* - don't im_invalidate() after paint, this now needs to be at a higher
|
* - don't im_invalidate() after paint, this now needs to be at a higher
|
||||||
* level
|
* level
|
||||||
|
* 22/9/10
|
||||||
|
* - gtk-doc
|
||||||
|
* - added 'fill'
|
||||||
|
* - renamed as im_draw_rect() for consistency
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -59,19 +57,47 @@
|
|||||||
#include <dmalloc.h>
|
#include <dmalloc.h>
|
||||||
#endif /*WITH_DMALLOC*/
|
#endif /*WITH_DMALLOC*/
|
||||||
|
|
||||||
/* Paint a rect of colour into an image.
|
/**
|
||||||
|
* im_draw_rect:
|
||||||
|
* @image: image to draw on
|
||||||
|
* @left: area to paint
|
||||||
|
* @top: area to paint
|
||||||
|
* @width: area to paint
|
||||||
|
* @height: area to paint
|
||||||
|
* @fill: fill the rect
|
||||||
|
* @ink: paint with this colour
|
||||||
|
*
|
||||||
|
* Paint pixels within @left, @top, @width, @height in @image with @ink. If
|
||||||
|
* @fill is zero, just paint a 1-pixel-wide outline.
|
||||||
|
*
|
||||||
|
* This an inplace operation, so @main is changed. It does not thread and will
|
||||||
|
* not work well as part of a pipeline.
|
||||||
|
*
|
||||||
|
* See also: im_draw_circle().
|
||||||
|
*
|
||||||
|
* Returns: 0 on success, or -1 on error.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
im_paintrect( IMAGE *im, Rect *r, PEL *ink )
|
im_draw_rect( IMAGE *im,
|
||||||
{
|
int left, int top, int width, int height, int fill, PEL *ink )
|
||||||
|
{
|
||||||
int es = IM_IMAGE_SIZEOF_ELEMENT( im );
|
int es = IM_IMAGE_SIZEOF_ELEMENT( im );
|
||||||
int ps = es * im->Bands;
|
int ps = es * im->Bands;
|
||||||
int ls = ps * im->Xsize;
|
int ls = ps * im->Xsize;
|
||||||
Rect image, clipped;
|
|
||||||
|
Rect image, rect, clipped;
|
||||||
int x, y, b;
|
int x, y, b;
|
||||||
PEL *to;
|
PEL *to;
|
||||||
PEL *q;
|
PEL *q;
|
||||||
|
|
||||||
|
if( !fill )
|
||||||
|
return( im_draw_rect( im, left, top, width, 1, 1, ink ) ||
|
||||||
|
im_draw_rect( im,
|
||||||
|
left + width - 1, top, 1, height, 1, ink ) ||
|
||||||
|
im_draw_rect( im,
|
||||||
|
left, top + height - 1, width, 1, 1, ink ) ||
|
||||||
|
im_draw_rect( im, left, top, 1, height, 1, ink ) );
|
||||||
|
|
||||||
if( im_rwcheck( im ) )
|
if( im_rwcheck( im ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
@ -81,7 +107,11 @@ im_paintrect( IMAGE *im, Rect *r, PEL *ink )
|
|||||||
image.top = 0;
|
image.top = 0;
|
||||||
image.width = im->Xsize;
|
image.width = im->Xsize;
|
||||||
image.height = im->Ysize;
|
image.height = im->Ysize;
|
||||||
im_rect_intersectrect( r, &image, &clipped );
|
rect.left = left;
|
||||||
|
rect.top = top;
|
||||||
|
rect.width = width;
|
||||||
|
rect.height = height;
|
||||||
|
im_rect_intersectrect( &rect, &image, &clipped );
|
||||||
|
|
||||||
/* Any points left to plot?
|
/* Any points left to plot?
|
||||||
*/
|
*/
|
||||||
@ -90,13 +120,16 @@ im_paintrect( IMAGE *im, Rect *r, PEL *ink )
|
|||||||
|
|
||||||
/* Loop through image plotting where required.
|
/* Loop through image plotting where required.
|
||||||
*/
|
*/
|
||||||
to = (PEL *) im->data + clipped.left * ps + clipped.top * ls;
|
to = (PEL *) IM_IMAGE_ADDR( im, clipped.left, clipped.top );
|
||||||
for( y = 0; y < clipped.height; y++ ) {
|
for( y = 0; y < clipped.height; y++ ) {
|
||||||
q = to;
|
q = to;
|
||||||
|
|
||||||
for( x = 0; x < clipped.width; x++ )
|
for( x = 0; x < clipped.width; x++ ) {
|
||||||
for( b = 0; b < ps; b++ )
|
for( b = 0; b < ps; b++ )
|
||||||
*q++ = ink[b];
|
q[b] = ink[b];
|
||||||
|
|
||||||
|
q += ps;
|
||||||
|
}
|
||||||
|
|
||||||
to += ls;
|
to += ls;
|
||||||
}
|
}
|
@ -132,21 +132,21 @@ static im_function lineset_desc = {
|
|||||||
* valid.
|
* valid.
|
||||||
*/
|
*/
|
||||||
PEL *
|
PEL *
|
||||||
im__vector_to_ink( IMAGE *im, double *vec )
|
im__vector_to_ink( const char *domain, IMAGE *im, int n, double *vec )
|
||||||
{
|
{
|
||||||
const int n = im->Bands;
|
|
||||||
|
|
||||||
IMAGE *t[3];
|
IMAGE *t[3];
|
||||||
double *zeros;
|
double *zeros;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if( im_open_local_array( im, t, 3, "vector_to_ink", "t" ) ||
|
if( im_check_vector( domain, n, im ) )
|
||||||
|
return( NULL );
|
||||||
|
if( im_open_local_array( im, t, 3, domain, "t" ) ||
|
||||||
!(zeros = IM_ARRAY( im, n, double )) )
|
!(zeros = IM_ARRAY( im, n, double )) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
for( i = 0; i < n; i++ )
|
for( i = 0; i < n; i++ )
|
||||||
zeros[i] = 0.0;
|
zeros[i] = 0.0;
|
||||||
|
|
||||||
if( im_black( t[0], 1, 1, n ) ||
|
if( im_black( t[0], 1, 1, im->Bands ) ||
|
||||||
im_lintra_vec( n, zeros, t[0], vec, t[1] ) ||
|
im_lintra_vec( n, zeros, t[0], vec, t[1] ) ||
|
||||||
im_clip2fmt( t[1], t[2], im->BandFmt ) )
|
im_clip2fmt( t[1], t[2], im->BandFmt ) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
@ -175,11 +175,8 @@ flood_blob_vec( im_object *argv )
|
|||||||
|
|
||||||
PEL *ink;
|
PEL *ink;
|
||||||
|
|
||||||
if( dv->n != image->Bands ) {
|
if( !(ink = im__vector_to_ink( "im_flood_blob",
|
||||||
im_error( "im_flood_blob", "%s", _( "bad vector length" ) );
|
image, dv->n, dv->vec )) )
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
if( !(ink = im__vector_to_ink( image, dv->vec )) )
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( im_flood_blob( image, start_x, start_y, ink, NULL ) );
|
return( im_flood_blob( image, start_x, start_y, ink, NULL ) );
|
||||||
@ -217,11 +214,7 @@ flood_vec( im_object *argv )
|
|||||||
|
|
||||||
PEL *ink;
|
PEL *ink;
|
||||||
|
|
||||||
if( dv->n != image->Bands ) {
|
if( !(ink = im__vector_to_ink( "im_flood", image, dv->n, dv->vec )) )
|
||||||
im_error( "im_flood", "%s", _( "bad vector length" ) );
|
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
if( !(ink = im__vector_to_ink( image, dv->vec )) )
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( im_flood( image, start_x, start_y, ink, NULL ) );
|
return( im_flood( image, start_x, start_y, ink, NULL ) );
|
||||||
@ -273,6 +266,51 @@ static im_function flood_other_desc = {
|
|||||||
flood_other_args /* Arg list */
|
flood_other_args /* Arg list */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Args for im_draw_rect.
|
||||||
|
*/
|
||||||
|
static im_arg_desc draw_rect_args[] = {
|
||||||
|
IM_RW_IMAGE( "image" ),
|
||||||
|
IM_INPUT_INT( "left" ),
|
||||||
|
IM_INPUT_INT( "top" ),
|
||||||
|
IM_INPUT_INT( "width" ),
|
||||||
|
IM_INPUT_INT( "height" ),
|
||||||
|
IM_INPUT_INT( "fill" ),
|
||||||
|
IM_INPUT_DOUBLEVEC( "ink" )
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Call im_draw_circle via arg vector.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
draw_rect_vec( im_object *argv )
|
||||||
|
{
|
||||||
|
IMAGE *image = argv[0];
|
||||||
|
int left = *((int *) argv[1]);
|
||||||
|
int top = *((int *) argv[2]);
|
||||||
|
int width = *((int *) argv[3]);
|
||||||
|
int height = *((int *) argv[4]);
|
||||||
|
int fill = *((int *) argv[5]);
|
||||||
|
im_doublevec_object *dv = (im_doublevec_object *) argv[6];
|
||||||
|
|
||||||
|
PEL *ink;
|
||||||
|
|
||||||
|
if( !(ink = im__vector_to_ink( "im_draw_rect",
|
||||||
|
image, dv->n, dv->vec )) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
return( im_draw_rect( image, left, top, width, height, fill, ink ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Description of im_draw_rect.
|
||||||
|
*/
|
||||||
|
static im_function draw_rect_desc = {
|
||||||
|
"im_draw_rect", /* Name */
|
||||||
|
"draw rect on image",
|
||||||
|
0, /* Flags */
|
||||||
|
draw_rect_vec, /* Dispatch function */
|
||||||
|
IM_NUMBER( draw_rect_args ), /* Size of arg list */
|
||||||
|
draw_rect_args /* Arg list */
|
||||||
|
};
|
||||||
|
|
||||||
/* Args for im_draw_circle.
|
/* Args for im_draw_circle.
|
||||||
*/
|
*/
|
||||||
static im_arg_desc draw_circle_args[] = {
|
static im_arg_desc draw_circle_args[] = {
|
||||||
@ -298,7 +336,8 @@ draw_circle_vec( im_object *argv )
|
|||||||
|
|
||||||
PEL *ink;
|
PEL *ink;
|
||||||
|
|
||||||
if( !(ink = im__vector_to_ink( image, dv->vec )) )
|
if( !(ink = im__vector_to_ink( "im_draw_circle",
|
||||||
|
image, dv->n, dv->vec )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( im_draw_circle( image, cx, cy, radius, fill, ink ) );
|
return( im_draw_circle( image, cx, cy, radius, fill, ink ) );
|
||||||
@ -318,8 +357,6 @@ static im_function draw_circle_desc = {
|
|||||||
/* To do:
|
/* To do:
|
||||||
* these all need some kind of pel type
|
* these all need some kind of pel type
|
||||||
*
|
*
|
||||||
im_flood.c
|
|
||||||
im_paintrect.c
|
|
||||||
im_plotmask.c
|
im_plotmask.c
|
||||||
line_draw.c
|
line_draw.c
|
||||||
plot_point.c
|
plot_point.c
|
||||||
@ -331,6 +368,7 @@ static im_function draw_circle_desc = {
|
|||||||
*/
|
*/
|
||||||
static im_function *inplace_list[] = {
|
static im_function *inplace_list[] = {
|
||||||
&draw_circle_desc,
|
&draw_circle_desc,
|
||||||
|
&draw_rect_desc,
|
||||||
&flood_desc,
|
&flood_desc,
|
||||||
&flood_blob_desc,
|
&flood_blob_desc,
|
||||||
&flood_other_desc,
|
&flood_other_desc,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user