XenevaOS
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
lzw.c File Reference

LZW decompression (implementation) More...

#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include "lzw.h"
Include dependency graph for lzw.c:

Classes

struct  lzw_read_ctx
 
struct  lzw_table_entry
 
struct  lzw_ctx
 

Macros

#define LZW_TABLE_ENTRY_MAX   (1u << LZW_CODE_MAX)
 

Typedefs

typedef uint32_t(* lzw_writer_fn) (struct lzw_ctx *ctx, void *restrict output_data, uint32_t output_length, uint32_t output_pos, uint16_t code, uint16_t left)
 

Functions

lzw_result lzw_context_create (struct lzw_ctx **ctx)
 
void lzw_context_destroy (struct lzw_ctx *ctx)
 
lzw_result lzw_decode_init (struct lzw_ctx *ctx, uint8_t minimum_code_size, const uint8_t *input_data, size_t input_length, size_t input_pos)
 
lzw_result lzw_decode_init_map (struct lzw_ctx *ctx, uint8_t minimum_code_size, uint32_t transparency_idx, const uint32_t *colour_table, const uint8_t *input_data, size_t input_length, size_t input_pos)
 
lzw_result lzw_decode (struct lzw_ctx *ctx, const uint8_t *restrict *const restrict output_data, uint32_t *restrict output_written)
 
lzw_result lzw_decode_map (struct lzw_ctx *ctx, uint32_t *restrict output_data, uint32_t output_length, uint32_t *restrict output_written)
 

Detailed Description

LZW decompression (implementation)

Decoder for GIF LZW data.

Macro Definition Documentation

◆ LZW_TABLE_ENTRY_MAX

#define LZW_TABLE_ENTRY_MAX   (1u << LZW_CODE_MAX)

Maximum number of lzw table entries.

Typedef Documentation

◆ lzw_writer_fn

typedef uint32_t(* lzw_writer_fn) (struct lzw_ctx *ctx, void *restrict output_data, uint32_t output_length, uint32_t output_pos, uint16_t code, uint16_t left)

Function Documentation

◆ lzw_context_create()

lzw_result lzw_context_create ( struct lzw_ctx **  ctx)

Create an LZW decompression context.

Parameters
[out]ctxReturns an LZW decompression context. Caller owned, free with lzw_context_destroy().
Returns
LZW_OK on success, or appropriate error code otherwise.

◆ lzw_context_destroy()

void lzw_context_destroy ( struct lzw_ctx *  ctx)

Destroy an LZW decompression context.

Parameters
[in]ctxThe LZW decompression context to destroy.

◆ lzw_decode()

lzw_result lzw_decode ( struct lzw_ctx *  ctx,
const uint8_t *restrict *const restrict  output_data,
uint32_t *restrict  output_written 
)

Read input codes until end of LZW context owned output buffer.

Ensure anything in output is used before calling this, as anything there before this call will be trampled.

Parameters
[in]ctxLZW reading context, updated.
[out]output_dataReturns pointer to array of output values.
[out]output_writtenReturns the number of values written to data.
Returns
LZW_OK on success, or appropriate error code otherwise.

◆ lzw_decode_init()

lzw_result lzw_decode_init ( struct lzw_ctx *  ctx,
uint8_t  minimum_code_size,
const uint8_t *  input_data,
size_t  input_length,
size_t  input_pos 
)

Initialise an LZW decompression context for decoding.

Parameters
[in]ctxThe LZW decompression context to initialise.
[in]minimum_code_sizeThe LZW Minimum Code Size.
[in]input_dataThe compressed data.
[in]input_lengthByte length of compressed data.
[in]input_posStart position in data. Must be position of a size byte at sub-block start.
Returns
LZW_OK on success, or appropriate error code otherwise.

◆ lzw_decode_init_map()

lzw_result lzw_decode_init_map ( struct lzw_ctx *  ctx,
uint8_t  minimum_code_size,
uint32_t  transparency_idx,
const uint32_t *  colour_table,
const uint8_t *  input_data,
size_t  input_length,
size_t  input_pos 
)

Initialise an LZW decompression context for decoding to colour map values.

For transparency to work correctly, the given client buffer must have the values from the previous frame. The transparency_idx should be a value of 256 or above, if the frame does not have transparency.

Parameters
[in]ctxThe LZW decompression context to initialise.
[in]minimum_code_sizeThe LZW Minimum Code Size.
[in]transparency_idxIndex representing transparency.
[in]colour_tableIndex to pixel colour mapping.
[in]input_dataThe compressed data.
[in]input_lengthByte length of compressed data.
[in]input_posStart position in data. Must be position of a size byte at sub-block start.
Returns
LZW_OK on success, or appropriate error code otherwise.

◆ lzw_decode_map()

lzw_result lzw_decode_map ( struct lzw_ctx *  ctx,
uint32_t *restrict  output_data,
uint32_t  output_length,
uint32_t *restrict  output_written 
)

Read LZW codes into client buffer, mapping output to colours.

The context must have been initialised using lzw_decode_init_map before calling this function, in order to provide the colour mapping table and any transparency index.

Ensure anything in output is used before calling this, as anything there before this call will be trampled.

Parameters
[in]ctxLZW reading context, updated.
[in]output_dataClient buffer to fill with colour mapped values.
[in]output_lengthSize of output array.
[out]output_writtenReturns the number of values written to data.
Returns
LZW_OK on success, or appropriate error code otherwise.