Mail Archives: djgpp/1998/04/20/18:31:32
Ishpeck writes:
>BITMAP *getimage(BITMAP *bmp2lookat, int x, int y, int w, int h) {
> BITMAP *returnme;
> int loopx, loopy;
> for(loopy=0;loopy<=h;loopy++)
> for(loopx=0;loopx<=w;loopx++)
> putpixel(returnme, loopx, loopy, getpixel(bmp2lookat, loopx+x,
>loopy+y));
> return returnme;
>} /* End getimage function */
Does this function actually work for you? If so you are incredibly
lucky, because there is no good reason why it should :-)
You are drawing pixels into the returnme image, but this is never
initialised anywhere, so it is pointing at a random memory location.
Also, your loops go one pixel too far along both axis: to copy exactly
the specified width and height number of pixels, the comparison should
be a less than, not less than or equal to.
But why do you need to do this at all, when Allegro already provides
just such a function? You can simply call blit() to do this copy, which
will be many times faster than repeated calls to getpixel() and
putpixel().
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa
- Raw text -