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

◆ nsgif__parse_image_data()

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

Parse the image data for a gif frame.

Sets up gif->colour_table for the frame.

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

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

1205{
1206 const fl::u8 *data = *pos;
1207 fl::size len = gif->buf + gif->buf_len - data;
1208 fl::u32 frame_idx = frame - gif->frames;
1209 fl::u8 minimum_code_size;
1210 nsgif_error ret;
1211
1212 FL_ASSERT(gif != nullptr, "GIF object required");
1213 FL_ASSERT(frame != nullptr, "Frame object required");
1214
1215 if (!decode) {
1216 gif->frame_count_partial = frame_idx + 1;
1217 }
1218
1219 /* Ensure sufficient data remains. A gif trailer or a minimum lzw code
1220 * followed by a gif trailer is treated as OK, although without any
1221 * image data. */
1222 switch (len) {
1223 default: if (data[0] == NSGIF_TRAILER) return NSGIF_OK;
1224 break;
1225 case 2: if (data[1] == NSGIF_TRAILER) return NSGIF_OK;
1226 /* Fall through. */
1227 case 1: if (data[0] == NSGIF_TRAILER) return NSGIF_OK;
1228 /* Fall through. */
1229 case 0: return NSGIF_ERR_END_OF_DATA;
1230 }
1231
1232 minimum_code_size = data[0];
1233 if (minimum_code_size >= LZW_CODE_MAX) {
1234 return NSGIF_ERR_DATA_FRAME;
1235 }
1236
1237 if (decode) {
1238 ret = nsgif__update_bitmap(gif, frame, data, frame_idx);
1239 } else {
1240 fl::u32 block_size = 0;
1241
1242 /* Skip the minimum code size. */
1243 data++;
1244 len--;
1245
1246 while (block_size != 1) {
1247 if (len < 1) {
1248 return NSGIF_ERR_END_OF_DATA;
1249 }
1250 block_size = data[0] + 1;
1251 /* Check if the frame data runs off the end of the file */
1252 if (block_size > len) {
1253 frame->lzw_data_length += len;
1254 return NSGIF_ERR_END_OF_DATA;
1255 }
1256
1257 len -= block_size;
1258 data += block_size;
1259 frame->lzw_data_length += block_size;
1260 }
1261
1262 *pos = data;
1263
1264 gif->info.frame_count = frame_idx + 1;
1265 gif->frames[frame_idx].info.display = true;
1266
1267 return NSGIF_OK;
1268 }
1269
1270 return ret;
1271}
uint8_t pos
Definition Blur.ino:11
#define FL_ASSERT(x, MSG)
Definition assert.h:6
#define LZW_CODE_MAX
Maximum LZW code size in bits.
Definition lzw.h:27
unsigned char u8
Definition coder.h:132
nsgif_error
LibNSGIF return codes.
Definition nsgif.hpp:58
@ 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
static nsgif_error nsgif__update_bitmap(struct nsgif *gif, struct nsgif_frame *frame, const fl::u8 *data, fl::u32 frame_idx) FL_NOEXCEPT
Definition gif.cpp.hpp:694
nsgif_frame * frames
decoded frames
Definition gif.cpp.hpp:79
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::size buf_len
total number of bytes of GIF data available
Definition gif.cpp.hpp:113
fl::u32 lzw_data_length
Amount of LZW data found in scan.
Definition gif.cpp.hpp:50
struct nsgif_info info
Definition gif.cpp.hpp:72
fl::u32 frame_count_partial
number of frames partially decoded
Definition gif.cpp.hpp:100
struct nsgif_frame_info info
Definition gif.cpp.hpp:38
const fl::u8 * buf
pointer to GIF data
Definition gif.cpp.hpp:109
#define NSGIF_TRAILER
Definition gif.cpp.hpp:174

References FL_ASSERT, FL_NOEXCEPT, LZW_CODE_MAX, nsgif__update_bitmap(), NSGIF_ERR_DATA_FRAME, NSGIF_ERR_END_OF_DATA, NSGIF_OK, NSGIF_TRAILER, and pos.

Referenced by nsgif__process_frame().

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