Subversion Repositories Kolibri OS

Rev

Rev 8463 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8463 Rev 8497
Line 1... Line 1...
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                                ;;
-
 
3
;;                //// (c) diamond, 2009,                                     ;;
-
 
4
;;                //// (c) dunkaist, 2011-2020                                ;;
3
;;================================================================================================;;
5
;;============================================================================;;
4
;;												  ;;
6
;;                                                                            ;;
5
;; This file is part of Common development libraries (Libs-Dev).				  ;;
7
;; This file is part of Common development libraries (Libs-Dev).              ;;
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     ;;
9
;; of the License, or (at your option) any later version.					  ;;
11
;; Free Software Foundation, either version 2.1 of the License, or (at your   ;;
-
 
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
;;============================================================================;;
Line 19... Line 23...
19
 
23
 
Line 20... Line 24...
20
 
24
 
Line 56... Line 60...
56
COMPOSITE_MODE equ MMX
60
COMPOSITE_MODE equ MMX
57
; MMX | pretty fast and compatible
61
; MMX | pretty fast and compatible
58
; SSE | a bit faster, but may be unsupported by some CPUs
62
; SSE | a bit faster, but may be unsupported by some CPUs
59
include 'blend.asm'
63
include 'blend.asm'
Line 60... Line 64...
60
 
64
 
61
;;================================================================================================;;
65
;;============================================================================;;
62
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
66
proc lib_init ;///////////////////////////////////////////////////////////////;;
63
;;------------------------------------------------------------------------------------------------;;
67
;;----------------------------------------------------------------------------;;
64
;? Library entry point (called after library load)						  ;;
68
;? Library entry point (called after library load)                            ;;
65
;;------------------------------------------------------------------------------------------------;;
69
;;----------------------------------------------------------------------------;;
66
;> eax = pointer to memory allocation routine							  ;;
70
;> eax = pointer to memory allocation routine                                 ;;
67
;> ebx = pointer to memory freeing routine							  ;;
71
;> ebx = pointer to memory freeing routine                                    ;;
68
;> ecx = pointer to memory reallocation routine 						  ;;
72
;> ecx = pointer to memory reallocation routine                               ;;
69
;> edx = pointer to library loading routine							  ;;
73
;> edx = pointer to library loading routine                                   ;;
70
;;------------------------------------------------------------------------------------------------;;
74
;;----------------------------------------------------------------------------;;
71
;< eax = 1 (fail) / 0 (ok) (library initialization result)					  ;;
75
;< eax = 1 (fail) / 0 (ok) (library initialization result)                    ;;
72
;;================================================================================================;;
76
;;============================================================================;;
73
    mov [mem.alloc], eax
77
        mov     [mem.alloc], eax
74
    mov [mem.free], ebx
78
        mov     [mem.free], ebx
75
    mov [mem.realloc], ecx
79
        mov     [mem.realloc], ecx
Line 88... Line 92...
88
    jnz @f
92
        jnz     @f
89
    mov dword [img._.do_rgb.handlers + (Image.bpp15-1)*4], img._.do_rgb.bpp15.intel
93
        mov     dword [img._.do_rgb.handlers + (Image.bpp15-1)*4], img._.do_rgb.bpp15.intel
90
    mov dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
94
        mov     dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
91
  @@:
95
@@:
Line -... Line 96...
-
 
96
 
92
 
97
.ok:
93
  .ok:	xor eax,eax
98
        xor     eax, eax
94
    ret
99
        ret
Line 95... Line 100...
95
endp
100
endp
96
 
101
 
97
;;================================================================================================;;
102
;;============================================================================;;
98
proc img.is_img _data, _length ;//////////////////////////////////////////////////////////////////;;
103
proc img.is_img _data, _length ;//////////////////////////////////////////////;;
99
;;------------------------------------------------------------------------------------------------;;
104
;;----------------------------------------------------------------------------;;
100
;? --- TBD ---											  ;;
105
;? --- TBD ---                                                                ;;
101
;;------------------------------------------------------------------------------------------------;;
106
;;----------------------------------------------------------------------------;;
102
;> --- TBD ---											  ;;
107
;> --- TBD ---                                                                ;;
103
;;------------------------------------------------------------------------------------------------;;
108
;;----------------------------------------------------------------------------;;
104
;< --- TBD ---											  ;;
109
;< --- TBD ---                                                                ;;
105
;;================================================================================================;;
110
;;============================================================================;;
-
 
111
        push    ebx
106
    push    ebx
112
        mov     ebx, img.formats_table
107
    mov ebx, img.formats_table
113
@@:
108
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
114
        stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
109
    or	eax, eax
115
        or      eax, eax
110
    jnz @f
116
        jnz     @f
111
    add ebx, sizeof.FormatsTableEntry
117
        add     ebx, sizeof.FormatsTableEntry
112
    cmp dword[ebx], 0
118
        cmp     dword[ebx], 0
-
 
119
        jnz     @b
113
    jnz @b
120
        xor     eax, eax
114
    xor eax, eax
121
@@:
115
    @@: pop ebx
122
        pop     ebx
Line 116... Line 123...
116
    ret
123
        ret
117
endp
124
endp
118
 
125
 
119
;;================================================================================================;;
126
;;============================================================================;;
120
proc img.info _data, _length ;////////////////////////////////////////////////////////////////////;;
127
proc img.info _data, _length ;////////////////////////////////////////////////;;
121
;;------------------------------------------------------------------------------------------------;;
128
;;----------------------------------------------------------------------------;;
122
;? --- TBD ---											  ;;
129
;? --- TBD ---                                                                ;;
123
;;------------------------------------------------------------------------------------------------;;
130
;;----------------------------------------------------------------------------;;
124
;> --- TBD ---											  ;;
131
;> --- TBD ---                                                                ;;
125
;;------------------------------------------------------------------------------------------------;;
132
;;----------------------------------------------------------------------------;;
126
;< --- TBD ---											  ;;
133
;< --- TBD ---                                                                ;;
127
;;================================================================================================;;
134
;;============================================================================;;
Line 128... Line 135...
128
    xor eax, eax
135
        xor     eax, eax
129
    ret
136
        ret
130
endp
137
endp
131
 
138
 
132
;;================================================================================================;;
139
;;============================================================================;;
133
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
140
proc img.from_file _filename ;////////////////////////////////////////////////;;
134
;;------------------------------------------------------------------------------------------------;;
141
;;----------------------------------------------------------------------------;;
135
;? load file from disk and decode it								  ;;
142
;? load file from disk and decode it                                          ;;
136
;;------------------------------------------------------------------------------------------------;;
143
;;----------------------------------------------------------------------------;;
137
;> [_filename] = file name as passed to libio							  ;;
144
;> [_filename] = file name as passed to libio                                 ;;
138
;;------------------------------------------------------------------------------------------------;;
145
;;----------------------------------------------------------------------------;;
139
;< eax = 0 / pointer to image									  ;;
146
;< eax = 0 / pointer to image                                                 ;;
140
;;================================================================================================;;
147
;;============================================================================;;
141
locals
148
locals
Line 175... Line 182...
175
  .exit:
182
.exit:
176
	pop	ebx
183
        pop     ebx
177
	ret
184
        ret
178
endp
185
endp
Line 179... Line 186...
179
 
186
 
180
;;================================================================================================;;
187
;;============================================================================;;
181
proc img.to_file _img, _filename ;////////////////////////////////////////////////////////////////;;
188
proc img.to_file _img, _filename ;////////////////////////////////////////////;;
182
;;------------------------------------------------------------------------------------------------;;
189
;;----------------------------------------------------------------------------;;
183
;? --- TBD ---											  ;;
190
;? --- TBD ---                                                                ;;
184
;;------------------------------------------------------------------------------------------------;;
191
;;----------------------------------------------------------------------------;;
185
;> --- TBD ---											  ;;
192
;> --- TBD ---                                                                ;;
186
;;------------------------------------------------------------------------------------------------;;
193
;;----------------------------------------------------------------------------;;
187
;< eax = false / true										  ;;
194
;< eax = false / true                                                         ;;
188
;;================================================================================================;;
195
;;============================================================================;;
189
    xor eax, eax
196
        xor     eax, eax
190
    ret
197
        ret
Line 191... Line 198...
191
endp
198
endp
192
 
199
 
193
;;================================================================================================;;
200
;;============================================================================;;
194
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////////////////////////;;
201
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////;;
195
;;------------------------------------------------------------------------------------------------;;
202
;;----------------------------------------------------------------------------;;
196
;? --- TBD ---											  ;;
203
;? --- TBD ---                                                                ;;
197
;;------------------------------------------------------------------------------------------------;;
204
;;----------------------------------------------------------------------------;;
198
;> --- TBD ---											  ;;
205
;> --- TBD ---                                                                ;;
199
;;------------------------------------------------------------------------------------------------;;
206
;;----------------------------------------------------------------------------;;
200
;< eax = 0 / pointer to image									  ;;
207
;< eax = 0 / pointer to image                                                 ;;
201
;;================================================================================================;;
208
;;============================================================================;;
202
    xor eax, eax
209
        xor     eax, eax
Line 203... Line 210...
203
    ret
210
        ret
204
endp
211
endp
205
 
212
 
206
;;================================================================================================;;
213
;;============================================================================;;
207
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
214
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////;;
208
;;------------------------------------------------------------------------------------------------;;
215
;;----------------------------------------------------------------------------;;
209
;? decodes image data into RGB triplets and stores them where [_out] points to			  ;;
216
;? decodes image data into RGB triplets and stores them where [_out] points to;;
210
;;------------------------------------------------------------------------------------------------;;
217
;;----------------------------------------------------------------------------;;
211
;> [_img] = pointer to source image								  ;;
218
;> [_img] = pointer to source image                                           ;;
212
;> [_out] = where to store RGB triplets 							  ;;
219
;> [_out] = where to store RGB triplets                                       ;;
213
;;------------------------------------------------------------------------------------------------;;
220
;;----------------------------------------------------------------------------;;
214
;< none 											  ;;
221
;< none                                                                       ;;
215
;;================================================================================================;;
222
;;============================================================================;;
216
    push    esi edi
223
        push    esi edi
217
    mov esi, [_img]
224
        mov     esi, [_img]
Line 223... Line 230...
223
.ret:
230
.ret:
224
    pop edi esi
231
        pop     edi esi
225
    ret
232
        ret
226
endp
233
endp
Line 227... Line 234...
227
 
234
 
228
;;================================================================================================;;
235
;;============================================================================;;
229
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
236
proc img.to_rgb _img ;////////////////////////////////////////////////////////;;
230
;;------------------------------------------------------------------------------------------------;;
237
;;----------------------------------------------------------------------------;;
-
 
238
;? decodes image data into RGB triplets and returns pointer to memory area of ;;
231
;? decodes image data into RGB triplets and returns pointer to memory area of following structure:;;
239
;? following structure:                                                       ;;
232
;? width  dd ?											  ;;
240
;? width  dd ?                                                                ;;
233
;? height dd ?											  ;;
241
;? height dd ?                                                                ;;
234
;? rgb triplets 										  ;;
242
;? rgb triplets                                                               ;;
235
;;------------------------------------------------------------------------------------------------;;
243
;;----------------------------------------------------------------------------;;
236
;> [_img] = pointer to source image								  ;;
244
;> [_img] = pointer to source image                                           ;;
237
;;------------------------------------------------------------------------------------------------;;
245
;;----------------------------------------------------------------------------;;
238
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets)					  ;;
246
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets)                    ;;
239
;;================================================================================================;;
247
;;============================================================================;;
240
    push    esi edi
248
        push    esi edi
241
    mov esi, [_img]
249
        mov     esi, [_img]
242
    stdcall img._.validate, esi
250
        stdcall img._.validate, esi
243
    or	eax, eax
251
        or      eax, eax
Line 266... Line 274...
266
    xor eax, eax
274
        xor     eax, eax
267
    pop edi esi
275
        pop     edi esi
268
    ret
276
        ret
269
endp
277
endp
Line 270... Line 278...
270
 
278
 
271
;;================================================================================================;;
279
;;============================================================================;;
272
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
280
proc img._.do_rgb ;///////////////////////////////////////////////////////////;;
273
;;------------------------------------------------------------------------------------------------;;
281
;;----------------------------------------------------------------------------;;
274
;? decodes [esi + Image.Data] data into RGB triplets and stores them at [edi]			  ;;
282
;? decodes [esi + Image.Data] data into RGB triplets and stores them at [edi] ;;
275
;;------------------------------------------------------------------------------------------------;;
283
;;----------------------------------------------------------------------------;;
276
;> esi = pointer to source image								  ;;
284
;> esi = pointer to source image                                              ;;
277
;> edi = pointer to memory to store RGB triplets						  ;;
285
;> edi = pointer to memory to store RGB triplets                              ;;
278
;;------------------------------------------------------------------------------------------------;;
286
;;----------------------------------------------------------------------------;;
279
;< none 											  ;;
287
;< none                                                                       ;;
280
;;================================================================================================;;
288
;;============================================================================;;
281
    mov ecx, [esi + Image.Width]
289
        mov     ecx, [esi + Image.Width]
282
    imul    ecx, [esi + Image.Height]
290
        imul    ecx, [esi + Image.Height]
283
    mov eax, [esi + Image.Type]
291
        mov     eax, [esi + Image.Type]
Line 706... Line 714...
706
    pop ebp ebx
714
        pop     ebp ebx
707
    ret
715
        ret
Line 708... Line 716...
708
 
716
 
Line 709... Line 717...
709
endp
717
endp
710
 
718
 
711
;;================================================================================================;;
719
;;============================================================================;;
712
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
720
proc img.decode _data, _length, _options ;////////////////////////////////////;;
713
;;------------------------------------------------------------------------------------------------;;
721
;;----------------------------------------------------------------------------;;
714
;? decodes loaded into memory graphic file							  ;;
722
;? decodes loaded into memory graphic file                                    ;;
715
;;------------------------------------------------------------------------------------------------;;
723
;;----------------------------------------------------------------------------;;
716
;> [_data]    = pointer to file in memory							  ;;
724
;> [_data]    = pointer to file in memory                                     ;;
717
;> [_length]  = size in bytes of memory area pointed to by [_data]				  ;;
725
;> [_length]  = size in bytes of memory area pointed to by [_data]            ;;
718
;> [_options] = 0 / pointer to the structure of additional options				  ;;
726
;> [_options] = 0 / pointer to the structure of additional options            ;;
719
;;------------------------------------------------------------------------------------------------;;
727
;;----------------------------------------------------------------------------;;
720
;< eax = 0 / pointer to image									  ;;
728
;< eax = 0 / pointer to image                                                 ;;
721
;;================================================================================================;;
729
;;============================================================================;;
722
    push    ebx
730
        push    ebx
723
    mov ebx, [_length]
731
        mov     ebx, [_length]
724
    or  ebx,ebx
732
        or      ebx, ebx
-
 
733
        jz      .fail
725
    jz  .fail
734
        mov     ebx, img.formats_table
726
    mov ebx, img.formats_table
735
@@:
727
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
736
        stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
728
    or	eax, eax
737
        or      eax, eax
729
    jnz @f
738
        jnz     @f
730
    add ebx, sizeof.FormatsTableEntry
739
        add     ebx, sizeof.FormatsTableEntry
731
    cmp dword[ebx], eax ;0
740
        cmp     dword[ebx], eax ;0
732
    jnz @b
741
        jnz     @b
733
  .fail:
742
.fail:
734
    xor eax, eax
743
        xor     eax, eax
-
 
744
        pop     ebx
735
    pop ebx
745
        ret
736
    ret
746
@@:
737
    @@: mov eax, [ebx + FormatsTableEntry.Decode]
747
        mov     eax, [ebx + FormatsTableEntry.Decode]
738
    pop ebx
748
        pop     ebx
739
    leave
749
        leave
Line 740... Line 750...
740
    jmp eax
750
        jmp     eax
741
endp
751
endp
742
 
752
 
743
;;================================================================================================;;
753
;;============================================================================;;
744
proc img.encode uses ebx, _img, _common, _specific ;////////////////////////////////////////////////////////;;
754
proc img.encode uses ebx, _img, _common, _specific ;//////////////////////////;;
745
;;------------------------------------------------------------------------------------------------;;
755
;;----------------------------------------------------------------------------;;
746
;? encode image to some format									  ;;
756
;? encode image to some format                                                ;;
747
;;------------------------------------------------------------------------------------------------;;
757
;;----------------------------------------------------------------------------;;
748
;> [_img]      = pointer to input image 							  ;;
758
;> [_img]      = pointer to input image                                       ;;
749
;> [_common]   = some most important/common options						  ;;
759
;> [_common]   = some most important/common options                           ;;
-
 
760
;     0x00 :  byte : format id (defined in libimg.inc)                        ;;
750
;     0x00 :  byte : format id (defined in libimg.inc)						  ;;
761
;     0x01 :  byte : fast encoding (0) / best compression ratio (255)         ;;
751
;     0x01 :  byte : fast encoding (0) / best compression ratio (255)				  ;;
762
;                    0 : store uncompressed data (if supported both by the    ;;
-
 
763
;                        format and libimg)                                   ;;
752
;		     0 : store uncompressed data (if supported both by the format and libimg)	  ;;
764
;                    1 - 255 : use compression, if supported                  ;;
753
;		     1 - 255 : use compression, if supported					  ;;
765
;                        this option may be ignored if any format specific    ;;
754
;		     this option may be ignored if any format specific options are defined	  ;;
766
;                        options are defined, i.e. 0 here will be ignored if  ;;
-
 
767
;                        particular compression algorithm is specified        ;;
755
;		     i.e. 0 here will be ignored if particular compression algorithm is specified ;;
768
;     0x02 :  byte : flags (bitfield)                                         ;;
-
 
769
;                    0x01 : return an error if format specific conditions     ;;
756
;     0x02 :  byte : flags (bitfield)								  ;;
770
;                           cannot be met                                     ;;
757
;		    0x01 : return an error if format specific conditions cannot be met		  ;;
771
;                    0x02 : preserve current bit depth. means 8bpp/16bpp/     ;;
-
 
772
;                           24bpp and so on                                   ;;
758
;		    0x02 : preserve current bit depth. means 8bpp/16bpp/24bpp and so on 	  ;;
773
;                    0x04 : delete alpha channel, if any                      ;;
759
;		    0x04 : delete alpha channel, if any 					  ;;
774
;                    0x08 : flush alpha channel with 0xff, if any; add it if  ;;
760
;		    0x08 : flush alpha channel with 0xff, if any; add it if none		  ;;
775
;                           none                                              ;;
761
;     0x03 :  byte : reserved, must be 0							  ;;
776
;     0x03 :  byte : reserved, must be 0                                      ;;
762
;> [_specific] = 0 / pointer to the structure of format specific options			  ;;
777
;> [_specific] = 0 / pointer to the structure of format specific options      ;;
763
;		    see .inc for description					  ;;
778
;                   see .inc for description                     ;;
764
;;------------------------------------------------------------------------------------------------;;
779
;;----------------------------------------------------------------------------;;
765
;< eax = 0 / pointer to encoded data								  ;;
780
;< eax = 0 / pointer to encoded data                                          ;;
766
;< ecx = error code / the size of encoded data							  ;;
781
;< ecx = error code / the size of encoded data                                ;;
767
;     1 : out of memory 									  ;;
782
;     1 : out of memory                                                       ;;
768
;     2 : format is not supported								  ;;
783
;     2 : format is not supported                                             ;;
769
;     3 : specific conditions cannot be satisfied						  ;;
784
;     3 : specific conditions cannot be satisfied                             ;;
Line 770... Line 785...
770
;     4 : bit depth cannot be preserved 							  ;;
785
;     4 : bit depth cannot be preserved                                       ;;
771
;;================================================================================================;;
786
;;============================================================================;;
772
	mov	ebx, [_img]
787
        mov     ebx, [_img]
Line 828... Line 843...
828
	xor	eax, eax
843
        xor     eax, eax
829
  .quit:
844
.quit:
830
	ret
845
        ret
831
endp
846
endp
Line 832... Line 847...
832
 
847
 
833
;;================================================================================================;;
848
;;============================================================================;;
834
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
849
proc img.create _width, _height, _type ;//////////////////////////////////////;;
835
;;------------------------------------------------------------------------------------------------;;
850
;;----------------------------------------------------------------------------;;
836
;? creates an Image structure and initializes some its fields					  ;;
851
;? creates an Image structure and initializes some its fields                 ;;
837
;;------------------------------------------------------------------------------------------------;;
852
;;----------------------------------------------------------------------------;;
838
;> [_width]  = width of an image in pixels							  ;;
853
;> [_width]  = width of an image in pixels                                    ;;
839
;> [_height] = height of an image in pixels							  ;;
854
;> [_height] = height of an image in pixels                                   ;;
840
;> [_type]   = one of the Image.bppN constants from libimg.inc					  ;;
855
;> [_type]   = one of the Image.bppN constants from libimg.inc                ;;
841
;;------------------------------------------------------------------------------------------------;;
856
;;----------------------------------------------------------------------------;;
842
;< eax = 0 / pointer to image									  ;;
857
;< eax = 0 / pointer to image                                                 ;;
843
;;================================================================================================;;
858
;;============================================================================;;
Line 844... Line 859...
844
    push    ecx
859
        push    ecx
845
 
860
 
846
    stdcall img._.new
861
        stdcall img._.new
Line 868... Line 883...
868
  .ret:
883
.ret:
869
    pop ecx
884
        pop     ecx
870
    ret
885
        ret
871
endp
886
endp
Line 872... Line 887...
872
 
887
 
873
;;================================================================================================;;
888
;;============================================================================;;
874
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
889
proc img.destroy.layer _img ;/////////////////////////////////////////////////;;
875
;;------------------------------------------------------------------------------------------------;;
890
;;----------------------------------------------------------------------------;;
876
;? frees memory occupied by an image and all the memory regions its fields point to		  ;;
891
;? Frees memory occupied by an image and all the memory regions its fields    ;;
-
 
892
;? point to. For image sequences deletes only one frame and fixes Previous/   ;;
877
;? for image sequences deletes only one frame and fixes Previous/Next pointers			  ;;
893
;? Next pointers.                                                             ;;
878
;;------------------------------------------------------------------------------------------------;;
894
;;----------------------------------------------------------------------------;;
879
;> [_img] = pointer to image									  ;;
895
;> [_img] = pointer to image                                                  ;;
880
;;------------------------------------------------------------------------------------------------;;
896
;;----------------------------------------------------------------------------;;
881
;< eax = 0 (fail) / 1 (success) 								  ;;
897
;< eax = 0 (fail) / 1 (success)                                               ;;
882
;;================================================================================================;;
898
;;============================================================================;;
883
    mov eax, [_img]
899
        mov     eax, [_img]
884
    mov edx, [eax + Image.Previous]
900
        mov     edx, [eax + Image.Previous]
885
    test    edx, edx
901
        test    edx, edx
886
    jz	@f
902
        jz      @f
Line 895... Line 911...
895
@@:
911
@@:
896
    stdcall img._.delete, eax
912
        stdcall img._.delete, eax
897
    ret
913
        ret
898
endp
914
endp
Line 899... Line 915...
899
 
915
 
900
;;================================================================================================;;
916
;;============================================================================;;
901
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
917
proc img.destroy _img ;///////////////////////////////////////////////////////;;
902
;;------------------------------------------------------------------------------------------------;;
918
;;----------------------------------------------------------------------------;;
903
;? frees memory occupied by an image and all the memory regions its fields point to		  ;;
919
;? Frees memory occupied by an image and all the memory regions its fields    ;;
-
 
920
;? point to. Follows Previous/Next pointers and deletes all the images in     ;;
904
;? follows Previous/Next pointers and deletes all the images in sequence			  ;;
921
;? sequence.                                                                  ;;
905
;;------------------------------------------------------------------------------------------------;;
922
;;----------------------------------------------------------------------------;;
906
;> [_img] = pointer to image									  ;;
923
;> [_img] = pointer to image                                                  ;;
907
;;------------------------------------------------------------------------------------------------;;
924
;;----------------------------------------------------------------------------;;
908
;< eax = 0 (fail) / 1 (success) 								  ;;
925
;< eax = 0 (fail) / 1 (success)                                               ;;
909
;;================================================================================================;;
926
;;============================================================================;;
910
    push    1
927
        push    1
911
    mov eax, [_img]
928
        mov     eax, [_img]
912
    mov eax, [eax + Image.Previous]
929
        mov     eax, [eax + Image.Previous]
913
.destroy_prev_loop:
930
.destroy_prev_loop:
Line 935... Line 952...
935
    jnz .destroy_next_loop
952
        jnz     .destroy_next_loop
936
    pop eax
953
        pop     eax
937
    ret
954
        ret
938
endp
955
endp
Line 939... Line 956...
939
 
956
 
940
;;================================================================================================;;
957
;;============================================================================;;
941
proc img.count _img ;/////////////////////////////////////////////////////////////////////////////;;
958
proc img.count _img ;/////////////////////////////////////////////////////////;;
942
;;------------------------------------------------------------------------------------------------;;
959
;;----------------------------------------------------------------------------;;
943
;? Get number of images in the list (e.g. in animated GIF file) 				  ;;
960
;? Get number of images in the list (e.g. in animated GIF file)               ;;
944
;;------------------------------------------------------------------------------------------------;;
961
;;----------------------------------------------------------------------------;;
945
;> _img = pointer to image									  ;;
962
;> _img = pointer to image                                                    ;;
946
;;------------------------------------------------------------------------------------------------;;
963
;;----------------------------------------------------------------------------;;
947
;< eax = -1 (fail) / >0 (ok)									  ;;
964
;< eax = -1 (fail) / >0 (ok)                                                  ;;
948
;;================================================================================================;;
965
;;============================================================================;;
949
    push    ecx edx
966
        push    ecx edx
950
    mov edx, [_img]
967
        mov     edx, [_img]
951
    stdcall img._.validate, edx
968
        stdcall img._.validate, edx
952
    or	eax, eax
969
        or      eax, eax
Line -... Line 970...
-
 
970
        jnz     .error
953
    jnz .error
971
 
954
 
972
@@:
955
    @@: mov eax, [edx + Image.Previous]
973
        mov     eax, [edx + Image.Previous]
956
    or	eax, eax
974
        or      eax, eax
957
    jz	@f
975
        jz      @f
Line -... Line 976...
-
 
976
        mov     edx, eax
958
    mov edx, eax
977
        jmp     @b
-
 
978
 
959
    jmp @b
979
@@:
960
 
980
        xor     ecx, ecx
961
    @@: xor ecx, ecx
981
@@:
962
    @@: inc ecx
982
        inc     ecx
963
    mov eax, [edx + Image.Next]
983
        mov     eax, [edx + Image.Next]
964
    or	eax, eax
984
        or      eax, eax
Line 975... Line 995...
975
    or	eax, -1
995
        or      eax, -1
976
    pop edx ecx
996
        pop     edx ecx
977
    ret
997
        ret
978
endp
998
endp
Line 979... Line 999...
979
 
999
 
Line 980... Line 1000...
980
;;//// image processing //////////////////////////////////////////////////////////////////////////;;
1000
;;//// image processing //////////////////////////////////////////////////////;;
981
 
1001
 
982
;;================================================================================================;;
1002
;;============================================================================;;
983
proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////////////////////////;;
1003
proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////;;
984
;;------------------------------------------------------------------------------------------------;;
1004
;;----------------------------------------------------------------------------;;
985
;? --- TBD ---											  ;;
1005
;? --- TBD ---                                                                ;;
986
;;------------------------------------------------------------------------------------------------;;
1006
;;----------------------------------------------------------------------------;;
987
;> --- TBD ---											  ;;
1007
;> --- TBD ---                                                                ;;
988
;;------------------------------------------------------------------------------------------------;;
1008
;;----------------------------------------------------------------------------;;
989
;< eax = 0 / pointer to bits									  ;;
1009
;< eax = 0 / pointer to bits                                                  ;;
990
;;================================================================================================;;
1010
;;============================================================================;;
991
    xor eax, eax
1011
        xor     eax, eax
Line 992... Line 1012...
992
    ret
1012
        ret
993
endp
1013
endp
994
 
1014
 
995
;;================================================================================================;;
1015
;;============================================================================;;
996
proc img.unlock_bits _img, _lock ;////////////////////////////////////////////////////////////////;;
1016
proc img.unlock_bits _img, _lock ;////////////////////////////////////////////;;
997
;;------------------------------------------------------------------------------------------------;;
1017
;;----------------------------------------------------------------------------;;
998
;? --- TBD ---											  ;;
1018
;? --- TBD ---                                                                ;;
999
;;------------------------------------------------------------------------------------------------;;
1019
;;----------------------------------------------------------------------------;;
1000
;> --- TBD ---											  ;;
1020
;> --- TBD ---                                                                ;;
1001
;;------------------------------------------------------------------------------------------------;;
1021
;;----------------------------------------------------------------------------;;
1002
;< eax = false / true										  ;;
1022
;< eax = false / true                                                         ;;
1003
;;================================================================================================;;
1023
;;============================================================================;;
Line 1004... Line 1024...
1004
    xor eax, eax
1024
        xor     eax, eax
1005
    ret
1025
        ret
1006
endp
1026
endp
1007
 
1027
 
1008
;;================================================================================================;;
1028
;;============================================================================;;
1009
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////////////////////////;;
1029
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////;;
1010
;;------------------------------------------------------------------------------------------------;;
1030
;;----------------------------------------------------------------------------;;
1011
;? Flip image layer										  ;;
1031
;? Flip image layer                                                           ;;
1012
;;------------------------------------------------------------------------------------------------;;
1032
;;----------------------------------------------------------------------------;;
1013
;> _img = pointer to image									  ;;
1033
;> _img = pointer to image                                                    ;;
1014
;> _flip_kind = one of FLIP_* constants 							  ;;
1034
;> _flip_kind = one of FLIP_* constants                                       ;;
1015
;;------------------------------------------------------------------------------------------------;;
1035
;;----------------------------------------------------------------------------;;
1016
;< eax = false / true										  ;;
1036
;< eax = false / true                                                         ;;
Line 1017... Line 1037...
1017
;;================================================================================================;;
1037
;;============================================================================;;
Line 1094... Line 1114...
1094
  .next_line_horz:
1114
.next_line_horz:
1095
    push    ecx esi edi
1115
        push    ecx esi edi
Line 1096... Line 1116...
1096
 
1116
 
1097
    mov ecx, [scanline_len]
1117
        mov     ecx, [scanline_len]
-
 
1118
        shr     ecx, 3
1098
    shr ecx, 3
1119
@@:
1099
    @@: mov eax, [esi]
1120
        mov     eax, [esi]
1100
    xchg    eax, [edi]
1121
        xchg    eax, [edi]
1101
    mov [esi], eax
1122
        mov     [esi], eax
1102
    add esi, 4
1123
        add     esi, 4
1103
    add edi, -4
1124
        add     edi, -4
Line 1115... Line 1136...
1115
    sub edi, 2
1136
        sub     edi, 2
1116
  .next_line_horz1x:
1137
.next_line_horz1x:
1117
    push    ecx esi edi
1138
        push    ecx esi edi
Line 1118... Line 1139...
1118
 
1139
 
-
 
1140
        mov     ecx, [ebx + Image.Width]
1119
    mov ecx, [ebx + Image.Width]
1141
@@:
1120
    @@: mov ax, [esi]
1142
        mov     ax, [esi]
1121
    mov dx, [edi]
1143
        mov     dx, [edi]
1122
    mov [edi], ax
1144
        mov     [edi], ax
1123
    mov [esi], dx
1145
        mov     [esi], dx
1124
    add esi, 2
1146
        add     esi, 2
Line 1138... Line 1160...
1138
  .next_line_horz8ig:
1160
.next_line_horz8ig:
1139
    push    ecx esi edi
1161
        push    ecx esi edi
Line 1140... Line 1162...
1140
 
1162
 
1141
    mov ecx, [scanline_len]
1163
        mov     ecx, [scanline_len]
-
 
1164
        shr     ecx, 1
1142
    shr ecx, 1
1165
@@:
1143
    @@: mov al, [esi]
1166
        mov     al, [esi]
1144
    mov dl, [edi]
1167
        mov     dl, [edi]
1145
    mov [edi], al
1168
        mov     [edi], al
1146
    mov [esi], dl
1169
        mov     [esi], dl
1147
    add esi, 1
1170
        add     esi, 1
Line 1378... Line 1401...
1378
    xor eax, eax
1401
        xor     eax, eax
1379
    pop edi esi ebx
1402
        pop     edi esi ebx
1380
    ret
1403
        ret
1381
endp
1404
endp
Line 1382... Line 1405...
1382
 
1405
 
1383
;;================================================================================================;;
1406
;;============================================================================;;
1384
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
1407
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////;;
1385
;;------------------------------------------------------------------------------------------------;;
1408
;;----------------------------------------------------------------------------;;
1386
;? Flip all layers of image									  ;;
1409
;? Flip all layers of image                                                   ;;
1387
;;------------------------------------------------------------------------------------------------;;
1410
;;----------------------------------------------------------------------------;;
1388
;> _img = pointer to image									  ;;
1411
;> _img = pointer to image                                                    ;;
1389
;> _flip_kind = one of FLIP_* constants 							  ;;
1412
;> _flip_kind = one of FLIP_* constants                                       ;;
1390
;;------------------------------------------------------------------------------------------------;;
1413
;;----------------------------------------------------------------------------;;
1391
;< eax = false / true										  ;;
1414
;< eax = false / true                                                         ;;
1392
;;================================================================================================;;
1415
;;============================================================================;;
1393
    push    1
1416
        push    1
1394
    mov ebx, [_img]
1417
        mov     ebx, [_img]
1395
@@:
1418
@@:
1396
    mov eax, [ebx + Image.Previous]
1419
        mov     eax, [ebx + Image.Previous]
Line 1409... Line 1432...
1409
    jnz .loop
1432
        jnz     .loop
1410
    pop eax
1433
        pop     eax
1411
    ret
1434
        ret
1412
endp
1435
endp
Line 1413... Line 1436...
1413
 
1436
 
1414
;;================================================================================================;;
1437
;;============================================================================;;
1415
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////////////////////////;;
1438
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////;;
1416
;;------------------------------------------------------------------------------------------------;;
1439
;;----------------------------------------------------------------------------;;
1417
;? Rotate image layer										  ;;
1440
;? Rotate image layer                                                         ;;
1418
;;------------------------------------------------------------------------------------------------;;
1441
;;----------------------------------------------------------------------------;;
1419
;> _img = pointer to image									  ;;
1442
;> _img = pointer to image                                                    ;;
1420
;> _rotate_kind = one of ROTATE_* constants							  ;;
1443
;> _rotate_kind = one of ROTATE_* constants                                   ;;
1421
;;------------------------------------------------------------------------------------------------;;
1444
;;----------------------------------------------------------------------------;;
1422
;< eax = false / true										  ;;
1445
;< eax = false / true                                                         ;;
1423
;;================================================================================================;;
1446
;;============================================================================;;
1424
locals
1447
locals
1425
  scanline_len_old    dd ?
1448
  scanline_len_old    dd ?
1426
  scanline_len_new    dd ?
1449
  scanline_len_new    dd ?
1427
  scanline_pixels_new dd ?
1450
  scanline_pixels_new dd ?
Line 1490... Line 1513...
1490
    add [scanline_len_old], -2
1513
        add     [scanline_len_old], -2
Line 1491... Line 1514...
1491
 
1514
 
1492
    mov ecx, [scanline_pixels_new]
1515
        mov     ecx, [scanline_pixels_new]
1493
    mov esi, [ebx + Image.Data]
1516
        mov     esi, [ebx + Image.Data]
-
 
1517
        mov     edi, [line_buffer]
1494
    mov edi, [line_buffer]
1518
@@:
1495
    @@: mov ax, [esi]
1519
        mov     ax, [esi]
1496
    mov [edi], ax
1520
        mov     [edi], ax
1497
    add esi, edx
1521
        add     esi, edx
1498
    add edi, 2
1522
        add     edi, 2
1499
    sub ecx, 1
1523
        sub     ecx, 1
Line 1500... Line 1524...
1500
    jnz @b
1524
        jnz     @b
1501
 
1525
 
1502
    mov eax, [scanline_pixels_new]
1526
        mov     eax, [scanline_pixels_new]
1503
    mov edi, [ebx + Image.Data]
1527
        mov     edi, [ebx + Image.Data]
-
 
1528
        lea     esi, [edi + 2]
1504
    lea esi, [edi + 2]
1529
        mov     edx, [scanline_len_old]
1505
    mov edx, [scanline_len_old]
1530
@@:
1506
    @@: mov ecx, edx
1531
        mov     ecx, edx
1507
    shr ecx, 2
1532
        shr     ecx, 2
1508
    rep movsd
1533
        rep movsd
1509
    mov ecx, edx
1534
        mov     ecx, edx
Line 1538... Line 1563...
1538
    add [scanline_len_old], -4
1563
        add     [scanline_len_old], -4
Line 1539... Line 1564...
1539
 
1564
 
1540
    mov ecx, [scanline_pixels_new]
1565
        mov     ecx, [scanline_pixels_new]
1541
    mov esi, [ebx + Image.Data]
1566
        mov     esi, [ebx + Image.Data]
-
 
1567
        mov     edi, [line_buffer]
1542
    mov edi, [line_buffer]
1568
@@:
1543
    @@: mov eax, [esi]
1569
        mov     eax, [esi]
1544
    stosd
1570
        stosd
1545
    add esi, edx
1571
        add     esi, edx
1546
    dec ecx
1572
        dec     ecx
Line 1547... Line 1573...
1547
    jnz @b
1573
        jnz     @b
1548
 
1574
 
1549
    mov eax, [scanline_pixels_new]
1575
        mov     eax, [scanline_pixels_new]
1550
    mov edi, [ebx + Image.Data]
1576
        mov     edi, [ebx + Image.Data]
1551
    lea esi, [edi + 4]
1577
        lea     esi, [edi + 4]
-
 
1578
        mov     edx, [scanline_len_old]
1552
    mov edx, [scanline_len_old]
1579
        shr     edx, 2
1553
    shr edx, 2
1580
@@:
1554
    @@: mov ecx, edx
1581
        mov     ecx, edx
1555
    rep movsd
1582
        rep movsd
1556
    add esi, 4
1583
        add     esi, 4
Line 1577... Line 1604...
1577
    add [scanline_len_old], -1
1604
        add     [scanline_len_old], -1
Line 1578... Line 1605...
1578
 
1605
 
1579
    mov ecx, [scanline_pixels_new]
1606
        mov     ecx, [scanline_pixels_new]
1580
    mov esi, [ebx + Image.Data]
1607
        mov     esi, [ebx + Image.Data]
-
 
1608
        mov     edi, [line_buffer]
1581
    mov edi, [line_buffer]
1609
@@:
1582
    @@: mov al, [esi]
1610
        mov     al, [esi]
1583
    mov [edi], al
1611
        mov     [edi], al
1584
    add esi, edx
1612
        add     esi, edx
1585
    add edi, 1
1613
        add     edi, 1
1586
    sub ecx, 1
1614
        sub     ecx, 1
Line 1587... Line 1615...
1587
    jnz @b
1615
        jnz     @b
1588
 
1616
 
1589
    mov eax, [scanline_pixels_new]
1617
        mov     eax, [scanline_pixels_new]
1590
    mov edi, [ebx + Image.Data]
1618
        mov     edi, [ebx + Image.Data]
-
 
1619
        lea     esi, [edi + 1]
1591
    lea esi, [edi + 1]
1620
        mov     edx, [scanline_len_old]
1592
    mov edx, [scanline_len_old]
1621
@@:
1593
    @@: mov ecx, edx
1622
        mov     ecx, edx
1594
    shr ecx, 2
1623
        shr     ecx, 2
1595
    rep movsd
1624
        rep movsd
1596
    mov ecx, edx
1625
        mov     ecx, edx
Line 1625... Line 1654...
1625
    add [scanline_len_old], -3
1654
        add     [scanline_len_old], -3
Line 1626... Line 1655...
1626
 
1655
 
1627
    mov ecx, [scanline_pixels_new]
1656
        mov     ecx, [scanline_pixels_new]
1628
    mov esi, [ebx + Image.Data]
1657
        mov     esi, [ebx + Image.Data]
-
 
1658
        mov     edi, [line_buffer]
1629
    mov edi, [line_buffer]
1659
@@:
1630
    @@: mov al, [esi]
1660
        mov     al, [esi]
1631
    mov [edi], al
1661
        mov     [edi], al
1632
    mov al, [esi+1]
1662
        mov     al, [esi+1]
1633
    mov [edi+1], al
1663
        mov     [edi+1], al
1634
    mov al, [esi+2]
1664
        mov     al, [esi+2]
Line 1640... Line 1670...
1640
 
1670
 
1641
    mov eax, [scanline_pixels_new]
1671
        mov     eax, [scanline_pixels_new]
1642
    mov edi, [ebx + Image.Data]
1672
        mov     edi, [ebx + Image.Data]
1643
    lea esi, [edi + 3]
1673
        lea     esi, [edi + 3]
-
 
1674
        mov     edx, [scanline_len_old]
1644
    mov edx, [scanline_len_old]
1675
@@:
1645
    @@: mov ecx, edx
1676
        mov     ecx, edx
1646
    shr ecx, 2
1677
        shr     ecx, 2
1647
    rep movsd
1678
        rep movsd
1648
    mov ecx, edx
1679
        mov     ecx, edx
1649
    and ecx, 3
1680
        and     ecx, 3
Line 1940... Line 1971...
1940
 
1971
 
1941
    mov ecx, [scanline_pixels_new]
1972
        mov     ecx, [scanline_pixels_new]
1942
    mov esi, [pixels_ptr]
1973
        mov     esi, [pixels_ptr]
1943
    add esi, -2
1974
        add     esi, -2
-
 
1975
        mov     edi, [line_buffer]
1944
    mov edi, [line_buffer]
1976
@@:
1945
    @@: mov ax, [esi]
1977
        mov     ax, [esi]
1946
    mov [edi], ax
1978
        mov     [edi], ax
1947
    sub esi, edx
1979
        sub     esi, edx
1948
    add edi, 2
1980
        add     edi, 2
1949
    sub ecx, 1
1981
        sub     ecx, 1
Line 1953... Line 1985...
1953
    dec eax
1985
        dec     eax
1954
    mov edi, [ebx + Image.Data]
1986
        mov     edi, [ebx + Image.Data]
1955
    add edi, [scanline_len_old]
1987
        add     edi, [scanline_len_old]
1956
    lea esi, [edi + 2]
1988
        lea     esi, [edi + 2]
1957
    mov edx, [scanline_len_old]
1989
        mov     edx, [scanline_len_old]
-
 
1990
@@:
1958
    @@: mov ecx, edx
1991
        mov     ecx, edx
1959
    shr ecx, 2
1992
        shr     ecx, 2
1960
    rep movsd
1993
        rep movsd
1961
    mov ecx, edx
1994
        mov     ecx, edx
1962
    and ecx, 3
1995
        and     ecx, 3
1963
    rep movsb
1996
        rep movsb
Line 1990... Line 2023...
1990
 
2023
 
1991
    mov ecx, [scanline_pixels_new]
2024
        mov     ecx, [scanline_pixels_new]
1992
    mov esi, [pixels_ptr]
2025
        mov     esi, [pixels_ptr]
1993
    add esi, -4
2026
        add     esi, -4
-
 
2027
        mov     edi, [line_buffer]
1994
    mov edi, [line_buffer]
2028
@@:
1995
    @@: mov eax, [esi]
2029
        mov     eax, [esi]
1996
    stosd
2030
        stosd
1997
    sub esi, edx
2031
        sub     esi, edx
1998
    dec ecx
2032
        dec     ecx
Line 2003... Line 2037...
2003
    mov edi, [ebx + Image.Data]
2037
        mov     edi, [ebx + Image.Data]
2004
    add edi, [scanline_len_old]
2038
        add     edi, [scanline_len_old]
2005
    lea esi, [edi + 4]
2039
        lea     esi, [edi + 4]
2006
    mov edx, [scanline_len_old]
2040
        mov     edx, [scanline_len_old]
2007
    shr edx, 2
2041
        shr     edx, 2
-
 
2042
@@:
2008
    @@: mov ecx, edx
2043
        mov     ecx, edx
2009
    rep movsd
2044
        rep movsd
2010
    add esi, 4
2045
        add     esi, 4
2011
    dec eax
2046
        dec     eax
2012
    jnz @b
2047
        jnz     @b
Line 2032... Line 2067...
2032
 
2067
 
2033
    mov ecx, [scanline_pixels_new]
2068
        mov     ecx, [scanline_pixels_new]
2034
    mov esi, [pixels_ptr]
2069
        mov     esi, [pixels_ptr]
2035
    add esi, -1
2070
        add     esi, -1
-
 
2071
        mov     edi, [line_buffer]
2036
    mov edi, [line_buffer]
2072
@@:
2037
    @@: mov al, [esi]
2073
        mov     al, [esi]
2038
    mov [edi], al
2074
        mov     [edi], al
2039
    sub esi, edx
2075
        sub     esi, edx
2040
    add edi, 1
2076
        add     edi, 1
2041
    sub ecx, 1
2077
        sub     ecx, 1
Line 2045... Line 2081...
2045
    dec eax
2081
        dec     eax
2046
    mov edi, [ebx + Image.Data]
2082
        mov     edi, [ebx + Image.Data]
2047
    add edi, [scanline_len_old]
2083
        add     edi, [scanline_len_old]
2048
    lea esi, [edi + 1]
2084
        lea     esi, [edi + 1]
2049
    mov edx, [scanline_len_old]
2085
        mov     edx, [scanline_len_old]
-
 
2086
@@:
2050
    @@: mov ecx, edx
2087
        mov     ecx, edx
2051
    shr ecx, 2
2088
        shr     ecx, 2
2052
    rep movsd
2089
        rep movsd
2053
    mov ecx, edx
2090
        mov     ecx, edx
2054
    and ecx, 3
2091
        and     ecx, 3
2055
    rep movsb
2092
        rep movsb
Line 2082... Line 2119...
2082
 
2119
 
2083
    mov ecx, [scanline_pixels_new]
2120
        mov     ecx, [scanline_pixels_new]
2084
    mov esi, [pixels_ptr]
2121
        mov     esi, [pixels_ptr]
2085
    add esi, -3
2122
        add     esi, -3
-
 
2123
        mov     edi, [line_buffer]
2086
    mov edi, [line_buffer]
2124
@@:
2087
    @@: mov al, [esi]
2125
        mov     al, [esi]
2088
    mov [edi], al
2126
        mov     [edi], al
2089
    mov al, [esi+1]
2127
        mov     al, [esi+1]
2090
    mov [edi+1], al
2128
        mov     [edi+1], al
2091
    mov al, [esi+2]
2129
        mov     al, [esi+2]
Line 2099... Line 2137...
2099
    dec eax
2137
        dec     eax
2100
    mov edi, [ebx + Image.Data]
2138
        mov     edi, [ebx + Image.Data]
2101
    add edi, [scanline_len_old]
2139
        add     edi, [scanline_len_old]
2102
    lea esi, [edi + 3]
2140
        lea     esi, [edi + 3]
2103
    mov edx, [scanline_len_old]
2141
        mov     edx, [scanline_len_old]
-
 
2142
@@:
2104
    @@: mov ecx, edx
2143
        mov     ecx, edx
2105
    shr ecx, 2
2144
        shr     ecx, 2
2106
    rep movsd
2145
        rep movsd
2107
    mov ecx, edx
2146
        mov     ecx, edx
2108
    and ecx, 3
2147
        and     ecx, 3
2109
    rep movsb
2148
        rep movsb
Line 2372... Line 2411...
2372
    xor eax, eax
2411
        xor     eax, eax
2373
    pop edi esi ebx
2412
        pop     edi esi ebx
2374
    ret
2413
        ret
2375
endp
2414
endp
Line 2376... Line 2415...
2376
 
2415
 
2377
;;================================================================================================;;
2416
;;============================================================================;;
2378
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
2417
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////;;
2379
;;------------------------------------------------------------------------------------------------;;
2418
;;----------------------------------------------------------------------------;;
2380
;? Rotate all layers of image									  ;;
2419
;? Rotate all layers of image                                                 ;;
2381
;;------------------------------------------------------------------------------------------------;;
2420
;;----------------------------------------------------------------------------;;
2382
;> _img = pointer to image									  ;;
2421
;> _img = pointer to image                                                    ;;
2383
;> _rotate_kind = one of ROTATE_* constants							  ;;
2422
;> _rotate_kind = one of ROTATE_* constants                                   ;;
2384
;;------------------------------------------------------------------------------------------------;;
2423
;;----------------------------------------------------------------------------;;
2385
;< eax = false / true										  ;;
2424
;< eax = false / true                                                         ;;
2386
;;================================================================================================;;
2425
;;============================================================================;;
2387
    push    1
2426
        push    1
2388
    mov ebx, [_img]
2427
        mov     ebx, [_img]
2389
@@:
2428
@@:
2390
    mov eax, [ebx + Image.Previous]
2429
        mov     eax, [ebx + Image.Previous]
Line 2403... Line 2442...
2403
    jnz .loop
2442
        jnz     .loop
2404
    pop eax
2443
        pop     eax
2405
    ret
2444
        ret
2406
endp
2445
endp
Line 2407... Line 2446...
2407
 
2446
 
2408
;;================================================================================================;;
2447
;;============================================================================;;
2409
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////////////////////////;;
2448
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////;;
2410
;;------------------------------------------------------------------------------------------------;;
2449
;;----------------------------------------------------------------------------;;
2411
;? Draw image in the window									  ;;
2450
;? Draw image in the window                                                   ;;
2412
;;------------------------------------------------------------------------------------------------;;
2451
;;----------------------------------------------------------------------------;;
2413
;> _img = pointer to image									  ;;
2452
;> _img = pointer to image                                                    ;;
2414
;>_x = x-coordinate in the window								  ;;
2453
;>_x = x-coordinate in the window                                             ;;
2415
;>_y = y-coordinate in the window								  ;;
2454
;>_y = y-coordinate in the window                                             ;;
2416
;>_width = maximum width to draw								  ;;
2455
;>_width = maximum width to draw                                              ;;
2417
;>_height = maximum height to draw								  ;;
2456
;>_height = maximum height to draw                                            ;;
2418
;>_xpos = offset in image by x-axis								  ;;
2457
;>_xpos = offset in image by x-axis                                           ;;
2419
;>_ypos = offset in image by y-axis								  ;;
2458
;>_ypos = offset in image by y-axis                                           ;;
2420
;;------------------------------------------------------------------------------------------------;;
2459
;;----------------------------------------------------------------------------;;
2421
;< no return value										  ;;
2460
;< no return value                                                            ;;
2422
;;================================================================================================;;
2461
;;============================================================================;;
2423
    push    ebx esi edi
2462
        push    ebx esi edi
2424
    mov ebx, [_img]
2463
        mov     ebx, [_img]
2425
    stdcall img._.validate, ebx
2464
        stdcall img._.validate, ebx
2426
    test    eax, eax
2465
        test    eax, eax
Line 2485... Line 2524...
2485
  .wbmp dd LIBIMG_FORMAT_WBMP, img.is.wbmp, img.decode.wbmp,	img.encode.wbmp,0
2524
  .wbmp dd LIBIMG_FORMAT_WBMP, img.is.wbmp, img.decode.wbmp,    img.encode.wbmp,0
2486
  .xbm	dd LIBIMG_FORMAT_XBM,  img.is.xbm,  img.decode.xbm,	img.encode.xbm, 0
2525
  .xbm  dd LIBIMG_FORMAT_XBM,  img.is.xbm,  img.decode.xbm,     img.encode.xbm, 0
2487
  .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
2526
  .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
2488
	dd 0
2527
        dd 0
Line 2489... Line 2528...
2489
 
2528
 
2490
;;================================================================================================;;
2529
;;============================================================================;;
2491
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2530
;;////////////////////////////////////////////////////////////////////////////;;
2492
;;================================================================================================;;
2531
;;============================================================================;;
2493
;! Below are private procs you should never call directly from your code			  ;;
2532
;! Below are private procs you should never call directly from your code      ;;
2494
;;================================================================================================;;
2533
;;============================================================================;;
2495
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2534
;;////////////////////////////////////////////////////////////////////////////;;
Line 2496... Line 2535...
2496
;;================================================================================================;;
2535
;;============================================================================;;
2497
 
2536
 
2498
 
2537
 
2499
;;================================================================================================;;
2538
;;============================================================================;;
2500
proc img._.validate, _img ;///////////////////////////////////////////////////////////////////////;;
2539
proc img._.validate, _img ;///////////////////////////////////////////////////;;
2501
;;------------------------------------------------------------------------------------------------;;
2540
;;----------------------------------------------------------------------------;;
2502
;? --- TBD ---											  ;;
2541
;? --- TBD ---                                                                ;;
2503
;;------------------------------------------------------------------------------------------------;;
2542
;;----------------------------------------------------------------------------;;
2504
;> --- TBD ---											  ;;
2543
;> --- TBD ---                                                                ;;
2505
;;------------------------------------------------------------------------------------------------;;
2544
;;----------------------------------------------------------------------------;;
2506
;< --- TBD ---											  ;;
2545
;< --- TBD ---                                                                ;;
2507
;;================================================================================================;;
2546
;;============================================================================;;
Line 2508... Line 2547...
2508
    xor eax, eax
2547
        xor     eax, eax
2509
    ret
2548
        ret
2510
endp
2549
endp
2511
 
2550
 
2512
;;================================================================================================;;
2551
;;============================================================================;;
2513
proc img._.new ;//////////////////////////////////////////////////////////////////////////////////;;
2552
proc img._.new ;//////////////////////////////////////////////////////////////;;
2514
;;------------------------------------------------------------------------------------------------;;
2553
;;----------------------------------------------------------------------------;;
2515
;? --- TBD ---											  ;;
2554
;? --- TBD ---                                                                ;;
2516
;;------------------------------------------------------------------------------------------------;;
2555
;;----------------------------------------------------------------------------;;
2517
;> --- TBD ---											  ;;
2556
;> --- TBD ---                                                                ;;
2518
;;------------------------------------------------------------------------------------------------;;
2557
;;----------------------------------------------------------------------------;;
2519
;< eax = 0 / pointer to image									  ;;
2558
;< eax = 0 / pointer to image                                                 ;;
2520
;;================================================================================================;;
2559
;;============================================================================;;
2521
    invoke  mem.alloc, sizeof.Image
2560
        invoke  mem.alloc, sizeof.Image
Line 2532... Line 2571...
2532
    pop ecx
2571
        pop     ecx
2533
@@:
2572
@@:
2534
    ret
2573
        ret
2535
endp
2574
endp
Line 2536... Line 2575...
2536
 
2575
 
2537
;;================================================================================================;;
2576
;;============================================================================;;
2538
proc img._.delete _img ;//////////////////////////////////////////////////////////////////////////;;
2577
proc img._.delete _img ;//////////////////////////////////////////////////////;;
2539
;;------------------------------------------------------------------------------------------------;;
2578
;;----------------------------------------------------------------------------;;
2540
;? --- TBD ---											  ;;
2579
;? --- TBD ---                                                                ;;
2541
;;------------------------------------------------------------------------------------------------;;
2580
;;----------------------------------------------------------------------------;;
2542
;> --- TBD ---											  ;;
2581
;> --- TBD ---                                                                ;;
2543
;;------------------------------------------------------------------------------------------------;;
2582
;;----------------------------------------------------------------------------;;
2544
;< eax = false / true										  ;;
2583
;< eax = false / true                                                         ;;
2545
;;================================================================================================;;
2584
;;============================================================================;;
2546
    push    edx
2585
        push    edx
2547
    mov edx, [_img]
2586
        mov     edx, [_img]
2548
    cmp [edx + Image.Data], 0
2587
        cmp     [edx + Image.Data], 0
2549
    je	@f
2588
        je      @f
-
 
2589
        invoke  mem.free, [edx + Image.Data]
2550
    invoke  mem.free, [edx + Image.Data]
2590
@@:
2551
    @@: cmp [edx + Image.Extended], 0
2591
        cmp     [edx + Image.Extended], 0
2552
    je	@f
2592
        je      @f
-
 
2593
        invoke  mem.free, [edx + Image.Extended]
2553
    invoke  mem.free, [edx + Image.Extended]
2594
@@:
2554
    @@: invoke	mem.free, edx
2595
        invoke  mem.free, edx
2555
    pop edx
2596
        pop     edx
2556
    ret
2597
        ret
Line 2557... Line 2598...
2557
endp
2598
endp
2558
 
2599
 
2559
;;================================================================================================;;
2600
;;============================================================================;;
2560
proc img.resize_data _img, _width, _height ;//////////////////////////////////////////////////////;;
2601
proc img.resize_data _img, _width, _height ;//////////////////////////////////;;
2561
;;------------------------------------------------------------------------------------------------;;
2602
;;----------------------------------------------------------------------------;;
2562
;? Resize data block of image. New size is calculated from _width and _height params and internal ;;
2603
;? Resize data block of image. New size is calculated from _width and _height ;;
-
 
2604
;? params and internal Image.Type value. All the internal fields are updated  ;;
2563
;? Image.Type value. All the internal fields are updated iff succeeded.                           ;;
2605
;? iff succeeded. This function does not scale images, use img.scale if you   ;;
2564
;? This function does not scale images, use img.scale if you need to.                             ;;
2606
;? need to.                                                                   ;;
2565
;;------------------------------------------------------------------------------------------------;;
2607
;;----------------------------------------------------------------------------;;
2566
;> _img = pointer to image                                                                        ;;
2608
;> _img = pointer to image                                                    ;;
2567
;> _width = new width                                                                             ;;
2609
;> _width = new width                                                         ;;
2568
;> _height = new height                                                                           ;;
2610
;> _height = new height                                                       ;;
2569
;;------------------------------------------------------------------------------------------------;;
2611
;;----------------------------------------------------------------------------;;
2570
;< eax = 0 (fail) / pointer to the new pixels data                                                ;;
2612
;< eax = 0 (fail) / pointer to the new pixels data                            ;;
2571
;;================================================================================================;;
2613
;;============================================================================;;
2572
    push    ebx esi
2614
        push    ebx esi
2573
    mov ebx, [_img]
2615
        mov     ebx, [_img]
2574
    mov eax, [_height]
2616
        mov     eax, [_height]
Line 2696... Line 2738...
2696
  .ret:
2738
  .ret:
2697
    pop esi ebx
2739
        pop     esi ebx
2698
    ret
2740
        ret
2699
endp
2741
endp
Line 2700... Line 2742...
2700
 
2742
 
2701
;;================================================================================================;;
2743
;;============================================================================;;
2702
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
2744
img._.get_scanline_len: ;/////////////////////////////////////////////////////;;
2703
;;------------------------------------------------------------------------------------------------;;
2745
;;----------------------------------------------------------------------------;;
2704
;? Get scanline length of image in bytes							  ;;
2746
;? Get scanline length of image in bytes                                      ;;
2705
;;------------------------------------------------------------------------------------------------;;
2747
;;----------------------------------------------------------------------------;;
2706
;> eax = width of image in pixels								  ;;
2748
;> eax = width of image in pixels                                             ;;
2707
;> ebx = image											  ;;
2749
;> ebx = image                                                                ;;
2708
;;------------------------------------------------------------------------------------------------;;
2750
;;----------------------------------------------------------------------------;;
2709
;< eax = scanline length in bytes								  ;;
2751
;< eax = scanline length in bytes                                             ;;
2710
;;================================================================================================;;
2752
;;============================================================================;;
2711
    cmp [ebx + Image.Type], Image.bpp1
2753
        cmp     [ebx + Image.Type], Image.bpp1
2712
    jz	.bpp1.1
2754
        jz      .bpp1.1
2713
    cmp [ebx + Image.Type], Image.bpp2i
2755
        cmp     [ebx + Image.Type], Image.bpp2i
2714
    jz	.bpp2i.1
2756
        jz      .bpp2i.1
Line 2747... Line 2789...
2747
.bpp8.1:
2789
.bpp8.1:
2748
.quit:
2790
.quit:
2749
    ret
2791
        ret
Line 2750... Line 2792...
2750
 
2792
 
2751
 
2793
 
2752
;;================================================================================================;;
2794
;;============================================================================;;
2753
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2795
;;////////////////////////////////////////////////////////////////////////////;;
2754
;;================================================================================================;;
2796
;;============================================================================;;
2755
;! Below is private data you should never use directly from your code				  ;;
2797
;! Below is private data you should never use directly from your code         ;;
2756
;;================================================================================================;;
2798
;;============================================================================;;
Line 2757... Line 2799...
2757
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2799
;;////////////////////////////////////////////////////////////////////////////;;
2758
;;================================================================================================;;
2800
;;============================================================================;;
Line 2759... Line 2801...
2759
 
2801
 
Line 2782... Line 2824...
2782
    dd	img.flip.layer.bpp1_horz
2824
    dd  img.flip.layer.bpp1_horz
2783
    dd	img.flip.layer.bpp8ig_horz
2825
    dd  img.flip.layer.bpp8ig_horz
2784
    dd	img.flip.layer.bpp2i_horz
2826
    dd  img.flip.layer.bpp2i_horz
2785
    dd	img.flip.layer.bpp4i_horz
2827
    dd  img.flip.layer.bpp4i_horz
Line 2786... Line 2828...
2786
 
2828
 
2787
;;================================================================================================;;
2829
;;============================================================================;;
2788
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2830
;;////////////////////////////////////////////////////////////////////////////;;
2789
;;================================================================================================;;
2831
;;============================================================================;;
2790
;! Exported functions section									  ;;
2832
;! Exported functions section                                                 ;;
2791
;;================================================================================================;;
2833
;;============================================================================;;
2792
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2834
;;////////////////////////////////////////////////////////////////////////////;;
Line 2793... Line 2835...
2793
;;================================================================================================;;
2835
;;============================================================================;;
2794
 
2836