delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/20/18:31:32

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A cool thing...
Date: Mon, 20 Apr 1998 18:52:28 +0100
Organization: None
Message-ID: <rVbdvaAct4O1Ew4m@talula.demon.co.uk>
References: <353B895B DOT BEDEE7A5 AT sprynet DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 29
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019