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

◆ nsgif__decode_complex()

static nsgif_error fl::third_party::nsgif__decode_complex ( struct nsgif * gif,
fl::u32 width,
fl::u32 height,
fl::u32 offset_x,
fl::u32 offset_y,
fl::u32 interlace,
const fl::u8 * data,
fl::u32 transparency_index,
fl::u32 * frame_data,
fl::u32 * colour_table )
static

Definition at line 446 of file gif.cpp.hpp.

457{
458 lzw_result res;
459 nsgif_error ret = NSGIF_OK;
460 fl::u32 clip_x = gif__clip(offset_x, width, gif->info.width);
461 fl::u32 clip_y = gif__clip(offset_y, height, gif->info.height);
462 const fl::u8 *uncompressed;
463 fl::u32 available = 0;
464 fl::u8 step = 24;
465 fl::u32 skip = 0;
466 fl::u32 y = 0;
467
468 if (offset_x >= gif->info.width ||
469 offset_y >= gif->info.height) {
470 return NSGIF_OK;
471 }
472
473 width -= clip_x;
474 height -= clip_y;
475
476 if (width == 0 || height == 0) {
477 return NSGIF_OK;
478 }
479
480 /* Initialise the LZW decoding */
481 res = lzw_decode_init(static_cast<struct lzw_ctx*>(gif->lzw_ctx), data[0],
482 gif->buf, gif->buf_len,
483 data + 1 - gif->buf);
484 if (res != LZW_OK) {
485 return nsgif__error_from_lzw(res);
486 }
487
488 do {
489 fl::u32 x;
490 fl::u32 *frame_scanline;
491
492 frame_scanline = frame_data + offset_x +
493 (y + offset_y) * gif->rowspan;
494
495 x = width;
496 while (x > 0) {
497 unsigned row_available;
498 while (available == 0) {
499 if (res != LZW_OK) {
500 /* Unexpected end of frame, try to recover */
501 if (res == LZW_OK_EOD ||
502 res == LZW_EOI_CODE) {
503 ret = NSGIF_OK;
504 } else {
505 ret = nsgif__error_from_lzw(res);
506 }
507 return ret;
508 }
509 res = lzw_decode(static_cast<struct lzw_ctx*>(gif->lzw_ctx),
510 &uncompressed, &available);
511
512 if (available == 0) {
513 return NSGIF_OK;
514 }
515 gif__jump_data(&skip, &available, &uncompressed);
516 }
517
518 row_available = x < available ? x : available;
519 x -= row_available;
520 available -= row_available;
521 if (transparency_index > 0xFF) {
522 while (row_available-- > 0) {
523 *frame_scanline++ =
524 colour_table[*uncompressed++];
525 }
526 } else {
527 while (row_available-- > 0) {
528 fl::u32 colour;
529 colour = *uncompressed++;
530 if (colour != transparency_index) {
531 *frame_scanline =
532 colour_table[colour];
533 }
534 frame_scanline++;
535 }
536 }
537 }
538
539 skip = clip_x;
540 gif__jump_data(&skip, &available, &uncompressed);
541 } while (nsgif__next_row(interlace, height, &y, &step));
542
543 return ret;
544}
unsigned char u8
Definition coder.h:132
lzw_result 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) FL_NOEXCEPT
Initialise an LZW decompression context for decoding.
Definition lzw.cpp.hpp:263
nsgif_error
LibNSGIF return codes.
Definition nsgif.hpp:58
@ NSGIF_OK
Success.
Definition nsgif.hpp:62
static fl::u32 gif__clip(fl::u32 frame_off, fl::u32 frame_dim, fl::u32 image_ext) FL_NOEXCEPT
Get any frame clip adjustment for the image extent.
Definition gif.cpp.hpp:413
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_OK_EOD
Success; reached zero-length sub-block.
Definition lzw.h:35
static nsgif_error nsgif__error_from_lzw(lzw_result l_res) FL_NOEXCEPT
Convert an LZW result code to equivalent GIF result code.
Definition gif.cpp.hpp:182
static bool nsgif__next_row(fl::u32 interlace, fl::u32 height, fl::u32 *y, fl::u8 *step) FL_NOEXCEPT
Get the next line for GIF decode.
Definition gif.cpp.hpp:394
lzw_result lzw_decode(struct lzw_ctx *ctx, const fl::u8 **const output_data, fl::u32 *output_written) FL_NOEXCEPT
Read input codes until end of LZW context owned output buffer.
Definition lzw.cpp.hpp:500
static void gif__jump_data(fl::u32 *skip, fl::u32 *available, const fl::u8 **pos) FL_NOEXCEPT
Perform any jump over decoded data, to accommodate clipped portion of frame.
Definition gif.cpp.hpp:434
fl::u32 rowspan
Row span of frame_image in pixels.
Definition gif.cpp.hpp:88
fl::u32 width
width of GIF (may increase during decoding)
Definition nsgif.hpp:384
fl::u32 height
height of GIF (may increase during decoding)
Definition nsgif.hpp:386
fl::size buf_len
total number of bytes of GIF data available
Definition gif.cpp.hpp:113
void * lzw_ctx
LZW decode context.
Definition gif.cpp.hpp:75
struct nsgif_info info
Definition gif.cpp.hpp:72
const fl::u8 * buf
pointer to GIF data
Definition gif.cpp.hpp:109
LZW decompression context.
Definition lzw.cpp.hpp:72
int available()
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186
constexpr enable_if< is_fixed_point< T >::value, T >::type step(T edge, T x) FL_NOEXCEPT

References fl::available(), FL_NOEXCEPT, gif__clip(), gif__jump_data(), fl::height, lzw_decode(), lzw_decode_init(), LZW_EOI_CODE, LZW_OK, LZW_OK_EOD, nsgif__error_from_lzw(), nsgif__next_row(), NSGIF_OK, fl::step(), fl::width, fl::x, and fl::y.

Referenced by nsgif__decode().

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