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
|
#ifndef __LIBJIN_BITMAP_H
#define __LIBJIN_BITMAP_H
#include "../jin_configuration.h"
#if LIBJIN_MODULES_RENDER
#include "../Math/Vector2.hpp"
#include "../3rdparty/GLee/GLee.h"
#include "Color.h"
namespace jin
{
namespace graphics
{
///
/// A RGBA32 bitmap.
///
/// A bitmap keeps pixels and can't render directly onto screen. To render bitmap,
/// a texture is required. A texture is create from specific bitmap.
///
class Bitmap
{
public:
///
/// 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.
/// @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();
/* init pixels */
void bind(Color* pixels, int w, int h);
void resetPixels(const Color* pixels, int w, int h);
void resetPixels(const Color& pixels, int w, int h);
/* modify pixels */
void setPixel(const Color& pixel, int x, int y);
void setPixels(Color pixels);
void setPixels(Color* pixels);
Color getPixel(int x, int y);
const Color* getPixels() const;
/* get width and height */
inline int getWidth() const { return width; }
inline int getHeight() const { return height; }
inline math::Vector2<int> getSize() const { return math::Vector2<int>(width, height); }
protected:
Bitmap();
Bitmap(unsigned w, unsigned h);
Color * pixels;
unsigned width, height;
};
} // namespace graphics
} // namespace jin
#endif
#endif
|