xref: /haiku/src/add-ons/translators/gif/GIFLoad.h (revision 4e3137c085bae361922078f123dceb92da700640)
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 //	File: GIFLoad.h
4 //
5 //	Date: December 1999
6 //
7 //	Author: Daniel Switkin
8 //
9 //	Copyright 2003 (c) by Daniel Switkin. This file is made publically available
10 //	under the BSD license, with the stipulations that this complete header must
11 //	remain at the top of the file indefinitely, and credit must be given to the
12 //	original author in any about box using this software.
13 //
14 ////////////////////////////////////////////////////////////////////////////////
15 
16 // Additional authors:	John Scipione, <jscipione@gmail.com>
17 
18 #ifndef GIF_LOAD_H
19 #define GIF_LOAD_H
20 
21 
22 #include <DataIO.h>
23 #include "LoadPalette.h"
24 
25 
26 #define GIF_INTERLACED		0x40
27 #define GIF_LOCALCOLORMAP	0x80
28 
29 #define ENTRY_COUNT			4354
30 	// 4354 = 4096 + 256 + 1 + 1
31 	// 4096 for the image data, 256 for the color codes,
32 	// 1 for the clear code, 1 for the end code
33 
34 
35 typedef struct Memblock {
36 	unsigned char	data[ENTRY_COUNT];
37 	int				offset;
38 	Memblock*		next;
39 } Memblock;
40 
41 
42 const int gl_pass_starts_at[]		= { 0, 4, 2, 1, 0 };
43 const int gl_increment_pass_by[]	= { 8, 8, 4, 2, 0 };
44 
45 
46 class GIFLoad {
47 public:
48 								GIFLoad(BPositionIO* input,
49 									BPositionIO* output);
50 	virtual						~GIFLoad();
51 
52 			bool				fatalerror;
53 
54 private:
55 			bool				ReadGIFHeader();
56 			bool				ReadGIFLoopBlock();
57 			bool				ReadGIFControlBlock();
58 			bool				ReadGIFImageHeader();
59 			bool				ReadGIFImageData();
60 			bool				ReadGIFCommentBlock();
61 			bool				ReadGIFUnknownBlock(unsigned char c);
62 
63 			bool				InitFrame(int codeSize);
64 			short				NextCode();
65 			void				ResetTable();
66 
67 			unsigned char*		MemblockAllocate(int size);
68 			void				MemblockDeleteAll();
69 
70 			inline	bool		OutputColor(unsigned char* string, int size);
71 
72 			BPositionIO*		fInput;
73 			BPositionIO*		fOutput;
74 			LoadPalette*		fPalette;
75 
76 			bool				fInterlaced;
77 
78 			int					fPass;
79 			int					fRow;
80 
81 			int					fWidth;
82 			int					fHeight;
83 
84 			unsigned char		fOldCode[ENTRY_COUNT];
85 			unsigned int		fOldCodeLength;
86 
87 			short				fNewCode;
88 			int					fBits;
89 			int					fMaxCode;
90 			int					fCodeSize;
91 
92 			short				fClearCode;
93 			short				fEndCode;
94 			short				fNextCode;
95 
96 			unsigned char*		fTable[ENTRY_COUNT];
97 			short				fEntrySize[ENTRY_COUNT];
98 			Memblock*			fHeadMemblock;
99 
100 			int					fBitCount;
101 			unsigned int		fBitBuffer;
102 			unsigned char		fByteCount;
103 			unsigned char		fByteBuffer[255];
104 
105 			uint32*				fScanLine;
106 			int					fScanlinePosition;
107 };
108 
109 
110 #endif	// GIF_LOAD_H
111