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

◆ nsgif_frame_prepare()

nsgif_error fl::third_party::nsgif_frame_prepare ( nsgif_t * gif,
nsgif_rect_t * area,
fl::u32 * delay_cs,
fl::u32 * frame_new )

Prepare to show a frame.

If this is the last frame of an animation with a finite loop count, the returned delay_cs will be NSGIF_INFINITE, indicating that the frame should be shown forever.

Note that if nsgif_data_complete has not been called on this gif, animated GIFs will not loop back to the start. Instead it will return NSGIF_ERR_END_OF_DATA.

Parameters
[in]gifThe nsgif_t object.
[out]areaThe area in pixels that must be redrawn.
[out]delay_csTime to wait after frame_new before next frame in cs.
[out]frame_newThe frame to decode.
Returns
NSGIF_OK on success, or appropriate error otherwise.

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

1887{
1888 nsgif_error ret;
1889 nsgif_rect_t rect = {0, 0, 0, 0};
1890 fl::u32 delay = 0;
1891 fl::u32 frame = gif->frame;
1892
1893 if (gif->frame != NSGIF_FRAME_INVALID &&
1894 gif->frame < gif->info.frame_count &&
1895 gif->frames[gif->frame].info.display) {
1896 rect = gif->frames[gif->frame].info.rect;
1897 }
1898
1900 gif->loop_count,
1901 gif->info.loop_max)) {
1903 }
1904
1905 ret = nsgif__next_displayable_frame(gif, &frame, &delay);
1906 if (ret != NSGIF_OK) {
1907 return ret;
1908 }
1909
1910 if (gif->frame != NSGIF_FRAME_INVALID && frame < gif->frame) {
1911 gif->loop_count++;
1912 }
1913
1914 if (gif->data_complete) {
1915 /* Check for last frame, which has infinite delay. */
1916
1917 if (gif->info.frame_count == 1) {
1919 } else if (gif->info.loop_max != 0) {
1920 fl::u32 frame_next = frame;
1921
1923 &frame_next, nullptr);
1924 if (ret != NSGIF_OK) {
1925 return ret;
1926 }
1927
1928 if (gif->data_complete && frame_next < frame) {
1930 gif->loop_count + 1,
1931 gif->info.loop_max)) {
1933 }
1934 }
1935 }
1936 }
1937
1938 gif->frame = frame;
1939 nsgif__redraw_rect_extend(&gif->frames[frame].info.rect, &rect);
1940
1941 if (delay < gif->delay_min) {
1942 delay = gif->delay_default;
1943 }
1944
1945 *frame_new = gif->frame;
1946 *delay_cs = delay;
1947 *area = rect;
1948
1949 return NSGIF_OK;
1950}
nsgif_error
LibNSGIF return codes.
Definition nsgif.hpp:58
@ NSGIF_ERR_ANIMATION_END
Indicates an animation is complete, and nsgif_reset must be called to restart the animation from the ...
Definition nsgif.hpp:103
@ NSGIF_OK
Success.
Definition nsgif.hpp:62
struct fl::third_party::nsgif_rect nsgif_rect_t
LibNSGIF rectangle structure.
static bool nsgif__animation_complete(int count, int max) FL_NOEXCEPT
Definition gif.cpp.hpp:1863
static void nsgif__redraw_rect_extend(const nsgif_rect_t *frame, nsgif_rect_t *redraw) FL_NOEXCEPT
Definition gif.cpp.hpp:1797
static nsgif_error nsgif__next_displayable_frame(const nsgif_t *gif, fl::u32 *frame, fl::u32 *delay) FL_NOEXCEPT
Definition gif.cpp.hpp:1836
nsgif_rect_t rect
Frame's redraw rectangle.
Definition nsgif.hpp:437
nsgif_frame * frames
decoded frames
Definition gif.cpp.hpp:79
int loop_max
number of times to play animation (zero means loop forever)
Definition nsgif.hpp:390
bool display
whether the frame should be displayed/animated
Definition nsgif.hpp:424
fl::u32 frame_count
number of frames decoded
Definition nsgif.hpp:388
fl::u16 delay_default
Frame delay to apply when delay is less than delay_min.
Definition gif.cpp.hpp:94
fl::u32 frame
current frame
Definition gif.cpp.hpp:81
struct nsgif_info info
Definition gif.cpp.hpp:72
struct nsgif_frame_info info
Definition gif.cpp.hpp:38
bool data_complete
Whether all the GIF data has been supplied, or if there may be more to come.
Definition gif.cpp.hpp:106
int loop_count
number of animation loops so far
Definition gif.cpp.hpp:97
void delay(u32 ms, bool run_async=true) FL_NOEXCEPT
Public delay wrapper that keeps bare Arduino delay() preferred after using fl::delay; while still all...
Definition delay.h:98
#define NSGIF_INFINITE
Representation of infinity.
Definition nsgif.hpp:26
#define NSGIF_FRAME_INVALID
Internal flag that a frame is invalid/unprocessed.
Definition gif.cpp.hpp:162

References fl::rect< T >::rect(), fl::delay(), FL_NOEXCEPT, nsgif__animation_complete(), nsgif__next_displayable_frame(), nsgif__redraw_rect_extend(), NSGIF_ERR_ANIMATION_END, NSGIF_FRAME_INVALID, NSGIF_INFINITE, and NSGIF_OK.

+ Here is the call graph for this function: