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

◆ lzw__decode()

static lzw_result fl::third_party::lzw__decode ( struct lzw_ctx * ctx,
lzw_writer_fn write_fn,
void * output_data,
fl::u32 output_length,
fl::u32 * output_written )
inlinestatic

Get the next LZW code and write its value(s) to output buffer.

Parameters
[in]ctxLZW reading context, updated.
[in]write_fnFunction for writing pixels to output.
[in]output_dataArray to write output values into.
[in]output_lengthSize of output array.
[in,out]output_writtenNumber of values written. Updated on exit.
Returns
LZW_OK on success, or appropriate error code otherwise.

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

395{
396 lzw_result res;
397 fl::u16 code = 0;
398
399 /* Get a new code from the input */
400 res = lzw__read_code(&ctx->input, ctx->code_size, &code);
401 if (res != LZW_OK) {
402 return res;
403 }
404
405 /* Handle the new code */
406 if (code == ctx->eoi_code) {
407 /* Got End of Information code */
408 return LZW_EOI_CODE;
409
410 } else if (code > ctx->table_size) {
411 /* Code is invalid */
412 return LZW_BAD_CODE;
413
414 } else if (code == ctx->clear_code) {
415 res = lzw__handle_clear(ctx, &code);
416 if (res != LZW_OK) {
417 return res;
418 }
419
420 } else if (ctx->table_size < LZW_TABLE_ENTRY_MAX) {
421 fl::u16 size = ctx->table_size;
422 lzw__table_add_entry(ctx, (code < size) ?
423 ctx->table[code].first :
424 ctx->prev_code_first);
425
426 /* Ensure code size is increased, if needed. */
427 if (size == ctx->code_max && ctx->code_size < LZW_CODE_MAX) {
428 ctx->code_size++;
429 ctx->code_max = (1 << ctx->code_size) - 1;
430 }
431 }
432
433 *output_written += write_fn(ctx,
434 output_data, output_length, *output_written,
435 code, ctx->table[code].count);
436
437 /* Store details of this code as "previous code" to the context. */
438 ctx->prev_code_first = ctx->table[code].first;
439 ctx->prev_code_count = ctx->table[code].count;
440 ctx->prev_code = code;
441
442 return LZW_OK;
443}
#define LZW_TABLE_ENTRY_MAX
Maximum number of lzw table entries.
Definition lzw.cpp.hpp:29
#define LZW_CODE_MAX
Maximum LZW code size in bits.
Definition lzw.h:27
static lzw_result lzw__read_code(struct lzw_read_ctx *ctx, fl::u16 code_size, fl::u16 *code_out) FL_NOEXCEPT
Get the next LZW code of given size from the raw input data.
Definition lzw.cpp.hpp:167
lzw_result
LZW decoding response codes.
Definition lzw.h:33
@ LZW_EOI_CODE
Error: End of Information code.
Definition lzw.h:38
@ LZW_OK
Success.
Definition lzw.h:34
@ LZW_BAD_CODE
Error: Bad LZW code.
Definition lzw.h:42
static void lzw__table_add_entry(struct lzw_ctx *ctx, fl::u16 code) FL_NOEXCEPT
Create new table entry.
Definition lzw.cpp.hpp:357
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::u16 table_size
Next position in table to fill.
Definition lzw.cpp.hpp:87
fl::u16 clear_code
Special Clear code value.
Definition lzw.cpp.hpp:84
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::u16 count
Count of values in this entry's record.
Definition lzw.cpp.hpp:65
fl::u8 code_size
Current LZW code size.
Definition lzw.cpp.hpp:81
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::u16 code_max
Max code value for current code size.
Definition lzw.cpp.hpp:82
fl::u16 prev_code_count
Total values for previous code.
Definition lzw.cpp.hpp:77

References fl::third_party::lzw_ctx::clear_code, fl::third_party::lzw_ctx::code_max, fl::third_party::lzw_ctx::code_size, fl::third_party::lzw_table_entry::count, fl::third_party::lzw_ctx::eoi_code, fl::third_party::lzw_table_entry::first, FL_NOEXCEPT, fl::third_party::lzw_ctx::input, lzw__handle_clear(), lzw__read_code(), lzw__table_add_entry(), LZW_BAD_CODE, LZW_CODE_MAX, LZW_EOI_CODE, LZW_OK, LZW_TABLE_ENTRY_MAX, fl::third_party::lzw_ctx::prev_code, fl::third_party::lzw_ctx::prev_code_count, fl::third_party::lzw_ctx::prev_code_first, fl::third_party::lzw_ctx::table, and fl::third_party::lzw_ctx::table_size.

Referenced by lzw_decode(), and lzw_decode_map().

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