#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <libnsbmp.h>
Macros | |
#define | UNUSED(x) ((x)=(x)) |
#define | BMP_FILE_HEADER_SIZE 14 |
#define | ICO_FILE_HEADER_SIZE 6 |
#define | ICO_DIR_ENTRY_SIZE 16 |
Functions | |
static int8_t | read_int8 (const uint8_t *data, unsigned int o) |
static uint8_t | read_uint8 (const uint8_t *data, unsigned int o) |
static int16_t | read_int16 (const uint8_t *data, unsigned int o) |
static uint16_t | read_uint16 (const uint8_t *data, unsigned int o) |
static int32_t | read_int32 (const uint8_t *data, unsigned int o) |
static uint32_t | read_uint32 (const uint8_t *data, unsigned int o) |
static bmp_result | next_ico_image (ico_collection *ico, ico_image *image) |
static bmp_result | bmp_analyse_header (bmp_image *bmp, unsigned char *data) |
static bmp_result | bmp_decode_rgb24 (bmp_image *bmp, uint8_t **start, int bytes) |
static bmp_result | bmp_decode_rgb16 (bmp_image *bmp, uint8_t **start, int bytes) |
static bmp_result | bmp_decode_rgb (bmp_image *bmp, uint8_t **start, int bytes) |
static bmp_result | bmp_decode_mask (bmp_image *bmp, uint8_t *data, int bytes) |
static bmp_result | bmp_decode_rle (bmp_image *bmp, uint8_t *data, int bytes, int size) |
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 *cdata) |
bmp_result | ico_analyse (ico_collection *ico, size_t size, const uint8_t *data) |
static bmp_result | bmp_analyse_header (bmp_image *bmp, uint8_t *data) |
bmp_image * | ico_find (ico_collection *ico, uint16_t width, uint16_t height) |
bmp_result | bmp_decode (bmp_image *bmp) |
bmp_result | bmp_decode_trans (bmp_image *bmp, uint32_t colour) |
void | bmp_finalise (bmp_image *bmp) |
void | ico_finalise (ico_collection *ico) |
#define BMP_FILE_HEADER_SIZE 14 |
#define ICO_DIR_ENTRY_SIZE 16 |
#define ICO_FILE_HEADER_SIZE 6 |
#define UNUSED | ( | x | ) | ((x)=(x)) |
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.
bmp | the BMP image to analyse |
|
static |
|
static |
The bpp value should be in the range 1-32, but the only values considered legal are: RGB ENCODING: 1, 4, 8, 16, 24 and 32
The bpp value should be in the range 1-32, but the only values considered legal are: RGB ENCODING: 1, 4, 8, 16, 24 and 32 RLE4 ENCODING: 4 RLE8 ENCODING: 8 BITFIELD ENCODING: 16 and 32
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.
bmp | the BMP image to decode |
|
static |
Decode a 1bpp mask for an ICO
bmp | the BMP image to decode |
data | the data to decode |
bytes | the number of bytes of data available |
|
static |
Decode BMP data stored with a palette and in 8bpp colour or less.
bmp | the BMP image to decode |
start | the data to decode, updated to last byte read on success |
bytes | the number of bytes of data available |
|
static |
Decode BMP data stored in 16bpp colour.
bmp | the BMP image to decode |
start | the data to decode, updated to last byte read on success |
bytes | the number of bytes of data available |
|
static |
Decode BMP data stored in 24bpp colour.
bmp | the BMP image to decode |
start | the data to decode, updated to last byte read on success |
bytes | the number of bytes of data available |
|
static |
Decode BMP data stored encoded in either RLE4 or RLE8.
bmp | the BMP image to decode |
data | the data to decode |
bytes | the number of bytes of data available |
size | the size of the RLE tokens (4 or 8) |
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.
bmp | the BMP image to decode |
colour | the colour to use as "transparent" |
Finalise a BMP prior to destruction.
bmp | the 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().
ico | the ICO image to analyse |
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.
ico | the 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.
ico | the ICO collection to examine |
width | the preferred width (0 to use ICO header width) |
height | the preferred height (0 to use ICO header height) |
|
static |
Allocates memory for the next BMP in an ICO collection
Sets proper structure values
ico | the ICO collection to add the image to |
image | a pointer to the ICO image to be initialised |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |