FastLED 3.9.15
Loading...
Searching...
No Matches

◆ lzw_decode_init()

lzw_result fl::third_party::lzw_decode_init ( struct lzw_ctx * ctx,
fl::u8 minimum_code_size,
const fl::u8 * input_data,
fl::size input_length,
fl::size 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.

Definition at line 263 of file lzw.cpp.hpp.

269{
270 struct lzw_table_entry *table = ctx->table;
271 lzw_result res;
272 fl::u16 code;
273
274 if (minimum_code_size >= LZW_CODE_MAX) {
275 return LZW_BAD_ICODE;
276 }
277
278 /* Initialise the input reading context */
279 ctx->input.data = input_data;
280 ctx->input.data_len = input_length;
281 ctx->input.data_sb_next = input_pos;
282
283 ctx->input.sb_bit = 0;
284 ctx->input.sb_bit_count = 0;
285
286 /* Initialise the table building context */
287 ctx->initial_code_size = minimum_code_size + 1;
288
289 ctx->clear_code = (1 << minimum_code_size) + 0;
290 ctx->eoi_code = (1 << minimum_code_size) + 1;
291
292 ctx->output_left = 0;
293
294 /* Initialise the standard table entries */
295 for (fl::u16 i = 0; i < ctx->clear_code; i++) {
296 table[i].first = i;
297 table[i].value = i;
298 table[i].count = 1;
299 }
300
301 res = lzw__handle_clear(ctx, &code);
302 if (res != LZW_OK) {
303 return res;
304 }
305
306 /* Store details of this code as "previous code" to the context. */
307 ctx->prev_code_first = ctx->table[code].first;
308 ctx->prev_code_count = ctx->table[code].count;
309 ctx->prev_code = code;
310
311 /* Add code to context for immediate output. */
312 ctx->output_code = code;
313 ctx->output_left = 1;
314
315 ctx->has_transparency = false;
316 ctx->transparency_idx = 0;
317 ctx->colour_map = nullptr;
318
319 return LZW_OK;
320}
#define LZW_CODE_MAX
Maximum LZW code size in bits.
Definition lzw.h:27
lzw_result
LZW decoding response codes.
Definition lzw.h:33
@ LZW_OK
Success.
Definition lzw.h:34
@ LZW_BAD_ICODE
Error: Bad initial LZW code.
Definition lzw.h:40
static lzw_result lzw__handle_clear(struct lzw_ctx *ctx, fl::u16 *code_out) FL_NOEXCEPT
Handle clear code.
Definition lzw.cpp.hpp:233
fl::u8 first
First value in entry's entire record.
Definition lzw.cpp.hpp:64
fl::size data_sb_next
Offset to sub-block size.
Definition lzw.cpp.hpp:45
fl::u16 clear_code
Special Clear code value.
Definition lzw.cpp.hpp:84
bool has_transparency
Whether the image is opaque.
Definition lzw.cpp.hpp:92
fl::u32 sb_bit_count
Bit count in sub-block.
Definition lzw.cpp.hpp:49
fl::u16 prev_code_first
First value of previous code.
Definition lzw.cpp.hpp:76
struct lzw_table_entry table[LZW_TABLE_ENTRY_MAX]
LZW code table.
Definition lzw.cpp.hpp:97
fl::u16 eoi_code
Special End of Information code value.
Definition lzw.cpp.hpp:85
fl::size sb_bit
Current bit offset in sub-block.
Definition lzw.cpp.hpp:48
fl::u16 count
Count of values in this entry's record.
Definition lzw.cpp.hpp:65
const fl::u32 * colour_map
Index to colour mapping.
Definition lzw.cpp.hpp:94
fl::u8 initial_code_size
Starting LZW code size.
Definition lzw.cpp.hpp:79
fl::u8 transparency_idx
Index representing transparency.
Definition lzw.cpp.hpp:93
fl::size data_len
Input data length.
Definition lzw.cpp.hpp:44
fl::u16 prev_code
Code read from input previously.
Definition lzw.cpp.hpp:75
struct lzw_read_ctx input
Input reading context.
Definition lzw.cpp.hpp:73
fl::u8 value
Last value for record ending at entry.
Definition lzw.cpp.hpp:63
fl::u16 output_left
Number of values left for output_code.
Definition lzw.cpp.hpp:90
const fl::u8 * data
Pointer to start of input data.
Definition lzw.cpp.hpp:43
fl::u16 output_code
Code that has been partially output.
Definition lzw.cpp.hpp:89
fl::u16 prev_code_count
Total values for previous code.
Definition lzw.cpp.hpp:77
LZW table entry.
Definition lzw.cpp.hpp:62

References fl::third_party::lzw_table_entry::count, fl::third_party::lzw_table_entry::first, FL_NOEXCEPT, lzw__handle_clear(), LZW_BAD_ICODE, LZW_CODE_MAX, LZW_OK, and fl::third_party::lzw_table_entry::value.

Referenced by lzw_decode_init_map(), and nsgif__decode_complex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: