xref: /utopia/UTPA2-700.0.x/modules/gpd/drv/gpd/gif_lib.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 /******************************************************************************
79 * In order to make life a little bit easier when using the GIF file format,   *
80 * this library was written, and which does all the dirty work...              *
81 *                                                                             *
82 *                                        Written by Gershon Elber,  Jun. 1989 *
83 *                                        Hacks by Eric S. Raymond,  Sep. 1992 *
84 *******************************************************************************
85 * History:                                                                    *
86 * 14 Jun 89 - Version 1.0 by Gershon Elber.                                   *
87 *  3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names)  *
88 * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp)   *
89 * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)             *
90 * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code)     *
91 ******************************************************************************/
92 
93 #ifndef _GIF_LIB_H
94 #define _GIF_LIB_H
95 
96 #include "gpd.h"
97 
98 #define GIF_LIB_VERSION	" Version 4.0, "
99 
100 //#define SW_DEC
101 
102 #define	GIF_ERROR	0
103 #define GIF_OK		1
104 
105 #ifndef SUPPORT_MGIF
106 #define SUPPORT_MGIF 1
107 #endif
108 
109 #ifndef NO_SUPPORT_MGIF
110 #define NO_SUPPORT_MGIF 0
111 #endif
112 
113 #ifndef TRUE
114 #define TRUE		1
115 #define FALSE		0
116 #endif
117 
118 #ifndef NULL
119 #define NULL		0
120 #endif /* NULL */
121 
122 #define GIF_STAMP "GIFVER"          /* First chars in file - GIF stamp.  */
123 #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
124 #define GIF_VERSION_POS	3           /* Version first character in stamp. */
125 #define GIF87_STAMP	"GIF87a"        /* First chars in file - GIF stamp.  */
126 #define GIF89_STAMP	"GIF89a"        /* First chars in file - GIF stamp.  */
127 
128 #define GIF_FILE_BUFFER_SIZE 16384  /* Files uses bigger buffers than usual. */
129 
130 typedef	int		GifBooleanType;
131 typedef	MS_U8	GifPixelType;
132 typedef MS_U8 *	GifRowType;
133 typedef MS_U8	GifByteType;
134 
135 #ifdef SYSV
136 #define VoidPtr char *
137 #else
138 #define VoidPtr void *
139 #endif /* SYSV */
140 
141 typedef struct GifColorType {
142     GifByteType Red, Green, Blue;
143 } GifColorType;
144 
145 typedef struct ColorMapObject
146 {
147     int	ColorCount;
148     MS_U32 BitsPerPixel;
149     GifColorType *Colors;		/* on malloc(3) heap */
150 }
151 ColorMapObject;
152 
153 typedef struct GifImageDesc {
154     MS_U32 Left, Top, Width, Height,	/* Current image dimensions. */
155 	Interlace;			/* Sequential/Interlaced lines. */
156     ColorMapObject *ColorMap;		/* The local color map */
157 } GifImageDesc;
158 
159 typedef struct GifGraphicCtrl {
160     MS_U32 enable;
161     MS_U32 disposal_method;
162     MS_U32 time;
163     MS_U32 trans_bit;
164     MS_U32 trans_idx;
165 } GifGraphicCtrl;
166 
167 typedef struct GifFileType {
168     MS_U32 SWidth, SHeight;		/* Screen dimensions. */
169 	MS_U32 SColorResolution, 		/* How many colors can we generate? */
170 	SBackGroundColor,		/* I hope you understand this one... */
171 	AspectRatio;            /* from 89a*/
172     ColorMapObject *SColorMap;		/* NULL if not exists. */
173     MS_U32 ImageCount;			/* Number of current image */
174     GifImageDesc Image;			/* Block describing current image */
175     GifGraphicCtrl GraphicCtrl;
176     struct SavedImage *SavedImages;	/* Use this to accumulate file state */
177     MS_VIRT UserData;           /* hook to attach user data (TVT) */
178     VoidPtr Private;	  		/* Don't mess with this! */
179     MS_U32  GifState;     /*record the decode state*/
180     MS_U32 isMGIF;                 /*record the current GIF picture is animate or static*/
181 } GifFileType;
182 
183 typedef enum {
184     UNDEFINED_RECORD_TYPE,
185     SCREEN_DESC_RECORD_TYPE,
186     IMAGE_DESC_RECORD_TYPE,		/* Begin with ',' */
187     EXTENSION_RECORD_TYPE,		/* Begin with '!' */
188     TERMINATE_RECORD_TYPE		/* Begin with ';' */
189 } GifRecordType;
190 
191 
192 typedef enum {
193     STATE_MGIF_TERMINATE,
194     STATE_GIF_ERROR,
195     STATE_MGIF_WAIT_BUFFFER,
196     STATE_GIF_SUCCESS
197 } GifState;
198 
199 /* DumpScreen2Gif routine constants identify type of window/screen to dump.  */
200 /* Note all values below 1000 are reserved for the IBMPC different display   */
201 /* devices (it has many!) and are compatible with the numbering TC2.0        */
202 /* (Turbo C 2.0 compiler for IBM PC) gives to these devices.		     */
203 typedef enum {
204     GIF_DUMP_SGI_WINDOW = 1000,
205     GIF_DUMP_X_WINDOW = 1001
206 } GifScreenDumpType;
207 
208 /* func type to read gif data from arbitrary sources (TVT) */
209 typedef MS_U32 (*InputFunc)(GifFileType*,GifByteType*,int);
210 
211 /* func type to write gif data ro arbitrary targets.
212  * Returns count of bytes written. (MRB)
213  */
214 typedef MS_U32 (*OutputFunc)(GifFileType *, const GifByteType *, int);
215 /******************************************************************************
216 *  GIF89 extension function codes                                             *
217 ******************************************************************************/
218 
219 #define COMMENT_EXT_FUNC_CODE		0xfe	/* comment */
220 #define GRAPHICS_EXT_FUNC_CODE		0xf9	/* graphics control */
221 #define PLAINTEXT_EXT_FUNC_CODE		0x01	/* plaintext */
222 #define APPLICATION_EXT_FUNC_CODE	0xff	/* application block */
223 
224 /******************************************************************************
225 * O.K., here are the routines one can access in order to encode GIF file:     *
226 * (GIF_LIB file EGIF_LIB.C).						      *
227 ******************************************************************************/
228 
229 GifFileType *EGifOpenFileName(const char *GifFileName, MS_U32 GifTestExistance);
230 GifFileType *EGifOpenFileHandle(MS_U32 GifFileHandle);
231 GifFileType *EgifOpen(void *userPtr, OutputFunc writeFunc);
232 MS_U32 EGifSpew(GifFileType *GifFile);
233 void EGifSetGifVersion(const char *Version);
234 MS_U32 EGifPutScreenDesc(GifFileType *GifFile,
235 	MS_U32 GifWidth, MS_U32 GifHeight, MS_U32 GifColorRes, MS_U32 GifBackGround,
236 	const ColorMapObject *GifColorMap);
237 MS_U32 EGifPutImageDesc(GifFileType *GifFile,
238 	MS_U32 GifLeft, MS_U32 GifTop, MS_U32 Width, MS_U32 GifHeight, MS_U32 GifInterlace,
239 	const ColorMapObject *GifColorMap);
240 MS_U32 EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, MS_U32 GifLineLen);
241 MS_U32 EGifPutPixel(GifFileType *GifFile, GifPixelType GifPixel);
242 MS_U32 EGifPutComment(GifFileType *GifFile, const char *GifComment);
243 MS_U32 EGifPutExtensionFirst(GifFileType *GifFile, MS_U32 GifExtCode, MS_U32 GifExtLen,
244                            const VoidPtr GifExtension);
245 MS_U32 EGifPutExtensionNext(GifFileType *GifFile, MS_U32 GifExtCode, MS_U32 GifExtLen,
246                            const VoidPtr GifExtension);
247 MS_U32 EGifPutExtensionLast(GifFileType *GifFile, MS_U32 GifExtCode, MS_U32 GifExtLen,
248                            const VoidPtr GifExtension);
249 MS_U32 EGifPutExtension(GifFileType *GifFile, MS_U32 GifExtCode, MS_U32 GifExtLen,
250 							const VoidPtr GifExtension);
251 MS_U32 EGifPutCode(GifFileType *GifFile, MS_U32 GifCodeSize,
252 					  const GifByteType *GifCodeBlock);
253 MS_U32 EGifPutCodeNext(GifFileType *GifFile, const GifByteType *GifCodeBlock);
254 MS_U32 EGifCloseFile(GifFileType *GifFile);
255 
256 #define	E_GIF_ERR_OPEN_FAILED	1		/* And EGif possible errors. */
257 #define	E_GIF_ERR_WRITE_FAILED	2
258 #define E_GIF_ERR_HAS_SCRN_DSCR	3
259 #define E_GIF_ERR_HAS_IMAG_DSCR	4
260 #define E_GIF_ERR_NO_COLOR_MAP	5
261 #define E_GIF_ERR_DATA_TOO_BIG	6
262 #define E_GIF_ERR_NOT_ENOUGH_MEM 7
263 #define E_GIF_ERR_DISK_IS_FULL	8
264 #define E_GIF_ERR_CLOSE_FAILED	9
265 #define E_GIF_ERR_NOT_WRITEABLE	10
266 
267 /******************************************************************************
268 * O.K., here are the routines one can access in order to decode GIF file:     *
269 * (GIF_LIB file DGIF_LIB.C).						      *
270 ******************************************************************************/
271 
272 
273 GifFileType *MstDGifProcess(void* ptr,MS_U32 ocolor_typ,MS_U32 mode,void *roi);
274 GifFileType *MstDGifOpenFileHandle(MS_U32 GifFileHandle,InputFunc read_fun, GifByteType* bitstream);
275 GifFileType *MstDGifOpen( void* userPtr, InputFunc readFunc );  /* new one (TVT) */
276 MS_U32 MstDGifSlurp(GifFileType *GifFile);
277 MS_U32 MstDGifGetScreenDesc(GifFileType *GifFile);
278 MS_U32 MstDGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
279 MS_U32 MstDGifGetImageDesc(GifFileType *GifFile);
280 MS_U32 MstDGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, MS_U32 GifLineLen);
281 MS_U32 MstDGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
282 MS_U32 MstDGifGetComment(GifFileType *GifFile, char *GifComment);
283 MS_U32 MstDGifGetExtension(GifFileType *GifFile, MS_U32 *GifExtCode,
284 						GifByteType **GifExtension);
285 MS_U32 MstDGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
286 MS_U32 MstDGifGetCode(GifFileType *GifFile, MS_U32 *GifCodeSize,
287 						GifByteType **GifCodeBlock);
288 MS_U32 MstDGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
289 MS_U32 MstDGifGetLZCodes(GifFileType *GifFile, MS_U32 *GifCode);
290 MS_U32 MstDGifCloseFile(GifFileType *GifFile);
291 void MstDGifSetMode (MS_U32 mode);
292 MS_U32 MstDGifGetDuration(void);
293 
294 
295 #define	D_GIF_ERR_OPEN_FAILED	101		/* And DGif possible errors. */
296 #define	D_GIF_ERR_READ_FAILED	102
297 #define	D_GIF_ERR_NOT_GIF_FILE	103
298 #define D_GIF_ERR_NO_SCRN_DSCR	104
299 #define D_GIF_ERR_NO_IMAG_DSCR	105
300 #define D_GIF_ERR_NO_COLOR_MAP	106
301 #define D_GIF_ERR_WRONG_RECORD	107
302 #define D_GIF_ERR_DATA_TOO_BIG	108
303 #define D_GIF_ERR_NOT_ENOUGH_MEM 109
304 #define D_GIF_ERR_CLOSE_FAILED	110
305 #define D_GIF_ERR_NOT_READABLE	111
306 #define D_GIF_ERR_IMAGE_DEFECT	112
307 #define D_GIF_ERR_EOF_TOO_SOON	113
308 
309 #if 0
310 /******************************************************************************
311 * O.K., here are the routines from GIF_LIB file QUANTIZE.C.		      *
312 ******************************************************************************/
313 MS_U32 QuantizeBuffer(MS_U32 Width, MS_U32 Height, MS_U32 *ColorMapSize,
314 	GifByteType *RedInput, GifByteType *GreenInput, GifByteType *BlueInput,
315 	GifByteType *OutputBuffer, GifColorType *OutputColorMap);
316 #endif
317 
318 
319 /******************************************************************************
320 * O.K., here are the routines from GIF_LIB file GIF_ERR.C.		      *
321 ******************************************************************************/
322  void PrintGifError(void);
323  MS_U32 MstGifLastError(void);
324 
325 /******************************************************************************
326 * O.K., here are the routines from GIF_LIB file DEV2GIF.C.		      *
327 ******************************************************************************/
328  MS_U32 DumpScreen2Gif(const char *FileName,
329 			  MS_U32 ReqGraphDriver,
330 			  MS_U32 ReqGraphMode1,
331 			  MS_U32 ReqGraphMode2,
332 			  MS_U32 ReqGraphMode3);
333 
334 /*****************************************************************************
335  *
336  * Everything below this point is new after version 1.2, supporting `slurp
337  * mode' for doing I/O in two big belts with all the image-bashing in core.
338  *
339  *****************************************************************************/
340 
341 /******************************************************************************
342 * Color Map handling from ALLOCGIF.C					      *
343 ******************************************************************************/
344 
345  ColorMapObject *MstMakeMapObject(MS_U32 ColorCount, const GifColorType *ColorMap);
346  void MstFreeMapObject(ColorMapObject *Object);
347  ColorMapObject *UnionColorMap(
348 				const ColorMapObject *ColorIn1,
349 				const ColorMapObject *ColorIn2,
350 				GifPixelType ColorTransIn2[]);
351  MS_U32 MstBitSize(MS_U32 n);
352 
353 /******************************************************************************
354 * Support for the in-core structures allocation (slurp mode).		      *
355 ******************************************************************************/
356 
357 /* This is the in-core version of an extension record */
358 typedef struct {
359     int		ByteCount;
360     char	*Bytes;		/* on malloc(3) heap */
361     MS_U32 Function;       /* Holds the type of the Extension block. */
362 } ExtensionBlock;
363 
364 /* This holds an image header, its unpacked raster bits, and extensions */
365 typedef struct SavedImage {
366     GifImageDesc	ImageDesc;
367 
368     char		*RasterBits;		/* on malloc(3) heap */
369 
370     int			Function; /* DEPRECATED: Use ExtensionBlocks[x].Function
371                            * instead */
372     int			ExtensionBlockCount;
373     ExtensionBlock	*ExtensionBlocks;	/* on malloc(3) heap */
374 } SavedImage;
375 
376 extern void ApplyTranslation(SavedImage *Image, GifPixelType Translation[]);
377 
378 extern void MakeExtension(SavedImage *New, MS_U32 Function);
379 extern MS_U32 AddExtensionBlock(SavedImage *New, MS_U32 Len, char ExtData[]);
380 extern void FreeExtension(SavedImage *Image);
381 
382 extern SavedImage *MakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom);
383 extern void FreeSavedImages(GifFileType *GifFile);
384 
385 /******************************************************************************
386 * The library's internal utility font					      *
387 ******************************************************************************/
388 #if 0
389 #define GIF_FONT_WIDTH	8
390 #define GIF_FONT_HEIGHT	8
391 extern MS_U8 AsciiTable[][GIF_FONT_WIDTH];
392 
393 extern void DrawText(SavedImage *Image,
394 		     const MS_U32 x, const MS_U32 y,
395 		     const char *legend,
396 		     const MS_U32 color);
397 
398 extern void DrawBox(SavedImage *Image,
399 		     const MS_U32 x, const MS_U32 y,
400 		     const MS_U32 w, const MS_U32 d,
401 		     const MS_U32 color);
402 
403 void DrawRectangle(SavedImage *Image,
404 		     const MS_U32 x, const MS_U32 y,
405 		     const MS_U32 w, const MS_U32 d,
406 		     const MS_U32 color);
407 
408 extern void DrawBoxedText(SavedImage *Image,
409 		     const MS_U32 x, const MS_U32 y,
410 		     const char *legend,
411 		     const MS_U32 border,
412 		     const MS_U32 bg,
413 		     const MS_U32 fg);
414 #endif
415 
416 #endif /* _GIF_LIB_H */
417