Subversion Repositories Kolibri OS

Rev

Rev 1806 | Details | Compare with Previous | Last modification | View Log | RSS feed

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