im_draw_rect() is a class
This commit is contained in:
parent
495a6c7af1
commit
33551fbf4c
@ -4,7 +4,7 @@
|
||||
- colourspace has a source_space option
|
||||
- operations can be tagged as "deprecated"
|
||||
- redo im_draw_circle(), im_draw_flood(), im_draw_line(), im_draw_mask(),
|
||||
im_draw_image() as classes
|
||||
im_draw_image(), im_draw_rect() as classes
|
||||
- better rounding in vips_flatten()
|
||||
- VipsStatistic operations are sequential
|
||||
|
||||
|
18
TODO
18
TODO
@ -1,3 +1,11 @@
|
||||
- get/set point next
|
||||
|
||||
- rename vips_paintrect as vips_draw_rect()
|
||||
vips_circle() as vips_draw_circle()
|
||||
etc.
|
||||
|
||||
best to have them obviously in the same namespace, and draw is clearer than
|
||||
paint
|
||||
|
||||
|
||||
|
||||
@ -15,6 +23,16 @@
|
||||
|
||||
needs to work for eg. vips_linear() as well
|
||||
|
||||
if vector.len is == bands, expand to complex by setting imaginary == 0
|
||||
if vector.len == bands * 2, set imaginary from constant
|
||||
if vector.len == 1, bandup with imaginary == 0
|
||||
if vector.len == 2, bandup setting imaginary from vector
|
||||
|
||||
what about bands == 2? ambigious
|
||||
|
||||
we must insist vector.length == 2 or bands * 2 for complex, or have the
|
||||
current behaviour of imaginary == 0 always
|
||||
|
||||
- inplace
|
||||
|
||||
can we set a region for the pixels we will modify?
|
||||
|
@ -4575,6 +4575,22 @@ im_draw_image( VipsImage *image, VipsImage *sub, int x, int y )
|
||||
{
|
||||
return( vips_paintimage( image, sub, x, y, NULL ) );
|
||||
}
|
||||
|
||||
int
|
||||
im_draw_rect( IMAGE *image,
|
||||
int left, int top, int width, int height, int fill, VipsPel *ink )
|
||||
{
|
||||
double *vec;
|
||||
int n;
|
||||
|
||||
if( !(vec = vips__ink_to_vector( "im_draw_rect", image, ink, &n )) )
|
||||
return( -1 );
|
||||
|
||||
return( vips_paintrect( image, vec, n, left, top, width, height,
|
||||
"fill", fill,
|
||||
NULL ) );
|
||||
}
|
||||
|
||||
int
|
||||
im_draw_flood( IMAGE *image, int x, int y, VipsPel *ink, Rect *dout )
|
||||
{
|
||||
|
@ -8,10 +8,10 @@ libdraw_la_SOURCES = \
|
||||
flood.c \
|
||||
paintmask.c \
|
||||
paintimage.c \
|
||||
paintrect.c \
|
||||
linemask.c \
|
||||
lineuser.c \
|
||||
im_draw_point.c \
|
||||
im_draw_rect.c \
|
||||
im_draw_smudge.c \
|
||||
inplace_dispatch.c \
|
||||
old_draw.c \
|
||||
|
@ -130,16 +130,18 @@ vips_draw_init( VipsDraw *draw )
|
||||
void
|
||||
vips_draw_operation_init( void )
|
||||
{
|
||||
extern GType vips_paintmask_get_type( void );
|
||||
extern GType vips_paintrect_get_type( void );
|
||||
extern GType vips_paintimage_get_type( void );
|
||||
extern GType vips_paintmask_get_type( void );
|
||||
extern GType vips_line_get_type( void );
|
||||
extern GType vips_line_mask_get_type( void );
|
||||
extern GType vips_line_user_get_type( void );
|
||||
extern GType vips_circle_get_type( void );
|
||||
extern GType vips_flood_get_type( void );
|
||||
|
||||
vips_paintmask_get_type();
|
||||
vips_paintrect_get_type();
|
||||
vips_paintimage_get_type();
|
||||
vips_paintmask_get_type();
|
||||
vips_line_get_type();
|
||||
vips_line_mask_get_type();
|
||||
vips_line_user_get_type();
|
||||
|
@ -1,139 +0,0 @@
|
||||
/* Fill Rect r of image im with pels of colour ink.
|
||||
*
|
||||
* Copyright: J. Cupitt
|
||||
* Written: 15/06/1992
|
||||
* 22/7/93 JC
|
||||
* - im_incheck() added
|
||||
* 16/8/94 JC
|
||||
* - im_incheck() changed to im_makerw()
|
||||
* 5/12/06
|
||||
* - im_invalidate() after paint
|
||||
* 6/3/10
|
||||
* - don't im_invalidate() after paint, this now needs to be at a higher
|
||||
* level
|
||||
* 22/9/10
|
||||
* - gtk-doc
|
||||
* - added 'fill'
|
||||
* - renamed as im_draw_rect() for consistency
|
||||
* 27/9/10
|
||||
* - memcpy() subsequent lines of the rect
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
#include "old_draw.h"
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* See also: im_draw_circle().
|
||||
*
|
||||
* Returns: 0 on success, or -1 on error.
|
||||
*/
|
||||
int
|
||||
im_draw_rect( IMAGE *image,
|
||||
int left, int top, int width, int height, int fill, VipsPel *ink )
|
||||
{
|
||||
Rect im, rect, clipped;
|
||||
Draw draw;
|
||||
|
||||
if( !fill )
|
||||
return( im_draw_rect( image, left, top, width, 1, 1, ink ) ||
|
||||
im_draw_rect( image,
|
||||
left + width - 1, top, 1, height, 1, ink ) ||
|
||||
im_draw_rect( image,
|
||||
left, top + height - 1, width, 1, 1, ink ) ||
|
||||
im_draw_rect( image, left, top, 1, height, 1, ink ) );
|
||||
|
||||
int x, y;
|
||||
VipsPel *to;
|
||||
VipsPel *q;
|
||||
|
||||
/* Find area we plot.
|
||||
*/
|
||||
im.left = 0;
|
||||
im.top = 0;
|
||||
im.width = image->Xsize;
|
||||
im.height = image->Ysize;
|
||||
rect.left = left;
|
||||
rect.top = top;
|
||||
rect.width = width;
|
||||
rect.height = height;
|
||||
im_rect_intersectrect( &rect, &im, &clipped );
|
||||
|
||||
/* Any points left to plot?
|
||||
*/
|
||||
if( im_rect_isempty( &clipped ) )
|
||||
return( 0 );
|
||||
|
||||
if( im_check_coding_known( "im_draw_rect", image ) ||
|
||||
!im__draw_init( &draw, image, ink ) )
|
||||
return( -1 );
|
||||
|
||||
/* We plot the first line pointwise, then memcpy() it for the
|
||||
* subsequent lines.
|
||||
*/
|
||||
to = IM_IMAGE_ADDR( image, clipped.left, clipped.top );
|
||||
|
||||
q = to;
|
||||
for( x = 0; x < clipped.width; x++ ) {
|
||||
im__draw_pel( &draw, q );
|
||||
q += draw.psize;
|
||||
}
|
||||
|
||||
q = to + draw.lsize;
|
||||
for( y = 1; y < clipped.height; y++ ) {
|
||||
memcpy( q, to, clipped.width * draw.psize );
|
||||
q += draw.lsize;
|
||||
}
|
||||
|
||||
im__draw_free( &draw );
|
||||
|
||||
return( 0 );
|
||||
}
|
301
libvips/draw/paintrect.c
Normal file
301
libvips/draw/paintrect.c
Normal file
@ -0,0 +1,301 @@
|
||||
/* Fill Rect r of image im with pels of colour ink.
|
||||
*
|
||||
* Copyright: J. Cupitt
|
||||
* Written: 15/06/1992
|
||||
* 22/7/93 JC
|
||||
* - im_incheck() added
|
||||
* 16/8/94 JC
|
||||
* - im_incheck() changed to im_makerw()
|
||||
* 5/12/06
|
||||
* - im_invalidate() after paint
|
||||
* 6/3/10
|
||||
* - don't im_invalidate() after paint, this now needs to be at a higher
|
||||
* level
|
||||
* 22/9/10
|
||||
* - gtk-doc
|
||||
* - added 'fill'
|
||||
* - renamed as im_draw_rect() for consistency
|
||||
* 27/9/10
|
||||
* - memcpy() subsequent lines of the rect
|
||||
* 10/2/14
|
||||
* - redo as a class
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
|
||||
#include "pdraw.h"
|
||||
|
||||
typedef struct _VipsPaintrect {
|
||||
VipsDraw parent_object;
|
||||
|
||||
/* Parameters.
|
||||
*/
|
||||
int left;
|
||||
int top;
|
||||
int width;
|
||||
int height;
|
||||
gboolean fill;
|
||||
|
||||
} VipsPaintrect;
|
||||
|
||||
typedef struct _VipsPaintrectClass {
|
||||
VipsDrawClass parent_class;
|
||||
|
||||
} VipsPaintrectClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsPaintrect, vips_paintrect, VIPS_TYPE_DRAW );
|
||||
|
||||
static int
|
||||
vips_paintrect_build( VipsObject *object )
|
||||
{
|
||||
VipsDraw *draw = VIPS_DRAW( object );
|
||||
VipsPaintrect *paintrect = (VipsPaintrect *) object;
|
||||
int left = paintrect->left;
|
||||
int top = paintrect->top;
|
||||
int width = paintrect->width;
|
||||
int height = paintrect->height;
|
||||
|
||||
VipsRect image;
|
||||
VipsRect rect;
|
||||
VipsRect clip;
|
||||
|
||||
if( VIPS_OBJECT_CLASS( vips_paintrect_parent_class )->build( object ) )
|
||||
return( -1 );
|
||||
|
||||
/* Also use a solid fill for very narrow unfilled rects.
|
||||
*/
|
||||
if( !paintrect->fill &&
|
||||
width > 2 &&
|
||||
height > 2 )
|
||||
return( vips_paintrect( draw->image,
|
||||
draw->ink->data, draw->ink->n,
|
||||
left, top, width, 1, NULL ) ||
|
||||
vips_paintrect( draw->image,
|
||||
draw->ink->data, draw->ink->n,
|
||||
left + width - 1, top, 1, height, NULL ) ||
|
||||
vips_paintrect( draw->image,
|
||||
draw->ink->data, draw->ink->n,
|
||||
left, top + height - 1, width, 1, NULL ) ||
|
||||
vips_paintrect( draw->image,
|
||||
draw->ink->data, draw->ink->n,
|
||||
left, top, 1, height, NULL ) );
|
||||
|
||||
image.left = 0;
|
||||
image.top = 0;
|
||||
image.width = draw->image->Xsize;
|
||||
image.height = draw->image->Ysize;
|
||||
rect.left = left;
|
||||
rect.top = top;
|
||||
rect.width = width;
|
||||
rect.height = height;
|
||||
vips_rect_intersectrect( &rect, &image, &clip );
|
||||
|
||||
if( !vips_rect_isempty( &clip ) ) {
|
||||
VipsPel *to =
|
||||
VIPS_IMAGE_ADDR( draw->image, clip.left, clip.top );
|
||||
|
||||
VipsPel *q;
|
||||
int x, y;
|
||||
|
||||
/* We plot the first line pointwise, then memcpy() it for the
|
||||
* subsequent lines.
|
||||
*/
|
||||
|
||||
q = to;
|
||||
for( x = 0; x < clip.width; x++ ) {
|
||||
vips__draw_pel( draw, q );
|
||||
q += draw->psize;
|
||||
}
|
||||
|
||||
q = to + draw->lsize;
|
||||
for( y = 1; y < clip.height; y++ ) {
|
||||
memcpy( q, to, clip.width * draw->psize );
|
||||
q += draw->lsize;
|
||||
}
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_paintrect_class_init( VipsPaintrectClass *class )
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
|
||||
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
gobject_class->get_property = vips_object_get_property;
|
||||
|
||||
vobject_class->nickname = "paintrect";
|
||||
vobject_class->description = _( "paint a rectangle on an image" );
|
||||
vobject_class->build = vips_paintrect_build;
|
||||
|
||||
VIPS_ARG_INT( class, "left", 6,
|
||||
_( "Left" ),
|
||||
_( "Rect to fill" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsPaintrect, left ),
|
||||
-1000000000, 1000000000, 0 );
|
||||
|
||||
VIPS_ARG_INT( class, "top", 7,
|
||||
_( "top" ),
|
||||
_( "Rect to fill" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsPaintrect, top ),
|
||||
-1000000000, 1000000000, 0 );
|
||||
|
||||
VIPS_ARG_INT( class, "width", 8,
|
||||
_( "width" ),
|
||||
_( "Rect to fill" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsPaintrect, width ),
|
||||
-1000000000, 1000000000, 0 );
|
||||
|
||||
VIPS_ARG_INT( class, "height", 9,
|
||||
_( "height" ),
|
||||
_( "Rect to fill" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsPaintrect, height ),
|
||||
-1000000000, 1000000000, 0 );
|
||||
|
||||
VIPS_ARG_BOOL( class, "fill", 10,
|
||||
_( "Fill" ),
|
||||
_( "Draw a solid object" ),
|
||||
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||
G_STRUCT_OFFSET( VipsPaintrect, fill ),
|
||||
FALSE );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_paintrect_init( VipsPaintrect *paintrect )
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
vips_paintrectv( VipsImage *image,
|
||||
double *ink, int n, int left, int top, int width, int height,
|
||||
va_list ap )
|
||||
{
|
||||
VipsArea *area_ink;
|
||||
int result;
|
||||
|
||||
area_ink = (VipsArea *) vips_array_double_new( ink, n );
|
||||
result = vips_call_split( "paintrect", ap,
|
||||
image, area_ink, left, top, width, height );
|
||||
vips_area_unref( area_ink );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_paintrect:
|
||||
* @image: image to draw on
|
||||
* @ink: (array length=n): value to draw
|
||||
* @n: length of ink array
|
||||
* @left: area to paint
|
||||
* @top: area to paint
|
||||
* @width: area to paint
|
||||
* @height: area to paint
|
||||
*
|
||||
* Optional arguments:
|
||||
*
|
||||
* @fill: fill the rect
|
||||
*
|
||||
* Paint pixels within @left, @top, @width, @height in @image with @ink. If
|
||||
* @fill is zero, just paint a 1-pixel-wide outline.
|
||||
*
|
||||
* See also: vips_circle().
|
||||
*
|
||||
* Returns: 0 on success, or -1 on error.
|
||||
*/
|
||||
int
|
||||
vips_paintrect( VipsImage *image,
|
||||
double *ink, int n, int left, int top, int width, int height, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
va_start( ap, height );
|
||||
result = vips_paintrectv( image,
|
||||
ink, n, left, top, width, height, ap );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_paintrect1:
|
||||
* @image: image to draw on
|
||||
* @ink: (array length=n): value to draw
|
||||
* @n: length of ink array
|
||||
* @left: area to paint
|
||||
* @top: area to paint
|
||||
* @width: area to paint
|
||||
* @height: area to paint
|
||||
*
|
||||
* Optional arguments:
|
||||
*
|
||||
* @fill: fill the rect
|
||||
*
|
||||
* As vips_painrect(), but just takes a single double for @ink.
|
||||
*
|
||||
* See also: vips_paintrect().
|
||||
*
|
||||
* Returns: 0 on success, or -1 on error.
|
||||
*/
|
||||
int
|
||||
vips_paintrect1( VipsImage *image,
|
||||
double ink, int left, int top, int width, int height, ... )
|
||||
{
|
||||
double array_ink[1];
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
array_ink[0] = ink;
|
||||
|
||||
va_start( ap, height );
|
||||
result = vips_paintrectv( image,
|
||||
array_ink, 1, left, top, width, height, ap );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
@ -38,6 +38,16 @@
|
||||
extern "C" {
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
int vips_paintrect( VipsImage *image,
|
||||
double *ink, int n, int left, int top, int width, int height, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_paintrect1( VipsImage *image,
|
||||
double ink, int left, int top, int width, int height, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int vips_paintimage( VipsImage *image, VipsImage *sub, int x, int y, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int vips_paintmask( VipsImage *image,
|
||||
double *ink, int n, VipsImage *mask, int x, int y, ... )
|
||||
__attribute__((sentinel));
|
||||
@ -45,9 +55,6 @@ int vips_paintmask1( VipsImage *image,
|
||||
double ink, VipsImage *mask, int x, int y, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int vips_paintimage( VipsImage *image, VipsImage *sub, int x, int y, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int vips_line( VipsImage *image,
|
||||
double *ink, int n, int x1, int y1, int x2, int y2, ... )
|
||||
__attribute__((sentinel));
|
||||
@ -81,10 +88,6 @@ int vips_flood1( VipsImage *image, double ink, int x, int y, ... )
|
||||
|
||||
|
||||
|
||||
|
||||
int im_draw_rect( VipsImage *image,
|
||||
int left, int top, int width, int height, int fill, VipsPel *ink );
|
||||
|
||||
int im_draw_point( VipsImage *image, int x, int y, VipsPel *ink );
|
||||
int im_read_point( VipsImage *image, int x, int y, VipsPel *ink );
|
||||
|
||||
|
@ -1009,6 +1009,8 @@ typedef int (*VipsPlotFn)( VipsImage *, int, int, void *, void *, void * );
|
||||
int im_draw_mask( VipsImage *image,
|
||||
VipsImage *mask_im, int x, int y, VipsPel *ink );
|
||||
int im_draw_image( VipsImage *image, VipsImage *sub, int x, int y );
|
||||
int im_draw_rect( VipsImage *image,
|
||||
int left, int top, int width, int height, int fill, VipsPel *ink );
|
||||
|
||||
int im_draw_line_user( VipsImage *image,
|
||||
int x1, int y1, int x2, int y2,
|
||||
|
Loading…
Reference in New Issue
Block a user