Subversion Repositories Kolibri OS

Rev

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

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