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