Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Image flipping
Index -> General Programming
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Thu Aug 26, 2004 8:04 pm   Post subject: (No subject)

Just thinking about this more...

code:
#include <algorithm>

namespace my_stuff
{
   tamplate <int width, int height, int bytes_per_pixel>
   class image
   {
      private:
         GLubyte * const image_start;
         const int bytes_per_row;
      public:
         image(GLubyte * const init_image_start)
         : image_start(init_image_start)
         , bytes_per_row(width * bytes_per_pixel)
         {  }

         GLubyte * const get_row(const int row) const
         {
            return image_start + row * bytes_per_row;
         }

         GLubyte * const copy_row(const int row) const
         {
            GLubyte * const new_row = new GLubyte[bytes_per_row];
            GLubyte * const start_of_old_row = get_row(row);
            std::copy(start_of_old_row, start_of_old_row + bytes_per_row, new_row);
            return new_row;
         }

         void swap_rows(const int first_row_number, const int second_row_number)
         {
            GLubyte * const first_row = get_row(first_row_number);
            GLubyte * const second_row = get_row(second_row_number);
            GLubyte * const backup = copy_row(first_row_number);

            std::copy(second_row, second_row + bytes_per_row, first_row);
            std::copy(back_up, back_up + bytes_per_row, second_row);

            delete [] backup;           
         }
   };
}


Usage might look something like:

code:
my_stuff::image<128, 128, 4> * my_image = new my_stuff::image<128, 128, 4>(pixels);

for (int i = 0; i < 64; i++)
{
   my_image->swap_rows(i, 127 - i);
}

delete my_image;


Edit: congrats on getting it to work.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 16 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: