Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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