Subversion Repositories Kolibri OS

Rev

Rev 8449 | Show entire file | Regard 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
;;                                                                                                ;;
6
;;                                                                            ;;
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 ;;
-
 
9
;; of the License, or (at your option) any later version.                                         ;;
7
;; SPDX-License-Identifier: LGPL-2.1-or-later                                 ;;
10
;;                                                                                                ;;
8
;;                                                                            ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
9
;; Libs-Dev is free software: you can redistribute it and/or modify it under  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
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   ;;
13
;; Lesser General Public License for more details.                                                ;;
12
;; option) any later version.                                                 ;;
14
;;                                                                                                ;;
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      ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public        ;;
16
;; If not, see .                                                    ;;
17
;; License for more details.                                                  ;;
17
;;                                                                                                ;;
18
;;                                                                            ;;
-
 
19
;; You should have received a copy of the GNU Lesser General Public License   ;;
-
 
20
;; along with Libs-Dev. If not, see .           ;;
-
 
21
;;                                                                            ;;
18
;;================================================================================================;;
22
;;============================================================================;;
19
 
-
 
Line 20... Line 23...
20
 
23
 
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 ?
Line 73... Line 76...
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
Line 149... Line 151...
149
        shr     eax, 16
151
        shr     eax, 16
150
        mov     [edi + 2], al
152
        mov     [edi + 2], al
151
        ret
153
        ret
152
endp
154
endp
Line 153... Line -...
153
 
-
 
154
 
155
 
155
proc img._.convert.bpp8i_to_bpp32 _src, _dst
156
proc img._.convert.bpp8i_to_bpp32 _src, _dst
156
        mov     ecx, [ebx + Image.Width]
157
        mov     ecx, [ebx + Image.Width]
Line 157... Line 158...
157
        imul    ecx, [ebx + Image.Height]
158
        imul    ecx, [ebx + Image.Height]
Line 166... Line 167...
166
        dec     ecx
167
        dec     ecx
167
        jnz     @b
168
        jnz     @b
168
        ret
169
        ret
169
endp
170
endp
Line 170... Line -...
170
 
-
 
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
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
@@:
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
@@:
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]
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 540... Line 594...
540
  .quit:
594
.quit:
541
        ret
595
        ret
542
endp
596
endp
Line 543... Line 597...
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
Line 578... Line 632...
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]
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: