Subversion Repositories Kolibri OS

Rev

Rev 134 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
134 diamond 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'
139 diamond 91
    jne  .ex            ; signature
134 diamond 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
139 diamond 126
    jne  .ex
134 diamond 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
  .end:
215
    mov  eax,[.cur_info]
216
    mov  [eax],edi
217
    mov  [.cur_info],edi
218
    add  esi,2
219
    xchg esi,edi
220
  .nxt:
221
    cmp  byte[edi],0
222
    jnz  .continue
223
    inc  edi
224
    jmp  .nxt
225
  .continue:
226
    cmp  byte[edi],0x3b
227
    jne  .nextblock
228
    xor  eax,eax
229
    mov  ecx,[.img_count]
230
  .ex:
231
    pop  edi esi
232
    ret
233
 
234
.Gif_skipmap:
235
; in: ecx - image descriptor, esi - pointer to colormap
236
; out: edi - pointer to area after colormap
237
 
238
    and  ecx,111b
239
    inc  ecx            ; color map size
240
    mov  ebx,1
241
    shl  ebx,cl
242
    lea  ebx,[ebx*2+ebx]
243
    lea  edi,[esi+ebx]
244
    ret
245
 
246
.Gif_get_sym:
247
    mov  ecx,[.compsize]
248
    push ecx
249
    xor  eax,eax
250
  .shift:
251
    ror  byte[esi],1
252
    rcr  eax,1
253
    dec  [.bit_count]
254
    jnz  .loop1
255
    inc  esi
256
    cmp  esi,[.block_ofs]
257
    jb   .noblock
258
    push eax
259
    xor  eax,eax
260
    lodsb
261
    test eax,eax
262
    jnz  .nextbl
263
    mov  eax,[.EOI]
264
    sub  esi,2
265
    add  esp,8
266
    jmp  .exx
267
  .nextbl:
268
    add  eax,esi
269
    mov  [.block_ofs],eax
270
    pop  eax
271
  .noblock:
272
    mov  [.bit_count],8
273
  .loop1:
274
    loop .shift
275
    pop  ecx
276
    rol  eax,cl
277
  .exx:
278
    xor  ecx,ecx
279
    ret
280
 
281
.Gif_output:
282
    push esi eax edx
283
    mov  edx,[.table_ptr]
284
  .next:
285
    push word[edx+eax*4]
286
    mov  ax,word[edx+eax*4+2]
287
    inc  ecx
288
    cmp  ax,_null
289
    jnz  .next
290
    shl  ebx,16
291
    mov  bx,[esp]
292
  .loop2:
293
    pop  ax
294
 
295
    lea  esi,[eax+eax*2]
296
    add  esi,[.Palette]
297
 
298
    if COLOR_ORDER eq MENUETOS
299
        mov  esi,[esi]
300
        bswap esi
301
        shr  esi,8
302
        mov  [edi],esi
303
        add  edi,3
304
    else
305
        movsw
306
        movsb
307
    end if
308
 
309
    loop .loop2
310
    pop  edx eax esi
311
    ret
312
 
313
    .globalColor rd 1
314
    .img_count rd 1
315
    .cur_info rd 1        ; image table pointer
316
    .img_start rd 1
317
    .codesize rd 1
318
    .compsize rd 1
319
    .bit_count rd 1
320
    .CC rd 1
321
    .EOI rd 1
322
    .Palette rd 1
323
    .block_ofs rd 1
324
    .table_ptr rd 1