Subversion Repositories Kolibri OS

Rev

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

Rev 1102 Rev 1152
1
;;================================================================================================;;
1
;;================================================================================================;;
2
;;//// libimg.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ////////////////////////////////;;
2
;;//// libimg.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ////////////////////////////////;;
3
;;================================================================================================;;
3
;;================================================================================================;;
4
;;                                                                                                ;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
9
;; of the License, or (at your option) any later version.                                         ;;
9
;; of the License, or (at your option) any later version.                                         ;;
10
;;                                                                                                ;;
10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
13
;; Lesser General Public License for more details.                                                ;;
13
;; Lesser General Public License for more details.                                                ;;
14
;;                                                                                                ;;
14
;;                                                                                                ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
18
;;================================================================================================;;
19
 
19
 
20
 
20
 
21
format MS COFF
21
format MS COFF
22
 
22
 
23
public @EXPORT as 'EXPORTS'
23
public @EXPORT as 'EXPORTS'
24
 
24
 
25
include '../../../../struct.inc'
25
include '../../../../struct.inc'
26
include '../../../../proc32.inc'
26
include '../../../../proc32.inc'
27
include '../../../../macros.inc'
27
include '../../../../macros.inc'
28
purge section,mov,add,sub
28
purge section,mov,add,sub
29
 
29
 
30
include 'libimg.inc'
30
include 'libimg.inc'
31
 
31
 
32
section '.flat' code readable align 16
32
section '.flat' code readable align 16
33
 
33
 
34
include 'bmp/bmp.asm'
34
include 'bmp/bmp.asm'
35
include 'gif/gif.asm'
35
include 'gif/gif.asm'
36
include 'jpeg/jpeg.asm'
36
include 'jpeg/jpeg.asm'
37
include 'png/png.asm'
37
include 'png/png.asm'
38
include 'tga/tga.asm'
38
include 'tga/tga.asm'
39
include 'z80/z80.asm'
39
include 'z80/z80.asm'
40
include 'ico_cur/ico_cur.asm'
40
include 'ico_cur/ico_cur.asm'
41
 
41
 
42
;;================================================================================================;;
42
;;================================================================================================;;
43
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
43
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
44
;;------------------------------------------------------------------------------------------------;;
44
;;------------------------------------------------------------------------------------------------;;
45
;? Library entry point (called after library load)                                                ;;
45
;? Library entry point (called after library load)                                                ;;
46
;;------------------------------------------------------------------------------------------------;;
46
;;------------------------------------------------------------------------------------------------;;
47
;> eax = pointer to memory allocation routine                                                     ;;
47
;> eax = pointer to memory allocation routine                                                     ;;
48
;> ebx = pointer to memory freeing routine                                                        ;;
48
;> ebx = pointer to memory freeing routine                                                        ;;
49
;> ecx = pointer to memory reallocation routine                                                   ;;
49
;> ecx = pointer to memory reallocation routine                                                   ;;
50
;> edx = pointer to library loading routine                                                       ;;
50
;> edx = pointer to library loading routine                                                       ;;
51
;;------------------------------------------------------------------------------------------------;;
51
;;------------------------------------------------------------------------------------------------;;
52
;< eax = 1 (fail) / 0 (ok) (library initialization result)                                        ;;
52
;< eax = 1 (fail) / 0 (ok) (library initialization result)                                        ;;
53
;;================================================================================================;;
53
;;================================================================================================;;
54
	mov	[mem.alloc], eax
54
	mov	[mem.alloc], eax
55
	mov	[mem.free], ebx
55
	mov	[mem.free], ebx
56
	mov	[mem.realloc], ecx
56
	mov	[mem.realloc], ecx
57
	mov	[dll.load], edx
57
	mov	[dll.load], edx
58
 
58
 
59
	call	img.initialize.jpeg
59
	call	img.initialize.jpeg
60
 
60
 
61
	xor	eax, eax
61
	xor	eax, eax
62
	cpuid
62
	cpuid
63
	cmp	ecx, 'ntel'
63
	cmp	ecx, 'ntel'
64
	jnz	@f
64
	jnz	@f
65
	mov	dword [img._.do_rgb.handlers + (Image.bpp15-1)*4], img._.do_rgb.bpp15.intel
65
	mov	dword [img._.do_rgb.handlers + (Image.bpp15-1)*4], img._.do_rgb.bpp15.intel
66
	mov	dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
66
	mov	dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
67
  @@:
67
  @@:
68
 
68
 
69
  .ok:	xor	eax,eax
69
  .ok:	xor	eax,eax
70
	ret
70
	ret
71
endp
71
endp
72
 
72
 
73
;;================================================================================================;;
73
;;================================================================================================;;
74
proc img.is_img _data, _length ;//////////////////////////////////////////////////////////////////;;
74
proc img.is_img _data, _length ;//////////////////////////////////////////////////////////////////;;
75
;;------------------------------------------------------------------------------------------------;;
75
;;------------------------------------------------------------------------------------------------;;
76
;? --- TBD ---                                                                                    ;;
76
;? --- TBD ---                                                                                    ;;
77
;;------------------------------------------------------------------------------------------------;;
77
;;------------------------------------------------------------------------------------------------;;
78
;> --- TBD ---                                                                                    ;;
78
;> --- TBD ---                                                                                    ;;
79
;;------------------------------------------------------------------------------------------------;;
79
;;------------------------------------------------------------------------------------------------;;
80
;< --- TBD ---                                                                                    ;;
80
;< --- TBD ---                                                                                    ;;
81
;;================================================================================================;;
81
;;================================================================================================;;
82
	push	ebx
82
	push	ebx
83
	mov	ebx, img._.formats_table
83
	mov	ebx, img._.formats_table
84
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
84
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
85
	or	eax, eax
85
	or	eax, eax
86
	jnz	@f
86
	jnz	@f
87
	add	ebx, sizeof.FormatsTableEntry
87
	add	ebx, sizeof.FormatsTableEntry
88
	cmp	dword[ebx], 0
88
	cmp	dword[ebx], 0
89
	jnz	@b
89
	jnz	@b
90
	xor	eax, eax
90
	xor	eax, eax
91
    @@: pop	ebx
91
    @@: pop	ebx
92
	ret
92
	ret
93
endp
93
endp
94
 
94
 
95
;;================================================================================================;;
95
;;================================================================================================;;
96
proc img.info _data, _length ;////////////////////////////////////////////////////////////////////;;
96
proc img.info _data, _length ;////////////////////////////////////////////////////////////////////;;
97
;;------------------------------------------------------------------------------------------------;;
97
;;------------------------------------------------------------------------------------------------;;
98
;? --- TBD ---                                                                                    ;;
98
;? --- TBD ---                                                                                    ;;
99
;;------------------------------------------------------------------------------------------------;;
99
;;------------------------------------------------------------------------------------------------;;
100
;> --- TBD ---                                                                                    ;;
100
;> --- TBD ---                                                                                    ;;
101
;;------------------------------------------------------------------------------------------------;;
101
;;------------------------------------------------------------------------------------------------;;
102
;< --- TBD ---                                                                                    ;;
102
;< --- TBD ---                                                                                    ;;
103
;;================================================================================================;;
103
;;================================================================================================;;
104
	xor	eax, eax
104
	xor	eax, eax
105
	ret
105
	ret
106
endp
106
endp
107
 
107
 
108
;;================================================================================================;;
108
;;================================================================================================;;
109
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
109
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
110
;;------------------------------------------------------------------------------------------------;;
110
;;------------------------------------------------------------------------------------------------;;
111
;? --- TBD ---                                                                                    ;;
111
;? --- TBD ---                                                                                    ;;
112
;;------------------------------------------------------------------------------------------------;;
112
;;------------------------------------------------------------------------------------------------;;
113
;> --- TBD ---                                                                                    ;;
113
;> --- TBD ---                                                                                    ;;
114
;;------------------------------------------------------------------------------------------------;;
114
;;------------------------------------------------------------------------------------------------;;
115
;< eax = 0 / pointer to image                                                                     ;;
115
;< eax = 0 / pointer to image                                                                     ;;
116
;;================================================================================================;;
116
;;================================================================================================;;
117
	xor	eax, eax
117
	xor	eax, eax
118
	ret
118
	ret
119
endp
119
endp
120
 
120
 
121
;;================================================================================================;;
121
;;================================================================================================;;
122
proc img.to_file _img, _filename ;////////////////////////////////////////////////////////////////;;
122
proc img.to_file _img, _filename ;////////////////////////////////////////////////////////////////;;
123
;;------------------------------------------------------------------------------------------------;;
123
;;------------------------------------------------------------------------------------------------;;
124
;? --- TBD ---                                                                                    ;;
124
;? --- TBD ---                                                                                    ;;
125
;;------------------------------------------------------------------------------------------------;;
125
;;------------------------------------------------------------------------------------------------;;
126
;> --- TBD ---                                                                                    ;;
126
;> --- TBD ---                                                                                    ;;
127
;;------------------------------------------------------------------------------------------------;;
127
;;------------------------------------------------------------------------------------------------;;
128
;< eax = false / true                                                                             ;;
128
;< eax = false / true                                                                             ;;
129
;;================================================================================================;;
129
;;================================================================================================;;
130
	xor	eax, eax
130
	xor	eax, eax
131
	ret
131
	ret
132
endp
132
endp
133
 
133
 
134
;;================================================================================================;;
134
;;================================================================================================;;
135
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////////////////////////;;
135
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////////////////////////;;
136
;;------------------------------------------------------------------------------------------------;;
136
;;------------------------------------------------------------------------------------------------;;
137
;? --- TBD ---                                                                                    ;;
137
;? --- TBD ---                                                                                    ;;
138
;;------------------------------------------------------------------------------------------------;;
138
;;------------------------------------------------------------------------------------------------;;
139
;> --- TBD ---                                                                                    ;;
139
;> --- TBD ---                                                                                    ;;
140
;;------------------------------------------------------------------------------------------------;;
140
;;------------------------------------------------------------------------------------------------;;
141
;< eax = 0 / pointer to image                                                                     ;;
141
;< eax = 0 / pointer to image                                                                     ;;
142
;;================================================================================================;;
142
;;================================================================================================;;
143
	xor	eax, eax
143
	xor	eax, eax
144
	ret
144
	ret
145
endp
145
endp
146
 
146
 
147
;;================================================================================================;;
147
;;================================================================================================;;
148
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
148
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
149
;;------------------------------------------------------------------------------------------------;;
149
;;------------------------------------------------------------------------------------------------;;
150
;? --- TBD ---                                                                                    ;;
150
;? --- TBD ---                                                                                    ;;
151
;;------------------------------------------------------------------------------------------------;;
151
;;------------------------------------------------------------------------------------------------;;
152
;> --- TBD ---                                                                                    ;;
152
;> --- TBD ---                                                                                    ;;
153
;;------------------------------------------------------------------------------------------------;;
153
;;------------------------------------------------------------------------------------------------;;
154
;< --- TBD ---                                                                                    ;;
154
;< --- TBD ---                                                                                    ;;
155
;;================================================================================================;;
155
;;================================================================================================;;
156
	push	esi edi
156
	push	esi edi
157
	mov	esi, [_img]
157
	mov	esi, [_img]
158
	stdcall	img._.validate, esi
158
	stdcall	img._.validate, esi
159
	or	eax, eax
159
	or	eax, eax
160
	jnz	.ret
160
	jnz	.ret
161
	mov	edi, [_out]
161
	mov	edi, [_out]
162
	call	img._.do_rgb
162
	call	img._.do_rgb
163
.ret:
163
.ret:
164
	pop	edi esi
164
	pop	edi esi
165
	ret
165
	ret
166
endp
166
endp
167
 
167
 
168
;;================================================================================================;;
168
;;================================================================================================;;
169
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
169
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
170
;;------------------------------------------------------------------------------------------------;;
170
;;------------------------------------------------------------------------------------------------;;
171
;? --- TBD ---                                                                                    ;;
171
;? --- TBD ---                                                                                    ;;
172
;;------------------------------------------------------------------------------------------------;;
172
;;------------------------------------------------------------------------------------------------;;
173
;> --- TBD ---                                                                                    ;;
173
;> --- TBD ---                                                                                    ;;
174
;;------------------------------------------------------------------------------------------------;;
174
;;------------------------------------------------------------------------------------------------;;
175
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets)                                        ;;
175
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets)                                        ;;
176
;;================================================================================================;;
176
;;================================================================================================;;
177
	push	esi edi
177
	push	esi edi
178
	mov	esi, [_img]
178
	mov	esi, [_img]
179
	stdcall img._.validate, esi
179
	stdcall img._.validate, esi
180
	or	eax, eax
180
	or	eax, eax
181
	jnz	.error
181
	jnz	.error
182
 
182
 
183
	mov	esi, [_img]
183
	mov	esi, [_img]
184
	mov	ecx, [esi + Image.Width]
184
	mov	ecx, [esi + Image.Width]
185
	imul	ecx, [esi + Image.Height]
185
	imul	ecx, [esi + Image.Height]
186
	lea	eax, [ecx * 3 + 4 * 3]
186
	lea	eax, [ecx * 3 + 4 * 3]
187
	invoke	mem.alloc, eax
187
	invoke	mem.alloc, eax
188
	or	eax, eax
188
	or	eax, eax
189
	jz	.error
189
	jz	.error
190
 
190
 
191
	mov	edi, eax
191
	mov	edi, eax
192
	push	eax
192
	push	eax
193
	mov	eax, [esi + Image.Width]
193
	mov	eax, [esi + Image.Width]
194
	stosd
194
	stosd
195
	mov	eax, [esi + Image.Height]
195
	mov	eax, [esi + Image.Height]
196
	stosd
196
	stosd
197
	call	img._.do_rgb
197
	call	img._.do_rgb
198
	pop	eax
198
	pop	eax
199
	pop	edi esi
199
	pop	edi esi
200
	ret
200
	ret
201
 
201
 
202
  .error:
202
  .error:
203
	xor	eax, eax
203
	xor	eax, eax
204
	pop	edi esi
204
	pop	edi esi
205
	ret
205
	ret
206
endp
206
endp
207
 
207
 
208
;;================================================================================================;;
208
;;================================================================================================;;
209
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
209
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
210
;;------------------------------------------------------------------------------------------------;;
210
;;------------------------------------------------------------------------------------------------;;
211
;? --- TBD ---                                                                                    ;;
211
;? --- TBD ---                                                                                    ;;
212
;;------------------------------------------------------------------------------------------------;;
212
;;------------------------------------------------------------------------------------------------;;
213
;> --- TBD ---                                                                                    ;;
213
;> --- TBD ---                                                                                    ;;
214
;;------------------------------------------------------------------------------------------------;;
214
;;------------------------------------------------------------------------------------------------;;
215
;< --- TBD ---                                                                                    ;;
215
;< --- TBD ---                                                                                    ;;
216
;;================================================================================================;;
216
;;================================================================================================;;
217
	mov	ecx, [esi + Image.Width]
217
	mov	ecx, [esi + Image.Width]
218
	imul	ecx, [esi + Image.Height]
218
	imul	ecx, [esi + Image.Height]
219
	mov	eax, [esi + Image.Type]
219
	mov	eax, [esi + Image.Type]
220
	jmp	dword [.handlers + (eax-1)*4]
220
	jmp	dword [.handlers + (eax-1)*4]
221
 
221
 
222
align 16
222
align 16
223
.bpp8:
223
.bpp8:
224
; 8 BPP -> 24 BPP
224
; 8 BPP -> 24 BPP
225
	push	ebx
225
	push	ebx
226
	mov	ebx, [esi + Image.Palette]
226
	mov	ebx, [esi + Image.Palette]
227
	mov	esi, [esi + Image.Data]
227
	mov	esi, [esi + Image.Data]
-
 
228
	sub	ecx, 1
-
 
229
	jz	.bpp8.last
228
@@:
230
@@:
229
	movzx	eax, byte [esi]
231
	movzx	eax, byte [esi]
230
	add	esi, 1
232
	add	esi, 1
231
	mov	eax, [ebx + eax*4]
233
	mov	eax, [ebx + eax*4]
232
	mov	[edi], eax
234
	mov	[edi], eax
233
	add	edi, 3
235
	add	edi, 3
234
	sub	ecx, 1
236
	sub	ecx, 1
235
	jnz	@b
237
	jnz	@b
-
 
238
.bpp8.last:
-
 
239
	movzx	eax, byte [esi]
-
 
240
	mov	eax, [ebx + eax*4]
-
 
241
	mov	[edi], ax
-
 
242
	shr	eax, 16
-
 
243
	mov	[edi+2], al
236
	pop	ebx
244
	pop	ebx
237
	ret
245
	ret
238
 
246
 
239
; 15 BPP -> 24 BPP
247
; 15 BPP -> 24 BPP
240
.bpp15.intel:
248
.bpp15.intel:
241
	push	ebx ebp
249
	push	ebx ebp
242
	sub	ecx, 4
250
	sub	ecx, 4
243
	jb	.bpp15.tail
251
	jb	.bpp15.tail
244
align 16
252
align 16
245
.bpp15.intel.loop:
253
.bpp15.intel.loop:
246
repeat 2
254
repeat 2
247
	mov	ebx, [esi]
255
	mov	ebx, [esi]
248
	mov	al, [esi]
256
	mov	al, [esi]
249
	mov	ah, [esi+1]
257
	mov	ah, [esi+1]
250
	add	esi, 4
258
	add	esi, 4
251
	and	al, 0x1F
259
	and	al, 0x1F
252
	and	ah, 0x1F shl 2
260
	and	ah, 0x1F shl 2
253
	mov	ebp, ebx
261
	mov	ebp, ebx
254
	mov	dl, al
262
	mov	dl, al
255
	mov	dh, ah
263
	mov	dh, ah
256
	shr	al, 2
264
	shr	al, 2
257
	shr	ah, 4
265
	shr	ah, 4
258
	shl	dl, 3
266
	shl	dl, 3
259
	shl	dh, 1
267
	shl	dh, 1
260
	and	ebp, 0x1F shl 5
268
	and	ebp, 0x1F shl 5
261
	add	al, dl
269
	add	al, dl
262
	add	ah, dh
270
	add	ah, dh
263
	shr	ebp, 2
271
	shr	ebp, 2
264
	mov	[edi], al
272
	mov	[edi], al
265
	mov	[edi+2], ah
273
	mov	[edi+2], ah
266
	mov	eax, ebx
274
	mov	eax, ebx
267
	mov	ebx, ebp
275
	mov	ebx, ebp
268
	shr	eax, 16
276
	shr	eax, 16
269
	shr	ebx, 5
277
	shr	ebx, 5
270
	add	ebx, ebp
278
	add	ebx, ebp
271
	mov	ebp, eax
279
	mov	ebp, eax
272
	mov	[edi+1], bl
280
	mov	[edi+1], bl
273
	and	eax, (0x1F) or (0x1F shl 10)
281
	and	eax, (0x1F) or (0x1F shl 10)
274
	and	ebp, 0x1F shl 5
282
	and	ebp, 0x1F shl 5
275
	lea	edx, [eax+eax]
283
	lea	edx, [eax+eax]
276
	shr	al, 2
284
	shr	al, 2
277
	mov	ebx, ebp
285
	mov	ebx, ebp
278
	shr	ah, 4
286
	shr	ah, 4
279
	shl	dl, 2
287
	shl	dl, 2
280
	shr	ebx, 2
288
	shr	ebx, 2
281
	shr	ebp, 7
289
	shr	ebp, 7
282
	add	al, dl
290
	add	al, dl
283
	add	ah, dh
291
	add	ah, dh
284
	mov	[edi+3], al
292
	mov	[edi+3], al
285
	add	ebx, ebp
293
	add	ebx, ebp
286
	mov	[edi+5], ah
294
	mov	[edi+5], ah
287
	mov	[edi+4], bl
295
	mov	[edi+4], bl
288
	add	edi, 6
296
	add	edi, 6
289
end repeat
297
end repeat
290
	sub	ecx, 4
298
	sub	ecx, 4
291
	jnb	.bpp15.intel.loop
299
	jnb	.bpp15.intel.loop
292
.bpp15.tail:
300
.bpp15.tail:
293
	add	ecx, 4
301
	add	ecx, 4
294
	jz	.bpp15.done
302
	jz	.bpp15.done
295
@@:
303
@@:
296
	movzx	eax, word [esi]
304
	movzx	eax, word [esi]
297
	mov	ebx, eax
305
	mov	ebx, eax
298
	add	esi, 2
306
	add	esi, 2
299
	and	eax, (0x1F) or (0x1F shl 10)
307
	and	eax, (0x1F) or (0x1F shl 10)
300
	and	ebx, 0x1F shl 5
308
	and	ebx, 0x1F shl 5
301
	lea	edx, [eax+eax]
309
	lea	edx, [eax+eax]
302
	shr	al, 2
310
	shr	al, 2
303
	mov	ebp, ebx
311
	mov	ebp, ebx
304
	shr	ebx, 2
312
	shr	ebx, 2
305
	shr	ah, 4
313
	shr	ah, 4
306
	shl	dl, 2
314
	shl	dl, 2
307
	shr	ebp, 7
315
	shr	ebp, 7
308
	add	eax, edx
316
	add	eax, edx
309
	add	ebx, ebp
317
	add	ebx, ebp
310
	mov	[edi], al
318
	mov	[edi], al
311
	mov	[edi+1], bl
319
	mov	[edi+1], bl
312
	mov	[edi+2], ah
320
	mov	[edi+2], ah
313
	add	edi, 3
321
	add	edi, 3
314
	sub	ecx, 1
322
	sub	ecx, 1
315
	jnz	@b
323
	jnz	@b
316
.bpp15.done:
324
.bpp15.done:
317
	pop	ebp ebx
325
	pop	ebp ebx
318
	ret
326
	ret
319
 
327
 
320
.bpp15.amd:
328
.bpp15.amd:
321
	push	ebx ebp
329
	push	ebx ebp
322
	sub	ecx, 4
330
	sub	ecx, 4
323
	jb	.bpp15.tail
331
	jb	.bpp15.tail
324
align 16
332
align 16
325
.bpp15.amd.loop:
333
.bpp15.amd.loop:
326
repeat 4
334
repeat 4
327
if (% mod 2) = 1
335
if (% mod 2) = 1
328
	mov	eax, dword [esi]
336
	mov	eax, dword [esi]
329
	mov	ebx, dword [esi]
337
	mov	ebx, dword [esi]
330
else
338
else
331
	movzx	eax, word [esi]
339
	movzx	eax, word [esi]
332
	mov	ebx, eax
340
	mov	ebx, eax
333
end if
341
end if
334
	add	esi, 2
342
	add	esi, 2
335
	and	eax, (0x1F) or (0x1F shl 10)
343
	and	eax, (0x1F) or (0x1F shl 10)
336
	and	ebx, 0x1F shl 5
344
	and	ebx, 0x1F shl 5
337
	lea	edx, [eax+eax]
345
	lea	edx, [eax+eax]
338
	shr	al, 2
346
	shr	al, 2
339
	mov	ebp, ebx
347
	mov	ebp, ebx
340
	shr	ebx, 2
348
	shr	ebx, 2
341
	shr	ah, 4
349
	shr	ah, 4
342
	shl	dl, 2
350
	shl	dl, 2
343
	shr	ebp, 7
351
	shr	ebp, 7
344
	add	eax, edx
352
	add	eax, edx
345
	add	ebx, ebp
353
	add	ebx, ebp
346
	mov	[edi], al
354
	mov	[edi], al
347
	mov	[edi+1], bl
355
	mov	[edi+1], bl
348
	mov	[edi+2], ah
356
	mov	[edi+2], ah
349
	add	edi, 3
357
	add	edi, 3
350
end repeat
358
end repeat
351
	sub	ecx, 4
359
	sub	ecx, 4
352
	jnb	.bpp15.amd.loop
360
	jnb	.bpp15.amd.loop
353
	jmp	.bpp15.tail
361
	jmp	.bpp15.tail
354
 
362
 
355
; 16 BPP -> 24 BPP
363
; 16 BPP -> 24 BPP
356
.bpp16.intel:
364
.bpp16.intel:
357
	push	ebx ebp
365
	push	ebx ebp
358
	sub	ecx, 4
366
	sub	ecx, 4
359
	jb	.bpp16.tail
367
	jb	.bpp16.tail
360
align 16
368
align 16
361
.bpp16.intel.loop:
369
.bpp16.intel.loop:
362
repeat 2
370
repeat 2
363
	mov	ebx, [esi]
371
	mov	ebx, [esi]
364
	mov	al, [esi]
372
	mov	al, [esi]
365
	mov	ah, [esi+1]
373
	mov	ah, [esi+1]
366
	add	esi, 4
374
	add	esi, 4
367
	and	al, 0x1F
375
	and	al, 0x1F
368
	and	ah, 0x1F shl 3
376
	and	ah, 0x1F shl 3
369
	mov	ebp, ebx
377
	mov	ebp, ebx
370
	mov	dl, al
378
	mov	dl, al
371
	mov	dh, ah
379
	mov	dh, ah
372
	shr	al, 2
380
	shr	al, 2
373
	shr	ah, 5
381
	shr	ah, 5
374
	shl	dl, 3
382
	shl	dl, 3
375
	and	ebp, 0x3F shl 5
383
	and	ebp, 0x3F shl 5
376
	add	al, dl
384
	add	al, dl
377
	add	ah, dh
385
	add	ah, dh
378
	shr	ebp, 3
386
	shr	ebp, 3
379
	mov	[edi], al
387
	mov	[edi], al
380
	mov	[edi+2], ah
388
	mov	[edi+2], ah
381
	mov	eax, ebx
389
	mov	eax, ebx
382
	mov	ebx, ebp
390
	mov	ebx, ebp
383
	shr	eax, 16
391
	shr	eax, 16
384
	shr	ebx, 6
392
	shr	ebx, 6
385
	add	ebx, ebp
393
	add	ebx, ebp
386
	mov	ebp, eax
394
	mov	ebp, eax
387
	mov	[edi+1], bl
395
	mov	[edi+1], bl
388
	and	eax, (0x1F) or (0x1F shl 11)
396
	and	eax, (0x1F) or (0x1F shl 11)
389
	and	ebp, 0x3F shl 5
397
	and	ebp, 0x3F shl 5
390
	mov	edx, eax
398
	mov	edx, eax
391
	shr	al, 2
399
	shr	al, 2
392
	mov	ebx, ebp
400
	mov	ebx, ebp
393
	shr	ah, 5
401
	shr	ah, 5
394
	shl	dl, 3
402
	shl	dl, 3
395
	shr	ebx, 3
403
	shr	ebx, 3
396
	shr	ebp, 9
404
	shr	ebp, 9
397
	add	al, dl
405
	add	al, dl
398
	add	ah, dh
406
	add	ah, dh
399
	mov	[edi+3], al
407
	mov	[edi+3], al
400
	add	ebx, ebp
408
	add	ebx, ebp
401
	mov	[edi+5], ah
409
	mov	[edi+5], ah
402
	mov	[edi+4], bl
410
	mov	[edi+4], bl
403
	add	edi, 6
411
	add	edi, 6
404
end repeat
412
end repeat
405
	sub	ecx, 4
413
	sub	ecx, 4
406
	jnb	.bpp16.intel.loop
414
	jnb	.bpp16.intel.loop
407
.bpp16.tail:
415
.bpp16.tail:
408
	add	ecx, 4
416
	add	ecx, 4
409
	jz	.bpp16.done
417
	jz	.bpp16.done
410
@@:
418
@@:
411
	movzx	eax, word [esi]
419
	movzx	eax, word [esi]
412
	mov	ebx, eax
420
	mov	ebx, eax
413
	add	esi, 2
421
	add	esi, 2
414
	and	eax, (0x1F) or (0x1F shl 11)
422
	and	eax, (0x1F) or (0x1F shl 11)
415
	and	ebx, 0x3F shl 5
423
	and	ebx, 0x3F shl 5
416
	mov	edx, eax
424
	mov	edx, eax
417
	shr	al, 2
425
	shr	al, 2
418
	mov	ebp, ebx
426
	mov	ebp, ebx
419
	shr	ebx, 3
427
	shr	ebx, 3
420
	shr	ah, 5
428
	shr	ah, 5
421
	shl	dl, 3
429
	shl	dl, 3
422
	shr	ebp, 9
430
	shr	ebp, 9
423
	add	eax, edx
431
	add	eax, edx
424
	add	ebx, ebp
432
	add	ebx, ebp
425
	mov	[edi], al
433
	mov	[edi], al
426
	mov	[edi+1], bl
434
	mov	[edi+1], bl
427
	mov	[edi+2], ah
435
	mov	[edi+2], ah
428
	add	edi, 3
436
	add	edi, 3
429
	sub	ecx, 1
437
	sub	ecx, 1
430
	jnz	@b
438
	jnz	@b
431
.bpp16.done:
439
.bpp16.done:
432
	pop	ebp ebx
440
	pop	ebp ebx
433
	ret
441
	ret
434
 
442
 
435
.bpp16.amd:
443
.bpp16.amd:
436
	push	ebx ebp
444
	push	ebx ebp
437
	sub	ecx, 4
445
	sub	ecx, 4
438
	jb	.bpp16.tail
446
	jb	.bpp16.tail
439
align 16
447
align 16
440
.bpp16.amd.loop:
448
.bpp16.amd.loop:
441
repeat 4
449
repeat 4
442
if (% mod 2) = 1
450
if (% mod 2) = 1
443
	mov	eax, dword [esi]
451
	mov	eax, dword [esi]
444
	mov	ebx, dword [esi]
452
	mov	ebx, dword [esi]
445
else
453
else
446
	movzx	eax, word [esi]
454
	movzx	eax, word [esi]
447
	mov	ebx, eax
455
	mov	ebx, eax
448
end if
456
end if
449
	add	esi, 2
457
	add	esi, 2
450
	and	eax, (0x1F) or (0x1F shl 11)
458
	and	eax, (0x1F) or (0x1F shl 11)
451
	and	ebx, 0x3F shl 5
459
	and	ebx, 0x3F shl 5
452
	mov	edx, eax
460
	mov	edx, eax
453
	shr	al, 2
461
	shr	al, 2
454
	mov	ebp, ebx
462
	mov	ebp, ebx
455
	shr	ebx, 3
463
	shr	ebx, 3
456
	shr	ah, 5
464
	shr	ah, 5
457
	shl	dl, 3
465
	shl	dl, 3
458
	shr	ebp, 9
466
	shr	ebp, 9
459
	add	eax, edx
467
	add	eax, edx
460
	add	ebx, ebp
468
	add	ebx, ebp
461
	mov	[edi], al
469
	mov	[edi], al
462
	mov	[edi+1], bl
470
	mov	[edi+1], bl
463
	mov	[edi+2], ah
471
	mov	[edi+2], ah
464
	add	edi, 3
472
	add	edi, 3
465
end repeat
473
end repeat
466
	sub	ecx, 4
474
	sub	ecx, 4
467
	jnb	.bpp16.amd.loop
475
	jnb	.bpp16.amd.loop
468
	jmp	.bpp16.tail
476
	jmp	.bpp16.tail
469
 
477
 
470
align 16
478
align 16
471
.bpp24:
479
.bpp24:
472
; 24 BPP -> 24 BPP
480
; 24 BPP -> 24 BPP
473
	lea	ecx, [ecx*3 + 3]
481
	lea	ecx, [ecx*3 + 3]
474
	mov	esi, [esi + Image.Data]
482
	mov	esi, [esi + Image.Data]
475
	shr	ecx, 2
483
	shr	ecx, 2
476
	rep	movsd
484
	rep	movsd
477
	ret
485
	ret
478
 
486
 
479
align 16
487
align 16
480
.bpp32:
488
.bpp32:
481
; 32 BPP -> 24 BPP
489
; 32 BPP -> 24 BPP
482
	mov	esi, [esi + Image.Data]
490
	mov	esi, [esi + Image.Data]
483
 
491
 
484
    @@:
492
    @@:
485
	mov	eax, [esi]
493
	mov	eax, [esi]
486
	mov	[edi], ax
494
	mov	[edi], ax
487
	shr	eax, 16
495
	shr	eax, 16
488
	mov	[edi+2], al
496
	mov	[edi+2], al
489
	add	esi, 4
497
	add	esi, 4
490
	add	edi, 3
498
	add	edi, 3
491
	sub	ecx, 1
499
	sub	ecx, 1
492
	jnz	@b
500
	jnz	@b
493
 
501
 
494
    @@:
502
    @@:
495
	ret
503
	ret
496
 
504
 
497
endp
505
endp
498
 
506
 
499
;;================================================================================================;;
507
;;================================================================================================;;
500
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
508
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
501
;;------------------------------------------------------------------------------------------------;;
509
;;------------------------------------------------------------------------------------------------;;
502
;? --- TBD ---                                                                                    ;;
510
;? --- TBD ---                                                                                    ;;
503
;;------------------------------------------------------------------------------------------------;;
511
;;------------------------------------------------------------------------------------------------;;
504
;> --- TBD ---                                                                                    ;;
512
;> --- TBD ---                                                                                    ;;
505
;;------------------------------------------------------------------------------------------------;;
513
;;------------------------------------------------------------------------------------------------;;
506
;< eax = 0 / pointer to image                                                                     ;;
514
;< eax = 0 / pointer to image                                                                     ;;
507
;;================================================================================================;;
515
;;================================================================================================;;
508
	push	ebx
516
	push	ebx
509
	mov	ebx, img._.formats_table
517
	mov	ebx, img._.formats_table
510
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
518
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
511
	or	eax, eax
519
	or	eax, eax
512
	jnz	@f
520
	jnz	@f
513
	add	ebx, sizeof.FormatsTableEntry
521
	add	ebx, sizeof.FormatsTableEntry
514
	cmp	dword[ebx], eax ;0
522
	cmp	dword[ebx], eax ;0
515
	jnz	@b
523
	jnz	@b
516
	pop	ebx
524
	pop	ebx
517
	ret
525
	ret
518
    @@: mov	eax, [ebx + FormatsTableEntry.Decode]
526
    @@: mov	eax, [ebx + FormatsTableEntry.Decode]
519
	pop	ebx
527
	pop	ebx
520
	leave
528
	leave
521
	jmp	eax
529
	jmp	eax
522
endp
530
endp
523
 
531
 
524
;;================================================================================================;;
532
;;================================================================================================;;
525
proc img.encode _img, _p_length, _options ;///////////////////////////////////////////////////////;;
533
proc img.encode _img, _p_length, _options ;///////////////////////////////////////////////////////;;
526
;;------------------------------------------------------------------------------------------------;;
534
;;------------------------------------------------------------------------------------------------;;
527
;? --- TBD ---                                                                                    ;;
535
;? --- TBD ---                                                                                    ;;
528
;;------------------------------------------------------------------------------------------------;;
536
;;------------------------------------------------------------------------------------------------;;
529
;> --- TBD ---                                                                                    ;;
537
;> --- TBD ---                                                                                    ;;
530
;;------------------------------------------------------------------------------------------------;;
538
;;------------------------------------------------------------------------------------------------;;
531
;< eax = 0 / pointer to encoded data                                                              ;;
539
;< eax = 0 / pointer to encoded data                                                              ;;
532
;< [_p_length] = data length                                                                      ;;
540
;< [_p_length] = data length                                                                      ;;
533
;;================================================================================================;;
541
;;================================================================================================;;
534
	xor	eax, eax
542
	xor	eax, eax
535
	ret
543
	ret
536
endp
544
endp
537
 
545
 
538
;;================================================================================================;;
546
;;================================================================================================;;
539
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
547
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
540
;;------------------------------------------------------------------------------------------------;;
548
;;------------------------------------------------------------------------------------------------;;
541
;? --- TBD ---                                                                                    ;;
549
;? --- TBD ---                                                                                    ;;
542
;;------------------------------------------------------------------------------------------------;;
550
;;------------------------------------------------------------------------------------------------;;
543
;> --- TBD ---                                                                                    ;;
551
;> --- TBD ---                                                                                    ;;
544
;;------------------------------------------------------------------------------------------------;;
552
;;------------------------------------------------------------------------------------------------;;
545
;< eax = 0 / pointer to image                                                                     ;;
553
;< eax = 0 / pointer to image                                                                     ;;
546
;;================================================================================================;;
554
;;================================================================================================;;
547
	push	ecx
555
	push	ecx
548
 
556
 
549
	stdcall img._.new
557
	stdcall img._.new
550
	or	eax, eax
558
	or	eax, eax
551
	jz	.error
559
	jz	.error
552
 
560
 
553
	mov	ecx, [_type]
561
	mov	ecx, [_type]
554
	mov	[eax + Image.Type], ecx
562
	mov	[eax + Image.Type], ecx
555
 
563
 
556
	push	eax
564
	push	eax
557
 
565
 
558
	stdcall img._.resize_data, eax, [_width], [_height]
566
	stdcall img._.resize_data, eax, [_width], [_height]
559
	or	eax, eax
567
	or	eax, eax
560
	jz	.error.2
568
	jz	.error.2
561
 
569
 
562
	pop	eax
570
	pop	eax
563
	jmp	.ret
571
	jmp	.ret
564
 
572
 
565
  .error.2:
573
  .error.2:
566
;       pop     eax
574
;       pop     eax
567
	stdcall img._.delete; eax
575
	stdcall img._.delete; eax
568
	xor	eax, eax
576
	xor	eax, eax
569
 
577
 
570
  .error:
578
  .error:
571
  .ret:
579
  .ret:
572
	pop	ecx
580
	pop	ecx
573
	ret
581
	ret
574
endp
582
endp
575
 
583
 
576
;;================================================================================================;;
584
;;================================================================================================;;
577
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
585
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
578
;;------------------------------------------------------------------------------------------------;;
586
;;------------------------------------------------------------------------------------------------;;
579
;? --- TBD ---                                                                                    ;;
587
;? --- TBD ---                                                                                    ;;
580
;;------------------------------------------------------------------------------------------------;;
588
;;------------------------------------------------------------------------------------------------;;
581
;> --- TBD ---                                                                                    ;;
589
;> --- TBD ---                                                                                    ;;
582
;;------------------------------------------------------------------------------------------------;;
590
;;------------------------------------------------------------------------------------------------;;
583
;< eax = false / true                                                                             ;;
591
;< eax = false / true                                                                             ;;
584
;;================================================================================================;;
592
;;================================================================================================;;
585
	mov	eax, [_img]
593
	mov	eax, [_img]
586
	mov	edx, [eax + Image.Previous]
594
	mov	edx, [eax + Image.Previous]
587
	test	edx, edx
595
	test	edx, edx
588
	jz	@f
596
	jz	@f
589
	push	[eax + Image.Next]
597
	push	[eax + Image.Next]
590
	pop	[edx + Image.Next]
598
	pop	[edx + Image.Next]
591
@@:
599
@@:
592
	mov	edx, [eax + Image.Next]
600
	mov	edx, [eax + Image.Next]
593
	test	edx, edx
601
	test	edx, edx
594
	jz	@f
602
	jz	@f
595
	push	[eax + Image.Previous]
603
	push	[eax + Image.Previous]
596
	pop	[edx + Image.Previous]
604
	pop	[edx + Image.Previous]
597
@@:
605
@@:
598
	stdcall img._.delete, eax
606
	stdcall img._.delete, eax
599
	ret
607
	ret
600
endp
608
endp
601
 
609
 
602
;;================================================================================================;;
610
;;================================================================================================;;
603
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
611
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
604
;;------------------------------------------------------------------------------------------------;;
612
;;------------------------------------------------------------------------------------------------;;
605
;? --- TBD ---                                                                                    ;;
613
;? --- TBD ---                                                                                    ;;
606
;;------------------------------------------------------------------------------------------------;;
614
;;------------------------------------------------------------------------------------------------;;
607
;> --- TBD ---                                                                                    ;;
615
;> --- TBD ---                                                                                    ;;
608
;;------------------------------------------------------------------------------------------------;;
616
;;------------------------------------------------------------------------------------------------;;
609
;< eax = false / true                                                                             ;;
617
;< eax = false / true                                                                             ;;
610
;;================================================================================================;;
618
;;================================================================================================;;
611
	push	1
619
	push	1
612
	mov	eax, [_img]
620
	mov	eax, [_img]
613
	mov	eax, [eax + Image.Previous]
621
	mov	eax, [eax + Image.Previous]
614
.destroy_prev_loop:
622
.destroy_prev_loop:
615
	test	eax, eax
623
	test	eax, eax
616
	jz	.destroy_prev_done
624
	jz	.destroy_prev_done
617
	pushd	[eax + Image.Previous]
625
	pushd	[eax + Image.Previous]
618
	stdcall	img._.delete, eax
626
	stdcall	img._.delete, eax
619
	test	eax, eax
627
	test	eax, eax
620
	jnz	@f
628
	jnz	@f
621
	mov	byte [esp+4], 0
629
	mov	byte [esp+4], 0
622
@@:
630
@@:
623
	pop	eax
631
	pop	eax
624
	jmp	.destroy_prev_loop
632
	jmp	.destroy_prev_loop
625
.destroy_prev_done:
633
.destroy_prev_done:
626
	mov	eax, [_img]
634
	mov	eax, [_img]
627
.destroy_next_loop:
635
.destroy_next_loop:
628
	pushd	[eax + Image.Next]
636
	pushd	[eax + Image.Next]
629
	stdcall	img._.delete, eax
637
	stdcall	img._.delete, eax
630
	test	eax, eax
638
	test	eax, eax
631
	jnz	@f
639
	jnz	@f
632
	mov	byte [esp+4], 0
640
	mov	byte [esp+4], 0
633
@@:
641
@@:
634
	pop	eax
642
	pop	eax
635
	test	eax, eax
643
	test	eax, eax
636
	jnz	.destroy_next_loop
644
	jnz	.destroy_next_loop
637
	pop	eax
645
	pop	eax
638
	ret
646
	ret
639
endp
647
endp
640
 
648
 
641
;;================================================================================================;;
649
;;================================================================================================;;
642
proc img.count _img ;/////////////////////////////////////////////////////////////////////////////;;
650
proc img.count _img ;/////////////////////////////////////////////////////////////////////////////;;
643
;;------------------------------------------------------------------------------------------------;;
651
;;------------------------------------------------------------------------------------------------;;
644
;? Get number of images in the list (e.g. in animated GIF file)                                   ;;
652
;? Get number of images in the list (e.g. in animated GIF file)                                   ;;
645
;;------------------------------------------------------------------------------------------------;;
653
;;------------------------------------------------------------------------------------------------;;
646
;> _img = pointer to image                                                                        ;;
654
;> _img = pointer to image                                                                        ;;
647
;;------------------------------------------------------------------------------------------------;;
655
;;------------------------------------------------------------------------------------------------;;
648
;< eax = -1 (fail) / >0 (ok)                                                                      ;;
656
;< eax = -1 (fail) / >0 (ok)                                                                      ;;
649
;;================================================================================================;;
657
;;================================================================================================;;
650
	push	ecx edx
658
	push	ecx edx
651
	mov	edx, [_img]
659
	mov	edx, [_img]
652
	stdcall img._.validate, edx
660
	stdcall img._.validate, edx
653
	or	eax, eax
661
	or	eax, eax
654
	jnz	.error
662
	jnz	.error
655
 
663
 
656
    @@: mov	eax, [edx + Image.Previous]
664
    @@: mov	eax, [edx + Image.Previous]
657
	or	eax, eax
665
	or	eax, eax
658
	jz	@f
666
	jz	@f
659
	mov	edx, eax
667
	mov	edx, eax
660
	jmp	@b
668
	jmp	@b
661
 
669
 
662
    @@: xor	ecx, ecx
670
    @@: xor	ecx, ecx
663
    @@: inc	ecx
671
    @@: inc	ecx
664
	mov	eax, [edx + Image.Next]
672
	mov	eax, [edx + Image.Next]
665
	or	eax, eax
673
	or	eax, eax
666
	jz	.exit
674
	jz	.exit
667
	mov	edx, eax
675
	mov	edx, eax
668
	jmp	@b
676
	jmp	@b
669
 
677
 
670
  .exit:
678
  .exit:
671
	mov	eax, ecx
679
	mov	eax, ecx
672
	pop	edx ecx
680
	pop	edx ecx
673
	ret
681
	ret
674
 
682
 
675
  .error:
683
  .error:
676
	or	eax, -1
684
	or	eax, -1
677
	pop	edx ecx
685
	pop	edx ecx
678
	ret
686
	ret
679
endp
687
endp
680
 
688
 
681
;;//// image processing //////////////////////////////////////////////////////////////////////////;;
689
;;//// image processing //////////////////////////////////////////////////////////////////////////;;
682
 
690
 
683
;;================================================================================================;;
691
;;================================================================================================;;
684
proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////////////////////////;;
692
proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////////////////////////;;
685
;;------------------------------------------------------------------------------------------------;;
693
;;------------------------------------------------------------------------------------------------;;
686
;? --- TBD ---                                                                                    ;;
694
;? --- TBD ---                                                                                    ;;
687
;;------------------------------------------------------------------------------------------------;;
695
;;------------------------------------------------------------------------------------------------;;
688
;> --- TBD ---                                                                                    ;;
696
;> --- TBD ---                                                                                    ;;
689
;;------------------------------------------------------------------------------------------------;;
697
;;------------------------------------------------------------------------------------------------;;
690
;< eax = 0 / pointer to bits                                                                      ;;
698
;< eax = 0 / pointer to bits                                                                      ;;
691
;;================================================================================================;;
699
;;================================================================================================;;
692
	xor	eax, eax
700
	xor	eax, eax
693
	ret
701
	ret
694
endp
702
endp
695
 
703
 
696
;;================================================================================================;;
704
;;================================================================================================;;
697
proc img.unlock_bits _img, _lock ;////////////////////////////////////////////////////////////////;;
705
proc img.unlock_bits _img, _lock ;////////////////////////////////////////////////////////////////;;
698
;;------------------------------------------------------------------------------------------------;;
706
;;------------------------------------------------------------------------------------------------;;
699
;? --- TBD ---                                                                                    ;;
707
;? --- TBD ---                                                                                    ;;
700
;;------------------------------------------------------------------------------------------------;;
708
;;------------------------------------------------------------------------------------------------;;
701
;> --- TBD ---                                                                                    ;;
709
;> --- TBD ---                                                                                    ;;
702
;;------------------------------------------------------------------------------------------------;;
710
;;------------------------------------------------------------------------------------------------;;
703
;< eax = false / true                                                                             ;;
711
;< eax = false / true                                                                             ;;
704
;;================================================================================================;;
712
;;================================================================================================;;
705
	xor	eax, eax
713
	xor	eax, eax
706
	ret
714
	ret
707
endp
715
endp
708
 
716
 
709
;;================================================================================================;;
717
;;================================================================================================;;
710
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////////////////////////;;
718
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////////////////////////;;
711
;;------------------------------------------------------------------------------------------------;;
719
;;------------------------------------------------------------------------------------------------;;
712
;? Flip image layer                                                                               ;;
720
;? Flip image layer                                                                               ;;
713
;;------------------------------------------------------------------------------------------------;;
721
;;------------------------------------------------------------------------------------------------;;
714
;> _img = pointer to image                                                                        ;;
722
;> _img = pointer to image                                                                        ;;
715
;> _flip_kind = one of FLIP_* constants                                                           ;;
723
;> _flip_kind = one of FLIP_* constants                                                           ;;
716
;;------------------------------------------------------------------------------------------------;;
724
;;------------------------------------------------------------------------------------------------;;
717
;< eax = false / true                                                                             ;;
725
;< eax = false / true                                                                             ;;
718
;;================================================================================================;;
726
;;================================================================================================;;
719
locals
727
locals
720
  scanline_len dd ?
728
  scanline_len dd ?
721
endl
729
endl
722
 
730
 
723
	push	ebx esi edi
731
	push	ebx esi edi
724
	mov	ebx, [_img]
732
	mov	ebx, [_img]
725
	stdcall img._.validate, ebx
733
	stdcall img._.validate, ebx
726
	or	eax, eax
734
	or	eax, eax
727
	jnz	.error
735
	jnz	.error
728
 
736
 
729
	mov	ecx, [ebx + Image.Height]
737
	mov	ecx, [ebx + Image.Height]
730
	mov	eax, [ebx + Image.Width]
738
	mov	eax, [ebx + Image.Width]
731
	call	img._.get_scanline_len
739
	call	img._.get_scanline_len
732
	mov	[scanline_len], eax
740
	mov	[scanline_len], eax
733
 
741
 
734
	test	[_flip_kind], FLIP_VERTICAL
742
	test	[_flip_kind], FLIP_VERTICAL
735
	jz	.dont_flip_vert
743
	jz	.dont_flip_vert
736
 
744
 
737
	imul	eax, ecx
745
	imul	eax, ecx
738
	sub	eax, [scanline_len]
746
	sub	eax, [scanline_len]
739
	shr	ecx, 1
747
	shr	ecx, 1
740
	mov	esi, [ebx + Image.Data]
748
	mov	esi, [ebx + Image.Data]
741
	lea	edi, [esi + eax]
749
	lea	edi, [esi + eax]
742
	
750
	
743
  .next_line_vert:
751
  .next_line_vert:
744
	push	ecx
752
	push	ecx
745
 
753
 
746
	mov	ecx, [scanline_len]
754
	mov	ecx, [scanline_len]
747
	push	ecx
755
	push	ecx
748
	shr	ecx, 2
756
	shr	ecx, 2
749
    @@: mov	eax, [esi]
757
    @@: mov	eax, [esi]
750
	xchg	eax, [edi]
758
	xchg	eax, [edi]
751
	mov	[esi], eax
759
	mov	[esi], eax
752
	add	esi, 4
760
	add	esi, 4
753
	add	edi, 4
761
	add	edi, 4
754
	sub	ecx, 1
762
	sub	ecx, 1
755
	jnz	@b
763
	jnz	@b
756
	pop	ecx
764
	pop	ecx
757
	and	ecx, 3
765
	and	ecx, 3
758
	jz	.cont_line_vert
766
	jz	.cont_line_vert
759
    @@:
767
    @@:
760
	mov	al, [esi]
768
	mov	al, [esi]
761
	xchg	al, [edi]
769
	xchg	al, [edi]
762
	mov	[esi], al
770
	mov	[esi], al
763
	add	esi, 1
771
	add	esi, 1
764
	add	edi, 1
772
	add	edi, 1
765
	dec	ecx
773
	dec	ecx
766
	jnz	@b
774
	jnz	@b
767
    .cont_line_vert:
775
    .cont_line_vert:
768
 
776
 
769
	pop	ecx
777
	pop	ecx
770
	mov	eax, [scanline_len]
778
	mov	eax, [scanline_len]
771
	shl	eax, 1
779
	shl	eax, 1
772
	sub	edi, eax
780
	sub	edi, eax
773
	dec	ecx
781
	dec	ecx
774
	jnz	.next_line_vert
782
	jnz	.next_line_vert
775
 
783
 
776
  .dont_flip_vert:
784
  .dont_flip_vert:
777
 
785
 
778
	test	[_flip_kind], FLIP_HORIZONTAL
786
	test	[_flip_kind], FLIP_HORIZONTAL
779
	jz	.exit
787
	jz	.exit
780
 
788
 
781
	mov	ecx, [ebx + Image.Height]
789
	mov	ecx, [ebx + Image.Height]
782
	mov	eax, [ebx + Image.Type]
790
	mov	eax, [ebx + Image.Type]
783
	mov	esi, [ebx + Image.Data]
791
	mov	esi, [ebx + Image.Data]
784
	mov	edi, [scanline_len]
792
	mov	edi, [scanline_len]
785
	add	edi, esi
793
	add	edi, esi
786
	jmp	dword [.handlers_horz + (eax-1)*4]
794
	jmp	dword [.handlers_horz + (eax-1)*4]
787
 
795
 
788
.bpp32_horz:
796
.bpp32_horz:
789
	sub	edi, 4
797
	sub	edi, 4
790
 
798
 
791
  .next_line_horz:
799
  .next_line_horz:
792
	push	ecx esi edi
800
	push	ecx esi edi
793
 
801
 
794
	mov	ecx, [scanline_len]
802
	mov	ecx, [scanline_len]
795
	shr	ecx, 3
803
	shr	ecx, 3
796
    @@: mov	eax, [esi]
804
    @@: mov	eax, [esi]
797
	xchg	eax, [edi]
805
	xchg	eax, [edi]
798
	mov	[esi], eax
806
	mov	[esi], eax
799
	add	esi, 4
807
	add	esi, 4
800
	add	edi, -4
808
	add	edi, -4
801
	sub	ecx, 1
809
	sub	ecx, 1
802
	jnz	@b
810
	jnz	@b
803
 
811
 
804
	pop	edi esi ecx
812
	pop	edi esi ecx
805
	add	esi, [scanline_len]
813
	add	esi, [scanline_len]
806
	add	edi, [scanline_len]
814
	add	edi, [scanline_len]
807
	dec	ecx
815
	dec	ecx
808
	jnz	.next_line_horz
816
	jnz	.next_line_horz
809
	jmp	.exit
817
	jmp	.exit
810
 
818
 
811
.bpp1x_horz:
819
.bpp1x_horz:
812
	sub	edi, 2
820
	sub	edi, 2
813
  .next_line_horz1x:
821
  .next_line_horz1x:
814
	push	ecx esi edi
822
	push	ecx esi edi
815
 
823
 
816
	mov	ecx, [ebx + Image.Width]
824
	mov	ecx, [ebx + Image.Width]
817
    @@: mov	ax, [esi]
825
    @@: mov	ax, [esi]
818
	mov	dx, [edi]
826
	mov	dx, [edi]
819
	mov	[edi], ax
827
	mov	[edi], ax
820
	mov	[esi], dx
828
	mov	[esi], dx
821
	add	esi, 2
829
	add	esi, 2
822
	sub	edi, 2
830
	sub	edi, 2
823
	sub	ecx, 2
831
	sub	ecx, 2
824
	ja	@b
832
	ja	@b
825
 
833
 
826
	pop	edi esi ecx
834
	pop	edi esi ecx
827
	add	esi, [scanline_len]
835
	add	esi, [scanline_len]
828
	add	edi, [scanline_len]
836
	add	edi, [scanline_len]
829
	dec	ecx
837
	dec	ecx
830
	jnz	.next_line_horz1x
838
	jnz	.next_line_horz1x
831
	jmp	.exit
839
	jmp	.exit
832
 
840
 
833
.bpp8_horz:
841
.bpp8_horz:
834
	dec	edi
842
	dec	edi
835
  .next_line_horz8:
843
  .next_line_horz8:
836
	push	ecx esi edi
844
	push	ecx esi edi
837
 
845
 
838
	mov	ecx, [scanline_len]
846
	mov	ecx, [scanline_len]
839
	shr	ecx, 1
847
	shr	ecx, 1
840
    @@: mov	al, [esi]
848
    @@: mov	al, [esi]
841
	mov	dl, [edi]
849
	mov	dl, [edi]
842
	mov	[edi], al
850
	mov	[edi], al
843
	mov	[esi], dl
851
	mov	[esi], dl
844
	add	esi, 1
852
	add	esi, 1
845
	sub	edi, 1
853
	sub	edi, 1
846
	sub	ecx, 1
854
	sub	ecx, 1
847
	jnz	@b
855
	jnz	@b
848
 
856
 
849
	pop	edi esi ecx
857
	pop	edi esi ecx
850
	add	esi, [scanline_len]
858
	add	esi, [scanline_len]
851
	add	edi, [scanline_len]
859
	add	edi, [scanline_len]
852
	dec	ecx
860
	dec	ecx
853
	jnz	.next_line_horz8
861
	jnz	.next_line_horz8
854
	jmp	.exit
862
	jmp	.exit
855
 
863
 
856
.bpp24_horz:
864
.bpp24_horz:
857
	sub	edi, 3
865
	sub	edi, 3
858
  .next_line_horz24:
866
  .next_line_horz24:
859
	push	ecx esi edi
867
	push	ecx esi edi
860
 
868
 
861
	mov	ecx, [ebx + Image.Width]
869
	mov	ecx, [ebx + Image.Width]
862
    @@:
870
    @@:
863
	mov	al, [esi]
871
	mov	al, [esi]
864
	mov	dl, [edi]
872
	mov	dl, [edi]
865
	mov	[edi], al
873
	mov	[edi], al
866
	mov	[esi], dl
874
	mov	[esi], dl
867
	mov	al, [esi+1]
875
	mov	al, [esi+1]
868
	mov	dl, [edi+1]
876
	mov	dl, [edi+1]
869
	mov	[edi+1], al
877
	mov	[edi+1], al
870
	mov	[esi+1], dl
878
	mov	[esi+1], dl
871
	mov	al, [esi+2]
879
	mov	al, [esi+2]
872
	mov	dl, [edi+2]
880
	mov	dl, [edi+2]
873
	mov	[edi+2], al
881
	mov	[edi+2], al
874
	mov	[esi+2], dl
882
	mov	[esi+2], dl
875
	add	esi, 3
883
	add	esi, 3
876
	sub	edi, 3
884
	sub	edi, 3
877
	sub	ecx, 2
885
	sub	ecx, 2
878
	ja	@b
886
	ja	@b
879
 
887
 
880
	pop	edi esi ecx
888
	pop	edi esi ecx
881
	add	esi, [scanline_len]
889
	add	esi, [scanline_len]
882
	add	edi, [scanline_len]
890
	add	edi, [scanline_len]
883
	dec	ecx
891
	dec	ecx
884
	jnz	.next_line_horz24
892
	jnz	.next_line_horz24
885
 
893
 
886
  .exit:
894
  .exit:
887
	xor	eax, eax
895
	xor	eax, eax
888
	inc	eax
896
	inc	eax
889
	pop	edi esi ebx
897
	pop	edi esi ebx
890
	ret
898
	ret
891
 
899
 
892
  .error:
900
  .error:
893
	xor	eax, eax
901
	xor	eax, eax
894
	pop	edi esi ebx
902
	pop	edi esi ebx
895
	ret
903
	ret
896
endp
904
endp
897
 
905
 
898
;;================================================================================================;;
906
;;================================================================================================;;
899
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
907
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
900
;;------------------------------------------------------------------------------------------------;;
908
;;------------------------------------------------------------------------------------------------;;
901
;? Flip all layers of image                                                                       ;;
909
;? Flip all layers of image                                                                       ;;
902
;;------------------------------------------------------------------------------------------------;;
910
;;------------------------------------------------------------------------------------------------;;
903
;> _img = pointer to image                                                                        ;;
911
;> _img = pointer to image                                                                        ;;
904
;> _flip_kind = one of FLIP_* constants                                                           ;;
912
;> _flip_kind = one of FLIP_* constants                                                           ;;
905
;;------------------------------------------------------------------------------------------------;;
913
;;------------------------------------------------------------------------------------------------;;
906
;< eax = false / true                                                                             ;;
914
;< eax = false / true                                                                             ;;
907
;;================================================================================================;;
915
;;================================================================================================;;
908
	push	1
916
	push	1
909
	mov	ebx, [_img]
917
	mov	ebx, [_img]
910
@@:
918
@@:
911
	mov	eax, [ebx + Image.Previous]
919
	mov	eax, [ebx + Image.Previous]
912
	test	eax, eax
920
	test	eax, eax
913
	jz	.loop
921
	jz	.loop
914
	mov	ebx, eax
922
	mov	ebx, eax
915
	jmp	@b
923
	jmp	@b
916
.loop:
924
.loop:
917
	stdcall	img.flip.layer, ebx, [_flip_kind]
925
	stdcall	img.flip.layer, ebx, [_flip_kind]
918
	test	eax, eax
926
	test	eax, eax
919
	jnz	@f
927
	jnz	@f
920
	mov	byte [esp], 0
928
	mov	byte [esp], 0
921
@@:
929
@@:
922
	mov	ebx, [ebx + Image.Next]
930
	mov	ebx, [ebx + Image.Next]
923
	test	ebx, ebx
931
	test	ebx, ebx
924
	jnz	.loop
932
	jnz	.loop
925
	pop	eax
933
	pop	eax
926
	ret
934
	ret
927
endp
935
endp
928
 
936
 
929
;;================================================================================================;;
937
;;================================================================================================;;
930
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////////////////////////;;
938
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////////////////////////;;
931
;;------------------------------------------------------------------------------------------------;;
939
;;------------------------------------------------------------------------------------------------;;
932
;? Rotate image layer                                                                             ;;
940
;? Rotate image layer                                                                             ;;
933
;;------------------------------------------------------------------------------------------------;;
941
;;------------------------------------------------------------------------------------------------;;
934
;> _img = pointer to image                                                                        ;;
942
;> _img = pointer to image                                                                        ;;
935
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
943
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
936
;;------------------------------------------------------------------------------------------------;;
944
;;------------------------------------------------------------------------------------------------;;
937
;< eax = false / true                                                                             ;;
945
;< eax = false / true                                                                             ;;
938
;;================================================================================================;;
946
;;================================================================================================;;
939
locals
947
locals
940
  scanline_len_old    dd ?
948
  scanline_len_old    dd ?
941
  scanline_len_new    dd ?
949
  scanline_len_new    dd ?
942
  scanline_pixels_new dd ?
950
  scanline_pixels_new dd ?
943
  line_buffer	      dd ?
951
  line_buffer	      dd ?
944
  pixels_ptr	      dd ?
952
  pixels_ptr	      dd ?
945
endl
953
endl
946
 
954
 
947
	mov	[line_buffer], 0
955
	mov	[line_buffer], 0
948
 
956
 
949
	push	ebx esi edi
957
	push	ebx esi edi
950
	mov	ebx, [_img]
958
	mov	ebx, [_img]
951
	stdcall img._.validate, ebx
959
	stdcall img._.validate, ebx
952
	or	eax, eax
960
	or	eax, eax
953
	jnz	.error
961
	jnz	.error
954
 
962
 
955
	cmp	[_rotate_kind], ROTATE_90_CCW
963
	cmp	[_rotate_kind], ROTATE_90_CCW
956
	je	.rotate_ccw_low
964
	je	.rotate_ccw_low
957
	cmp	[_rotate_kind], ROTATE_90_CW
965
	cmp	[_rotate_kind], ROTATE_90_CW
958
	je	.rotate_cw_low
966
	je	.rotate_cw_low
959
	cmp	[_rotate_kind], ROTATE_180
967
	cmp	[_rotate_kind], ROTATE_180
960
	je	.flip
968
	je	.flip
961
	jmp	.exit
969
	jmp	.exit
962
 
970
 
963
  .rotate_ccw_low:
971
  .rotate_ccw_low:
964
	mov	eax, [ebx + Image.Height]
972
	mov	eax, [ebx + Image.Height]
965
	mov	[scanline_pixels_new], eax
973
	mov	[scanline_pixels_new], eax
966
	call	img._.get_scanline_len
974
	call	img._.get_scanline_len
967
	mov	[scanline_len_new], eax
975
	mov	[scanline_len_new], eax
968
 
976
 
969
	invoke	mem.alloc, eax
977
	invoke	mem.alloc, eax
970
	or	eax, eax
978
	or	eax, eax
971
	jz	.error
979
	jz	.error
972
	mov	[line_buffer], eax
980
	mov	[line_buffer], eax
973
 
981
 
974
	mov	eax, [ebx + Image.Width]
982
	mov	eax, [ebx + Image.Width]
975
	mov	ecx, eax
983
	mov	ecx, eax
976
	call	img._.get_scanline_len
984
	call	img._.get_scanline_len
977
	mov	[scanline_len_old], eax
985
	mov	[scanline_len_old], eax
978
 
986
 
979
	mov	eax, [scanline_len_new]
987
	mov	eax, [scanline_len_new]
980
	imul	eax, ecx
988
	imul	eax, ecx
981
	add	eax, [ebx + Image.Data]
989
	add	eax, [ebx + Image.Data]
982
	mov	[pixels_ptr], eax
990
	mov	[pixels_ptr], eax
983
 
991
 
984
	cmp	[ebx + Image.Type], Image.bpp8
992
	cmp	[ebx + Image.Type], Image.bpp8
985
	jz	.rotate_ccw8
993
	jz	.rotate_ccw8
986
	cmp	[ebx + Image.Type], Image.bpp24
994
	cmp	[ebx + Image.Type], Image.bpp24
987
	jz	.rotate_ccw24
995
	jz	.rotate_ccw24
988
	cmp	[ebx + Image.Type], Image.bpp32
996
	cmp	[ebx + Image.Type], Image.bpp32
989
	jz	.rotate_ccw32
997
	jz	.rotate_ccw32
990
 
998
 
991
  .next_column_ccw_low1x:
999
  .next_column_ccw_low1x:
992
	dec	ecx
1000
	dec	ecx
993
	js	.exchange_dims
1001
	js	.exchange_dims
994
	push	ecx
1002
	push	ecx
995
 
1003
 
996
	mov	edx, [scanline_len_old]
1004
	mov	edx, [scanline_len_old]
997
	add	[scanline_len_old], -2
1005
	add	[scanline_len_old], -2
998
 
1006
 
999
	mov	ecx, [scanline_pixels_new]
1007
	mov	ecx, [scanline_pixels_new]
1000
	mov	esi, [ebx + Image.Data]
1008
	mov	esi, [ebx + Image.Data]
1001
	mov	edi, [line_buffer]
1009
	mov	edi, [line_buffer]
1002
    @@: mov	ax, [esi]
1010
    @@: mov	ax, [esi]
1003
	mov	[edi], ax
1011
	mov	[edi], ax
1004
	add	esi, edx
1012
	add	esi, edx
1005
	add	edi, 2
1013
	add	edi, 2
1006
	sub	ecx, 1
1014
	sub	ecx, 1
1007
	jnz	@b
1015
	jnz	@b
1008
 
1016
 
1009
	mov	eax, [scanline_pixels_new]
1017
	mov	eax, [scanline_pixels_new]
1010
	mov	edi, [ebx + Image.Data]
1018
	mov	edi, [ebx + Image.Data]
1011
	lea	esi, [edi + 2]
1019
	lea	esi, [edi + 2]
1012
	mov	edx, [scanline_len_old]
1020
	mov	edx, [scanline_len_old]
1013
    @@: mov	ecx, edx
1021
    @@: mov	ecx, edx
1014
	shr	ecx, 2
1022
	shr	ecx, 2
1015
	rep	movsd
1023
	rep	movsd
1016
	mov	ecx, edx
1024
	mov	ecx, edx
1017
	and	ecx, 3
1025
	and	ecx, 3
1018
	rep	movsb
1026
	rep	movsb
1019
	add	esi, 1
1027
	add	esi, 1
1020
	sub	eax, 1
1028
	sub	eax, 1
1021
	jnz	@b
1029
	jnz	@b
1022
 
1030
 
1023
	mov	eax, [scanline_len_new]
1031
	mov	eax, [scanline_len_new]
1024
	sub	[pixels_ptr], eax
1032
	sub	[pixels_ptr], eax
1025
	mov	ecx, [scanline_pixels_new]
1033
	mov	ecx, [scanline_pixels_new]
1026
	mov	esi, [line_buffer]
1034
	mov	esi, [line_buffer]
1027
	mov	edi, [pixels_ptr]
1035
	mov	edi, [pixels_ptr]
1028
	mov	edx, ecx
1036
	mov	edx, ecx
1029
	shr	ecx, 2
1037
	shr	ecx, 2
1030
	rep	movsd
1038
	rep	movsd
1031
	mov	ecx, edx
1039
	mov	ecx, edx
1032
	and	ecx, 3
1040
	and	ecx, 3
1033
	rep	movsb
1041
	rep	movsb
1034
 
1042
 
1035
	pop	ecx
1043
	pop	ecx
1036
	jmp	.next_column_ccw_low1x
1044
	jmp	.next_column_ccw_low1x
1037
 
1045
 
1038
.rotate_ccw32:
1046
.rotate_ccw32:
1039
  .next_column_ccw_low:
1047
  .next_column_ccw_low:
1040
	dec	ecx
1048
	dec	ecx
1041
	js	.exchange_dims
1049
	js	.exchange_dims
1042
	push	ecx
1050
	push	ecx
1043
 
1051
 
1044
	mov	edx, [scanline_len_old]
1052
	mov	edx, [scanline_len_old]
1045
	add	[scanline_len_old], -4
1053
	add	[scanline_len_old], -4
1046
 
1054
 
1047
	mov	ecx, [scanline_pixels_new]
1055
	mov	ecx, [scanline_pixels_new]
1048
	mov	esi, [ebx + Image.Data]
1056
	mov	esi, [ebx + Image.Data]
1049
	mov	edi, [line_buffer]
1057
	mov	edi, [line_buffer]
1050
    @@: mov	eax, [esi]
1058
    @@: mov	eax, [esi]
1051
	stosd
1059
	stosd
1052
	add	esi, edx
1060
	add	esi, edx
1053
	dec	ecx
1061
	dec	ecx
1054
	jnz	@b
1062
	jnz	@b
1055
 
1063
 
1056
	mov	eax, [scanline_pixels_new]
1064
	mov	eax, [scanline_pixels_new]
1057
	mov	edi, [ebx + Image.Data]
1065
	mov	edi, [ebx + Image.Data]
1058
	lea	esi, [edi + 4]
1066
	lea	esi, [edi + 4]
1059
	mov	edx, [scanline_len_old]
1067
	mov	edx, [scanline_len_old]
1060
	shr	edx, 2
1068
	shr	edx, 2
1061
    @@: mov	ecx, edx
1069
    @@: mov	ecx, edx
1062
	rep	movsd
1070
	rep	movsd
1063
	add	esi, 4
1071
	add	esi, 4
1064
	dec	eax
1072
	dec	eax
1065
	jnz	@b
1073
	jnz	@b
1066
 
1074
 
1067
	mov	eax, [scanline_len_new]
1075
	mov	eax, [scanline_len_new]
1068
	sub	[pixels_ptr], eax
1076
	sub	[pixels_ptr], eax
1069
	mov	ecx, [scanline_pixels_new]
1077
	mov	ecx, [scanline_pixels_new]
1070
	mov	esi, [line_buffer]
1078
	mov	esi, [line_buffer]
1071
	mov	edi, [pixels_ptr]
1079
	mov	edi, [pixels_ptr]
1072
	rep	movsd
1080
	rep	movsd
1073
 
1081
 
1074
	pop	ecx
1082
	pop	ecx
1075
	jmp	.next_column_ccw_low
1083
	jmp	.next_column_ccw_low
1076
 
1084
 
1077
.rotate_ccw8:
1085
.rotate_ccw8:
1078
  .next_column_ccw_low8:
1086
  .next_column_ccw_low8:
1079
	dec	ecx
1087
	dec	ecx
1080
	js	.exchange_dims
1088
	js	.exchange_dims
1081
	push	ecx
1089
	push	ecx
1082
 
1090
 
1083
	mov	edx, [scanline_len_old]
1091
	mov	edx, [scanline_len_old]
1084
	add	[scanline_len_old], -1
1092
	add	[scanline_len_old], -1
1085
 
1093
 
1086
	mov	ecx, [scanline_pixels_new]
1094
	mov	ecx, [scanline_pixels_new]
1087
	mov	esi, [ebx + Image.Data]
1095
	mov	esi, [ebx + Image.Data]
1088
	mov	edi, [line_buffer]
1096
	mov	edi, [line_buffer]
1089
    @@: mov	al, [esi]
1097
    @@: mov	al, [esi]
1090
	mov	[edi], al
1098
	mov	[edi], al
1091
	add	esi, edx
1099
	add	esi, edx
1092
	add	edi, 1
1100
	add	edi, 1
1093
	sub	ecx, 1
1101
	sub	ecx, 1
1094
	jnz	@b
1102
	jnz	@b
1095
 
1103
 
1096
	mov	eax, [scanline_pixels_new]
1104
	mov	eax, [scanline_pixels_new]
1097
	mov	edi, [ebx + Image.Data]
1105
	mov	edi, [ebx + Image.Data]
1098
	lea	esi, [edi + 1]
1106
	lea	esi, [edi + 1]
1099
	mov	edx, [scanline_len_old]
1107
	mov	edx, [scanline_len_old]
1100
    @@: mov	ecx, edx
1108
    @@: mov	ecx, edx
1101
	shr	ecx, 2
1109
	shr	ecx, 2
1102
	rep	movsd
1110
	rep	movsd
1103
	mov	ecx, edx
1111
	mov	ecx, edx
1104
	and	ecx, 3
1112
	and	ecx, 3
1105
	rep	movsb
1113
	rep	movsb
1106
	add	esi, 1
1114
	add	esi, 1
1107
	sub	eax, 1
1115
	sub	eax, 1
1108
	jnz	@b
1116
	jnz	@b
1109
 
1117
 
1110
	mov	eax, [scanline_len_new]
1118
	mov	eax, [scanline_len_new]
1111
	sub	[pixels_ptr], eax
1119
	sub	[pixels_ptr], eax
1112
	mov	ecx, [scanline_pixels_new]
1120
	mov	ecx, [scanline_pixels_new]
1113
	mov	esi, [line_buffer]
1121
	mov	esi, [line_buffer]
1114
	mov	edi, [pixels_ptr]
1122
	mov	edi, [pixels_ptr]
1115
	mov	edx, ecx
1123
	mov	edx, ecx
1116
	shr	ecx, 2
1124
	shr	ecx, 2
1117
	rep	movsd
1125
	rep	movsd
1118
	mov	ecx, edx
1126
	mov	ecx, edx
1119
	and	ecx, 3
1127
	and	ecx, 3
1120
	rep	movsb
1128
	rep	movsb
1121
 
1129
 
1122
	pop	ecx
1130
	pop	ecx
1123
	jmp	.next_column_ccw_low8
1131
	jmp	.next_column_ccw_low8
1124
 
1132
 
1125
.rotate_ccw24:
1133
.rotate_ccw24:
1126
  .next_column_ccw_low24:
1134
  .next_column_ccw_low24:
1127
	dec	ecx
1135
	dec	ecx
1128
	js	.exchange_dims
1136
	js	.exchange_dims
1129
	push	ecx
1137
	push	ecx
1130
 
1138
 
1131
	mov	edx, [scanline_len_old]
1139
	mov	edx, [scanline_len_old]
1132
	add	[scanline_len_old], -3
1140
	add	[scanline_len_old], -3
1133
 
1141
 
1134
	mov	ecx, [scanline_pixels_new]
1142
	mov	ecx, [scanline_pixels_new]
1135
	mov	esi, [ebx + Image.Data]
1143
	mov	esi, [ebx + Image.Data]
1136
	mov	edi, [line_buffer]
1144
	mov	edi, [line_buffer]
1137
    @@: mov	al, [esi]
1145
    @@: mov	al, [esi]
1138
	mov	[edi], al
1146
	mov	[edi], al
1139
	mov	al, [esi+1]
1147
	mov	al, [esi+1]
1140
	mov	[edi+1], al
1148
	mov	[edi+1], al
1141
	mov	al, [esi+2]
1149
	mov	al, [esi+2]
1142
	mov	[edi+2], al
1150
	mov	[edi+2], al
1143
	add	esi, edx
1151
	add	esi, edx
1144
	add	edi, 3
1152
	add	edi, 3
1145
	sub	ecx, 1
1153
	sub	ecx, 1
1146
	jnz	@b
1154
	jnz	@b
1147
 
1155
 
1148
	mov	eax, [scanline_pixels_new]
1156
	mov	eax, [scanline_pixels_new]
1149
	mov	edi, [ebx + Image.Data]
1157
	mov	edi, [ebx + Image.Data]
1150
	lea	esi, [edi + 3]
1158
	lea	esi, [edi + 3]
1151
	mov	edx, [scanline_len_old]
1159
	mov	edx, [scanline_len_old]
1152
    @@: mov	ecx, edx
1160
    @@: mov	ecx, edx
1153
	shr	ecx, 2
1161
	shr	ecx, 2
1154
	rep	movsd
1162
	rep	movsd
1155
	mov	ecx, edx
1163
	mov	ecx, edx
1156
	and	ecx, 3
1164
	and	ecx, 3
1157
	rep	movsb
1165
	rep	movsb
1158
	add	esi, 3
1166
	add	esi, 3
1159
	sub	eax, 1
1167
	sub	eax, 1
1160
	jnz	@b
1168
	jnz	@b
1161
 
1169
 
1162
	mov	eax, [scanline_len_new]
1170
	mov	eax, [scanline_len_new]
1163
	sub	[pixels_ptr], eax
1171
	sub	[pixels_ptr], eax
1164
	mov	ecx, eax
1172
	mov	ecx, eax
1165
	mov	esi, [line_buffer]
1173
	mov	esi, [line_buffer]
1166
	mov	edi, [pixels_ptr]
1174
	mov	edi, [pixels_ptr]
1167
	shr	ecx, 2
1175
	shr	ecx, 2
1168
	rep	movsd
1176
	rep	movsd
1169
	mov	ecx, eax
1177
	mov	ecx, eax
1170
	and	ecx, 3
1178
	and	ecx, 3
1171
	rep	movsb
1179
	rep	movsb
1172
 
1180
 
1173
	pop	ecx
1181
	pop	ecx
1174
	jmp	.next_column_ccw_low24
1182
	jmp	.next_column_ccw_low24
1175
 
1183
 
1176
  .rotate_cw_low:
1184
  .rotate_cw_low:
1177
	mov	eax, [ebx + Image.Height]
1185
	mov	eax, [ebx + Image.Height]
1178
	mov	[scanline_pixels_new], eax
1186
	mov	[scanline_pixels_new], eax
1179
	call	img._.get_scanline_len
1187
	call	img._.get_scanline_len
1180
	mov	[scanline_len_new], eax
1188
	mov	[scanline_len_new], eax
1181
 
1189
 
1182
	invoke	mem.alloc, eax
1190
	invoke	mem.alloc, eax
1183
	or	eax, eax
1191
	or	eax, eax
1184
	jz	.error
1192
	jz	.error
1185
	mov	[line_buffer], eax
1193
	mov	[line_buffer], eax
1186
 
1194
 
1187
	mov	eax, [ebx + Image.Width]
1195
	mov	eax, [ebx + Image.Width]
1188
	mov	ecx, eax
1196
	mov	ecx, eax
1189
	call	img._.get_scanline_len
1197
	call	img._.get_scanline_len
1190
	mov	[scanline_len_old], eax
1198
	mov	[scanline_len_old], eax
1191
 
1199
 
1192
	mov	eax, [scanline_len_new]
1200
	mov	eax, [scanline_len_new]
1193
	imul	eax, ecx
1201
	imul	eax, ecx
1194
	add	eax, [ebx + Image.Data]
1202
	add	eax, [ebx + Image.Data]
1195
	mov	[pixels_ptr], eax
1203
	mov	[pixels_ptr], eax
1196
 
1204
 
1197
	cmp	[ebx + Image.Type], Image.bpp8
1205
	cmp	[ebx + Image.Type], Image.bpp8
1198
	jz	.rotate_cw8
1206
	jz	.rotate_cw8
1199
	cmp	[ebx + Image.Type], Image.bpp24
1207
	cmp	[ebx + Image.Type], Image.bpp24
1200
	jz	.rotate_cw24
1208
	jz	.rotate_cw24
1201
	cmp	[ebx + Image.Type], Image.bpp32
1209
	cmp	[ebx + Image.Type], Image.bpp32
1202
	jz	.rotate_cw32
1210
	jz	.rotate_cw32
1203
 
1211
 
1204
  .next_column_cw_low1x:
1212
  .next_column_cw_low1x:
1205
	dec	ecx
1213
	dec	ecx
1206
	js	.exchange_dims
1214
	js	.exchange_dims
1207
	push	ecx
1215
	push	ecx
1208
 
1216
 
1209
	mov	edx, [scanline_len_old]
1217
	mov	edx, [scanline_len_old]
1210
	add	[scanline_len_old], -2
1218
	add	[scanline_len_old], -2
1211
 
1219
 
1212
	mov	ecx, [scanline_pixels_new]
1220
	mov	ecx, [scanline_pixels_new]
1213
	mov	esi, [pixels_ptr]
1221
	mov	esi, [pixels_ptr]
1214
	add	esi, -2
1222
	add	esi, -2
1215
	mov	edi, [line_buffer]
1223
	mov	edi, [line_buffer]
1216
    @@: mov	ax, [esi]
1224
    @@: mov	ax, [esi]
1217
	mov	[edi], ax
1225
	mov	[edi], ax
1218
	sub	esi, edx
1226
	sub	esi, edx
1219
	add	edi, 2
1227
	add	edi, 2
1220
	sub	ecx, 1
1228
	sub	ecx, 1
1221
	jnz	@b
1229
	jnz	@b
1222
 
1230
 
1223
	mov	eax, [scanline_pixels_new]
1231
	mov	eax, [scanline_pixels_new]
1224
	dec	eax
1232
	dec	eax
1225
	mov	edi, [ebx + Image.Data]
1233
	mov	edi, [ebx + Image.Data]
1226
	add	edi, [scanline_len_old]
1234
	add	edi, [scanline_len_old]
1227
	lea	esi, [edi + 2]
1235
	lea	esi, [edi + 2]
1228
	mov	edx, [scanline_len_old]
1236
	mov	edx, [scanline_len_old]
1229
    @@: mov	ecx, edx
1237
    @@: mov	ecx, edx
1230
	shr	ecx, 2
1238
	shr	ecx, 2
1231
	rep	movsd
1239
	rep	movsd
1232
	mov	ecx, edx
1240
	mov	ecx, edx
1233
	and	ecx, 3
1241
	and	ecx, 3
1234
	rep	movsb
1242
	rep	movsb
1235
	add	esi, 3
1243
	add	esi, 3
1236
	sub	eax, 1
1244
	sub	eax, 1
1237
	jnz	@b
1245
	jnz	@b
1238
 
1246
 
1239
	mov	eax, [scanline_len_new]
1247
	mov	eax, [scanline_len_new]
1240
	sub	[pixels_ptr], eax
1248
	sub	[pixels_ptr], eax
1241
	mov	ecx, eax
1249
	mov	ecx, eax
1242
	mov	esi, [line_buffer]
1250
	mov	esi, [line_buffer]
1243
	mov	edi, [pixels_ptr]
1251
	mov	edi, [pixels_ptr]
1244
	shr	ecx, 2
1252
	shr	ecx, 2
1245
	rep	movsd
1253
	rep	movsd
1246
	mov	ecx, eax
1254
	mov	ecx, eax
1247
	and	ecx, 3
1255
	and	ecx, 3
1248
	rep	movsb
1256
	rep	movsb
1249
 
1257
 
1250
	pop	ecx
1258
	pop	ecx
1251
	jmp	.next_column_cw_low1x
1259
	jmp	.next_column_cw_low1x
1252
 
1260
 
1253
.rotate_cw32:
1261
.rotate_cw32:
1254
  .next_column_cw_low:
1262
  .next_column_cw_low:
1255
	dec	ecx
1263
	dec	ecx
1256
	js	.exchange_dims
1264
	js	.exchange_dims
1257
	push	ecx
1265
	push	ecx
1258
 
1266
 
1259
	mov	edx, [scanline_len_old]
1267
	mov	edx, [scanline_len_old]
1260
	add	[scanline_len_old], -4
1268
	add	[scanline_len_old], -4
1261
 
1269
 
1262
	mov	ecx, [scanline_pixels_new]
1270
	mov	ecx, [scanline_pixels_new]
1263
	mov	esi, [pixels_ptr]
1271
	mov	esi, [pixels_ptr]
1264
	add	esi, -4
1272
	add	esi, -4
1265
	mov	edi, [line_buffer]
1273
	mov	edi, [line_buffer]
1266
    @@: mov	eax, [esi]
1274
    @@: mov	eax, [esi]
1267
	stosd
1275
	stosd
1268
	sub	esi, edx
1276
	sub	esi, edx
1269
	dec	ecx
1277
	dec	ecx
1270
	jnz	@b
1278
	jnz	@b
1271
 
1279
 
1272
	mov	eax, [scanline_pixels_new]
1280
	mov	eax, [scanline_pixels_new]
1273
	dec	eax
1281
	dec	eax
1274
	mov	edi, [ebx + Image.Data]
1282
	mov	edi, [ebx + Image.Data]
1275
	add	edi, [scanline_len_old]
1283
	add	edi, [scanline_len_old]
1276
	lea	esi, [edi + 4]
1284
	lea	esi, [edi + 4]
1277
	mov	edx, [scanline_len_old]
1285
	mov	edx, [scanline_len_old]
1278
	shr	edx, 2
1286
	shr	edx, 2
1279
    @@: mov	ecx, edx
1287
    @@: mov	ecx, edx
1280
	rep	movsd
1288
	rep	movsd
1281
	add	esi, 4
1289
	add	esi, 4
1282
	dec	eax
1290
	dec	eax
1283
	jnz	@b
1291
	jnz	@b
1284
 
1292
 
1285
	mov	eax, [scanline_len_new]
1293
	mov	eax, [scanline_len_new]
1286
	sub	[pixels_ptr], eax
1294
	sub	[pixels_ptr], eax
1287
	mov	ecx, [scanline_pixels_new]
1295
	mov	ecx, [scanline_pixels_new]
1288
	mov	esi, [line_buffer]
1296
	mov	esi, [line_buffer]
1289
	mov	edi, [pixels_ptr]
1297
	mov	edi, [pixels_ptr]
1290
	rep	movsd
1298
	rep	movsd
1291
 
1299
 
1292
	pop	ecx
1300
	pop	ecx
1293
	jmp	.next_column_cw_low
1301
	jmp	.next_column_cw_low
1294
 
1302
 
1295
.rotate_cw8:
1303
.rotate_cw8:
1296
  .next_column_cw_low8:
1304
  .next_column_cw_low8:
1297
	dec	ecx
1305
	dec	ecx
1298
	js	.exchange_dims
1306
	js	.exchange_dims
1299
	push	ecx
1307
	push	ecx
1300
 
1308
 
1301
	mov	edx, [scanline_len_old]
1309
	mov	edx, [scanline_len_old]
1302
	add	[scanline_len_old], -1
1310
	add	[scanline_len_old], -1
1303
 
1311
 
1304
	mov	ecx, [scanline_pixels_new]
1312
	mov	ecx, [scanline_pixels_new]
1305
	mov	esi, [pixels_ptr]
1313
	mov	esi, [pixels_ptr]
1306
	add	esi, -1
1314
	add	esi, -1
1307
	mov	edi, [line_buffer]
1315
	mov	edi, [line_buffer]
1308
    @@: mov	al, [esi]
1316
    @@: mov	al, [esi]
1309
	mov	[edi], al
1317
	mov	[edi], al
1310
	sub	esi, edx
1318
	sub	esi, edx
1311
	add	edi, 1
1319
	add	edi, 1
1312
	sub	ecx, 1
1320
	sub	ecx, 1
1313
	jnz	@b
1321
	jnz	@b
1314
 
1322
 
1315
	mov	eax, [scanline_pixels_new]
1323
	mov	eax, [scanline_pixels_new]
1316
	dec	eax
1324
	dec	eax
1317
	mov	edi, [ebx + Image.Data]
1325
	mov	edi, [ebx + Image.Data]
1318
	add	edi, [scanline_len_old]
1326
	add	edi, [scanline_len_old]
1319
	lea	esi, [edi + 1]
1327
	lea	esi, [edi + 1]
1320
	mov	edx, [scanline_len_old]
1328
	mov	edx, [scanline_len_old]
1321
    @@: mov	ecx, edx
1329
    @@: mov	ecx, edx
1322
	shr	ecx, 2
1330
	shr	ecx, 2
1323
	rep	movsd
1331
	rep	movsd
1324
	mov	ecx, edx
1332
	mov	ecx, edx
1325
	and	ecx, 3
1333
	and	ecx, 3
1326
	rep	movsb
1334
	rep	movsb
1327
	add	esi, 1
1335
	add	esi, 1
1328
	sub	eax, 1
1336
	sub	eax, 1
1329
	jnz	@b
1337
	jnz	@b
1330
 
1338
 
1331
	mov	eax, [scanline_len_new]
1339
	mov	eax, [scanline_len_new]
1332
	sub	[pixels_ptr], eax
1340
	sub	[pixels_ptr], eax
1333
	mov	ecx, eax
1341
	mov	ecx, eax
1334
	mov	esi, [line_buffer]
1342
	mov	esi, [line_buffer]
1335
	mov	edi, [pixels_ptr]
1343
	mov	edi, [pixels_ptr]
1336
	shr	ecx, 2
1344
	shr	ecx, 2
1337
	rep	movsd
1345
	rep	movsd
1338
	mov	ecx, eax
1346
	mov	ecx, eax
1339
	and	ecx, 3
1347
	and	ecx, 3
1340
	rep	movsb
1348
	rep	movsb
1341
 
1349
 
1342
	pop	ecx
1350
	pop	ecx
1343
	jmp	.next_column_cw_low8
1351
	jmp	.next_column_cw_low8
1344
 
1352
 
1345
.rotate_cw24:
1353
.rotate_cw24:
1346
  .next_column_cw_low24:
1354
  .next_column_cw_low24:
1347
	dec	ecx
1355
	dec	ecx
1348
	js	.exchange_dims
1356
	js	.exchange_dims
1349
	push	ecx
1357
	push	ecx
1350
 
1358
 
1351
	mov	edx, [scanline_len_old]
1359
	mov	edx, [scanline_len_old]
1352
	add	[scanline_len_old], -3
1360
	add	[scanline_len_old], -3
1353
 
1361
 
1354
	mov	ecx, [scanline_pixels_new]
1362
	mov	ecx, [scanline_pixels_new]
1355
	mov	esi, [pixels_ptr]
1363
	mov	esi, [pixels_ptr]
1356
	add	esi, -3
1364
	add	esi, -3
1357
	mov	edi, [line_buffer]
1365
	mov	edi, [line_buffer]
1358
    @@: mov	al, [esi]
1366
    @@: mov	al, [esi]
1359
	mov	[edi], al
1367
	mov	[edi], al
1360
	mov	al, [esi+1]
1368
	mov	al, [esi+1]
1361
	mov	[edi+1], al
1369
	mov	[edi+1], al
1362
	mov	al, [esi+2]
1370
	mov	al, [esi+2]
1363
	mov	[edi+2], al
1371
	mov	[edi+2], al
1364
	sub	esi, edx
1372
	sub	esi, edx
1365
	add	edi, 3
1373
	add	edi, 3
1366
	sub	ecx, 1
1374
	sub	ecx, 1
1367
	jnz	@b
1375
	jnz	@b
1368
 
1376
 
1369
	mov	eax, [scanline_pixels_new]
1377
	mov	eax, [scanline_pixels_new]
1370
	dec	eax
1378
	dec	eax
1371
	mov	edi, [ebx + Image.Data]
1379
	mov	edi, [ebx + Image.Data]
1372
	add	edi, [scanline_len_old]
1380
	add	edi, [scanline_len_old]
1373
	lea	esi, [edi + 3]
1381
	lea	esi, [edi + 3]
1374
	mov	edx, [scanline_len_old]
1382
	mov	edx, [scanline_len_old]
1375
    @@: mov	ecx, edx
1383
    @@: mov	ecx, edx
1376
	shr	ecx, 2
1384
	shr	ecx, 2
1377
	rep	movsd
1385
	rep	movsd
1378
	mov	ecx, edx
1386
	mov	ecx, edx
1379
	and	ecx, 3
1387
	and	ecx, 3
1380
	rep	movsb
1388
	rep	movsb
1381
	add	esi, 3
1389
	add	esi, 3
1382
	sub	eax, 1
1390
	sub	eax, 1
1383
	jnz	@b
1391
	jnz	@b
1384
 
1392
 
1385
	mov	eax, [scanline_len_new]
1393
	mov	eax, [scanline_len_new]
1386
	sub	[pixels_ptr], eax
1394
	sub	[pixels_ptr], eax
1387
	mov	ecx, eax
1395
	mov	ecx, eax
1388
	mov	esi, [line_buffer]
1396
	mov	esi, [line_buffer]
1389
	mov	edi, [pixels_ptr]
1397
	mov	edi, [pixels_ptr]
1390
	shr	ecx, 2
1398
	shr	ecx, 2
1391
	rep	movsd
1399
	rep	movsd
1392
	mov	ecx, eax
1400
	mov	ecx, eax
1393
	and	ecx, 3
1401
	and	ecx, 3
1394
	rep	movsb
1402
	rep	movsb
1395
 
1403
 
1396
	pop	ecx
1404
	pop	ecx
1397
	jmp	.next_column_cw_low24
1405
	jmp	.next_column_cw_low24
1398
 
1406
 
1399
  .flip:
1407
  .flip:
1400
	jmp	.exit
1408
	jmp	.exit
1401
 
1409
 
1402
  .exchange_dims:
1410
  .exchange_dims:
1403
	push	[ebx + Image.Width] [ebx + Image.Height]
1411
	push	[ebx + Image.Width] [ebx + Image.Height]
1404
	pop	[ebx + Image.Width] [ebx + Image.Height]
1412
	pop	[ebx + Image.Width] [ebx + Image.Height]
1405
 
1413
 
1406
  .exit:
1414
  .exit:
1407
	invoke	mem.free, [line_buffer]
1415
	invoke	mem.free, [line_buffer]
1408
	xor	eax, eax
1416
	xor	eax, eax
1409
	inc	eax
1417
	inc	eax
1410
	pop	edi esi ebx
1418
	pop	edi esi ebx
1411
	ret
1419
	ret
1412
 
1420
 
1413
  .error:
1421
  .error:
1414
	invoke	mem.free, [line_buffer]
1422
	invoke	mem.free, [line_buffer]
1415
	xor	eax, eax
1423
	xor	eax, eax
1416
	pop	edi esi ebx
1424
	pop	edi esi ebx
1417
	ret
1425
	ret
1418
endp
1426
endp
1419
 
1427
 
1420
;;================================================================================================;;
1428
;;================================================================================================;;
1421
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
1429
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
1422
;;------------------------------------------------------------------------------------------------;;
1430
;;------------------------------------------------------------------------------------------------;;
1423
;? Rotate all layers of image                                                                     ;;
1431
;? Rotate all layers of image                                                                     ;;
1424
;;------------------------------------------------------------------------------------------------;;
1432
;;------------------------------------------------------------------------------------------------;;
1425
;> _img = pointer to image                                                                        ;;
1433
;> _img = pointer to image                                                                        ;;
1426
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
1434
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
1427
;;------------------------------------------------------------------------------------------------;;
1435
;;------------------------------------------------------------------------------------------------;;
1428
;< eax = false / true                                                                             ;;
1436
;< eax = false / true                                                                             ;;
1429
;;================================================================================================;;
1437
;;================================================================================================;;
1430
	push	1
1438
	push	1
1431
	mov	ebx, [_img]
1439
	mov	ebx, [_img]
1432
@@:
1440
@@:
1433
	mov	eax, [ebx + Image.Previous]
1441
	mov	eax, [ebx + Image.Previous]
1434
	test	eax, eax
1442
	test	eax, eax
1435
	jz	.loop
1443
	jz	.loop
1436
	mov	ebx, eax
1444
	mov	ebx, eax
1437
	jmp	@b
1445
	jmp	@b
1438
.loop:
1446
.loop:
1439
	stdcall	img.rotate.layer, ebx, [_rotate_kind]
1447
	stdcall	img.rotate.layer, ebx, [_rotate_kind]
1440
	test	eax, eax
1448
	test	eax, eax
1441
	jnz	@f
1449
	jnz	@f
1442
	mov	byte [esp], 0
1450
	mov	byte [esp], 0
1443
@@:
1451
@@:
1444
	mov	ebx, [ebx + Image.Next]
1452
	mov	ebx, [ebx + Image.Next]
1445
	test	ebx, ebx
1453
	test	ebx, ebx
1446
	jnz	.loop
1454
	jnz	.loop
1447
	pop	eax
1455
	pop	eax
1448
	ret
1456
	ret
1449
endp
1457
endp
1450
 
1458
 
1451
;;================================================================================================;;
1459
;;================================================================================================;;
1452
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////////////////////////;;
1460
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////////////////////////;;
1453
;;------------------------------------------------------------------------------------------------;;
1461
;;------------------------------------------------------------------------------------------------;;
1454
;? Draw image in the window                                                                       ;;
1462
;? Draw image in the window                                                                       ;;
1455
;;------------------------------------------------------------------------------------------------;;
1463
;;------------------------------------------------------------------------------------------------;;
1456
;> _img = pointer to image                                                                        ;;
1464
;> _img = pointer to image                                                                        ;;
1457
;>_x = x-coordinate in the window                                                                 ;;
1465
;>_x = x-coordinate in the window                                                                 ;;
1458
;>_y = y-coordinate in the window                                                                 ;;
1466
;>_y = y-coordinate in the window                                                                 ;;
1459
;>_width = maximum width to draw                                                                  ;;
1467
;>_width = maximum width to draw                                                                  ;;
1460
;>_height = maximum height to draw                                                                ;;
1468
;>_height = maximum height to draw                                                                ;;
1461
;>_xpos = offset in image by x-axis                                                               ;;
1469
;>_xpos = offset in image by x-axis                                                               ;;
1462
;>_ypos = offset in image by y-axis                                                               ;;
1470
;>_ypos = offset in image by y-axis                                                               ;;
1463
;;------------------------------------------------------------------------------------------------;;
1471
;;------------------------------------------------------------------------------------------------;;
1464
;< no return value                                                                                ;;
1472
;< no return value                                                                                ;;
1465
;;================================================================================================;;
1473
;;================================================================================================;;
1466
	push	ebx esi edi
1474
	push	ebx esi edi
1467
	mov	ebx, [_img]
1475
	mov	ebx, [_img]
1468
	stdcall	img._.validate, ebx
1476
	stdcall	img._.validate, ebx
1469
	test	eax, eax
1477
	test	eax, eax
1470
	jnz	.done
1478
	jnz	.done
1471
	mov	ecx, [ebx + Image.Width]
1479
	mov	ecx, [ebx + Image.Width]
1472
	sub	ecx, [_xpos]
1480
	sub	ecx, [_xpos]
1473
	jbe	.done
1481
	jbe	.done
1474
	cmp	ecx, [_width]
1482
	cmp	ecx, [_width]
1475
	jb	@f
1483
	jb	@f
1476
	mov	ecx, [_width]
1484
	mov	ecx, [_width]
1477
@@:
1485
@@:
1478
	mov	edx, [ebx + Image.Height]
1486
	mov	edx, [ebx + Image.Height]
1479
	sub	edx, [_ypos]
1487
	sub	edx, [_ypos]
1480
	jbe	.done
1488
	jbe	.done
1481
	cmp	edx, [_height]
1489
	cmp	edx, [_height]
1482
	jb	@f
1490
	jb	@f
1483
	mov	edx, [_height]
1491
	mov	edx, [_height]
1484
@@:
1492
@@:
1485
	mov	eax, [ebx + Image.Width]
1493
	mov	eax, [ebx + Image.Width]
1486
	sub	eax, ecx
1494
	sub	eax, ecx
1487
	call	img._.get_scanline_len
1495
	call	img._.get_scanline_len
1488
	shl	ecx, 16
1496
	shl	ecx, 16
1489
	add	ecx, edx
1497
	add	ecx, edx
1490
	mov	edx, [_x - 2]
1498
	mov	edx, [_x - 2]
1491
	mov	dx, word [_y]
1499
	mov	dx, word [_y]
1492
	mov	esi, [ebx + Image.Type]
1500
	mov	esi, [ebx + Image.Type]
1493
	mov	esi, [type2bpp + (esi-1)*4]
1501
	mov	esi, [type2bpp + (esi-1)*4]
1494
	mov	edi, [ebx + Image.Palette]
1502
	mov	edi, [ebx + Image.Palette]
1495
	mov	ebx, [ebx + Image.Data]
1503
	mov	ebx, [ebx + Image.Data]
1496
	push	ebp
1504
	push	ebp
1497
	push	65
1505
	push	65
1498
	pop	ebp
1506
	pop	ebp
1499
	xchg	eax, ebp
1507
	xchg	eax, ebp
1500
	int	40h
1508
	int	40h
1501
	pop	ebp
1509
	pop	ebp
1502
.done:
1510
.done:
1503
	pop	edi esi ebx
1511
	pop	edi esi ebx
1504
	ret
1512
	ret
1505
endp
1513
endp
1506
 
1514
 
1507
;;================================================================================================;;
1515
;;================================================================================================;;
1508
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1516
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1509
;;================================================================================================;;
1517
;;================================================================================================;;
1510
;! Below are private procs you should never call directly from your code                          ;;
1518
;! Below are private procs you should never call directly from your code                          ;;
1511
;;================================================================================================;;
1519
;;================================================================================================;;
1512
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1520
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1513
;;================================================================================================;;
1521
;;================================================================================================;;
1514
 
1522
 
1515
 
1523
 
1516
;;================================================================================================;;
1524
;;================================================================================================;;
1517
proc img._.validate, _img ;///////////////////////////////////////////////////////////////////////;;
1525
proc img._.validate, _img ;///////////////////////////////////////////////////////////////////////;;
1518
;;------------------------------------------------------------------------------------------------;;
1526
;;------------------------------------------------------------------------------------------------;;
1519
;? --- TBD ---                                                                                    ;;
1527
;? --- TBD ---                                                                                    ;;
1520
;;------------------------------------------------------------------------------------------------;;
1528
;;------------------------------------------------------------------------------------------------;;
1521
;> --- TBD ---                                                                                    ;;
1529
;> --- TBD ---                                                                                    ;;
1522
;;------------------------------------------------------------------------------------------------;;
1530
;;------------------------------------------------------------------------------------------------;;
1523
;< --- TBD ---                                                                                    ;;
1531
;< --- TBD ---                                                                                    ;;
1524
;;================================================================================================;;
1532
;;================================================================================================;;
1525
	xor	eax, eax
1533
	xor	eax, eax
1526
	ret
1534
	ret
1527
endp
1535
endp
1528
 
1536
 
1529
;;================================================================================================;;
1537
;;================================================================================================;;
1530
proc img._.new ;//////////////////////////////////////////////////////////////////////////////////;;
1538
proc img._.new ;//////////////////////////////////////////////////////////////////////////////////;;
1531
;;------------------------------------------------------------------------------------------------;;
1539
;;------------------------------------------------------------------------------------------------;;
1532
;? --- TBD ---                                                                                    ;;
1540
;? --- TBD ---                                                                                    ;;
1533
;;------------------------------------------------------------------------------------------------;;
1541
;;------------------------------------------------------------------------------------------------;;
1534
;> --- TBD ---                                                                                    ;;
1542
;> --- TBD ---                                                                                    ;;
1535
;;------------------------------------------------------------------------------------------------;;
1543
;;------------------------------------------------------------------------------------------------;;
1536
;< eax = 0 / pointer to image                                                                     ;;
1544
;< eax = 0 / pointer to image                                                                     ;;
1537
;;================================================================================================;;
1545
;;================================================================================================;;
1538
	invoke	mem.alloc, sizeof.Image
1546
	invoke	mem.alloc, sizeof.Image
1539
	test	eax, eax
1547
	test	eax, eax
1540
	jz	@f
1548
	jz	@f
1541
	push	ecx
1549
	push	ecx
1542
	xor	ecx, ecx
1550
	xor	ecx, ecx
1543
	mov	[eax + Image.Data], ecx
1551
	mov	[eax + Image.Data], ecx
1544
	mov	[eax + Image.Type], ecx
1552
	mov	[eax + Image.Type], ecx
1545
	mov	[eax + Image.Flags], ecx
1553
	mov	[eax + Image.Flags], ecx
1546
	mov	[eax + Image.Extended], ecx
1554
	mov	[eax + Image.Extended], ecx
1547
	mov	[eax + Image.Previous], ecx
1555
	mov	[eax + Image.Previous], ecx
1548
	mov	[eax + Image.Next], ecx
1556
	mov	[eax + Image.Next], ecx
1549
	pop	ecx
1557
	pop	ecx
1550
@@:
1558
@@:
1551
	ret
1559
	ret
1552
endp
1560
endp
1553
 
1561
 
1554
;;================================================================================================;;
1562
;;================================================================================================;;
1555
proc img._.delete _img ;//////////////////////////////////////////////////////////////////////////;;
1563
proc img._.delete _img ;//////////////////////////////////////////////////////////////////////////;;
1556
;;------------------------------------------------------------------------------------------------;;
1564
;;------------------------------------------------------------------------------------------------;;
1557
;? --- TBD ---                                                                                    ;;
1565
;? --- TBD ---                                                                                    ;;
1558
;;------------------------------------------------------------------------------------------------;;
1566
;;------------------------------------------------------------------------------------------------;;
1559
;> --- TBD ---                                                                                    ;;
1567
;> --- TBD ---                                                                                    ;;
1560
;;------------------------------------------------------------------------------------------------;;
1568
;;------------------------------------------------------------------------------------------------;;
1561
;< eax = false / true                                                                             ;;
1569
;< eax = false / true                                                                             ;;
1562
;;================================================================================================;;
1570
;;================================================================================================;;
1563
	push	edx
1571
	push	edx
1564
	mov	edx, [_img]
1572
	mov	edx, [_img]
1565
	cmp	[edx + Image.Data], 0
1573
	cmp	[edx + Image.Data], 0
1566
	je	@f
1574
	je	@f
1567
	invoke	mem.free, [edx + Image.Data]
1575
	invoke	mem.free, [edx + Image.Data]
1568
    @@: cmp	[edx + Image.Extended], 0
1576
    @@: cmp	[edx + Image.Extended], 0
1569
	je	@f
1577
	je	@f
1570
	invoke	mem.free, [edx + Image.Extended]
1578
	invoke	mem.free, [edx + Image.Extended]
1571
    @@: invoke	mem.free, edx
1579
    @@: invoke	mem.free, edx
1572
	pop	edx
1580
	pop	edx
1573
	ret
1581
	ret
1574
endp
1582
endp
1575
 
1583
 
1576
;;================================================================================================;;
1584
;;================================================================================================;;
1577
proc img._.resize_data _img, _width, _height ;////////////////////////////////////////////////////;;
1585
proc img._.resize_data _img, _width, _height ;////////////////////////////////////////////////////;;
1578
;;------------------------------------------------------------------------------------------------;;
1586
;;------------------------------------------------------------------------------------------------;;
1579
;? --- TBD ---                                                                                    ;;
1587
;? --- TBD ---                                                                                    ;;
1580
;;------------------------------------------------------------------------------------------------;;
1588
;;------------------------------------------------------------------------------------------------;;
1581
;> --- TBD ---                                                                                    ;;
1589
;> --- TBD ---                                                                                    ;;
1582
;;------------------------------------------------------------------------------------------------;;
1590
;;------------------------------------------------------------------------------------------------;;
1583
;< --- TBD ---                                                                                    ;;
1591
;< --- TBD ---                                                                                    ;;
1584
;;================================================================================================;;
1592
;;================================================================================================;;
1585
	push	ebx esi
1593
	push	ebx esi
1586
	mov	ebx, [_img]
1594
	mov	ebx, [_img]
1587
	mov	eax, [_height]
1595
	mov	eax, [_height]
1588
; our memory is limited, [_width]*[_height] must not overflow
1596
; our memory is limited, [_width]*[_height] must not overflow
1589
; image with width or height greater than 65535 is most likely bogus
1597
; image with width or height greater than 65535 is most likely bogus
1590
	cmp	word [_width+2], 0
1598
	cmp	word [_width+2], 0
1591
	jnz	.error
1599
	jnz	.error
1592
	cmp	word [_height+2], 0
1600
	cmp	word [_height+2], 0
1593
	jnz	.error
1601
	jnz	.error
1594
	imul	eax, [_width]
1602
	imul	eax, [_width]
1595
	test	eax, eax
1603
	test	eax, eax
1596
	jz	.error
1604
	jz	.error
1597
; do not allow images which require too many memory
1605
; do not allow images which require too many memory
1598
	cmp	eax, 4000000h
1606
	cmp	eax, 4000000h
1599
	jae	.error
1607
	jae	.error
1600
	cmp	[ebx + Image.Type], Image.bpp8
1608
	cmp	[ebx + Image.Type], Image.bpp8
1601
	jz	.bpp8
1609
	jz	.bpp8
1602
	cmp	[ebx + Image.Type], Image.bpp24
1610
	cmp	[ebx + Image.Type], Image.bpp24
1603
	jz	.bpp24
1611
	jz	.bpp24
1604
.bpp32:
1612
.bpp32:
1605
	shl	eax, 2
1613
	shl	eax, 2
1606
	jmp	@f
1614
	jmp	@f
1607
.bpp24:
1615
.bpp24:
1608
	lea	eax, [eax*3]
1616
	lea	eax, [eax*3]
1609
	jmp	@f
1617
	jmp	@f
1610
.bpp8:
1618
.bpp8:
1611
	add	eax, 256*4	; for palette
1619
	add	eax, 256*4	; for palette
1612
@@:
1620
@@:
1613
	mov	esi, eax
1621
	mov	esi, eax
1614
	invoke	mem.realloc, [ebx + Image.Data], eax
1622
	invoke	mem.realloc, [ebx + Image.Data], eax
1615
	or	eax, eax
1623
	or	eax, eax
1616
	jz	.error
1624
	jz	.error
1617
 
1625
 
1618
	mov	[ebx + Image.Data], eax
1626
	mov	[ebx + Image.Data], eax
1619
	push	[_width]
1627
	push	[_width]
1620
	pop	[ebx + Image.Width]
1628
	pop	[ebx + Image.Width]
1621
	push	[_height]
1629
	push	[_height]
1622
	pop	[ebx + Image.Height]
1630
	pop	[ebx + Image.Height]
1623
	cmp	[ebx + Image.Type], Image.bpp8
1631
	cmp	[ebx + Image.Type], Image.bpp8
1624
	jnz	.ret
1632
	jnz	.ret
1625
	lea	esi, [eax + esi - 256*4]
1633
	lea	esi, [eax + esi - 256*4]
1626
	mov	[ebx + Image.Palette], esi
1634
	mov	[ebx + Image.Palette], esi
1627
	jmp	.ret
1635
	jmp	.ret
1628
 
1636
 
1629
  .error:
1637
  .error:
1630
	xor	eax, eax
1638
	xor	eax, eax
1631
  .ret:
1639
  .ret:
1632
	pop	esi ebx
1640
	pop	esi ebx
1633
	ret
1641
	ret
1634
endp
1642
endp
1635
 
1643
 
1636
;;================================================================================================;;
1644
;;================================================================================================;;
1637
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
1645
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
1638
;;------------------------------------------------------------------------------------------------;;
1646
;;------------------------------------------------------------------------------------------------;;
1639
;? --- TBD ---                                                                                    ;;
1647
;? --- TBD ---                                                                                    ;;
1640
;;------------------------------------------------------------------------------------------------;;
1648
;;------------------------------------------------------------------------------------------------;;
1641
;> --- TBD ---                                                                                    ;;
1649
;> --- TBD ---                                                                                    ;;
1642
;;------------------------------------------------------------------------------------------------;;
1650
;;------------------------------------------------------------------------------------------------;;
1643
;< --- TBD ---                                                                                    ;;
1651
;< --- TBD ---                                                                                    ;;
1644
;;================================================================================================;;
1652
;;================================================================================================;;
1645
	cmp	[ebx + Image.Type], Image.bpp8
1653
	cmp	[ebx + Image.Type], Image.bpp8
1646
	jz	.bpp8.1
1654
	jz	.bpp8.1
1647
	cmp	[ebx + Image.Type], Image.bpp24
1655
	cmp	[ebx + Image.Type], Image.bpp24
1648
	jz	.bpp24.1
1656
	jz	.bpp24.1
1649
	add	eax, eax
1657
	add	eax, eax
1650
	cmp	[ebx + Image.Type], Image.bpp32
1658
	cmp	[ebx + Image.Type], Image.bpp32
1651
	jnz	@f
1659
	jnz	@f
1652
	add	eax, eax
1660
	add	eax, eax
1653
	jmp	@f
1661
	jmp	@f
1654
.bpp24.1:
1662
.bpp24.1:
1655
	lea	eax, [eax*3]
1663
	lea	eax, [eax*3]
1656
.bpp8.1:
1664
.bpp8.1:
1657
@@:
1665
@@:
1658
	ret
1666
	ret
1659
 
1667
 
1660
 
1668
 
1661
;;================================================================================================;;
1669
;;================================================================================================;;
1662
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1670
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1663
;;================================================================================================;;
1671
;;================================================================================================;;
1664
;! Below is private data you should never use directly from your code                             ;;
1672
;! Below is private data you should never use directly from your code                             ;;
1665
;;================================================================================================;;
1673
;;================================================================================================;;
1666
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1674
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1667
;;================================================================================================;;
1675
;;================================================================================================;;
1668
 
1676
 
1669
align 4
1677
align 4
1670
img._.formats_table:
1678
img._.formats_table:
1671
  .bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
1679
  .bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
1672
  .ico dd img.is.ico, img.decode.ico_cur, img.encode.ico
1680
  .ico dd img.is.ico, img.decode.ico_cur, img.encode.ico
1673
  .cur dd img.is.cur, img.decode.ico_cur, img.encode.cur
1681
  .cur dd img.is.cur, img.decode.ico_cur, img.encode.cur
1674
  .gif dd img.is.gif, img.decode.gif, img.encode.gif
1682
  .gif dd img.is.gif, img.decode.gif, img.encode.gif
1675
  .png dd img.is.png, img.decode.png, img.encode.png
1683
  .png dd img.is.png, img.decode.png, img.encode.png
1676
  .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
1684
  .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
1677
  .tga dd img.is.tga, img.decode.tga, img.encode.tga
1685
  .tga dd img.is.tga, img.decode.tga, img.encode.tga
1678
  .z80 dd img.is.z80, img.decode.z80, img.encode.z80 ;this must be the last entry as there are no
1686
  .z80 dd img.is.z80, img.decode.z80, img.encode.z80 ;this must be the last entry as there are no
1679
  ;signatures in z80 screens at all
1687
  ;signatures in z80 screens at all
1680
       dd 0
1688
       dd 0
1681
 
1689
 
1682
align 4
1690
align 4
1683
type2bpp	dd	8, 24, 32, 15, 16
1691
type2bpp	dd	8, 24, 32, 15, 16
1684
img._.do_rgb.handlers:
1692
img._.do_rgb.handlers:
1685
	dd	img._.do_rgb.bpp8
1693
	dd	img._.do_rgb.bpp8
1686
	dd	img._.do_rgb.bpp24
1694
	dd	img._.do_rgb.bpp24
1687
	dd	img._.do_rgb.bpp32
1695
	dd	img._.do_rgb.bpp32
1688
	dd	img._.do_rgb.bpp15.amd	; can be overwritten in lib_init
1696
	dd	img._.do_rgb.bpp15.amd	; can be overwritten in lib_init
1689
	dd	img._.do_rgb.bpp16.amd	; can be overwritten in lib_init
1697
	dd	img._.do_rgb.bpp16.amd	; can be overwritten in lib_init
1690
 
1698
 
1691
img.flip.layer.handlers_horz:
1699
img.flip.layer.handlers_horz:
1692
	dd	img.flip.layer.bpp8_horz
1700
	dd	img.flip.layer.bpp8_horz
1693
	dd	img.flip.layer.bpp24_horz
1701
	dd	img.flip.layer.bpp24_horz
1694
	dd	img.flip.layer.bpp32_horz
1702
	dd	img.flip.layer.bpp32_horz
1695
	dd	img.flip.layer.bpp1x_horz
1703
	dd	img.flip.layer.bpp1x_horz
1696
	dd	img.flip.layer.bpp1x_horz
1704
	dd	img.flip.layer.bpp1x_horz
1697
 
1705
 
1698
;;================================================================================================;;
1706
;;================================================================================================;;
1699
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1707
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1700
;;================================================================================================;;
1708
;;================================================================================================;;
1701
;! Exported functions section                                                                     ;;
1709
;! Exported functions section                                                                     ;;
1702
;;================================================================================================;;
1710
;;================================================================================================;;
1703
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1711
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1704
;;================================================================================================;;
1712
;;================================================================================================;;
1705
 
1713
 
1706
 
1714
 
1707
align 4
1715
align 4
1708
@EXPORT:
1716
@EXPORT:
1709
 
1717
 
1710
export					      \
1718
export					      \
1711
	lib_init	, 'lib_init'	    , \
1719
	lib_init	, 'lib_init'	    , \
1712
	0x00050005	, 'version'	    , \
1720
	0x00050006	, 'version'	    , \
1713
	img.is_img	, 'img_is_img'	    , \
1721
	img.is_img	, 'img_is_img'	    , \
1714
	img.info	, 'img_info'	    , \
1722
	img.info	, 'img_info'	    , \
1715
	img.from_file	, 'img_from_file'   , \
1723
	img.from_file	, 'img_from_file'   , \
1716
	img.to_file	, 'img_to_file'     , \
1724
	img.to_file	, 'img_to_file'     , \
1717
	img.from_rgb	, 'img_from_rgb'    , \
1725
	img.from_rgb	, 'img_from_rgb'    , \
1718
	img.to_rgb	, 'img_to_rgb'	    , \
1726
	img.to_rgb	, 'img_to_rgb'	    , \
1719
	img.to_rgb2	, 'img_to_rgb2'     , \
1727
	img.to_rgb2	, 'img_to_rgb2'     , \
1720
	img.decode	, 'img_decode'	    , \
1728
	img.decode	, 'img_decode'	    , \
1721
	img.encode	, 'img_encode'	    , \
1729
	img.encode	, 'img_encode'	    , \
1722
	img.create	, 'img_create'	    , \
1730
	img.create	, 'img_create'	    , \
1723
	img.destroy	, 'img_destroy'     , \
1731
	img.destroy	, 'img_destroy'     , \
1724
	img.destroy.layer, 'img_destroy_layer', \
1732
	img.destroy.layer, 'img_destroy_layer', \
1725
	img.count	, 'img_count'	    , \
1733
	img.count	, 'img_count'	    , \
1726
	img.lock_bits	, 'img_lock_bits'   , \
1734
	img.lock_bits	, 'img_lock_bits'   , \
1727
	img.unlock_bits , 'img_unlock_bits' , \
1735
	img.unlock_bits , 'img_unlock_bits' , \
1728
	img.flip	, 'img_flip'	    , \
1736
	img.flip	, 'img_flip'	    , \
1729
	img.flip.layer  , 'img_flip_layer'  , \
1737
	img.flip.layer  , 'img_flip_layer'  , \
1730
	img.rotate	, 'img_rotate'      , \
1738
	img.rotate	, 'img_rotate'      , \
1731
	img.rotate.layer, 'img_rotate_layer', \
1739
	img.rotate.layer, 'img_rotate_layer', \
1732
	img.draw        , 'img_draw'
1740
	img.draw        , 'img_draw'
1733
 
1741
 
1734
; import from deflate unpacker
1742
; import from deflate unpacker
1735
; is initialized only when PNG loading is requested
1743
; is initialized only when PNG loading is requested
1736
align 4
1744
align 4
1737
@IMPORT:
1745
@IMPORT:
1738
 
1746
 
1739
library archiver, 'archiver.obj'
1747
library archiver, 'archiver.obj'
1740
import	archiver, \
1748
import	archiver, \
1741
	deflate_unpack2, 'deflate_unpack2'
1749
	deflate_unpack2, 'deflate_unpack2'
1742
 
1750
 
1743
align 4
1751
align 4
1744
; mutex for unpacker loading
1752
; mutex for unpacker loading
1745
deflate_loader_mutex	dd	0
1753
deflate_loader_mutex	dd	0
1746
 
1754
 
1747
; default palette for GIF - b&w
1755
; default palette for GIF - b&w
1748
gif_default_palette:
1756
gif_default_palette:
1749
	db	0, 0, 0
1757
	db	0, 0, 0
1750
	db	0xFF, 0xFF, 0xFF
1758
	db	0xFF, 0xFF, 0xFF
1751
 
1759
 
1752
section '.data' data readable writable align 16
1760
section '.data' data readable writable align 16
1753
; uninitialized data - global constant tables
1761
; uninitialized data - global constant tables
1754
mem.alloc   dd ?
1762
mem.alloc   dd ?
1755
mem.free    dd ?
1763
mem.free    dd ?
1756
mem.realloc dd ?
1764
mem.realloc dd ?
1757
dll.load    dd ?
1765
dll.load    dd ?
1758
 
1766
 
1759
; data for YCbCr -> RGB translation
1767
; data for YCbCr -> RGB translation
1760
color_table_1		rd	256
1768
color_table_1		rd	256
1761
color_table_2		rd	256
1769
color_table_2		rd	256
1762
color_table_3		rd	256
1770
color_table_3		rd	256
1763
color_table_4		rd	256
1771
color_table_4		rd	256