-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmap.h
48 lines (40 loc) · 1.41 KB
/
bitmap.h
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
#ifndef RENDER_BITMAP_H
#define RENDER_BITMAP_H
#include "common.h"
#define BMP_MAGIC 0x4d42
#define BMP_COLOR(r, g, b) \
&(RGBTRIPLE) { b, g, r }
#define BMP_GRAY_SCALE(v) \
&(RGBTRIPLE) { v, v, v }
#pragma pack(push)
#pragma pack(1)
typedef struct tagBITMAPFILEHEADER {
uint16_t bfType;
uint32_t bfSize;
uint16_t bfReserved1;
uint16_t bfReserved2;
uint32_t bfOffBits;
} BITMAPFILEHEADER;
typedef struct tagBITMAPCOREHEADER {
uint32_t bcSize;
uint16_t bcWidth;
uint16_t bcHeight;
uint16_t bcPlanes;
uint16_t bcBitCount;
} BITMAPCOREHEADER;
typedef struct tagRGBTRIPLE {
uint8_t rgbtBlue;
uint8_t rgbtGreen;
uint8_t rgbtRed;
} RGBTRIPLE;
#pragma pack(pop)
typedef struct tagBitmap {
BITMAPFILEHEADER fileHeader;
BITMAPCOREHEADER dibHeader;
RGBTRIPLE *pixels; // bottom-up
} Bitmap;
Bitmap *BitmapNewImage(uint16_t width, uint16_t height);
bool BitmapDestroy(Bitmap *bitmap);
bool BitmapWriteFile(const Bitmap *bitmap, const char *filename);
bool BitmapSetPixelColor(Bitmap *bitmap, uint16_t x, uint16_t y, const RGBTRIPLE *color);
#endif // RENDER_BITMAP_H