-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathegi_gif.h
190 lines (147 loc) · 7.66 KB
/
egi_gif.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This module is a wrapper of GIFLIB routines and functions, based on
giflib-5.2.1.
The GIFLIB distribution is Copyright (c) 1997 Eric S. Raymond
SPDX-License-Identifier: MIT
Midas-Zhou
------------------------------------------------------------------*/
#ifndef __EGI_GIF_H__
#define __EGI_GIF_H__
#include "gif_lib.h"
#include "egi_imgbuf.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct fbdev FBDEV; /* Just a declaration, referring to definition in egi_fbdev.h */
/*** GIF saved images with uncompressed data */
typedef struct {
bool VerGIF89; /* Version: GIF89 OR GIF87 */
int SWidth; /* Size of virtual canvas */
int SHeight;
int SColorResolution; /* How many colors can we generate? */
int SBackGroundColor; /* Background color for virtual canvas */
GifByteType AspectByte; /* Used to compute pixel aspect ratio */
ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent. */
int ImageTotal; /* Total number of images */
// GifImageDesc Image; /* Current image (low-level API) */
SavedImage *SavedImages; /* Image sequence (high-level API) */
// int ExtensionBlockCount; /* Count extensions past last image */
// ExtensionBlock *ExtensionBlocks; /* Extensions past last image */
} EGI_GIF_DATA;
/*** --- NOTE ---
* 1. For big GIF file, be careful to use EGI_GIF, it needs large mem space!
* 2. No mutex lock applied for EGI_GIF, however EGI_IMGBUF HAS mutex lock imbedded.
*/
typedef struct egi_gif {
bool VerGIF89; /* Version: GIF89 OR GIF87 */
bool ImgTransp_ON; /* Try image transparency */
/* typedef int GifWord */
int SWidth; /* Size of virtual canvas */
int SHeight;
int RWidth; /* Size for RSimgbuf, Unapplicable if both <=0, */
int RHeight; /* At least either RWidth or RHeigth to be >0 */
int BWidth; /* Size of current block image */
int BHeight;
int offx; /* Current block offset relative to canvas origin */
int offy;
/* --- For recording last status, update only when Disposal_Mode==2 */
int last_BWidth; /* record last size of current block image */
int last_BHeight;
int last_offx; /* record last block offset relative to canvas origin */
int last_offy;
int last_Disposal_Mode; /* ! update for each frame */
int SColorResolution; /* How many colors can we generate? */
int SBackGroundColor; /* Background color for virtual canvas, color index */
EGI_16BIT_COLOR bkcolor; /* 16bit color according to SBackGroundColor and SColorMap */
GifByteType AspectByte; /* Used to compute pixel aspect ratio */
bool Is_DataOwner; /* Ture: SColorMap and SavedImages to be freed by egi_gif_free()
* When the EGI_GIF is created by egi_gif_slurpFile(), it will auto. set to be true.
* False: To be freed by egi_gifdata_free()
* Usually the EGI_GIF is created by egi_gif_create() with a given EGI_GIF_DATA.
*/
ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent.
* if(!Is_DataOwner): A refrence poiner to EGI_GIF_DATA.SColorMap, to be freed by egi_gifdata_free()
*/
SavedImage *SavedImages; /*** Image sequence (high-level API)
* if(!Is_DataOwner): A refrence poiner to EGI_GIF_DATA.SavedImages, to be freed by egi_gifdata_free()
*/
struct timeval prevtm; /* Time stamp for the previous frame playing */
unsigned int Delayms; /* GIF Delay for current frame, in ms. */
int ImageCount; /* Index of current image (both APIs), starts from 0
* Index ready for display!!
*/
int ImageTotal; /* Total number of images */
GifImageDesc Image; /* Current image (low-level API) */
// int ExtensionBlockCount; /* Count extensions past last image */
// ExtensionBlock *ExtensionBlocks; /* Extensions past last image */
EGI_IMGBUF *Simgbuf; /* to hold GIF screen/canvas */
bool Simgbuf_ready; /* To indicate that Simgbuf data is ready!
* In some case Simgbuf may be emptied before it is updated, so all alpha values may be
* reset to 0 at that moment, if a thread read and display just at that point, it will
* leave a blank on the screen and cause flickering.
*/
/* To be applied when at least either RWidth or RHeigth to be >0 */
EGI_IMGBUF *RSimgbuf; /* resized to RWidthxRHeight, NOT applied yet. */
/* Following for one producer and one consumer scenario only! */
pthread_t thread_display; /* displaying thread ID */
bool thread_running; /* True if thread is running */
bool request_quit_display; /* True if request to quit egi_gif_displayFrame() */
} EGI_GIF;
/*------------------------------------------
Context for GIF displaying thread.
Parameter definition:
Refert to egi_gif_displayFrame( )
-------------------------------------------*/
typedef struct egi_gif_context
{
FBDEV *fbdev;
EGI_GIF *egif;
bool TimeSyncOn; /* Use time stamp to synchronize, Only for nloop==0 */
unsigned int delayms; /* User defined delayms, valid only when TimeSynchOn is false.
* For big size GIF: It takes more time for decoding, and the original
* GIF DelayMs will be too big to catch up its normal speed, a self_defined
* smaller delayms will work around then.
*/
int nloop;
// bool nodelay;
bool DirectFB_ON;
int User_DisposalMode; /* <0 disable */
int User_TransColor; /* <0 disable */
int User_BkgColor; /* <0 disable */
int xp;
int yp;
int xw;
int yw;
int winw, winh;
} EGI_GIF_CONTEXT;
/*** ----- static functions -----
static void GifQprintf(char *Format, ...);
static void PrintGifError(int ErrorCode);
static void egi_gif_FreeSavedImages(SavedImage **psimg, int ImageCount);
inline static void egi_gif_rasterWriteFB( FBDEV *fbdev, EGI_IMGBUF *Simgbuf, int Disposal_Mode, / img_mutex lock /
int xp, int yp, int xw, int yw, int winw, int winh,
int BWidth, int BHeight, int offx, int offy,
ColorMapObject *ColorMap, GifByteType *buffer,
int trans_color, int User_TransColor, int bkg_color,
bool ImgTransp_ON, bool BkgTransp_ON );
static void *egi_gif_threadDisplay(void *argv);
*/
int egi_gif_playFile(const char *fpath, bool Silent_Mode, bool ImgTransp_ON, int *ImageCount, int nloop, bool *sigstop);
EGI_GIF_DATA* egi_gifdata_readFile(const char *fpath);
EGI_GIF* egi_gif_create(const EGI_GIF_DATA *gif_data, bool ImgTransp_ON);
EGI_GIF* egi_gif_slurpFile(const char *fpath, bool ImgTransp_ON);
void egi_gifdata_free(EGI_GIF_DATA **gif_data);
void egi_gif_free(EGI_GIF **egif);
//void egi_gif_displayFrame(FBDEV *fbdev, EGI_GIF *egif, int nloop, bool DirectFB_ON,
// int User_DisposalMode, int User_TransColor,int User_BkgColor,
// int xp, int yp, int xw, int yw, int winw, int winh );
void egi_gif_displayGifCtxt( EGI_GIF_CONTEXT *gif_ctxt ); /* img_mutex lock */
int egi_gif_runDisplayThread(EGI_GIF_CONTEXT *gif_ctxt);
int egi_gif_stopDisplayThread(EGI_GIF *egif);
#ifdef __cplusplus
extern "C" {
#endif
#endif