aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/je_bitmap.h
blob: 9d10106beca7fc8d02a4d7dd58a8382c71f1db73 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#ifndef __JE_BITMAP_H
#define __JE_BITMAP_H
#include "../core/je_configuration.h"
#if defined(jin_graphics)

#include "GLee/GLee.h"

#include "../common/je_types.h"
#include "../math/je_vector2.hpp"

#include "je_color.h"

namespace JinEngine
{
	namespace Graphics
	{

        /// 
        /// A RGBA32 bitmap.
        /// 
        /// A bitmap keeps pixels and can't draw directly onto screen. To render bitmap, a texture is required. A
        /// texture is a renderable hard ware side structure which could be handled with GPU. For instance, opengl
        /// create texture and store it in GPU memory for rendering them onto hdc.
        /// 
		class Bitmap
		{
		public:
            ///
            /// Create bitmap from given file.
            ///
            /// @param path Path of image file.
            /// @return Bitmap if create successful, otherwise retrun false.
            ///
            static Bitmap* createBitmap(const char* path);

            /// 
            /// Create bitmap by pixels data.
            /// 
            /// @param pixels Pixels data.
            /// @param width Width of bitmap.
            /// @param height Height of bitmap.
            /// @return Return bitmap pointer if created, otherwise return null.
            /// 
			static Bitmap* createBitmap(const void* pixels, unsigned width, unsigned height);

            /// 
            /// Create bitmap from compressed image data.
            /// 
            /// @param imgData Compressed image data. 
            /// @param size Size of image data.
            /// @return Return bitmap pointer if created, otherwise return null.
            /// 
			static Bitmap* createBitmap(const void* imgData, size_t size);

            /// 
            /// Create bitmap with specific color and size.
            /// 
            /// @param width Width of bitmap. 
            /// @param height Height of bitmap. 
            /// @param color Color of bitmap, black by default.
            /// @return Return bitmap pointer if created, otherwise return null.
            /// 
			static Bitmap* createBitmap(int width, int height, Color color = Color::BLACK);

            /// 
            /// Create bitmap with another one. 
            /// 
            /// @param bitmap Bitmap be cloned.
            /// @return Return bitmap pointer if created, otherwise return null.
            /// 
			static Bitmap* clone(const Bitmap* bitmap);

            /// 
            /// Destructor of bitmap
            /// 
			virtual ~Bitmap();

            /// 
            /// Directly bind pixels with given pixels data
            /// 
            /// @param pixels Pixels to be binded. 
            /// @param width Width of bitmap 
            /// @param height Height of bitmap 
            /// 
			void bind(Color* pixels, int width, int height);

            /// 
            /// Reset pixel data with given pixels data. 
            /// 
            /// @param pixels Pixels to be set.
            /// @param width Width of bitmap 
            /// @param height Height of bitmap 
            /// 
			void resetPixels(const Color* pixels, int width, int height);

            /// 
            /// Reset pixel data with given color. 
            /// 
            /// @param color Color to be set.
            /// @param width Width of bitmap 
            /// @param height Height of bitmap 
            ///
			void resetPixels(const Color& color, int width, int height);

            /// 
            /// Set pixel with given color.
            /// 
            /// @param color Color to be set. 
            /// @param x X value of pixel. 
            /// @param y Y value of pixel.
            /// 
			void setPixel(const Color& color, int x, int y);

            /// 
            /// Set pixels with given color. 
            /// 
            /// @param color Color to be set.
            /// 
			void setPixels(Color color);

            /// 
            /// Set pixels with given color data.
            /// 
            /// @param colors New pixels' colors.
            /// 
			void setPixels(Color* colors);

            /// 
            /// Get pixel in given position.
            /// 
            /// @param x X value of position. 
            /// @param y Y value of position.
            /// 
			Color getPixel(int x, int y);

            /// 
            /// Get pixels. 
            /// @return Colors of the bitmap.
            /// 
			const Color* getPixels() const;

            /// 
            /// Get bitmap width.
            /// 
            /// @return Width of bitmap.
            /// 
			inline int getWidth() const { return width; }

            /// 
            /// Get bitmap height.
            /// 
            /// @return Height of bitmap.
            /// 
			inline int getHeight() const { return height; }

            /// 
            /// Get bitmap size.
            /// 
            /// @return Size of bitmap.
            /// 
			inline Math::Vector2<int> getSize() const { return Math::Vector2<int>(width, height); }

		protected:
            /// 
            /// Constructor of bitmap.
            /// 
			Bitmap();

            /// 
            /// Constructor of bitmap.  
            /// 
            /// @param width Width of bitmap.
            /// @param height Height of bitmap.
            /// 
			Bitmap(unsigned w, unsigned h);

			Color * pixels;
			unsigned width, height;

		};

	} // namespace Graphics
} // namespace JinEngine

#endif

#endif