-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitmapSprite.h
More file actions
79 lines (65 loc) · 2.27 KB
/
BitmapSprite.h
File metadata and controls
79 lines (65 loc) · 2.27 KB
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
/*
BitmapSprite Class for use with SmartMatrix Library.
Sprites are 2D images with transparency that can be rendered at any position on the display.
Image data is loaded from BMP files on the SD Card.
*/
#ifndef BitmapSprite_h
#define BitmapSprite_h
#include <Arduino.h>
#include <MatrixCommon.h> // from SmartMatrix library
#include <memory>
class BitmapSprite {
public:
static void setDisplaySize(uint16_t displayWidth, uint16_t displayHeight);
int x = 0;
int y = 0;
uint8_t alpha = 255;
BitmapSprite();
BitmapSprite(const char* filename);
BitmapSprite(const char* filename, void* destination, size_t allocatedSize);
bool render(rgb24* buffer);
uint16_t width() { return wd; };
uint16_t height() { return abs(ht); };
private:
enum Format { // Supported BMP formats
RGB1, // 1bpp, indexed
RGB4, // 4bpp, indexed
RGB8, // 8bpp, indexed
XRGB16, // 16bpp, arbitrary bitmask with transparency
RGB24, // 24bpp, R8G8B8
ARGB32, // 32bpp, R8G8B8 or A8R8G8B8
XRGB32 // 32bpp, arbitrary bitmask with transparency
};
static uint16_t matrixWidth;
static uint16_t matrixHeight;
uint16_t wd = 0;
int16_t ht = 0;
uint fsize;
std::shared_ptr<uint8_t> bmpfile;
uint8_t* image = nullptr;
BitmapSprite::Format format;
uint8_t* palette = nullptr;
bool alphaChannel = false;
uint16_t rowBytes = 0;
uint32_t rMask = 0;
uint8_t rScale = 0;
uint8_t rShift = 0;
uint32_t gMask = 0;
uint8_t gScale = 0;
uint8_t gShift = 0;
uint32_t bMask = 0;
uint8_t bScale = 0;
uint8_t bShift = 0;
uint32_t aMask = 0;
uint8_t aScale = 0;
uint8_t aShift = 0;
void composite(rgb24* bufPtr, uint row, uint col);
void loadBitmap(const char* filename);
void loadBitmap(const char* filename, void* destination, size_t allocatedSize);
void parseHeader(uint8_t* ptr);
uint32_t read32(uint8_t* ptr);
uint16_t read16(uint8_t* ptr);
uint8_t maskToScale(uint32_t mask);
uint8_t maskToShift(uint32_t mask);
};
#endif