im_region_black() etc.

This commit is contained in:
John Cupitt 2010-01-27 14:40:24 +00:00
parent 8d17720212
commit 95a57de46c
8 changed files with 74 additions and 70 deletions

View File

@ -61,7 +61,7 @@
static int
black_gen( REGION *or, void *seq, void *a, void *b )
{
im__black_region( or );
im_region_black( or );
return( 0 );
}

View File

@ -18,6 +18,8 @@
* - added IM_CODING_RAD support
* 5/11/09
* - gtkdoc
* 27/1/10
* - use im_region_paint()
*/
/*
@ -81,27 +83,6 @@ typedef struct _Embed {
Rect border[8];
} Embed;
/* Paint 'value' into an area of a region. 0/255 for value usually.
*/
static void
embed_paint_rect( REGION *or, Rect *r, int value )
{
Rect ovl;
im_rect_intersectrect( r, &or->valid, &ovl );
if( !im_rect_isempty( &ovl ) ) {
PEL *q = (PEL *) IM_REGION_ADDR( or, ovl.left, ovl.top );
int wd = ovl.width * IM_IMAGE_SIZEOF_PEL( or->im );
int ls = IM_REGION_LSKIP( or );
int y;
for( y = 0; y < ovl.height; y++ ) {
memset( (char *) q, value, wd );
q += ls;
}
}
}
/* r is the bit we are trying to paint, guaranteed to be entirely within
* border area i. Set out to be the edge of the image we need to paint the
* pixels in r.
@ -257,7 +238,7 @@ embed_gen( REGION *or, void *seq, void *a, void *b )
/* Paint the borders a solid value.
*/
for( i = 0; i < 8; i++ )
embed_paint_rect( or, &embed->border[i],
im_region_paint( or, &embed->border[i],
embed->flag == 0 ? 0 : 255 );
break;

View File

@ -123,20 +123,6 @@ just_one( REGION *or, REGION *ir, int x, int y )
return( 0 );
}
/* Black out a region.
*/
static void
black_region( REGION *reg )
{
PEL *q = (PEL *) IM_REGION_ADDR( reg, reg->valid.left, reg->valid.top );
int wd = IM_REGION_SIZEOF_LINE( reg );
int ls = IM_REGION_LSKIP( reg );
int y;
for( y = 0; y < reg->valid.height; y++, q += ls )
memset( (char *) q, 0, wd );
}
/* Paste in parts of ir that fall within or --- ir is an input REGION for an
* image positioned at pos within or.
*/
@ -199,7 +185,7 @@ insert_gen( REGION *or, void *seq, void *a, void *b )
/* Could be clever --- but just black the whole thing for
* simplicity.
*/
black_region( or );
im_region_black( or );
/* Paste from main.
*/

View File

@ -226,7 +226,6 @@ int im__find_best_contrast( IMAGE *image,
int nbest, int hcorsize );
int im__balance( IMAGE *ref, IMAGE *sec, IMAGE *out,
IMAGE **ref_out, IMAGE **sec_out, int dx, int dy, int balancetype );
void im__black_region( REGION *reg );
void imb_Lab2LCh( float *, float *, int );
void imb_LCh2Lab( float *, float *, int );

View File

@ -76,6 +76,9 @@ int im_region_region( REGION *reg, REGION *to, Rect *r, int x, int y );
int im_region_equalsregion( REGION *reg1, REGION *reg2 );
int im_region_position( REGION *reg1, int x, int y );
void im_region_paint( REGION *reg, Rect *r, int value );
void im_region_black( REGION *reg );
/* Macros on REGIONs.
* IM_REGION_LSKIP() add to move down line
* IM_REGION_N_ELEMENTS() number of elements across region

View File

@ -754,22 +754,71 @@ im_region_fill( REGION *reg, Rect *r, im_region_fill_fn fn, void *a )
return( 0 );
}
/* Handy for debug.
/**
* im_region_print:
* @reg: region to operate upon
*
* Print out interesting fields from @reg. Handy for debug.
*/
void
im_region_print( REGION *region )
im_region_print( REGION *reg )
{
printf( "REGION: %p, ", region );
printf( "im = %p, ", region->im );
printf( "valid.left = %d, ", region->valid.left );
printf( "valid.top = %d, ", region->valid.top );
printf( "valid.width = %d, ", region->valid.width );
printf( "valid.height = %d, ", region->valid.height );
printf( "type = %d, ", region->type );
printf( "data = %p, ", region->data );
printf( "bpl = %d, ", region->bpl );
printf( "seq = %p, ", region->seq );
printf( "thread = %p, ", region->thread );
printf( "window = %p, ", region->window );
printf( "buffer = %p\n", region->buffer );
printf( "REGION: %p, ", reg );
printf( "im = %p, ", reg->im );
printf( "valid.left = %d, ", reg->valid.left );
printf( "valid.top = %d, ", reg->valid.top );
printf( "valid.width = %d, ", reg->valid.width );
printf( "valid.height = %d, ", reg->valid.height );
printf( "type = %d, ", reg->type );
printf( "data = %p, ", reg->data );
printf( "bpl = %d, ", reg->bpl );
printf( "seq = %p, ", reg->seq );
printf( "thread = %p, ", reg->thread );
printf( "window = %p, ", reg->window );
printf( "buffer = %p\n", reg->buffer );
}
/**
* im_region_paint:
* @reg: region to operate upon
* @r: area to paint
* @value: value to paint
*
* Paints @value into @reg covering rectangle @r. @value is passed to
* memset(), so it usually needs to be 0 or 255. @r is clipped against
* @reg->valid.
*
* See also: im_region_black().
*/
void
im_region_paint( REGION *reg, Rect *r, int value )
{
Rect ovl;
im_rect_intersectrect( r, &reg->valid, &ovl );
if( !im_rect_isempty( &ovl ) ) {
PEL *q = (PEL *) IM_REGION_ADDR( reg, ovl.left, ovl.top );
int wd = ovl.width * IM_IMAGE_SIZEOF_PEL( reg->im );
int ls = IM_REGION_LSKIP( reg );
int y;
for( y = 0; y < ovl.height; y++ ) {
memset( (char *) q, value, wd );
q += ls;
}
}
}
/**
* im_region_black:
* @reg: region to operate upon
*
* Paints 0 into the valid part of @reg.
*
* See also: im_region_paint().
*/
void
im_region_black( REGION *reg )
{
im_region_paint( reg, &reg->valid, 0 );
}

View File

@ -890,20 +890,6 @@ im__copy_input( REGION *or, REGION *ir, Rect *area, Rect *reg )
return( 0 );
}
/* Black out a region.
*/
void
im__black_region( REGION *reg )
{
PEL *q = (PEL *) IM_REGION_ADDR( reg, reg->valid.left, reg->valid.top );
int wd = IM_REGION_SIZEOF_LINE( reg );
int ls = IM_REGION_LSKIP( reg );
int y;
for( y = 0; y < reg->valid.height; y++, q += ls )
memset( (char *) q, 0, wd );
}
/* Generate function for merge. This is shared between im_lrmerge() and
* im_tbmerge().
*/
@ -946,7 +932,7 @@ im__merge_gen( REGION *or, void *seq, void *a, void *b )
im_rect_intersectrect( r, &ovlap->sarea, &sreg );
im_rect_intersectrect( r, &ovlap->overlap, &oreg );
im__black_region( or );
im_region_black( or );
if( !im_rect_isempty( &rreg ) )
if( im__copy_input( or,
inf->rir, &ovlap->rarea, &rreg ) )

View File

@ -245,7 +245,7 @@ affinei_gen( REGION *or, void *seq, void *a, void *b )
/* Outside input image? All black.
*/
if( im_rect_isempty( &clipped ) ) {
im__black_region( or );
im_region_black( or );
return( 0 );
}