Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SMurf7

Scaling an image

This topic is 5962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Now don't get upset at the sight of my hideous code, I'm simply exploring how well I can convert a theory into a working model using simple code I've got an image in a buffer, size 192x144 and 8-bit colour depth, which I want to stretch onto the screen, size 320x200. Basically, I decided that for every 3rd pixel in the source image I want to draw it twice onto the screen (horizontal stretching) and for every three lines drawn I want to draw an additional copy underneath it (vertical stretching). I came up with this code:-
    
(accepting that x, y, j and k are ints and j and k are intitialised to 0...)

for (y=0;y<144;y++)
{
   for (x=0;x<192;x++)
   {
      if (x % 3 == 0)
         screen[(j*320)+k++] = buffer[(y*192)+x];
      screen[(j*320)+k++] = buffer[(y*192)+x];
   }
   if (y % 3 == 0)
      memcpy(screen+((j+1)*320), screen+(j++*320), k);
   j++;
}
  
Crap, hard-wired code, huh? I know this can be done in assembler at high speed, but I'd like to explore what actually occurs in pixel scaling before actually making better, more optimised versions of it. There seems to be a problem here somewhere, which results in the horizontal scaling being less than 320 (k = 256 at the end), and the vertical scaling seems to miss a line every 2 lines. (Incidentally, I also know that ((144 / 3) * 2) + 96, the number of vertical lines, doesn't equal 200, it equals 192, but 3 is the nearest integer that works in my current model ) Help me out here. Pretty please? Attack my rubbish code if you want, but leave me out of it! Edited by - SMurf7 on March 20, 2002 8:46:13 AM

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
if you would use an error term (like in a bresenham algorithm) instead of the "x % 3" stuff, the code would not only be as fast as your current version, but it would work under several conditions!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!