GLIB BMP#

Bitmap Support.

Modules#

__BMP_Header

BMP_Palette

BMP_DataType

Functions#

__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

Get width of BMP image in pixels.

int32_t

Get height of BMP image in pixels.

int16_t

Get color depth (bits per pixel)

int32_t

Get compression type.

int32_t

Get imageDataSize in bytes.

int32_t

Get the offset, i.e.

int32_t

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 undefined

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

Palette size in bytes.

#define

BMP Header Size in bytes.

#define

BMP Local cache limit.

#define

Use RLE8 compression.

#define

Use no compression.

#define
BMP_LOCAL_CACHE_SIZE (BMP_CONFIG_LOCAL_CACHE_SIZE)

BMP Local cache size.

Function Documentation#

__attribute__#

struct __BMP_Header __attribute__ ((__packed__))
Parameters
N/A

Definition at line 1 of file platform/middleware/glib/glib/bmp.h

BMP_init#

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

Initializes BMP Module.

Parameters
N/Apalette

Data buffer to hold palette. Required for 8bpp BMPs.

N/ApaletteSize

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.

N/Afp

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.

Support:

  • 24-bit Uncompressed.

  • 8-bit Uncompressed.

  • 8-bit RLE compressed.

Returns

  • Returns BMP_OK on success, or else error code.


Definition at line 178 of file platform/middleware/glib/glib/bmp.h

BMP_reset#

EMSTATUS BMP_reset (void)

Makes the module ready for new bmp file.

Parameters
N/A

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


Definition at line 179 of file platform/middleware/glib/glib/bmp.h

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.

Parameters
N/Abuffer

Buffer to hold RGB values.

N/AbufLength

Buffer length in bytes.

N/ApixelsRead

Pointer to a uint32_t which holds how many bytes that are read.

This function terminates either when the buffer is full, end of row is reached or end of file is reached.

Returns

    • Returns BMP_OK on success

    • Returns BMP_ERROR_END_OF_FILE if end of file is reached

    • Returns error code otherwise.


Definition at line 180 of file platform/middleware/glib/glib/bmp.h

BMP_readRawData#

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

Fills buffer with raw data from BMP file.

Parameters
N/AdataType

Data type struct which holds information about the data returned

N/Abuffer

Buffer to be filled with raw data

N/AbufLength

Length of buffer

  • 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.

Returns

  • Returns BMP_OK on success, or else error code


Definition at line 181 of file platform/middleware/glib/glib/bmp.h

BMP_getWidth#

int32_t BMP_getWidth (void)

Get width of BMP image in pixels.

Parameters
N/A

Returns

  • Returns width of image, or -1 on error


Definition at line 184 of file platform/middleware/glib/glib/bmp.h

BMP_getHeight#

int32_t BMP_getHeight (void)

Get height of BMP image in pixels.

Parameters
N/A

Returns

  • Returns height, or -1 on error


Definition at line 185 of file platform/middleware/glib/glib/bmp.h

BMP_getBitsPerPixel#

int16_t BMP_getBitsPerPixel (void)

Get color depth (bits per pixel)

Parameters
N/A

Returns

  • Returns bitsPerPixel, or -1 on error


Definition at line 186 of file platform/middleware/glib/glib/bmp.h

BMP_getCompressionType#

int32_t BMP_getCompressionType (void)

Get compression type.

Parameters
N/A

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

  • Returns compressionType, or -1 on error


Definition at line 187 of file platform/middleware/glib/glib/bmp.h

BMP_getImageDataSize#

int32_t BMP_getImageDataSize (void)

Get imageDataSize in bytes.

Parameters
N/A

Returns

  • Returns imageDataSize, or -1 on error


Definition at line 188 of file platform/middleware/glib/glib/bmp.h

BMP_getDataOffset#

int32_t BMP_getDataOffset (void)

Get the offset, i.e.

Parameters
N/A

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

  • Returns dataOffset, or -1 on error


Definition at line 189 of file platform/middleware/glib/glib/bmp.h

BMP_getFileSize#

int32_t BMP_getFileSize (void)

Get the fileSize in bytes.

Parameters
N/A

Returns

  • Returns fileSize, or -1 on error


Definition at line 190 of file platform/middleware/glib/glib/bmp.h

Macro Definition Documentation#

ECODE_BMP_BASE#

#define ECODE_BMP_BASE
Value:
0x00000000

BMP base error code.


Definition at line 59 of file platform/middleware/glib/glib/bmp.h

BMP_OK#

#define BMP_OK
Value:
0x00000000

Successful call.


Definition at line 63 of file platform/middleware/glib/glib/bmp.h

BMP_END_OF_FILE#

#define BMP_END_OF_FILE

End of file has been reached.


Definition at line 65 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_IO#

#define BMP_ERROR_IO
Value:
(ECODE_BMP_BASE | 0x0001)

General IO error.


Definition at line 67 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_HEADER_SIZE_MISMATCH#

#define BMP_ERROR_HEADER_SIZE_MISMATCH
Value:
(ECODE_BMP_BASE | 0x0002)

BMP_Header size in bytes is different from BMP_HEADER_SIZE.


Definition at line 69 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_ENDIAN_MISMATCH#

#define BMP_ERROR_ENDIAN_MISMATCH
Value:
(ECODE_BMP_BASE | 0x0003)

Endian mismatch.


Definition at line 71 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_FILE_NOT_SUPPORTED#

#define BMP_ERROR_FILE_NOT_SUPPORTED
Value:
(ECODE_BMP_BASE | 0x0004)

BMP file is not supported.


Definition at line 73 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_FILE_INVALID#

#define BMP_ERROR_FILE_INVALID
Value:
(ECODE_BMP_BASE | 0x0005)

BMP "file" is not a BMP file.


Definition at line 75 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_INVALID_ARGUMENT#

#define BMP_ERROR_INVALID_ARGUMENT
Value:
(ECODE_BMP_BASE | 0x0006)

Argument passed to function is invalid.


Definition at line 77 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_MODULE_NOT_INITIALIZED#

#define BMP_ERROR_MODULE_NOT_INITIALIZED
Value:
(ECODE_BMP_BASE | 0x0007)

BMP module is not initialized.

Call BMP_init()


Definition at line 79 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_INVALID_PALETTE_SIZE#

#define BMP_ERROR_INVALID_PALETTE_SIZE
Value:
(ECODE_BMP_BASE | 0x0008)

Invalid palette size.


Definition at line 81 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_FILE_NOT_RESET#

#define BMP_ERROR_FILE_NOT_RESET
Value:
(ECODE_BMP_BASE | 0x0009)

File not reset.

Call BMP_reset()


Definition at line 83 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_END_OF_FILE#

#define BMP_ERROR_END_OF_FILE
Value:
(ECODE_BMP_BASE | 0x0010)

End of bmp file is reached.


Definition at line 85 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_BUFFER_TOO_SMALL#

#define BMP_ERROR_BUFFER_TOO_SMALL
Value:
(ECODE_BMP_BASE | 0x0020)

Buffer provided is too small.


Definition at line 87 of file platform/middleware/glib/glib/bmp.h

BMP_ERROR_PALETTE_NOT_READ#

#define BMP_ERROR_PALETTE_NOT_READ
Value:
(ECODE_BMP_BASE | 0x0030)

Bmp palette is not read.


Definition at line 89 of file platform/middleware/glib/glib/bmp.h

BMP_PALETTE_8BIT_SIZE#

#define BMP_PALETTE_8BIT_SIZE
Value:
(256 * 4)

Palette size in bytes.


Definition at line 92 of file platform/middleware/glib/glib/bmp.h

BMP_HEADER_SIZE#

#define BMP_HEADER_SIZE
Value:
(54)

BMP Header Size in bytes.


Definition at line 94 of file platform/middleware/glib/glib/bmp.h

BMP_LOCAL_CACHE_LIMIT#

#define BMP_LOCAL_CACHE_LIMIT
Value:
(3)

BMP Local cache limit.


Definition at line 96 of file platform/middleware/glib/glib/bmp.h

RLE8_COMPRESSION#

#define RLE8_COMPRESSION
Value:
(1)

Use RLE8 compression.


Definition at line 99 of file platform/middleware/glib/glib/bmp.h

NO_COMPRESSION#

#define NO_COMPRESSION
Value:
(0)

Use no compression.


Definition at line 101 of file platform/middleware/glib/glib/bmp.h

BMP_LOCAL_CACHE_SIZE#

#define BMP_LOCAL_CACHE_SIZE
Value:
(BMP_CONFIG_LOCAL_CACHE_SIZE)

BMP Local cache size.


Definition at line 104 of file platform/middleware/glib/glib/bmp.h