Description

Bitmap Support.

Data Structures

struct BMP_Header
BMP Module header structure.
struct __BMP_Palette
BMP palette structure to hold palette pointer and size.
struct __BMP_DataType
BMP Data type structure to hold information about the bmp data returned.

Functions

struct __BMP_Header __attribute__ ((__packed__))
EMSTATUS BMP_init (uint8_t *palette, uint32_t paletteSize, EMSTATUS(*fp)(uint8_t buffer[], uint32_t bufLength, uint32_t bytesToRead))
Initializes BMP Module.
EMSTATUS BMP_reset (void)
Makes the module ready for new bmp file.
EMSTATUS BMP_readRgbData (uint8_t buffer[], uint32_t bufLength, uint32_t *pixelsRead)
Reads in data from BMP file and fills buffer with RGB values.
EMSTATUS BMP_readRawData (BMP_DataType *dataType, uint8_t buffer[], uint32_t bufLength)
Fills buffer with raw data from BMP file.
int32_t BMP_getWidth (void)
Get width of BMP image in pixels.
int32_t BMP_getHeight (void)
Get height of BMP image in pixels.
int16_t BMP_getBitsPerPixel (void)
Get color depth (bits per pixel)
int32_t BMP_getCompressionType (void)
Get compression type.
int32_t BMP_getImageDataSize (void)
Get imageDataSize in bytes.
int32_t BMP_getDataOffset (void)
Get the offset, i.e.
int32_t BMP_getFileSize (void)
Get the fileSize in bytes.

Macros

#define ECODE_BMP_BASE 0x00000000
BMP base error code.
#define BMP_OK 0x00000000
Successful call.
#define BMP_END_OF_FILE
End of file has been reached.
#define BMP_ERROR_IO ( ECODE_BMP_BASE | 0x0001)
General IO error.
#define BMP_ERROR_HEADER_SIZE_MISMATCH ( ECODE_BMP_BASE | 0x0002)
BMP_Header size in bytes is different from BMP_HEADER_SIZE.
#define BMP_ERROR_ENDIAN_MISMATCH ( ECODE_BMP_BASE | 0x0003)
Endian mismatch.
#define BMP_ERROR_FILE_NOT_SUPPORTED ( ECODE_BMP_BASE | 0x0004)
BMP file is not supported.
#define BMP_ERROR_FILE_INVALID ( ECODE_BMP_BASE | 0x0005)
BMP "file" is not a BMP file.
#define BMP_ERROR_INVALID_ARGUMENT ( ECODE_BMP_BASE | 0x0006)
Argument passed to function is invalid.
#define BMP_ERROR_MODULE_NOT_INITIALIZED ( ECODE_BMP_BASE | 0x0007)
BMP module is not initialized.
#define BMP_ERROR_INVALID_PALETTE_SIZE ( ECODE_BMP_BASE | 0x0008)
Invalid palette size.
#define BMP_ERROR_FILE_NOT_RESET ( ECODE_BMP_BASE | 0x0009)
File not reset.
#define BMP_ERROR_END_OF_FILE ( ECODE_BMP_BASE | 0x0010)
End of bmp file is reached.
#define BMP_ERROR_BUFFER_TOO_SMALL ( ECODE_BMP_BASE | 0x0020)
Buffer provided is too small.
#define BMP_ERROR_PALETTE_NOT_READ ( ECODE_BMP_BASE | 0x0030)
Bmp palette is not read.
#define BMP_PALETTE_8BIT_SIZE (256 * 4)
Palette size in bytes.
#define BMP_HEADER_SIZE (54)
BMP Header Size in bytes.
#define BMP_LOCAL_CACHE_LIMIT (3)
BMP Local cache limit.
#define RLE8_COMPRESSION (1)
Use RLE8 compression.
#define NO_COMPRESSION (0)
Use no compression.
#define BMP_LOCAL_CACHE_SIZE (BMP_CONFIG_LOCAL_CACHE_SIZE)
BMP Local cache size.

Function Documentation

BMP_init()

EMSTATUS BMP_init ( uint8_t * palette,
uint32_t paletteSize,
EMSTATUS(*)(uint8_t buffer[], uint32_t bufLength, uint32_t bytesToRead) fp
)

Initializes BMP Module.

Support:

  • 24-bit Uncompressed.
  • 8-bit Uncompressed.
  • 8-bit RLE compressed.
Parameters
palette Data buffer to hold palette. Required for 8bpp BMPs.
paletteSize Size of palette in bytes. If BMP is 8-bit, this potentially has to be 256 * 4 bytes. If the user knows that he only loads BMPs with N bytes, he can pass in paletteSize = N. Otherwise this value should be 256 * 4 = 1024 bytes to ensure that the palette is big enough for all 8-bits BMPs.
fp Function pointer that is used to read in bytes from BMP file. The function has to return an EMSTATUS and have the following parameter list (uint32_t buffer[], uint32_t bufLength, uint32_t bytesToRead). The function should fill (buffer) with (bytesToRead) bytes from the beginning. If it succeds it has to return BMP_OK, otherwise it should return BMP_ERROR_IO. When the function returns it should be ready to read from where it left off.
Returns
Returns BMP_OK on success, or else error code.

BMP_reset()

EMSTATUS BMP_reset ( )

Makes the module ready for new bmp file.

Reads in header from file, and checks if the provided bmp file is valid and supported. It reads in palette if BMP file is 8bpp. Uses function pointer set in BMP_init() .

Returns
Returns BMP_OK on success, or else error code

BMP_readRgbData()

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 the buffer is full, end of row is reached or end of file is reached.

Parameters
buffer Buffer to hold RGB values.
bufLength Buffer length in bytes.
pixelsRead Pointer to a uint32_t which holds how many bytes that are read.
Returns
  • Returns BMP_OK on success
  • Returns BMP_ERROR_END_OF_FILE if end of file is reached
  • Returns error code otherwise.

BMP_readRawData()

EMSTATUS BMP_readRawData ( BMP_DataType * dataType,
uint8_t buffer[],
uint32_t bufLength
)

Fills buffer with raw data from BMP file.

  • If data is 24bit: Buffer is filled with RGB values till its full or end of row is reached.
  • If data is 8bit: Buffer is filled with palette indicies till its full or end of row is reached.
  • If data is RLE8: Buffer is filled with number of pixels, followed by palette indicies like this (N is number of pixels, P is palette index) buffer = { N P N P ... }.
  • Data is 24bpp if dataType.bitsPerPixel == 24 and dataType.compressionType == NO_COMPRESSION.
  • Data is 8bpp if dataType.bitsPerPixel == 8 and dataType.compressionType == NO_COMPRESSION.
  • Data is RLE8 if dataType.bitsPerPixel == 8 and dataType.compressionType == RLE8_COMPRESSION.
Parameters
dataType Data type struct which holds information about the data returned
buffer Buffer to be filled with raw data
bufLength Length of buffer
Returns
Returns BMP_OK on success, or else error code

BMP_getWidth()

int32_t BMP_getWidth ( )

Get width of BMP image in pixels.

Returns
Returns width of image, or -1 on error

BMP_getHeight()

int32_t BMP_getHeight ( )

Get height of BMP image in pixels.

Returns
Returns height, or -1 on error

BMP_getBitsPerPixel()

int16_t BMP_getBitsPerPixel ( )

Get color depth (bits per pixel)

Returns
Returns bitsPerPixel, or -1 on error

BMP_getCompressionType()

int32_t BMP_getCompressionType ( )

Get compression type.

0 - No compression 1 - RLE 8bpp 2 - RLE 4bpp

Returns
Returns compressionType, or -1 on error

BMP_getImageDataSize()

int32_t BMP_getImageDataSize ( )

Get imageDataSize in bytes.

Returns
Returns imageDataSize, or -1 on error

BMP_getDataOffset()

int32_t BMP_getDataOffset ( )

Get the offset, i.e.

starting address, of the byte where the bitmap data can be found.

Returns
Returns dataOffset, or -1 on error

BMP_getFileSize()

int32_t BMP_getFileSize ( )

Get the fileSize in bytes.

Returns
Returns fileSize, or -1 on error

Macro Definition Documentation

ECODE_BMP_BASE

#define ECODE_BMP_BASE   0x00000000

BMP base error code.

BMP_OK

#define BMP_OK   0x00000000

Successful call.

BMP_END_OF_FILE

#define BMP_END_OF_FILE

End of file has been reached.

BMP_ERROR_IO

#define BMP_ERROR_IO   ( ECODE_BMP_BASE | 0x0001)

General IO error.

BMP_ERROR_HEADER_SIZE_MISMATCH

#define BMP_ERROR_HEADER_SIZE_MISMATCH   ( ECODE_BMP_BASE | 0x0002)

BMP_Header size in bytes is different from BMP_HEADER_SIZE.

BMP_ERROR_ENDIAN_MISMATCH

#define BMP_ERROR_ENDIAN_MISMATCH   ( ECODE_BMP_BASE | 0x0003)

Endian mismatch.

BMP_ERROR_FILE_NOT_SUPPORTED

#define BMP_ERROR_FILE_NOT_SUPPORTED   ( ECODE_BMP_BASE | 0x0004)

BMP file is not supported.

BMP_ERROR_FILE_INVALID

#define BMP_ERROR_FILE_INVALID   ( ECODE_BMP_BASE | 0x0005)

BMP "file" is not a BMP file.

BMP_ERROR_INVALID_ARGUMENT

#define BMP_ERROR_INVALID_ARGUMENT   ( ECODE_BMP_BASE | 0x0006)

Argument passed to function is invalid.

BMP_ERROR_MODULE_NOT_INITIALIZED

#define BMP_ERROR_MODULE_NOT_INITIALIZED   ( ECODE_BMP_BASE | 0x0007)

BMP module is not initialized.

Call BMP_init()

BMP_ERROR_INVALID_PALETTE_SIZE

#define BMP_ERROR_INVALID_PALETTE_SIZE   ( ECODE_BMP_BASE | 0x0008)

Invalid palette size.

BMP_ERROR_FILE_NOT_RESET

#define BMP_ERROR_FILE_NOT_RESET   ( ECODE_BMP_BASE | 0x0009)

File not reset.

Call BMP_reset()

BMP_ERROR_END_OF_FILE

#define BMP_ERROR_END_OF_FILE   ( ECODE_BMP_BASE | 0x0010)

End of bmp file is reached.

BMP_ERROR_BUFFER_TOO_SMALL

#define BMP_ERROR_BUFFER_TOO_SMALL   ( ECODE_BMP_BASE | 0x0020)

Buffer provided is too small.

BMP_ERROR_PALETTE_NOT_READ

#define BMP_ERROR_PALETTE_NOT_READ   ( ECODE_BMP_BASE | 0x0030)

Bmp palette is not read.

BMP_PALETTE_8BIT_SIZE

#define BMP_PALETTE_8BIT_SIZE   (256 * 4)

Palette size in bytes.

BMP_HEADER_SIZE

#define BMP_HEADER_SIZE   (54)

BMP Header Size in bytes.

BMP_LOCAL_CACHE_LIMIT

#define BMP_LOCAL_CACHE_LIMIT   (3)

BMP Local cache limit.

RLE8_COMPRESSION

#define RLE8_COMPRESSION   (1)

Use RLE8 compression.

NO_COMPRESSION

#define NO_COMPRESSION   (0)

Use no compression.

BMP_LOCAL_CACHE_SIZE

#define BMP_LOCAL_CACHE_SIZE   (BMP_CONFIG_LOCAL_CACHE_SIZE)

BMP Local cache size.