-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgifdec.h
59 lines (49 loc) · 1.1 KB
/
gifdec.h
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "gif.h"
#include <cassert>
#include <fstream>
#include <unordered_map>
using namespace std;
// write as argb for sdl rendering
typedef struct {
uint16_t l;
uint16_t t;
uint16_t w;
uint16_t h;
} rect_t;
enum pix_fmt_t {
ARGB,
RGBA,
RGB
};
class GifDecoder {
// file states
lsd_t lsd{};
gce_t gce{};
image_desc_t image_desc{};
string gct;
string lct;
uint32_t file_loop_offset{};
// storages
ifstream file;
unordered_map<uint16_t, u8string> code_table;
// configs
pix_fmt_t pix_fmt;
void parse_header();
void parse_metadata();
void parse_lsd_and_set_gct();
void parse_gce();
void parse_application_extension();
void parse_comment_extension();
void lzw_unpack_decode();
void init_code_table(uint16_t size);
void decode_frame_internal();
string bytes_from_all_sub_blocks();
public:
unsigned char* buffer;
GifDecoder(const char* filename, pix_fmt_t pix_fmt);
~GifDecoder();
bool decode_frame();
uint16_t get_width() const;
uint16_t get_height() const;
void loop();
};