Subversion Repositories Kolibri OS

Rev

Rev 223 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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