bmp.c File Reference

BMP Module.

License

Copyright 2018 Silicon Laboratories Inc. www.silabs.com

The licensor of this software is Silicon Laboratories Inc. Your use of this software is governed by the terms of Silicon Labs Master Software License Agreement (MSLA) available at www.silabs.com/about-us/legal/master-software-license-agreement. This software is distributed to you in Source Code format and is governed by the sections of the MSLA applicable to Source Code.

Definition in file bmp.c .

#include " bmp.h "
#include <stdint.h>
#include "em_types.h"

Functions

int16_t BMP_getBitsPerPixel ()
Get color depth (bits per pixel)
int32_t BMP_getCompressionType ()
Get compression type.
int32_t BMP_getDataOffset ()
Get the offset, i.e. starting address, of the byte where the bitmap data can be found.
int32_t BMP_getFileSize ()
Get the fileSize in bytes.
int32_t BMP_getHeight ()
Get height of BMP image in pixels.
int32_t BMP_getImageDataSize ()
Get imageDataSize in bytes.
int32_t BMP_getWidth ()
Get width of BMP image in pixels.
EMSTATUS BMP_init (uint8_t *palette, uint32_t paletteSize, EMSTATUS(*fp)(uint8_t buffer[], uint32_t bufLength, uint32_t bytesToRead))
Initializes BMP Module.
static EMSTATUS BMP_readPaddingBytes (uint8_t paddingBytes)
Help function to read in padding bytes.
EMSTATUS BMP_readRawData ( BMP_DataType *dataType, uint8_t buffer[], uint32_t bufLength)
Fills buffer with raw data from BMP file.
static EMSTATUS BMP_readRawData24bit ( BMP_DataType *dataType, uint8_t buffer[], uint32_t bufLength)
Help function to read 24-bit RGB BMP data.
static EMSTATUS BMP_readRawData8bit ( BMP_DataType *dataType, uint8_t buffer[], uint32_t bufLength)
Help function to read 8-bit BMP data.
static EMSTATUS BMP_readRawDataRLE8 ( BMP_DataType *dataType, uint8_t buffer[], uint32_t bufLength)
Help function to read 8-bit RLE BMP data.
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.
static EMSTATUS BMP_readRgbDataRLE8 (uint8_t buffer[], uint32_t bufLength, uint32_t *pixelsRead)
Help function used by BMP_readRgbData to read in RLE8 data. This function terminates either when the buffer is full or end of row is reached.
static EMSTATUS BMP_readRleData ( BMP_DataType *dataType, uint8_t buffer[], uint32_t bufLength)
Help function to read in RLE info. Use this only if you know that RLE info is coming. This function takes the markers and decode them. If no marker is present, buffer is filled with 2 bytes containing the RLE info. This function always reads in two bytes.
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() .

Function Documentation

static EMSTATUS BMP_readPaddingBytes ( uint8_t paddingBytes )
static

Help function to read in padding bytes.

Parameters
paddingBytes Number of paddingBytes at the end of the row
Returns
Returns BMP_OK on success, or else error code

Definition at line 727 of file bmp.c .

References BMP_LOCAL_CACHE_SIZE , and BMP_OK .

Referenced by BMP_readRawData() , and BMP_readRgbData() .

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

Help function to read 24-bit RGB BMP data.

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

Definition at line 551 of file bmp.c .

References __BMP_DataType::bitsPerPixel , BMP_ERROR_END_OF_FILE , BMP_OK , __BMP_DataType::compressionType , __BMP_DataType::endOfRow , __BMP_Header::height , __BMP_Header::imageDataSize , NO_COMPRESSION , __BMP_DataType::size , and __BMP_Header::width .

Referenced by BMP_readRawData() .

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

Help function to read 8-bit BMP data.

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

Definition at line 498 of file bmp.c .

References __BMP_DataType::bitsPerPixel , BMP_ERROR_END_OF_FILE , BMP_OK , __BMP_DataType::compressionType , __BMP_DataType::endOfRow , __BMP_Header::height , __BMP_Header::imageDataSize , __BMP_DataType::size , and __BMP_Header::width .

Referenced by BMP_readRawData() , and BMP_readRgbData() .

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

Help function to read 8-bit RLE BMP data.

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

Definition at line 616 of file bmp.c .

References __BMP_DataType::bitsPerPixel , BMP_LOCAL_CACHE_SIZE , BMP_OK , BMP_readRleData() , __BMP_DataType::compressionType , __BMP_DataType::endOfRow , NO_COMPRESSION , RLE8_COMPRESSION , and __BMP_DataType::size .

Referenced by BMP_readRawData() .

static EMSTATUS BMP_readRgbDataRLE8 ( uint8_t buffer[],
uint32_t bufLength,
uint32_t * pixelsRead
)
static

Help function used by BMP_readRgbData to read in RLE8 data. This function terminates either when the buffer is full or end of row 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, or else error code

Definition at line 366 of file bmp.c .

References BMP_LOCAL_CACHE_SIZE , BMP_OK , BMP_readRleData() , __BMP_Palette::data , and __BMP_DataType::endOfRow .

Referenced by BMP_readRgbData() .

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

Help function to read in RLE info. Use this only if you know that RLE info is coming. This function takes the markers and decode them. If no marker is present, buffer is filled with 2 bytes containing the RLE info. This function always reads in two bytes.

Parameters
dataType Data type structure which holds endOfRow.
buffer Buffer to be filled with RLE info.
bufLength Length of buffer. Has to be at least 2.
Returns
Returns BMP_OK on success. Returns BMP_END_OF_FILE if EOF is reached, or else error code

Definition at line 759 of file bmp.c .

References BMP_ERROR_END_OF_FILE , BMP_LOCAL_CACHE_SIZE , BMP_OK , and __BMP_DataType::endOfRow .

Referenced by BMP_readRawDataRLE8() , and BMP_readRgbDataRLE8() .