/* render/image.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_RENDER_IMAGE_H__ #define __INCLUDED_RENDER_IMAGE_H__ #include namespace render { /// RGB (24bpp) or RGBA (32bpp) image data class Image { public: Image(unsigned int width, unsigned int height, unsigned int channels); ~Image(); /// pointer to the raw image data inline unsigned char *ptr() { return image_data; } /// index into the raw image data inline unsigned char *operator[](size_t index) { return &image_data[index]; } inline unsigned char *pixel(size_t x, size_t y) { return &image_data[(y * image_width + x) * image_channels]; } /// width of the image in pixels inline unsigned int width() const { return image_width; } /// height of the image in pixels inline unsigned int height() const { return image_height; } /// size of the image data in bytes inline size_t size() const { return ((size_t) image_width *(size_t) image_height *(size_t) image_channels); } /// number of channels 3 (RGB) or 4 (RGBA) inline unsigned int channels() const { return image_channels; } /// bits per pixel inline unsigned int bpp() const { return (image_channels * 8); } /// set image data to zero void clear(); /// swap the red and blue channel values of the image void swap_channels(); /// flip upside-down void flip_vertical(); /// flip left-right void flip_horizontal(); /// pad width and height up to 8 bytes void pad(); /// load an image static Image *load(const std::string & name); private: unsigned char *image_data; unsigned int image_width; unsigned int image_height; unsigned int image_channels; }; } #endif // __INCLUDED_RENDER_IMAGE_H__