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

◆ nsgif__parse_image_descriptor()

static nsgif_error fl::third_party::nsgif__parse_image_descriptor ( struct nsgif * gif,
struct nsgif_frame * frame,
const fl::u8 ** pos,
bool decode )
static

Parse a GIF Image Descriptor.

The format is:

+0 CHAR Image Separator (0x2c) +1 SHORT Image Left Position +3 SHORT Image Top Position +5 SHORT Width +7 SHORT Height +9 CHAR Packed Fields 1BIT Local Colour Table Flag 1BIT Interlace Flag 1BIT Sort Flag 2BITS Reserved 3BITS Size of Local Colour Table

Parameters
[in]gifThe gif object we're decoding.
[in]frameThe frame to parse an image descriptor for.
[in]posCurrent position in data, updated on exit.
[in]decodeWhether to decode the image descriptor.
Returns
NSGIF_OK on success, appropriate error otherwise.

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

1020{
1021 const fl::u8 *data = *pos;
1022 fl::size len = gif->buf + gif->buf_len - data;
1023 enum {
1024 NSGIF_IMAGE_DESCRIPTOR_LEN = 10u,
1025 NSGIF_IMAGE_SEPARATOR = 0x2Cu,
1026 NSGIF_MASK_INTERLACE = 0x40u,
1027 };
1028
1029 FL_ASSERT(gif != nullptr, "GIF object required");
1030 FL_ASSERT(frame != nullptr, "Frame object required");
1031
1032 if (len < NSGIF_IMAGE_DESCRIPTOR_LEN) {
1033 return NSGIF_ERR_END_OF_DATA;
1034 }
1035
1036 if (decode) {
1037 fl::u32 x, y, w, h;
1038
1039 if (data[0] != NSGIF_IMAGE_SEPARATOR) {
1040 return NSGIF_ERR_DATA_FRAME;
1041 }
1042
1043 x = data[1] | (data[2] << 8);
1044 y = data[3] | (data[4] << 8);
1045 w = data[5] | (data[6] << 8);
1046 h = data[7] | (data[8] << 8);
1047 frame->flags = data[9];
1048
1049 frame->info.rect.x0 = x;
1050 frame->info.rect.y0 = y;
1051 frame->info.rect.x1 = x + w;
1052 frame->info.rect.y1 = y + h;
1053
1054 frame->info.interlaced = frame->flags & NSGIF_MASK_INTERLACE;
1055
1056 /* Allow first frame to grow image dimensions. */
1057 if (gif->info.frame_count == 0) {
1058 if (x + w > gif->info.width) {
1059 gif->info.width = x + w;
1060 }
1061 if (y + h > gif->info.height) {
1062 gif->info.height = y + h;
1063 }
1064 }
1065 }
1066
1067 *pos += NSGIF_IMAGE_DESCRIPTOR_LEN;
1068 return NSGIF_OK;
1069}
int y
Definition simple.h:93
int x
Definition simple.h:92
uint8_t pos
Definition Blur.ino:11
#define FL_ASSERT(x, MSG)
Definition assert.h:6
unsigned char u8
Definition coder.h:132
@ NSGIF_ERR_END_OF_DATA
Unexpected end of GIF source data.
Definition nsgif.hpp:87
@ NSGIF_ERR_DATA_FRAME
GIF source data contained an error in a frame.
Definition nsgif.hpp:82
@ NSGIF_OK
Success.
Definition nsgif.hpp:62
nsgif_rect_t rect
Frame's redraw rectangle.
Definition nsgif.hpp:437
fl::u32 frame_count
number of frames decoded
Definition nsgif.hpp:388
fl::u32 y0
y co-ordinate of redraw rectangle, top
Definition nsgif.hpp:48
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
bool interlaced
whether the frame is interlaced
Definition nsgif.hpp:430
fl::u32 x1
x co-ordinate of redraw rectangle, right
Definition nsgif.hpp:50
struct nsgif_info info
Definition gif.cpp.hpp:72
fl::u32 y1
y co-ordinate of redraw rectangle, bottom
Definition nsgif.hpp:52
fl::u32 x0
x co-ordinate of redraw rectangle, left
Definition nsgif.hpp:46
struct nsgif_frame_info info
Definition gif.cpp.hpp:38
const fl::u8 * buf
pointer to GIF data
Definition gif.cpp.hpp:109

References FL_ASSERT, FL_NOEXCEPT, NSGIF_ERR_DATA_FRAME, NSGIF_ERR_END_OF_DATA, NSGIF_OK, pos, fl::x, and fl::y.

Referenced by nsgif__process_frame().

+ Here is the caller graph for this function: