🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #642

Rotating a bitmap

#642
From: Steve Madsen
Date: Mon, 28 Sep 1992 05:07
67 lines
2619 bytes
        First off, this deals with Turbo C++ 1.0 and 256 color VGA graphics.

        I've got a problem with some code I'm trying to develop to rotate an
image.  This is pretty basic stuff.  All I'm trying to do is have an image in
putimage() format, pass a couple of pointers to memory and an angle to rotate,
and have the destination image be the rotated version of the source.  I've got
most of the thing completed, but it just does not work right and I've spent
about 4 1/2 hours trying to debug it.

        So, if any cares to look at the code and see what's wrong, or maybe
knows where I can look for some information on this type of thing, PLEASE let
me know!

        Code follows .sig...

-- 
Steve Madsen
Miami University  Oxford, OH
Internet: sjmadsen@miavx1.acs.muohio.edu

--
/**************************************************************************
   rotateimage:
 
   Rotates an image in putimage format "angle" degrees.  The resulting
   image is stored at "dest".
**************************************************************************/
 
void rotateimage(char *src, char *dest, int angle)
{
  double hypotenuse;
  double theta;
  double radians;
  int x, y;
  int dx, dy;
  int width = src[0] + src[1] * 256;
  int height = src[2] + src[3] * 256;
  int centerx = width / 2, centery = height / 2;
 
  // First fill up the destination memory with "normal" values:
 
  dest[0] = src[0];
  dest[1] = src[1];
  dest[2] = src[2];
  dest[3] = src[3];
  for (x = 0; x < width * height; x++)
    dest[x + 4] = 0;
 
  angle = angle % 360;  // reduce & adjust for clockwise rotation
  radians = (M_PI / 180) * angle; // convert degrees -> radians
  for (y = 0; y < height; y++)
    for (x = 0; x < width; x++) {
      dx = x - centerx;
      dy = y - centery;
      hypotenuse = sqrt((double)(dx * dx) + (double)(dy * dy));
      if (hypotenuse == 0.0) {
        dx = x;
        dy = y;
      } else {
        theta = asin(dy / hypotenuse);
        dx = cos(theta + radians) * hypotenuse;
        dy = sin(theta + radians) * hypotenuse;
      }
      if (dx >= 0 && dx < width && dy >= 0 && dy < height)
        dest[dy * width + dx + 4] = src[y * width + x + 4];
    }
}
Technical Details
Message-ID: <1992Sep28.000708.13175@miavx1.acs.muohio.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!wupost!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!ohstpy!miavx1!sjmadsen

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!wupost!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!ohstpy!miavx1!sjmadsen
Newsgroups: alt.msdos.programmer
Subject: Rotating a bitmap
Message-ID: <1992Sep28.000708.13175@miavx1.acs.muohio.edu>
From: sjmadsen@miavx1.acs.muohio.edu (Steve Madsen)
Date: 28 Sep 92 00:07:08 -0500
Organization: Miami of Ohio
Lines: 67