XenevaOS
Loading...
Searching...
No Matches
Macros | Functions
libnsbmp.c File Reference
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <libnsbmp.h>
#include "utils/log.h"
Include dependency graph for libnsbmp.c:

Macros

#define UNUSED(x)   ((x)=(x))
 
#define BMP_FILE_HEADER_SIZE   14
 
#define ICO_FILE_HEADER_SIZE   6
 
#define ICO_DIR_ENTRY_SIZE   16
 
#define BITMAPCOREHEADER   12
 

Functions

bmp_result bmp_create (bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks)
 
bmp_result ico_collection_create (ico_collection *ico, bmp_bitmap_callback_vt *bitmap_callbacks)
 
bmp_result bmp_analyse (bmp_image *bmp, size_t size, uint8_t *data)
 
bmp_result ico_analyse (ico_collection *ico, size_t size, uint8_t *data)
 
bmp_result bmp_decode (bmp_image *bmp)
 
bmp_result bmp_decode_trans (bmp_image *bmp, uint32_t colour)
 
bmp_image * ico_find (ico_collection *ico, uint16_t width, uint16_t height)
 
void bmp_finalise (bmp_image *bmp)
 
void ico_finalise (ico_collection *ico)
 

Detailed Description

BMP decoding implementation

This library decode windows bitmaps and icons from their disc images.

The image format is described in several documents: https://msdn.microsoft.com/en-us/library/dd183391(v=vs.85).aspx http://www.fileformat.info/format/bmp/egff.htm https://en.wikipedia.org/wiki/BMP_file_format

Despite the format being clearly defined many bitmaps found on the web are not compliant and this implementation attempts to cope with as many issues as possible rather than simply failing.

Macro Definition Documentation

◆ BITMAPCOREHEADER

#define BITMAPCOREHEADER   12

◆ BMP_FILE_HEADER_SIZE

#define BMP_FILE_HEADER_SIZE   14

◆ ICO_DIR_ENTRY_SIZE

#define ICO_DIR_ENTRY_SIZE   16

◆ ICO_FILE_HEADER_SIZE

#define ICO_FILE_HEADER_SIZE   6

◆ UNUSED

#define UNUSED (   x)    ((x)=(x))

Function Documentation

◆ bmp_analyse()

bmp_result bmp_analyse ( bmp_image *  bmp,
size_t  size,
uint8_t *  data 
)

Analyse a BMP prior to decoding.

This will scan the data provided and perform checks to ensure the data is a valid BMP and prepare the bitmap image structure ready for decode.

This function must be called and resturn BMP_OK before bmp_decode() as it prepares the bmp internal state for the decode process.

Parameters
bmpthe BMP image to analyse.
sizeThe size of data in cdata.
dataThe bitmap source data.
Returns
BMP_OK on success or error code on faliure.

◆ bmp_create()

bmp_result bmp_create ( bmp_image *  bmp,
bmp_bitmap_callback_vt *  callbacks 
)

Initialises bitmap ready for analysing the bitmap.

Parameters
bmpThe Bitmap to initialise
callbacksThe callbacks the library will call on operations.
Returns
BMP_OK on success or appropriate error code.

◆ bmp_decode()

bmp_result bmp_decode ( bmp_image *  bmp)

Decode a BMP

This function decodes the BMP data such that bmp->bitmap is a valid image. The state of bmp->decoded is set to TRUE on exit such that it can easily be identified which BMPs are in a fully decoded state.

Parameters
bmpthe BMP image to decode
Returns
BMP_OK on success

◆ bmp_decode_trans()

bmp_result bmp_decode_trans ( bmp_image *  bmp,
uint32_t  transparent_colour 
)

Decode a BMP using "limited transparency"

Bitmaps do not have native transparency support. However, there is a "trick" that is used in some instances in which the first pixel of the bitmap becomes the "transparency index". The decoding application can replace this index with whatever background colour it chooses to create the illusion of transparency.

When to use transparency is at the discretion of the decoding application.

Parameters
bmpthe BMP image to decode
colourthe colour to use as "transparent"
Returns
BMP_OK on success

◆ bmp_finalise()

void bmp_finalise ( bmp_image *  bmp)

Finalise a BMP prior to destruction.

Parameters
bmpthe BMP image to finalise.

◆ ico_analyse()

bmp_result ico_analyse ( ico_collection *  ico,
size_t  size,
uint8_t *  data 
)

Analyse an ICO prior to decoding.

This function will scan the data provided and perform checks to ensure the data is a valid ICO.

This function must be called before ico_find().

Parameters
icothe ICO image to analyse
sizeThe size of data in cdata.
dataThe bitmap source data.
Returns
BMP_OK on success

◆ ico_collection_create()

bmp_result ico_collection_create ( ico_collection *  ico,
bmp_bitmap_callback_vt *  callbacks 
)

Initialises icon ready for analysing the icon

Parameters
bmpThe Bitmap to initialise
callbacksThe callbacks the library will call on operations.
Returns
BMP_OK on success or appropriate error code.

◆ ico_finalise()

void ico_finalise ( ico_collection *  ico)

Finalise an ICO prior to destruction.

Parameters
icothe ICO image to finalise,

◆ ico_find()

bmp_image * ico_find ( ico_collection *  ico,
uint16_t  width,
uint16_t  height 
)

Finds the closest BMP within an ICO collection

This function finds the BMP with dimensions as close to a specified set as possible from the images in the collection.

Parameters
icothe ICO collection to examine
widththe preferred width (0 to use ICO header width)
heightthe preferred height (0 to use ICO header height)