1 // This code is in the public domain -- castanyo@yahoo.es
2 
3 #ifndef NV_IMAGE_IMAGE_H
4 #define NV_IMAGE_IMAGE_H
5 
6 #include <nvcore/Debug.h>
7 #include <nvimage/nvimage.h>
8 
9 namespace nv
10 {
11 	class Color32;
12 
13 	/// 32 bit RGBA image.
14 	class NVIMAGE_CLASS Image
15 	{
16 	public:
17 
18 		enum Format
19 		{
20 			Format_RGB,
21 			Format_ARGB,
22 		};
23 
24 		Image();
25 		Image(const Image & img);
26 		~Image();
27 
28 		const Image & operator=(const Image & img);
29 
30 
31 		void allocate(uint w, uint h);
32 		bool load(const char * name);
33 
34 		void wrap(void * data, uint w, uint h);
35 		void unwrap();
36 
37 		uint width() const;
38 		uint height() const;
39 
40 		const Color32 * scanline(uint h) const;
41 		Color32 * scanline(uint h);
42 
43 		const Color32 * pixels() const;
44 		Color32 * pixels();
45 
46 		const Color32 & pixel(uint idx) const;
47 		Color32 & pixel(uint idx);
48 
49 		const Color32 & pixel(uint x, uint y) const;
50 		Color32 & pixel(uint x, uint y);
51 
52 		Format format() const;
53 		void setFormat(Format f);
54 
55 		void fill(Color32 c);
56 
57 	private:
58 		void free();
59 
60 	private:
61 		uint m_width;
62 		uint m_height;
63 		Format m_format;
64 		Color32 * m_data;
65 	};
66 
67 
pixel(uint x,uint y)68 	inline const Color32 & Image::pixel(uint x, uint y) const
69 	{
70 		nvDebugCheck(x < width() && y < height());
71 		return pixel(y * width() + x);
72 	}
73 
pixel(uint x,uint y)74 	inline Color32 & Image::pixel(uint x, uint y)
75 	{
76 		nvDebugCheck(x < width() && y < height());
77 		return pixel(y * width() + x);
78 	}
79 
80 } // nv namespace
81 
82 
83 #endif // NV_IMAGE_IMAGE_H
84