#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;
}
};
} |