29 {
30 GifInfo info;
31
32
34 if (error_message) {
35 *error_message = "Empty GIF data";
36 }
37 return info;
38 }
39
40
41 if (data.
size() < 13) {
42 if (error_message) {
43 *error_message = "GIF data too small";
44 }
45 return info;
46 }
47
48
49 if (data[0] != 'G' || data[1] != 'I' || data[2] != 'F') {
50 if (error_message) {
51 *error_message = "Invalid GIF signature";
52 }
53 return info;
54 }
55
56
57 if (!((data[3] == '8' && data[4] == '7' && data[5] == 'a') ||
58 (data[3] == '8' && data[4] == '9' && data[5] == 'a'))) {
59 if (error_message) {
60 *error_message = "Unsupported GIF version";
61 }
62 return info;
63 }
64
65
66
67
68 fl::u16
width = data[6] | (data[7] << 8);
69 fl::u16
height = data[8] | (data[9] << 8);
70
72 if (error_message) {
73 *error_message = "Invalid GIF dimensions";
74 }
75 return info;
76 }
77
78
79
82 stream->write(data);
83
84 if (decoder->begin(stream)) {
85
86 info.width = decoder->getWidth();
87 info.height = decoder->getHeight();
88 info.frameCount = decoder->getFrameCount();
89 info.loopCount = decoder->getLoopCount();
90 info.isAnimated = decoder->isAnimated();
91 info.bitsPerPixel = 8;
92 info.isValid = true;
93
94 decoder->end();
95 } else {
96
99 info.frameCount = 1;
100 info.loopCount = 0;
101 info.isAnimated = false;
102 info.bitsPerPixel = 8;
103 info.isValid = true;
104
105 if (error_message) {
106 *error_message = "";
107 }
108 }
109
110 return info;
111}
constexpr bool empty() const FL_NO_EXCEPT
constexpr fl::size size() const FL_NO_EXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT