Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 3182fc8947d3ad7973afec34eefc16bc76da53f4 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
   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 *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__