Re: [AD] stretch_blit bug

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sat, 2007-04-21 at 12:06 +1000, Peter Wang wrote:
> I found the thread:
> 
> http://sourceforge.net/mailarchive/message.php?msg_id=5.0.2.1.0.20030211014915.021cee90%40oishii.org
> 
> As usual, I don't remember any of it :P
> 

Ok, as I don't understand the Bresenham version used in cstretch.c
(which makes it hard to fix..), I tried writing up a simple
re-implementation of a stretch blit.

I'm not sure what bmp_select, bmp_write_line, bmp_write8 and
bmp_unwrite_line really do, I just tried to match their use with the
current implementation.

my_stretch8 is about 10% faster than the current stretch_blit (when
stretch a bitmap from 333x333 to 1000x1000), likely once wired in there
would be extra per-call overhead, so I'd say it has about the same
performance. But it's *much* simpler, and doesn't show that bug.

I'm going to try and replace cstretch.c with this one, but needs
clipping and color depths (i won't care about "mode X") and masking, so
it will take some time.

void my_stretch8(BITMAP *source, BITMAP *destination,
    int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
{
    int x, y;
    fixed fx, fy; /* fractional source position */
    fixed xi, yi; /* x and y increment */
    uintptr_t dptr;

    xi = itofix(sw) / dw;
    yi = itofix(sh) / dh;

    fy = itofix(sy) + yi / 2;
    fx = itofix(sx) + xi / 2;

    bmp_select(destination);

    for (y = dy; y < dy + dh; y++) {
        unsigned char *sptr = source->line[fixtoi(fy)];
        unsigned char *sptr2;
        fixed fx_backup = fx;
        dptr = bmp_write_line(destination, y) + dx;
        for (x = dx; x < dx + dw; x++) {
            sptr2 = sptr + fixtoi(fx);
            bmp_write8(dptr++, *sptr2);
            fx += xi;
        }
        fx = fx_backup;
        fy += yi;
    }
    bmp_unwrite_line(destination);
}

-- 
Elias Pschernig





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/