-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgif.hpp
66 lines (52 loc) · 1.29 KB
/
gif.hpp
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
60
61
62
63
64
65
66
#ifndef __gif_frame_h__
#define __gif_frame_h__
#include "debug.h"
#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include "gif_frame.hpp"
using namespace std;
struct gif_header
{
char signature[4];
char version[4];
uint16_t width; // canvas width
uint16_t height; // canvas height
bool gct_flag;
uint8_t colour_res;
bool sort_flag;
unsigned int gct_size;
uint8_t bgcolour_index;
uint8_t pixel_aspect_ratio;
uint8_t *gct;
};
class GIF
{
ifstream gif_file;
vector<GIFFrame*> frames;
public:
static const uint8_t EXTENSION_BLOCK = 0x21;
static const uint8_t EXTENSION_BLOCK_GCE = 0xF9;
static const uint8_t EXTENSION_BLOCK_COMMENT = 0xFE;
static const uint8_t EXTENSION_BLOCK_PLAINTEXT = 0x01;
static const uint8_t EXTENSION_BLOCK_APPLICATION = 0xFF;
static const uint8_t IMAGE_DESCRIPTOR = 0x2C;
static const uint8_t GIF_EOF = 0x3B;
struct gif_header header;
GIF();
GIF(string filename);
void open(string filename);
void decode();
GIFFrame* operator[](int i);
virtual ~GIF();
protected:
void decode_header();
void skip_extension();
};
class GIFDecodeError : public runtime_error
{
public:
GIFDecodeError(const std::string& msg) : runtime_error(msg) {}
};
#endif