Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Jul 26, 2024
1 parent ce3b4cf commit 22f4cda
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 41 deletions.
78 changes: 44 additions & 34 deletions img/aafill.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,47 @@ advance_pointers(PIcon i, PRenderContext render)
}
}

static Bool
conversion_needed( Handle self, NPoint *pts, int n_pts, int rule, PImgPaintContext ctx, Bool *ok)
{
PIcon i = (PIcon) self;
int bpp = ( i->type & imGrayScale) ? imByte : imRGB;
Bool is_icon = kind_of(self, CIcon);
ImagePreserveTypeRec p;

if (i-> type != bpp || ( is_icon && i->maskType != imbpp8 )) {
i->self-> begin_preserve_type( self, &p );
if ( i->type != bpp ) {
img_resample_colors( self, bpp, ctx );
i->self-> set_type( self, bpp );
}
if ( is_icon && i->maskType != imbpp8 )
i->self->set_maskType( self, imbpp8 );
*ok = img_aafill( self, pts, n_pts, rule, ctx);
i-> self-> end_preserve_type( self, &p );
return true;
}

if ( ctx->tile != NULL_HANDLE ) {
PIcon tile = (PIcon) ctx->tile;
Bool tile_is_icon = kind_of( ctx->tile, CIcon );

/* can only do mono non-icon tiles or those that match bpp and type */
if (
tile->type != i->type &&
(tile_is_icon || tile->type != imBW)
) {
CImage(ctx->tile)-> begin_preserve_type( ctx->tile, &p );
CImage(ctx->tile)-> set_type( ctx->tile, i->type );
*ok = img_aafill( self, pts, n_pts, rule, ctx);
CImage(ctx->tile)-> end_preserve_type( ctx->tile, &p );
return true;
}
}

return false;
}

Bool
img_aafill( Handle self, NPoint *pts, int n_pts, int rule, PImgPaintContext ctx)
{
Expand All @@ -781,25 +822,10 @@ img_aafill( Handle self, NPoint *pts, int n_pts, int rule, PImgPaintContext ctx)
return aafill_inplace(self, pts, n_pts, rule);

/* align types and geometry - can only operate over imByte and imRGB and 8-bit icons */
if ( conversion_needed(self, pts, n_pts, rule, ctx, &ok))
return ok;

is_icon = kind_of(self, CIcon);
{
int bpp = ( i->type & imGrayScale) ? imByte : imRGB;
if (i-> type != bpp || ( is_icon && i->maskType != imbpp8 )) {
Bool ok;
ImagePreserveTypeRec p;

i->self-> begin_preserve_type( self, &p );
if ( i->type != bpp ) {
img_resample_colors( self, bpp, ctx );
i->self-> set_type( self, bpp );
}
if ( is_icon && i->maskType != imbpp8 )
i->self->set_maskType( self, imbpp8 );
ok = img_aafill( self, pts, n_pts, rule, ctx);
i-> self-> end_preserve_type( self, &p );
return ok;
}
}

bzero(&render, sizeof(render));
render.bpp = ( i->type & imBPP ) / 8;
Expand All @@ -824,22 +850,6 @@ img_aafill( Handle self, NPoint *pts, int n_pts, int rule, PImgPaintContext ctx)
ctx->patternOffset.y %= PImage(ctx->tile)->h;
ctx->patternOffset.x %= PImage(ctx->tile)->w;
dual_pattern = pattern = false;

/* can only do mono non-icon tiles or those that match bpp and type */
if (
tile->type != i->type &&
(tile_is_icon || tile->type != imBW)
) {
Bool ok;
ImagePreserveTypeRec p;

CImage(ctx->tile)-> begin_preserve_type( ctx->tile, &p );
CImage(ctx->tile)-> set_type( ctx->tile, i->type );
ok = img_aafill( self, pts, n_pts, rule, ctx);
CImage(ctx->tile)-> end_preserve_type( ctx->tile, &p );

return ok;
}
}

clip.left = clip.bottom = 0;
Expand Down
14 changes: 7 additions & 7 deletions t/Image/AAFill.t
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,23 @@ sub test_region
size => [6,6],
type => im::Byte,
);
$i->clear;
$i->region( Prima::Region->new( box => [
-5,-2,10,2,
-5,-1,10,2,
-5,2,10,1,
1,4,1,1,
3,4,10,3,
]));
$i->color(0xffffff);
$i->antialias(1);
$i->fillpoly([0,0,0,6,6,6,6,0]);
is_pict($i, "region",
"### ".
"# # ".
"######".
" #".
"######".
" #"
" ###".
" # ###".
" ".
"##### ".
" ".
"##### "
);
}

Expand Down

0 comments on commit 22f4cda

Please sign in to comment.