Subversion Repositories Kolibri OS

Rev

Rev 8449 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8449 Rev 9713
Line 1... Line 1...
1
;;================================================================================================;;
1
;;============================================================================;;
2
;;//// convert.asm //// (c) dunkaist, 2012 ///////////////////////////////////////////////////////;;
2
;;//// convert.asm //// (c) dunkaist, 2012,2016,2017,2020,2022 ///////////////;;
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
;;                                                                            ;;
-
 
7
;; SPDX-License-Identifier: LGPL-2.1-or-later                                 ;;
6
;;                                                                                                ;;
8
;;                                                                            ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
9
;; Libs-Dev is free software: you can redistribute it and/or modify it under  ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
10
;; the terms of the GNU Lesser General Public License as published by the     ;;
-
 
11
;; Free Software Foundation, either version 2.1 of the License, or (at your   ;;
9
;; of the License, or (at your option) any later version.                                         ;;
12
;; option) any later version.                                                 ;;
10
;;                                                                                                ;;
13
;;                                                                            ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
14
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT    ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
15
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      ;;
-
 
16
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public        ;;
13
;; Lesser General Public License for more details.                                                ;;
17
;; License for more details.                                                  ;;
14
;;                                                                                                ;;
18
;;                                                                            ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
19
;; You should have received a copy of the GNU Lesser General Public License   ;;
16
;; If not, see .                                                    ;;
20
;; along with Libs-Dev. If not, see .           ;;
17
;;                                                                                                ;;
21
;;                                                                            ;;
18
;;================================================================================================;;
22
;;============================================================================;;
19
 
23
 
20
 
-
 
21
 
24
 
22
;;================================================================================================;;
25
;;============================================================================;;
23
proc img.convert _src, _dst, _dst_type, _flags, _param                                            ;;
26
proc img.convert _src, _dst, _dst_type, _flags, _param                        ;;
24
;;------------------------------------------------------------------------------------------------;;
27
;;----------------------------------------------------------------------------;;
25
;? convert _image                                                                                 ;;
28
;? convert _image                                                             ;;
26
;;------------------------------------------------------------------------------------------------;;
29
;;----------------------------------------------------------------------------;;
27
;> [_src]      = pointer to source image                                                          ;;
30
;> [_src]      = pointer to source image                                      ;;
28
;> [_dst]      = pointer to destination image, or 0 to create a new one                           ;;
31
;> [_dst]      = pointer to destination image, or 0 to create a new one       ;;
29
;> [_dst_type] = Image.Type of resulting image                                                    ;;
32
;> [_dst_type] = Image.Type of resulting image                                ;;
30
;> [_flags]    = see libimg.inc                                                                   ;;
33
;> [_flags]    = see libimg.inc                                               ;;
31
;> [_param]    = depends on _flags fields, see libimg.inc                                         ;;
34
;> [_param]    = depends on _flags fields, see libimg.inc                     ;;
32
;;------------------------------------------------------------------------------------------------;;
35
;;----------------------------------------------------------------------------;;
33
;< eax = 0 / pointer to converted image                                                           ;;
36
;< eax = 0 / pointer to converted image                                       ;;
34
;< ecx = error code / undefined                                                                   ;;
37
;< ecx = error code / undefined                                               ;;
35
;;================================================================================================;;
38
;;============================================================================;;
36
locals
39
locals
37
        img     dd ?
40
        img     dd ?
38
        prev    dd ?
41
        prev    dd ?
39
endl
42
endl
40
        push    ebx esi edi
43
        push    ebx esi edi
41
        mov     [img], 0
44
        mov     [img], 0
42
        mov     [prev], 0
45
        mov     [prev], 0
43
        mov     ebx, [_src]
46
        mov     ebx, [_src]
44
    @@:
47
@@:
45
        mov     eax, [ebx + Image.Previous]
48
        mov     eax, [ebx + Image.Previous]
46
        test    eax, eax
49
        test    eax, eax
47
        jz      .loop
50
        jz      .loop
48
        mov     ebx, eax
51
        mov     ebx, eax
49
        jmp     @b
52
        jmp     @b
50
  .loop:
53
.loop:
51
        stdcall img.convert.layer, ebx, [_dst], [_dst_type], [_flags], [_param]
54
        stdcall img.convert.layer, ebx, [_dst], [_dst_type], [_flags], [_param]
52
        test    eax, eax
55
        test    eax, eax
53
        jz      .error
56
        jz      .error
54
        cmp     [img], 0
57
        cmp     [img], 0
55
        jnz     @f
58
        jnz     @f
56
        mov     [img], eax
59
        mov     [img], eax
57
    @@:
60
@@:
58
        mov     ecx, [prev]
61
        mov     ecx, [prev]
59
        jecxz   @f
62
        jecxz   @f
60
        mov     [ecx + Image.Next], eax
63
        mov     [ecx + Image.Next], eax
61
        mov     [eax + Image.Previous], ecx
64
        mov     [eax + Image.Previous], ecx
62
    @@:
65
@@:
63
        mov     [prev], eax
66
        mov     [prev], eax
64
        push    [ebx + Image.Flags]
67
        push    [ebx + Image.Flags]
65
        pop     [eax + Image.Flags]
68
        pop     [eax + Image.Flags]
66
        push    [ebx + Image.Delay]
69
        push    [ebx + Image.Delay]
67
        pop     [eax + Image.Delay]
70
        pop     [eax + Image.Delay]
68
        mov     ebx, [ebx + Image.Next]
71
        mov     ebx, [ebx + Image.Next]
69
        test    ebx, ebx
72
        test    ebx, ebx
70
        jnz     .loop
73
        jnz     .loop
71
        mov     eax, [img]
74
        mov     eax, [img]
72
  .error:
75
.error:
73
        pop     edi esi ebx
76
        pop     edi esi ebx
74
        ret
77
        ret
75
endp
78
endp
Line 76... Line 79...
76
 
79
 
77
 
80
 
78
;;================================================================================================;;
81
;;============================================================================;;
79
proc img.convert.layer _src, _dst, _dst_type, _flags, _param                                      ;;
82
proc img.convert.layer _src, _dst, _dst_type, _flags, _param                  ;;
80
;;------------------------------------------------------------------------------------------------;;
83
;;----------------------------------------------------------------------------;;
81
;? convert _image layer                                                                           ;;
84
;? convert _image layer                                                       ;;
82
;;------------------------------------------------------------------------------------------------;;
85
;;----------------------------------------------------------------------------;;
83
;> [_src]      = pointer to source image                                                          ;;
86
;> [_src]      = pointer to source image                                      ;;
84
;> [_dst]      = pointer to destination image, or 0 to create a new one                           ;;
87
;> [_dst]      = pointer to destination image, or 0 to create a new one       ;;
85
;> [_dst_type] = Image.Type of resulting image                                                    ;;
88
;> [_dst_type] = Image.Type of resulting image                                ;;
86
;> [_flags]    = see libimg.inc                                                                   ;;
89
;> [_flags]    = see libimg.inc                                               ;;
87
;> [_param]    = depends on _flags fields, see libimg.inc                                         ;;
90
;> [_param]    = depends on _flags fields, see libimg.inc                     ;;
88
;;------------------------------------------------------------------------------------------------;;
91
;;----------------------------------------------------------------------------;;
89
;< eax = 0 / pointer to converted image                                                           ;;
92
;< eax = 0 / pointer to converted image                                       ;;
90
;< ecx = error code / undefined                                                                   ;;
93
;< ecx = error code / undefined                                               ;;
91
;;================================================================================================;;
94
;;============================================================================;;
92
locals
95
locals
93
        fun     rd 1
96
        fun     rd 1
Line 94... Line 97...
94
endl
97
endl
95
        push    ebx esi edi
98
        push    ebx esi edi
96
 
99
 
-
 
100
        mov     ebx, [_src]
97
        mov     ebx, [_src]
101
        mov     eax, [ebx + Image.Type]
98
        mov     eax, [ebx + Image.Type]
102
        mov     esi, [img.convert.table + 4*eax]
99
        mov     esi, [img.convert.table + 4*eax]
103
        mov     ecx, LIBIMG_ERROR_BIT_DEPTH
100
  .next:
-
 
101
        lodsd
-
 
102
        test    eax, eax
104
.next:
103
        jnz     @f
-
 
104
        mov     ecx, LIBIMG_ERROR_BIT_DEPTH
105
        lodsd
105
        jmp     .exit
106
        test    eax, eax
106
    @@:
107
        jz      .exit
107
        cmp     eax, [_dst_type]
108
        cmp     eax, [_dst_type]
Line 108... Line 109...
108
        lodsd
109
        lodsd
109
        jnz     .next
110
        jnz     .next
110
        mov     [fun], eax
111
        mov     [fun], eax
111
 
112
 
-
 
113
        mov     eax, [_dst]
112
        mov     eax, [_dst]
114
        test    eax, eax
113
        test    eax, eax
115
        jnz     @f
114
        jnz     @f
116
        stdcall img.create, [ebx + Image.Width], [ebx + Image.Height], \
115
        stdcall img.create, [ebx + Image.Width], [ebx + Image.Height], [_dst_type]
117
                [_dst_type]
116
        test    eax, eax
118
        test    eax, eax
117
        jz      .exit
119
        jz      .exit
118
        mov     [_dst], eax
120
        mov     [_dst], eax
119
    @@:
121
@@:
120
        mov     edi, [eax + Image.Data]
122
        mov     edi, [eax + Image.Data]
121
        mov     esi, [ebx + Image.Data]
123
        mov     esi, [ebx + Image.Data]
122
        mov     eax, [ebx + Image.Type]
124
        mov     eax, [ebx + Image.Type]
123
        stdcall [fun], [_src], [_dst]
125
        stdcall [fun], [_src], [_dst]
124
        mov     eax, [_dst]
126
        mov     eax, [_dst]
Line 125... Line 127...
125
  .exit:
127
.exit:
Line 132... Line 134...
132
        imul    ecx, [ebx + Image.Height]
134
        imul    ecx, [ebx + Image.Height]
Line 133... Line 135...
133
 
135
 
134
        mov     ebx, [ebx + Image.Palette]
136
        mov     ebx, [ebx + Image.Palette]
135
        sub     ecx, 1
137
        sub     ecx, 1
136
        jz      .bpp8i.last
138
        jz      .bpp8i.last
137
    @@:
139
@@:
138
        movzx   eax, byte[esi]
140
        movzx   eax, byte[esi]
139
        add     esi, 1
141
        add     esi, 1
140
        mov     eax, [ebx + eax*4]
142
        mov     eax, [ebx + eax*4]
141
        mov     [edi], eax
143
        mov     [edi], eax
142
        add     edi, 3
144
        add     edi, 3
143
        sub     ecx, 1
145
        sub     ecx, 1
144
        jnz     @b
146
        jnz     @b
145
  .bpp8i.last:
147
.bpp8i.last:
146
        movzx   eax, byte[esi]
148
        movzx   eax, byte[esi]
147
        mov     eax, [ebx + eax*4]
149
        mov     eax, [ebx + eax*4]
148
        mov     [edi], ax
150
        mov     [edi], ax
149
        shr     eax, 16
151
        shr     eax, 16
150
        mov     [edi + 2], al
152
        mov     [edi + 2], al
151
        ret
153
        ret
Line 152... Line -...
152
endp
-
 
153
 
154
endp
154
 
155
 
155
proc img._.convert.bpp8i_to_bpp32 _src, _dst
156
proc img._.convert.bpp8i_to_bpp32 _src, _dst
Line 156... Line 157...
156
        mov     ecx, [ebx + Image.Width]
157
        mov     ecx, [ebx + Image.Width]
157
        imul    ecx, [ebx + Image.Height]
158
        imul    ecx, [ebx + Image.Height]
158
 
159
 
159
        mov     ebx, [ebx + Image.Palette]
160
        mov     ebx, [ebx + Image.Palette]
160
    @@:
161
@@:
161
        movzx   eax, byte[esi]
162
        movzx   eax, byte[esi]
162
        add     esi, 1
163
        add     esi, 1
163
        mov     eax, [ebx + eax*4]
164
        mov     eax, [ebx + eax*4]
164
        mov     [edi], eax
165
        mov     [edi], eax
165
        add     edi, 4
166
        add     edi, 4
166
        dec     ecx
167
        dec     ecx
Line 167... Line -...
167
        jnz     @b
-
 
168
        ret
168
        jnz     @b
169
endp
169
        ret
170
 
170
endp
171
 
171
 
172
proc img._.convert.bpp8g_to_bpp1 _src, _dst
172
proc img._.convert.bpp8g_to_bpp1 _src, _dst
173
        mov     eax, [_dst]
173
        mov     eax, [_dst]
174
        mov     eax, [eax + Image.Palette]
174
        mov     eax, [eax + Image.Palette]
175
        mov     dword[eax], 0x00000000
175
        mov     dword[eax], 0x00000000
176
        mov     dword[eax + 4], 0xffffffff
176
        mov     dword[eax + 4], 0xffffffff
177
        mov     edx, [ebx + Image.Height]
177
        mov     edx, [ebx + Image.Height]
178
  .bpp8g_to_bpp1.line:
178
.bpp8g_to_bpp1.line:
179
        mov     ax, 0x0800
179
        mov     ax, 0x0800
180
        mov     ecx, [ebx + Image.Width]
180
        mov     ecx, [ebx + Image.Width]
181
  .bpp8g_to_bpp1.pixel:
181
.bpp8g_to_bpp1.pixel:
182
        shl     al, 1
182
        shl     al, 1
183
        cmp     byte[esi], 0x7f
183
        cmp     byte[esi], 0x7f
184
        cmc
184
        cmc
185
        adc     eax, 0
185
        adc     eax, 0
186
        add     esi, 1
186
        add     esi, 1
187
        dec     ah
187
        dec     ah
188
        jnz     @f
188
        jnz     @f
189
        mov     byte[edi], al
189
        mov     byte[edi], al
190
        add     edi, 1
190
        add     edi, 1
191
        mov     ax, 0x0800
191
        mov     ax, 0x0800
192
    @@:
192
@@:
193
        dec     ecx
193
        dec     ecx
194
        jnz     .bpp8g_to_bpp1.pixel
194
        jnz     .bpp8g_to_bpp1.pixel
195
        cmp     ah, 8
195
        cmp     ah, 8
196
        je      @f
196
        je      @f
197
        mov     cl, ah
197
        mov     cl, ah
198
        shl     al, cl
198
        shl     al, cl
199
        mov     byte[edi], al
199
        mov     byte[edi], al
200
        add     edi, 1
200
        add     edi, 1
201
    @@:
201
@@:
Line 202... Line 202...
202
        dec     edx
202
        dec     edx
203
        jnz     .bpp8g_to_bpp1.line
203
        jnz     .bpp8g_to_bpp1.line
204
        ret
204
        ret
205
endp
205
endp
206
 
206
 
207
proc img._.convert.bpp8g_to_bpp24 _src, _dst
207
proc img._.convert.bpp8g_to_bpp24 _src, _dst
208
        mov     ecx, [ebx + Image.Width]
208
        mov     ecx, [ebx + Image.Width]
209
        imul    ecx, [ebx + Image.Height]
209
        imul    ecx, [ebx + Image.Height]
210
    @@:
210
@@:
Line 217... Line 217...
217
        sub     ecx, 1
217
        sub     ecx, 1
218
        jnz     @b
218
        jnz     @b
219
        ret
219
        ret
220
endp
220
endp
Line -... Line 221...
-
 
221
 
-
 
222
proc img._.convert.bpp8g_to_bpp32 _src, _dst
-
 
223
        mov     ecx, [ebx + Image.Width]
-
 
224
        imul    ecx, [ebx + Image.Height]
-
 
225
@@:
-
 
226
        mov     al, byte[esi]
-
 
227
        mov     byte[edi + 0], al
-
 
228
        mov     byte[edi + 1], al
-
 
229
        mov     byte[edi + 2], al
-
 
230
        mov     byte[edi + 3], -1
-
 
231
        add     esi, 1
-
 
232
        add     edi, 4
-
 
233
        dec     ecx
-
 
234
        jnz     @b
-
 
235
        ret
Line 221... Line 236...
221
 
236
endp
222
 
237
 
223
proc img._.convert.bpp24_to_bpp24 _src, _dst
238
proc img._.convert.bpp24_to_bpp24 _src, _dst
224
        mov     ecx, [ebx + Image.Width]
239
        mov     ecx, [ebx + Image.Width]
Line 231... Line 246...
231
        and     ecx, 3
246
        and     ecx, 3
232
        rep     movsb
247
        rep     movsb
233
        ret
248
        ret
234
endp
249
endp
Line 235... Line -...
235
 
-
 
236
 
250
 
237
proc img._.convert.bpp24_to_bpp8g _src, _dst
251
proc img._.convert.bpp24_to_bpp8g _src, _dst
238
        mov     ecx, [ebx + Image.Width]
252
        mov     ecx, [ebx + Image.Width]
239
        imul    ecx, [ebx + Image.Height]
253
        imul    ecx, [ebx + Image.Height]
240
    @@:
254
@@:
241
        movzx   ebx, byte[esi + 0]
255
        movzx   ebx, byte[esi + 0]
242
        movzx   eax, byte[esi + 1]
256
        movzx   eax, byte[esi + 1]
243
        add     ebx, eax
257
        add     ebx, eax
244
        movzx   eax, byte[esi + 2]
258
        movzx   eax, byte[esi + 2]
Line 251... Line 265...
251
        sub     ecx, 1
265
        sub     ecx, 1
252
        jnz     @b
266
        jnz     @b
253
        ret
267
        ret
254
endp
268
endp
Line 255... Line -...
255
 
-
 
256
 
269
 
257
proc img._.convert.bpp24_to_bpp32 _src, _dst
270
proc img._.convert.bpp24_to_bpp32 _src, _dst
258
        mov     ecx, [ebx + Image.Width]
271
        mov     ecx, [ebx + Image.Width]
259
        imul    ecx, [ebx + Image.Height]
272
        imul    ecx, [ebx + Image.Height]
260
    @@:
273
@@:
261
        lodsw
274
        lodsw
262
        ror     eax, 16
275
        ror     eax, 16
263
        lodsb
276
        lodsb
264
        mov     ah, 0xff        ; opaque
277
        mov     ah, 0xff        ; opaque
Line 267... Line 280...
267
        dec     ecx
280
        dec     ecx
268
        jnz     @b
281
        jnz     @b
269
        ret
282
        ret
270
endp
283
endp
Line -... Line 284...
-
 
284
 
-
 
285
proc img._.convert.bpp24_to_bpp1 _src, _dst
-
 
286
        stdcall img.convert.layer, [_src], 0, Image.bpp8g, 0, 0
-
 
287
        test    eax, eax
-
 
288
        jz      .exit
-
 
289
        push    eax
-
 
290
        mov     ecx, [_dst]
-
 
291
        stdcall img.convert.layer, eax, ecx, [ecx+Image.Type], 0, 0
-
 
292
        stdcall img.destroy     ; arg pushed
-
 
293
.exit:
-
 
294
        ret
Line 271... Line 295...
271
 
295
endp
272
 
296
 
273
proc img._.convert.bpp32_to_bpp24 _src, _dst
297
proc img._.convert.bpp32_to_bpp24 _src, _dst
274
        mov     ecx, [ebx + Image.Width]
298
        mov     ecx, [ebx + Image.Width]
275
        imul    ecx, [ebx + Image.Height]
299
        imul    ecx, [ebx + Image.Height]
276
    @@:
300
@@:
277
        mov     eax, [esi]
301
        mov     eax, [esi]
278
        mov     [edi], ax
302
        mov     [edi], ax
279
        shr     eax, 16
303
        shr     eax, 16
Line 283... Line 307...
283
        sub     ecx, 1
307
        sub     ecx, 1
284
        jnz     @b
308
        jnz     @b
285
        ret
309
        ret
286
endp
310
endp
Line 287... Line -...
287
 
-
 
288
 
311
 
289
proc img._.convert.bpp32_to_bpp32 _src, _dst
312
proc img._.convert.bpp32_to_bpp32 _src, _dst
290
        mov     ecx, [ebx + Image.Width]
313
        mov     ecx, [ebx + Image.Width]
291
        imul    ecx, [ebx + Image.Height]
314
        imul    ecx, [ebx + Image.Height]
292
        rep     movsd
315
        rep     movsd
293
        ret
316
        ret
Line -... Line 317...
-
 
317
endp
-
 
318
 
-
 
319
proc img._.convert.bpp32_to_bpp1 _src, _dst
-
 
320
        push    esi
-
 
321
        stdcall img.convert.layer, [_src], 0, Image.bpp24, 0, 0
-
 
322
        test    eax, eax
-
 
323
        jz      .exit
-
 
324
        push    eax
-
 
325
        stdcall img.convert.layer, eax, 0, Image.bpp8g, 0, 0
-
 
326
        mov     esi, eax
-
 
327
        stdcall img.destroy     ; arg pushed
-
 
328
        test    esi, esi
-
 
329
        jz      .exit
-
 
330
        push    esi
-
 
331
        mov     ecx, [_dst]
-
 
332
        stdcall img.convert.layer, esi, ecx, [ecx+Image.Type], 0, 0
-
 
333
        stdcall img.destroy     ; arg pushed
-
 
334
.exit:
-
 
335
        pop     esi
-
 
336
        ret
-
 
337
endp
-
 
338
 
-
 
339
proc img._.convert.bpp32_to_bpp8g _src, _dst
-
 
340
        stdcall img.convert.layer, [_src], 0, Image.bpp24, 0, 0
-
 
341
        test    eax, eax
-
 
342
        jz      .exit
-
 
343
        push    eax
-
 
344
        mov     ecx, [_dst]
-
 
345
        stdcall img.convert.layer, eax, ecx, [ecx+Image.Type], 0, 0
-
 
346
        stdcall img.destroy     ; arg pushed
-
 
347
.exit:
Line 294... Line 348...
294
endp
348
        ret
295
 
349
endp
296
 
350
 
Line 297... Line 351...
297
proc img._.convert.bpp15_to_bpp24 _src, _dst
351
proc img._.convert.bpp15_to_bpp24 _src, _dst
298
        mov     ecx, [ebx + Image.Width]
352
        mov     ecx, [ebx + Image.Width]
299
        imul    ecx, [ebx + Image.Height]
353
        imul    ecx, [ebx + Image.Height]
300
 
354
 
301
  .bpp15.intel: ; copypasted from do_rgb
355
.bpp15.intel: ; copypasted from do_rgb
302
        push    ebx ebp
356
        push    ebx ebp
303
        sub     ecx, 4
357
        sub     ecx, 4
304
        jb      .bpp15.tail
358
        jb      .bpp15.tail
305
align 16
359
align 16
306
  .bpp15.intel.loop:
360
.bpp15.intel.loop:
307
repeat 2
361
repeat 2
Line 348... Line 402...
348
        mov     [edi + 4], bl
402
        mov     [edi + 4], bl
349
        add     edi, 6
403
        add     edi, 6
350
end repeat
404
end repeat
351
        sub     ecx, 4
405
        sub     ecx, 4
352
        jnb     .bpp15.intel.loop
406
        jnb     .bpp15.intel.loop
353
  .bpp15.tail:
407
.bpp15.tail:
354
        add     ecx, 4
408
        add     ecx, 4
355
        jz      .bpp15.done
409
        jz      .bpp15.done
356
    @@:
410
    @@:
357
        movzx   eax, word [esi]
411
        movzx   eax, word [esi]
358
        mov     ebx, eax
412
        mov     ebx, eax
Line 372... Line 426...
372
        mov     [edi + 1], bl
426
        mov     [edi + 1], bl
373
        mov     [edi + 2], ah
427
        mov     [edi + 2], ah
374
        add     edi, 3
428
        add     edi, 3
375
        sub     ecx, 1
429
        sub     ecx, 1
376
        jnz     @b
430
        jnz     @b
377
  .bpp15.done:
431
.bpp15.done:
378
        pop     ebp ebx
432
        pop     ebp ebx
379
        mov     eax, [_dst]
433
        mov     eax, [_dst]
380
        jmp     .quit
434
        jmp     .quit
Line 381... Line 435...
381
 
435
 
382
  .bpp15.amd:
436
.bpp15.amd:
383
        push    ebx ebp
437
        push    ebx ebp
384
        sub     ecx, 4
438
        sub     ecx, 4
385
        jb      .bpp15.tail
439
        jb      .bpp15.tail
386
align 16
440
align 16
387
  .bpp15.amd.loop:
441
.bpp15.amd.loop:
388
repeat 4
442
repeat 4
389
if (% mod 2) = 1
443
if (% mod 2) = 1
390
        mov     eax, dword[esi]
444
        mov     eax, dword[esi]
391
        mov     ebx, dword[esi]
445
        mov     ebx, dword[esi]
Line 412... Line 466...
412
end repeat
466
end repeat
413
        sub     ecx, 4
467
        sub     ecx, 4
414
        jnb     .bpp15.amd.loop
468
        jnb     .bpp15.amd.loop
415
        jmp     .bpp15.tail
469
        jmp     .bpp15.tail
Line 416... Line 470...
416
 
470
 
417
  .quit:
471
.quit:
418
        ret
472
        ret
Line 419... Line 473...
419
endp
473
endp
420
 
474
 
421
 
475
 
422
proc img._.convert.bpp16_to_bpp24 _src, _dst
476
proc img._.convert.bpp16_to_bpp24 _src, _dst
423
        mov     ecx, [ebx + Image.Width]
477
        mov     ecx, [ebx + Image.Width]
424
        imul    ecx, [ebx + Image.Height]
478
        imul    ecx, [ebx + Image.Height]
425
  .bpp16.intel:
479
.bpp16.intel:
426
        push    ebx ebp
480
        push    ebx ebp
427
        sub     ecx, 4
481
        sub     ecx, 4
428
        jb      .bpp16.tail
482
        jb      .bpp16.tail
429
align 16
483
align 16
430
  .bpp16.intel.loop:
484
.bpp16.intel.loop:
431
repeat 2
485
repeat 2
432
        mov     ebx, [esi]
486
        mov     ebx, [esi]
Line 471... Line 525...
471
        mov     [edi + 4], bl
525
        mov     [edi + 4], bl
472
        add     edi, 6
526
        add     edi, 6
473
end repeat
527
end repeat
474
        sub     ecx, 4
528
        sub     ecx, 4
475
        jnb     .bpp16.intel.loop
529
        jnb     .bpp16.intel.loop
476
  .bpp16.tail:
530
.bpp16.tail:
477
        add     ecx, 4
531
        add     ecx, 4
478
        jz      .bpp16.done
532
        jz      .bpp16.done
479
    @@:
533
    @@:
480
        movzx   eax, word[esi]
534
        movzx   eax, word[esi]
481
        mov     ebx, eax
535
        mov     ebx, eax
Line 495... Line 549...
495
        mov     [edi + 1], bl
549
        mov     [edi + 1], bl
496
        mov     [edi + 2], ah
550
        mov     [edi + 2], ah
497
        add     edi, 3
551
        add     edi, 3
498
        sub     ecx, 1
552
        sub     ecx, 1
499
        jnz     @b
553
        jnz     @b
500
  .bpp16.done:
554
.bpp16.done:
501
        pop     ebp ebx
555
        pop     ebp ebx
502
        mov     eax, [_dst]
556
        mov     eax, [_dst]
503
        jmp     .quit
557
        jmp     .quit
Line 504... Line 558...
504
 
558
 
505
  .bpp16.amd:
559
.bpp16.amd:
506
        push    ebx ebp
560
        push    ebx ebp
507
        sub     ecx, 4
561
        sub     ecx, 4
508
        jb      .bpp16.tail
562
        jb      .bpp16.tail
509
align 16
563
align 16
510
  .bpp16.amd.loop:
564
.bpp16.amd.loop:
511
repeat 4
565
repeat 4
512
if (% mod 2) = 1
566
if (% mod 2) = 1
513
        mov     eax, dword[esi]
567
        mov     eax, dword[esi]
514
        mov     ebx, dword[esi]
568
        mov     ebx, dword[esi]
Line 535... Line 589...
535
end repeat
589
end repeat
536
        sub     ecx, 4
590
        sub     ecx, 4
537
        jnb     .bpp16.amd.loop
591
        jnb     .bpp16.amd.loop
538
        jmp     .bpp16.tail
592
        jmp     .bpp16.tail
Line 539... Line 593...
539
 
593
 
540
  .quit:
594
.quit:
541
        ret
595
        ret
Line 542... Line 596...
542
endp
596
endp
543
 
597
 
544
 
598
 
545
proc img._.convert.bpp1_to_bpp24 _src, _dst
599
proc img._.convert.bpp1_to_bpp24 uses ebx, _src, _dst
546
locals
600
locals
547
        width   rd 1
601
        width   rd 1
548
        height  rd 1
602
        height  rd 1
549
endl
603
endl
550
        push    [ebx + Image.Width]
604
        push    [ebx + Image.Width]
551
        pop     [width]
605
        pop     [width]
552
        push    [ebx + Image.Height]
606
        push    [ebx + Image.Height]
553
        pop     [height]
607
        pop     [height]
554
        mov     edx, [ebx + Image.Palette]
608
        mov     edx, [ebx + Image.Palette]
555
  .bpp1_to_bpp24.line:
609
.bpp1_to_bpp24.line:
556
        mov     ebx, [width]
610
        mov     ebx, [width]
557
  .bpp1_to_bpp24.byte:
611
.bpp1_to_bpp24.byte:
558
        mov     ah, 8
612
        mov     ah, 8
559
        mov     al, byte[esi]
613
        mov     al, byte[esi]
560
        add     esi, 1
614
        add     esi, 1
561
  .bpp1_to_bpp24.bit:
615
.bpp1_to_bpp24.bit:
562
        xor     ecx, ecx
616
        xor     ecx, ecx
563
        shl     al, 1
617
        shl     al, 1
Line 570... Line 624...
570
        sub     ebx, 1
624
        sub     ebx, 1
571
        jnz     @f
625
        jnz     @f
572
        sub     [height], 1
626
        sub     [height], 1
573
        jnz     .bpp1_to_bpp24.line
627
        jnz     .bpp1_to_bpp24.line
574
        jmp     .bpp1.done
628
        jmp     .bpp1.done
575
    @@:
629
@@:
576
        sub     ah, 1
630
        sub     ah, 1
577
        jnz     .bpp1_to_bpp24.bit
631
        jnz     .bpp1_to_bpp24.bit
578
        jmp     .bpp1_to_bpp24.byte
632
        jmp     .bpp1_to_bpp24.byte
579
  .bpp1.done:
633
.bpp1.done:
580
        ret
634
        ret
581
endp
635
endp
Line -... Line 636...
-
 
636
 
-
 
637
proc img._.convert.bpp1_to_bpp32 _src, _dst
-
 
638
        stdcall img.convert.layer, [_src], 0, Image.bpp24, 0, 0
-
 
639
        test    eax, eax
-
 
640
        jz      .exit
-
 
641
        push    eax
-
 
642
        mov     ecx, [_dst]
-
 
643
        stdcall img.convert.layer, eax, ecx, [ecx+Image.Type], 0, 0
-
 
644
        stdcall img.destroy     ; arg pushed
-
 
645
.exit:
-
 
646
        ret
-
 
647
endp
-
 
648
 
-
 
649
proc img._.convert.bpp1_to_bpp8g _src, _dst
-
 
650
locals
-
 
651
        width   rd 1
-
 
652
        height  rd 1
-
 
653
endl
-
 
654
        push    [ebx + Image.Width]
-
 
655
        pop     [width]
-
 
656
        push    [ebx + Image.Height]
-
 
657
        pop     [height]
-
 
658
.line:
-
 
659
        mov     edx, [width]
-
 
660
.byte:
-
 
661
        mov     ah, 8
-
 
662
        mov     al, byte[esi]
-
 
663
        inc     esi
-
 
664
.bit:
-
 
665
        xor     ecx, ecx
-
 
666
        shl     al, 1
-
 
667
        sbb     ecx, 0
-
 
668
        mov     byte[edi], cl
-
 
669
        inc     edi
-
 
670
        dec     edx
-
 
671
        jnz     @f
-
 
672
        dec     [height]
-
 
673
        jnz     .line
-
 
674
        jmp     .done
-
 
675
@@:
-
 
676
        dec     ah
-
 
677
        jnz     .bit
-
 
678
        jmp     .byte
-
 
679
.done:
-
 
680
        ret
Line 582... Line 681...
582
 
681
endp
583
 
682
 
584
proc img._.convert.bpp8a_to_bpp1 _src, _dst
683
proc img._.convert.bpp8a_to_bpp1 _src, _dst
585
        mov     eax, [_dst]
684
        mov     eax, [_dst]
586
        mov     eax, [eax + Image.Palette]
685
        mov     eax, [eax + Image.Palette]
587
        mov     dword[eax], 0x00000000
686
        mov     dword[eax], 0x00000000
588
        mov     dword[eax + 4], 0xffffffff
687
        mov     dword[eax + 4], 0xffffffff
589
        mov     edx, [ebx + Image.Height]
688
        mov     edx, [ebx + Image.Height]
590
  .bpp8a_to_bpp1.line:
689
.bpp8a_to_bpp1.line:
591
        mov     ax, 0x0800
690
        mov     ax, 0x0800
592
        mov     ecx, [ebx + Image.Width]
691
        mov     ecx, [ebx + Image.Width]
593
  .bpp8a_to_bpp1.pixel:
692
.bpp8a_to_bpp1.pixel:
594
        shl     al, 1
693
        shl     al, 1
595
        cmp     byte[esi], 0x7f
694
        cmp     byte[esi], 0x7f
596
        cmc
695
        cmc
597
        adc     eax, 0
696
        adc     eax, 0
598
        add     esi, 2
697
        add     esi, 2
599
        dec     ah
698
        dec     ah
600
        jnz     @f
699
        jnz     @f
601
        mov     byte[edi], al
700
        mov     byte[edi], al
602
        add     edi, 1
701
        add     edi, 1
603
        mov     ax, 0x0800
702
        mov     ax, 0x0800
604
    @@:
703
@@:
605
        dec     ecx
704
        dec     ecx
606
        jnz     .bpp8a_to_bpp1.pixel
705
        jnz     .bpp8a_to_bpp1.pixel
607
        cmp     ah, 8
706
        cmp     ah, 8
608
        je      @f
707
        je      @f
609
        mov     cl, ah
708
        mov     cl, ah
610
        shl     al, cl
709
        shl     al, cl
611
        mov     byte[edi], al
710
        mov     byte[edi], al
612
        add     edi, 1
711
        add     edi, 1
613
    @@:
712
@@:
614
        dec     edx
713
        dec     edx
615
        jnz     .bpp8a_to_bpp1.line
714
        jnz     .bpp8a_to_bpp1.line
Line 616... Line 715...
616
        ret
715
        ret
617
endp
716
endp
618
 
717
 
619
 
718
 
620
proc img._.convert.bpp8a_to_bpp24 _src, _dst
719
proc img._.convert.bpp8a_to_bpp24 _src, _dst
621
        mov     ecx, [ebx + Image.Width]
720
        mov     ecx, [ebx + Image.Width]
622
        imul    ecx, [ebx + Image.Height]
721
        imul    ecx, [ebx + Image.Height]
623
    @@:
722
@@:
624
        mov     al, byte[esi]
723
        mov     al, byte[esi]
Line 634... Line 733...
634
 
733
 
635
 
734
 
636
proc img._.convert.bpp8a_to_bpp32 _src, _dst
735
proc img._.convert.bpp8a_to_bpp32 _src, _dst
637
        mov     ecx, [ebx + Image.Width]
736
        mov     ecx, [ebx + Image.Width]
638
        imul    ecx, [ebx + Image.Height]
737
        imul    ecx, [ebx + Image.Height]
639
    @@:
738
@@:
640
        lodsw
739
        lodsw
641
        shl     eax, 8
740
        shl     eax, 8
642
        mov     al, ah
741
        mov     al, ah
Line 655... Line 754...
655
        dd 0
754
        dd 0
656
img.convert.bpp24.table:
755
img.convert.bpp24.table:
657
        dd Image.bpp24, img._.convert.bpp24_to_bpp24
756
        dd Image.bpp24, img._.convert.bpp24_to_bpp24
658
        dd Image.bpp8g, img._.convert.bpp24_to_bpp8g
757
        dd Image.bpp8g, img._.convert.bpp24_to_bpp8g
659
        dd Image.bpp32, img._.convert.bpp24_to_bpp32
758
        dd Image.bpp32, img._.convert.bpp24_to_bpp32
-
 
759
        dd Image.bpp1,  img._.convert.bpp24_to_bpp1
660
        dd 0
760
        dd 0
661
img.convert.bpp32.table:
761
img.convert.bpp32.table:
662
        dd Image.bpp24, img._.convert.bpp32_to_bpp24
762
        dd Image.bpp24, img._.convert.bpp32_to_bpp24
663
        dd Image.bpp32, img._.convert.bpp32_to_bpp32
763
        dd Image.bpp32, img._.convert.bpp32_to_bpp32
-
 
764
        dd Image.bpp1,  img._.convert.bpp32_to_bpp1
-
 
765
        dd Image.bpp8g, img._.convert.bpp32_to_bpp8g
664
        dd 0
766
        dd 0
665
img.convert.bpp15.table:
767
img.convert.bpp15.table:
666
        dd Image.bpp24, img._.convert.bpp15_to_bpp24
768
        dd Image.bpp24, img._.convert.bpp15_to_bpp24
667
        dd 0
769
        dd 0
668
img.convert.bpp16.table:
770
img.convert.bpp16.table:
669
        dd Image.bpp24, img._.convert.bpp16_to_bpp24
771
        dd Image.bpp24, img._.convert.bpp16_to_bpp24
670
        dd 0
772
        dd 0
671
img.convert.bpp1.table:
773
img.convert.bpp1.table:
672
        dd Image.bpp24, img._.convert.bpp1_to_bpp24
774
        dd Image.bpp24, img._.convert.bpp1_to_bpp24
-
 
775
        dd Image.bpp32, img._.convert.bpp1_to_bpp32
-
 
776
        dd Image.bpp8g, img._.convert.bpp1_to_bpp8g
673
        dd 0
777
        dd 0
674
img.convert.bpp8g.table:
778
img.convert.bpp8g.table:
675
        dd Image.bpp24, img._.convert.bpp8g_to_bpp24
779
        dd Image.bpp24, img._.convert.bpp8g_to_bpp24
-
 
780
        dd Image.bpp32, img._.convert.bpp8g_to_bpp32
676
        dd Image.bpp1,  img._.convert.bpp8g_to_bpp1
781
        dd Image.bpp1,  img._.convert.bpp8g_to_bpp1
677
        dd 0
782
        dd 0
678
img.convert.bpp2i.table:
783
img.convert.bpp2i.table:
679
        dd 0
784
        dd 0
680
img.convert.bpp4i.table:
785
img.convert.bpp4i.table: