Subversion Repositories Kolibri OS

Rev

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

Rev 3499 Rev 3503
1
;;================================================================================================;;
1
;;================================================================================================;;
2
;;//// libimg.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009, (c) dunkaist, 2011-2012 ///////;;
2
;;//// libimg.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009, (c) dunkaist, 2011-2013 ///////;;
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
include '../../../../config.inc'
28
include '../../../../config.inc'
29
;include '../../../../debug.inc'
29
;include '../../../../debug.inc'
30
purge section,mov,add,sub
30
purge section,mov,add,sub
31
 
31
 
32
include 'libimg.inc'
32
include 'libimg.inc'
33
 
33
 
34
section '.flat' code readable align 16
34
section '.flat' code readable align 16
35
 
35
 
36
include 'bmp/bmp.asm'
36
include 'bmp/bmp.asm'
37
include 'gif/gif.asm'
37
include 'gif/gif.asm'
38
include 'jpeg/jpeg.asm'
38
include 'jpeg/jpeg.asm'
39
include 'png/png.asm'
39
include 'png/png.asm'
40
include 'tga/tga.asm'
40
include 'tga/tga.asm'
41
include 'z80/z80.asm'
41
include 'z80/z80.asm'
42
include 'ico_cur/ico_cur.asm'
42
include 'ico_cur/ico_cur.asm'
43
include 'pcx/pcx.asm'
43
include 'pcx/pcx.asm'
44
include 'xcf/xcf.asm'
44
include 'xcf/xcf.asm'
45
include 'tiff/tiff.asm'
45
include 'tiff/tiff.asm'
46
include 'pnm/pnm.asm'
46
include 'pnm/pnm.asm'
47
include 'wbmp/wbmp.asm'
47
include 'wbmp/wbmp.asm'
48
include 'xbm/xbm.asm'
48
include 'xbm/xbm.asm'
49
 
49
 
50
include 'scale.asm'
50
include 'scale.asm'
51
include 'convert.asm'
51
include 'convert.asm'
52
;include 'transform.asm'
52
;include 'transform.asm'
53
 
53
 
54
;;================================================================================================;;
54
;;================================================================================================;;
55
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
55
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
56
;;------------------------------------------------------------------------------------------------;;
56
;;------------------------------------------------------------------------------------------------;;
57
;? Library entry point (called after library load)                                                ;;
57
;? Library entry point (called after library load)                                                ;;
58
;;------------------------------------------------------------------------------------------------;;
58
;;------------------------------------------------------------------------------------------------;;
59
;> eax = pointer to memory allocation routine                                                     ;;
59
;> eax = pointer to memory allocation routine                                                     ;;
60
;> ebx = pointer to memory freeing routine                                                        ;;
60
;> ebx = pointer to memory freeing routine                                                        ;;
61
;> ecx = pointer to memory reallocation routine                                                   ;;
61
;> ecx = pointer to memory reallocation routine                                                   ;;
62
;> edx = pointer to library loading routine                                                       ;;
62
;> edx = pointer to library loading routine                                                       ;;
63
;;------------------------------------------------------------------------------------------------;;
63
;;------------------------------------------------------------------------------------------------;;
64
;< eax = 1 (fail) / 0 (ok) (library initialization result)                                        ;;
64
;< eax = 1 (fail) / 0 (ok) (library initialization result)                                        ;;
65
;;================================================================================================;;
65
;;================================================================================================;;
66
    mov [mem.alloc], eax
66
    mov [mem.alloc], eax
67
    mov [mem.free], ebx
67
    mov [mem.free], ebx
68
    mov [mem.realloc], ecx
68
    mov [mem.realloc], ecx
69
    mov [dll.load], edx
69
    mov [dll.load], edx
70
 
70
 
71
    call    img.initialize.jpeg
71
    call    img.initialize.jpeg
72
 
72
 
73
    xor eax, eax
73
    xor eax, eax
74
    cpuid
74
    cpuid
75
    cmp ecx, 'ntel'
75
    cmp ecx, 'ntel'
76
    jnz @f
76
    jnz @f
77
    mov dword [img._.do_rgb.handlers + (Image.bpp15-1)*4], img._.do_rgb.bpp15.intel
77
    mov dword [img._.do_rgb.handlers + (Image.bpp15-1)*4], img._.do_rgb.bpp15.intel
78
    mov dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
78
    mov dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
79
  @@:
79
  @@:
80
 
80
 
81
  .ok:  xor eax,eax
81
  .ok:  xor eax,eax
82
    ret
82
    ret
83
endp
83
endp
84
 
84
 
85
;;================================================================================================;;
85
;;================================================================================================;;
86
proc img.is_img _data, _length ;//////////////////////////////////////////////////////////////////;;
86
proc img.is_img _data, _length ;//////////////////////////////////////////////////////////////////;;
87
;;------------------------------------------------------------------------------------------------;;
87
;;------------------------------------------------------------------------------------------------;;
88
;? --- TBD ---                                                                                    ;;
88
;? --- TBD ---                                                                                    ;;
89
;;------------------------------------------------------------------------------------------------;;
89
;;------------------------------------------------------------------------------------------------;;
90
;> --- TBD ---                                                                                    ;;
90
;> --- TBD ---                                                                                    ;;
91
;;------------------------------------------------------------------------------------------------;;
91
;;------------------------------------------------------------------------------------------------;;
92
;< --- TBD ---                                                                                    ;;
92
;< --- TBD ---                                                                                    ;;
93
;;================================================================================================;;
93
;;================================================================================================;;
94
    push    ebx
94
    push    ebx
95
    mov ebx, img.formats_table
95
    mov ebx, img.formats_table
96
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
96
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
97
    or  eax, eax
97
    or  eax, eax
98
    jnz @f
98
    jnz @f
99
    add ebx, sizeof.FormatsTableEntry
99
    add ebx, sizeof.FormatsTableEntry
100
    cmp dword[ebx], 0
100
    cmp dword[ebx], 0
101
    jnz @b
101
    jnz @b
102
    xor eax, eax
102
    xor eax, eax
103
    @@: pop ebx
103
    @@: pop ebx
104
    ret
104
    ret
105
endp
105
endp
106
 
106
 
107
;;================================================================================================;;
107
;;================================================================================================;;
108
proc img.info _data, _length ;////////////////////////////////////////////////////////////////////;;
108
proc img.info _data, _length ;////////////////////////////////////////////////////////////////////;;
109
;;------------------------------------------------------------------------------------------------;;
109
;;------------------------------------------------------------------------------------------------;;
110
;? --- TBD ---                                                                                    ;;
110
;? --- TBD ---                                                                                    ;;
111
;;------------------------------------------------------------------------------------------------;;
111
;;------------------------------------------------------------------------------------------------;;
112
;> --- TBD ---                                                                                    ;;
112
;> --- TBD ---                                                                                    ;;
113
;;------------------------------------------------------------------------------------------------;;
113
;;------------------------------------------------------------------------------------------------;;
114
;< --- TBD ---                                                                                    ;;
114
;< --- TBD ---                                                                                    ;;
115
;;================================================================================================;;
115
;;================================================================================================;;
116
    xor eax, eax
116
    xor eax, eax
117
    ret
117
    ret
118
endp
118
endp
119
 
119
 
120
;;================================================================================================;;
120
;;================================================================================================;;
121
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
121
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
122
;;------------------------------------------------------------------------------------------------;;
122
;;------------------------------------------------------------------------------------------------;;
123
;? --- TBD ---                                                                                    ;;
123
;? --- TBD ---                                                                                    ;;
124
;;------------------------------------------------------------------------------------------------;;
124
;;------------------------------------------------------------------------------------------------;;
125
;> --- TBD ---                                                                                    ;;
125
;> --- TBD ---                                                                                    ;;
126
;;------------------------------------------------------------------------------------------------;;
126
;;------------------------------------------------------------------------------------------------;;
127
;< eax = 0 / pointer to image                                                                     ;;
127
;< eax = 0 / pointer to image                                                                     ;;
128
;;================================================================================================;;
128
;;================================================================================================;;
129
    xor eax, eax
129
    xor eax, eax
130
    ret
130
    ret
131
endp
131
endp
132
 
132
 
133
;;================================================================================================;;
133
;;================================================================================================;;
134
proc img.to_file _img, _filename ;////////////////////////////////////////////////////////////////;;
134
proc img.to_file _img, _filename ;////////////////////////////////////////////////////////////////;;
135
;;------------------------------------------------------------------------------------------------;;
135
;;------------------------------------------------------------------------------------------------;;
136
;? --- TBD ---                                                                                    ;;
136
;? --- TBD ---                                                                                    ;;
137
;;------------------------------------------------------------------------------------------------;;
137
;;------------------------------------------------------------------------------------------------;;
138
;> --- TBD ---                                                                                    ;;
138
;> --- TBD ---                                                                                    ;;
139
;;------------------------------------------------------------------------------------------------;;
139
;;------------------------------------------------------------------------------------------------;;
140
;< eax = false / true                                                                             ;;
140
;< eax = false / true                                                                             ;;
141
;;================================================================================================;;
141
;;================================================================================================;;
142
    xor eax, eax
142
    xor eax, eax
143
    ret
143
    ret
144
endp
144
endp
145
 
145
 
146
;;================================================================================================;;
146
;;================================================================================================;;
147
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////////////////////////;;
147
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////////////////////////;;
148
;;------------------------------------------------------------------------------------------------;;
148
;;------------------------------------------------------------------------------------------------;;
149
;? --- TBD ---                                                                                    ;;
149
;? --- TBD ---                                                                                    ;;
150
;;------------------------------------------------------------------------------------------------;;
150
;;------------------------------------------------------------------------------------------------;;
151
;> --- TBD ---                                                                                    ;;
151
;> --- TBD ---                                                                                    ;;
152
;;------------------------------------------------------------------------------------------------;;
152
;;------------------------------------------------------------------------------------------------;;
153
;< eax = 0 / pointer to image                                                                     ;;
153
;< eax = 0 / pointer to image                                                                     ;;
154
;;================================================================================================;;
154
;;================================================================================================;;
155
    xor eax, eax
155
    xor eax, eax
156
    ret
156
    ret
157
endp
157
endp
158
 
158
 
159
;;================================================================================================;;
159
;;================================================================================================;;
160
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
160
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
161
;;------------------------------------------------------------------------------------------------;;
161
;;------------------------------------------------------------------------------------------------;;
162
;? decodes image data into RGB triplets and stores them where [_out] points to                    ;;
162
;? decodes image data into RGB triplets and stores them where [_out] points to                    ;;
163
;;------------------------------------------------------------------------------------------------;;
163
;;------------------------------------------------------------------------------------------------;;
164
;> [_img] = pointer to source image                                                               ;;
164
;> [_img] = pointer to source image                                                               ;;
165
;> [_out] = where to store RGB triplets                                                           ;;
165
;> [_out] = where to store RGB triplets                                                           ;;
166
;;------------------------------------------------------------------------------------------------;;
166
;;------------------------------------------------------------------------------------------------;;
167
;< none                                                                                           ;;
167
;< none                                                                                           ;;
168
;;================================================================================================;;
168
;;================================================================================================;;
169
    push    esi edi
169
    push    esi edi
170
    mov esi, [_img]
170
    mov esi, [_img]
171
    stdcall img._.validate, esi
171
    stdcall img._.validate, esi
172
    or  eax, eax
172
    or  eax, eax
173
    jnz .ret
173
    jnz .ret
174
    mov edi, [_out]
174
    mov edi, [_out]
175
    call    img._.do_rgb
175
    call    img._.do_rgb
176
.ret:
176
.ret:
177
    pop edi esi
177
    pop edi esi
178
    ret
178
    ret
179
endp
179
endp
180
 
180
 
181
;;================================================================================================;;
181
;;================================================================================================;;
182
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
182
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
183
;;------------------------------------------------------------------------------------------------;;
183
;;------------------------------------------------------------------------------------------------;;
184
;? decodes image data into RGB triplets and returns pointer to memory area containing them        ;;
184
;? decodes image data into RGB triplets and returns pointer to memory area containing them        ;;
185
;;------------------------------------------------------------------------------------------------;;
185
;;------------------------------------------------------------------------------------------------;;
186
;> [_img] = pointer to source image                                                               ;;
186
;> [_img] = pointer to source image                                                               ;;
187
;;------------------------------------------------------------------------------------------------;;
187
;;------------------------------------------------------------------------------------------------;;
188
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets)                                        ;;
188
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets)                                        ;;
189
;;================================================================================================;;
189
;;================================================================================================;;
190
    push    esi edi
190
    push    esi edi
191
    mov esi, [_img]
191
    mov esi, [_img]
192
    stdcall img._.validate, esi
192
    stdcall img._.validate, esi
193
    or  eax, eax
193
    or  eax, eax
194
    jnz .error
194
    jnz .error
195
 
195
 
196
    mov esi, [_img]
196
    mov esi, [_img]
197
    mov ecx, [esi + Image.Width]
197
    mov ecx, [esi + Image.Width]
198
    imul    ecx, [esi + Image.Height]
198
    imul    ecx, [esi + Image.Height]
199
    lea eax, [ecx * 3 + 4 * 3]
199
    lea eax, [ecx * 3 + 4 * 3]
200
    invoke  mem.alloc, eax
200
    invoke  mem.alloc, eax
201
    or  eax, eax
201
    or  eax, eax
202
    jz  .error
202
    jz  .error
203
 
203
 
204
    mov edi, eax
204
    mov edi, eax
205
    push    eax
205
    push    eax
206
    mov eax, [esi + Image.Width]
206
    mov eax, [esi + Image.Width]
207
    stosd
207
    stosd
208
    mov eax, [esi + Image.Height]
208
    mov eax, [esi + Image.Height]
209
    stosd
209
    stosd
210
    call    img._.do_rgb
210
    call    img._.do_rgb
211
    pop eax
211
    pop eax
212
    pop edi esi
212
    pop edi esi
213
    ret
213
    ret
214
 
214
 
215
  .error:
215
  .error:
216
    xor eax, eax
216
    xor eax, eax
217
    pop edi esi
217
    pop edi esi
218
    ret
218
    ret
219
endp
219
endp
220
 
220
 
221
;;================================================================================================;;
221
;;================================================================================================;;
222
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
222
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
223
;;------------------------------------------------------------------------------------------------;;
223
;;------------------------------------------------------------------------------------------------;;
224
;? decodes [esi + Image.Data] data into RGB triplets and stores them at [edi]                     ;;
224
;? decodes [esi + Image.Data] data into RGB triplets and stores them at [edi]                     ;;
225
;;------------------------------------------------------------------------------------------------;;
225
;;------------------------------------------------------------------------------------------------;;
226
;> esi = pointer to source image                                                                  ;;
226
;> esi = pointer to source image                                                                  ;;
227
;> edi = pointer to memory to store RGB triplets                                                  ;;
227
;> edi = pointer to memory to store RGB triplets                                                  ;;
228
;;------------------------------------------------------------------------------------------------;;
228
;;------------------------------------------------------------------------------------------------;;
229
;< none                                                                                           ;;
229
;< none                                                                                           ;;
230
;;================================================================================================;;
230
;;================================================================================================;;
231
    mov ecx, [esi + Image.Width]
231
    mov ecx, [esi + Image.Width]
232
    imul    ecx, [esi + Image.Height]
232
    imul    ecx, [esi + Image.Height]
233
    mov eax, [esi + Image.Type]
233
    mov eax, [esi + Image.Type]
234
    jmp dword [.handlers + (eax-1)*4]
234
    jmp dword [.handlers + (eax-1)*4]
235
 
235
 
236
align 16
236
align 16
237
.bpp8i:
237
.bpp8i:
238
; 8 BPP WITH PALETTE -> 24 BPP
238
; 8 BPP WITH PALETTE -> 24 BPP
239
    push    ebx
239
    push    ebx
240
    mov ebx, [esi + Image.Palette]
240
    mov ebx, [esi + Image.Palette]
241
    mov esi, [esi + Image.Data]
241
    mov esi, [esi + Image.Data]
242
    sub ecx, 1
242
    sub ecx, 1
243
    jz  .bpp8i.last
243
    jz  .bpp8i.last
244
@@:
244
@@:
245
    movzx   eax, byte [esi]
245
    movzx   eax, byte [esi]
246
    add esi, 1
246
    add esi, 1
247
    mov eax, [ebx + eax*4]
247
    mov eax, [ebx + eax*4]
248
    mov [edi], eax
248
    mov [edi], eax
249
    add edi, 3
249
    add edi, 3
250
    sub ecx, 1
250
    sub ecx, 1
251
    jnz @b
251
    jnz @b
252
.bpp8i.last:
252
.bpp8i.last:
253
    movzx   eax, byte [esi]
253
    movzx   eax, byte [esi]
254
    mov eax, [ebx + eax*4]
254
    mov eax, [ebx + eax*4]
255
    mov [edi], ax
255
    mov [edi], ax
256
    shr eax, 16
256
    shr eax, 16
257
    mov [edi+2], al
257
    mov [edi+2], al
258
    pop ebx
258
    pop ebx
259
    ret
259
    ret
260
 
260
 
261
align 16
261
align 16
262
.bpp8g:
262
.bpp8g:
263
; 8 BPP GRAYSCALE -> 24 BPP
263
; 8 BPP GRAYSCALE -> 24 BPP
264
    mov esi, [esi + Image.Data]
264
    mov esi, [esi + Image.Data]
265
@@:
265
@@:
266
    lodsb
266
    lodsb
267
    mov ah, al
267
    mov ah, al
268
    stosb
268
    stosb
269
    stosw
269
    stosw
270
    dec ecx
270
    dec ecx
271
    jnz @b
271
    jnz @b
272
    ret
272
    ret
273
;
273
;
274
;align 16
274
;align 16
275
;.bpp8a: ; considered application layer, may be changed in the future
275
;.bpp8a: ; considered application layer, may be changed in the future
276
;; 8a BPP -> 24 BPP
276
;; 8a BPP -> 24 BPP
277
;    mov esi, [esi + Image.Data]
277
;    mov esi, [esi + Image.Data]
278
;@@:
278
;@@:
279
;    lodsw
279
;    lodsw
280
;    mov ah, al
280
;    mov ah, al
281
;    stosb
281
;    stosb
282
;    stosw
282
;    stosw
283
;    dec ecx
283
;    dec ecx
284
;    jnz @b
284
;    jnz @b
285
;    ret
285
;    ret
286
 
286
 
287
; 15 BPP -> 24 BPP
287
; 15 BPP -> 24 BPP
288
.bpp15.intel:
288
.bpp15.intel:
289
    push    ebx ebp
289
    push    ebx ebp
290
    sub ecx, 4
290
    sub ecx, 4
291
    jb  .bpp15.tail
291
    jb  .bpp15.tail
292
align 16
292
align 16
293
.bpp15.intel.loop:
293
.bpp15.intel.loop:
294
repeat 2
294
repeat 2
295
    mov ebx, [esi]
295
    mov ebx, [esi]
296
    mov al, [esi]
296
    mov al, [esi]
297
    mov ah, [esi+1]
297
    mov ah, [esi+1]
298
    add esi, 4
298
    add esi, 4
299
    and al, 0x1F
299
    and al, 0x1F
300
    and ah, 0x1F shl 2
300
    and ah, 0x1F shl 2
301
    mov ebp, ebx
301
    mov ebp, ebx
302
    mov dl, al
302
    mov dl, al
303
    mov dh, ah
303
    mov dh, ah
304
    shr al, 2
304
    shr al, 2
305
    shr ah, 4
305
    shr ah, 4
306
    shl dl, 3
306
    shl dl, 3
307
    shl dh, 1
307
    shl dh, 1
308
    and ebp, 0x1F shl 5
308
    and ebp, 0x1F shl 5
309
    add al, dl
309
    add al, dl
310
    add ah, dh
310
    add ah, dh
311
    shr ebp, 2
311
    shr ebp, 2
312
    mov [edi], al
312
    mov [edi], al
313
    mov [edi+2], ah
313
    mov [edi+2], ah
314
    mov eax, ebx
314
    mov eax, ebx
315
    mov ebx, ebp
315
    mov ebx, ebp
316
    shr eax, 16
316
    shr eax, 16
317
    shr ebx, 5
317
    shr ebx, 5
318
    add ebx, ebp
318
    add ebx, ebp
319
    mov ebp, eax
319
    mov ebp, eax
320
    mov [edi+1], bl
320
    mov [edi+1], bl
321
    and eax, (0x1F) or (0x1F shl 10)
321
    and eax, (0x1F) or (0x1F shl 10)
322
    and ebp, 0x1F shl 5
322
    and ebp, 0x1F shl 5
323
    lea edx, [eax+eax]
323
    lea edx, [eax+eax]
324
    shr al, 2
324
    shr al, 2
325
    mov ebx, ebp
325
    mov ebx, ebp
326
    shr ah, 4
326
    shr ah, 4
327
    shl dl, 2
327
    shl dl, 2
328
    shr ebx, 2
328
    shr ebx, 2
329
    shr ebp, 7
329
    shr ebp, 7
330
    add al, dl
330
    add al, dl
331
    add ah, dh
331
    add ah, dh
332
    mov [edi+3], al
332
    mov [edi+3], al
333
    add ebx, ebp
333
    add ebx, ebp
334
    mov [edi+5], ah
334
    mov [edi+5], ah
335
    mov [edi+4], bl
335
    mov [edi+4], bl
336
    add edi, 6
336
    add edi, 6
337
end repeat
337
end repeat
338
    sub ecx, 4
338
    sub ecx, 4
339
    jnb .bpp15.intel.loop
339
    jnb .bpp15.intel.loop
340
.bpp15.tail:
340
.bpp15.tail:
341
    add ecx, 4
341
    add ecx, 4
342
    jz  .bpp15.done
342
    jz  .bpp15.done
343
@@:
343
@@:
344
    movzx   eax, word [esi]
344
    movzx   eax, word [esi]
345
    mov ebx, eax
345
    mov ebx, eax
346
    add esi, 2
346
    add esi, 2
347
    and eax, (0x1F) or (0x1F shl 10)
347
    and eax, (0x1F) or (0x1F shl 10)
348
    and ebx, 0x1F shl 5
348
    and ebx, 0x1F shl 5
349
    lea edx, [eax+eax]
349
    lea edx, [eax+eax]
350
    shr al, 2
350
    shr al, 2
351
    mov ebp, ebx
351
    mov ebp, ebx
352
    shr ebx, 2
352
    shr ebx, 2
353
    shr ah, 4
353
    shr ah, 4
354
    shl dl, 2
354
    shl dl, 2
355
    shr ebp, 7
355
    shr ebp, 7
356
    add eax, edx
356
    add eax, edx
357
    add ebx, ebp
357
    add ebx, ebp
358
    mov [edi], al
358
    mov [edi], al
359
    mov [edi+1], bl
359
    mov [edi+1], bl
360
    mov [edi+2], ah
360
    mov [edi+2], ah
361
    add edi, 3
361
    add edi, 3
362
    sub ecx, 1
362
    sub ecx, 1
363
    jnz @b
363
    jnz @b
364
.bpp15.done:
364
.bpp15.done:
365
    pop ebp ebx
365
    pop ebp ebx
366
    ret
366
    ret
367
 
367
 
368
.bpp15.amd:
368
.bpp15.amd:
369
    push    ebx ebp
369
    push    ebx ebp
370
    sub ecx, 4
370
    sub ecx, 4
371
    jb  .bpp15.tail
371
    jb  .bpp15.tail
372
align 16
372
align 16
373
.bpp15.amd.loop:
373
.bpp15.amd.loop:
374
repeat 4
374
repeat 4
375
if (% mod 2) = 1
375
if (% mod 2) = 1
376
    mov eax, dword [esi]
376
    mov eax, dword [esi]
377
    mov ebx, dword [esi]
377
    mov ebx, dword [esi]
378
else
378
else
379
    movzx   eax, word [esi]
379
    movzx   eax, word [esi]
380
    mov ebx, eax
380
    mov ebx, eax
381
end if
381
end if
382
    add esi, 2
382
    add esi, 2
383
    and eax, (0x1F) or (0x1F shl 10)
383
    and eax, (0x1F) or (0x1F shl 10)
384
    and ebx, 0x1F shl 5
384
    and ebx, 0x1F shl 5
385
    lea edx, [eax+eax]
385
    lea edx, [eax+eax]
386
    shr al, 2
386
    shr al, 2
387
    mov ebp, ebx
387
    mov ebp, ebx
388
    shr ebx, 2
388
    shr ebx, 2
389
    shr ah, 4
389
    shr ah, 4
390
    shl dl, 2
390
    shl dl, 2
391
    shr ebp, 7
391
    shr ebp, 7
392
    add eax, edx
392
    add eax, edx
393
    add ebx, ebp
393
    add ebx, ebp
394
    mov [edi], al
394
    mov [edi], al
395
    mov [edi+1], bl
395
    mov [edi+1], bl
396
    mov [edi+2], ah
396
    mov [edi+2], ah
397
    add edi, 3
397
    add edi, 3
398
end repeat
398
end repeat
399
    sub ecx, 4
399
    sub ecx, 4
400
    jnb .bpp15.amd.loop
400
    jnb .bpp15.amd.loop
401
    jmp .bpp15.tail
401
    jmp .bpp15.tail
402
 
402
 
403
; 16 BPP -> 24 BPP
403
; 16 BPP -> 24 BPP
404
.bpp16.intel:
404
.bpp16.intel:
405
    push    ebx ebp
405
    push    ebx ebp
406
    sub ecx, 4
406
    sub ecx, 4
407
    jb  .bpp16.tail
407
    jb  .bpp16.tail
408
align 16
408
align 16
409
.bpp16.intel.loop:
409
.bpp16.intel.loop:
410
repeat 2
410
repeat 2
411
    mov ebx, [esi]
411
    mov ebx, [esi]
412
    mov al, [esi]
412
    mov al, [esi]
413
    mov ah, [esi+1]
413
    mov ah, [esi+1]
414
    add esi, 4
414
    add esi, 4
415
    and al, 0x1F
415
    and al, 0x1F
416
    and ah, 0x1F shl 3
416
    and ah, 0x1F shl 3
417
    mov ebp, ebx
417
    mov ebp, ebx
418
    mov dl, al
418
    mov dl, al
419
    mov dh, ah
419
    mov dh, ah
420
    shr al, 2
420
    shr al, 2
421
    shr ah, 5
421
    shr ah, 5
422
    shl dl, 3
422
    shl dl, 3
423
    and ebp, 0x3F shl 5
423
    and ebp, 0x3F shl 5
424
    add al, dl
424
    add al, dl
425
    add ah, dh
425
    add ah, dh
426
    shr ebp, 3
426
    shr ebp, 3
427
    mov [edi], al
427
    mov [edi], al
428
    mov [edi+2], ah
428
    mov [edi+2], ah
429
    mov eax, ebx
429
    mov eax, ebx
430
    mov ebx, ebp
430
    mov ebx, ebp
431
    shr eax, 16
431
    shr eax, 16
432
    shr ebx, 6
432
    shr ebx, 6
433
    add ebx, ebp
433
    add ebx, ebp
434
    mov ebp, eax
434
    mov ebp, eax
435
    mov [edi+1], bl
435
    mov [edi+1], bl
436
    and eax, (0x1F) or (0x1F shl 11)
436
    and eax, (0x1F) or (0x1F shl 11)
437
    and ebp, 0x3F shl 5
437
    and ebp, 0x3F shl 5
438
    mov edx, eax
438
    mov edx, eax
439
    shr al, 2
439
    shr al, 2
440
    mov ebx, ebp
440
    mov ebx, ebp
441
    shr ah, 5
441
    shr ah, 5
442
    shl dl, 3
442
    shl dl, 3
443
    shr ebx, 3
443
    shr ebx, 3
444
    shr ebp, 9
444
    shr ebp, 9
445
    add al, dl
445
    add al, dl
446
    add ah, dh
446
    add ah, dh
447
    mov [edi+3], al
447
    mov [edi+3], al
448
    add ebx, ebp
448
    add ebx, ebp
449
    mov [edi+5], ah
449
    mov [edi+5], ah
450
    mov [edi+4], bl
450
    mov [edi+4], bl
451
    add edi, 6
451
    add edi, 6
452
end repeat
452
end repeat
453
    sub ecx, 4
453
    sub ecx, 4
454
    jnb .bpp16.intel.loop
454
    jnb .bpp16.intel.loop
455
.bpp16.tail:
455
.bpp16.tail:
456
    add ecx, 4
456
    add ecx, 4
457
    jz  .bpp16.done
457
    jz  .bpp16.done
458
@@:
458
@@:
459
    movzx   eax, word [esi]
459
    movzx   eax, word [esi]
460
    mov ebx, eax
460
    mov ebx, eax
461
    add esi, 2
461
    add esi, 2
462
    and eax, (0x1F) or (0x1F shl 11)
462
    and eax, (0x1F) or (0x1F shl 11)
463
    and ebx, 0x3F shl 5
463
    and ebx, 0x3F shl 5
464
    mov edx, eax
464
    mov edx, eax
465
    shr al, 2
465
    shr al, 2
466
    mov ebp, ebx
466
    mov ebp, ebx
467
    shr ebx, 3
467
    shr ebx, 3
468
    shr ah, 5
468
    shr ah, 5
469
    shl dl, 3
469
    shl dl, 3
470
    shr ebp, 9
470
    shr ebp, 9
471
    add eax, edx
471
    add eax, edx
472
    add ebx, ebp
472
    add ebx, ebp
473
    mov [edi], al
473
    mov [edi], al
474
    mov [edi+1], bl
474
    mov [edi+1], bl
475
    mov [edi+2], ah
475
    mov [edi+2], ah
476
    add edi, 3
476
    add edi, 3
477
    sub ecx, 1
477
    sub ecx, 1
478
    jnz @b
478
    jnz @b
479
.bpp16.done:
479
.bpp16.done:
480
    pop ebp ebx
480
    pop ebp ebx
481
    ret
481
    ret
482
 
482
 
483
.bpp16.amd:
483
.bpp16.amd:
484
    push    ebx ebp
484
    push    ebx ebp
485
    sub ecx, 4
485
    sub ecx, 4
486
    jb  .bpp16.tail
486
    jb  .bpp16.tail
487
align 16
487
align 16
488
.bpp16.amd.loop:
488
.bpp16.amd.loop:
489
repeat 4
489
repeat 4
490
if (% mod 2) = 1
490
if (% mod 2) = 1
491
    mov eax, dword [esi]
491
    mov eax, dword [esi]
492
    mov ebx, dword [esi]
492
    mov ebx, dword [esi]
493
else
493
else
494
    movzx   eax, word [esi]
494
    movzx   eax, word [esi]
495
    mov ebx, eax
495
    mov ebx, eax
496
end if
496
end if
497
    add esi, 2
497
    add esi, 2
498
    and eax, (0x1F) or (0x1F shl 11)
498
    and eax, (0x1F) or (0x1F shl 11)
499
    and ebx, 0x3F shl 5
499
    and ebx, 0x3F shl 5
500
    mov edx, eax
500
    mov edx, eax
501
    shr al, 2
501
    shr al, 2
502
    mov ebp, ebx
502
    mov ebp, ebx
503
    shr ebx, 3
503
    shr ebx, 3
504
    shr ah, 5
504
    shr ah, 5
505
    shl dl, 3
505
    shl dl, 3
506
    shr ebp, 9
506
    shr ebp, 9
507
    add eax, edx
507
    add eax, edx
508
    add ebx, ebp
508
    add ebx, ebp
509
    mov [edi], al
509
    mov [edi], al
510
    mov [edi+1], bl
510
    mov [edi+1], bl
511
    mov [edi+2], ah
511
    mov [edi+2], ah
512
    add edi, 3
512
    add edi, 3
513
end repeat
513
end repeat
514
    sub ecx, 4
514
    sub ecx, 4
515
    jnb .bpp16.amd.loop
515
    jnb .bpp16.amd.loop
516
    jmp .bpp16.tail
516
    jmp .bpp16.tail
517
 
517
 
518
align 16
518
align 16
519
.bpp24:
519
.bpp24:
520
; 24 BPP -> 24 BPP
520
; 24 BPP -> 24 BPP
521
    lea ecx, [ecx*3 + 3]
521
    lea ecx, [ecx*3 + 3]
522
    mov esi, [esi + Image.Data]
522
    mov esi, [esi + Image.Data]
523
    shr ecx, 2
523
    shr ecx, 2
524
    rep movsd
524
    rep movsd
525
    ret
525
    ret
526
 
526
 
527
align 16
527
align 16
528
.bpp32:
528
.bpp32:
529
; 32 BPP -> 24 BPP
529
; 32 BPP -> 24 BPP
530
    mov esi, [esi + Image.Data]
530
    mov esi, [esi + Image.Data]
531
 
531
 
532
    @@:
532
    @@:
533
    mov eax, [esi]
533
    mov eax, [esi]
534
    mov [edi], ax
534
    mov [edi], ax
535
    shr eax, 16
535
    shr eax, 16
536
    mov [edi+2], al
536
    mov [edi+2], al
537
    add esi, 4
537
    add esi, 4
538
    add edi, 3
538
    add edi, 3
539
    sub ecx, 1
539
    sub ecx, 1
540
    jnz @b
540
    jnz @b
541
 
541
 
542
    @@:
542
    @@:
543
    ret
543
    ret
544
 
544
 
545
align 16
545
align 16
546
.bpp1:
546
.bpp1:
547
    push ebx edx
547
    push ebx ebp
-
 
548
    mov ebp, [esi + Image.Width]
-
 
549
    mov edx, [esi + Image.Height]
548
    mov ebx, esi
550
    shl edx, 16
549
    mov esi, [ebx + Image.Data]
551
    mov ebx, [esi + Image.Palette]
550
    mov ecx, [ebx + Image.Height]
552
    mov esi, [esi + Image.Data]
551
  .bpp1.pre:
553
  .bpp1.pre:
552
    mov edx, [ebx + Image.Width]
554
    mov dx, bp
553
    mov eax, 7
555
    mov ecx, 7
554
  .bpp1.begin:
556
  .bpp1.begin:
555
    push ecx esi
-
 
556
    xor cx, cx
557
    xor eax, eax
557
    bt [esi], eax
558
    bt  [esi], ecx
558
    setc cl
559
    adc eax, 0
559
    mov esi, [ebx + Image.Palette]
560
    mov eax, [ebx + eax*4]
560
     jcxz @f
561
    mov [edi], ax
561
    add esi, 4
562
    shr eax, 16
562
  @@:
-
 
563
    mov ecx, 3
563
    mov [edi + 2], al
564
    cld
-
 
565
    rep movsb
-
 
566
    pop esi ecx
564
    add edi, 3
567
    dec edx
565
    dec dx
568
     jz .bpp1.end_line
566
    jz .bpp1.end_line
569
    dec eax
567
    dec ecx
570
     jns .bpp1.begin
568
    jns .bpp1.begin
571
    mov eax, 7
569
    mov ecx, 7
572
    inc esi
570
    inc esi
573
     jmp .bpp1.begin
571
    jmp .bpp1.begin
574
 
-
 
575
  .bpp1.end_line:
572
  .bpp1.end_line:
576
    dec ecx
573
    sub edx, 0x10000
577
     jz .bpp1.quit
574
    jz .bpp1.quit
578
    inc esi
575
    inc esi
579
     jmp .bpp1.pre
576
    jmp .bpp1.pre
580
 
-
 
581
  .bpp1.quit:
577
  .bpp1.quit:
-
 
578
    pop ebp ebx
-
 
579
    ret
-
 
580
 
-
 
581
align 16
-
 
582
.bpp2i:
-
 
583
    push ebx ebp
-
 
584
    mov ebp, [esi + Image.Width]
-
 
585
    mov edx, [esi + Image.Height]
-
 
586
    shl edx, 16
-
 
587
    mov ebx, [esi + Image.Palette]
-
 
588
    mov esi, [esi + Image.Data]
-
 
589
  .bpp2i.pre:
-
 
590
    mov dx, bp
-
 
591
    mov ecx, 3
-
 
592
  .bpp2i.begin:
-
 
593
    mov eax, 3
-
 
594
    shl ecx, 1
-
 
595
    shl eax, cl
-
 
596
    and al, [esi]
-
 
597
    shr eax, cl
-
 
598
    shr ecx, 1
-
 
599
    mov eax, [ebx + eax*4]
-
 
600
    mov [edi], ax
-
 
601
    shr eax, 16
-
 
602
    mov [edi + 2], al
-
 
603
    add edi, 3
-
 
604
    dec dx
-
 
605
    jz .bpp2i.end_line
-
 
606
    dec ecx
-
 
607
    jns .bpp2i.begin
-
 
608
    mov ecx, 3
-
 
609
    inc esi
-
 
610
    jmp .bpp2i.begin
-
 
611
  .bpp2i.end_line:
-
 
612
    sub edx, 0x10000
-
 
613
    jz .bpp2i.quit
-
 
614
    inc esi
-
 
615
    jmp .bpp2i.pre
-
 
616
  .bpp2i.quit:
-
 
617
    pop ebp ebx
-
 
618
    ret
-
 
619
 
-
 
620
align 16
-
 
621
.bpp4i:
-
 
622
    push ebx ebp
-
 
623
    mov ebp, [esi + Image.Width]
-
 
624
    mov edx, [esi + Image.Height]
-
 
625
    shl edx, 16
-
 
626
    mov ebx, [esi + Image.Palette]
-
 
627
    mov esi, [esi + Image.Data]
-
 
628
  .bpp4i.pre:
-
 
629
    mov dx, bp
-
 
630
    mov ecx, 1
-
 
631
  .bpp4i.begin:
-
 
632
    mov eax, 15
-
 
633
    shl ecx, 2
-
 
634
    shl eax, cl
-
 
635
    and al, [esi]
-
 
636
    shr eax, cl
-
 
637
    shr ecx, 2
-
 
638
    mov eax, [ebx + eax*4]
-
 
639
    mov [edi], ax
-
 
640
    shr eax, 16
-
 
641
    mov [edi + 2], al
-
 
642
    add edi, 3
-
 
643
    dec dx
-
 
644
    jz .bpp4i.end_line
-
 
645
    dec ecx
-
 
646
    jns .bpp4i.begin
-
 
647
    mov ecx, 1
-
 
648
    inc esi
-
 
649
    jmp .bpp4i.begin
-
 
650
  .bpp4i.end_line:
-
 
651
    sub edx, 0x10000
-
 
652
    jz .bpp4i.quit
-
 
653
    inc esi
-
 
654
    jmp .bpp4i.pre
-
 
655
  .bpp4i.quit:
582
    pop edx ebx
656
    pop ebp ebx
583
    ret
657
    ret
584
 
658
 
585
endp
659
endp
586
 
660
 
587
;;================================================================================================;;
661
;;================================================================================================;;
588
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
662
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
589
;;------------------------------------------------------------------------------------------------;;
663
;;------------------------------------------------------------------------------------------------;;
590
;? decodes loaded into memory graphic file                                                        ;;
664
;? decodes loaded into memory graphic file                                                        ;;
591
;;------------------------------------------------------------------------------------------------;;
665
;;------------------------------------------------------------------------------------------------;;
592
;> [_data]    = pointer to file in memory                                                         ;;
666
;> [_data]    = pointer to file in memory                                                         ;;
593
;> [_length]  = size in bytes of memory area pointed to by [_data]                                ;;
667
;> [_length]  = size in bytes of memory area pointed to by [_data]                                ;;
594
;> [_options] = 0 / pointer to the structure of additional options                                ;;
668
;> [_options] = 0 / pointer to the structure of additional options                                ;;
595
;;------------------------------------------------------------------------------------------------;;
669
;;------------------------------------------------------------------------------------------------;;
596
;< eax = 0 / pointer to image                                                                     ;;
670
;< eax = 0 / pointer to image                                                                     ;;
597
;;================================================================================================;;
671
;;================================================================================================;;
598
    push    ebx
672
    push    ebx
599
    mov ebx, img.formats_table
673
    mov ebx, img.formats_table
600
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
674
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
601
    or  eax, eax
675
    or  eax, eax
602
    jnz @f
676
    jnz @f
603
    add ebx, sizeof.FormatsTableEntry
677
    add ebx, sizeof.FormatsTableEntry
604
    cmp dword[ebx], eax ;0
678
    cmp dword[ebx], eax ;0
605
    jnz @b
679
    jnz @b
606
    pop ebx
680
    pop ebx
607
    ret
681
    ret
608
    @@: mov eax, [ebx + FormatsTableEntry.Decode]
682
    @@: mov eax, [ebx + FormatsTableEntry.Decode]
609
    pop ebx
683
    pop ebx
610
    leave
684
    leave
611
    jmp eax
685
    jmp eax
612
endp
686
endp
613
 
687
 
614
;;================================================================================================;;
688
;;================================================================================================;;
615
proc img.encode _img, _common, _specific ;////////////////////////////////////////////////////////;;
689
proc img.encode _img, _common, _specific ;////////////////////////////////////////////////////////;;
616
;;------------------------------------------------------------------------------------------------;;
690
;;------------------------------------------------------------------------------------------------;;
617
;? encode image to some format                                                                    ;;
691
;? encode image to some format                                                                    ;;
618
;;------------------------------------------------------------------------------------------------;;
692
;;------------------------------------------------------------------------------------------------;;
619
;> [_img]      = pointer to input image                                                           ;;
693
;> [_img]      = pointer to input image                                                           ;;
620
;> [_common]   = some most important options                                                      ;;
694
;> [_common]   = some most important options                                                      ;;
621
;     0x00 :  byte : format id (defined in libimg.inc)                                            ;;
695
;     0x00 :  byte : format id (defined in libimg.inc)                                            ;;
622
;     0x01 :  byte : fast encoding (0) / best compression ratio (255)                             ;;
696
;     0x01 :  byte : fast encoding (0) / best compression ratio (255)                             ;;
623
;                    0 : store uncompressed data (if supported both by the format and libimg)     ;;
697
;                    0 : store uncompressed data (if supported both by the format and libimg)     ;;
624
;                    1 - 255 : use compression, if supported                                      ;;
698
;                    1 - 255 : use compression, if supported                                      ;;
625
;                    this option may be ignored if any format specific options are defined        ;;
699
;                    this option may be ignored if any format specific options are defined        ;;
626
;                    i.e. the 0 here will be ignored if some compression algorithm is specified   ;;
700
;                    i.e. the 0 here will be ignored if some compression algorithm is specified   ;;
627
;     0x02 :  byte : flags (bitfield)                                                             ;;
701
;     0x02 :  byte : flags (bitfield)                                                             ;;
628
;                   0x01 : return an error if format specific conditions cannot be met            ;;
702
;                   0x01 : return an error if format specific conditions cannot be met            ;;
629
;                   0x02 : preserve current bit depth. means 8bpp/16bpp/24bpp and so on           ;;
703
;                   0x02 : preserve current bit depth. means 8bpp/16bpp/24bpp and so on           ;;
630
;                   0x04 : delete alpha channel, if any                                           ;;
704
;                   0x04 : delete alpha channel, if any                                           ;;
631
;                   0x08 : flush alpha channel with 0xff, if any; add it if none                  ;;
705
;                   0x08 : flush alpha channel with 0xff, if any; add it if none                  ;;
632
;     0x03 :  byte : reserved, must be 0                                                          ;;
706
;     0x03 :  byte : reserved, must be 0                                                          ;;
633
;> [_specific] = 0 / pointer to the structure of format specific options                          ;;
707
;> [_specific] = 0 / pointer to the structure of format specific options                          ;;
634
;                   see .inc for description                                         ;;
708
;                   see .inc for description                                         ;;
635
;;------------------------------------------------------------------------------------------------;;
709
;;------------------------------------------------------------------------------------------------;;
636
;< eax = 0 / pointer to encoded data                                                              ;;
710
;< eax = 0 / pointer to encoded data                                                              ;;
637
;< ecx = error code / the size of encoded data                                                    ;;
711
;< ecx = error code / the size of encoded data                                                    ;;
638
;     1 : out of memory                                                                           ;;
712
;     1 : out of memory                                                                           ;;
639
;     2 : format is not supported                                                                 ;;
713
;     2 : format is not supported                                                                 ;;
640
;     3 : specific conditions cannot be satisfied                                                 ;;
714
;     3 : specific conditions cannot be satisfied                                                 ;;
641
;     4 : bit depth cannot be preserved                                                           ;;
715
;     4 : bit depth cannot be preserved                                                           ;;
642
;;================================================================================================;;
716
;;================================================================================================;;
643
	mov	ebx, [_img]
717
	mov	ebx, [_img]
644
 
718
 
645
	movzx	eax, byte[_common]
719
	movzx	eax, byte[_common]
646
	dec	eax
720
	dec	eax
647
	imul	eax, sizeof.FormatsTableEntry
721
	imul	eax, sizeof.FormatsTableEntry
648
	add	eax, FormatsTableEntry.Capabilities
722
	add	eax, FormatsTableEntry.Capabilities
649
	add	eax, img.formats_table
723
	add	eax, img.formats_table
650
	mov	eax, [eax]
724
	mov	eax, [eax]
651
	test	eax, 1				; is encoding to this format supported at all?
725
	test	eax, 1				; is encoding to this format supported at all?
652
	jnz	@f
726
	jnz	@f
653
	mov	ecx, LIBIMG_ERROR_FORMAT
727
	mov	ecx, LIBIMG_ERROR_FORMAT
654
	jmp	.error
728
	jmp	.error
655
    @@:
729
    @@:
656
	mov	ecx, [ebx + Image.Type]
730
	mov	ecx, [ebx + Image.Type]
657
	mov	edx, 1
731
	mov	edx, 1
658
	shl	edx, cl
732
	shl	edx, cl
659
	test	eax, edx
733
	test	eax, edx
660
	jnz	.bit_depth_ok
734
	jnz	.bit_depth_ok
661
	test	byte[_common+2], LIBIMG_ENCODE_STRICT_BIT_DEPTH
735
	test	byte[_common+2], LIBIMG_ENCODE_STRICT_BIT_DEPTH
662
	jz	@f
736
	jz	@f
663
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
737
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
664
	jmp	.error
738
	jmp	.error
665
    @@:
739
    @@:
666
	mov	edx, 1 SHL Image.bpp24
740
	mov	edx, 1 SHL Image.bpp24
667
	test	eax, edx
741
	test	eax, edx
668
	jnz	@f
742
	jnz	@f
669
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
743
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
670
	jmp	.error
744
	jmp	.error
671
    @@:
745
    @@:
672
	stdcall	img.create, [ebx + Image.Width], [ebx + Image.Height], Image.bpp24
746
	stdcall	img.create, [ebx + Image.Width], [ebx + Image.Height], Image.bpp24
673
	test	eax, eax
747
	test	eax, eax
674
	jnz	@f
748
	jnz	@f
675
	mov	ecx, LIBIMG_ERROR_OUT_OF_MEMORY
749
	mov	ecx, LIBIMG_ERROR_OUT_OF_MEMORY
676
	jmp	.error
750
	jmp	.error
677
    @@:
751
    @@:
678
	push	eax
752
	push	eax
679
	stdcall	img.to_rgb2, ebx, [eax + Image.Data]
753
	stdcall	img.to_rgb2, ebx, [eax + Image.Data]
680
	pop	ebx
754
	pop	ebx
681
 
755
 
682
  .bit_depth_ok:
756
  .bit_depth_ok:
683
	movzx	eax, byte[_common]
757
	movzx	eax, byte[_common]
684
	dec	eax
758
	dec	eax
685
	imul	eax, sizeof.FormatsTableEntry
759
	imul	eax, sizeof.FormatsTableEntry
686
	add	eax, FormatsTableEntry.Encode
760
	add	eax, FormatsTableEntry.Encode
687
	add	eax, img.formats_table
761
	add	eax, img.formats_table
688
	mov	eax, [eax]
762
	mov	eax, [eax]
689
	stdcall	eax, [_img], [_common], [_specific]
763
	stdcall	eax, [_img], [_common], [_specific]
690
	push	eax ecx
764
	push	eax ecx
691
	cmp	ebx, [_img]
765
	cmp	ebx, [_img]
692
	je	@f
766
	je	@f
693
	stdcall	img.destroy, ebx
767
	stdcall	img.destroy, ebx
694
    @@:
768
    @@:
695
	pop	ecx eax
769
	pop	ecx eax
696
	jmp	.quit
770
	jmp	.quit
697
 
771
 
698
  .error:
772
  .error:
699
	xor	eax, eax
773
	xor	eax, eax
700
  .quit:
774
  .quit:
701
	ret
775
	ret
702
endp
776
endp
703
 
777
 
704
;;================================================================================================;;
778
;;================================================================================================;;
705
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
779
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
706
;;------------------------------------------------------------------------------------------------;;
780
;;------------------------------------------------------------------------------------------------;;
707
;? creates an Image structure and initializes some its fields                                     ;;
781
;? creates an Image structure and initializes some its fields                                     ;;
708
;;------------------------------------------------------------------------------------------------;;
782
;;------------------------------------------------------------------------------------------------;;
709
;> [_width]  = width of an image in pixels                                                        ;;
783
;> [_width]  = width of an image in pixels                                                        ;;
710
;> [_height] = height of an image in pixels                                                       ;;
784
;> [_height] = height of an image in pixels                                                       ;;
711
;> [_type]   = one of the Image.bppN constants from libimg.inc                                    ;;
785
;> [_type]   = one of the Image.bppN constants from libimg.inc                                    ;;
712
;;------------------------------------------------------------------------------------------------;;
786
;;------------------------------------------------------------------------------------------------;;
713
;< eax = 0 / pointer to image                                                                     ;;
787
;< eax = 0 / pointer to image                                                                     ;;
714
;;================================================================================================;;
788
;;================================================================================================;;
715
    push    ecx
789
    push    ecx
716
 
790
 
717
    stdcall img._.new
791
    stdcall img._.new
718
    or  eax, eax
792
    or  eax, eax
719
    jz  .error
793
    jz  .error
720
 
794
 
721
    mov ecx, [_type]
795
    mov ecx, [_type]
722
    mov [eax + Image.Type], ecx
796
    mov [eax + Image.Type], ecx
723
 
797
 
724
    push    eax
798
    push    eax
725
 
799
 
726
    stdcall img._.resize_data, eax, [_width], [_height]
800
    stdcall img._.resize_data, eax, [_width], [_height]
727
    or  eax, eax
801
    or  eax, eax
728
    jz  .error.2
802
    jz  .error.2
729
 
803
 
730
    pop eax
804
    pop eax
731
    jmp .ret
805
    jmp .ret
732
 
806
 
733
  .error.2:
807
  .error.2:
734
;       pop     eax
808
;       pop     eax
735
    stdcall img._.delete; eax
809
    stdcall img._.delete; eax
736
    xor eax, eax
810
    xor eax, eax
737
 
811
 
738
  .error:
812
  .error:
739
  .ret:
813
  .ret:
740
    pop ecx
814
    pop ecx
741
    ret
815
    ret
742
endp
816
endp
743
 
817
 
744
;;================================================================================================;;
818
;;================================================================================================;;
745
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
819
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
746
;;------------------------------------------------------------------------------------------------;;
820
;;------------------------------------------------------------------------------------------------;;
747
;? frees memory occupied by an image and all the memory regions its fields point to               ;;
821
;? frees memory occupied by an image and all the memory regions its fields point to               ;;
748
;? for image sequences deletes only one frame and fixes Previous/Next pointers                    ;;
822
;? for image sequences deletes only one frame and fixes Previous/Next pointers                    ;;
749
;;------------------------------------------------------------------------------------------------;;
823
;;------------------------------------------------------------------------------------------------;;
750
;> [_img] = pointer to image                                                                      ;;
824
;> [_img] = pointer to image                                                                      ;;
751
;;------------------------------------------------------------------------------------------------;;
825
;;------------------------------------------------------------------------------------------------;;
752
;< eax = 0 (fail) / 1 (success)                                                                   ;;
826
;< eax = 0 (fail) / 1 (success)                                                                   ;;
753
;;================================================================================================;;
827
;;================================================================================================;;
754
    mov eax, [_img]
828
    mov eax, [_img]
755
    mov edx, [eax + Image.Previous]
829
    mov edx, [eax + Image.Previous]
756
    test    edx, edx
830
    test    edx, edx
757
    jz  @f
831
    jz  @f
758
    push    [eax + Image.Next]
832
    push    [eax + Image.Next]
759
    pop [edx + Image.Next]
833
    pop [edx + Image.Next]
760
@@:
834
@@:
761
    mov edx, [eax + Image.Next]
835
    mov edx, [eax + Image.Next]
762
    test    edx, edx
836
    test    edx, edx
763
    jz  @f
837
    jz  @f
764
    push    [eax + Image.Previous]
838
    push    [eax + Image.Previous]
765
    pop [edx + Image.Previous]
839
    pop [edx + Image.Previous]
766
@@:
840
@@:
767
    stdcall img._.delete, eax
841
    stdcall img._.delete, eax
768
    ret
842
    ret
769
endp
843
endp
770
 
844
 
771
;;================================================================================================;;
845
;;================================================================================================;;
772
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
846
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
773
;;------------------------------------------------------------------------------------------------;;
847
;;------------------------------------------------------------------------------------------------;;
774
;? frees memory occupied by an image and all the memory regions its fields point to               ;;
848
;? frees memory occupied by an image and all the memory regions its fields point to               ;;
775
;? follows Previous/Next pointers and deletes all the images in sequence                          ;;
849
;? follows Previous/Next pointers and deletes all the images in sequence                          ;;
776
;;------------------------------------------------------------------------------------------------;;
850
;;------------------------------------------------------------------------------------------------;;
777
;> [_img] = pointer to image                                                                      ;;
851
;> [_img] = pointer to image                                                                      ;;
778
;;------------------------------------------------------------------------------------------------;;
852
;;------------------------------------------------------------------------------------------------;;
779
;< eax = 0 (fail) / 1 (success)                                                                   ;;
853
;< eax = 0 (fail) / 1 (success)                                                                   ;;
780
;;================================================================================================;;
854
;;================================================================================================;;
781
    push    1
855
    push    1
782
    mov eax, [_img]
856
    mov eax, [_img]
783
    mov eax, [eax + Image.Previous]
857
    mov eax, [eax + Image.Previous]
784
.destroy_prev_loop:
858
.destroy_prev_loop:
785
    test    eax, eax
859
    test    eax, eax
786
    jz  .destroy_prev_done
860
    jz  .destroy_prev_done
787
    pushd   [eax + Image.Previous]
861
    pushd   [eax + Image.Previous]
788
    stdcall img._.delete, eax
862
    stdcall img._.delete, eax
789
    test    eax, eax
863
    test    eax, eax
790
    jnz @f
864
    jnz @f
791
    mov byte [esp+4], 0
865
    mov byte [esp+4], 0
792
@@:
866
@@:
793
    pop eax
867
    pop eax
794
    jmp .destroy_prev_loop
868
    jmp .destroy_prev_loop
795
.destroy_prev_done:
869
.destroy_prev_done:
796
    mov eax, [_img]
870
    mov eax, [_img]
797
.destroy_next_loop:
871
.destroy_next_loop:
798
    pushd   [eax + Image.Next]
872
    pushd   [eax + Image.Next]
799
    stdcall img._.delete, eax
873
    stdcall img._.delete, eax
800
    test    eax, eax
874
    test    eax, eax
801
    jnz @f
875
    jnz @f
802
    mov byte [esp+4], 0
876
    mov byte [esp+4], 0
803
@@:
877
@@:
804
    pop eax
878
    pop eax
805
    test    eax, eax
879
    test    eax, eax
806
    jnz .destroy_next_loop
880
    jnz .destroy_next_loop
807
    pop eax
881
    pop eax
808
    ret
882
    ret
809
endp
883
endp
810
 
884
 
811
;;================================================================================================;;
885
;;================================================================================================;;
812
proc img.count _img ;/////////////////////////////////////////////////////////////////////////////;;
886
proc img.count _img ;/////////////////////////////////////////////////////////////////////////////;;
813
;;------------------------------------------------------------------------------------------------;;
887
;;------------------------------------------------------------------------------------------------;;
814
;? Get number of images in the list (e.g. in animated GIF file)                                   ;;
888
;? Get number of images in the list (e.g. in animated GIF file)                                   ;;
815
;;------------------------------------------------------------------------------------------------;;
889
;;------------------------------------------------------------------------------------------------;;
816
;> _img = pointer to image                                                                        ;;
890
;> _img = pointer to image                                                                        ;;
817
;;------------------------------------------------------------------------------------------------;;
891
;;------------------------------------------------------------------------------------------------;;
818
;< eax = -1 (fail) / >0 (ok)                                                                      ;;
892
;< eax = -1 (fail) / >0 (ok)                                                                      ;;
819
;;================================================================================================;;
893
;;================================================================================================;;
820
    push    ecx edx
894
    push    ecx edx
821
    mov edx, [_img]
895
    mov edx, [_img]
822
    stdcall img._.validate, edx
896
    stdcall img._.validate, edx
823
    or  eax, eax
897
    or  eax, eax
824
    jnz .error
898
    jnz .error
825
 
899
 
826
    @@: mov eax, [edx + Image.Previous]
900
    @@: mov eax, [edx + Image.Previous]
827
    or  eax, eax
901
    or  eax, eax
828
    jz  @f
902
    jz  @f
829
    mov edx, eax
903
    mov edx, eax
830
    jmp @b
904
    jmp @b
831
 
905
 
832
    @@: xor ecx, ecx
906
    @@: xor ecx, ecx
833
    @@: inc ecx
907
    @@: inc ecx
834
    mov eax, [edx + Image.Next]
908
    mov eax, [edx + Image.Next]
835
    or  eax, eax
909
    or  eax, eax
836
    jz  .exit
910
    jz  .exit
837
    mov edx, eax
911
    mov edx, eax
838
    jmp @b
912
    jmp @b
839
 
913
 
840
  .exit:
914
  .exit:
841
    mov eax, ecx
915
    mov eax, ecx
842
    pop edx ecx
916
    pop edx ecx
843
    ret
917
    ret
844
 
918
 
845
  .error:
919
  .error:
846
    or  eax, -1
920
    or  eax, -1
847
    pop edx ecx
921
    pop edx ecx
848
    ret
922
    ret
849
endp
923
endp
850
 
924
 
851
;;//// image processing //////////////////////////////////////////////////////////////////////////;;
925
;;//// image processing //////////////////////////////////////////////////////////////////////////;;
852
 
926
 
853
;;================================================================================================;;
927
;;================================================================================================;;
854
proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////////////////////////;;
928
proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////////////////////////;;
855
;;------------------------------------------------------------------------------------------------;;
929
;;------------------------------------------------------------------------------------------------;;
856
;? --- TBD ---                                                                                    ;;
930
;? --- TBD ---                                                                                    ;;
857
;;------------------------------------------------------------------------------------------------;;
931
;;------------------------------------------------------------------------------------------------;;
858
;> --- TBD ---                                                                                    ;;
932
;> --- TBD ---                                                                                    ;;
859
;;------------------------------------------------------------------------------------------------;;
933
;;------------------------------------------------------------------------------------------------;;
860
;< eax = 0 / pointer to bits                                                                      ;;
934
;< eax = 0 / pointer to bits                                                                      ;;
861
;;================================================================================================;;
935
;;================================================================================================;;
862
    xor eax, eax
936
    xor eax, eax
863
    ret
937
    ret
864
endp
938
endp
865
 
939
 
866
;;================================================================================================;;
940
;;================================================================================================;;
867
proc img.unlock_bits _img, _lock ;////////////////////////////////////////////////////////////////;;
941
proc img.unlock_bits _img, _lock ;////////////////////////////////////////////////////////////////;;
868
;;------------------------------------------------------------------------------------------------;;
942
;;------------------------------------------------------------------------------------------------;;
869
;? --- TBD ---                                                                                    ;;
943
;? --- TBD ---                                                                                    ;;
870
;;------------------------------------------------------------------------------------------------;;
944
;;------------------------------------------------------------------------------------------------;;
871
;> --- TBD ---                                                                                    ;;
945
;> --- TBD ---                                                                                    ;;
872
;;------------------------------------------------------------------------------------------------;;
946
;;------------------------------------------------------------------------------------------------;;
873
;< eax = false / true                                                                             ;;
947
;< eax = false / true                                                                             ;;
874
;;================================================================================================;;
948
;;================================================================================================;;
875
    xor eax, eax
949
    xor eax, eax
876
    ret
950
    ret
877
endp
951
endp
878
 
952
 
879
;;================================================================================================;;
953
;;================================================================================================;;
880
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////////////////////////;;
954
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////////////////////////;;
881
;;------------------------------------------------------------------------------------------------;;
955
;;------------------------------------------------------------------------------------------------;;
882
;? Flip image layer                                                                               ;;
956
;? Flip image layer                                                                               ;;
883
;;------------------------------------------------------------------------------------------------;;
957
;;------------------------------------------------------------------------------------------------;;
884
;> _img = pointer to image                                                                        ;;
958
;> _img = pointer to image                                                                        ;;
885
;> _flip_kind = one of FLIP_* constants                                                           ;;
959
;> _flip_kind = one of FLIP_* constants                                                           ;;
886
;;------------------------------------------------------------------------------------------------;;
960
;;------------------------------------------------------------------------------------------------;;
887
;< eax = false / true                                                                             ;;
961
;< eax = false / true                                                                             ;;
888
;;================================================================================================;;
962
;;================================================================================================;;
889
locals
963
locals
890
  scanline_len dd ?
964
  scanline_len dd ?
891
endl
965
endl
892
 
966
 
893
    push    ebx esi edi
967
    push    ebx esi edi
894
    mov ebx, [_img]
968
    mov ebx, [_img]
895
    stdcall img._.validate, ebx
969
    stdcall img._.validate, ebx
896
    or  eax, eax
970
    or  eax, eax
897
    jnz .error
971
    jnz .error
898
 
972
 
899
    mov ecx, [ebx + Image.Height]
973
    mov ecx, [ebx + Image.Height]
900
    mov eax, [ebx + Image.Width]
974
    mov eax, [ebx + Image.Width]
901
    call    img._.get_scanline_len
975
    call    img._.get_scanline_len
902
    mov [scanline_len], eax
976
    mov [scanline_len], eax
903
 
977
 
904
    test    [_flip_kind], FLIP_VERTICAL
978
    test    [_flip_kind], FLIP_VERTICAL
905
    jz  .dont_flip_vert
979
    jz  .dont_flip_vert
906
 
980
 
907
    imul    eax, ecx
981
    imul    eax, ecx
908
    sub eax, [scanline_len]
982
    sub eax, [scanline_len]
909
    shr ecx, 1
983
    shr ecx, 1
910
    mov esi, [ebx + Image.Data]
984
    mov esi, [ebx + Image.Data]
911
    lea edi, [esi + eax]
985
    lea edi, [esi + eax]
912
    
986
    
913
  .next_line_vert:
987
  .next_line_vert:
914
    push    ecx
988
    push    ecx
915
 
989
 
916
    mov ecx, [scanline_len]
990
    mov ecx, [scanline_len]
917
    push    ecx
991
    push    ecx
918
    shr ecx, 2
992
    shr ecx, 2
919
    @@:
993
    @@:
920
    dec ecx
994
    dec ecx
921
    js  @f
995
    js  @f
922
    mov eax, [esi]
996
    mov eax, [esi]
923
    xchg    eax, [edi]
997
    xchg    eax, [edi]
924
    mov [esi], eax
998
    mov [esi], eax
925
    add esi, 4
999
    add esi, 4
926
    add edi, 4
1000
    add edi, 4
927
    jmp @b
1001
    jmp @b
928
    @@:
1002
    @@:
929
 
1003
 
930
    pop ecx
1004
    pop ecx
931
    and ecx, 3
1005
    and ecx, 3
932
    jz  .cont_line_vert
1006
    jz  .cont_line_vert
933
    @@:
1007
    @@:
934
    mov al, [esi]
1008
    mov al, [esi]
935
    xchg    al, [edi]
1009
    xchg    al, [edi]
936
    mov [esi], al
1010
    mov [esi], al
937
    add esi, 1
1011
    add esi, 1
938
    add edi, 1
1012
    add edi, 1
939
    dec ecx
1013
    dec ecx
940
    jnz @b
1014
    jnz @b
941
    .cont_line_vert:
1015
    .cont_line_vert:
942
 
1016
 
943
    pop ecx
1017
    pop ecx
944
    mov eax, [scanline_len]
1018
    mov eax, [scanline_len]
945
    shl eax, 1
1019
    shl eax, 1
946
    sub edi, eax
1020
    sub edi, eax
947
    dec ecx
1021
    dec ecx
948
    jnz .next_line_vert
1022
    jnz .next_line_vert
949
 
1023
 
950
  .dont_flip_vert:
1024
  .dont_flip_vert:
951
 
1025
 
952
    test    [_flip_kind], FLIP_HORIZONTAL
1026
    test    [_flip_kind], FLIP_HORIZONTAL
953
    jz  .exit
1027
    jz  .exit
954
 
1028
 
955
    mov ecx, [ebx + Image.Height]
1029
    mov ecx, [ebx + Image.Height]
956
    mov eax, [ebx + Image.Type]
1030
    mov eax, [ebx + Image.Type]
957
    mov esi, [ebx + Image.Data]
1031
    mov esi, [ebx + Image.Data]
958
    mov edi, [scanline_len]
1032
    mov edi, [scanline_len]
959
    add edi, esi
1033
    add edi, esi
960
    jmp dword [.handlers_horz + (eax-1)*4]
1034
    jmp dword [.handlers_horz + (eax-1)*4]
961
 
1035
 
962
.bpp32_horz:
1036
.bpp32_horz:
963
    sub edi, 4
1037
    sub edi, 4
964
 
1038
 
965
  .next_line_horz:
1039
  .next_line_horz:
966
    push    ecx esi edi
1040
    push    ecx esi edi
967
 
1041
 
968
    mov ecx, [scanline_len]
1042
    mov ecx, [scanline_len]
969
    shr ecx, 3
1043
    shr ecx, 3
970
    @@: mov eax, [esi]
1044
    @@: mov eax, [esi]
971
    xchg    eax, [edi]
1045
    xchg    eax, [edi]
972
    mov [esi], eax
1046
    mov [esi], eax
973
    add esi, 4
1047
    add esi, 4
974
    add edi, -4
1048
    add edi, -4
975
    sub ecx, 1
1049
    sub ecx, 1
976
    jnz @b
1050
    jnz @b
977
 
1051
 
978
    pop edi esi ecx
1052
    pop edi esi ecx
979
    add esi, [scanline_len]
1053
    add esi, [scanline_len]
980
    add edi, [scanline_len]
1054
    add edi, [scanline_len]
981
    dec ecx
1055
    dec ecx
982
    jnz .next_line_horz
1056
    jnz .next_line_horz
983
    jmp .exit
1057
    jmp .exit
984
 
1058
 
985
.bpp1x_horz:
1059
.bpp1x_horz:
986
    sub edi, 2
1060
    sub edi, 2
987
  .next_line_horz1x:
1061
  .next_line_horz1x:
988
    push    ecx esi edi
1062
    push    ecx esi edi
989
 
1063
 
990
    mov ecx, [ebx + Image.Width]
1064
    mov ecx, [ebx + Image.Width]
991
    @@: mov ax, [esi]
1065
    @@: mov ax, [esi]
992
    mov dx, [edi]
1066
    mov dx, [edi]
993
    mov [edi], ax
1067
    mov [edi], ax
994
    mov [esi], dx
1068
    mov [esi], dx
995
    add esi, 2
1069
    add esi, 2
996
    sub edi, 2
1070
    sub edi, 2
997
    sub ecx, 2
1071
    sub ecx, 2
998
    ja  @b
1072
    ja  @b
999
 
1073
 
1000
    pop edi esi ecx
1074
    pop edi esi ecx
1001
    add esi, [scanline_len]
1075
    add esi, [scanline_len]
1002
    add edi, [scanline_len]
1076
    add edi, [scanline_len]
1003
    dec ecx
1077
    dec ecx
1004
    jnz .next_line_horz1x
1078
    jnz .next_line_horz1x
1005
    jmp .exit
1079
    jmp .exit
1006
 
1080
 
1007
.bpp8ig_horz:
1081
.bpp8ig_horz:
1008
    dec edi
1082
    dec edi
1009
  .next_line_horz8ig:
1083
  .next_line_horz8ig:
1010
    push    ecx esi edi
1084
    push    ecx esi edi
1011
 
1085
 
1012
    mov ecx, [scanline_len]
1086
    mov ecx, [scanline_len]
1013
    shr ecx, 1
1087
    shr ecx, 1
1014
    @@: mov al, [esi]
1088
    @@: mov al, [esi]
1015
    mov dl, [edi]
1089
    mov dl, [edi]
1016
    mov [edi], al
1090
    mov [edi], al
1017
    mov [esi], dl
1091
    mov [esi], dl
1018
    add esi, 1
1092
    add esi, 1
1019
    sub edi, 1
1093
    sub edi, 1
1020
    sub ecx, 1
1094
    sub ecx, 1
1021
    jnz @b
1095
    jnz @b
1022
 
1096
 
1023
    pop edi esi ecx
1097
    pop edi esi ecx
1024
    add esi, [scanline_len]
1098
    add esi, [scanline_len]
1025
    add edi, [scanline_len]
1099
    add edi, [scanline_len]
1026
    dec ecx
1100
    dec ecx
1027
    jnz .next_line_horz8ig
1101
    jnz .next_line_horz8ig
1028
    jmp .exit
1102
    jmp .exit
1029
 
1103
 
1030
.bpp24_horz:
1104
.bpp24_horz:
1031
    sub edi, 3
1105
    sub edi, 3
1032
  .next_line_horz24:
1106
  .next_line_horz24:
1033
    push    ecx esi edi
1107
    push    ecx esi edi
1034
 
1108
 
1035
    mov ecx, [ebx + Image.Width]
1109
    mov ecx, [ebx + Image.Width]
1036
    @@:
1110
    @@:
1037
    mov al, [esi]
1111
    mov al, [esi]
1038
    mov dl, [edi]
1112
    mov dl, [edi]
1039
    mov [edi], al
1113
    mov [edi], al
1040
    mov [esi], dl
1114
    mov [esi], dl
1041
    mov al, [esi+1]
1115
    mov al, [esi+1]
1042
    mov dl, [edi+1]
1116
    mov dl, [edi+1]
1043
    mov [edi+1], al
1117
    mov [edi+1], al
1044
    mov [esi+1], dl
1118
    mov [esi+1], dl
1045
    mov al, [esi+2]
1119
    mov al, [esi+2]
1046
    mov dl, [edi+2]
1120
    mov dl, [edi+2]
1047
    mov [edi+2], al
1121
    mov [edi+2], al
1048
    mov [esi+2], dl
1122
    mov [esi+2], dl
1049
    add esi, 3
1123
    add esi, 3
1050
    sub edi, 3
1124
    sub edi, 3
1051
    sub ecx, 2
1125
    sub ecx, 2
1052
    ja  @b
1126
    ja  @b
1053
 
1127
 
1054
    pop edi esi ecx
1128
    pop edi esi ecx
1055
    add esi, [scanline_len]
1129
    add esi, [scanline_len]
1056
    add edi, [scanline_len]
1130
    add edi, [scanline_len]
1057
    dec ecx
1131
    dec ecx
1058
    jnz .next_line_horz24
1132
    jnz .next_line_horz24
1059
    jmp .exit
1133
    jmp .exit
1060
 
1134
 
1061
.bpp1_horz:
1135
.bpp1_horz:
1062
    push eax edx
-
 
1063
    mov edi, [scanline_len]
1136
    mov edi, [scanline_len]
1064
    mov edx, [ebx+Image.Width]
1137
    mov edx, [ebx + Image.Width]
1065
    and edx,  0x07
1138
    and edx, 7
1066
    neg dl
1139
    neg edx
1067
    add dl, 8
1140
    add edx, 8
1068
    and dl, 0x07                                        ; clear if cl=8
1141
    and edx, 7
1069
.bpp1_horz.begin:
1142
.bpp1_horz.begin:
1070
    push ebx ecx edx esi
1143
    push ebx edx esi
1071
    mov eax, 7
1144
    mov eax, 7
1072
    add edi, esi
1145
    add edi, esi
1073
    sub edi, 1
1146
    sub edi, 1
1074
    mov ebx, [ebx+Image.Width]
1147
    mov ebx, [ebx + Image.Width]
1075
    shr ebx, 1
1148
    shr ebx, 1
1076
.bpp1_horz.flip_line:
1149
.bpp1_horz.bit:
1077
    xor ecx, ecx
-
 
1078
    bt  [esi], eax
-
 
1079
    setc cl
-
 
1080
    bt  [edi], edx
1150
    bt  [edi], edx
1081
     jc .bpp1_horz.one
1151
    jc  @f
1082
  .bpp1_horz.zero:
-
 
1083
    btr [esi], eax
1152
    btr [esi], eax
1084
     jmp @f
-
 
1085
  .bpp1_horz.one:
1153
    jmp .bpp1_horz.right
1086
    bts [esi], eax
-
 
1087
  @@:
1154
  @@:
1088
     jecxz .bpp1_horz.reset
1155
    bts [esi], eax
1089
  .bpp1_horz.set:
1156
  .bpp1_horz.right:
-
 
1157
    jnc @f
1090
    bts [edi], edx
1158
    bts [edi], edx
1091
     jmp @f
-
 
1092
  .bpp1_horz.reset:
1159
    jmp .bpp1_horz.bit_done
1093
    btr [edi], edx
-
 
1094
  @@:
1160
  @@:
-
 
1161
    btr [edi], edx
-
 
1162
  .bpp1_horz.bit_done:
1095
    inc edx
1163
    inc edx
1096
    and edx, 0x07
1164
    and edx, 7
1097
     jnz @f
1165
    jnz @f
1098
    dec edi
1166
    dec edi
1099
  @@:
1167
  @@:
1100
    dec eax
1168
    dec eax
1101
     jns @f
1169
    jns @f
1102
    mov eax, 7
1170
    mov eax, 7
1103
    inc esi
1171
    inc esi
1104
  @@:
1172
  @@:
1105
    dec ebx
1173
    dec ebx
1106
     jnz .bpp1_horz.flip_line
1174
    jnz .bpp1_horz.bit
1107
 
1175
 
1108
    pop esi edx ecx ebx
1176
    pop esi edx ebx
1109
    add esi, [scanline_len]
1177
    add esi, [scanline_len]
1110
    mov edi, [scanline_len]
1178
    mov edi, [scanline_len]
1111
    dec ecx
1179
    dec ecx
1112
     jnz .bpp1_horz.begin
1180
    jnz .bpp1_horz.begin
-
 
1181
    jmp .exit
-
 
1182
 
-
 
1183
 
-
 
1184
.bpp2i_horz:
-
 
1185
    mov edi, [scanline_len]
-
 
1186
    mov edx, [ebx + Image.Width]
-
 
1187
    and edx, 3
-
 
1188
    neg edx
-
 
1189
    add edx, 4
-
 
1190
    and edx, 3
-
 
1191
.bpp2i_horz.begin:
-
 
1192
    push ebx edx esi
-
 
1193
    mov eax, 3
-
 
1194
    add edi, esi
-
 
1195
    sub edi, 1
-
 
1196
    mov ebx, [ebx + Image.Width]
-
 
1197
    shr ebx, 1
-
 
1198
.bpp2i_horz.pixel:
-
 
1199
    push ebx ecx
-
 
1200
    mov ebx, 3
-
 
1201
    mov ecx, edx
-
 
1202
    shl ebx, cl
-
 
1203
    shl ebx, cl
-
 
1204
    and bl, [edi]
-
 
1205
    shr ebx, cl
-
 
1206
    shr ebx, cl
-
 
1207
    mov bh,  3
-
 
1208
    mov ecx, eax
-
 
1209
    shl ebx, cl
-
 
1210
    shl ebx, cl
-
 
1211
    not bh
-
 
1212
    and bh, [esi]
-
 
1213
    or  bl, bh
-
 
1214
    mov bh, [esi]
-
 
1215
    mov [esi], bl
-
 
1216
    shr ebx, 8
-
 
1217
    shr ebx, cl
-
 
1218
    shr ebx, cl
-
 
1219
    and ebx, 3
-
 
1220
    mov bh,  3
-
 
1221
    mov ecx, edx
-
 
1222
    shl ebx, cl
-
 
1223
    shl ebx, cl
-
 
1224
    not bh
-
 
1225
    and bh, [edi]
-
 
1226
    or  bl, bh
-
 
1227
    mov [edi], bl
-
 
1228
    pop ecx ebx
-
 
1229
  .bpp2i_horz.pixel_done:
-
 
1230
    inc edx
-
 
1231
    and edx, 3
-
 
1232
    jnz @f
-
 
1233
    dec edi
-
 
1234
  @@:
-
 
1235
    dec eax
-
 
1236
    jns @f
-
 
1237
    mov eax, 3
-
 
1238
    inc esi
-
 
1239
  @@:
-
 
1240
    dec ebx
-
 
1241
    jnz .bpp2i_horz.pixel
-
 
1242
 
-
 
1243
    pop esi edx ebx
-
 
1244
    add esi, [scanline_len]
-
 
1245
    mov edi, [scanline_len]
-
 
1246
    dec ecx
-
 
1247
    jnz .bpp2i_horz.begin
-
 
1248
    jmp .exit
-
 
1249
 
-
 
1250
 
-
 
1251
.bpp4i_horz:
-
 
1252
    mov edi, [scanline_len]
-
 
1253
    mov edx, [ebx + Image.Width]
-
 
1254
    and edx, 1
-
 
1255
    neg edx
-
 
1256
    add edx, 2
-
 
1257
    and edx, 1
-
 
1258
.bpp4i_horz.begin:
-
 
1259
    push ebx edx esi
-
 
1260
    mov eax, 1
-
 
1261
    add edi, esi
-
 
1262
    sub edi, 1
-
 
1263
    mov ebx, [ebx + Image.Width]
-
 
1264
    shr ebx, 1
-
 
1265
.bpp4i_horz.pixel:
-
 
1266
    push ebx ecx
-
 
1267
    mov ebx, 15
-
 
1268
    mov ecx, edx
-
 
1269
    shl ecx, 2
-
 
1270
    shl ebx, cl
-
 
1271
    and bl, [edi]
-
 
1272
    shr ebx, cl
-
 
1273
    mov bh,  15
-
 
1274
    mov ecx, eax
-
 
1275
    shl ecx, 2
-
 
1276
    shl ebx, cl
-
 
1277
    not bh
-
 
1278
    and bh, [esi]
-
 
1279
    or  bl, bh
-
 
1280
    mov bh, [esi]
-
 
1281
    mov [esi], bl
-
 
1282
    shr ebx, 8
-
 
1283
    shr ebx, cl
-
 
1284
    and ebx, 15
-
 
1285
    mov bh,  15
-
 
1286
    mov ecx, edx
-
 
1287
    shl ecx, 2
-
 
1288
    shl ebx, cl
-
 
1289
    not bh
-
 
1290
    and bh, [edi]
-
 
1291
    or  bl, bh
-
 
1292
    mov [edi], bl
1113
    pop edx eax
1293
    pop ecx ebx
-
 
1294
  .bpp4i_horz.pixel_done:
-
 
1295
    inc edx
-
 
1296
    and edx, 1
-
 
1297
    jnz @f
-
 
1298
    dec edi
-
 
1299
  @@:
-
 
1300
    dec eax
-
 
1301
    jns @f
-
 
1302
    mov eax, 1
-
 
1303
    inc esi
-
 
1304
  @@:
-
 
1305
    dec ebx
-
 
1306
    jnz .bpp4i_horz.pixel
-
 
1307
 
-
 
1308
    pop esi edx ebx
-
 
1309
    add esi, [scanline_len]
-
 
1310
    mov edi, [scanline_len]
-
 
1311
    dec ecx
-
 
1312
    jnz .bpp4i_horz.begin
-
 
1313
    jmp .exit
-
 
1314
 
1114
 
1315
 
1115
  .exit:
1316
  .exit:
1116
    xor eax, eax
1317
    xor eax, eax
1117
    inc eax
1318
    inc eax
1118
    pop edi esi ebx
1319
    pop edi esi ebx
1119
    ret
1320
    ret
1120
 
1321
 
1121
  .error:
1322
  .error:
1122
    xor eax, eax
1323
    xor eax, eax
1123
    pop edi esi ebx
1324
    pop edi esi ebx
1124
    ret
1325
    ret
1125
endp
1326
endp
1126
 
1327
 
1127
;;================================================================================================;;
1328
;;================================================================================================;;
1128
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
1329
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
1129
;;------------------------------------------------------------------------------------------------;;
1330
;;------------------------------------------------------------------------------------------------;;
1130
;? Flip all layers of image                                                                       ;;
1331
;? Flip all layers of image                                                                       ;;
1131
;;------------------------------------------------------------------------------------------------;;
1332
;;------------------------------------------------------------------------------------------------;;
1132
;> _img = pointer to image                                                                        ;;
1333
;> _img = pointer to image                                                                        ;;
1133
;> _flip_kind = one of FLIP_* constants                                                           ;;
1334
;> _flip_kind = one of FLIP_* constants                                                           ;;
1134
;;------------------------------------------------------------------------------------------------;;
1335
;;------------------------------------------------------------------------------------------------;;
1135
;< eax = false / true                                                                             ;;
1336
;< eax = false / true                                                                             ;;
1136
;;================================================================================================;;
1337
;;================================================================================================;;
1137
    push    1
1338
    push    1
1138
    mov ebx, [_img]
1339
    mov ebx, [_img]
1139
@@:
1340
@@:
1140
    mov eax, [ebx + Image.Previous]
1341
    mov eax, [ebx + Image.Previous]
1141
    test    eax, eax
1342
    test    eax, eax
1142
    jz  .loop
1343
    jz  .loop
1143
    mov ebx, eax
1344
    mov ebx, eax
1144
    jmp @b
1345
    jmp @b
1145
.loop:
1346
.loop:
1146
    stdcall img.flip.layer, ebx, [_flip_kind]
1347
    stdcall img.flip.layer, ebx, [_flip_kind]
1147
    test    eax, eax
1348
    test    eax, eax
1148
    jnz @f
1349
    jnz @f
1149
    mov byte [esp], 0
1350
    mov byte [esp], 0
1150
@@:
1351
@@:
1151
    mov ebx, [ebx + Image.Next]
1352
    mov ebx, [ebx + Image.Next]
1152
    test    ebx, ebx
1353
    test    ebx, ebx
1153
    jnz .loop
1354
    jnz .loop
1154
    pop eax
1355
    pop eax
1155
    ret
1356
    ret
1156
endp
1357
endp
1157
 
1358
 
1158
;;================================================================================================;;
1359
;;================================================================================================;;
1159
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////////////////////////;;
1360
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////////////////////////;;
1160
;;------------------------------------------------------------------------------------------------;;
1361
;;------------------------------------------------------------------------------------------------;;
1161
;? Rotate image layer                                                                             ;;
1362
;? Rotate image layer                                                                             ;;
1162
;;------------------------------------------------------------------------------------------------;;
1363
;;------------------------------------------------------------------------------------------------;;
1163
;> _img = pointer to image                                                                        ;;
1364
;> _img = pointer to image                                                                        ;;
1164
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
1365
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
1165
;;------------------------------------------------------------------------------------------------;;
1366
;;------------------------------------------------------------------------------------------------;;
1166
;< eax = false / true                                                                             ;;
1367
;< eax = false / true                                                                             ;;
1167
;;================================================================================================;;
1368
;;================================================================================================;;
1168
locals
1369
locals
1169
  scanline_len_old    dd ?
1370
  scanline_len_old    dd ?
1170
  scanline_len_new    dd ?
1371
  scanline_len_new    dd ?
1171
  scanline_pixels_new dd ?
1372
  scanline_pixels_new dd ?
1172
  line_buffer         dd ?
1373
  line_buffer         dd ?
1173
  pixels_ptr          dd ?
1374
  pixels_ptr          dd ?
1174
endl
1375
endl
1175
 
1376
 
1176
    mov [line_buffer], 0
1377
    mov [line_buffer], 0
1177
 
1378
 
1178
    push    ebx esi edi
1379
    push    ebx esi edi
1179
    mov ebx, [_img]
1380
    mov ebx, [_img]
1180
    stdcall img._.validate, ebx
1381
    stdcall img._.validate, ebx
1181
    or  eax, eax
1382
    or  eax, eax
1182
    jnz .error
1383
    jnz .error
1183
 
1384
 
1184
    cmp [_rotate_kind], ROTATE_90_CCW
1385
    cmp [_rotate_kind], ROTATE_90_CCW
1185
    je  .rotate_ccw_low
1386
    je  .rotate_ccw_low
1186
    cmp [_rotate_kind], ROTATE_90_CW
1387
    cmp [_rotate_kind], ROTATE_90_CW
1187
    je  .rotate_cw_low
1388
    je  .rotate_cw_low
1188
    cmp [_rotate_kind], ROTATE_180
1389
    cmp [_rotate_kind], ROTATE_180
1189
    je  .flip
1390
    je  .flip
1190
    jmp .exit
1391
    jmp .exit
1191
 
1392
 
1192
  .rotate_ccw_low:
1393
  .rotate_ccw_low:
1193
    mov eax, [ebx + Image.Height]
1394
    mov eax, [ebx + Image.Height]
1194
    mov [scanline_pixels_new], eax
1395
    mov [scanline_pixels_new], eax
1195
    call    img._.get_scanline_len
1396
    call    img._.get_scanline_len
1196
    mov [scanline_len_new], eax
1397
    mov [scanline_len_new], eax
1197
 
1398
 
1198
    invoke  mem.alloc, eax
1399
    invoke  mem.alloc, eax
1199
    or  eax, eax
1400
    or  eax, eax
1200
    jz  .error
1401
    jz  .error
1201
    mov [line_buffer], eax
1402
    mov [line_buffer], eax
1202
 
1403
 
1203
    mov eax, [ebx + Image.Width]
1404
    mov eax, [ebx + Image.Width]
1204
    mov ecx, eax
1405
    mov ecx, eax
1205
    call    img._.get_scanline_len
1406
    call    img._.get_scanline_len
1206
    mov [scanline_len_old], eax
1407
    mov [scanline_len_old], eax
1207
 
1408
 
1208
    mov eax, [scanline_len_new]
1409
    mov eax, [scanline_len_new]
1209
    imul    eax, ecx
1410
    imul    eax, ecx
1210
    add eax, [ebx + Image.Data]
1411
    add eax, [ebx + Image.Data]
1211
    mov [pixels_ptr], eax
1412
    mov [pixels_ptr], eax
1212
 
1413
 
1213
    cmp [ebx + Image.Type], Image.bpp1
1414
    cmp [ebx + Image.Type], Image.bpp1
1214
    jz  .rotate_ccw1
1415
    jz  .rotate_ccw1
-
 
1416
    cmp [ebx + Image.Type], Image.bpp2i
-
 
1417
    jz  .rotate_ccw2i
-
 
1418
    cmp [ebx + Image.Type], Image.bpp4i
-
 
1419
    jz  .rotate_ccw4i
1215
    cmp [ebx + Image.Type], Image.bpp8i
1420
    cmp [ebx + Image.Type], Image.bpp8i
1216
    jz  .rotate_ccw8ig
1421
    jz  .rotate_ccw8ig
1217
    cmp [ebx + Image.Type], Image.bpp8g
1422
    cmp [ebx + Image.Type], Image.bpp8g
1218
    jz  .rotate_ccw8ig
1423
    jz  .rotate_ccw8ig
1219
    cmp [ebx + Image.Type], Image.bpp24
1424
    cmp [ebx + Image.Type], Image.bpp24
1220
    jz  .rotate_ccw24
1425
    jz  .rotate_ccw24
1221
    cmp [ebx + Image.Type], Image.bpp32
1426
    cmp [ebx + Image.Type], Image.bpp32
1222
    jz  .rotate_ccw32
1427
    jz  .rotate_ccw32
1223
 
1428
 
1224
  .next_column_ccw_low1x:
1429
  .next_column_ccw_low1x:
1225
    dec ecx
1430
    dec ecx
1226
    js  .exchange_dims
1431
    js  .exchange_dims
1227
    push    ecx
1432
    push    ecx
1228
 
1433
 
1229
    mov edx, [scanline_len_old]
1434
    mov edx, [scanline_len_old]
1230
    add [scanline_len_old], -2
1435
    add [scanline_len_old], -2
1231
 
1436
 
1232
    mov ecx, [scanline_pixels_new]
1437
    mov ecx, [scanline_pixels_new]
1233
    mov esi, [ebx + Image.Data]
1438
    mov esi, [ebx + Image.Data]
1234
    mov edi, [line_buffer]
1439
    mov edi, [line_buffer]
1235
    @@: mov ax, [esi]
1440
    @@: mov ax, [esi]
1236
    mov [edi], ax
1441
    mov [edi], ax
1237
    add esi, edx
1442
    add esi, edx
1238
    add edi, 2
1443
    add edi, 2
1239
    sub ecx, 1
1444
    sub ecx, 1
1240
    jnz @b
1445
    jnz @b
1241
 
1446
 
1242
    mov eax, [scanline_pixels_new]
1447
    mov eax, [scanline_pixels_new]
1243
    mov edi, [ebx + Image.Data]
1448
    mov edi, [ebx + Image.Data]
1244
    lea esi, [edi + 2]
1449
    lea esi, [edi + 2]
1245
    mov edx, [scanline_len_old]
1450
    mov edx, [scanline_len_old]
1246
    @@: mov ecx, edx
1451
    @@: mov ecx, edx
1247
    shr ecx, 2
1452
    shr ecx, 2
1248
    rep movsd
1453
    rep movsd
1249
    mov ecx, edx
1454
    mov ecx, edx
1250
    and ecx, 3
1455
    and ecx, 3
1251
    rep movsb
1456
    rep movsb
1252
    add esi, 1
1457
    add esi, 1
1253
    sub eax, 1
1458
    sub eax, 1
1254
    jnz @b
1459
    jnz @b
1255
 
1460
 
1256
    mov eax, [scanline_len_new]
1461
    mov eax, [scanline_len_new]
1257
    sub [pixels_ptr], eax
1462
    sub [pixels_ptr], eax
1258
    mov ecx, [scanline_pixels_new]
1463
    mov ecx, [scanline_pixels_new]
1259
    mov esi, [line_buffer]
1464
    mov esi, [line_buffer]
1260
    mov edi, [pixels_ptr]
1465
    mov edi, [pixels_ptr]
1261
    mov edx, ecx
1466
    mov edx, ecx
1262
    shr ecx, 2
1467
    shr ecx, 2
1263
    rep movsd
1468
    rep movsd
1264
    mov ecx, edx
1469
    mov ecx, edx
1265
    and ecx, 3
1470
    and ecx, 3
1266
    rep movsb
1471
    rep movsb
1267
 
1472
 
1268
    pop ecx
1473
    pop ecx
1269
    jmp .next_column_ccw_low1x
1474
    jmp .next_column_ccw_low1x
1270
 
1475
 
1271
.rotate_ccw32:
1476
.rotate_ccw32:
1272
  .next_column_ccw_low:
1477
  .next_column_ccw_low:
1273
    dec ecx
1478
    dec ecx
1274
    js  .exchange_dims
1479
    js  .exchange_dims
1275
    push    ecx
1480
    push    ecx
1276
 
1481
 
1277
    mov edx, [scanline_len_old]
1482
    mov edx, [scanline_len_old]
1278
    add [scanline_len_old], -4
1483
    add [scanline_len_old], -4
1279
 
1484
 
1280
    mov ecx, [scanline_pixels_new]
1485
    mov ecx, [scanline_pixels_new]
1281
    mov esi, [ebx + Image.Data]
1486
    mov esi, [ebx + Image.Data]
1282
    mov edi, [line_buffer]
1487
    mov edi, [line_buffer]
1283
    @@: mov eax, [esi]
1488
    @@: mov eax, [esi]
1284
    stosd
1489
    stosd
1285
    add esi, edx
1490
    add esi, edx
1286
    dec ecx
1491
    dec ecx
1287
    jnz @b
1492
    jnz @b
1288
 
1493
 
1289
    mov eax, [scanline_pixels_new]
1494
    mov eax, [scanline_pixels_new]
1290
    mov edi, [ebx + Image.Data]
1495
    mov edi, [ebx + Image.Data]
1291
    lea esi, [edi + 4]
1496
    lea esi, [edi + 4]
1292
    mov edx, [scanline_len_old]
1497
    mov edx, [scanline_len_old]
1293
    shr edx, 2
1498
    shr edx, 2
1294
    @@: mov ecx, edx
1499
    @@: mov ecx, edx
1295
    rep movsd
1500
    rep movsd
1296
    add esi, 4
1501
    add esi, 4
1297
    dec eax
1502
    dec eax
1298
    jnz @b
1503
    jnz @b
1299
 
1504
 
1300
    mov eax, [scanline_len_new]
1505
    mov eax, [scanline_len_new]
1301
    sub [pixels_ptr], eax
1506
    sub [pixels_ptr], eax
1302
    mov ecx, [scanline_pixels_new]
1507
    mov ecx, [scanline_pixels_new]
1303
    mov esi, [line_buffer]
1508
    mov esi, [line_buffer]
1304
    mov edi, [pixels_ptr]
1509
    mov edi, [pixels_ptr]
1305
    rep movsd
1510
    rep movsd
1306
 
1511
 
1307
    pop ecx
1512
    pop ecx
1308
    jmp .next_column_ccw_low
1513
    jmp .next_column_ccw_low
1309
 
1514
 
1310
.rotate_ccw8ig:
1515
.rotate_ccw8ig:
1311
  .next_column_ccw_low8ig:
1516
  .next_column_ccw_low8ig:
1312
    dec ecx
1517
    dec ecx
1313
    js  .exchange_dims
1518
    js  .exchange_dims
1314
    push    ecx
1519
    push    ecx
1315
 
1520
 
1316
    mov edx, [scanline_len_old]
1521
    mov edx, [scanline_len_old]
1317
    add [scanline_len_old], -1
1522
    add [scanline_len_old], -1
1318
 
1523
 
1319
    mov ecx, [scanline_pixels_new]
1524
    mov ecx, [scanline_pixels_new]
1320
    mov esi, [ebx + Image.Data]
1525
    mov esi, [ebx + Image.Data]
1321
    mov edi, [line_buffer]
1526
    mov edi, [line_buffer]
1322
    @@: mov al, [esi]
1527
    @@: mov al, [esi]
1323
    mov [edi], al
1528
    mov [edi], al
1324
    add esi, edx
1529
    add esi, edx
1325
    add edi, 1
1530
    add edi, 1
1326
    sub ecx, 1
1531
    sub ecx, 1
1327
    jnz @b
1532
    jnz @b
1328
 
1533
 
1329
    mov eax, [scanline_pixels_new]
1534
    mov eax, [scanline_pixels_new]
1330
    mov edi, [ebx + Image.Data]
1535
    mov edi, [ebx + Image.Data]
1331
    lea esi, [edi + 1]
1536
    lea esi, [edi + 1]
1332
    mov edx, [scanline_len_old]
1537
    mov edx, [scanline_len_old]
1333
    @@: mov ecx, edx
1538
    @@: mov ecx, edx
1334
    shr ecx, 2
1539
    shr ecx, 2
1335
    rep movsd
1540
    rep movsd
1336
    mov ecx, edx
1541
    mov ecx, edx
1337
    and ecx, 3
1542
    and ecx, 3
1338
    rep movsb
1543
    rep movsb
1339
    add esi, 1
1544
    add esi, 1
1340
    sub eax, 1
1545
    sub eax, 1
1341
    jnz @b
1546
    jnz @b
1342
 
1547
 
1343
    mov eax, [scanline_len_new]
1548
    mov eax, [scanline_len_new]
1344
    sub [pixels_ptr], eax
1549
    sub [pixels_ptr], eax
1345
    mov ecx, [scanline_pixels_new]
1550
    mov ecx, [scanline_pixels_new]
1346
    mov esi, [line_buffer]
1551
    mov esi, [line_buffer]
1347
    mov edi, [pixels_ptr]
1552
    mov edi, [pixels_ptr]
1348
    mov edx, ecx
1553
    mov edx, ecx
1349
    shr ecx, 2
1554
    shr ecx, 2
1350
    rep movsd
1555
    rep movsd
1351
    mov ecx, edx
1556
    mov ecx, edx
1352
    and ecx, 3
1557
    and ecx, 3
1353
    rep movsb
1558
    rep movsb
1354
 
1559
 
1355
    pop ecx
1560
    pop ecx
1356
    jmp .next_column_ccw_low8ig
1561
    jmp .next_column_ccw_low8ig
1357
 
1562
 
1358
.rotate_ccw24:
1563
.rotate_ccw24:
1359
  .next_column_ccw_low24:
1564
  .next_column_ccw_low24:
1360
    dec ecx
1565
    dec ecx
1361
    js  .exchange_dims
1566
    js  .exchange_dims
1362
    push    ecx
1567
    push    ecx
1363
 
1568
 
1364
    mov edx, [scanline_len_old]
1569
    mov edx, [scanline_len_old]
1365
    add [scanline_len_old], -3
1570
    add [scanline_len_old], -3
1366
 
1571
 
1367
    mov ecx, [scanline_pixels_new]
1572
    mov ecx, [scanline_pixels_new]
1368
    mov esi, [ebx + Image.Data]
1573
    mov esi, [ebx + Image.Data]
1369
    mov edi, [line_buffer]
1574
    mov edi, [line_buffer]
1370
    @@: mov al, [esi]
1575
    @@: mov al, [esi]
1371
    mov [edi], al
1576
    mov [edi], al
1372
    mov al, [esi+1]
1577
    mov al, [esi+1]
1373
    mov [edi+1], al
1578
    mov [edi+1], al
1374
    mov al, [esi+2]
1579
    mov al, [esi+2]
1375
    mov [edi+2], al
1580
    mov [edi+2], al
1376
    add esi, edx
1581
    add esi, edx
1377
    add edi, 3
1582
    add edi, 3
1378
    sub ecx, 1
1583
    sub ecx, 1
1379
    jnz @b
1584
    jnz @b
1380
 
1585
 
1381
    mov eax, [scanline_pixels_new]
1586
    mov eax, [scanline_pixels_new]
1382
    mov edi, [ebx + Image.Data]
1587
    mov edi, [ebx + Image.Data]
1383
    lea esi, [edi + 3]
1588
    lea esi, [edi + 3]
1384
    mov edx, [scanline_len_old]
1589
    mov edx, [scanline_len_old]
1385
    @@: mov ecx, edx
1590
    @@: mov ecx, edx
1386
    shr ecx, 2
1591
    shr ecx, 2
1387
    rep movsd
1592
    rep movsd
1388
    mov ecx, edx
1593
    mov ecx, edx
1389
    and ecx, 3
1594
    and ecx, 3
1390
    rep movsb
1595
    rep movsb
1391
    add esi, 3
1596
    add esi, 3
1392
    sub eax, 1
1597
    sub eax, 1
1393
    jnz @b
1598
    jnz @b
1394
 
1599
 
1395
    mov eax, [scanline_len_new]
1600
    mov eax, [scanline_len_new]
1396
    sub [pixels_ptr], eax
1601
    sub [pixels_ptr], eax
1397
    mov ecx, eax
1602
    mov ecx, eax
1398
    mov esi, [line_buffer]
1603
    mov esi, [line_buffer]
1399
    mov edi, [pixels_ptr]
1604
    mov edi, [pixels_ptr]
1400
    shr ecx, 2
1605
    shr ecx, 2
1401
    rep movsd
1606
    rep movsd
1402
    mov ecx, eax
1607
    mov ecx, eax
1403
    and ecx, 3
1608
    and ecx, 3
1404
    rep movsb
1609
    rep movsb
1405
 
1610
 
1406
    pop ecx
1611
    pop ecx
1407
    jmp .next_column_ccw_low24
1612
    jmp .next_column_ccw_low24
1408
 
1613
 
1409
.rotate_ccw1:
1614
.rotate_ccw1:
1410
    push ecx edx
1615
    push ecx edx
1411
 
1616
 
1412
    mov eax, [ebx+Image.Height]
1617
    mov eax, [ebx + Image.Height]
1413
    add eax, 7
1618
    add eax, 7
1414
    shr eax, 3
1619
    shr eax, 3
1415
    mul word[ebx+Image.Width]
1620
    imul eax, [ebx + Image.Width]
1416
    shl eax, 16
-
 
1417
    shrd eax, edx, 16
-
 
1418
    push eax                                            ; save new data size
1621
    push eax                                            ; save new data size
1419
 
1622
 
1420
    invoke  mem.alloc, eax
1623
    invoke  mem.alloc, eax
1421
    or  eax, eax
1624
    or  eax, eax
1422
    jz  .error
1625
    jz  .error
1423
    push eax                                            ; save pointer to new data
1626
    push eax                                            ; save pointer to new data
1424
 
1627
 
1425
    mov ecx, [ebx+Image.Width]
1628
    mov ecx, [ebx + Image.Width]
1426
    and ecx,  0x07
1629
    and ecx, 7
1427
    neg cl
1630
    neg ecx
1428
    add cl, 8
1631
    add ecx, 8
1429
    and cl, 0x07                                        ; clear if cl=8
1632
    and ecx, 7
1430
 
1633
 
1431
    mov esi, eax
1634
    mov edi, eax
1432
    mov edi, [ebx+Image.Data]
1635
    mov esi, [ebx + Image.Data]
1433
    mov eax, 7
1636
    mov eax, 7
1434
    mov edx, [scanline_len_old]
1637
    mov edx, [scanline_len_old]
1435
    dec edx
1638
    dec edx
1436
    add edi, edx
1639
    add esi, edx
1437
 
1640
 
1438
  .rotate_ccw1.begin:
1641
  .rotate_ccw1.begin:
1439
    bt  [edi], ecx
1642
    bt  [esi], ecx
1440
     jc .rotate_ccw1.one
1643
    jc .rotate_ccw1.one
1441
  .rotate_ccw1.zero:
1644
  .rotate_ccw1.zero:
1442
    btr [esi], eax
1645
    btr [edi], eax
1443
     jmp @f
1646
    jmp @f
1444
  .rotate_ccw1.one:
1647
  .rotate_ccw1.one:
1445
    bts [esi], eax
1648
    bts [edi], eax
1446
  @@:
1649
  @@:
1447
    add edi, [scanline_len_old]
1650
    add esi, [scanline_len_old]
1448
    dec [scanline_pixels_new]
1651
    dec [scanline_pixels_new]
1449
     jz .rotate_ccw1.end_of_line
1652
    jz .rotate_ccw1.end_of_line
1450
    dec eax
-
 
1451
     jns .rotate_ccw1.begin
1653
    sub eax, 1
1452
    mov eax, 7
1654
    adc edi, 0
1453
    inc esi
1655
    and eax, 7
1454
     jmp .rotate_ccw1.begin
-
 
1455
 
1656
    jmp .rotate_ccw1.begin
1456
  .rotate_ccw1.end_of_line:
1657
  .rotate_ccw1.end_of_line:
-
 
1658
    inc edi
-
 
1659
    mov eax, [ebx + Image.Height]
1457
    inc esi
1660
    mov [scanline_pixels_new], eax
1458
    mov eax, 7
-
 
1459
    mov edi, [ebx+Image.Height]
-
 
1460
    mov [scanline_pixels_new],  edi
1661
    mov eax, 7
1461
    inc ecx
1662
    inc ecx
1462
    and cl, 0x07
1663
    and ecx, 7
1463
     jz @f
1664
    jz @f
1464
    mov edi, [ebx+Image.Data]
1665
    mov esi, [ebx + Image.Data]
1465
    add edi, edx
1666
    add esi, edx
1466
     jmp .rotate_ccw1.begin 
1667
    jmp .rotate_ccw1.begin 
1467
  @@:
1668
  @@:
1468
    dec edx
1669
    dec edx
1469
     js .rotate_ccw1.quit
1670
    js .rotate_ccw1.quit
1470
    mov edi, [ebx+Image.Data]
1671
    mov esi, [ebx + Image.Data]
1471
    add edi, edx
1672
    add esi, edx
1472
     jmp .rotate_ccw1.begin
1673
    jmp .rotate_ccw1.begin
1473
 
-
 
1474
  .rotate_ccw1.quit:
1674
  .rotate_ccw1.quit:
1475
    pop eax                                             ; get pointer to new data
1675
    pop esi                                             ; get pointer to new data
1476
    mov esi, eax
-
 
1477
    mov edi, [ebx + Image.Data]
1676
    mov edi, [ebx + Image.Data]
1478
    pop ecx                                             ; get new data size
1677
    pop ecx                                             ; get new data size
1479
    rep movsb
1678
    rep movsb
-
 
1679
    invoke  mem.free, esi
-
 
1680
    pop edx ecx
-
 
1681
     jmp .exchange_dims
1480
 
-
 
-
 
1682
 
-
 
1683
 
-
 
1684
.rotate_ccw2i:
-
 
1685
    push ecx edx
-
 
1686
 
-
 
1687
    mov eax, [ebx + Image.Height]
-
 
1688
    add eax, 3
-
 
1689
    shr eax, 2
-
 
1690
    imul eax, [ebx + Image.Width]
-
 
1691
    push eax                                            ; save new data size
-
 
1692
 
-
 
1693
    invoke  mem.alloc, eax
-
 
1694
    or  eax, eax
-
 
1695
    jz  .error
-
 
1696
    push eax                                            ; save pointer to new data
-
 
1697
 
-
 
1698
    mov ecx, [ebx + Image.Width]
-
 
1699
    and ecx, 3
-
 
1700
    neg ecx
-
 
1701
    add ecx, 4
-
 
1702
    and ecx, 3
-
 
1703
 
-
 
1704
    mov edi, eax
-
 
1705
    mov esi, [ebx + Image.Data]
-
 
1706
    mov eax, 3
-
 
1707
    mov edx, [scanline_len_old]
-
 
1708
    dec edx
-
 
1709
    add esi, edx
-
 
1710
 
-
 
1711
  .rotate_ccw2i.begin:
-
 
1712
    push ebx ecx
-
 
1713
    mov ebx, 3
-
 
1714
    shl ebx, cl
-
 
1715
    shl ebx, cl
-
 
1716
    and bl, [esi]
-
 
1717
    shr ebx, cl
-
 
1718
    shr ebx, cl
-
 
1719
    mov bh, 3
-
 
1720
    mov ecx, eax
-
 
1721
    shl ebx, cl
-
 
1722
    shl ebx, cl
-
 
1723
    not bh
-
 
1724
    and bh, [edi]
-
 
1725
    or  bl, bh
-
 
1726
    mov [edi], bl
-
 
1727
    pop ecx ebx
-
 
1728
 
-
 
1729
    add esi, [scanline_len_old]
-
 
1730
    dec [scanline_pixels_new]
-
 
1731
    jz .rotate_ccw2i.end_of_line
-
 
1732
    sub eax, 1
-
 
1733
    adc edi, 0
-
 
1734
    and eax, 3
-
 
1735
    jmp .rotate_ccw2i.begin
-
 
1736
  .rotate_ccw2i.end_of_line:
-
 
1737
    inc edi
-
 
1738
    mov eax, 3
-
 
1739
    mov esi, [ebx + Image.Height]
-
 
1740
    mov [scanline_pixels_new], esi
-
 
1741
    inc ecx
-
 
1742
    and ecx, 3
-
 
1743
    jz @f
-
 
1744
    mov esi, [ebx + Image.Data]
-
 
1745
    add esi, edx
-
 
1746
    jmp .rotate_ccw2i.begin 
-
 
1747
  @@:
-
 
1748
    dec edx
-
 
1749
    js .rotate_ccw2i.quit
-
 
1750
    mov esi, [ebx + Image.Data]
-
 
1751
    add esi, edx
-
 
1752
    jmp .rotate_ccw2i.begin
-
 
1753
  .rotate_ccw2i.quit:
-
 
1754
    pop esi                                             ; get pointer to new data
-
 
1755
    mov edi, [ebx + Image.Data]
-
 
1756
    pop ecx                                             ; get new data size
-
 
1757
    rep movsb
-
 
1758
    invoke  mem.free, esi
-
 
1759
    pop edx ecx
-
 
1760
     jmp .exchange_dims
-
 
1761
 
-
 
1762
 
-
 
1763
.rotate_ccw4i:
-
 
1764
    push ecx edx
-
 
1765
 
-
 
1766
    mov eax, [ebx + Image.Height]
-
 
1767
    add eax, 1
-
 
1768
    shr eax, 1
-
 
1769
    imul eax, [ebx + Image.Width]
-
 
1770
    push eax                                            ; save new data size
-
 
1771
 
-
 
1772
    invoke  mem.alloc, eax
-
 
1773
    or  eax, eax
-
 
1774
    jz  .error
-
 
1775
    push eax                                            ; save pointer to new data
-
 
1776
 
-
 
1777
    mov ecx, [ebx + Image.Width]
-
 
1778
    and ecx, 1
-
 
1779
    neg ecx
-
 
1780
    add ecx, 2
-
 
1781
    and ecx, 1
-
 
1782
 
-
 
1783
    mov edi, eax
-
 
1784
    mov esi, [ebx + Image.Data]
-
 
1785
    mov eax, 1
-
 
1786
    mov edx, [scanline_len_old]
-
 
1787
    dec edx
-
 
1788
    add esi, edx
-
 
1789
 
-
 
1790
  .rotate_ccw4i.begin:
-
 
1791
    push ebx ecx
-
 
1792
    mov ebx, 15
-
 
1793
    shl ecx, 2
-
 
1794
    shl ebx, cl
-
 
1795
    and bl, [esi]
-
 
1796
    shr ebx, cl
-
 
1797
    mov bh, 15
-
 
1798
    mov ecx, eax
-
 
1799
    shl ecx, 2
-
 
1800
    shl ebx, cl
-
 
1801
    not bh
-
 
1802
    and bh, [edi]
-
 
1803
    or  bl, bh
-
 
1804
    mov [edi], bl
-
 
1805
    pop ecx ebx
-
 
1806
 
-
 
1807
    add esi, [scanline_len_old]
-
 
1808
    dec [scanline_pixels_new]
-
 
1809
    jz .rotate_ccw4i.end_of_line
-
 
1810
    sub eax, 1
-
 
1811
    adc edi, 0
-
 
1812
    and eax, 1
-
 
1813
    jmp .rotate_ccw4i.begin
-
 
1814
  .rotate_ccw4i.end_of_line:
-
 
1815
    inc edi
-
 
1816
    mov eax, 1
-
 
1817
    mov esi, [ebx + Image.Height]
-
 
1818
    mov [scanline_pixels_new], esi
-
 
1819
    inc ecx
-
 
1820
    and ecx, 1
-
 
1821
    jz @f
-
 
1822
    mov esi, [ebx + Image.Data]
-
 
1823
    add esi, edx
-
 
1824
    jmp .rotate_ccw4i.begin 
-
 
1825
  @@:
-
 
1826
    dec edx
-
 
1827
    js .rotate_ccw4i.quit
-
 
1828
    mov esi, [ebx + Image.Data]
-
 
1829
    add esi, edx
-
 
1830
    jmp .rotate_ccw4i.begin
-
 
1831
  .rotate_ccw4i.quit:
-
 
1832
    pop esi                                             ; get pointer to new data
-
 
1833
    mov edi, [ebx + Image.Data]
-
 
1834
    pop ecx                                             ; get new data size
1481
    invoke  mem.free, eax
1835
    rep movsb
1482
 
1836
    invoke  mem.free, esi
1483
    pop edx ecx
1837
    pop edx ecx
1484
     jmp .exchange_dims
1838
     jmp .exchange_dims
-
 
1839
 
-
 
1840
 
1485
 
1841
 
1486
  .rotate_cw_low:
1842
  .rotate_cw_low:
1487
    mov eax, [ebx + Image.Height]
1843
    mov eax, [ebx + Image.Height]
1488
    mov [scanline_pixels_new], eax
1844
    mov [scanline_pixels_new], eax
1489
    call    img._.get_scanline_len
1845
    call    img._.get_scanline_len
1490
    mov [scanline_len_new], eax
1846
    mov [scanline_len_new], eax
1491
 
1847
 
1492
    invoke  mem.alloc, eax
1848
    invoke  mem.alloc, eax
1493
    or  eax, eax
1849
    or  eax, eax
1494
    jz  .error
1850
    jz  .error
1495
    mov [line_buffer], eax
1851
    mov [line_buffer], eax
1496
 
1852
 
1497
    mov eax, [ebx + Image.Width]
1853
    mov eax, [ebx + Image.Width]
1498
    mov ecx, eax
1854
    mov ecx, eax
1499
    call    img._.get_scanline_len
1855
    call    img._.get_scanline_len
1500
    mov [scanline_len_old], eax
1856
    mov [scanline_len_old], eax
1501
 
1857
 
1502
    mov eax, [scanline_len_new]
1858
    mov eax, [scanline_len_new]
1503
    imul    eax, ecx
1859
    imul    eax, ecx
1504
    add eax, [ebx + Image.Data]
1860
    add eax, [ebx + Image.Data]
1505
    mov [pixels_ptr], eax
1861
    mov [pixels_ptr], eax
1506
 
1862
 
1507
    cmp [ebx + Image.Type], Image.bpp1
1863
    cmp [ebx + Image.Type], Image.bpp1
1508
    jz  .rotate_cw1
1864
    jz  .rotate_cw1
-
 
1865
    cmp [ebx + Image.Type], Image.bpp2i
-
 
1866
    jz  .rotate_cw2i
-
 
1867
    cmp [ebx + Image.Type], Image.bpp4i
-
 
1868
    jz  .rotate_cw4i
1509
    cmp [ebx + Image.Type], Image.bpp8i
1869
    cmp [ebx + Image.Type], Image.bpp8i
1510
    jz  .rotate_cw8ig
1870
    jz  .rotate_cw8ig
1511
    cmp [ebx + Image.Type], Image.bpp8g
1871
    cmp [ebx + Image.Type], Image.bpp8g
1512
    jz  .rotate_cw8ig
1872
    jz  .rotate_cw8ig
1513
    cmp [ebx + Image.Type], Image.bpp24
1873
    cmp [ebx + Image.Type], Image.bpp24
1514
    jz  .rotate_cw24
1874
    jz  .rotate_cw24
1515
    cmp [ebx + Image.Type], Image.bpp32
1875
    cmp [ebx + Image.Type], Image.bpp32
1516
    jz  .rotate_cw32
1876
    jz  .rotate_cw32
1517
 
1877
 
1518
  .next_column_cw_low1x:
1878
  .next_column_cw_low1x:
1519
    dec ecx
1879
    dec ecx
1520
    js  .exchange_dims
1880
    js  .exchange_dims
1521
    push    ecx
1881
    push    ecx
1522
 
1882
 
1523
    mov edx, [scanline_len_old]
1883
    mov edx, [scanline_len_old]
1524
    add [scanline_len_old], -2
1884
    add [scanline_len_old], -2
1525
 
1885
 
1526
    mov ecx, [scanline_pixels_new]
1886
    mov ecx, [scanline_pixels_new]
1527
    mov esi, [pixels_ptr]
1887
    mov esi, [pixels_ptr]
1528
    add esi, -2
1888
    add esi, -2
1529
    mov edi, [line_buffer]
1889
    mov edi, [line_buffer]
1530
    @@: mov ax, [esi]
1890
    @@: mov ax, [esi]
1531
    mov [edi], ax
1891
    mov [edi], ax
1532
    sub esi, edx
1892
    sub esi, edx
1533
    add edi, 2
1893
    add edi, 2
1534
    sub ecx, 1
1894
    sub ecx, 1
1535
    jnz @b
1895
    jnz @b
1536
 
1896
 
1537
    mov eax, [scanline_pixels_new]
1897
    mov eax, [scanline_pixels_new]
1538
    dec eax
1898
    dec eax
1539
    mov edi, [ebx + Image.Data]
1899
    mov edi, [ebx + Image.Data]
1540
    add edi, [scanline_len_old]
1900
    add edi, [scanline_len_old]
1541
    lea esi, [edi + 2]
1901
    lea esi, [edi + 2]
1542
    mov edx, [scanline_len_old]
1902
    mov edx, [scanline_len_old]
1543
    @@: mov ecx, edx
1903
    @@: mov ecx, edx
1544
    shr ecx, 2
1904
    shr ecx, 2
1545
    rep movsd
1905
    rep movsd
1546
    mov ecx, edx
1906
    mov ecx, edx
1547
    and ecx, 3
1907
    and ecx, 3
1548
    rep movsb
1908
    rep movsb
1549
    add esi, 3
1909
    add esi, 3
1550
    sub eax, 1
1910
    sub eax, 1
1551
    jnz @b
1911
    jnz @b
1552
 
1912
 
1553
    mov eax, [scanline_len_new]
1913
    mov eax, [scanline_len_new]
1554
    sub [pixels_ptr], eax
1914
    sub [pixels_ptr], eax
1555
    mov ecx, eax
1915
    mov ecx, eax
1556
    mov esi, [line_buffer]
1916
    mov esi, [line_buffer]
1557
    mov edi, [pixels_ptr]
1917
    mov edi, [pixels_ptr]
1558
    shr ecx, 2
1918
    shr ecx, 2
1559
    rep movsd
1919
    rep movsd
1560
    mov ecx, eax
1920
    mov ecx, eax
1561
    and ecx, 3
1921
    and ecx, 3
1562
    rep movsb
1922
    rep movsb
1563
 
1923
 
1564
    pop ecx
1924
    pop ecx
1565
    jmp .next_column_cw_low1x
1925
    jmp .next_column_cw_low1x
1566
 
1926
 
1567
.rotate_cw32:
1927
.rotate_cw32:
1568
  .next_column_cw_low:
1928
  .next_column_cw_low:
1569
    dec ecx
1929
    dec ecx
1570
    js  .exchange_dims
1930
    js  .exchange_dims
1571
    push    ecx
1931
    push    ecx
1572
 
1932
 
1573
    mov edx, [scanline_len_old]
1933
    mov edx, [scanline_len_old]
1574
    add [scanline_len_old], -4
1934
    add [scanline_len_old], -4
1575
 
1935
 
1576
    mov ecx, [scanline_pixels_new]
1936
    mov ecx, [scanline_pixels_new]
1577
    mov esi, [pixels_ptr]
1937
    mov esi, [pixels_ptr]
1578
    add esi, -4
1938
    add esi, -4
1579
    mov edi, [line_buffer]
1939
    mov edi, [line_buffer]
1580
    @@: mov eax, [esi]
1940
    @@: mov eax, [esi]
1581
    stosd
1941
    stosd
1582
    sub esi, edx
1942
    sub esi, edx
1583
    dec ecx
1943
    dec ecx
1584
    jnz @b
1944
    jnz @b
1585
 
1945
 
1586
    mov eax, [scanline_pixels_new]
1946
    mov eax, [scanline_pixels_new]
1587
    dec eax
1947
    dec eax
1588
    mov edi, [ebx + Image.Data]
1948
    mov edi, [ebx + Image.Data]
1589
    add edi, [scanline_len_old]
1949
    add edi, [scanline_len_old]
1590
    lea esi, [edi + 4]
1950
    lea esi, [edi + 4]
1591
    mov edx, [scanline_len_old]
1951
    mov edx, [scanline_len_old]
1592
    shr edx, 2
1952
    shr edx, 2
1593
    @@: mov ecx, edx
1953
    @@: mov ecx, edx
1594
    rep movsd
1954
    rep movsd
1595
    add esi, 4
1955
    add esi, 4
1596
    dec eax
1956
    dec eax
1597
    jnz @b
1957
    jnz @b
1598
 
1958
 
1599
    mov eax, [scanline_len_new]
1959
    mov eax, [scanline_len_new]
1600
    sub [pixels_ptr], eax
1960
    sub [pixels_ptr], eax
1601
    mov ecx, [scanline_pixels_new]
1961
    mov ecx, [scanline_pixels_new]
1602
    mov esi, [line_buffer]
1962
    mov esi, [line_buffer]
1603
    mov edi, [pixels_ptr]
1963
    mov edi, [pixels_ptr]
1604
    rep movsd
1964
    rep movsd
1605
 
1965
 
1606
    pop ecx
1966
    pop ecx
1607
    jmp .next_column_cw_low
1967
    jmp .next_column_cw_low
1608
 
1968
 
1609
.rotate_cw8ig:
1969
.rotate_cw8ig:
1610
  .next_column_cw_low8ig:
1970
  .next_column_cw_low8ig:
1611
    dec ecx
1971
    dec ecx
1612
    js  .exchange_dims
1972
    js  .exchange_dims
1613
    push    ecx
1973
    push    ecx
1614
 
1974
 
1615
    mov edx, [scanline_len_old]
1975
    mov edx, [scanline_len_old]
1616
    add [scanline_len_old], -1
1976
    add [scanline_len_old], -1
1617
 
1977
 
1618
    mov ecx, [scanline_pixels_new]
1978
    mov ecx, [scanline_pixels_new]
1619
    mov esi, [pixels_ptr]
1979
    mov esi, [pixels_ptr]
1620
    add esi, -1
1980
    add esi, -1
1621
    mov edi, [line_buffer]
1981
    mov edi, [line_buffer]
1622
    @@: mov al, [esi]
1982
    @@: mov al, [esi]
1623
    mov [edi], al
1983
    mov [edi], al
1624
    sub esi, edx
1984
    sub esi, edx
1625
    add edi, 1
1985
    add edi, 1
1626
    sub ecx, 1
1986
    sub ecx, 1
1627
    jnz @b
1987
    jnz @b
1628
 
1988
 
1629
    mov eax, [scanline_pixels_new]
1989
    mov eax, [scanline_pixels_new]
1630
    dec eax
1990
    dec eax
1631
    mov edi, [ebx + Image.Data]
1991
    mov edi, [ebx + Image.Data]
1632
    add edi, [scanline_len_old]
1992
    add edi, [scanline_len_old]
1633
    lea esi, [edi + 1]
1993
    lea esi, [edi + 1]
1634
    mov edx, [scanline_len_old]
1994
    mov edx, [scanline_len_old]
1635
    @@: mov ecx, edx
1995
    @@: mov ecx, edx
1636
    shr ecx, 2
1996
    shr ecx, 2
1637
    rep movsd
1997
    rep movsd
1638
    mov ecx, edx
1998
    mov ecx, edx
1639
    and ecx, 3
1999
    and ecx, 3
1640
    rep movsb
2000
    rep movsb
1641
    add esi, 1
2001
    add esi, 1
1642
    sub eax, 1
2002
    sub eax, 1
1643
    jnz @b
2003
    jnz @b
1644
 
2004
 
1645
    mov eax, [scanline_len_new]
2005
    mov eax, [scanline_len_new]
1646
    sub [pixels_ptr], eax
2006
    sub [pixels_ptr], eax
1647
    mov ecx, eax
2007
    mov ecx, eax
1648
    mov esi, [line_buffer]
2008
    mov esi, [line_buffer]
1649
    mov edi, [pixels_ptr]
2009
    mov edi, [pixels_ptr]
1650
    shr ecx, 2
2010
    shr ecx, 2
1651
    rep movsd
2011
    rep movsd
1652
    mov ecx, eax
2012
    mov ecx, eax
1653
    and ecx, 3
2013
    and ecx, 3
1654
    rep movsb
2014
    rep movsb
1655
 
2015
 
1656
    pop ecx
2016
    pop ecx
1657
    jmp .next_column_cw_low8ig
2017
    jmp .next_column_cw_low8ig
1658
 
2018
 
1659
.rotate_cw24:
2019
.rotate_cw24:
1660
  .next_column_cw_low24:
2020
  .next_column_cw_low24:
1661
    dec ecx
2021
    dec ecx
1662
    js  .exchange_dims
2022
    js  .exchange_dims
1663
    push    ecx
2023
    push    ecx
1664
 
2024
 
1665
    mov edx, [scanline_len_old]
2025
    mov edx, [scanline_len_old]
1666
    add [scanline_len_old], -3
2026
    add [scanline_len_old], -3
1667
 
2027
 
1668
    mov ecx, [scanline_pixels_new]
2028
    mov ecx, [scanline_pixels_new]
1669
    mov esi, [pixels_ptr]
2029
    mov esi, [pixels_ptr]
1670
    add esi, -3
2030
    add esi, -3
1671
    mov edi, [line_buffer]
2031
    mov edi, [line_buffer]
1672
    @@: mov al, [esi]
2032
    @@: mov al, [esi]
1673
    mov [edi], al
2033
    mov [edi], al
1674
    mov al, [esi+1]
2034
    mov al, [esi+1]
1675
    mov [edi+1], al
2035
    mov [edi+1], al
1676
    mov al, [esi+2]
2036
    mov al, [esi+2]
1677
    mov [edi+2], al
2037
    mov [edi+2], al
1678
    sub esi, edx
2038
    sub esi, edx
1679
    add edi, 3
2039
    add edi, 3
1680
    sub ecx, 1
2040
    sub ecx, 1
1681
    jnz @b
2041
    jnz @b
1682
 
2042
 
1683
    mov eax, [scanline_pixels_new]
2043
    mov eax, [scanline_pixels_new]
1684
    dec eax
2044
    dec eax
1685
    mov edi, [ebx + Image.Data]
2045
    mov edi, [ebx + Image.Data]
1686
    add edi, [scanline_len_old]
2046
    add edi, [scanline_len_old]
1687
    lea esi, [edi + 3]
2047
    lea esi, [edi + 3]
1688
    mov edx, [scanline_len_old]
2048
    mov edx, [scanline_len_old]
1689
    @@: mov ecx, edx
2049
    @@: mov ecx, edx
1690
    shr ecx, 2
2050
    shr ecx, 2
1691
    rep movsd
2051
    rep movsd
1692
    mov ecx, edx
2052
    mov ecx, edx
1693
    and ecx, 3
2053
    and ecx, 3
1694
    rep movsb
2054
    rep movsb
1695
    add esi, 3
2055
    add esi, 3
1696
    sub eax, 1
2056
    sub eax, 1
1697
    jnz @b
2057
    jnz @b
1698
 
2058
 
1699
    mov eax, [scanline_len_new]
2059
    mov eax, [scanline_len_new]
1700
    sub [pixels_ptr], eax
2060
    sub [pixels_ptr], eax
1701
    mov ecx, eax
2061
    mov ecx, eax
1702
    mov esi, [line_buffer]
2062
    mov esi, [line_buffer]
1703
    mov edi, [pixels_ptr]
2063
    mov edi, [pixels_ptr]
1704
    shr ecx, 2
2064
    shr ecx, 2
1705
    rep movsd
2065
    rep movsd
1706
    mov ecx, eax
2066
    mov ecx, eax
1707
    and ecx, 3
2067
    and ecx, 3
1708
    rep movsb
2068
    rep movsb
1709
 
2069
 
1710
    pop ecx
2070
    pop ecx
1711
    jmp .next_column_cw_low24
2071
    jmp .next_column_cw_low24
-
 
2072
 
1712
 
2073
 
1713
.rotate_cw1:
2074
.rotate_cw1:
1714
    push ecx edx
2075
    push ecx edx
1715
 
2076
 
1716
    mov eax, [ebx+Image.Height]
2077
    mov eax, [ebx + Image.Height]
1717
    add eax, 7
2078
    add eax, 7
1718
    shr eax, 3
2079
    shr eax, 3
1719
    mul word[ebx+Image.Width]
2080
    imul [ebx + Image.Width]
1720
    shl eax, 16
-
 
1721
    shrd eax, edx, 16
-
 
1722
 
-
 
1723
    push eax                                            ; save new data size
2081
    push eax                                            ; save new data size
1724
 
2082
 
1725
    invoke  mem.alloc, eax
2083
    invoke  mem.alloc, eax
1726
    or  eax, eax
2084
    or  eax, eax
1727
    jz  .error
2085
    jz  .error
1728
    push eax                                            ; save pointer to new data
2086
    push eax                                            ; save pointer to new data
1729
 
-
 
1730
    mov ecx, 7
-
 
1731
 
-
 
1732
    mov edx, [ebx+Image.Width]
-
 
1733
    mov [pixels_ptr],   edx                             ; we don't use pixels_ptr as it do other procedures, we save there [ebx+Image.Width]
2087
 
1734
    mov esi, eax
2088
    mov edi, eax
1735
    mov edi, [ebx+Image.Data]
2089
    mov esi, [ebx + Image.Data]
1736
    mov eax, [ebx+Image.Height]
2090
    mov eax, [ebx + Image.Height]
1737
    dec eax
2091
    dec eax
1738
    mul [scanline_len_old]
2092
    imul eax, [scanline_len_old]
1739
    add edi, eax
2093
    add esi, eax
-
 
2094
    mov eax, 7
1740
    mov eax, 7
2095
    mov ecx, 7
1741
    mov edx, 0
2096
    mov edx, 0
1742
 
2097
 
1743
  .rotate_cw1.begin:
2098
  .rotate_cw1.begin:
1744
    bt  [edi], ecx
2099
    bt  [esi], ecx
1745
     jc .rotate_cw1.one
2100
    jc .rotate_cw1.one
1746
  .rotate_cw1.zero:
2101
  .rotate_cw1.zero:
1747
    btr [esi], eax
2102
    btr [edi], eax
1748
     jmp @f
2103
    jmp @f
1749
  .rotate_cw1.one:
2104
  .rotate_cw1.one:
1750
    bts [esi], eax
2105
    bts [edi], eax
1751
  @@:
2106
  @@:
1752
    sub edi, [scanline_len_old]
2107
    sub esi, [scanline_len_old]
1753
    dec [scanline_pixels_new]
2108
    dec [scanline_pixels_new]
1754
     jz .rotate_cw1.end_of_line
2109
    jz  .rotate_cw1.end_of_line
1755
    dec eax
2110
    sub eax, 1
1756
     jns .rotate_cw1.begin
-
 
1757
    mov eax, 7
2111
    adc edi, 0
1758
    inc esi
2112
    and eax, 7
1759
     jmp .rotate_cw1.begin
2113
    jmp .rotate_cw1.begin
1760
 
-
 
1761
  .rotate_cw1.end_of_line:
2114
  .rotate_cw1.end_of_line:
1762
    dec [pixels_ptr]
-
 
1763
     jz .rotate_cw1.quit
-
 
1764
    inc esi
2115
    inc edi
1765
    mov eax, [ebx+Image.Height]
2116
    mov eax, [ebx + Image.Height]
1766
    mov [scanline_pixels_new],   eax
2117
    mov [scanline_pixels_new],   eax
1767
    mov eax, 7
2118
    mov eax, 7
1768
    dec ecx
2119
    dec ecx
1769
     js @f
2120
    jns @f
1770
    mov edi, [ebx+Image.Height]
-
 
1771
    dec edi
-
 
1772
    imul edi, [scanline_len_old]
-
 
1773
    add edi, [ebx+Image.Data]
-
 
1774
    add edi, edx
-
 
1775
     jmp .rotate_cw1.begin
-
 
1776
  @@:
-
 
1777
    mov ecx, 7
2121
    mov ecx, 7
1778
    inc edx
2122
    inc edx
1779
    cmp edx, [scanline_len_old]
2123
    cmp edx, [scanline_len_old]
1780
     je .rotate_cw1.quit
2124
    je .rotate_cw1.quit
-
 
2125
  @@:
1781
    mov edi, [ebx+Image.Height]
2126
    mov esi, [ebx + Image.Height]
1782
    dec edi
2127
    dec esi
1783
    imul edi, [scanline_len_old]
2128
    imul esi, [scanline_len_old]
1784
    add edi, [ebx+Image.Data]
2129
    add esi, [ebx + Image.Data]
1785
    add edi, edx
2130
    add esi, edx
1786
     jmp .rotate_cw1.begin
2131
    jmp .rotate_cw1.begin
1787
 
-
 
1788
  .rotate_cw1.quit:
2132
  .rotate_cw1.quit:
1789
    pop eax                                             ; get pointer to new data
2133
    pop eax                                             ; get pointer to new data
1790
    mov esi, eax
2134
    mov esi, eax
1791
    mov edi, [ebx + Image.Data]
2135
    mov edi, [ebx + Image.Data]
1792
    pop ecx                                             ; get new data size
2136
    pop ecx                                             ; get new data size
1793
    rep movsb
2137
    rep movsb
-
 
2138
    invoke  mem.free, eax
-
 
2139
    pop edx ecx
-
 
2140
    jmp .exchange_dims
-
 
2141
 
-
 
2142
 
-
 
2143
.rotate_cw2i:
-
 
2144
    push ecx edx
-
 
2145
 
-
 
2146
    mov eax, [ebx + Image.Height]
-
 
2147
    add eax, 3
-
 
2148
    shr eax, 2
-
 
2149
    imul [ebx + Image.Width]
-
 
2150
    push eax                                            ; save new data size
-
 
2151
 
-
 
2152
    invoke  mem.alloc, eax
-
 
2153
    or  eax, eax
-
 
2154
    jz  .error
-
 
2155
    push eax                                            ; save pointer to new data
-
 
2156
 
-
 
2157
    mov edi, eax
-
 
2158
    mov esi, [ebx + Image.Data]
-
 
2159
    mov eax, [ebx + Image.Height]
-
 
2160
    dec eax
-
 
2161
    imul eax, [scanline_len_old]
-
 
2162
    add esi, eax
-
 
2163
    mov eax, 3
-
 
2164
    mov ecx, 3
-
 
2165
    mov edx, 0
-
 
2166
 
-
 
2167
  .rotate_cw2i.begin:
-
 
2168
    push ebx ecx
-
 
2169
    mov ebx, 3
-
 
2170
    shl ebx, cl
-
 
2171
    shl ebx, cl
-
 
2172
    and bl, [esi]
-
 
2173
    shr ebx, cl
-
 
2174
    shr ebx, cl
-
 
2175
    mov bh, 3
-
 
2176
    mov ecx, eax
-
 
2177
    shl ebx, cl
-
 
2178
    shl ebx, cl
-
 
2179
    not bh
-
 
2180
    and bh, [edi]
-
 
2181
    or  bl, bh
-
 
2182
    mov [edi], bl
-
 
2183
    pop ecx ebx
-
 
2184
 
-
 
2185
    sub esi, [scanline_len_old]
-
 
2186
    dec [scanline_pixels_new]
-
 
2187
    jz  .rotate_cw2i.end_of_line
-
 
2188
    sub eax, 1
-
 
2189
    adc edi, 0
-
 
2190
    and eax, 3
-
 
2191
    jmp .rotate_cw2i.begin
-
 
2192
  .rotate_cw2i.end_of_line:
-
 
2193
    inc edi
-
 
2194
    mov eax, [ebx + Image.Height]
-
 
2195
    mov [scanline_pixels_new],   eax
-
 
2196
    mov eax, 3
-
 
2197
    dec ecx
-
 
2198
    jns @f
-
 
2199
    mov ecx, 3
-
 
2200
    inc edx
-
 
2201
    cmp edx, [scanline_len_old]
-
 
2202
    je .rotate_cw2i.quit
-
 
2203
  @@:
-
 
2204
    mov esi, [ebx + Image.Height]
-
 
2205
    dec esi
-
 
2206
    imul esi, [scanline_len_old]
-
 
2207
    add esi, [ebx + Image.Data]
-
 
2208
    add esi, edx
-
 
2209
    jmp .rotate_cw2i.begin
-
 
2210
  .rotate_cw2i.quit:
-
 
2211
    pop eax                                             ; get pointer to new data
-
 
2212
    mov esi, eax
-
 
2213
    mov edi, [ebx + Image.Data]
-
 
2214
    pop ecx                                             ; get new data size
1794
 
2215
    rep movsb
-
 
2216
    invoke  mem.free, eax
-
 
2217
    pop edx ecx
-
 
2218
    jmp .exchange_dims
-
 
2219
 
-
 
2220
 
-
 
2221
.rotate_cw4i:
-
 
2222
    push ecx edx
-
 
2223
 
-
 
2224
    mov eax, [ebx + Image.Height]
-
 
2225
    add eax, 1
-
 
2226
    shr eax, 1
-
 
2227
    imul [ebx + Image.Width]
-
 
2228
    push eax                                            ; save new data size
-
 
2229
 
-
 
2230
    invoke  mem.alloc, eax
-
 
2231
    or  eax, eax
-
 
2232
    jz  .error
-
 
2233
    push eax                                            ; save pointer to new data
-
 
2234
 
-
 
2235
    mov edi, eax
-
 
2236
    mov esi, [ebx + Image.Data]
-
 
2237
    mov eax, [ebx + Image.Height]
-
 
2238
    dec eax
-
 
2239
    imul eax, [scanline_len_old]
-
 
2240
    add esi, eax
-
 
2241
    mov eax, 1
-
 
2242
    mov ecx, 1
-
 
2243
    mov edx, 0
-
 
2244
 
-
 
2245
  .rotate_cw4i.begin:
-
 
2246
    push ebx ecx
-
 
2247
    mov ebx, 15
-
 
2248
    shl ecx, 2
-
 
2249
    shl ebx, cl
-
 
2250
    and bl, [esi]
-
 
2251
    shr ebx, cl
-
 
2252
    mov bh, 15
-
 
2253
    mov ecx, eax
-
 
2254
    shl ecx, 2
-
 
2255
    shl ebx, cl
-
 
2256
    not bh
-
 
2257
    and bh, [edi]
-
 
2258
    or  bl, bh
-
 
2259
    mov [edi], bl
-
 
2260
    pop ecx ebx
-
 
2261
 
-
 
2262
    sub esi, [scanline_len_old]
-
 
2263
    dec [scanline_pixels_new]
-
 
2264
    jz  .rotate_cw4i.end_of_line
-
 
2265
    sub eax, 1
-
 
2266
    adc edi, 0
-
 
2267
    and eax, 1
-
 
2268
    jmp .rotate_cw4i.begin
-
 
2269
  .rotate_cw4i.end_of_line:
-
 
2270
    inc edi
-
 
2271
    mov eax, [ebx + Image.Height]
-
 
2272
    mov [scanline_pixels_new],   eax
-
 
2273
    mov eax, 1
-
 
2274
    dec ecx
-
 
2275
    jns @f
-
 
2276
    mov ecx, 1
-
 
2277
    inc edx
-
 
2278
    cmp edx, [scanline_len_old]
-
 
2279
    je .rotate_cw4i.quit
-
 
2280
  @@:
-
 
2281
    mov esi, [ebx + Image.Height]
-
 
2282
    dec esi
-
 
2283
    imul esi, [scanline_len_old]
-
 
2284
    add esi, [ebx + Image.Data]
-
 
2285
    add esi, edx
-
 
2286
    jmp .rotate_cw4i.begin
-
 
2287
  .rotate_cw4i.quit:
-
 
2288
    pop eax                                             ; get pointer to new data
-
 
2289
    mov esi, eax
-
 
2290
    mov edi, [ebx + Image.Data]
-
 
2291
    pop ecx                                             ; get new data size
1795
    invoke  mem.free, eax
2292
    rep movsb
1796
 
2293
    invoke  mem.free, eax
1797
    pop edx ecx
2294
    pop edx ecx
1798
     jmp .exchange_dims
2295
    jmp .exchange_dims
-
 
2296
 
1799
 
2297
 
1800
  .flip:
2298
  .flip:
1801
    jmp .exit
2299
    jmp .exit
1802
 
2300
 
1803
  .exchange_dims:
2301
  .exchange_dims:
1804
    push    [ebx + Image.Width] [ebx + Image.Height]
2302
    push    [ebx + Image.Width] [ebx + Image.Height]
1805
    pop [ebx + Image.Width] [ebx + Image.Height]
2303
    pop [ebx + Image.Width] [ebx + Image.Height]
1806
 
2304
 
1807
  .exit:
2305
  .exit:
1808
    invoke  mem.free, [line_buffer]
2306
    invoke  mem.free, [line_buffer]
1809
    xor eax, eax
2307
    xor eax, eax
1810
    inc eax
2308
    inc eax
1811
    pop edi esi ebx
2309
    pop edi esi ebx
1812
    ret
2310
    ret
1813
 
2311
 
1814
  .error:
2312
  .error:
1815
    invoke  mem.free, [line_buffer]
2313
    invoke  mem.free, [line_buffer]
1816
    xor eax, eax
2314
    xor eax, eax
1817
    pop edi esi ebx
2315
    pop edi esi ebx
1818
    ret
2316
    ret
1819
endp
2317
endp
1820
 
2318
 
1821
;;================================================================================================;;
2319
;;================================================================================================;;
1822
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
2320
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
1823
;;------------------------------------------------------------------------------------------------;;
2321
;;------------------------------------------------------------------------------------------------;;
1824
;? Rotate all layers of image                                                                     ;;
2322
;? Rotate all layers of image                                                                     ;;
1825
;;------------------------------------------------------------------------------------------------;;
2323
;;------------------------------------------------------------------------------------------------;;
1826
;> _img = pointer to image                                                                        ;;
2324
;> _img = pointer to image                                                                        ;;
1827
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
2325
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
1828
;;------------------------------------------------------------------------------------------------;;
2326
;;------------------------------------------------------------------------------------------------;;
1829
;< eax = false / true                                                                             ;;
2327
;< eax = false / true                                                                             ;;
1830
;;================================================================================================;;
2328
;;================================================================================================;;
1831
    push    1
2329
    push    1
1832
    mov ebx, [_img]
2330
    mov ebx, [_img]
1833
@@:
2331
@@:
1834
    mov eax, [ebx + Image.Previous]
2332
    mov eax, [ebx + Image.Previous]
1835
    test    eax, eax
2333
    test    eax, eax
1836
    jz  .loop
2334
    jz  .loop
1837
    mov ebx, eax
2335
    mov ebx, eax
1838
    jmp @b
2336
    jmp @b
1839
.loop:
2337
.loop:
1840
    stdcall img.rotate.layer, ebx, [_rotate_kind]
2338
    stdcall img.rotate.layer, ebx, [_rotate_kind]
1841
    test    eax, eax
2339
    test    eax, eax
1842
    jnz @f
2340
    jnz @f
1843
    mov byte [esp], 0
2341
    mov byte [esp], 0
1844
@@:
2342
@@:
1845
    mov ebx, [ebx + Image.Next]
2343
    mov ebx, [ebx + Image.Next]
1846
    test    ebx, ebx
2344
    test    ebx, ebx
1847
    jnz .loop
2345
    jnz .loop
1848
    pop eax
2346
    pop eax
1849
    ret
2347
    ret
1850
endp
2348
endp
1851
 
2349
 
1852
;;================================================================================================;;
2350
;;================================================================================================;;
1853
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////////////////////////;;
2351
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////////////////////////;;
1854
;;------------------------------------------------------------------------------------------------;;
2352
;;------------------------------------------------------------------------------------------------;;
1855
;? Draw image in the window                                                                       ;;
2353
;? Draw image in the window                                                                       ;;
1856
;;------------------------------------------------------------------------------------------------;;
2354
;;------------------------------------------------------------------------------------------------;;
1857
;> _img = pointer to image                                                                        ;;
2355
;> _img = pointer to image                                                                        ;;
1858
;>_x = x-coordinate in the window                                                                 ;;
2356
;>_x = x-coordinate in the window                                                                 ;;
1859
;>_y = y-coordinate in the window                                                                 ;;
2357
;>_y = y-coordinate in the window                                                                 ;;
1860
;>_width = maximum width to draw                                                                  ;;
2358
;>_width = maximum width to draw                                                                  ;;
1861
;>_height = maximum height to draw                                                                ;;
2359
;>_height = maximum height to draw                                                                ;;
1862
;>_xpos = offset in image by x-axis                                                               ;;
2360
;>_xpos = offset in image by x-axis                                                               ;;
1863
;>_ypos = offset in image by y-axis                                                               ;;
2361
;>_ypos = offset in image by y-axis                                                               ;;
1864
;;------------------------------------------------------------------------------------------------;;
2362
;;------------------------------------------------------------------------------------------------;;
1865
;< no return value                                                                                ;;
2363
;< no return value                                                                                ;;
1866
;;================================================================================================;;
2364
;;================================================================================================;;
1867
    push    ebx esi edi
2365
    push    ebx esi edi
1868
    mov ebx, [_img]
2366
    mov ebx, [_img]
1869
    stdcall img._.validate, ebx
2367
    stdcall img._.validate, ebx
1870
    test    eax, eax
2368
    test    eax, eax
1871
    jnz .done
2369
    jnz .done
1872
    mov ecx, [ebx + Image.Width]
2370
    mov ecx, [ebx + Image.Width]
1873
    sub ecx, [_xpos]
2371
    sub ecx, [_xpos]
1874
    jbe .done
2372
    jbe .done
1875
    cmp ecx, [_width]
2373
    cmp ecx, [_width]
1876
    jb  @f
2374
    jb  @f
1877
    mov ecx, [_width]
2375
    mov ecx, [_width]
1878
@@:
2376
@@:
1879
    mov edx, [ebx + Image.Height]
2377
    mov edx, [ebx + Image.Height]
1880
    sub edx, [_ypos]
2378
    sub edx, [_ypos]
1881
    jbe .done
2379
    jbe .done
1882
    cmp edx, [_height]
2380
    cmp edx, [_height]
1883
    jb  @f
2381
    jb  @f
1884
    mov edx, [_height]
2382
    mov edx, [_height]
1885
@@:
2383
@@:
1886
    mov eax, [ebx + Image.Width]
2384
    mov eax, [ebx + Image.Width]
1887
    sub eax, ecx
2385
    sub eax, ecx
1888
    call    img._.get_scanline_len
2386
    call    img._.get_scanline_len
1889
    shl ecx, 16
2387
    shl ecx, 16
1890
    add ecx, edx
2388
    add ecx, edx
1891
    push    eax
2389
    push    eax
1892
    mov eax, [ebx + Image.Width]
2390
    mov eax, [ebx + Image.Width]
1893
    imul    eax, [_ypos]
2391
    imul    eax, [_ypos]
1894
    add eax, [_xpos]
2392
    add eax, [_xpos]
1895
    call    img._.get_scanline_len
2393
    call    img._.get_scanline_len
1896
    add eax, [ebx + Image.Data]
2394
    add eax, [ebx + Image.Data]
1897
    mov edx, [_x - 2]
2395
    mov edx, [_x - 2]
1898
    mov dx, word [_y]
2396
    mov dx, word [_y]
1899
    mov esi, [ebx + Image.Type]
2397
    mov esi, [ebx + Image.Type]
1900
    mov esi, [type2bpp + (esi-1)*4]
2398
    mov esi, [type2bpp + (esi-1)*4]
1901
    mov edi, [ebx + Image.Palette]
2399
    mov edi, [ebx + Image.Palette]
1902
    xchg    eax, ebx
2400
    xchg    eax, ebx
1903
    pop eax
2401
    pop eax
1904
    push    ebp
2402
    push    ebp
1905
    push    65
2403
    push    65
1906
    pop ebp
2404
    pop ebp
1907
    xchg    eax, ebp
2405
    xchg    eax, ebp
1908
    int 40h
2406
    int 40h
1909
    pop ebp
2407
    pop ebp
1910
.done:
2408
.done:
1911
    pop edi esi ebx
2409
    pop edi esi ebx
1912
    ret
2410
    ret
1913
endp
2411
endp
1914
 
2412
 
1915
 
2413
 
1916
align 4
2414
align 4
1917
img.formats_table:
2415
img.formats_table:
1918
  .bmp  dd LIBIMG_FORMAT_BMP,  img.is.bmp,  img.decode.bmp,     img.encode.bmp, 1 + (1 SHL Image.bpp24) + (1 SHL Image.bpp32)
2416
  .bmp  dd LIBIMG_FORMAT_BMP,  img.is.bmp,  img.decode.bmp,     img.encode.bmp, 1 + (1 SHL Image.bpp24) + (1 SHL Image.bpp32)
1919
  .ico  dd LIBIMG_FORMAT_ICO,  img.is.ico,  img.decode.ico_cur, img.encode.ico, 0
2417
  .ico  dd LIBIMG_FORMAT_ICO,  img.is.ico,  img.decode.ico_cur, img.encode.ico, 0
1920
  .cur  dd LIBIMG_FORMAT_CUR,  img.is.cur,  img.decode.ico_cur, img.encode.cur, 0
2418
  .cur  dd LIBIMG_FORMAT_CUR,  img.is.cur,  img.decode.ico_cur, img.encode.cur, 0
1921
  .gif  dd LIBIMG_FORMAT_GIF,  img.is.gif,  img.decode.gif,     img.encode.gif, 0
2419
  .gif  dd LIBIMG_FORMAT_GIF,  img.is.gif,  img.decode.gif,     img.encode.gif, 0
1922
  .png  dd LIBIMG_FORMAT_PNG,  img.is.png,  img.decode.png,     img.encode.png, 0
2420
  .png  dd LIBIMG_FORMAT_PNG,  img.is.png,  img.decode.png,     img.encode.png, 0
1923
  .jpg  dd LIBIMG_FORMAT_JPEG, img.is.jpg,  img.decode.jpg,     img.encode.jpg, 0
2421
  .jpg  dd LIBIMG_FORMAT_JPEG, img.is.jpg,  img.decode.jpg,     img.encode.jpg, 0
1924
  .tga  dd LIBIMG_FORMAT_TGA,  img.is.tga,  img.decode.tga,     img.encode.tga, 0
2422
  .tga  dd LIBIMG_FORMAT_TGA,  img.is.tga,  img.decode.tga,     img.encode.tga, 0
1925
  .pcx  dd LIBIMG_FORMAT_PCX,  img.is.pcx,  img.decode.pcx,     img.encode.pcx, 0
2423
  .pcx  dd LIBIMG_FORMAT_PCX,  img.is.pcx,  img.decode.pcx,     img.encode.pcx, 0
1926
  .xcf  dd LIBIMG_FORMAT_XCF,  img.is.xcf,  img.decode.xcf,     img.encode.xcf, 0
2424
  .xcf  dd LIBIMG_FORMAT_XCF,  img.is.xcf,  img.decode.xcf,     img.encode.xcf, 0
1927
  .tiff dd LIBIMG_FORMAT_TIFF, img.is.tiff, img.decode.tiff,    img.encode.tiff,0
2425
  .tiff dd LIBIMG_FORMAT_TIFF, img.is.tiff, img.decode.tiff,    img.encode.tiff,0
1928
  .pnm  dd LIBIMG_FORMAT_PNM,  img.is.pnm,  img.decode.pnm,     img.encode.pnm, 1 + (1 SHL Image.bpp1) + (1 SHL Image.bpp8g) + (1 SHL Image.bpp24)
2426
  .pnm  dd LIBIMG_FORMAT_PNM,  img.is.pnm,  img.decode.pnm,     img.encode.pnm, 1 + (1 SHL Image.bpp1) + (1 SHL Image.bpp8g) + (1 SHL Image.bpp24)
1929
  .wbmp dd LIBIMG_FORMAT_WBMP, img.is.wbmp, img.decode.wbmp,    img.encode.wbmp,0
2427
  .wbmp dd LIBIMG_FORMAT_WBMP, img.is.wbmp, img.decode.wbmp,    img.encode.wbmp,0
1930
  .xbm  dd LIBIMG_FORMAT_XBM,  img.is.xbm,  img.decode.xbm,     img.encode.xbm, 0
2428
  .xbm  dd LIBIMG_FORMAT_XBM,  img.is.xbm,  img.decode.xbm,     img.encode.xbm, 0
1931
  .z80  dd LIBIMG_FORMAT_Z80,  img.is.z80,  img.decode.z80,     img.encode.z80, 0 ;this must be the last entry as there are no signatures in z80 screens at all
2429
  .z80  dd LIBIMG_FORMAT_Z80,  img.is.z80,  img.decode.z80,     img.encode.z80, 0 ;this must be the last entry as there are no signatures in z80 screens at all
1932
        dd 0
2430
        dd 0
1933
 
2431
 
1934
align 4
2432
align 4
1935
img.types_table:	; entries order must correspond to type defnitions in libimg.inc
2433
img.types_table:	; entries order must correspond to type defnitions in libimg.inc
1936
         dd 0	; there is no Image.bpp* = 0
2434
         dd 0	; there is no Image.bpp* = 0
1937
  .bpp8i dd (1 SHL Image.bpp24)
2435
  .bpp8i dd (1 SHL Image.bpp24)
1938
  .bpp24 dd (1 SHL Image.bpp24) OR (1 SHL Image.bpp8g)
2436
  .bpp24 dd (1 SHL Image.bpp24) OR (1 SHL Image.bpp8g)
1939
  .bpp32 dd (1 SHL Image.bpp24)
2437
  .bpp32 dd (1 SHL Image.bpp24)
1940
  .bpp15 dd (1 SHL Image.bpp24)
2438
  .bpp15 dd (1 SHL Image.bpp24)
1941
  .bpp16 dd (1 SHL Image.bpp24)
2439
  .bpp16 dd (1 SHL Image.bpp24)
1942
  .bpp1  dd (1 SHL Image.bpp24)
2440
  .bpp1  dd (1 SHL Image.bpp24)
1943
  .bpp8g dd (1 SHL Image.bpp24) OR (1 SHL Image.bpp1 )
2441
  .bpp8g dd (1 SHL Image.bpp24) OR (1 SHL Image.bpp1 )
1944
  .bpp8a dd (1 SHL Image.bpp24)
2442
  .bpp8a dd (1 SHL Image.bpp24)
1945
 
2443
 
1946
;;================================================================================================;;
2444
;;================================================================================================;;
1947
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2445
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1948
;;================================================================================================;;
2446
;;================================================================================================;;
1949
;! Below are private procs you should never call directly from your code                          ;;
2447
;! Below are private procs you should never call directly from your code                          ;;
1950
;;================================================================================================;;
2448
;;================================================================================================;;
1951
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2449
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1952
;;================================================================================================;;
2450
;;================================================================================================;;
1953
 
2451
 
1954
 
2452
 
1955
;;================================================================================================;;
2453
;;================================================================================================;;
1956
proc img._.validate, _img ;///////////////////////////////////////////////////////////////////////;;
2454
proc img._.validate, _img ;///////////////////////////////////////////////////////////////////////;;
1957
;;------------------------------------------------------------------------------------------------;;
2455
;;------------------------------------------------------------------------------------------------;;
1958
;? --- TBD ---                                                                                    ;;
2456
;? --- TBD ---                                                                                    ;;
1959
;;------------------------------------------------------------------------------------------------;;
2457
;;------------------------------------------------------------------------------------------------;;
1960
;> --- TBD ---                                                                                    ;;
2458
;> --- TBD ---                                                                                    ;;
1961
;;------------------------------------------------------------------------------------------------;;
2459
;;------------------------------------------------------------------------------------------------;;
1962
;< --- TBD ---                                                                                    ;;
2460
;< --- TBD ---                                                                                    ;;
1963
;;================================================================================================;;
2461
;;================================================================================================;;
1964
    xor eax, eax
2462
    xor eax, eax
1965
    ret
2463
    ret
1966
endp
2464
endp
1967
 
2465
 
1968
;;================================================================================================;;
2466
;;================================================================================================;;
1969
proc img._.new ;//////////////////////////////////////////////////////////////////////////////////;;
2467
proc img._.new ;//////////////////////////////////////////////////////////////////////////////////;;
1970
;;------------------------------------------------------------------------------------------------;;
2468
;;------------------------------------------------------------------------------------------------;;
1971
;? --- TBD ---                                                                                    ;;
2469
;? --- TBD ---                                                                                    ;;
1972
;;------------------------------------------------------------------------------------------------;;
2470
;;------------------------------------------------------------------------------------------------;;
1973
;> --- TBD ---                                                                                    ;;
2471
;> --- TBD ---                                                                                    ;;
1974
;;------------------------------------------------------------------------------------------------;;
2472
;;------------------------------------------------------------------------------------------------;;
1975
;< eax = 0 / pointer to image                                                                     ;;
2473
;< eax = 0 / pointer to image                                                                     ;;
1976
;;================================================================================================;;
2474
;;================================================================================================;;
1977
    invoke  mem.alloc, sizeof.Image
2475
    invoke  mem.alloc, sizeof.Image
1978
    test    eax, eax
2476
    test    eax, eax
1979
    jz  @f
2477
    jz  @f
1980
    push    ecx
2478
    push    ecx
1981
    xor ecx, ecx
2479
    xor ecx, ecx
1982
    mov [eax + Image.Data], ecx
2480
    mov [eax + Image.Data], ecx
1983
    mov [eax + Image.Type], ecx
2481
    mov [eax + Image.Type], ecx
1984
    mov [eax + Image.Flags], ecx
2482
    mov [eax + Image.Flags], ecx
1985
    mov [eax + Image.Extended], ecx
2483
    mov [eax + Image.Extended], ecx
1986
    mov [eax + Image.Previous], ecx
2484
    mov [eax + Image.Previous], ecx
1987
    mov [eax + Image.Next], ecx
2485
    mov [eax + Image.Next], ecx
1988
    pop ecx
2486
    pop ecx
1989
@@:
2487
@@:
1990
    ret
2488
    ret
1991
endp
2489
endp
1992
 
2490
 
1993
;;================================================================================================;;
2491
;;================================================================================================;;
1994
proc img._.delete _img ;//////////////////////////////////////////////////////////////////////////;;
2492
proc img._.delete _img ;//////////////////////////////////////////////////////////////////////////;;
1995
;;------------------------------------------------------------------------------------------------;;
2493
;;------------------------------------------------------------------------------------------------;;
1996
;? --- TBD ---                                                                                    ;;
2494
;? --- TBD ---                                                                                    ;;
1997
;;------------------------------------------------------------------------------------------------;;
2495
;;------------------------------------------------------------------------------------------------;;
1998
;> --- TBD ---                                                                                    ;;
2496
;> --- TBD ---                                                                                    ;;
1999
;;------------------------------------------------------------------------------------------------;;
2497
;;------------------------------------------------------------------------------------------------;;
2000
;< eax = false / true                                                                             ;;
2498
;< eax = false / true                                                                             ;;
2001
;;================================================================================================;;
2499
;;================================================================================================;;
2002
    push    edx
2500
    push    edx
2003
    mov edx, [_img]
2501
    mov edx, [_img]
2004
    cmp [edx + Image.Data], 0
2502
    cmp [edx + Image.Data], 0
2005
    je  @f
2503
    je  @f
2006
    invoke  mem.free, [edx + Image.Data]
2504
    invoke  mem.free, [edx + Image.Data]
2007
    @@: cmp [edx + Image.Extended], 0
2505
    @@: cmp [edx + Image.Extended], 0
2008
    je  @f
2506
    je  @f
2009
    invoke  mem.free, [edx + Image.Extended]
2507
    invoke  mem.free, [edx + Image.Extended]
2010
    @@: invoke  mem.free, edx
2508
    @@: invoke  mem.free, edx
2011
    pop edx
2509
    pop edx
2012
    ret
2510
    ret
2013
endp
2511
endp
2014
 
2512
 
2015
;;================================================================================================;;
2513
;;================================================================================================;;
2016
proc img._.resize_data _img, _width, _height ;////////////////////////////////////////////////////;;
2514
proc img._.resize_data _img, _width, _height ;////////////////////////////////////////////////////;;
2017
;;------------------------------------------------------------------------------------------------;;
2515
;;------------------------------------------------------------------------------------------------;;
2018
;? --- TBD ---                                                                                    ;;
2516
;? --- TBD ---                                                                                    ;;
2019
;;------------------------------------------------------------------------------------------------;;
2517
;;------------------------------------------------------------------------------------------------;;
2020
;> --- TBD ---                                                                                    ;;
2518
;> --- TBD ---                                                                                    ;;
2021
;;------------------------------------------------------------------------------------------------;;
2519
;;------------------------------------------------------------------------------------------------;;
2022
;< --- TBD ---                                                                                    ;;
2520
;< --- TBD ---                                                                                    ;;
2023
;;================================================================================================;;
2521
;;================================================================================================;;
2024
    push    ebx esi
2522
    push    ebx esi
2025
    mov ebx, [_img]
2523
    mov ebx, [_img]
2026
    mov eax, [_height]
2524
    mov eax, [_height]
2027
; our memory is limited, [_width]*[_height] must not overflow
2525
; our memory is limited, [_width]*[_height] must not overflow
2028
; image with width or height greater than 65535 is most likely bogus
2526
; image with width or height greater than 65535 is most likely bogus
2029
    cmp word [_width+2], 0
2527
    cmp word [_width+2], 0
2030
    jnz .error
2528
    jnz .error
2031
    cmp word [_height+2], 0
2529
    cmp word [_height+2], 0
2032
    jnz .error
2530
    jnz .error
2033
    imul    eax, [_width]
2531
    imul    eax, [_width]
2034
    test    eax, eax
2532
    test    eax, eax
2035
    jz  .error
2533
    jz  .error
2036
; do not allow images which require too many memory
-
 
2037
    cmp eax, 4000000h
-
 
2038
    jae .error
-
 
2039
    cmp [ebx + Image.Type], Image.bpp1
2534
    cmp [ebx + Image.Type], Image.bpp1
2040
    jz  .bpp1
2535
    jz  .bpp1
-
 
2536
    cmp [ebx + Image.Type], Image.bpp2i
-
 
2537
    jz  .bpp2i
-
 
2538
    cmp [ebx + Image.Type], Image.bpp4i
-
 
2539
    jz  .bpp4i
2041
    cmp [ebx + Image.Type], Image.bpp8i
2540
    cmp [ebx + Image.Type], Image.bpp8i
2042
    jz  .bpp8i
2541
    jz  .bpp8i
2043
    cmp [ebx + Image.Type], Image.bpp8g
2542
    cmp [ebx + Image.Type], Image.bpp8g
2044
    jz  .bpp8g
2543
    jz  .bpp8g
2045
    cmp [ebx + Image.Type], Image.bpp8a
2544
    cmp [ebx + Image.Type], Image.bpp8a
2046
    jz  .bpp8a
2545
    jz  .bpp8a
2047
    cmp [ebx + Image.Type], Image.bpp24
2546
    cmp [ebx + Image.Type], Image.bpp24
2048
    jz  .bpp24
2547
    jz  .bpp24
2049
.bpp32:
2548
.bpp32:
2050
    shl eax, 2
2549
    shl eax, 2
2051
    jmp @f
2550
    jmp @f
2052
.bpp24:
2551
.bpp24:
2053
    lea eax, [eax*3]
2552
    lea eax, [eax*3]
2054
    jmp @f
2553
    jmp @f
2055
.bpp8i:
2554
.bpp8i:
2056
    add eax, 256*4  ; for palette
2555
    add eax, 256*4  ; for palette
2057
.bpp8g:
2556
.bpp8g:
2058
    jmp @f
2557
    jmp @f
2059
.bpp8a:
2558
.bpp8a:
2060
    shl eax, 1
2559
    shl eax, 1
2061
    jmp @f
2560
    jmp @f
-
 
2561
.bpp4i:
-
 
2562
    mov eax, [_width]
-
 
2563
    add eax, 1
-
 
2564
    shr eax, 1
-
 
2565
    imul eax, [_height]
-
 
2566
    mov ecx, eax
-
 
2567
    mov eax, [_height]
-
 
2568
    add eax, 1
-
 
2569
    shr eax, 1
-
 
2570
    imul eax, [_width]
-
 
2571
    cmp eax, ecx
-
 
2572
    jge .bpp4i.skip
-
 
2573
    mov eax, ecx
-
 
2574
 .bpp4i.skip:
-
 
2575
    add eax, 16*4    ; for palette
-
 
2576
    jmp @f
-
 
2577
.bpp2i:
-
 
2578
    mov eax, [_width]
-
 
2579
    add eax, 3
-
 
2580
    shr eax, 2
-
 
2581
    imul eax, [_height]
-
 
2582
    mov ecx, eax
-
 
2583
    mov eax, [_height]
-
 
2584
    add eax, 3
-
 
2585
    shr eax, 2
-
 
2586
    imul eax, [_width]
-
 
2587
    cmp eax, ecx
-
 
2588
    jge .bpp2i.skip
-
 
2589
    mov eax, ecx
-
 
2590
 .bpp2i.skip:
-
 
2591
    add eax, 4*4    ; for palette
-
 
2592
    jmp @f
2062
.bpp1:
2593
.bpp1:
2063
    mov eax, [_width]
2594
    mov eax, [_width]
2064
    add eax, 7
2595
    add eax, 7
2065
    shr eax, 3
2596
    shr eax, 3
2066
    mul word[_height]
2597
    imul eax, [_height]
2067
    shl eax, 16
-
 
2068
    mov ax,  dx
-
 
2069
    ror eax, 16
-
 
2070
 
-
 
2071
    push ebx
-
 
2072
    mov ebx, eax
2598
    mov ecx, eax
2073
 
-
 
2074
    mov eax, [_height]
2599
    mov eax, [_height]
2075
    add eax, 7
2600
    add eax, 7
2076
    shr eax, 3
2601
    shr eax, 3
2077
    mul word[_width]
2602
    imul eax, [_width]
2078
    shl eax, 16
-
 
2079
    mov ax,  dx
-
 
2080
    ror eax, 16
-
 
2081
 
-
 
2082
    cmp eax, ebx
2603
    cmp eax, ecx
2083
     jge .bpp1.skip
2604
    jge .bpp1.skip
2084
    mov eax, ebx
2605
    mov eax, ecx
2085
  .bpp1.skip:
2606
 .bpp1.skip:
2086
    pop ebx
-
 
2087
 
2607
 
2088
    add eax, 2*4    ; for palette
2608
    add eax, 2*4    ; for palette
2089
@@:
2609
@@:
2090
    mov esi, eax
2610
    mov esi, eax
2091
    invoke  mem.realloc, [ebx + Image.Data], eax
2611
    invoke  mem.realloc, [ebx + Image.Data], eax
2092
    or  eax, eax
2612
    or  eax, eax
2093
    jz  .error
2613
    jz  .error
2094
 
2614
 
2095
    mov [ebx + Image.Data], eax
2615
    mov [ebx + Image.Data], eax
2096
    push    [_width]
2616
    push    [_width]
2097
    pop [ebx + Image.Width]
2617
    pop [ebx + Image.Width]
2098
    push    [_height]
2618
    push    [_height]
2099
    pop [ebx + Image.Height]
2619
    pop [ebx + Image.Height]
2100
    cmp [ebx + Image.Type], Image.bpp8i
2620
    cmp [ebx + Image.Type], Image.bpp8i
2101
    jnz @f
2621
    jnz @f
2102
    lea esi, [eax + esi - 256*4]
2622
    lea esi, [eax + esi - 256*4]
2103
    mov [ebx + Image.Palette], esi
2623
    mov [ebx + Image.Palette], esi
2104
    jmp .ret
2624
    jmp .ret
2105
@@:
2625
@@:
2106
    cmp [ebx + Image.Type], Image.bpp1
2626
    cmp [ebx + Image.Type], Image.bpp1
2107
    jnz .ret
2627
    jnz @f
2108
    lea esi, [eax + esi - 2*4]
2628
    lea esi, [eax + esi - 2*4]
2109
    mov [ebx + Image.Palette], esi
2629
    mov [ebx + Image.Palette], esi
2110
    jmp .ret
2630
    jmp .ret
-
 
2631
@@:
-
 
2632
    cmp [ebx + Image.Type], Image.bpp2i
-
 
2633
    jnz @f
-
 
2634
    lea esi, [eax + esi - 4*4]
-
 
2635
    mov [ebx + Image.Palette], esi
-
 
2636
    jmp .ret
-
 
2637
@@:
-
 
2638
    cmp [ebx + Image.Type], Image.bpp4i
-
 
2639
    jnz .ret
-
 
2640
    lea esi, [eax + esi - 16*4]
-
 
2641
    mov [ebx + Image.Palette], esi
-
 
2642
    jmp .ret
2111
 
2643
 
2112
  .error:
2644
  .error:
2113
    xor eax, eax
2645
    xor eax, eax
2114
  .ret:
2646
  .ret:
2115
    pop esi ebx
2647
    pop esi ebx
2116
    ret
2648
    ret
2117
endp
2649
endp
2118
 
2650
 
2119
;;================================================================================================;;
2651
;;================================================================================================;;
2120
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
2652
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
2121
;;------------------------------------------------------------------------------------------------;;
2653
;;------------------------------------------------------------------------------------------------;;
2122
;? --- TBD ---                                                                                    ;;
2654
;? --- TBD ---                                                                                    ;;
2123
;;------------------------------------------------------------------------------------------------;;
2655
;;------------------------------------------------------------------------------------------------;;
2124
;> --- TBD ---                                                                                    ;;
2656
;> --- TBD ---                                                                                    ;;
2125
;;------------------------------------------------------------------------------------------------;;
2657
;;------------------------------------------------------------------------------------------------;;
2126
;< --- TBD ---                                                                                    ;;
2658
;< --- TBD ---                                                                                    ;;
2127
;;================================================================================================;;
2659
;;================================================================================================;;
2128
    cmp [ebx + Image.Type], Image.bpp1
2660
    cmp [ebx + Image.Type], Image.bpp1
2129
    jz  .bpp1.1
2661
    jz  .bpp1.1
-
 
2662
    cmp [ebx + Image.Type], Image.bpp2i
-
 
2663
    jz  .bpp2i.1
-
 
2664
    cmp [ebx + Image.Type], Image.bpp4i
-
 
2665
    jz  .bpp4i.1
2130
    cmp [ebx + Image.Type], Image.bpp8i
2666
    cmp [ebx + Image.Type], Image.bpp8i
2131
    jz  .bpp8.1
2667
    jz  .bpp8.1
2132
    cmp [ebx + Image.Type], Image.bpp8g
2668
    cmp [ebx + Image.Type], Image.bpp8g
2133
    jz  .bpp8.1
2669
    jz  .bpp8.1
2134
    cmp [ebx + Image.Type], Image.bpp8a
2670
    cmp [ebx + Image.Type], Image.bpp8a
2135
    jz  .bpp8a.1
2671
    jz  .bpp8a.1
2136
    cmp [ebx + Image.Type], Image.bpp24
2672
    cmp [ebx + Image.Type], Image.bpp24
2137
    jz  .bpp24.1
2673
    jz  .bpp24.1
2138
    add eax, eax
2674
    add eax, eax
2139
    cmp [ebx + Image.Type], Image.bpp32
2675
    cmp [ebx + Image.Type], Image.bpp32
2140
    jnz .quit
2676
    jnz .quit
2141
    add eax, eax
2677
    add eax, eax
2142
    jmp .quit
2678
    jmp .quit
2143
.bpp24.1:
2679
.bpp24.1:
2144
    lea eax, [eax*3]
2680
    lea eax, [eax*3]
2145
    jmp .quit
2681
    jmp .quit
2146
.bpp1.1:
2682
.bpp1.1:
2147
    add eax, 7
2683
    add eax, 7
2148
    shr eax, 3
2684
    shr eax, 3
2149
    jmp .quit
2685
    jmp .quit
-
 
2686
.bpp2i.1:
-
 
2687
    add eax, 3
-
 
2688
    shr eax, 2
-
 
2689
    jmp .quit
-
 
2690
.bpp4i.1:
-
 
2691
    add eax, 1
-
 
2692
    shr eax, 1
-
 
2693
    jmp .quit
2150
.bpp8a.1:
2694
.bpp8a.1:
2151
    shl eax, 1
2695
    shl eax, 1
2152
.bpp8.1:
2696
.bpp8.1:
2153
.quit:
2697
.quit:
2154
    ret
2698
    ret
2155
 
2699
 
2156
 
2700
 
2157
;;================================================================================================;;
2701
;;================================================================================================;;
2158
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2702
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2159
;;================================================================================================;;
2703
;;================================================================================================;;
2160
;! Below is private data you should never use directly from your code                             ;;
2704
;! Below is private data you should never use directly from your code                             ;;
2161
;;================================================================================================;;
2705
;;================================================================================================;;
2162
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2706
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2163
;;================================================================================================;;
2707
;;================================================================================================;;
2164
 
2708
 
2165
align 4
2709
align 4
2166
type2bpp    dd  8, 24, 32, 15, 16, 1, 9;, 2, 4
2710
type2bpp    dd  8, 24, 32, 15, 16, 1, 9, 2, 4
2167
img._.do_rgb.handlers:
2711
img._.do_rgb.handlers:
2168
    dd  img._.do_rgb.bpp8i
2712
    dd  img._.do_rgb.bpp8i
2169
    dd  img._.do_rgb.bpp24
2713
    dd  img._.do_rgb.bpp24
2170
    dd  img._.do_rgb.bpp32
2714
    dd  img._.do_rgb.bpp32
2171
    dd  img._.do_rgb.bpp15.amd  ; can be overwritten in lib_init
2715
    dd  img._.do_rgb.bpp15.amd  ; can be overwritten in lib_init
2172
    dd  img._.do_rgb.bpp16.amd  ; can be overwritten in lib_init
2716
    dd  img._.do_rgb.bpp16.amd  ; can be overwritten in lib_init
2173
    dd  img._.do_rgb.bpp1
2717
    dd  img._.do_rgb.bpp1
2174
    dd  img._.do_rgb.bpp8g
2718
    dd  img._.do_rgb.bpp8g
-
 
2719
    dd  img._.do_rgb.bpp2i
2175
;    dd  img._.do_rgb.bpp8a
2720
    dd  img._.do_rgb.bpp4i
2176
 
2721
 
2177
img.flip.layer.handlers_horz:
2722
img.flip.layer.handlers_horz:
2178
    dd  img.flip.layer.bpp8ig_horz
2723
    dd  img.flip.layer.bpp8ig_horz
2179
    dd  img.flip.layer.bpp24_horz
2724
    dd  img.flip.layer.bpp24_horz
2180
    dd  img.flip.layer.bpp32_horz
2725
    dd  img.flip.layer.bpp32_horz
2181
    dd  img.flip.layer.bpp1x_horz
2726
    dd  img.flip.layer.bpp1x_horz
2182
    dd  img.flip.layer.bpp1x_horz
2727
    dd  img.flip.layer.bpp1x_horz
2183
    dd  img.flip.layer.bpp1_horz
2728
    dd  img.flip.layer.bpp1_horz
2184
    dd  img.flip.layer.bpp8ig_horz
2729
    dd  img.flip.layer.bpp8ig_horz
-
 
2730
    dd  img.flip.layer.bpp2i_horz
2185
;    dd  img.flip.layer.bpp8a_horz
2731
    dd  img.flip.layer.bpp4i_horz
2186
 
2732
 
2187
;;================================================================================================;;
2733
;;================================================================================================;;
2188
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2734
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2189
;;================================================================================================;;
2735
;;================================================================================================;;
2190
;! Exported functions section                                                                     ;;
2736
;! Exported functions section                                                                     ;;
2191
;;================================================================================================;;
2737
;;================================================================================================;;
2192
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2738
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2193
;;================================================================================================;;
2739
;;================================================================================================;;
2194
 
2740
 
2195
 
2741
 
2196
align 4
2742
align 4
2197
@EXPORT:
2743
@EXPORT:
2198
 
2744
 
2199
export                                      \
2745
export                                      \
2200
    lib_init         , 'lib_init'         , \
2746
    lib_init         , 'lib_init'         , \
2201
    0x00050007       , 'version'          , \
2747
    0x00050007       , 'version'          , \
2202
    img.is_img       , 'img_is_img'       , \
2748
    img.is_img       , 'img_is_img'       , \
2203
    img.info         , 'img_info'         , \
2749
    img.info         , 'img_info'         , \
2204
    img.from_file    , 'img_from_file'    , \
2750
    img.from_file    , 'img_from_file'    , \
2205
    img.to_file      , 'img_to_file'      , \
2751
    img.to_file      , 'img_to_file'      , \
2206
    img.from_rgb     , 'img_from_rgb'     , \
2752
    img.from_rgb     , 'img_from_rgb'     , \
2207
    img.to_rgb       , 'img_to_rgb'       , \
2753
    img.to_rgb       , 'img_to_rgb'       , \
2208
    img.to_rgb2      , 'img_to_rgb2'      , \
2754
    img.to_rgb2      , 'img_to_rgb2'      , \
2209
    img.decode       , 'img_decode'       , \
2755
    img.decode       , 'img_decode'       , \
2210
    img.encode       , 'img_encode'       , \
2756
    img.encode       , 'img_encode'       , \
2211
    img.create       , 'img_create'       , \
2757
    img.create       , 'img_create'       , \
2212
    img.destroy      , 'img_destroy'      , \
2758
    img.destroy      , 'img_destroy'      , \
2213
    img.destroy.layer, 'img_destroy_layer', \
2759
    img.destroy.layer, 'img_destroy_layer', \
2214
    img.count        , 'img_count'        , \
2760
    img.count        , 'img_count'        , \
2215
    img.lock_bits    , 'img_lock_bits'    , \
2761
    img.lock_bits    , 'img_lock_bits'    , \
2216
    img.unlock_bits  , 'img_unlock_bits'  , \
2762
    img.unlock_bits  , 'img_unlock_bits'  , \
2217
    img.flip         , 'img_flip'         , \
2763
    img.flip         , 'img_flip'         , \
2218
    img.flip.layer   , 'img_flip_layer'   , \
2764
    img.flip.layer   , 'img_flip_layer'   , \
2219
    img.rotate       , 'img_rotate'       , \
2765
    img.rotate       , 'img_rotate'       , \
2220
    img.rotate.layer , 'img_rotate_layer' , \
2766
    img.rotate.layer , 'img_rotate_layer' , \
2221
    img.draw         , 'img_draw'         , \
2767
    img.draw         , 'img_draw'         , \
2222
    img.scale        , 'img_scale'        , \
2768
    img.scale        , 'img_scale'        , \
2223
    img.convert      , 'img_convert'      , \
2769
    img.convert      , 'img_convert'      , \
2224
    img.formats_table, 'img_formats_table'
2770
    img.formats_table, 'img_formats_table'
2225
 
2771
 
2226
; import from deflate unpacker
2772
; import from deflate unpacker
2227
; is initialized only when PNG loading is requested
2773
; is initialized only when PNG loading is requested
2228
align 4
2774
align 4
2229
@IMPORT:
2775
@IMPORT:
2230
 
2776
 
2231
library archiver, 'archiver.obj'
2777
library archiver, 'archiver.obj'
2232
import  archiver, \
2778
import  archiver, \
2233
    deflate_unpack2, 'deflate_unpack2'
2779
    deflate_unpack2, 'deflate_unpack2'
2234
 
2780
 
2235
align 4
2781
align 4
2236
; mutex for unpacker loading
2782
; mutex for unpacker loading
2237
deflate_loader_mutex    dd  0
2783
deflate_loader_mutex    dd  0
2238
 
2784
 
2239
; default palette for GIF - b&w
2785
; default palette for GIF - b&w
2240
gif_default_palette:
2786
gif_default_palette:
2241
    db  0, 0, 0
2787
    db  0, 0, 0
2242
    db  0xFF, 0xFF, 0xFF
2788
    db  0xFF, 0xFF, 0xFF
2243
 
2789
 
2244
section '.data' data readable writable align 16
2790
section '.data' data readable writable align 16
2245
; uninitialized data - global constant tables
2791
; uninitialized data - global constant tables
2246
mem.alloc   dd ?
2792
mem.alloc   dd ?
2247
mem.free    dd ?
2793
mem.free    dd ?
2248
mem.realloc dd ?
2794
mem.realloc dd ?
2249
dll.load    dd ?
2795
dll.load    dd ?
2250
 
2796
 
2251
; data for YCbCr -> RGB translation
2797
; data for YCbCr -> RGB translation
2252
color_table_1       rd  256
2798
color_table_1       rd  256
2253
color_table_2       rd  256
2799
color_table_2       rd  256
2254
color_table_3       rd  256
2800
color_table_3       rd  256
2255
color_table_4       rd  256
2801
color_table_4       rd  256