EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-doc-5.1.2
bmp.h
1  /*************************************************************************/
16 #ifndef __BMP_H_
17 #define __BMP_H_
18 
19 /* C Standard header files */
20 #include <stdlib.h>
21 #include <stdint.h>
22 
23 /* EM types */
24 #include "em_types.h"
25 
26 #include "bmp_conf.h"
27 
28 /***************************************************************************/
34 #define ECODE_BMP_BASE 0x00000000
35 
36 /* Error codes */
38 #define BMP_OK 0x00000000
39 
40 #define BMP_END_OF_FILE
41 
42 #define BMP_ERROR_IO (ECODE_BMP_BASE | 0x0001)
43 
44 #define BMP_ERROR_HEADER_SIZE_MISMATCH (ECODE_BMP_BASE | 0x0002)
45 
46 #define BMP_ERROR_ENDIAN_MISMATCH (ECODE_BMP_BASE | 0x0003)
47 
48 #define BMP_ERROR_FILE_NOT_SUPPORTED (ECODE_BMP_BASE | 0x0004)
49 
50 #define BMP_ERROR_FILE_INVALID (ECODE_BMP_BASE | 0x0005)
51 
52 #define BMP_ERROR_INVALID_ARGUMENT (ECODE_BMP_BASE | 0x0006)
53 
54 #define BMP_ERROR_MODULE_NOT_INITIALIZED (ECODE_BMP_BASE | 0x0007)
55 
56 #define BMP_ERROR_INVALID_PALETTE_SIZE (ECODE_BMP_BASE | 0x0008)
57 
58 #define BMP_ERROR_FILE_NOT_RESET (ECODE_BMP_BASE | 0x0009)
59 
60 #define BMP_ERROR_END_OF_FILE (ECODE_BMP_BASE | 0x0010)
61 
62 #define BMP_ERROR_BUFFER_TOO_SMALL (ECODE_BMP_BASE | 0x0020)
63 
64 #define BMP_ERROR_PALETTE_NOT_READ (ECODE_BMP_BASE | 0x0030)
65 
67 #define BMP_PALETTE_8BIT_SIZE (256 * 4)
68 
69 #define BMP_HEADER_SIZE (54)
70 
71 #define BMP_LOCAL_CACHE_LIMIT (3)
72 
74 #define RLE8_COMPRESSION (1)
75 
76 #define NO_COMPRESSION (0)
77 
79 #define BMP_LOCAL_CACHE_SIZE (BMP_CONFIG_LOCAL_CACHE_SIZE)
80 
83 #if defined ( __GNUC__ )
85 #else
86 __packed struct __BMP_Header
87 #endif
88 {
90  uint16_t magic;
92  uint32_t fileSize;
94  uint16_t reserved1;
96  uint16_t reserved2;
98  uint32_t dataOffset;
100  uint32_t headerSize;
102  uint32_t width;
104  uint32_t height;
106  uint16_t colorPlanes;
108  uint16_t bitsPerPixel;
110  uint32_t compressionType;
112  uint32_t imageDataSize;
114  uint32_t hPixelsPerMeter;
116  uint32_t vPixelsPerMeter;
118  uint32_t colorsUsed;
120  uint32_t colorsRequired;
121 #if defined ( __GNUC__ )
122 } __attribute__ ((__packed__));
123 #else
124 };
125 #endif
126 
127 typedef struct __BMP_Header BMP_Header;
128 
131 typedef struct __BMP_Palette
132 {
134  uint8_t *data;
136  uint32_t size;
137 } BMP_Palette;
138 
141 typedef struct __BMP_DataType
142 {
144  uint16_t bitsPerPixel;
146  uint32_t compressionType;
148  uint32_t size;
150  uint32_t endOfRow;
151 } BMP_DataType;
152 
153 
154 /* Module prototypes */
155 EMSTATUS BMP_init(uint8_t *palette, uint32_t paletteSize, EMSTATUS (*fp)(uint8_t buffer[], uint32_t bufLength, uint32_t bytesToRead));
156 EMSTATUS BMP_reset(void);
157 EMSTATUS BMP_readRgbData(uint8_t buffer[], uint32_t bufLength, uint32_t *pixelsRead);
158 EMSTATUS BMP_readRawData(BMP_DataType *dataType, uint8_t buffer[], uint32_t bufLength);
159 
160 /* Accessor functions */
161 int32_t BMP_getWidth(void);
162 int32_t BMP_getHeight(void);
163 int16_t BMP_getBitsPerPixel(void);
164 int32_t BMP_getCompressionType(void);
165 int32_t BMP_getImageDataSize(void);
166 int32_t BMP_getDataOffset(void);
167 int32_t BMP_getFileSize(void);
168 
171 #endif /* __BMP_H_ */
EMSTATUS BMP_reset(void)
Makes the module ready for new bmp file. Reads in header from file, and checks if the provided bmp fi...
Definition: bmp.c:131
uint32_t colorsRequired
Definition: bmp.h:120
uint32_t size
Definition: bmp.h:136
uint32_t compressionType
Definition: bmp.h:146
struct __BMP_DataType BMP_DataType
BMP Data type structure to hold information about the bmp data returned.
uint32_t height
Definition: bmp.h:104
uint16_t reserved1
Definition: bmp.h:94
uint32_t fileSize
Definition: bmp.h:92
uint8_t * data
Definition: bmp.h:134
uint32_t size
Definition: bmp.h:148
uint32_t colorsUsed
Definition: bmp.h:118
int32_t BMP_getHeight(void)
Get height of BMP image in pixels.
Definition: bmp.c:938
uint16_t magic
Definition: bmp.h:90
BMP palette structure to hold palette pointer and size.
Definition: bmp.h:131
uint32_t compressionType
Definition: bmp.h:110
uint16_t reserved2
Definition: bmp.h:96
int32_t BMP_getWidth(void)
Get width of BMP image in pixels.
Definition: bmp.c:924
uint32_t vPixelsPerMeter
Definition: bmp.h:116
int32_t BMP_getCompressionType(void)
Get compression type.
Definition: bmp.c:970
uint32_t endOfRow
Definition: bmp.h:150
uint32_t imageDataSize
Definition: bmp.h:112
uint32_t headerSize
Definition: bmp.h:100
int32_t BMP_getFileSize(void)
Get the fileSize in bytes.
Definition: bmp.c:1012
uint32_t hPixelsPerMeter
Definition: bmp.h:114
int16_t BMP_getBitsPerPixel(void)
Get color depth (bits per pixel)
Definition: bmp.c:952
EMSTATUS BMP_readRawData(BMP_DataType *dataType, uint8_t buffer[], uint32_t bufLength)
Fills buffer with raw data from BMP file.
Definition: bmp.c:850
uint16_t bitsPerPixel
Definition: bmp.h:144
BMP Module header structure. Must be packed to exact 54 bytes.
Definition: bmp.h:84
uint16_t colorPlanes
Definition: bmp.h:106
EMSTATUS BMP_init(uint8_t *palette, uint32_t paletteSize, EMSTATUS(*fp)(uint8_t buffer[], uint32_t bufLength, uint32_t bytesToRead))
Initializes BMP Module.
Definition: bmp.c:99
uint32_t width
Definition: bmp.h:102
BMP Data type structure to hold information about the bmp data returned.
Definition: bmp.h:141
int32_t BMP_getImageDataSize(void)
Get imageDataSize in bytes.
Definition: bmp.c:984
int32_t BMP_getDataOffset(void)
Get the offset, i.e. starting address, of the byte where the bitmap data can be found.
Definition: bmp.c:998
EMSTATUS BMP_readRgbData(uint8_t buffer[], uint32_t bufLength, uint32_t *pixelsRead)
Reads in data from BMP file and fills buffer with RGB values. This function terminates either when th...
Definition: bmp.c:247
uint16_t bitsPerPixel
Definition: bmp.h:108
struct __BMP_Palette BMP_Palette
BMP palette structure to hold palette pointer and size.
uint32_t dataOffset
Definition: bmp.h:98