EU1KY AA
libnsbmp.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  bmp_bitmap_callback_vt_s
 
struct  bmp_image
 
struct  ico_image
 
struct  ico_collection
 

Macros

#define BMP_NEW   0
 
#define BMP_OPAQUE   (1 << 0) /** image is opaque (as opposed to having an alpha mask) */
 
#define BMP_CLEAR_MEMORY   (1 << 1) /** memory should be wiped */
 

Typedefs

typedef void *(* bmp_bitmap_cb_create) (int width, int height, unsigned int state)
 
typedef void(* bmp_bitmap_cb_destroy) (void *bitmap)
 
typedef unsigned char *(* bmp_bitmap_cb_get_buffer) (void *bitmap)
 
typedef size_t(* bmp_bitmap_cb_get_bpp) (void *bitmap)
 
typedef void(* bmp_bitmap_cb_putcolor) (unsigned int, unsigned int, unsigned int)
 
typedef struct bmp_bitmap_callback_vt_s bmp_bitmap_callback_vt
 
typedef struct bmp_image bmp_image
 
typedef struct ico_image ico_image
 
typedef struct ico_collection ico_collection
 

Enumerations

enum  bmp_result { BMP_OK = 0, BMP_INSUFFICIENT_MEMORY = 1, BMP_INSUFFICIENT_DATA = 2, BMP_DATA_ERROR = 3 }
 
enum  bmp_encoding { BMP_ENCODING_RGB = 0, BMP_ENCODING_RLE8 = 1, BMP_ENCODING_RLE4 = 2, BMP_ENCODING_BITFIELDS = 3 }
 

Functions

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

Detailed Description

BMP file decoding (interface).

Macro Definition Documentation

#define BMP_CLEAR_MEMORY   (1 << 1) /** memory should be wiped */
#define BMP_NEW   0
#define BMP_OPAQUE   (1 << 0) /** image is opaque (as opposed to having an alpha mask) */

Typedef Documentation

typedef void*(* bmp_bitmap_cb_create) (int width, int height, unsigned int state)
typedef void(* bmp_bitmap_cb_destroy) (void *bitmap)
typedef size_t(* bmp_bitmap_cb_get_bpp) (void *bitmap)
typedef unsigned char*(* bmp_bitmap_cb_get_buffer) (void *bitmap)
typedef void(* bmp_bitmap_cb_putcolor) (unsigned int, unsigned int, unsigned int)
typedef struct bmp_image bmp_image
typedef struct ico_image ico_image

Enumeration Type Documentation

Enumerator
BMP_ENCODING_RGB 
BMP_ENCODING_RLE8 
BMP_ENCODING_RLE4 
BMP_ENCODING_BITFIELDS 
enum bmp_result
Enumerator
BMP_OK 
BMP_INSUFFICIENT_MEMORY 
BMP_INSUFFICIENT_DATA 
BMP_DATA_ERROR 

Function Documentation

bmp_result bmp_analyse ( bmp_image bmp,
size_t  size,
const uint8_t *  cdata 
)

Analyse a BMP prior to decoding.

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

This function must be called before bmp_decode() and sets up all the relevant values in the bmp structure.

Parameters
bmpthe BMP image to analyse
Returns
BMP_OK on success
void bmp_create ( bmp_image bmp,
bmp_bitmap_callback_vt bitmap_callbacks 
)

Initialises necessary bmp_image members.

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_result bmp_decode_trans ( bmp_image bmp,
uint32_t  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
void bmp_finalise ( bmp_image bmp)

Finalise a BMP prior to destruction.

Parameters
bmpthe BMP image to finalise
bmp_result ico_analyse ( ico_collection ico,
size_t  size,
const uint8_t *  data 
)

Analyse an ICO prior to decoding.

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

This function must be called before ico_find().

Parameters
icothe ICO image to analyse
Returns
BMP_OK on success
void ico_collection_create ( ico_collection ico,
bmp_bitmap_callback_vt bitmap_callbacks 
)

Initialises necessary ico_collection members.

void ico_finalise ( ico_collection ico)

Finalise an ICO prior to destruction.

Parameters
icothe ICO image to finalise
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)