Rev 37 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
37 | halyavin | 1 | ; GIF LITE v2.0 by Willow |
2 | ; Written in pure assembler by Ivushkin Andrey aka Willow |
||
3 | ; |
||
4 | ; This include file will contain functions to handle GIF image format |
||
5 | ; |
||
6 | ; Created: August 15, 2004 |
||
7 | ; Last changed: September 9, 2004 |
||
8 | |||
9 | ; Change COLOR_ORDER in your program |
||
10 | ; if colors are displayed improperly |
||
11 | |||
12 | if ~ (COLOR_ORDER in |
||
13 | ; This message may not appear under MenuetOS, so watch... |
||
14 | display 'Please define COLOR_ORDER: MENUETOS or OTHER',13,10 |
||
15 | end if |
||
16 | |||
17 | ; virtual structure, used internally |
||
18 | |||
19 | struc GIF_list |
||
20 | { |
||
21 | .NextImg rd 1 |
||
22 | .Left rw 1 |
||
23 | .Top rw 1 |
||
24 | .Width rw 1 |
||
25 | .Height rw 1 |
||
26 | } |
||
27 | |||
28 | struc GIF_info |
||
29 | { |
||
30 | .Left rw 1 |
||
31 | .Top rw 1 |
||
32 | .Width rw 1 |
||
33 | .Height rw 1 |
||
34 | } |
||
35 | |||
36 | _null fix 0x1000 |
||
37 | |||
38 | |||
39 | ; **************************************** |
||
40 | ; FUNCTION ReadGIF - unpacks GIF image |
||
41 | ; **************************************** |
||
42 | ; in: |
||
43 | ; esi - pointer to GIF file in memory |
||
44 | ; edi - pointer to output image list |
||
45 | ; eax - pointer to work area (MIN 16 KB!) |
||
46 | |||
47 | ; out: |
||
48 | ; eax - 0, all OK; |
||
49 | ; eax - 1, invalid signature; |
||
50 | ; eax >=8, unsupported image attributes |
||
51 | ; |
||
52 | ; ecx - number of images |
||
53 | |||
54 | ReadGIF: |
||
55 | push esi edi |
||
56 | mov [.table_ptr],eax |
||
57 | mov [.cur_info],edi |
||
58 | xor eax,eax |
||
59 | mov [.globalColor],eax |
||
60 | mov [.img_count],eax |
||
61 | inc eax |
||
62 | cmp dword[esi],'GIF8' |
||
63 | jne .er ; signature |
||
64 | mov ecx,[esi+0xa] |
||
65 | inc eax |
||
66 | add esi,0xd |
||
67 | mov edi,esi |
||
68 | bt ecx,7 |
||
69 | jnc .nextblock |
||
70 | mov [.globalColor],esi |
||
71 | call .Gif_skipmap |
||
72 | .nextblock: |
||
73 | cmp byte[edi],0x21 |
||
74 | jne .noextblock |
||
75 | inc edi |
||
76 | cmp byte[edi],0xf9 ; Graphic Control Ext |
||
77 | jne .no_gc |
||
78 | add edi,7 |
||
79 | jmp .nextblock |
||
80 | .no_gc: |
||
81 | cmp byte[edi],0xfe ; Comment Ext |
||
82 | jne .no_comm |
||
83 | inc edi |
||
84 | .block_skip: |
||
85 | movzx eax,byte[edi] |
||
86 | lea edi,[edi+eax+1] |
||
87 | cmp byte[edi],0 |
||
88 | jnz .block_skip |
||
89 | inc edi |
||
90 | jmp .nextblock |
||
91 | .no_comm: |
||
92 | cmp byte[edi],0xff ; Application Ext |
||
93 | jne .nextblock |
||
94 | add edi,13 |
||
95 | jmp .block_skip |
||
96 | .noextblock: |
||
97 | cmp byte[edi],0x2c ; image beginning |
||
98 | jne .er |
||
99 | inc [.img_count] |
||
100 | inc edi |
||
101 | mov esi,[.cur_info] |
||
102 | add esi,4 |
||
103 | xchg esi,edi |
||
104 | movsd |
||
105 | movsd |
||
106 | push edi |
||
107 | movzx ecx,word[esi] |
||
108 | inc esi |
||
109 | bt ecx,7 |
||
110 | jc .uselocal |
||
111 | push [.globalColor] |
||
112 | mov edi,esi |
||
113 | jmp .setPal |
||
114 | .uselocal: |
||
115 | call .Gif_skipmap |
||
116 | push esi |
||
117 | .setPal: |
||
118 | movzx ecx,byte[edi] |
||
119 | inc ecx |
||
120 | mov [.codesize],ecx |
||
121 | dec ecx |
||
122 | pop [.Palette] |
||
123 | lea esi,[edi+1] |
||
124 | mov edi,[.table_ptr] |
||
125 | xor eax,eax |
||
126 | cld |
||
127 | lodsb ; eax - block_count |
||
128 | add eax,esi |
||
129 | mov [.block_ofs],eax |
||
130 | mov [.bit_count],8 |
||
131 | mov eax,1 |
||
132 | shl eax,cl |
||
133 | mov [.CC],eax |
||
134 | inc eax |
||
135 | mov [.EOI],eax |
||
136 | lea ecx,[eax-1] |
||
137 | mov eax, _null shl 16 |
||
138 | .filltable: |
||
139 | stosd |
||
140 | inc eax |
||
141 | loop .filltable |
||
142 | pop edi |
||
143 | mov [.img_start],edi |
||
144 | .reinit: |
||
145 | mov edx,[.EOI] |
||
146 | inc edx |
||
147 | push [.codesize] |
||
148 | pop [.compsize] |
||
149 | call .Gif_get_sym |
||
150 | cmp eax,[.CC] |
||
151 | je .reinit |
||
152 | call .Gif_output |
||
153 | .cycle: |
||
154 | movzx ebx,ax |
||
155 | call .Gif_get_sym |
||
156 | cmp eax,edx |
||
157 | jae .notintable |
||
158 | cmp eax,[.CC] |
||
159 | je .reinit |
||
160 | cmp eax,[.EOI] |
||
161 | je .end |
||
162 | call .Gif_output |
||
163 | .add: |
||
164 | push eax |
||
165 | mov eax,[.table_ptr] |
||
166 | mov [eax+edx*4],ebx |
||
167 | pop eax |
||
168 | cmp edx,0xFFF |
||
169 | jae .cycle |
||
170 | inc edx |
||
171 | bsr ebx,edx |
||
172 | cmp ebx,[.compsize] |
||
173 | jne .noinc |
||
174 | inc [.compsize] |
||
175 | .noinc: |
||
176 | jmp .cycle |
||
177 | .notintable: |
||
178 | push eax |
||
179 | mov eax,ebx |
||
180 | call .Gif_output |
||
181 | push ebx |
||
182 | movzx eax,bx |
||
183 | call .Gif_output |
||
184 | pop ebx eax |
||
185 | jmp .add |
||
186 | .er: |
||
187 | pop edi |
||
188 | jmp .ex |
||
189 | .end: |
||
190 | mov eax,[.cur_info] |
||
191 | mov [eax],edi |
||
192 | mov [.cur_info],edi |
||
193 | add esi,2 |
||
194 | xchg esi,edi |
||
195 | .nxt: |
||
196 | cmp byte[edi],0 |
||
197 | jnz .continue |
||
198 | inc edi |
||
199 | jmp .nxt |
||
200 | .continue: |
||
201 | cmp byte[edi],0x3b |
||
202 | jne .nextblock |
||
203 | xor eax,eax |
||
204 | stosd |
||
205 | mov ecx,[.img_count] |
||
206 | .ex: |
||
207 | pop edi esi |
||
208 | ret |
||
209 | |||
210 | .Gif_skipmap: |
||
211 | ; in: ecx - image descriptor, esi - pointer to colormap |
||
212 | ; out: edi - pointer to area after colormap |
||
213 | |||
214 | and ecx,111b |
||
215 | inc ecx ; color map size |
||
216 | mov ebx,1 |
||
217 | shl ebx,cl |
||
218 | lea ebx,[ebx*2+ebx] |
||
219 | lea edi,[esi+ebx] |
||
220 | ret |
||
221 | |||
222 | .Gif_get_sym: |
||
223 | mov ecx,[.compsize] |
||
224 | push ecx |
||
225 | xor eax,eax |
||
226 | .shift: |
||
227 | ror byte[esi],1 |
||
228 | rcr eax,1 |
||
229 | dec [.bit_count] |
||
230 | jnz .loop1 |
||
231 | inc esi |
||
232 | cmp esi,[.block_ofs] |
||
233 | jb .noblock |
||
234 | push eax |
||
235 | xor eax,eax |
||
236 | lodsb |
||
237 | test eax,eax |
||
238 | jnz .nextbl |
||
239 | mov eax,[.EOI] |
||
240 | sub esi,2 |
||
241 | add esp,8 |
||
242 | jmp .exx |
||
243 | .nextbl: |
||
244 | add eax,esi |
||
245 | mov [.block_ofs],eax |
||
246 | pop eax |
||
247 | .noblock: |
||
248 | mov [.bit_count],8 |
||
249 | .loop1: |
||
250 | loop .shift |
||
251 | pop ecx |
||
252 | rol eax,cl |
||
253 | .exx: |
||
254 | xor ecx,ecx |
||
255 | ret |
||
256 | |||
257 | .Gif_output: |
||
258 | push esi eax edx |
||
259 | mov edx,[.table_ptr] |
||
260 | .next: |
||
261 | push word[edx+eax*4] |
||
262 | mov ax,word[edx+eax*4+2] |
||
263 | inc ecx |
||
264 | cmp ax,_null |
||
265 | jnz .next |
||
266 | shl ebx,16 |
||
267 | mov bx,[esp] |
||
268 | .loop2: |
||
269 | pop ax |
||
270 | |||
271 | lea esi,[eax+eax*2] |
||
272 | add esi,[.Palette] |
||
273 | |||
274 | if COLOR_ORDER eq MENUETOS |
||
275 | mov esi,[esi] |
||
276 | bswap esi |
||
277 | shr esi,8 |
||
278 | mov [edi],esi |
||
279 | add edi,3 |
||
280 | else |
||
281 | movsw |
||
282 | movsb |
||
283 | and byte[edi],0 |
||
284 | inc edi |
||
285 | end if |
||
286 | |||
287 | loop .loop2 |
||
288 | pop edx eax esi |
||
289 | ret |
||
290 | |||
291 | .globalColor rd 1 |
||
292 | .img_count rd 1 |
||
293 | .cur_info rd 1 ; image table pointer |
||
294 | .img_start rd 1 |
||
295 | .codesize rd 1 |
||
296 | .compsize rd 1 |
||
297 | .bit_count rd 1 |
||
298 | .CC rd 1 |
||
299 | .EOI rd 1 |
||
300 | .Palette rd 1 |
||
301 | .block_ofs rd 1 |
||
302 | .table_ptr rd 1 |