Subversion Repositories Kolibri OS

Rev

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

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