Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: c7add6f26d58f0e7fedb6c8f144b81f7b2a3816f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
   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 <string>

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 *data() { return image_data; }

	/// index into the raw image data
	inline unsigned char *operator[](size_t index) { return &image_data[index]; }

	/// 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();

	/// pad width and height up to 8 bytes
	void pad();

private:
	unsigned char 		*image_data;

	unsigned int		image_width;
	unsigned int		image_height;
	unsigned int		image_channels;
};

}

#endif // __INCLUDED_RENDER_IMAGE_H__