Rev 223 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
223 | Ghost | 1 | COLOR_ORDER equ MENUETOS |
2 | gif_hash_offset = gif_hash_area |
||
3 | |||
4 | macro gif2img gifsrc,imgsrc |
||
5 | { |
||
6 | local hasharea, ReadGIF, nextblock,_null |
||
532 | diamond | 7 | ;local globalColor, img_count, cur_info, img_start |
8 | ;local codesize, compsize, bit_count, CC, EOI, Palette |
||
9 | ;local block_ofs, table_ptr, gifmacend |
||
223 | Ghost | 10 | local no_gc, block_skip, no_comm, noextblock, uselocal |
11 | local setPal, filltable, reinit, cycle, zadd, noinc |
||
12 | local notintable, er, zend, nxt, continue, ex, Gif_skipmap |
||
13 | local Gif_get_sym, shift, nextbl, noblock, loop1, exx |
||
14 | local Gif_output, next, loop2 |
||
15 | |||
16 | _null fix 0x1000 ; 0x1000 |
||
17 | |||
18 | if ~gifsrc eq esi |
||
19 | mov esi,gifsrc |
||
20 | end if |
||
21 | if ~imgsrc eq edi |
||
22 | mov edi,imgsrc |
||
23 | end if |
||
24 | |||
25 | if defined gif_hash_offset |
||
26 | mov eax,gif_hash_offset |
||
27 | else |
||
28 | mov eax,hasharea |
||
29 | end if |
||
30 | |||
31 | call ReadGIF |
||
532 | diamond | 32 | ret |
223 | Ghost | 33 | |
34 | if defined gif_hash_offset |
||
35 | else |
||
36 | hasharea: |
||
37 | times 4096 dd 0 ;4096 |
||
38 | end if |
||
39 | |||
40 | ReadGIF: |
||
41 | push esi edi |
||
42 | mov [table_ptr],eax |
||
43 | mov [cur_info],edi |
||
44 | xor eax,eax |
||
45 | mov [globalColor],eax |
||
46 | mov [img_count],eax |
||
47 | inc eax |
||
48 | cmp dword[esi],'GIF8' |
||
532 | diamond | 49 | jne ex ; signature |
223 | Ghost | 50 | mov ecx,[esi+0xa] |
51 | inc eax |
||
52 | add esi,0xd |
||
53 | mov edi,esi |
||
54 | bt ecx,7 |
||
55 | jnc nextblock |
||
56 | mov [globalColor],esi |
||
57 | call Gif_skipmap |
||
58 | nextblock: |
||
59 | cmp byte[edi],0x21 |
||
60 | jne noextblock |
||
61 | inc edi |
||
62 | cmp byte[edi],0xf9 ; Graphic Control Ext |
||
63 | jne no_gc |
||
64 | add edi,7 |
||
65 | jmp nextblock |
||
66 | no_gc: |
||
67 | cmp byte[edi],0xfe ; Comment Ext |
||
68 | jne no_comm |
||
69 | inc edi |
||
70 | block_skip: |
||
71 | movzx eax,byte[edi] |
||
72 | lea edi,[edi+eax+1] |
||
73 | cmp byte[edi],0 |
||
74 | jnz block_skip |
||
75 | inc edi |
||
76 | jmp nextblock |
||
77 | no_comm: |
||
78 | cmp byte[edi],0xff ; Application Ext |
||
79 | jne nextblock |
||
80 | add edi,13 |
||
81 | jmp block_skip |
||
82 | noextblock: |
||
83 | cmp byte[edi],0x2c ; image beginning |
||
532 | diamond | 84 | jne ex |
223 | Ghost | 85 | inc [img_count] |
86 | inc edi |
||
87 | mov esi,[cur_info] |
||
88 | xchg esi,edi |
||
89 | ; movsd |
||
90 | ; movsd |
||
91 | |||
92 | mov bp,word[esi+4] |
||
93 | movzx ebx,bp |
||
94 | mov [edi],ebx |
||
95 | |||
96 | mov bp,word[esi+6] |
||
97 | movzx ebx,bp |
||
98 | mov [edi+4],ebx |
||
99 | |||
100 | add edi,8 |
||
101 | add esi,8 |
||
102 | |||
103 | push edi |
||
104 | movzx ecx,word[esi] |
||
105 | inc esi |
||
106 | bt ecx,7 |
||
107 | jc uselocal |
||
108 | push [globalColor] |
||
109 | mov edi,esi |
||
110 | jmp setPal |
||
111 | uselocal: |
||
112 | call Gif_skipmap |
||
113 | push esi |
||
114 | setPal: |
||
115 | movzx ecx,byte[edi] |
||
116 | inc ecx |
||
117 | mov [codesize],ecx |
||
118 | dec ecx |
||
119 | pop [Palette] |
||
120 | lea esi,[edi+1] |
||
121 | mov edi,[table_ptr] |
||
122 | xor eax,eax |
||
123 | cld |
||
124 | lodsb ; eax - block_count |
||
125 | add eax,esi |
||
126 | mov [block_ofs],eax |
||
127 | mov [bit_count],8 |
||
128 | mov eax,1 |
||
129 | shl eax,cl |
||
130 | mov [CC],eax |
||
131 | inc eax |
||
132 | mov [EOI],eax |
||
133 | lea ecx,[eax-1] |
||
134 | mov eax, _null shl 16 |
||
135 | filltable: |
||
136 | stosd |
||
137 | inc eax |
||
138 | loop filltable |
||
139 | pop edi |
||
140 | reinit: |
||
141 | mov edx,[EOI] |
||
142 | inc edx |
||
143 | push [codesize] |
||
144 | pop [compsize] |
||
145 | call Gif_get_sym |
||
146 | cmp eax,[CC] |
||
147 | je reinit |
||
148 | call Gif_output |
||
149 | cycle: |
||
150 | movzx ebx,ax |
||
151 | call Gif_get_sym |
||
152 | cmp eax,edx |
||
153 | jae notintable |
||
154 | cmp eax,[CC] |
||
155 | je reinit |
||
156 | cmp eax,[EOI] |
||
157 | je zend |
||
158 | call Gif_output |
||
159 | zadd: |
||
160 | push eax |
||
161 | mov eax,[table_ptr] |
||
162 | mov [eax+edx*4],ebx |
||
163 | pop eax |
||
164 | cmp edx,0xFFF |
||
165 | jae cycle |
||
166 | inc edx |
||
167 | bsr ebx,edx |
||
168 | cmp ebx,[compsize] |
||
169 | jne noinc |
||
170 | inc [compsize] |
||
171 | noinc: |
||
172 | jmp cycle |
||
173 | notintable: |
||
174 | push eax |
||
175 | mov eax,ebx |
||
176 | call Gif_output |
||
177 | push ebx |
||
178 | movzx eax,bx |
||
179 | call Gif_output |
||
180 | pop ebx eax |
||
181 | jmp zadd |
||
182 | zend: |
||
183 | ; mov eax,[.cur_info] ; skip offset to next frame |
||
184 | ; mov [eax],edi |
||
185 | mov [cur_info],edi |
||
186 | add esi,2 |
||
187 | xchg esi,edi |
||
188 | nxt: |
||
189 | cmp byte[edi],0 |
||
190 | jnz continue |
||
191 | inc edi |
||
192 | jmp nxt |
||
193 | continue: |
||
194 | ; cmp byte[edi],0x3b ;read next frame |
||
195 | ; jne nextblock |
||
196 | mov ecx,[img_count] |
||
197 | ex: |
||
198 | pop edi esi |
||
199 | ret |
||
200 | |||
201 | Gif_skipmap: |
||
202 | ; in: ecx - image descriptor, esi - pointer to colormap |
||
203 | ; out: edi - pointer to area after colormap |
||
204 | |||
205 | and ecx,111b |
||
206 | inc ecx ; color map size |
||
207 | mov ebx,1 |
||
208 | shl ebx,cl |
||
209 | lea ebx,[ebx*2+ebx] |
||
210 | lea edi,[esi+ebx] |
||
211 | ret |
||
212 | |||
213 | Gif_get_sym: |
||
214 | mov ecx,[compsize] |
||
215 | push ecx |
||
216 | xor eax,eax |
||
217 | shift: |
||
218 | ror byte[esi],1 |
||
219 | rcr eax,1 |
||
220 | dec [bit_count] |
||
221 | jnz loop1 |
||
222 | inc esi |
||
223 | cmp esi,[block_ofs] |
||
224 | jb noblock |
||
225 | push eax |
||
226 | xor eax,eax |
||
227 | lodsb |
||
228 | test eax,eax |
||
229 | jnz nextbl |
||
230 | mov eax,[EOI] |
||
231 | sub esi,2 |
||
232 | add esp,8 |
||
233 | jmp exx |
||
234 | nextbl: |
||
235 | add eax,esi |
||
236 | mov [block_ofs],eax |
||
237 | pop eax |
||
238 | noblock: |
||
239 | mov [bit_count],8 |
||
240 | loop1: |
||
241 | loop shift |
||
242 | pop ecx |
||
243 | rol eax,cl |
||
244 | exx: |
||
245 | xor ecx,ecx |
||
246 | ret |
||
247 | |||
248 | Gif_output: |
||
249 | push esi eax edx |
||
250 | mov edx,[table_ptr] |
||
251 | next: |
||
252 | push word[edx+eax*4] |
||
253 | mov ax,word[edx+eax*4+2] |
||
254 | inc ecx |
||
255 | cmp ax,_null |
||
256 | jnz next |
||
257 | shl ebx,16 |
||
258 | mov bx,[esp] |
||
259 | loop2: |
||
260 | pop ax |
||
261 | |||
262 | lea esi,[eax+eax*2] |
||
263 | add esi,[Palette] |
||
264 | |||
265 | if COLOR_ORDER eq MENUETOS |
||
266 | mov esi,[esi] |
||
267 | bswap esi |
||
268 | shr esi,8 |
||
269 | mov [edi],esi |
||
270 | add edi,3 |
||
271 | else |
||
272 | movsw |
||
273 | movsb |
||
274 | end if |
||
275 | |||
276 | loop loop2 |
||
277 | pop edx eax esi |
||
278 | ret |
||
279 | |||
280 | |||
281 | gifmacend: |
||
282 | } |
||
283 |