Subversion Repositories Kolibri OS

Rev

Rev 8449 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9713 dunkaist 1
;;============================================================================;;
2
;;//// convert.asm //// (c) dunkaist, 2012,2016,2017,2020,2022 ///////////////;;
3
;;============================================================================;;
4
;;                                                                            ;;
5
;; This file is part of Common development libraries (Libs-Dev).              ;;
6
;;                                                                            ;;
7
;; SPDX-License-Identifier: LGPL-2.1-or-later                                 ;;
8
;;                                                                            ;;
9
;; Libs-Dev is free software: you can redistribute it and/or modify it under  ;;
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   ;;
12
;; option) any later version.                                                 ;;
13
;;                                                                            ;;
14
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT    ;;
15
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      ;;
16
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public        ;;
17
;; License for more details.                                                  ;;
18
;;                                                                            ;;
19
;; You should have received a copy of the GNU Lesser General Public License   ;;
20
;; along with Libs-Dev. If not, see .           ;;
21
;;                                                                            ;;
22
;;============================================================================;;
3056 dunkaist 23
 
6807 dunkaist 24
 
9713 dunkaist 25
;;============================================================================;;
26
proc img.convert _src, _dst, _dst_type, _flags, _param                        ;;
27
;;----------------------------------------------------------------------------;;
28
;? convert _image                                                             ;;
29
;;----------------------------------------------------------------------------;;
30
;> [_src]      = pointer to source image                                      ;;
31
;> [_dst]      = pointer to destination image, or 0 to create a new one       ;;
32
;> [_dst_type] = Image.Type of resulting image                                ;;
33
;> [_flags]    = see libimg.inc                                               ;;
34
;> [_param]    = depends on _flags fields, see libimg.inc                     ;;
35
;;----------------------------------------------------------------------------;;
36
;< eax = 0 / pointer to converted image                                       ;;
37
;< ecx = error code / undefined                                               ;;
38
;;============================================================================;;
7105 dunkaist 39
locals
40
        img     dd ?
41
        prev    dd ?
42
endl
43
        push    ebx esi edi
44
        mov     [img], 0
45
        mov     [prev], 0
6807 dunkaist 46
        mov     ebx, [_src]
9713 dunkaist 47
@@:
6807 dunkaist 48
        mov     eax, [ebx + Image.Previous]
49
        test    eax, eax
50
        jz      .loop
51
        mov     ebx, eax
52
        jmp     @b
9713 dunkaist 53
.loop:
6807 dunkaist 54
        stdcall img.convert.layer, ebx, [_dst], [_dst_type], [_flags], [_param]
55
        test    eax, eax
56
        jz      .error
7105 dunkaist 57
        cmp     [img], 0
6807 dunkaist 58
        jnz     @f
7105 dunkaist 59
        mov     [img], eax
9713 dunkaist 60
@@:
7105 dunkaist 61
        mov     ecx, [prev]
6807 dunkaist 62
        jecxz   @f
63
        mov     [ecx + Image.Next], eax
7105 dunkaist 64
        mov     [eax + Image.Previous], ecx
9713 dunkaist 65
@@:
7105 dunkaist 66
        mov     [prev], eax
67
        push    [ebx + Image.Flags]
68
        pop     [eax + Image.Flags]
69
        push    [ebx + Image.Delay]
70
        pop     [eax + Image.Delay]
6807 dunkaist 71
        mov     ebx, [ebx + Image.Next]
72
        test    ebx, ebx
73
        jnz     .loop
7105 dunkaist 74
        mov     eax, [img]
9713 dunkaist 75
.error:
7105 dunkaist 76
        pop     edi esi ebx
6807 dunkaist 77
        ret
78
endp
79
 
80
 
9713 dunkaist 81
;;============================================================================;;
82
proc img.convert.layer _src, _dst, _dst_type, _flags, _param                  ;;
83
;;----------------------------------------------------------------------------;;
84
;? convert _image layer                                                       ;;
85
;;----------------------------------------------------------------------------;;
86
;> [_src]      = pointer to source image                                      ;;
87
;> [_dst]      = pointer to destination image, or 0 to create a new one       ;;
88
;> [_dst_type] = Image.Type of resulting image                                ;;
89
;> [_flags]    = see libimg.inc                                               ;;
90
;> [_param]    = depends on _flags fields, see libimg.inc                     ;;
91
;;----------------------------------------------------------------------------;;
92
;< eax = 0 / pointer to converted image                                       ;;
93
;< ecx = error code / undefined                                               ;;
94
;;============================================================================;;
3056 dunkaist 95
locals
7105 dunkaist 96
        fun     rd 1
3056 dunkaist 97
endl
6807 dunkaist 98
        push    ebx esi edi
99
 
7105 dunkaist 100
        mov     ebx, [_src]
101
        mov     eax, [ebx + Image.Type]
102
        mov     esi, [img.convert.table + 4*eax]
9713 dunkaist 103
        mov     ecx, LIBIMG_ERROR_BIT_DEPTH
104
.next:
7105 dunkaist 105
        lodsd
106
        test    eax, eax
9713 dunkaist 107
        jz      .exit
7105 dunkaist 108
        cmp     eax, [_dst_type]
109
        lodsd
110
        jnz     .next
111
        mov     [fun], eax
112
 
113
        mov     eax, [_dst]
114
        test    eax, eax
115
        jnz     @f
9713 dunkaist 116
        stdcall img.create, [ebx + Image.Width], [ebx + Image.Height], \
117
                [_dst_type]
7105 dunkaist 118
        test    eax, eax
119
        jz      .exit
120
        mov     [_dst], eax
9713 dunkaist 121
@@:
7105 dunkaist 122
        mov     edi, [eax + Image.Data]
123
        mov     esi, [ebx + Image.Data]
124
        mov     eax, [ebx + Image.Type]
125
        stdcall [fun], [_src], [_dst]
126
        mov     eax, [_dst]
9713 dunkaist 127
.exit:
7105 dunkaist 128
        pop     edi esi ebx
129
        ret
130
endp
3056 dunkaist 131
 
7105 dunkaist 132
proc img._.convert.bpp8i_to_bpp24 _src, _dst
133
        mov     ecx, [ebx + Image.Width]
134
        imul    ecx, [ebx + Image.Height]
135
 
136
        mov     ebx, [ebx + Image.Palette]
137
        sub     ecx, 1
138
        jz      .bpp8i.last
9713 dunkaist 139
@@:
7105 dunkaist 140
        movzx   eax, byte[esi]
141
        add     esi, 1
142
        mov     eax, [ebx + eax*4]
143
        mov     [edi], eax
144
        add     edi, 3
145
        sub     ecx, 1
146
        jnz     @b
9713 dunkaist 147
.bpp8i.last:
7105 dunkaist 148
        movzx   eax, byte[esi]
149
        mov     eax, [ebx + eax*4]
150
        mov     [edi], ax
151
        shr     eax, 16
152
        mov     [edi + 2], al
153
        ret
154
endp
3056 dunkaist 155
 
7105 dunkaist 156
proc img._.convert.bpp8i_to_bpp32 _src, _dst
157
        mov     ecx, [ebx + Image.Width]
158
        imul    ecx, [ebx + Image.Height]
3056 dunkaist 159
 
7105 dunkaist 160
        mov     ebx, [ebx + Image.Palette]
9713 dunkaist 161
@@:
7105 dunkaist 162
        movzx   eax, byte[esi]
163
        add     esi, 1
164
        mov     eax, [ebx + eax*4]
165
        mov     [edi], eax
166
        add     edi, 4
167
        dec     ecx
168
        jnz     @b
169
        ret
170
endp
3056 dunkaist 171
 
7105 dunkaist 172
proc img._.convert.bpp8g_to_bpp1 _src, _dst
173
        mov     eax, [_dst]
174
        mov     eax, [eax + Image.Palette]
175
        mov     dword[eax], 0x00000000
8394 dunkaist 176
        mov     dword[eax + 4], 0xffffffff
7105 dunkaist 177
        mov     edx, [ebx + Image.Height]
9713 dunkaist 178
.bpp8g_to_bpp1.line:
7105 dunkaist 179
        mov     ax, 0x0800
180
        mov     ecx, [ebx + Image.Width]
9713 dunkaist 181
.bpp8g_to_bpp1.pixel:
7105 dunkaist 182
        shl     al, 1
183
        cmp     byte[esi], 0x7f
184
        cmc
185
        adc     eax, 0
186
        add     esi, 1
187
        dec     ah
188
        jnz     @f
189
        mov     byte[edi], al
190
        add     edi, 1
191
        mov     ax, 0x0800
9713 dunkaist 192
@@:
7105 dunkaist 193
        dec     ecx
194
        jnz     .bpp8g_to_bpp1.pixel
195
        cmp     ah, 8
196
        je      @f
197
        mov     cl, ah
198
        shl     al, cl
199
        mov     byte[edi], al
200
        add     edi, 1
9713 dunkaist 201
@@:
7105 dunkaist 202
        dec     edx
203
        jnz     .bpp8g_to_bpp1.line
204
        ret
205
endp
3056 dunkaist 206
 
7105 dunkaist 207
proc img._.convert.bpp8g_to_bpp24 _src, _dst
208
        mov     ecx, [ebx + Image.Width]
209
        imul    ecx, [ebx + Image.Height]
9713 dunkaist 210
@@:
7105 dunkaist 211
        mov     al, byte[esi]
212
        mov     byte[edi + 0], al
213
        mov     byte[edi + 1], al
214
        mov     byte[edi + 2], al
215
        add     esi, 1
216
        add     edi, 3
217
        sub     ecx, 1
218
        jnz     @b
219
        ret
220
endp
6807 dunkaist 221
 
9713 dunkaist 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
236
endp
7105 dunkaist 237
 
238
proc img._.convert.bpp24_to_bpp24 _src, _dst
239
        mov     ecx, [ebx + Image.Width]
240
        imul    ecx, [ebx + Image.Height]
241
        lea     ecx, [ecx*3]
242
        mov     edx, ecx
243
        shr     ecx, 2
244
        rep     movsd
245
        mov     ecx, edx
246
        and     ecx, 3
247
        rep     movsb
248
        ret
249
endp
250
 
251
proc img._.convert.bpp24_to_bpp8g _src, _dst
252
        mov     ecx, [ebx + Image.Width]
253
        imul    ecx, [ebx + Image.Height]
9713 dunkaist 254
@@:
7105 dunkaist 255
        movzx   ebx, byte[esi + 0]
256
        movzx   eax, byte[esi + 1]
257
        add     ebx, eax
258
        movzx   eax, byte[esi + 2]
259
        add     eax, ebx
260
        mov     ebx, 3
261
        add     esi, 3
262
        div     bl
263
        mov     byte[edi], al
264
        add     edi, 1
265
        sub     ecx, 1
266
        jnz     @b
267
        ret
268
endp
3056 dunkaist 269
 
7105 dunkaist 270
proc img._.convert.bpp24_to_bpp32 _src, _dst
271
        mov     ecx, [ebx + Image.Width]
272
        imul    ecx, [ebx + Image.Height]
9713 dunkaist 273
@@:
6807 dunkaist 274
        lodsw
275
        ror     eax, 16
276
        lodsb
8394 dunkaist 277
        mov     ah, 0xff        ; opaque
6807 dunkaist 278
        rol     eax, 16
279
        stosd
280
        dec     ecx
281
        jnz     @b
7105 dunkaist 282
        ret
283
endp
3056 dunkaist 284
 
9713 dunkaist 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
295
endp
3056 dunkaist 296
 
7105 dunkaist 297
proc img._.convert.bpp32_to_bpp24 _src, _dst
298
        mov     ecx, [ebx + Image.Width]
299
        imul    ecx, [ebx + Image.Height]
9713 dunkaist 300
@@:
7105 dunkaist 301
        mov     eax, [esi]
302
        mov     [edi], ax
303
        shr     eax, 16
304
        mov     [edi + 2], al
305
        add     esi, 4
306
        add     edi, 3
307
        sub     ecx, 1
308
        jnz     @b
309
        ret
310
endp
3056 dunkaist 311
 
7105 dunkaist 312
proc img._.convert.bpp32_to_bpp32 _src, _dst
313
        mov     ecx, [ebx + Image.Width]
314
        imul    ecx, [ebx + Image.Height]
315
        rep     movsd
316
        ret
317
endp
3056 dunkaist 318
 
9713 dunkaist 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
7105 dunkaist 338
 
9713 dunkaist 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:
348
        ret
349
endp
350
 
7105 dunkaist 351
proc img._.convert.bpp15_to_bpp24 _src, _dst
352
        mov     ecx, [ebx + Image.Width]
353
        imul    ecx, [ebx + Image.Height]
354
 
9713 dunkaist 355
.bpp15.intel: ; copypasted from do_rgb
7105 dunkaist 356
        push    ebx ebp
357
        sub     ecx, 4
358
        jb      .bpp15.tail
3056 dunkaist 359
align 16
9713 dunkaist 360
.bpp15.intel.loop:
3056 dunkaist 361
repeat 2
7105 dunkaist 362
        mov     ebx, [esi]
363
        mov     al, [esi]
364
        mov     ah, [esi + 1]
365
        add     esi, 4
366
        and     al, 0x1F
367
        and     ah, 0x1F shl 2
368
        mov     ebp, ebx
369
        mov     dl, al
370
        mov     dh, ah
371
        shr     al, 2
372
        shr     ah, 4
373
        shl     dl, 3
374
        shl     dh, 1
375
        and     ebp, 0x1F shl 5
376
        add     al, dl
377
        add     ah, dh
378
        shr     ebp, 2
379
        mov     [edi], al
380
        mov     [edi + 2], ah
381
        mov     eax, ebx
382
        mov     ebx, ebp
383
        shr     eax, 16
384
        shr     ebx, 5
385
        add     ebx, ebp
386
        mov     ebp, eax
387
        mov     [edi + 1], bl
388
        and     eax, (0x1F) or (0x1F shl 10)
389
        and     ebp, 0x1F shl 5
390
        lea     edx, [eax + eax]
391
        shr     al, 2
392
        mov     ebx, ebp
393
        shr     ah, 4
394
        shl     dl, 2
395
        shr     ebx, 2
396
        shr     ebp, 7
397
        add     al, dl
398
        add     ah, dh
399
        mov     [edi + 3], al
400
        add     ebx, ebp
401
        mov     [edi + 5], ah
402
        mov     [edi + 4], bl
403
        add     edi, 6
3056 dunkaist 404
end repeat
7105 dunkaist 405
        sub     ecx, 4
406
        jnb     .bpp15.intel.loop
9713 dunkaist 407
.bpp15.tail:
7105 dunkaist 408
        add     ecx, 4
409
        jz      .bpp15.done
3056 dunkaist 410
    @@:
7105 dunkaist 411
        movzx   eax, word [esi]
412
        mov     ebx, eax
413
        add     esi, 2
414
        and     eax, (0x1F) or (0x1F shl 10)
415
        and     ebx, 0x1F shl 5
416
        lea     edx, [eax + eax]
417
        shr     al, 2
418
        mov     ebp, ebx
419
        shr     ebx, 2
420
        shr     ah, 4
421
        shl     dl, 2
422
        shr     ebp, 7
423
        add     eax, edx
424
        add     ebx, ebp
425
        mov     [edi], al
426
        mov     [edi + 1], bl
427
        mov     [edi + 2], ah
428
        add     edi, 3
429
        sub     ecx, 1
430
        jnz     @b
9713 dunkaist 431
.bpp15.done:
7105 dunkaist 432
        pop     ebp ebx
433
        mov     eax, [_dst]
434
        jmp     .quit
3056 dunkaist 435
 
9713 dunkaist 436
.bpp15.amd:
7105 dunkaist 437
        push    ebx ebp
438
        sub     ecx, 4
439
        jb      .bpp15.tail
3056 dunkaist 440
align 16
9713 dunkaist 441
.bpp15.amd.loop:
3056 dunkaist 442
repeat 4
443
if (% mod 2) = 1
7105 dunkaist 444
        mov     eax, dword[esi]
445
        mov     ebx, dword[esi]
3056 dunkaist 446
else
7105 dunkaist 447
        movzx   eax, word[esi]
448
        mov     ebx, eax
3056 dunkaist 449
end if
7105 dunkaist 450
        add     esi, 2
451
        and     eax, (0x1F) or (0x1F shl 10)
452
        and     ebx, 0x1F shl 5
453
        lea     edx, [eax + eax]
454
        shr     al, 2
455
        mov     ebp, ebx
456
        shr     ebx, 2
457
        shr     ah, 4
458
        shl     dl, 2
459
        shr     ebp, 7
460
        add     eax, edx
461
        add     ebx, ebp
462
        mov     [edi], al
463
        mov     [edi + 1], bl
464
        mov     [edi + 2], ah
465
        add     edi, 3
3056 dunkaist 466
end repeat
7105 dunkaist 467
        sub     ecx, 4
468
        jnb     .bpp15.amd.loop
469
        jmp     .bpp15.tail
3056 dunkaist 470
 
9713 dunkaist 471
.quit:
7105 dunkaist 472
        ret
473
endp
3056 dunkaist 474
 
7105 dunkaist 475
 
476
proc img._.convert.bpp16_to_bpp24 _src, _dst
477
        mov     ecx, [ebx + Image.Width]
478
        imul    ecx, [ebx + Image.Height]
9713 dunkaist 479
.bpp16.intel:
7105 dunkaist 480
        push    ebx ebp
481
        sub     ecx, 4
482
        jb      .bpp16.tail
3056 dunkaist 483
align 16
9713 dunkaist 484
.bpp16.intel.loop:
3056 dunkaist 485
repeat 2
7105 dunkaist 486
        mov     ebx, [esi]
487
        mov     al, [esi]
488
        mov     ah, [esi + 1]
489
        add     esi, 4
490
        and     al, 0x1F
491
        and     ah, 0x1F shl 3
492
        mov     ebp, ebx
493
        mov     dl, al
494
        mov     dh, ah
495
        shr     al, 2
496
        shr     ah, 5
497
        shl     dl, 3
498
        and     ebp, 0x3F shl 5
499
        add     al, dl
500
        add     ah, dh
501
        shr     ebp, 3
502
        mov     [edi], al
503
        mov     [edi + 2], ah
504
        mov     eax, ebx
505
        mov     ebx, ebp
506
        shr     eax, 16
507
        shr     ebx, 6
508
        add     ebx, ebp
509
        mov     ebp, eax
510
        mov     [edi + 1], bl
511
        and     eax, (0x1F) or (0x1F shl 11)
512
        and     ebp, 0x3F shl 5
513
        mov     edx, eax
514
        shr     al, 2
515
        mov     ebx, ebp
516
        shr     ah, 5
517
        shl     dl, 3
518
        shr     ebx, 3
519
        shr     ebp, 9
520
        add     al, dl
521
        add     ah, dh
522
        mov     [edi + 3], al
523
        add     ebx, ebp
524
        mov     [edi + 5], ah
525
        mov     [edi + 4], bl
526
        add     edi, 6
3056 dunkaist 527
end repeat
7105 dunkaist 528
        sub     ecx, 4
529
        jnb     .bpp16.intel.loop
9713 dunkaist 530
.bpp16.tail:
7105 dunkaist 531
        add     ecx, 4
532
        jz      .bpp16.done
3056 dunkaist 533
    @@:
7105 dunkaist 534
        movzx   eax, word[esi]
535
        mov     ebx, eax
536
        add     esi, 2
537
        and     eax, (0x1F) or (0x1F shl 11)
538
        and     ebx, 0x3F shl 5
539
        mov     edx, eax
540
        shr     al, 2
541
        mov     ebp, ebx
542
        shr     ebx, 3
543
        shr     ah, 5
544
        shl     dl, 3
545
        shr     ebp, 9
546
        add     eax, edx
547
        add     ebx, ebp
548
        mov     [edi], al
549
        mov     [edi + 1], bl
550
        mov     [edi + 2], ah
551
        add     edi, 3
552
        sub     ecx, 1
553
        jnz     @b
9713 dunkaist 554
.bpp16.done:
7105 dunkaist 555
        pop     ebp ebx
556
        mov     eax, [_dst]
557
        jmp     .quit
3056 dunkaist 558
 
9713 dunkaist 559
.bpp16.amd:
7105 dunkaist 560
        push    ebx ebp
561
        sub     ecx, 4
562
        jb      .bpp16.tail
3056 dunkaist 563
align 16
9713 dunkaist 564
.bpp16.amd.loop:
3056 dunkaist 565
repeat 4
566
if (% mod 2) = 1
7105 dunkaist 567
        mov     eax, dword[esi]
568
        mov     ebx, dword[esi]
3056 dunkaist 569
else
7105 dunkaist 570
        movzx   eax, word[esi]
571
        mov     ebx, eax
3056 dunkaist 572
end if
7105 dunkaist 573
        add     esi, 2
574
        and     eax, (0x1F) or (0x1F shl 11)
575
        and     ebx, 0x3F shl 5
576
        mov     edx, eax
577
        shr     al, 2
578
        mov     ebp, ebx
579
        shr     ebx, 3
580
        shr     ah, 5
581
        shl     dl, 3
582
        shr     ebp, 9
583
        add     eax, edx
584
        add     ebx, ebp
585
        mov     [edi], al
586
        mov     [edi + 1], bl
587
        mov     [edi + 2], ah
588
        add     edi, 3
3056 dunkaist 589
end repeat
7105 dunkaist 590
        sub     ecx, 4
591
        jnb     .bpp16.amd.loop
592
        jmp     .bpp16.tail
3056 dunkaist 593
 
9713 dunkaist 594
.quit:
7105 dunkaist 595
        ret
596
endp
3056 dunkaist 597
 
7105 dunkaist 598
 
9713 dunkaist 599
proc img._.convert.bpp1_to_bpp24 uses ebx, _src, _dst
7105 dunkaist 600
locals
601
        width   rd 1
602
        height  rd 1
603
endl
604
        push    [ebx + Image.Width]
605
        pop     [width]
606
        push    [ebx + Image.Height]
607
        pop     [height]
608
        mov     edx, [ebx + Image.Palette]
9713 dunkaist 609
.bpp1_to_bpp24.line:
7105 dunkaist 610
        mov     ebx, [width]
9713 dunkaist 611
.bpp1_to_bpp24.byte:
7105 dunkaist 612
        mov     ah, 8
613
        mov     al, byte[esi]
614
        add     esi, 1
9713 dunkaist 615
.bpp1_to_bpp24.bit:
7105 dunkaist 616
        xor     ecx, ecx
617
        shl     al, 1
618
        adc     ecx, 0
619
        mov     ecx, [edx + 4*ecx]
620
        mov     word[edi], cx
621
        shr     ecx, 8
622
        mov     byte[edi + 2], ch
623
        add     edi, 3
624
        sub     ebx, 1
625
        jnz     @f
626
        sub     [height], 1
627
        jnz     .bpp1_to_bpp24.line
628
        jmp     .bpp1.done
9713 dunkaist 629
@@:
7105 dunkaist 630
        sub     ah, 1
631
        jnz     .bpp1_to_bpp24.bit
632
        jmp     .bpp1_to_bpp24.byte
9713 dunkaist 633
.bpp1.done:
7105 dunkaist 634
        ret
635
endp
3056 dunkaist 636
 
9713 dunkaist 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
3056 dunkaist 648
 
9713 dunkaist 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
681
endp
682
 
7105 dunkaist 683
proc img._.convert.bpp8a_to_bpp1 _src, _dst
684
        mov     eax, [_dst]
685
        mov     eax, [eax + Image.Palette]
686
        mov     dword[eax], 0x00000000
8394 dunkaist 687
        mov     dword[eax + 4], 0xffffffff
7105 dunkaist 688
        mov     edx, [ebx + Image.Height]
9713 dunkaist 689
.bpp8a_to_bpp1.line:
7105 dunkaist 690
        mov     ax, 0x0800
691
        mov     ecx, [ebx + Image.Width]
9713 dunkaist 692
.bpp8a_to_bpp1.pixel:
7105 dunkaist 693
        shl     al, 1
694
        cmp     byte[esi], 0x7f
695
        cmc
696
        adc     eax, 0
697
        add     esi, 2
698
        dec     ah
699
        jnz     @f
700
        mov     byte[edi], al
701
        add     edi, 1
702
        mov     ax, 0x0800
9713 dunkaist 703
@@:
7105 dunkaist 704
        dec     ecx
705
        jnz     .bpp8a_to_bpp1.pixel
706
        cmp     ah, 8
707
        je      @f
708
        mov     cl, ah
709
        shl     al, cl
710
        mov     byte[edi], al
711
        add     edi, 1
9713 dunkaist 712
@@:
7105 dunkaist 713
        dec     edx
714
        jnz     .bpp8a_to_bpp1.line
715
        ret
716
endp
3056 dunkaist 717
 
7105 dunkaist 718
 
719
proc img._.convert.bpp8a_to_bpp24 _src, _dst
720
        mov     ecx, [ebx + Image.Width]
721
        imul    ecx, [ebx + Image.Height]
9713 dunkaist 722
@@:
7105 dunkaist 723
        mov     al, byte[esi]
724
        mov     byte[edi + 0], al
725
        mov     byte[edi + 1], al
726
        mov     byte[edi + 2], al
727
        add     esi, 2
728
        add     edi, 3
729
        sub     ecx, 1
730
        jnz     @b
731
        ret
3056 dunkaist 732
endp
733
 
734
 
8449 dunkaist 735
proc img._.convert.bpp8a_to_bpp32 _src, _dst
736
        mov     ecx, [ebx + Image.Width]
737
        imul    ecx, [ebx + Image.Height]
9713 dunkaist 738
@@:
8449 dunkaist 739
        lodsw
740
        shl     eax, 8
741
        mov     al, ah
742
        shl     eax, 8
743
        mov     al, ah
744
        stosd
745
        dec     ecx
746
        jnz     @b
747
        ret
748
endp
749
 
750
 
3056 dunkaist 751
img.convert.bpp8i.table:
7105 dunkaist 752
        dd Image.bpp24, img._.convert.bpp8i_to_bpp24
753
        dd Image.bpp32, img._.convert.bpp8i_to_bpp32
754
        dd 0
3056 dunkaist 755
img.convert.bpp24.table:
7105 dunkaist 756
        dd Image.bpp24, img._.convert.bpp24_to_bpp24
757
        dd Image.bpp8g, img._.convert.bpp24_to_bpp8g
758
        dd Image.bpp32, img._.convert.bpp24_to_bpp32
9713 dunkaist 759
        dd Image.bpp1,  img._.convert.bpp24_to_bpp1
7105 dunkaist 760
        dd 0
3056 dunkaist 761
img.convert.bpp32.table:
7105 dunkaist 762
        dd Image.bpp24, img._.convert.bpp32_to_bpp24
763
        dd Image.bpp32, img._.convert.bpp32_to_bpp32
9713 dunkaist 764
        dd Image.bpp1,  img._.convert.bpp32_to_bpp1
765
        dd Image.bpp8g, img._.convert.bpp32_to_bpp8g
7105 dunkaist 766
        dd 0
3056 dunkaist 767
img.convert.bpp15.table:
7105 dunkaist 768
        dd Image.bpp24, img._.convert.bpp15_to_bpp24
769
        dd 0
3056 dunkaist 770
img.convert.bpp16.table:
7105 dunkaist 771
        dd Image.bpp24, img._.convert.bpp16_to_bpp24
772
        dd 0
3056 dunkaist 773
img.convert.bpp1.table:
7105 dunkaist 774
        dd Image.bpp24, img._.convert.bpp1_to_bpp24
9713 dunkaist 775
        dd Image.bpp32, img._.convert.bpp1_to_bpp32
776
        dd Image.bpp8g, img._.convert.bpp1_to_bpp8g
7105 dunkaist 777
        dd 0
778
img.convert.bpp8g.table:
779
        dd Image.bpp24, img._.convert.bpp8g_to_bpp24
9713 dunkaist 780
        dd Image.bpp32, img._.convert.bpp8g_to_bpp32
7105 dunkaist 781
        dd Image.bpp1,  img._.convert.bpp8g_to_bpp1
782
        dd 0
783
img.convert.bpp2i.table:
784
        dd 0
785
img.convert.bpp4i.table:
786
        dd 0
3056 dunkaist 787
img.convert.bpp8a.table:
7105 dunkaist 788
        dd Image.bpp24, img._.convert.bpp8a_to_bpp24
8449 dunkaist 789
        dd Image.bpp32, img._.convert.bpp8a_to_bpp32
7105 dunkaist 790
        dd 0
791
 
792
img.convert.table:
793
        dd 0    ; no image type zero
794
        dd img.convert.bpp8i.table
795
        dd img.convert.bpp24.table
796
        dd img.convert.bpp32.table
797
        dd img.convert.bpp15.table
798
        dd img.convert.bpp16.table
799
        dd img.convert.bpp1.table
800
        dd img.convert.bpp8g.table
801
        dd img.convert.bpp2i.table
802
        dd img.convert.bpp4i.table
803
        dd img.convert.bpp8a.table