-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_ext_gp_ctrl.c
33 lines (25 loc) · 1.06 KB
/
block_ext_gp_ctrl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdlib.h>
#include "block_ext_gp_ctrl.h"
#include "tool.h"
#include "block_frame.h"
GIFBlockFrame *read_gif_block_ext_graph_ctrl(BinData *bytesp, GIFBlockFrame *framep) {
unsigned char bits;
if (framep->ctrl != NULL) framep = add_frame(framep);
framep->ctrl = (GIFBlockExtGpCtrl *) malloc(sizeof(GIFBlockExtGpCtrl));
if (framep->ctrl == NULL) {
die("[ERROR] could not allocate memory for gif graphic control extension");
}
framep->ctrl->block_size = bytesp->buf[bytesp->idx++];
bits = bytesp->buf[bytesp->idx++];
framep->ctrl->reserved = bits >> 5;
framep->ctrl->disposal_method = (bits & ((1 << 4) | (1 << 3) | (1 << 2))) >> 2;
framep->ctrl->user_input_flag = (bits & (1 << 1)) >> 1;
framep->ctrl->transparent_color_flag = bits & 1;
framep->ctrl->delay_time = extract_data(&bytesp->buf[bytesp->idx], 2);
bytesp->idx += 2;
framep->ctrl->transparent_color_index = bytesp->buf[bytesp->idx++];
if (bytesp->buf[bytesp->idx] != '\0') {
die("[ERROR] failed to read from gif graphic control extension block data");
}
return framep;
}