-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmplib.h
82 lines (63 loc) · 1.88 KB
/
bmplib.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
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
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
/*a simple BMP library*/
#ifndef BMPLIB_H
#define BMPLIB_H
#define BITMAP_INFO_HEADER 1
typedef struct {
int width;
int height;
int channels;
uint8_t* data;
} ImageArray; //flat image array (without padding)
typedef struct __attribute__((__packed__)) {
char idField[2];
uint32_t fileSize;
char appData[4];
uint32_t arrOffset;
} BmpHeader;
typedef struct {
uint32_t headerSize;
int width;
int height;
uint16_t numColorPlanes;
uint16_t bitsPerPixel;
uint32_t compressionMethod;
uint32_t bmpDataSize;
uint32_t pixelsPerMeterHorizontal;
uint32_t pixelsPerMeterVertical;
uint32_t numColorsPalette;
uint32_t numImportantColors;
} WindowsBitmapInfoHeader;
typedef union {
WindowsBitmapInfoHeader windowsBitmapInfoHeader;
} DibHeader;
typedef struct {
uint8_t paddingSize;
BmpHeader bmpHeader;
DibHeader dibHeader;
int dibHeaderType;
uint8_t* bmpData;
} BmpImage;
ImageArray imageArray_init(int width,int height,int channels);
void imageArray_delete(ImageArray *imageArray);
BmpImage bmp_init(const ImageArray *imageArray);
void bmp_delete(BmpImage *bmpImage);
void bmp_save_file(const BmpImage *bmpImage,const char* fileName);
void _convert_to_bmp_data(uint8_t* src,uint8_t* dest,int paddingSize,int width,int height,int channels);
static inline void rgb_array_set_pixel(
ImageArray *imageArray,
unsigned int row,
unsigned int col,
uint8_t red,
uint8_t green,
uint8_t blue
){
imageArray->data[row*imageArray->channels*imageArray->width + col*imageArray->channels] = blue;
imageArray->data[row*imageArray->channels*imageArray->width + col*imageArray->channels + 1] = green;
imageArray->data[row*imageArray->channels*imageArray->width + col*imageArray->channels + 2] = red;
}
#endif /*BMPLIB_H*/