Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
51 | mikedld | 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 | ; FUNCTION GetGIFinfo - retrieve Nth image info |
||
40 | ; **************************************** |
||
41 | ; in: |
||
42 | ; esi - pointer to image list header |
||
43 | ; ecx - image_index (0...img_count-1) |
||
44 | ; edi - pointer to GIF_info structure to be filled |
||
45 | |||
46 | ; out: |
||
47 | ; eax - pointer to RAW data, or 0, if error |
||
48 | |||
49 | GetGIFinfo: |
||
50 | push esi ecx edi |
||
51 | xor eax,eax |
||
52 | jecxz .eloop |
||
53 | .lp: |
||
54 | mov esi,[esi] |
||
55 | test esi,esi |
||
56 | jz .error |
||
57 | loop .lp |
||
58 | .eloop: |
||
59 | add esi,4 |
||
60 | movsd |
||
61 | movsd |
||
62 | mov eax,esi |
||
63 | .error: |
||
64 | pop edi ecx esi |
||
65 | ret |
||
66 | |||
67 | ; **************************************** |
||
68 | ; FUNCTION ReadGIF - unpacks GIF image |
||
69 | ; **************************************** |
||
70 | ; in: |
||
71 | ; esi - pointer to GIF file in memory |
||
72 | ; edi - pointer to output image list |
||
73 | ; eax - pointer to work area (MIN 16 KB!) |
||
74 | |||
75 | ; out: |
||
76 | ; eax - 0, all OK; |
||
77 | ; eax - 1, invalid signature; |
||
78 | ; eax >=8, unsupported image attributes |
||
79 | ; |
||
80 | ; ecx - number of images |
||
81 | |||
82 | ReadGIF: |
||
83 | push esi edi |
||
84 | mov [.table_ptr],eax |
||
85 | mov [.cur_info],edi |
||
86 | xor eax,eax |
||
87 | mov [.globalColor],eax |
||
88 | mov [.img_count],eax |
||
89 | inc eax |
||
90 | cmp dword[esi],'GIF8' |
||
91 | jne .er ; signature |
||
92 | mov ecx,[esi+0xa] |
||
93 | inc eax |
||
94 | add esi,0xd |
||
95 | mov edi,esi |
||
96 | bt ecx,7 |
||
97 | jnc .nextblock |
||
98 | mov [.globalColor],esi |
||
99 | call .Gif_skipmap |
||
100 | .nextblock: |
||
101 | cmp byte[edi],0x21 |
||
102 | jne .noextblock |
||
103 | inc edi |
||
104 | cmp byte[edi],0xf9 ; Graphic Control Ext |
||
105 | jne .no_gc |
||
106 | add edi,7 |
||
107 | jmp .nextblock |
||
108 | .no_gc: |
||
109 | cmp byte[edi],0xfe ; Comment Ext |
||
110 | jne .no_comm |
||
111 | inc edi |
||
112 | .block_skip: |
||
113 | movzx eax,byte[edi] |
||
114 | lea edi,[edi+eax+1] |
||
115 | cmp byte[edi],0 |
||
116 | jnz .block_skip |
||
117 | inc edi |
||
118 | jmp .nextblock |
||
119 | .no_comm: |
||
120 | cmp byte[edi],0xff ; Application Ext |
||
121 | jne .nextblock |
||
122 | add edi,13 |
||
123 | jmp .block_skip |
||
124 | .noextblock: |
||
125 | cmp byte[edi],0x2c ; image beginning |
||
126 | jne .er |
||
127 | inc [.img_count] |
||
128 | inc edi |
||
129 | mov esi,[.cur_info] |
||
130 | add esi,4 |
||
131 | xchg esi,edi |
||
132 | movsd |
||
133 | movsd |
||
134 | push edi |
||
135 | movzx ecx,word[esi] |
||
136 | inc esi |
||
137 | bt ecx,7 |
||
138 | jc .uselocal |
||
139 | push [.globalColor] |
||
140 | mov edi,esi |
||
141 | jmp .setPal |
||
142 | .uselocal: |
||
143 | call .Gif_skipmap |
||
144 | push esi |
||
145 | .setPal: |
||
146 | movzx ecx,byte[edi] |
||
147 | inc ecx |
||
148 | mov [.codesize],ecx |
||
149 | dec ecx |
||
150 | pop [.Palette] |
||
151 | lea esi,[edi+1] |
||
152 | mov edi,[.table_ptr] |
||
153 | xor eax,eax |
||
154 | cld |
||
155 | lodsb ; eax - block_count |
||
156 | add eax,esi |
||
157 | mov [.block_ofs],eax |
||
158 | mov [.bit_count],8 |
||
159 | mov eax,1 |
||
160 | shl eax,cl |
||
161 | mov [.CC],eax |
||
162 | inc eax |
||
163 | mov [.EOI],eax |
||
164 | lea ecx,[eax-1] |
||
165 | mov eax, _null shl 16 |
||
166 | .filltable: |
||
167 | stosd |
||
168 | inc eax |
||
169 | loop .filltable |
||
170 | pop edi |
||
171 | mov [.img_start],edi |
||
172 | .reinit: |
||
173 | mov edx,[.EOI] |
||
174 | inc edx |
||
175 | push [.codesize] |
||
176 | pop [.compsize] |
||
177 | call .Gif_get_sym |
||
178 | cmp eax,[.CC] |
||
179 | je .reinit |
||
180 | call .Gif_output |
||
181 | .cycle: |
||
182 | movzx ebx,ax |
||
183 | call .Gif_get_sym |
||
184 | cmp eax,edx |
||
185 | jae .notintable |
||
186 | cmp eax,[.CC] |
||
187 | je .reinit |
||
188 | cmp eax,[.EOI] |
||
189 | je .end |
||
190 | call .Gif_output |
||
191 | .add: |
||
192 | push eax |
||
193 | mov eax,[.table_ptr] |
||
194 | mov [eax+edx*4],ebx |
||
195 | pop eax |
||
196 | cmp edx,0xFFF |
||
197 | jae .cycle |
||
198 | inc edx |
||
199 | bsr ebx,edx |
||
200 | cmp ebx,[.compsize] |
||
201 | jne .noinc |
||
202 | inc [.compsize] |
||
203 | .noinc: |
||
204 | jmp .cycle |
||
205 | .notintable: |
||
206 | push eax |
||
207 | mov eax,ebx |
||
208 | call .Gif_output |
||
209 | push ebx |
||
210 | movzx eax,bx |
||
211 | call .Gif_output |
||
212 | pop ebx eax |
||
213 | jmp .add |
||
214 | .er: |
||
215 | pop edi |
||
216 | jmp .ex |
||
217 | .end: |
||
218 | mov eax,[.cur_info] |
||
219 | mov [eax],edi |
||
220 | mov [.cur_info],edi |
||
221 | add esi,2 |
||
222 | xchg esi,edi |
||
223 | .nxt: |
||
224 | cmp byte[edi],0 |
||
225 | jnz .continue |
||
226 | inc edi |
||
227 | jmp .nxt |
||
228 | .continue: |
||
229 | cmp byte[edi],0x3b |
||
230 | jne .nextblock |
||
231 | xor eax,eax |
||
232 | stosd |
||
233 | mov ecx,[.img_count] |
||
234 | .ex: |
||
235 | pop edi esi |
||
236 | ret |
||
237 | |||
238 | .Gif_skipmap: |
||
239 | ; in: ecx - image descriptor, esi - pointer to colormap |
||
240 | ; out: edi - pointer to area after colormap |
||
241 | |||
242 | and ecx,111b |
||
243 | inc ecx ; color map size |
||
244 | mov ebx,1 |
||
245 | shl ebx,cl |
||
246 | lea ebx,[ebx*2+ebx] |
||
247 | lea edi,[esi+ebx] |
||
248 | ret |
||
249 | |||
250 | .Gif_get_sym: |
||
251 | mov ecx,[.compsize] |
||
252 | push ecx |
||
253 | xor eax,eax |
||
254 | .shift: |
||
255 | ror byte[esi],1 |
||
256 | rcr eax,1 |
||
257 | dec [.bit_count] |
||
258 | jnz .loop1 |
||
259 | inc esi |
||
260 | cmp esi,[.block_ofs] |
||
261 | jb .noblock |
||
262 | push eax |
||
263 | xor eax,eax |
||
264 | lodsb |
||
265 | test eax,eax |
||
266 | jnz .nextbl |
||
267 | mov eax,[.EOI] |
||
268 | sub esi,2 |
||
269 | add esp,8 |
||
270 | jmp .exx |
||
271 | .nextbl: |
||
272 | add eax,esi |
||
273 | mov [.block_ofs],eax |
||
274 | pop eax |
||
275 | .noblock: |
||
276 | mov [.bit_count],8 |
||
277 | .loop1: |
||
278 | loop .shift |
||
279 | pop ecx |
||
280 | rol eax,cl |
||
281 | .exx: |
||
282 | xor ecx,ecx |
||
283 | ret |
||
284 | |||
285 | .Gif_output: |
||
286 | push esi eax edx |
||
287 | mov edx,[.table_ptr] |
||
288 | .next: |
||
289 | push word[edx+eax*4] |
||
290 | mov ax,word[edx+eax*4+2] |
||
291 | inc ecx |
||
292 | cmp ax,_null |
||
293 | jnz .next |
||
294 | shl ebx,16 |
||
295 | mov bx,[esp] |
||
296 | .loop2: |
||
297 | pop ax |
||
298 | |||
299 | lea esi,[eax+eax*2] |
||
300 | add esi,[.Palette] |
||
301 | |||
302 | if COLOR_ORDER eq MENUETOS |
||
303 | mov esi,[esi] |
||
304 | bswap esi |
||
305 | shr esi,8 |
||
306 | mov [edi],esi |
||
307 | add edi,3 |
||
308 | else |
||
309 | movsw |
||
310 | movsb |
||
311 | end if |
||
312 | |||
313 | loop .loop2 |
||
314 | pop edx eax esi |
||
315 | ret |
||
316 | |||
317 | .globalColor rd 1 |
||
318 | .img_count rd 1 |
||
319 | .cur_info rd 1 ; image table pointer |
||
320 | .img_start rd 1 |
||
321 | .codesize rd 1 |
||
322 | .compsize rd 1 |
||
323 | .bit_count rd 1 |
||
324 | .CC rd 1 |
||
325 | .EOI rd 1 |
||
326 | .Palette rd 1 |
||
327 | .block_ofs rd 1 |
||
328 | .table_ptr rd 1 |