Subversion Repositories Kolibri OS

Rev

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

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