|
From: Marlon <ma...@on...> - 2004-11-18 14:21:22
|
Some week ago I asked how to replicate bitmap pattern for filling a polygon
in a similar way that Gdi+ do, with flags for bitmap replication, for
example:
<] is a bitmap,
<],<],<] is a normal replication like in Agg,
<],[>,<] is with flag FlipX, etc...
I solved problem, (actually Maxim helped) by creating temporary bitmap cache
by 2x2 bitmap size with desired replication and using it with
span_pattern_filter_rgba32_bilinear.
But I think there must be more elegant way;
Question:
can I use custom interpolator to control replication? Something like this:
//########
template<class Transformer = trans_affine, unsigned SubpixelShift = 8>
class span_interpolator_linear_mirror :
public span_interpolator_linear<Transformer, SubpixelShift>
{
public:
typedef span_interpolator_linear<Transformer, SubpixelShift> base_type;
//--------------------------------------------------------------------
span_interpolator_linear_mirror(const trans_type& trans, unsigned
nMirrorX=0, unsigned nMirrorY=0) :
base_type(trans), mirror_x(nMirrorX<<subpixel_shift),
mirror_y(nMirrorY<<subpixel_shift) { }
//----------------------------------------------------------------
void coordinates(int* x, int* y) const
{
int zx, zy;
base_type::coordinates(&zx, &zy);
if(mirror_x) { *x=
mirror_x-1-(abs((((zx%(mirror_x<<1))-mirror_x)<<1)+1)>>1); }
else { *x=zx; }
if(mirror_y) { *y=
mirror_y-1-(abs((((zy%(mirror_y<<1))-mirror_y)<<1)+1)>>1); }
else { *y=zy; }
//this gargantuan formula is actually
//*x= ((zx%(2*mirror_x)) < mirror_x) ?
// zx%mirror_x : //normal
// mirror_x-1-(zx%mirror_x); //mirror
}
private:
unsigned mirror_x, mirror_y;
};
in nMirrorX, nMirrorY is width and height of bitmap, sorry about messy code
:)
Now it works, but about 30% slower than original.
Is there a better solution?
Thanks,
Marlon
-
|