Subversion Repositories Kolibri OS

Rev

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

Rev 6807 Rev 7105
1
;;================================================================================================;;
1
;;================================================================================================;;
2
;;//// convert.asm //// (c) dunkaist, 2012 ///////////////////////////////////////////////////////;;
2
;;//// convert.asm //// (c) dunkaist, 2012 ///////////////////////////////////////////////////////;;
3
;;================================================================================================;;
3
;;================================================================================================;;
4
;;                                                                                                ;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
9
;; of the License, or (at your option) any later version.                                         ;;
9
;; of the License, or (at your option) any later version.                                         ;;
10
;;                                                                                                ;;
10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
13
;; Lesser General Public License for more details.                                                ;;
13
;; Lesser General Public License for more details.                                                ;;
14
;;                                                                                                ;;
14
;;                                                                                                ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
18
;;================================================================================================;;
19
 
19
 
20
 
20
 
21
 
21
 
22
;;================================================================================================;;
22
;;================================================================================================;;
23
proc img.convert _src, _dst, _dst_type, _flags, _param                                            ;;
23
proc img.convert _src, _dst, _dst_type, _flags, _param                                            ;;
24
;;------------------------------------------------------------------------------------------------;;
24
;;------------------------------------------------------------------------------------------------;;
25
;? convert _image                                                                                 ;;
25
;? convert _image                                                                                 ;;
26
;;------------------------------------------------------------------------------------------------;;
26
;;------------------------------------------------------------------------------------------------;;
27
;> [_src]      = pointer to source image                                                          ;;
27
;> [_src]      = pointer to source image                                                          ;;
28
;> [_dst]      = pointer to destination image, or 0 to create a new one                           ;;
28
;> [_dst]      = pointer to destination image, or 0 to create a new one                           ;;
29
;> [_dst_type] = Image.Type of resulting image                                                    ;;
29
;> [_dst_type] = Image.Type of resulting image                                                    ;;
30
;> [_flags]    = see libimg.inc                                                                   ;;
30
;> [_flags]    = see libimg.inc                                                                   ;;
31
;> [_param]    = depends on _flags fields, see libimg.inc                                         ;;
31
;> [_param]    = depends on _flags fields, see libimg.inc                                         ;;
32
;;------------------------------------------------------------------------------------------------;;
32
;;------------------------------------------------------------------------------------------------;;
33
;< eax = 0 / pointer to converted image                                                           ;;
33
;< eax = 0 / pointer to converted image                                                           ;;
34
;< ecx = error code / undefined                                                                   ;;
34
;< ecx = error code / undefined                                                                   ;;
35
;;================================================================================================;;
35
;;================================================================================================;;
-
 
36
locals
-
 
37
        img     dd ?
-
 
38
        prev    dd ?
-
 
39
endl
36
        push    ebx esi edi 0 0
40
        push    ebx esi edi
-
 
41
        mov     [img], 0
-
 
42
        mov     [prev], 0
37
        mov     ebx, [_src]
43
        mov     ebx, [_src]
38
    @@:
44
    @@:
39
        mov     eax, [ebx + Image.Previous]
45
        mov     eax, [ebx + Image.Previous]
40
        test    eax, eax
46
        test    eax, eax
41
        jz      .loop
47
        jz      .loop
42
        mov     ebx, eax
48
        mov     ebx, eax
43
        jmp     @b
49
        jmp     @b
44
  .loop:
50
  .loop:
45
        stdcall img.convert.layer, ebx, [_dst], [_dst_type], [_flags], [_param]
51
        stdcall img.convert.layer, ebx, [_dst], [_dst_type], [_flags], [_param]
46
        test    eax, eax
52
        test    eax, eax
47
        jz      .error
53
        jz      .error
48
        cmp     dword[esp + 4], 0
54
        cmp     [img], 0
49
        jnz     @f
55
        jnz     @f
50
        mov     [esp + 4], eax
56
        mov     [img], eax
51
    @@:
57
    @@:
52
        mov     ecx, [esp]
58
        mov     ecx, [prev]
53
        jecxz   @f
59
        jecxz   @f
54
        mov     [ecx + Image.Next], eax
60
        mov     [ecx + Image.Next], eax
-
 
61
        mov     [eax + Image.Previous], ecx
55
    @@:
62
    @@:
-
 
63
        mov     [prev], eax
56
	push	[ebx + Image.Flags]
64
        push    [ebx + Image.Flags]
57
	pop	[eax + Image.Flags]
65
        pop     [eax + Image.Flags]
58
	push	[ebx + Image.Delay]
66
        push    [ebx + Image.Delay]
59
	pop	[eax + Image.Delay]
67
        pop     [eax + Image.Delay]
60
        mov     [eax + Image.Previous], ecx
-
 
61
        mov     [esp], eax
-
 
62
        mov     ebx, [ebx + Image.Next]
68
        mov     ebx, [ebx + Image.Next]
63
        test    ebx, ebx
69
        test    ebx, ebx
64
        jnz     .loop
70
        jnz     .loop
65
  .quit:
-
 
66
        pop     eax eax edi esi ebx
71
        mov     eax, [img]
67
        ret
-
 
68
  .error:
72
  .error:
69
        pop     eax eax edi esi ebx
73
        pop     edi esi ebx
70
        ret
74
        ret
71
endp
75
endp
72
 
76
 
73
 
77
 
74
;;================================================================================================;;
78
;;================================================================================================;;
75
proc img.convert.layer _src, _dst, _dst_type, _flags, _param                                      ;;
79
proc img.convert.layer _src, _dst, _dst_type, _flags, _param                                      ;;
76
;;------------------------------------------------------------------------------------------------;;
80
;;------------------------------------------------------------------------------------------------;;
77
;? convert _image layer                                                                           ;;
81
;? convert _image layer                                                                           ;;
78
;;------------------------------------------------------------------------------------------------;;
82
;;------------------------------------------------------------------------------------------------;;
79
;> [_src]      = pointer to source image                                                          ;;
83
;> [_src]      = pointer to source image                                                          ;;
80
;> [_dst]      = pointer to destination image, or 0 to create a new one                           ;;
84
;> [_dst]      = pointer to destination image, or 0 to create a new one                           ;;
81
;> [_dst_type] = Image.Type of resulting image                                                    ;;
85
;> [_dst_type] = Image.Type of resulting image                                                    ;;
82
;> [_flags]    = see libimg.inc                                                                   ;;
86
;> [_flags]    = see libimg.inc                                                                   ;;
83
;> [_param]    = depends on _flags fields, see libimg.inc                                         ;;
87
;> [_param]    = depends on _flags fields, see libimg.inc                                         ;;
84
;;------------------------------------------------------------------------------------------------;;
88
;;------------------------------------------------------------------------------------------------;;
85
;< eax = 0 / pointer to converted image                                                           ;;
89
;< eax = 0 / pointer to converted image                                                           ;;
86
;< ecx = error code / undefined                                                                   ;;
90
;< ecx = error code / undefined                                                                   ;;
87
;;================================================================================================;;
91
;;================================================================================================;;
88
locals
92
locals
89
	width	rd 1
-
 
90
	height	rd 1
93
        fun     rd 1
91
endl
94
endl
92
        push    ebx esi edi
95
        push    ebx esi edi
93
 
96
 
94
	mov	ebx, [_src]
97
        mov     ebx, [_src]
95
	mov	eax, 1
98
        mov     eax, [ebx + Image.Type]
96
	mov	ecx, [_dst_type]
99
        mov     esi, [img.convert.table + 4*eax]
97
	shl	eax, cl
100
  .next:
98
	mov	ecx, [ebx + Image.Type]
101
        lodsd
99
	test	eax, [img.types_table + 4*ecx]
102
        test    eax, eax
100
	jnz	@f
103
        jnz     @f
101
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
104
        mov     ecx, LIBIMG_ERROR_BIT_DEPTH
102
	jmp	.error
105
        jmp     .exit
103
    @@:
106
    @@:
-
 
107
        cmp     eax, [_dst_type]
-
 
108
        lodsd
-
 
109
        jnz     .next
-
 
110
        mov     [fun], eax
-
 
111
 
104
	mov	eax, [_dst]
112
        mov     eax, [_dst]
105
	test	eax, eax
113
        test    eax, eax
106
	jnz	@f
114
        jnz     @f
107
	stdcall	img.create, [ebx + Image.Width], [ebx + Image.Height], [_dst_type]
115
        stdcall img.create, [ebx + Image.Width], [ebx + Image.Height], [_dst_type]
108
	test	eax, eax
116
        test    eax, eax
109
	jz	.error
117
        jz      .exit
110
	mov	[_dst], eax
118
        mov     [_dst], eax
111
    @@:
119
    @@:
112
	mov	edi, [eax + Image.Data]
120
        mov     edi, [eax + Image.Data]
113
	mov	esi, [ebx + Image.Data]
121
        mov     esi, [ebx + Image.Data]
114
	mov	eax, [ebx + Image.Type]
122
        mov     eax, [ebx + Image.Type]
115
	cmp	eax, Image.bpp8i
123
        stdcall [fun], [_src], [_dst]
116
	je	.bpp8i
-
 
117
	cmp	eax, Image.bpp8g
124
        mov     eax, [_dst]
118
	je	.bpp8g
-
 
119
	cmp	eax, Image.bpp24
-
 
120
	je	.bpp24
-
 
121
	cmp	eax, Image.bpp32
-
 
122
	je	.bpp32
-
 
123
	cmp	eax, Image.bpp15
-
 
124
	je	.bpp15
125
  .exit:
125
	cmp	eax, Image.bpp16
126
        pop     edi esi ebx
126
	je	.bpp16
127
        ret
127
	cmp	eax, Image.bpp1
-
 
128
	je	.bpp1
128
endp
129
	cmp	eax, Image.bpp8a
-
 
130
	je	.bpp8a
-
 
131
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
-
 
132
	jmp	.error
-
 
133
 
-
 
134
  .find_in_table_and_jump:
-
 
135
	mov	ecx, [_dst_type]
-
 
136
    @@:
-
 
137
	mov	eax, [edx]
-
 
138
	add	edx, 8
-
 
139
	cmp	eax, ecx
-
 
140
	jne	@b
-
 
141
	jmp	dword[edx - 4]
-
 
142
 
-
 
143
 
-
 
144
  .bpp8i:
129
 
145
	mov	edx, img.convert.bpp8i.table
-
 
146
	jmp	.find_in_table_and_jump
-
 
147
  .bpp8i_to_bpp24:
130
proc img._.convert.bpp8i_to_bpp24 _src, _dst
148
	mov	ecx, [ebx + Image.Width]
131
        mov     ecx, [ebx + Image.Width]
149
	imul	ecx, [ebx + Image.Height]
132
        imul    ecx, [ebx + Image.Height]
150
 
133
 
151
	mov	ebx, [ebx + Image.Palette]
134
        mov     ebx, [ebx + Image.Palette]
152
	sub	ecx, 1
135
        sub     ecx, 1
153
	jz	.bpp8i.last
136
        jz      .bpp8i.last
154
    @@:
137
    @@:
155
	movzx	eax, byte[esi]
138
        movzx   eax, byte[esi]
156
	add	esi, 1
139
        add     esi, 1
157
	mov	eax, [ebx + eax*4]
140
        mov     eax, [ebx + eax*4]
158
	mov	[edi], eax
141
        mov     [edi], eax
159
	add	edi, 3
142
        add     edi, 3
160
	sub	ecx, 1
143
        sub     ecx, 1
161
	jnz	@b
144
        jnz     @b
162
  .bpp8i.last:
145
  .bpp8i.last:
163
	movzx	eax, byte[esi]
146
        movzx   eax, byte[esi]
164
	mov	eax, [ebx + eax*4]
147
        mov     eax, [ebx + eax*4]
165
	mov	[edi], ax
148
        mov     [edi], ax
166
	shr	eax, 16
149
        shr     eax, 16
167
	mov	[edi + 2], al
150
        mov     [edi + 2], al
168
	mov	eax, [_dst]
151
        ret
169
	jmp	.quit
152
endp
-
 
153
 
-
 
154
 
-
 
155
proc img._.convert.bpp8i_to_bpp32 _src, _dst
-
 
156
        mov     ecx, [ebx + Image.Width]
-
 
157
        imul    ecx, [ebx + Image.Height]
-
 
158
 
-
 
159
        mov     ebx, [ebx + Image.Palette]
-
 
160
    @@:
-
 
161
        movzx   eax, byte[esi]
-
 
162
        add     esi, 1
-
 
163
        mov     eax, [ebx + eax*4]
-
 
164
        mov     [edi], eax
-
 
165
        add     edi, 4
-
 
166
        dec     ecx
-
 
167
        jnz     @b
-
 
168
        ret
170
 
-
 
171
 
169
endp
172
 
-
 
173
  .bpp8g:
-
 
174
	mov	edx, img.convert.bpp8g.table
170
 
175
	jmp	.find_in_table_and_jump
171
 
176
  .bpp8g_to_bpp1:
172
proc img._.convert.bpp8g_to_bpp1 _src, _dst
177
	mov	eax, [_dst]
173
        mov     eax, [_dst]
178
	mov	eax, [eax + Image.Palette]
174
        mov     eax, [eax + Image.Palette]
179
	mov	dword[eax], 0x00000000
175
        mov     dword[eax], 0x00000000
180
	mov	dword[eax + 4], 0x00ffffff
176
        mov     dword[eax + 4], 0x00ffffff
181
	mov	edx, [ebx + Image.Height]
177
        mov     edx, [ebx + Image.Height]
182
  .bpp8g_to_bpp1.line:
178
  .bpp8g_to_bpp1.line:
183
	mov	ax, 0x0800
179
        mov     ax, 0x0800
184
	mov	ecx, [ebx + Image.Width]
180
        mov     ecx, [ebx + Image.Width]
185
  .bpp8g_to_bpp1.pixel:
181
  .bpp8g_to_bpp1.pixel:
186
	shl	al, 1
182
        shl     al, 1
187
	cmp	byte[esi], 0x7f
183
        cmp     byte[esi], 0x7f
188
	cmc
184
        cmc
189
	adc	eax, 0
185
        adc     eax, 0
190
	add	esi, 1
186
        add     esi, 1
191
	dec	ah
187
        dec     ah
192
	jnz	@f
188
        jnz     @f
193
	mov	byte[edi], al
189
        mov     byte[edi], al
194
	add	edi, 1
190
        add     edi, 1
195
	mov	ax, 0x0800
191
        mov     ax, 0x0800
196
    @@:
192
    @@:
197
	dec	ecx
193
        dec     ecx
198
	jnz	.bpp8g_to_bpp1.pixel
194
        jnz     .bpp8g_to_bpp1.pixel
199
	cmp	ah, 8
195
        cmp     ah, 8
200
	je	@f
196
        je      @f
201
	mov	cl, ah
197
        mov     cl, ah
202
	shl	al, cl
198
        shl     al, cl
203
	mov	byte[edi], al
199
        mov     byte[edi], al
204
	add	edi, 1
200
        add     edi, 1
205
    @@:
201
    @@:
206
	dec	edx
202
        dec     edx
207
	jnz	.bpp8g_to_bpp1.line
203
        jnz     .bpp8g_to_bpp1.line
208
	mov	eax, [_dst]
-
 
209
	jmp	.quit
204
        ret
210
 
205
endp
211
  .bpp8g_to_bpp8g:
-
 
212
	mov	ecx, [ebx + Image.Width]
-
 
213
	imul	ecx, [ebx + Image.Height]
-
 
214
	rep	movsb
-
 
215
	mov	eax, [_dst]
-
 
216
	jmp	.quit
-
 
217
 
206
 
218
  .bpp8g_to_bpp24:
207
proc img._.convert.bpp8g_to_bpp24 _src, _dst
219
	mov	ecx, [ebx + Image.Width]
208
        mov     ecx, [ebx + Image.Width]
220
	imul	ecx, [ebx + Image.Height]
209
        imul    ecx, [ebx + Image.Height]
221
    @@:
210
    @@:
222
	mov	al, byte[esi]
211
        mov     al, byte[esi]
223
	mov	byte[edi + 0], al
212
        mov     byte[edi + 0], al
224
	mov	byte[edi + 1], al
213
        mov     byte[edi + 1], al
225
	mov	byte[edi + 2], al
214
        mov     byte[edi + 2], al
226
	add	esi, 1
215
        add     esi, 1
227
	add	edi, 3
216
        add     edi, 3
228
	sub	ecx, 1
217
        sub     ecx, 1
229
	jnz	@b
218
        jnz     @b
230
	mov	eax, [_dst]
219
        ret
231
	jmp	.quit
220
endp
-
 
221
 
232
 
-
 
233
  .bpp24:
222
 
234
	mov	edx, img.convert.bpp24.table
-
 
235
	jmp	.find_in_table_and_jump
-
 
236
  .bpp24_to_bpp24:
223
proc img._.convert.bpp24_to_bpp24 _src, _dst
237
	mov	ecx, [ebx + Image.Width]
224
        mov     ecx, [ebx + Image.Width]
238
	imul	ecx, [ebx + Image.Height]
225
        imul    ecx, [ebx + Image.Height]
239
	lea	ecx, [ecx*3]
226
        lea     ecx, [ecx*3]
240
	mov	edx, ecx
227
        mov     edx, ecx
241
	shr	ecx, 2
228
        shr     ecx, 2
242
	rep	movsd
229
        rep     movsd
243
	mov	ecx, edx
230
        mov     ecx, edx
244
	and	ecx, 3
231
        and     ecx, 3
245
	rep	movsb
232
        rep     movsb
246
	mov	eax, [_dst]
233
        ret
247
	jmp	.quit
234
endp
-
 
235
 
-
 
236
 
248
  .bpp24_to_bpp8g:
237
proc img._.convert.bpp24_to_bpp8g _src, _dst
249
	mov	ecx, [ebx + Image.Width]
238
        mov     ecx, [ebx + Image.Width]
250
	imul	ecx, [ebx + Image.Height]
239
        imul    ecx, [ebx + Image.Height]
251
    @@:
240
    @@:
252
	movzx	ebx, byte[esi + 0]
241
        movzx   ebx, byte[esi + 0]
253
	movzx	eax, byte[esi + 1]
242
        movzx   eax, byte[esi + 1]
254
	add	ebx, eax
243
        add     ebx, eax
255
	movzx	eax, byte[esi + 2]
244
        movzx   eax, byte[esi + 2]
256
	add	eax, ebx
245
        add     eax, ebx
257
	mov	ebx, 3
246
        mov     ebx, 3
258
	add	esi, 3
247
        add     esi, 3
259
	div	bl
248
        div     bl
260
	mov	byte[edi], al
249
        mov     byte[edi], al
261
	add	edi, 1
250
        add     edi, 1
262
	sub	ecx, 1
251
        sub     ecx, 1
263
	jnz	@b
252
        jnz     @b
264
	mov	eax, [_dst]
253
        ret
265
	jmp	.quit
254
endp
-
 
255
 
-
 
256
 
266
  .bpp24_to_bpp32:
257
proc img._.convert.bpp24_to_bpp32 _src, _dst
267
	mov	ecx, [ebx + Image.Width]
258
        mov     ecx, [ebx + Image.Width]
268
	imul	ecx, [ebx + Image.Height]
259
        imul    ecx, [ebx + Image.Height]
269
    @@:
260
    @@:
270
        lodsw
261
        lodsw
271
        ror     eax, 16
262
        ror     eax, 16
272
        lodsb
263
        lodsb
273
        rol     eax, 16
264
        rol     eax, 16
274
        stosd
265
        stosd
275
        dec     ecx
266
        dec     ecx
276
        jnz     @b
267
        jnz     @b
277
	mov	eax, [_dst]
268
        ret
278
	jmp	.quit
269
endp
279
 
-
 
280
 
270
 
281
  .bpp32:
-
 
282
	mov	edx, img.convert.bpp32.table
-
 
283
	jmp	.find_in_table_and_jump
271
 
284
  .bpp32_to_bpp24:
272
proc img._.convert.bpp32_to_bpp24 _src, _dst
285
	mov	ecx, [ebx + Image.Width]
273
        mov     ecx, [ebx + Image.Width]
286
	imul	ecx, [ebx + Image.Height]
274
        imul    ecx, [ebx + Image.Height]
287
    @@:
275
    @@:
288
	mov	eax, [esi]
276
        mov     eax, [esi]
289
	mov	[edi], ax
277
        mov     [edi], ax
290
	shr	eax, 16
278
        shr     eax, 16
291
	mov	[edi + 2], al
279
        mov     [edi + 2], al
292
	add	esi, 4
280
        add     esi, 4
293
	add	edi, 3
281
        add     edi, 3
294
	sub	ecx, 1
282
        sub     ecx, 1
295
	jnz	@b
283
        jnz     @b
296
	mov	eax, [_dst]
284
        ret
-
 
285
endp
-
 
286
 
-
 
287
 
-
 
288
proc img._.convert.bpp32_to_bpp32 _src, _dst
-
 
289
        mov     ecx, [ebx + Image.Width]
-
 
290
        imul    ecx, [ebx + Image.Height]
-
 
291
        rep     movsd
297
	jmp	.quit
292
        ret
-
 
293
endp
298
 
-
 
299
 
294
 
300
  .bpp15:
-
 
301
	mov	edx, img.convert.bpp15.table
-
 
302
	jmp	.find_in_table_and_jump
295
 
303
  .bpp15_to_bpp24:
296
proc img._.convert.bpp15_to_bpp24 _src, _dst
304
	mov	ecx, [ebx + Image.Width]
297
        mov     ecx, [ebx + Image.Width]
305
	imul	ecx, [ebx + Image.Height]
298
        imul    ecx, [ebx + Image.Height]
306
 
299
 
307
  .bpp15.intel:	; copypasted from do_rgb
300
  .bpp15.intel: ; copypasted from do_rgb
308
	push	ebx ebp
301
        push    ebx ebp
309
	sub	ecx, 4
302
        sub     ecx, 4
310
	jb	.bpp15.tail
303
        jb      .bpp15.tail
311
align 16
304
align 16
312
  .bpp15.intel.loop:
305
  .bpp15.intel.loop:
313
repeat 2
306
repeat 2
314
	mov	ebx, [esi]
307
        mov     ebx, [esi]
315
	mov	al, [esi]
308
        mov     al, [esi]
316
	mov	ah, [esi + 1]
309
        mov     ah, [esi + 1]
317
	add	esi, 4
310
        add     esi, 4
318
	and	al, 0x1F
311
        and     al, 0x1F
319
	and	ah, 0x1F shl 2
312
        and     ah, 0x1F shl 2
320
	mov	ebp, ebx
313
        mov     ebp, ebx
321
	mov	dl, al
314
        mov     dl, al
322
	mov	dh, ah
315
        mov     dh, ah
323
	shr	al, 2
316
        shr     al, 2
324
	shr	ah, 4
317
        shr     ah, 4
325
	shl	dl, 3
318
        shl     dl, 3
326
	shl	dh, 1
319
        shl     dh, 1
327
	and	ebp, 0x1F shl 5
320
        and     ebp, 0x1F shl 5
328
	add	al, dl
321
        add     al, dl
329
	add	ah, dh
322
        add     ah, dh
330
	shr	ebp, 2
323
        shr     ebp, 2
331
	mov	[edi], al
324
        mov     [edi], al
332
	mov	[edi + 2], ah
325
        mov     [edi + 2], ah
333
	mov	eax, ebx
326
        mov     eax, ebx
334
	mov	ebx, ebp
327
        mov     ebx, ebp
335
	shr	eax, 16
328
        shr     eax, 16
336
	shr	ebx, 5
329
        shr     ebx, 5
337
	add	ebx, ebp
330
        add     ebx, ebp
338
	mov	ebp, eax
331
        mov     ebp, eax
339
	mov	[edi + 1], bl
332
        mov     [edi + 1], bl
340
	and	eax, (0x1F) or (0x1F shl 10)
333
        and     eax, (0x1F) or (0x1F shl 10)
341
	and	ebp, 0x1F shl 5
334
        and     ebp, 0x1F shl 5
342
	lea	edx, [eax + eax]
335
        lea     edx, [eax + eax]
343
	shr	al, 2
336
        shr     al, 2
344
	mov	ebx, ebp
337
        mov     ebx, ebp
345
	shr	ah, 4
338
        shr     ah, 4
346
	shl	dl, 2
339
        shl     dl, 2
347
	shr	ebx, 2
340
        shr     ebx, 2
348
	shr	ebp, 7
341
        shr     ebp, 7
349
	add	al, dl
342
        add     al, dl
350
	add	ah, dh
343
        add     ah, dh
351
	mov	[edi + 3], al
344
        mov     [edi + 3], al
352
	add	ebx, ebp
345
        add     ebx, ebp
353
	mov	[edi + 5], ah
346
        mov     [edi + 5], ah
354
	mov	[edi + 4], bl
347
        mov     [edi + 4], bl
355
	add	edi, 6
348
        add     edi, 6
356
end repeat
349
end repeat
357
	sub	ecx, 4
350
        sub     ecx, 4
358
	jnb	.bpp15.intel.loop
351
        jnb     .bpp15.intel.loop
359
  .bpp15.tail:
352
  .bpp15.tail:
360
	add	ecx, 4
353
        add     ecx, 4
361
	jz	.bpp15.done
354
        jz      .bpp15.done
362
    @@:
355
    @@:
363
	movzx	eax, word [esi]
356
        movzx   eax, word [esi]
364
	mov	ebx, eax
357
        mov     ebx, eax
365
	add	esi, 2
358
        add     esi, 2
366
	and	eax, (0x1F) or (0x1F shl 10)
359
        and     eax, (0x1F) or (0x1F shl 10)
367
	and	ebx, 0x1F shl 5
360
        and     ebx, 0x1F shl 5
368
	lea	edx, [eax + eax]
361
        lea     edx, [eax + eax]
369
	shr	al, 2
362
        shr     al, 2
370
	mov	ebp, ebx
363
        mov     ebp, ebx
371
	shr	ebx, 2
364
        shr     ebx, 2
372
	shr	ah, 4
365
        shr     ah, 4
373
	shl	dl, 2
366
        shl     dl, 2
374
	shr	ebp, 7
367
        shr     ebp, 7
375
	add	eax, edx
368
        add     eax, edx
376
	add	ebx, ebp
369
        add     ebx, ebp
377
	mov	[edi], al
370
        mov     [edi], al
378
	mov	[edi + 1], bl
371
        mov     [edi + 1], bl
379
	mov	[edi + 2], ah
372
        mov     [edi + 2], ah
380
	add	edi, 3
373
        add     edi, 3
381
	sub	ecx, 1
374
        sub     ecx, 1
382
	jnz	@b
375
        jnz     @b
383
  .bpp15.done:
376
  .bpp15.done:
384
	pop	ebp ebx
377
        pop     ebp ebx
385
	mov	eax, [_dst]
378
        mov     eax, [_dst]
386
	jmp	.quit
379
        jmp     .quit
387
 
380
 
388
  .bpp15.amd:
381
  .bpp15.amd:
389
	push	ebx ebp
382
        push    ebx ebp
390
	sub	ecx, 4
383
        sub     ecx, 4
391
	jb	.bpp15.tail
384
        jb      .bpp15.tail
392
align 16
385
align 16
393
  .bpp15.amd.loop:
386
  .bpp15.amd.loop:
394
repeat 4
387
repeat 4
395
if (% mod 2) = 1
388
if (% mod 2) = 1
396
	mov	eax, dword[esi]
389
        mov     eax, dword[esi]
397
	mov	ebx, dword[esi]
390
        mov     ebx, dword[esi]
398
else
391
else
399
	movzx	eax, word[esi]
392
        movzx   eax, word[esi]
400
	mov	ebx, eax
393
        mov     ebx, eax
401
end if
394
end if
402
	add	esi, 2
395
        add     esi, 2
403
	and	eax, (0x1F) or (0x1F shl 10)
396
        and     eax, (0x1F) or (0x1F shl 10)
404
	and	ebx, 0x1F shl 5
397
        and     ebx, 0x1F shl 5
405
	lea	edx, [eax + eax]
398
        lea     edx, [eax + eax]
406
	shr	al, 2
399
        shr     al, 2
407
	mov	ebp, ebx
400
        mov     ebp, ebx
408
	shr	ebx, 2
401
        shr     ebx, 2
409
	shr	ah, 4
402
        shr     ah, 4
410
	shl	dl, 2
403
        shl     dl, 2
411
	shr	ebp, 7
404
        shr     ebp, 7
412
	add	eax, edx
405
        add     eax, edx
413
	add	ebx, ebp
406
        add     ebx, ebp
414
	mov	[edi], al
407
        mov     [edi], al
415
	mov	[edi + 1], bl
408
        mov     [edi + 1], bl
416
	mov	[edi + 2], ah
409
        mov     [edi + 2], ah
417
	add	edi, 3
410
        add     edi, 3
418
end repeat
411
end repeat
419
	sub	ecx, 4
412
        sub     ecx, 4
420
	jnb	.bpp15.amd.loop
413
        jnb     .bpp15.amd.loop
421
	jmp	.bpp15.tail
414
        jmp     .bpp15.tail
-
 
415
 
-
 
416
  .quit:
-
 
417
        ret
-
 
418
endp
422
 
-
 
423
 
419
 
424
  .bpp16:
-
 
425
	mov	edx, img.convert.bpp16.table
-
 
426
	jmp	.find_in_table_and_jump
420
 
427
  .bpp16_to_bpp24:
421
proc img._.convert.bpp16_to_bpp24 _src, _dst
428
	mov	ecx, [ebx + Image.Width]
422
        mov     ecx, [ebx + Image.Width]
429
	imul	ecx, [ebx + Image.Height]
423
        imul    ecx, [ebx + Image.Height]
430
  .bpp16.intel:
424
  .bpp16.intel:
431
	push	ebx ebp
425
        push    ebx ebp
432
	sub	ecx, 4
426
        sub     ecx, 4
433
	jb	.bpp16.tail
427
        jb      .bpp16.tail
434
align 16
428
align 16
435
  .bpp16.intel.loop:
429
  .bpp16.intel.loop:
436
repeat 2
430
repeat 2
437
	mov	ebx, [esi]
431
        mov     ebx, [esi]
438
	mov	al, [esi]
432
        mov     al, [esi]
439
	mov	ah, [esi + 1]
433
        mov     ah, [esi + 1]
440
	add	esi, 4
434
        add     esi, 4
441
	and	al, 0x1F
435
        and     al, 0x1F
442
	and	ah, 0x1F shl 3
436
        and     ah, 0x1F shl 3
443
	mov	ebp, ebx
437
        mov     ebp, ebx
444
	mov	dl, al
438
        mov     dl, al
445
	mov	dh, ah
439
        mov     dh, ah
446
	shr	al, 2
440
        shr     al, 2
447
	shr	ah, 5
441
        shr     ah, 5
448
	shl	dl, 3
442
        shl     dl, 3
449
	and	ebp, 0x3F shl 5
443
        and     ebp, 0x3F shl 5
450
	add	al, dl
444
        add     al, dl
451
	add	ah, dh
445
        add     ah, dh
452
	shr	ebp, 3
446
        shr     ebp, 3
453
	mov	[edi], al
447
        mov     [edi], al
454
	mov	[edi + 2], ah
448
        mov     [edi + 2], ah
455
	mov	eax, ebx
449
        mov     eax, ebx
456
	mov	ebx, ebp
450
        mov     ebx, ebp
457
	shr	eax, 16
451
        shr     eax, 16
458
	shr	ebx, 6
452
        shr     ebx, 6
459
	add	ebx, ebp
453
        add     ebx, ebp
460
	mov	ebp, eax
454
        mov     ebp, eax
461
	mov	[edi + 1], bl
455
        mov     [edi + 1], bl
462
	and	eax, (0x1F) or (0x1F shl 11)
456
        and     eax, (0x1F) or (0x1F shl 11)
463
	and	ebp, 0x3F shl 5
457
        and     ebp, 0x3F shl 5
464
	mov	edx, eax
458
        mov     edx, eax
465
	shr	al, 2
459
        shr     al, 2
466
	mov	ebx, ebp
460
        mov     ebx, ebp
467
	shr	ah, 5
461
        shr     ah, 5
468
	shl	dl, 3
462
        shl     dl, 3
469
	shr	ebx, 3
463
        shr     ebx, 3
470
	shr	ebp, 9
464
        shr     ebp, 9
471
	add	al, dl
465
        add     al, dl
472
	add	ah, dh
466
        add     ah, dh
473
	mov	[edi + 3], al
467
        mov     [edi + 3], al
474
	add	ebx, ebp
468
        add     ebx, ebp
475
	mov	[edi + 5], ah
469
        mov     [edi + 5], ah
476
	mov	[edi + 4], bl
470
        mov     [edi + 4], bl
477
	add	edi, 6
471
        add     edi, 6
478
end repeat
472
end repeat
479
	sub	ecx, 4
473
        sub     ecx, 4
480
	jnb	.bpp16.intel.loop
474
        jnb     .bpp16.intel.loop
481
  .bpp16.tail:
475
  .bpp16.tail:
482
	add	ecx, 4
476
        add     ecx, 4
483
	jz	.bpp16.done
477
        jz      .bpp16.done
484
    @@:
478
    @@:
485
	movzx	eax, word[esi]
479
        movzx   eax, word[esi]
486
	mov	ebx, eax
480
        mov     ebx, eax
487
	add	esi, 2
481
        add     esi, 2
488
	and	eax, (0x1F) or (0x1F shl 11)
482
        and     eax, (0x1F) or (0x1F shl 11)
489
	and	ebx, 0x3F shl 5
483
        and     ebx, 0x3F shl 5
490
	mov	edx, eax
484
        mov     edx, eax
491
	shr	al, 2
485
        shr     al, 2
492
	mov	ebp, ebx
486
        mov     ebp, ebx
493
	shr	ebx, 3
487
        shr     ebx, 3
494
	shr	ah, 5
488
        shr     ah, 5
495
	shl	dl, 3
489
        shl     dl, 3
496
	shr	ebp, 9
490
        shr     ebp, 9
497
	add	eax, edx
491
        add     eax, edx
498
	add	ebx, ebp
492
        add     ebx, ebp
499
	mov	[edi], al
493
        mov     [edi], al
500
	mov	[edi + 1], bl
494
        mov     [edi + 1], bl
501
	mov	[edi + 2], ah
495
        mov     [edi + 2], ah
502
	add	edi, 3
496
        add     edi, 3
503
	sub	ecx, 1
497
        sub     ecx, 1
504
	jnz	@b
498
        jnz     @b
505
  .bpp16.done:
499
  .bpp16.done:
506
	pop	ebp ebx
500
        pop     ebp ebx
507
	mov	eax, [_dst]
501
        mov     eax, [_dst]
508
	jmp	.quit
502
        jmp     .quit
509
 
503
 
510
  .bpp16.amd:
504
  .bpp16.amd:
511
	push	ebx ebp
505
        push    ebx ebp
512
	sub	ecx, 4
506
        sub     ecx, 4
513
	jb	.bpp16.tail
507
        jb      .bpp16.tail
514
align 16
508
align 16
515
  .bpp16.amd.loop:
509
  .bpp16.amd.loop:
516
repeat 4
510
repeat 4
517
if (% mod 2) = 1
511
if (% mod 2) = 1
518
	mov	eax, dword[esi]
512
        mov     eax, dword[esi]
519
	mov	ebx, dword[esi]
513
        mov     ebx, dword[esi]
520
else
514
else
521
	movzx	eax, word[esi]
515
        movzx   eax, word[esi]
522
	mov	ebx, eax
516
        mov     ebx, eax
523
end if
517
end if
524
	add	esi, 2
518
        add     esi, 2
525
	and	eax, (0x1F) or (0x1F shl 11)
519
        and     eax, (0x1F) or (0x1F shl 11)
526
	and	ebx, 0x3F shl 5
520
        and     ebx, 0x3F shl 5
527
	mov	edx, eax
521
        mov     edx, eax
528
	shr	al, 2
522
        shr     al, 2
529
	mov	ebp, ebx
523
        mov     ebp, ebx
530
	shr	ebx, 3
524
        shr     ebx, 3
531
	shr	ah, 5
525
        shr     ah, 5
532
	shl	dl, 3
526
        shl     dl, 3
533
	shr	ebp, 9
527
        shr     ebp, 9
534
	add	eax, edx
528
        add     eax, edx
535
	add	ebx, ebp
529
        add     ebx, ebp
536
	mov	[edi], al
530
        mov     [edi], al
537
	mov	[edi + 1], bl
531
        mov     [edi + 1], bl
538
	mov	[edi + 2], ah
532
        mov     [edi + 2], ah
539
	add	edi, 3
533
        add     edi, 3
540
end repeat
534
end repeat
541
	sub	ecx, 4
535
        sub     ecx, 4
542
	jnb	.bpp16.amd.loop
536
        jnb     .bpp16.amd.loop
543
	jmp	.bpp16.tail
537
        jmp     .bpp16.tail
-
 
538
 
-
 
539
  .quit:
-
 
540
        ret
-
 
541
endp
544
 
-
 
545
 
542
 
-
 
543
 
546
  .bpp1:
544
proc img._.convert.bpp1_to_bpp24 _src, _dst
547
	mov	edx, img.convert.bpp1.table
545
locals
-
 
546
        width   rd 1
548
	jmp	.find_in_table_and_jump
547
        height  rd 1
549
  .bpp1_to_bpp24:
548
endl
550
	push	[ebx + Image.Width]
549
        push    [ebx + Image.Width]
551
	pop	[width]
550
        pop     [width]
552
	push	[ebx + Image.Height]
551
        push    [ebx + Image.Height]
553
	pop	[height]
552
        pop     [height]
554
	mov	edx, [ebx + Image.Palette]
553
        mov     edx, [ebx + Image.Palette]
555
  .bpp1_to_bpp24.line:
554
  .bpp1_to_bpp24.line:
556
	mov	ebx, [width]
555
        mov     ebx, [width]
557
  .bpp1_to_bpp24.byte:
556
  .bpp1_to_bpp24.byte:
558
	mov	ah, 8
557
        mov     ah, 8
559
	mov	al, byte[esi]
558
        mov     al, byte[esi]
560
	add	esi, 1
559
        add     esi, 1
561
  .bpp1_to_bpp24.bit:
560
  .bpp1_to_bpp24.bit:
562
	xor	ecx, ecx
561
        xor     ecx, ecx
563
	shl	al, 1
562
        shl     al, 1
564
	adc	ecx, 0
563
        adc     ecx, 0
565
	mov	ecx, [edx + 4*ecx]
564
        mov     ecx, [edx + 4*ecx]
566
	mov	word[edi], cx
565
        mov     word[edi], cx
567
	shr	ecx, 8
566
        shr     ecx, 8
568
	mov	byte[edi + 2], ch
567
        mov     byte[edi + 2], ch
569
	add	edi, 3
568
        add     edi, 3
570
	sub	ebx, 1
569
        sub     ebx, 1
571
	jnz	@f
570
        jnz     @f
572
	sub	[height], 1
571
        sub     [height], 1
573
	jnz	.bpp1_to_bpp24.line
572
        jnz     .bpp1_to_bpp24.line
574
	jmp	.bpp1.done
573
        jmp     .bpp1.done
575
    @@:
574
    @@:
576
	sub	ah, 1
575
        sub     ah, 1
577
	jnz	.bpp1_to_bpp24.bit
576
        jnz     .bpp1_to_bpp24.bit
578
	jmp	.bpp1_to_bpp24.byte
577
        jmp     .bpp1_to_bpp24.byte
579
  .bpp1.done:
578
  .bpp1.done:
580
	mov	eax, [_dst]
579
        ret
581
	jmp	.quit
580
endp
582
 
-
 
583
 
581
 
584
  .bpp8a:
-
 
585
	mov	edx, img.convert.bpp8a.table
-
 
586
	jmp	.find_in_table_and_jump
582
 
587
  .bpp8a_to_bpp1:
583
proc img._.convert.bpp8a_to_bpp1 _src, _dst
588
	mov	eax, [_dst]
584
        mov     eax, [_dst]
589
	mov	eax, [eax + Image.Palette]
585
        mov     eax, [eax + Image.Palette]
590
	mov	dword[eax], 0x00000000
586
        mov     dword[eax], 0x00000000
591
	mov	dword[eax + 4], 0x00ffffff
587
        mov     dword[eax + 4], 0x00ffffff
592
	mov	edx, [ebx + Image.Height]
588
        mov     edx, [ebx + Image.Height]
593
  .bpp8a_to_bpp1.line:
589
  .bpp8a_to_bpp1.line:
594
	mov	ax, 0x0800
590
        mov     ax, 0x0800
595
	mov	ecx, [ebx + Image.Width]
591
        mov     ecx, [ebx + Image.Width]
596
  .bpp8a_to_bpp1.pixel:
592
  .bpp8a_to_bpp1.pixel:
597
	shl	al, 1
593
        shl     al, 1
598
	cmp	byte[esi], 0x7f
594
        cmp     byte[esi], 0x7f
599
	cmc
595
        cmc
600
	adc	eax, 0
596
        adc     eax, 0
601
	add	esi, 2
597
        add     esi, 2
602
	dec	ah
598
        dec     ah
603
	jnz	@f
599
        jnz     @f
604
	mov	byte[edi], al
600
        mov     byte[edi], al
605
	add	edi, 1
601
        add     edi, 1
606
	mov	ax, 0x0800
602
        mov     ax, 0x0800
607
    @@:
603
    @@:
608
	dec	ecx
604
        dec     ecx
609
	jnz	.bpp8a_to_bpp1.pixel
605
        jnz     .bpp8a_to_bpp1.pixel
610
	cmp	ah, 8
606
        cmp     ah, 8
611
	je	@f
607
        je      @f
612
	mov	cl, ah
608
        mov     cl, ah
613
	shl	al, cl
609
        shl     al, cl
614
	mov	byte[edi], al
610
        mov     byte[edi], al
615
	add	edi, 1
611
        add     edi, 1
616
    @@:
612
    @@:
617
	dec	edx
613
        dec     edx
618
	jnz	.bpp8a_to_bpp1.line
614
        jnz     .bpp8a_to_bpp1.line
619
	mov	eax, [_dst]
615
        ret
620
	jmp	.quit
616
endp
-
 
617
 
621
 
618
 
622
  .bpp8a_to_bpp24:
619
proc img._.convert.bpp8a_to_bpp24 _src, _dst
623
	mov	ecx, [ebx + Image.Width]
620
        mov     ecx, [ebx + Image.Width]
624
	imul	ecx, [ebx + Image.Height]
621
        imul    ecx, [ebx + Image.Height]
625
    @@:
622
    @@:
626
	mov	al, byte[esi]
623
        mov     al, byte[esi]
627
	mov	byte[edi + 0], al
624
        mov     byte[edi + 0], al
628
	mov	byte[edi + 1], al
625
        mov     byte[edi + 1], al
629
	mov	byte[edi + 2], al
626
        mov     byte[edi + 2], al
630
	add	esi, 2
627
        add     esi, 2
631
	add	edi, 3
628
        add     edi, 3
632
	sub	ecx, 1
629
        sub     ecx, 1
633
	jnz	@b
630
        jnz     @b
634
	mov	eax, [_dst]
-
 
635
	jmp	.quit
-
 
636
 
-
 
637
 
-
 
638
  .error:
-
 
639
	xor	eax, eax
-
 
640
  .quit:
-
 
641
        pop     edi esi ebx
-
 
642
	ret
631
        ret
643
endp
632
endp
644
 
633
 
645
 
634
 
646
img.convert.bpp8i.table:
635
img.convert.bpp8i.table:
647
	dd Image.bpp24, img.convert.layer.bpp8i_to_bpp24
636
        dd Image.bpp24, img._.convert.bpp8i_to_bpp24
648
img.convert.bpp8g.table:
-
 
649
	dd Image.bpp24, img.convert.layer.bpp8g_to_bpp24
-
 
650
	dd Image.bpp8g, img.convert.layer.bpp8g_to_bpp8g
637
        dd Image.bpp32, img._.convert.bpp8i_to_bpp32
651
	dd Image.bpp1,  img.convert.layer.bpp8g_to_bpp1
638
        dd 0
652
img.convert.bpp24.table:
639
img.convert.bpp24.table:
653
	dd Image.bpp24, img.convert.layer.bpp24_to_bpp24
640
        dd Image.bpp24, img._.convert.bpp24_to_bpp24
654
	dd Image.bpp8g, img.convert.layer.bpp24_to_bpp8g
641
        dd Image.bpp8g, img._.convert.bpp24_to_bpp8g
655
	dd Image.bpp32, img.convert.layer.bpp24_to_bpp32
642
        dd Image.bpp32, img._.convert.bpp24_to_bpp32
-
 
643
        dd 0
656
img.convert.bpp32.table:
644
img.convert.bpp32.table:
657
	dd Image.bpp24, img.convert.layer.bpp32_to_bpp24
645
        dd Image.bpp24, img._.convert.bpp32_to_bpp24
-
 
646
        dd Image.bpp32, img._.convert.bpp32_to_bpp32
-
 
647
        dd 0
658
img.convert.bpp15.table:
648
img.convert.bpp15.table:
659
	dd Image.bpp24, img.convert.layer.bpp15_to_bpp24
649
        dd Image.bpp24, img._.convert.bpp15_to_bpp24
-
 
650
        dd 0
660
img.convert.bpp16.table:
651
img.convert.bpp16.table:
661
	dd Image.bpp24, img.convert.layer.bpp16_to_bpp24
652
        dd Image.bpp24, img._.convert.bpp16_to_bpp24
-
 
653
        dd 0
662
img.convert.bpp1.table:
654
img.convert.bpp1.table:
663
	dd Image.bpp24, img.convert.layer.bpp1_to_bpp24
655
        dd Image.bpp24, img._.convert.bpp1_to_bpp24
-
 
656
        dd 0
-
 
657
img.convert.bpp8g.table:
-
 
658
        dd Image.bpp24, img._.convert.bpp8g_to_bpp24
-
 
659
        dd Image.bpp1,  img._.convert.bpp8g_to_bpp1
-
 
660
        dd 0
-
 
661
img.convert.bpp2i.table:
-
 
662
        dd 0
-
 
663
img.convert.bpp4i.table:
-
 
664
        dd 0
664
img.convert.bpp8a.table:
665
img.convert.bpp8a.table:
665
	dd Image.bpp24, img.convert.layer.bpp8a_to_bpp24
666
        dd Image.bpp24, img._.convert.bpp8a_to_bpp24
-
 
667
        dd 0
-
 
668
 
-
 
669
img.convert.table:
-
 
670
        dd 0    ; no image type zero
-
 
671
        dd img.convert.bpp8i.table
-
 
672
        dd img.convert.bpp24.table
-
 
673
        dd img.convert.bpp32.table
-
 
674
        dd img.convert.bpp15.table
-
 
675
        dd img.convert.bpp16.table
-
 
676
        dd img.convert.bpp1.table
-
 
677
        dd img.convert.bpp8g.table
-
 
678
        dd img.convert.bpp2i.table
-
 
679
        dd img.convert.bpp4i.table
-
 
680
        dd img.convert.bpp8a.table