Looking for routine to expand bitmap
Doug Gwyn
gwyn at smoke.BRL.MIL
Wed Aug 9 07:15:58 AEST 1989
In article <8917 at attctc.Dallas.TX.US> bobc at attctc.Dallas.TX.US (Bob Calbridge) writes:
>Is there a general algorithm for handling this type of expansion?
static void
Magnify( b, r, tb, p, fac ) /* adapted from "lens" */
register Bitmap *b, *tb;
Rectangle r;
Point p, fac;
{
register Bitmap *stage;
register int i, shift;
Point d;
Rectangle s;
#if 0
if ( fac.x < 1 || fac.y < 1 ) /* "can't happen" */
return;
#endif
d = sub( r.corner, r.origin );
s.origin = p;
s.corner = add( p, Pt( fac.x * d.x, fac.y * d.y ) );
/* Copy source into origin of dest */
bitblt( b, r, tb, p, F_STORE );
/* Clear rest of dest */
rectf( tb, Rect( s.origin.x + d.x, s.origin.y,
s.corner.x, s.corner.y
),
F_CLR
);
rectf( tb, Rect( s.origin.x, s.origin.y + d.y,
s.origin.x + d.x, s.corner.y
),
F_CLR
);
/* Now we expand in place */
/* 1: expand horizontally */
if ( fac.x > 1 )
for( i = d.x - 1; i > 0; --i )
{
bitblt( tb, Rect( p.x + i, p.y, p.x + i + 1, p.y + d.y),
tb, Pt( p.x + i * fac.x, p.y ), F_OR
);
rectf( tb, Rect( p.x + i, p.y, p.x + i + 1, p.y + d.y ),
F_CLR
);
}
/* 2: smear horizontally */
for( i = 1; i < fac.x; i *= 2 )
{
shift = min( i, fac.x - i );
bitblt( tb, Rect( p.x, p.y, s.corner.x - shift, p.y + d.y ),
tb, Pt( p.x + shift, p.y ), F_OR
);
}
/* 3: expand vertically */
if ( fac.y > 1 )
for ( i = d.y - 1; i > 0; --i )
{
bitblt( tb, Rect( p.x, p.y + i, s.corner.x, p.y + i + 1
),
tb, Pt( p.x, p.y + i * fac.y ), F_OR
);
rectf( tb, Rect( p.x, p.y + i, s.corner.x, p.y + i + 1
),
F_CLR
);
}
/* 4: smear vertically */
for ( i = 1; i < fac.y; i *= 2 )
{
shift = min( i, fac.y - i );
bitblt( tb, Rect( p.x, p.y, s.corner.x, s.corner.y - shift ),
tb, Pt( p.x, p.y + shift ), F_OR
);
}
}
More information about the Comp.lang.c
mailing list