diff --git a/TODO b/TODO index 2298f40f..cfef0853 100644 --- a/TODO +++ b/TODO @@ -5,8 +5,6 @@ make a region, prepare to that, copy back over the image? -- draw_rect is broken - - smudge is too strong ... tone it down a bit - can we make more use of im__draw_pel()? eg. im_draw_rect() etc. diff --git a/libvips/inplace/im_draw_rect.c b/libvips/inplace/im_draw_rect.c index 921118fe..63d5f532 100644 --- a/libvips/inplace/im_draw_rect.c +++ b/libvips/inplace/im_draw_rect.c @@ -56,6 +56,8 @@ #include +#include "draw.h" + #ifdef WITH_DMALLOC #include #endif /*WITH_DMALLOC*/ @@ -78,63 +80,63 @@ * Returns: 0 on success, or -1 on error. */ int -im_draw_rect( IMAGE *im, +im_draw_rect( IMAGE *image, int left, int top, int width, int height, int fill, PEL *ink ) { - int es = IM_IMAGE_SIZEOF_ELEMENT( im ); - int ps = es * im->Bands; - int ls = ps * im->Xsize; + Rect im, rect, clipped; + Draw draw; - Rect image, rect, clipped; - int x, y, b; + 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; PEL *to; 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 ) ) - return( -1 ); - /* Find area we plot. */ - image.left = 0; - image.top = 0; - image.width = im->Xsize; - image.height = im->Ysize; + 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, &image, &clipped ); + 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 = (PEL *) IM_IMAGE_ADDR( im, clipped.left, clipped.top ); + to = (PEL *) IM_IMAGE_ADDR( image, clipped.left, clipped.top ); + q = to; - for( x = 0; x < clipped.width; x++ ) - for( b = 0; b < ps; b++ ) { - q[b] = ink[b]; - - q += ps; - } - - q = to + ls; - for( y = 1; y < clipped.height; y++ ) { - memcpy( q, to, clipped.width * ps ); - q += ls; + 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 ); } diff --git a/libvips/inplace/im_draw_smudge.c b/libvips/inplace/im_draw_smudge.c index 49a67611..62d5306d 100644 --- a/libvips/inplace/im_draw_smudge.c +++ b/libvips/inplace/im_draw_smudge.c @@ -100,8 +100,8 @@ im_draw_smudge( VipsImage *im, int left, int top, int width, int height ) return( 0 ); if( !blur ) { - blur = im_create_imaskv( "im_draw_smudge", 3, 1, 1, 1, 1 ); - blur->scale = 3; + blur = im_create_imaskv( "im_draw_smudge", 3, 1, 1, 2, 1 ); + blur->scale = 4; } if( !(t[0] = im_open( "im_draw_smudge", "p" )) )