Jump to content
  • Advertisement
Sign in to follow this  
madmaurice

missing pixel after rotating

This topic is 3848 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

I made a "Rotate by 90 degrees"-function for my VideoEngine but one pixel is always missing. its the pixel down left in the corner. although the new position is calculated to 0,0 when rotating clockwise. it is not set. here is my rotate function
SDL_Surface* VideoManager::Surface_Rotate90(SDL_Surface* source, int mode) {
       Uint32 pixel;
       int dx,dy;
       if(mode != VideoManager::_ROTATE_CLOCKWISE && mode != VideoManager::_ROTATE_COUNTERCLOCKWISE) {
                return NULL;
       }
       SDL_Surface *dest = VideoManager::Create_Surface(source->h,source->w);
       SDL_FillRect(dest,(SDL_Rect*)NULL,SDL_MapRGB(dest->format,255,0,0));
       for(int y = 0; y < source->h; y++) {
                for(int x = 0; x < source->w; x++) {
                         pixel = VideoManager::getPixel(source, x, y);
                         if(mode == VideoManager::_ROTATE_CLOCKWISE) {
                                 dx = source->h - y;
                                 dy = x;
                         } else if(mode == VideoManager::_ROTATE_COUNTERCLOCKWISE) {
                                 dx = y;
                                 dy = source->w - x;
                         }
                         VideoManager::setUint32Pixel(dest, dx, dy, pixel);
                }
       }
       return dest;
}

Share this post


Link to post
Share on other sites
Advertisement
You're not just missing one pixel, but the entire left column and bottom row.

The image is defined on the domain [0, source->w - 1]×[0, source->h - 1]. Note the exclusivity. So when you compute

dx = source->h - y;

the interval becomes [1, source->h] and the row is lost. Similarly for dy. The correct code would use:

dx = source->h - y - 1;
dy = source->w - x - 1;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!