Subversion Repositories Kolibri OS

Rev

Rev 2733 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2733 Rev 8341
1
;;================================================================================================;;
1
;;================================================================================================;;
2
;;//// xcf.asm //// (c) dunkaist, 2011-2012 //////////////////////////////////////////////////////;;
2
;;//// xcf.asm //// (c) dunkaist, 2011-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
;; References:                                                                                    ;;
20
;; References:                                                                                    ;;
21
;;   1. "SPECIFICATION OF THE XCF FILE FORMAT"                                                    ;;
21
;;   1. "SPECIFICATION OF THE XCF FILE FORMAT"                                                    ;;
22
;;      by Henning Makholm                                                                        ;;
22
;;      by Henning Makholm                                                                        ;;
23
;;      http://svn.gnome.org/viewvc/gimp/trunk/devel-docs/xcf.txt?view=markup                     ;;
23
;;      http://svn.gnome.org/viewvc/gimp/trunk/devel-docs/xcf.txt?view=markup                     ;;
24
;;   2. "Layer Modes"                                                                             ;;
24
;;   2. "Layer Modes"                                                                             ;;
25
;;      from docs.gimp.org                                                                        ;;
25
;;      from docs.gimp.org                                                                        ;;
26
;;      http://docs.gimp.org/en/gimp-concepts-layer-modes.html                                    ;;
26
;;      http://docs.gimp.org/en/gimp-concepts-layer-modes.html                                    ;;
27
;;                                                                                                ;;
27
;;                                                                                                ;;
28
;;================================================================================================;;
28
;;================================================================================================;;
29
include	'xcf.inc'
29
include	'xcf.inc'
30
;include	'../../../../../system/board/trunk/debug.inc'
30
;include	'../../../../../system/board/trunk/debug.inc'
31
 
-
 
32
COMPOSITE_MODE		equ	MMX
-
 
33
; MMX     | pretty fast and compatible
-
 
34
; SSE     | a bit faster, but may be unsupported by some CPUs
-
 
35
 
31
 
36
MAX_LAYERS		=	255
32
MAX_LAYERS		=	255
37
 
33
 
38
;;================================================================================================;;
34
;;================================================================================================;;
39
proc img.is.xcf _data, _length ;//////////////////////////////////////////////////////////////////;;
35
proc img.is.xcf _data, _length ;//////////////////////////////////////////////////////////////////;;
40
;;------------------------------------------------------------------------------------------------;;
36
;;------------------------------------------------------------------------------------------------;;
41
;? Determine if raw data could be decoded (is in xcf format)                                      ;;
37
;? Determine if raw data could be decoded (is in xcf format)                                      ;;
42
;;------------------------------------------------------------------------------------------------;;
38
;;------------------------------------------------------------------------------------------------;;
43
;> _data = raw data as read from file/stream                                                      ;;
39
;> _data = raw data as read from file/stream                                                      ;;
44
;> _length = data length                                                                          ;;
40
;> _length = data length                                                                          ;;
45
;;------------------------------------------------------------------------------------------------;;
41
;;------------------------------------------------------------------------------------------------;;
46
;< eax = false / true                                                                             ;;
42
;< eax = false / true                                                                             ;;
47
;;================================================================================================;;
43
;;================================================================================================;;
48
 
44
 
49
	push	edi
45
	push	edi
50
	xor	eax, eax
46
	xor	eax, eax
51
 
47
 
52
	mov	edi, [_data]
48
	mov	edi, [_data]
53
 
49
 
54
	cmp	dword[edi + xcf_header.magic_string], 'gimp'
50
	cmp	dword[edi + xcf_header.magic_string], 'gimp'
55
	jne	.is_not_xcf
51
	jne	.is_not_xcf
56
	cmp	dword[edi + xcf_header.magic_string + 4], ' xcf'
52
	cmp	dword[edi + xcf_header.magic_string + 4], ' xcf'
57
	jne	.is_not_xcf
53
	jne	.is_not_xcf
58
 
54
 
59
	cmp	[edi + xcf_header.version], 'file'
55
	cmp	[edi + xcf_header.version], 'file'
60
	je	@f
56
	je	@f
61
	cmp	[edi + xcf_header.version], 'v001'
57
	cmp	[edi + xcf_header.version], 'v001'
62
	je	@f
58
	je	@f
63
	cmp	[edi + xcf_header.version], 'v002'
59
	cmp	[edi + xcf_header.version], 'v002'
64
	je	@f
60
	je	@f
65
	jmp	.is_not_xcf
61
	jmp	.is_not_xcf
66
    @@:
62
    @@:
67
 
63
 
68
	cmp	byte[edi + xcf_header.reserved], 0
64
	cmp	byte[edi + xcf_header.reserved], 0
69
	jne	.is_not_xcf
65
	jne	.is_not_xcf
70
 
66
 
71
  .is_xcf:
67
  .is_xcf:
72
	inc	eax
68
	inc	eax
73
 
69
 
74
  .is_not_xcf:
70
  .is_not_xcf:
75
	pop	edi
71
	pop	edi
76
	ret
72
	ret
77
endp
73
endp
78
 
74
 
79
 
75
 
80
;;================================================================================================;;
76
;;================================================================================================;;
81
proc img.decode.xcf _data, _length, _options ;////////////////////////////////////////////////////;;
77
proc img.decode.xcf _data, _length, _options ;////////////////////////////////////////////////////;;
82
;;------------------------------------------------------------------------------------------------;;
78
;;------------------------------------------------------------------------------------------------;;
83
;? Decode data into image if it contains correctly formed raw data in xcf format                  ;;
79
;? Decode data into image if it contains correctly formed raw data in xcf format                  ;;
84
;;------------------------------------------------------------------------------------------------;;
80
;;------------------------------------------------------------------------------------------------;;
85
;> _data = raw data as read from file/stream                                                      ;;
81
;> _data = raw data as read from file/stream                                                      ;;
86
;> _length = data length                                                                          ;;
82
;> _length = data length                                                                          ;;
87
;;------------------------------------------------------------------------------------------------;;
83
;;------------------------------------------------------------------------------------------------;;
88
;< eax = 0 (error) or pointer to image                                                            ;;
84
;< eax = 0 (error) or pointer to image                                                            ;;
89
;;================================================================================================;;
85
;;================================================================================================;;
90
locals
86
locals
91
	layer_count	rd	1
87
	layer_count	rd	1
92
	retvalue	rd	1
88
	retvalue	rd	1
93
endl
89
endl
94
 
90
 
95
	push	ebx esi edi
91
	push	ebx esi edi
96
 
92
 
97
	mov	esi, [_data]
93
	mov	esi, [_data]
98
	add	esi, xcf_header.width
94
	add	esi, xcf_header.width
99
 
95
 
100
	lodsd
96
	lodsd
101
	bswap	eax
97
	bswap	eax
102
	mov	ebx, eax
98
	mov	ebx, eax
103
	lodsd
99
	lodsd
104
	bswap	eax
100
	bswap	eax
105
	mov	edx, eax
101
	mov	edx, eax
106
 
102
 
107
	lodsd
103
	lodsd
108
	bswap	eax
104
	bswap	eax
109
	test	eax, eax
105
	test	eax, eax
110
	jz	.process_rgb
106
	jz	.process_rgb
111
	dec	eax
107
	dec	eax
112
	jz	.process_grayscale
108
	jz	.process_grayscale
113
	dec	eax
109
	dec	eax
114
	jz	.process_indexed
110
	jz	.process_indexed
115
	jmp	.error
111
	jmp	.error
116
 
112
 
117
 
113
 
118
  .process_rgb:
114
  .process_rgb:
119
 
115
 
120
	stdcall	img.create, ebx, edx, Image.bpp32
116
	stdcall	img.create, ebx, edx, Image.bpp32
121
	mov	[retvalue], eax
117
	mov	[retvalue], eax
122
	test	eax, eax
118
	test	eax, eax
123
	jz	.error
119
	jz	.error
124
 
120
 
125
	mov	ebx, eax
121
	mov	ebx, eax
126
 
122
 
127
	mov	edx, XCF_BASETYPE_RGB
123
	mov	edx, XCF_BASETYPE_RGB
128
 
124
 
129
	jmp	.common_process
125
	jmp	.common_process
130
 
126
 
131
  .process_grayscale:
127
  .process_grayscale:
132
 
128
 
133
	stdcall	img.create, ebx, edx, Image.bpp8i
129
	stdcall	img.create, ebx, edx, Image.bpp8i
134
	mov	[retvalue], eax
130
	mov	[retvalue], eax
135
	test	eax, eax
131
	test	eax, eax
136
	jz	.error
132
	jz	.error
137
 
133
 
138
	mov	ebx, eax
134
	mov	ebx, eax
139
 
135
 
140
	mov	eax, [ebx + Image.Width]
136
	mov	eax, [ebx + Image.Width]
141
	imul	[ebx + Image.Height]
137
	imul	[ebx + Image.Height]
142
	shl	eax, 1
138
	shl	eax, 1
143
	mov	[ebx + Image.Palette], eax
139
	mov	[ebx + Image.Palette], eax
144
	add	eax, 256*4
140
	add	eax, 256*4
145
	invoke	mem.realloc, [ebx + Image.Data], eax
141
	invoke	mem.realloc, [ebx + Image.Data], eax
146
	mov	[ebx + Image.Data], eax
142
	mov	[ebx + Image.Data], eax
147
	add	[ebx + Image.Palette], eax
143
	add	[ebx + Image.Palette], eax
148
 
144
 
149
	mov	edi, [ebx + Image.Palette]
145
	mov	edi, [ebx + Image.Palette]
150
	mov	eax, 0xff000000
146
	mov	eax, 0xff000000
151
    @@:
147
    @@:
152
	stosd
148
	stosd
153
	add	eax, 0x00010101
149
	add	eax, 0x00010101
154
	jnc	@b
150
	jnc	@b
155
 
151
 
156
	mov	edx, XCF_BASETYPE_GRAY
152
	mov	edx, XCF_BASETYPE_GRAY
157
 
153
 
158
	jmp	.common_process
154
	jmp	.common_process
159
 
155
 
160
 
156
 
161
  .process_indexed:
157
  .process_indexed:
162
 
158
 
163
	stdcall	img.create, ebx, edx, Image.bpp8i
159
	stdcall	img.create, ebx, edx, Image.bpp8i
164
	mov	[retvalue], eax
160
	mov	[retvalue], eax
165
	test	eax, eax
161
	test	eax, eax
166
	jz	.error
162
	jz	.error
167
 
163
 
168
	mov	ebx, eax
164
	mov	ebx, eax
169
 
165
 
170
	mov	eax, [ebx + Image.Width]
166
	mov	eax, [ebx + Image.Width]
171
	imul	[ebx + Image.Height]
167
	imul	[ebx + Image.Height]
172
	shl	eax, 1
168
	shl	eax, 1
173
	mov	[ebx + Image.Palette], eax
169
	mov	[ebx + Image.Palette], eax
174
	add	eax, 256*4
170
	add	eax, 256*4
175
	invoke	mem.realloc, [ebx + Image.Data], eax
171
	invoke	mem.realloc, [ebx + Image.Data], eax
176
	mov	[ebx + Image.Data], eax
172
	mov	[ebx + Image.Data], eax
177
	add	[ebx + Image.Palette], eax
173
	add	[ebx + Image.Palette], eax
178
 
174
 
179
	mov	edx, XCF_BASETYPE_INDEXED
175
	mov	edx, XCF_BASETYPE_INDEXED
180
;	jmp	.common_process
176
;	jmp	.common_process
181
 
177
 
182
  .common_process:
178
  .common_process:
183
 
179
 
184
	invoke	mem.alloc, sizeof.xcf_ext
180
	invoke	mem.alloc, sizeof.xcf_ext
185
	or	eax, eax
181
	or	eax, eax
186
	jz	.error
182
	jz	.error
187
	mov	[ebx + Image.Extended], eax
183
	mov	[ebx + Image.Extended], eax
188
	mov	[eax + xcf_ext.opacity], 0xffffffff
184
	mov	[eax + xcf_ext.opacity], 0xffffffff
189
	mov	[eax + xcf_ext.type], edx
185
	mov	[eax + xcf_ext.type], edx
190
 
186
 
191
	stdcall	xcf._.parse_properties, ebx
187
	stdcall	xcf._.parse_properties, ebx
192
 
188
 
193
	mov	edi, esi
189
	mov	edi, esi
194
	xor	eax, eax
190
	xor	eax, eax
195
	mov	ecx, MAX_LAYERS
191
	mov	ecx, MAX_LAYERS
196
	mov	[layer_count], MAX_LAYERS-1
192
	mov	[layer_count], MAX_LAYERS-1
197
	repne	scasd
193
	repne	scasd
198
	sub	[layer_count], ecx
194
	sub	[layer_count], ecx
199
	mov	esi, edi
195
	mov	esi, edi
200
	xor	ecx, ecx
196
	xor	ecx, ecx
201
 
197
 
202
  .still:
198
  .still:
203
	sub	esi, 8
199
	sub	esi, 8
204
	lodsd
200
	lodsd
205
	bswap	eax
201
	bswap	eax
206
 
202
 
207
	push	ecx
203
	push	ecx
208
	stdcall	xcf._.decode_layer, eax, [_data]
204
	stdcall	xcf._.decode_layer, eax, [_data]
209
	pop	ecx
205
	pop	ecx
210
	test	eax, eax
206
	test	eax, eax
211
	jz	@f
207
	jz	@f
212
	push	ecx
208
	push	ecx
213
	stdcall	xcf._.merge_down, eax, [retvalue], ecx
209
	stdcall	xcf._.merge_down, eax, [retvalue], ecx
214
	pop	ecx
210
	pop	ecx
215
	add	ecx, 1
211
	add	ecx, 1
216
    @@:
212
    @@:
217
	dec	[layer_count]
213
	dec	[layer_count]
218
	jnz	.still
214
	jnz	.still
219
 
215
 
220
	cmp	[ebx + Image.Type], Image.bpp8i
216
	cmp	[ebx + Image.Type], Image.bpp8i
221
	jne	.quit
217
	jne	.quit
222
	stdcall	xcf._.pack_8a, ebx
218
	stdcall	xcf._.pack_8a, ebx
223
	jmp	.quit
219
	jmp	.quit
224
 
220
 
225
  .error:
221
  .error:
226
	mov	[retvalue], 0
222
	mov	[retvalue], 0
227
  .quit:
223
  .quit:
228
	pop	edi esi ebx
224
	pop	edi esi ebx
229
	mov	eax, [retvalue]
225
	mov	eax, [retvalue]
230
	ret
226
	ret
231
endp
227
endp
232
 
228
 
233
 
229
 
234
;;================================================================================================;;
230
;;================================================================================================;;
235
proc img.encode.xcf _img, _p_length, _options ;///////////////////////////////////////////////////;;
231
proc img.encode.xcf _img, _p_length, _options ;///////////////////////////////////////////////////;;
236
;;------------------------------------------------------------------------------------------------;;
232
;;------------------------------------------------------------------------------------------------;;
237
;? Encode image into raw data in xcf format                                                       ;;
233
;? Encode image into raw data in xcf format                                                       ;;
238
;;------------------------------------------------------------------------------------------------;;
234
;;------------------------------------------------------------------------------------------------;;
239
;> _img = pointer to image                                                                        ;;
235
;> _img = pointer to image                                                                        ;;
240
;;------------------------------------------------------------------------------------------------;;
236
;;------------------------------------------------------------------------------------------------;;
241
;< eax = 0 (error) or pointer to encoded data                                                     ;;
237
;< eax = 0 (error) or pointer to encoded data                                                     ;;
242
;< _p_length = encoded data length                                                                ;;
238
;< _p_length = encoded data length                                                                ;;
243
;;================================================================================================;;
239
;;================================================================================================;;
244
	xor	eax, eax
240
	xor	eax, eax
245
	ret
241
	ret
246
endp
242
endp
247
 
243
 
248
 
244
 
249
;;================================================================================================;;
245
;;================================================================================================;;
250
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
246
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
251
;;================================================================================================;;
247
;;================================================================================================;;
252
;! Below are private procs you should never call directly from your code                          ;;
248
;! Below are private procs you should never call directly from your code                          ;;
253
;;================================================================================================;;
249
;;================================================================================================;;
254
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
250
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
255
;;================================================================================================;;
251
;;================================================================================================;;
256
proc	xcf._.parse_properties _img
252
proc	xcf._.parse_properties _img
257
 
253
 
258
	mov	ebx, [_img]
254
	mov	ebx, [_img]
259
  .begin:
255
  .begin:
260
	lodsd
256
	lodsd
261
	bswap	eax
257
	bswap	eax
262
 
258
 
263
	mov	ecx, (xcf._.prop_table_end - xcf._.prop_table_begin)/8
259
	mov	ecx, (xcf._.prop_table_end - xcf._.prop_table_begin)/8
264
	mov	edi, xcf._.prop_table_begin
260
	mov	edi, xcf._.prop_table_begin
265
 
261
 
266
  .still:
262
  .still:
267
	cmp	eax, [edi]
263
	cmp	eax, [edi]
268
	jne	@f
264
	jne	@f
269
	jmp	dword[edi + 4]
265
	jmp	dword[edi + 4]
270
    @@:
266
    @@:
271
	add	edi, 8
267
	add	edi, 8
272
	dec	ecx
268
	dec	ecx
273
	jnz	.still
269
	jnz	.still
274
	lodsd
270
	lodsd
275
	bswap	eax
271
	bswap	eax
276
	add	esi, eax
272
	add	esi, eax
277
	jmp	.begin
273
	jmp	.begin
278
 
274
 
279
  .00:			; PROP_END
275
  .00:			; PROP_END
280
	lodsd
276
	lodsd
281
	ret
277
	ret
282
 
278
 
283
  .01:			; PROP_COLORMAP
279
  .01:			; PROP_COLORMAP
284
	lodsd
280
	lodsd
285
	mov	ecx, [ebx + Image.Extended]
281
	mov	ecx, [ebx + Image.Extended]
286
	cmp	[ecx + xcf_ext.type], XCF_BASETYPE_INDEXED
282
	cmp	[ecx + xcf_ext.type], XCF_BASETYPE_INDEXED
287
	je	@f
283
	je	@f
288
	bswap	eax
284
	bswap	eax
289
	add	esi, eax
285
	add	esi, eax
290
	jmp	xcf._.parse_properties.begin
286
	jmp	xcf._.parse_properties.begin
291
    @@:
287
    @@:
292
	lodsd
288
	lodsd
293
	bswap	eax
289
	bswap	eax
294
	mov	ecx, eax
290
	mov	ecx, eax
295
	mov	edi, [ebx + Image.Palette]
291
	mov	edi, [ebx + Image.Palette]
296
 
292
 
297
    @@:
293
    @@:
298
	lodsd
294
	lodsd
299
	sub	esi, 1
295
	sub	esi, 1
300
	bswap	eax
296
	bswap	eax
301
	shr	eax, 8
297
	shr	eax, 8
302
	or	eax, 0xff000000
298
	or	eax, 0xff000000
303
	stosd
299
	stosd
304
	dec	ecx
300
	dec	ecx
305
	jnz	@b
301
	jnz	@b
306
	jmp	xcf._.parse_properties.begin
302
	jmp	xcf._.parse_properties.begin
307
 
303
 
308
  .06:			; PROP_OPACITY
304
  .06:			; PROP_OPACITY
309
	lodsd
305
	lodsd
310
	lodsd
306
	lodsd
311
	bswap	eax
307
	bswap	eax
312
	mov	ecx, [ebx + Image.Extended]
308
	mov	ecx, [ebx + Image.Extended]
313
	mov	[ecx + xcf_ext.opacity], eax
309
	mov	[ecx + xcf_ext.opacity], eax
314
	jmp	xcf._.parse_properties.begin
310
	jmp	xcf._.parse_properties.begin
315
 
311
 
316
  .07:			; PROP_MODE
312
  .07:			; PROP_MODE
317
	lodsd
313
	lodsd
318
	lodsd
314
	lodsd
319
	bswap	eax
315
	bswap	eax
320
	mov	ecx, [ebx + Image.Extended]
316
	mov	ecx, [ebx + Image.Extended]
321
	mov	[ecx + xcf_ext.layer_mode], eax
317
	mov	[ecx + xcf_ext.layer_mode], eax
322
	jmp	xcf._.parse_properties.begin
318
	jmp	xcf._.parse_properties.begin
323
 
319
 
324
  .08:			; PROP_VISIBLE
320
  .08:			; PROP_VISIBLE
325
	lodsd
321
	lodsd
326
	lodsd
322
	lodsd
327
	bswap	eax
323
	bswap	eax
328
	mov	ecx, [ebx + Image.Extended]
324
	mov	ecx, [ebx + Image.Extended]
329
	mov	[ecx + xcf_ext.visible], eax
325
	mov	[ecx + xcf_ext.visible], eax
330
	jmp	xcf._.parse_properties.begin
326
	jmp	xcf._.parse_properties.begin
331
 
327
 
332
  .11:			; PROP_APPLY_MASK
328
  .11:			; PROP_APPLY_MASK
333
	lodsd
329
	lodsd
334
	lodsd
330
	lodsd
335
	bswap	eax
331
	bswap	eax
336
	mov	ecx, [ebx + Image.Extended]
332
	mov	ecx, [ebx + Image.Extended]
337
	mov	[ecx + xcf_ext.apply_mask], eax
333
	mov	[ecx + xcf_ext.apply_mask], eax
338
	jmp	xcf._.parse_properties.begin
334
	jmp	xcf._.parse_properties.begin
339
 
335
 
340
  .15:			; PROP_OFFSETS
336
  .15:			; PROP_OFFSETS
341
	lodsd
337
	lodsd
342
	lodsd
338
	lodsd
343
	mov	ecx, [ebx + Image.Extended]
339
	mov	ecx, [ebx + Image.Extended]
344
	bswap	eax
340
	bswap	eax
345
	mov	[ecx + xcf_ext.offset_x], eax
341
	mov	[ecx + xcf_ext.offset_x], eax
346
	lodsd
342
	lodsd
347
	bswap	eax
343
	bswap	eax
348
	mov	[ecx + xcf_ext.offset_y], eax
344
	mov	[ecx + xcf_ext.offset_y], eax
349
	jmp	xcf._.parse_properties.begin
345
	jmp	xcf._.parse_properties.begin
350
endp
346
endp
351
 
347
 
352
 
348
 
353
proc	xcf._.decode_channel _channel_begin, _data
349
proc	xcf._.decode_channel _channel_begin, _data
354
locals
350
locals
355
	channel_width		rd	1
351
	channel_width		rd	1
356
	channel_height		rd	1
352
	channel_height		rd	1
357
	planes_todo		rd	1
353
	planes_todo		rd	1
358
	total_bpl		rd	1
354
	total_bpl		rd	1
359
endl
355
endl
360
 
356
 
361
	push	ebx esi edi
357
	push	ebx esi edi
362
	mov	esi, [_channel_begin]
358
	mov	esi, [_channel_begin]
363
	add	esi, [_data]
359
	add	esi, [_data]
364
	lodsd
360
	lodsd
365
	bswap	eax
361
	bswap	eax
366
	mov	[channel_width], eax
362
	mov	[channel_width], eax
367
	mov	[total_bpl], eax
363
	mov	[total_bpl], eax
368
	lodsd
364
	lodsd
369
	bswap	eax
365
	bswap	eax
370
	mov	[channel_height], eax
366
	mov	[channel_height], eax
371
	lodsd
367
	lodsd
372
	bswap	eax
368
	bswap	eax
373
	add	esi, eax
369
	add	esi, eax
374
 
370
 
375
	stdcall	img.create, [channel_width], [channel_height], Image.bpp8i
371
	stdcall	img.create, [channel_width], [channel_height], Image.bpp8i
376
	mov	ebx, eax
372
	mov	ebx, eax
377
	test	ebx, ebx
373
	test	ebx, ebx
378
	jz	.quit
374
	jz	.quit
379
	invoke	mem.alloc, sizeof.xcf_ext
375
	invoke	mem.alloc, sizeof.xcf_ext
380
	or	eax, eax
376
	or	eax, eax
381
	jz	.error
377
	jz	.error
382
	mov	[ebx + Image.Extended], eax
378
	mov	[ebx + Image.Extended], eax
383
 
379
 
384
	stdcall	xcf._.parse_properties, ebx
380
	stdcall	xcf._.parse_properties, ebx
385
 
381
 
386
	lodsd
382
	lodsd
387
	bswap	eax
383
	bswap	eax
388
	mov	esi, eax
384
	mov	esi, eax
389
	add	esi, [_data]
385
	add	esi, [_data]
390
	lodsd
386
	lodsd
391
	lodsd
387
	lodsd
392
	lodsd
388
	lodsd
393
	bswap	eax
389
	bswap	eax
394
	mov	[planes_todo], eax
390
	mov	[planes_todo], eax
395
	lodsd
391
	lodsd
396
	bswap	eax
392
	bswap	eax
397
	mov	esi, eax
393
	mov	esi, eax
398
	add	esi, [_data]
394
	add	esi, [_data]
399
	lodsd
395
	lodsd
400
	lodsd
396
	lodsd
401
 
397
 
402
	mov	edi, [ebx + Image.Data]
398
	mov	edi, [ebx + Image.Data]
403
	mov	ecx, 0
399
	mov	ecx, 0
404
    @@:
400
    @@:
405
	lodsd
401
	lodsd
406
	test	eax, eax
402
	test	eax, eax
407
	jz	.quit
403
	jz	.quit
408
	bswap	eax
404
	bswap	eax
409
	add	eax, [_data]
405
	add	eax, [_data]
410
	stdcall	xcf._.decode_tile, eax, [channel_width], [channel_height], [total_bpl], [planes_todo], 1
406
	stdcall	xcf._.decode_tile, eax, [channel_width], [channel_height], [total_bpl], [planes_todo], 1
411
	add	ecx, 1
407
	add	ecx, 1
412
	jmp	@b
408
	jmp	@b
413
 
409
 
414
  .error:
410
  .error:
415
	stdcall	img.destroy, ebx
411
	stdcall	img.destroy, ebx
416
	mov	ebx, 0
412
	mov	ebx, 0
417
  .quit:
413
  .quit:
418
	mov	eax, ebx
414
	mov	eax, ebx
419
	pop	edi esi ebx
415
	pop	edi esi ebx
420
	ret
416
	ret
421
endp
417
endp
422
 
418
 
423
 
419
 
424
proc	xcf._.decode_layer _layer_begin, _data
420
proc	xcf._.decode_layer _layer_begin, _data
425
locals
421
locals
426
	layer_width		rd	1
422
	layer_width		rd	1
427
	layer_height		rd	1
423
	layer_height		rd	1
428
	planes_todo		rd	1
424
	planes_todo		rd	1
429
	total_bpl		rd	1
425
	total_bpl		rd	1
430
	color_step		rd	1
426
	color_step		rd	1
431
endl
427
endl
432
 
428
 
433
	push	ebx esi edi
429
	push	ebx esi edi
434
	mov	esi, [_layer_begin]
430
	mov	esi, [_layer_begin]
435
	add	esi, [_data]
431
	add	esi, [_data]
436
	lodsd
432
	lodsd
437
	bswap	eax
433
	bswap	eax
438
	mov	[layer_width], eax
434
	mov	[layer_width], eax
439
	mov	[total_bpl], eax
435
	mov	[total_bpl], eax
440
	shl	[total_bpl], 1
436
	shl	[total_bpl], 1
441
	lodsd
437
	lodsd
442
	bswap	eax
438
	bswap	eax
443
	mov	[layer_height], eax
439
	mov	[layer_height], eax
444
	lodsd
440
	lodsd
445
	bswap	eax
441
	bswap	eax
446
	mov	edx, Image.bpp8a
442
	mov	edx, Image.bpp8a
447
	mov	[color_step], 1
443
	mov	[color_step], 1
448
	cmp	eax, 2
444
	cmp	eax, 2
449
	jge	@f
445
	jge	@f
450
	mov	[color_step], 3
446
	mov	[color_step], 3
451
	mov	edx, Image.bpp32
447
	mov	edx, Image.bpp32
452
	shl	[total_bpl], 1
448
	shl	[total_bpl], 1
453
    @@:
449
    @@:
454
	stdcall	img.create, [layer_width], [layer_height], edx
450
	stdcall	img.create, [layer_width], [layer_height], edx
455
	mov	ebx, eax
451
	mov	ebx, eax
456
	test	ebx, ebx
452
	test	ebx, ebx
457
	jz	.quit
453
	jz	.quit
458
	invoke	mem.alloc, sizeof.xcf_ext
454
	invoke	mem.alloc, sizeof.xcf_ext
459
	or	eax, eax
455
	or	eax, eax
460
	jz	.error
456
	jz	.error
461
	mov	[ebx + Image.Extended], eax
457
	mov	[ebx + Image.Extended], eax
462
 
458
 
463
	lodsd
459
	lodsd
464
	bswap	eax
460
	bswap	eax
465
	add	esi, eax
461
	add	esi, eax
466
	stdcall	xcf._.parse_properties, ebx
462
	stdcall	xcf._.parse_properties, ebx
467
	mov	edx, [ebx + Image.Extended]
463
	mov	edx, [ebx + Image.Extended]
468
	or	[edx + xcf_ext.visible], 0
464
	or	[edx + xcf_ext.visible], 0
469
	jz	.unvisible
465
	jz	.unvisible
470
 
466
 
471
	lodsd
467
	lodsd
472
	bswap	eax
468
	bswap	eax
473
	push	esi
469
	push	esi
474
	mov	esi, eax
470
	mov	esi, eax
475
	add	esi, [_data]
471
	add	esi, [_data]
476
	lodsd
472
	lodsd
477
	lodsd
473
	lodsd
478
	lodsd
474
	lodsd
479
	bswap	eax
475
	bswap	eax
480
	mov	[planes_todo], eax
476
	mov	[planes_todo], eax
481
;	mov	ecx, [ebx + Image.Extended]
477
;	mov	ecx, [ebx + Image.Extended]
482
;	mov	[ecx + xcf_ext.planes], eax
478
;	mov	[ecx + xcf_ext.planes], eax
483
	lodsd
479
	lodsd
484
	bswap	eax
480
	bswap	eax
485
	mov	esi, eax
481
	mov	esi, eax
486
	add	esi, [_data]
482
	add	esi, [_data]
487
	lodsd
483
	lodsd
488
	lodsd
484
	lodsd
489
 
485
 
490
	mov	edi, [ebx + Image.Data]
486
	mov	edi, [ebx + Image.Data]
491
	mov	ecx, 0
487
	mov	ecx, 0
492
    @@:
488
    @@:
493
	lodsd
489
	lodsd
494
	test	eax, eax
490
	test	eax, eax
495
	jz	@f
491
	jz	@f
496
	bswap	eax
492
	bswap	eax
497
	add	eax, [_data]
493
	add	eax, [_data]
498
	stdcall	xcf._.decode_tile, eax, [layer_width], [layer_height], [total_bpl], [planes_todo], 0
494
	stdcall	xcf._.decode_tile, eax, [layer_width], [layer_height], [total_bpl], [planes_todo], 0
499
	add	ecx, 1
495
	add	ecx, 1
500
	jmp	@b
496
	jmp	@b
501
    @@:
497
    @@:
502
 
498
 
503
	stdcall	xcf._.apply_opacity, ebx, [color_step]
499
	stdcall	xcf._.apply_opacity, ebx, [color_step]
504
 
500
 
505
	pop	esi
501
	pop	esi
506
	lodsd
502
	lodsd
507
	bswap	eax
503
	bswap	eax
508
	test	eax, eax
504
	test	eax, eax
509
	jz	.quit
505
	jz	.quit
510
 
506
 
511
	stdcall	xcf._.decode_channel, eax, [_data]
507
	stdcall	xcf._.decode_channel, eax, [_data]
512
	test	eax, eax
508
	test	eax, eax
513
	jz	.error
509
	jz	.error
514
 
510
 
515
	mov	edx, [ebx + Image.Extended]
511
	mov	edx, [ebx + Image.Extended]
516
	cmp	[edx + xcf_ext.apply_mask], 0
512
	cmp	[edx + xcf_ext.apply_mask], 0
517
	je	.quit
513
	je	.quit
518
 
514
 
519
	stdcall	xcf._.apply_alpha_mask, ebx, eax, [color_step]
515
	stdcall	xcf._.apply_alpha_mask, ebx, eax, [color_step]
520
	jmp	.quit
516
	jmp	.quit
521
 
517
 
522
  .unvisible:
518
  .unvisible:
523
  .error:
519
  .error:
524
	stdcall	img.destroy, ebx
520
	stdcall	img.destroy, ebx
525
	mov	ebx, 0
521
	mov	ebx, 0
526
  .quit:
522
  .quit:
527
	mov	eax, ebx
523
	mov	eax, ebx
528
	pop	edi esi ebx
524
	pop	edi esi ebx
529
	ret
525
	ret
530
endp
526
endp
531
 
527
 
532
 
528
 
533
proc	xcf._.decode_tile _tile_data, _width, _height, _total_bpl, _bytes_pp, _is_channel
529
proc	xcf._.decode_tile _tile_data, _width, _height, _total_bpl, _bytes_pp, _is_channel
534
locals
530
locals
535
	tile_x			rd	1
531
	tile_x			rd	1
536
	tile_y			rd	1
532
	tile_y			rd	1
537
	tile_width		rd	1
533
	tile_width		rd	1
538
	tile_height		rd	1
534
	tile_height		rd	1
539
	planes_todo		rd	1
535
	planes_todo		rd	1
540
	color_step		rd	1
536
	color_step		rd	1
541
endl
537
endl
542
 
538
 
543
	push	ebx ecx edx esi edi
539
	push	ebx ecx edx esi edi
544
	pushd	[_bytes_pp]
540
	pushd	[_bytes_pp]
545
	popd	[planes_todo]
541
	popd	[planes_todo]
546
 
542
 
547
	cmp	[_is_channel], 1
543
	cmp	[_is_channel], 1
548
	je	@f
544
	je	@f
549
	test	[_bytes_pp], 0x01
545
	test	[_bytes_pp], 0x01
550
	jz	@f
546
	jz	@f
551
	add	[_bytes_pp], 1
547
	add	[_bytes_pp], 1
552
    @@:
548
    @@:
553
	mov	ebx, [_bytes_pp]
549
	mov	ebx, [_bytes_pp]
554
	sub	ebx, 1
550
	sub	ebx, 1
555
	mov	[color_step], ebx
551
	mov	[color_step], ebx
556
 
552
 
557
	mov	esi, [_tile_data]
553
	mov	esi, [_tile_data]
558
	mov	eax, ecx
554
	mov	eax, ecx
559
	mov	ebx, [_width]
555
	mov	ebx, [_width]
560
	dec	ebx
556
	dec	ebx
561
	shr	ebx, 6
557
	shr	ebx, 6
562
	inc	ebx
558
	inc	ebx
563
	mov	edx, 0
559
	mov	edx, 0
564
	div	bx
560
	div	bx
565
	mov	[tile_x], edx
561
	mov	[tile_x], edx
566
	mov	[tile_y], eax
562
	mov	[tile_y], eax
567
 
563
 
568
	mov	[tile_width], 64
564
	mov	[tile_width], 64
569
	mov	ebx, [_width]
565
	mov	ebx, [_width]
570
	test	ebx, 0x0000003F
566
	test	ebx, 0x0000003F
571
	jz	@f
567
	jz	@f
572
	dec	ebx
568
	dec	ebx
573
	shr	ebx, 6
569
	shr	ebx, 6
574
	cmp	ebx, [tile_x]
570
	cmp	ebx, [tile_x]
575
	jne	@f
571
	jne	@f
576
	mov	ebx, [_width]
572
	mov	ebx, [_width]
577
	and	ebx, 0x0000003F
573
	and	ebx, 0x0000003F
578
	mov	[tile_width], ebx
574
	mov	[tile_width], ebx
579
    @@:
575
    @@:
580
 
576
 
581
	mov	[tile_height], 64
577
	mov	[tile_height], 64
582
	mov	ebx, [_height]
578
	mov	ebx, [_height]
583
	test	ebx, 0x0000003F
579
	test	ebx, 0x0000003F
584
	jz	@f
580
	jz	@f
585
	dec	ebx
581
	dec	ebx
586
	shr	ebx, 6
582
	shr	ebx, 6
587
	cmp	ebx, [tile_y]
583
	cmp	ebx, [tile_y]
588
	jne	@f
584
	jne	@f
589
	mov	ebx, [_height]
585
	mov	ebx, [_height]
590
	and	ebx, 0x0000003F
586
	and	ebx, 0x0000003F
591
	mov	[tile_height], ebx
587
	mov	[tile_height], ebx
592
    @@:
588
    @@:
593
 
589
 
594
 
590
 
595
	mov	eax, [_total_bpl]
591
	mov	eax, [_total_bpl]
596
	shl	eax, 6
592
	shl	eax, 6
597
	mul	[tile_y]
593
	mul	[tile_y]
598
	add	edi, eax
594
	add	edi, eax
599
 
595
 
600
	mov	eax, [tile_x]
596
	mov	eax, [tile_x]
601
	shl	eax, 6
597
	shl	eax, 6
602
	imul	eax, [_bytes_pp]
598
	imul	eax, [_bytes_pp]
603
	add	edi, eax
599
	add	edi, eax
604
 
600
 
605
	cmp	[_is_channel], 1
601
	cmp	[_is_channel], 1
606
	jne	@f
602
	jne	@f
607
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
603
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
608
	jmp	.quit
604
	jmp	.quit
609
    @@:
605
    @@:
610
	mov	eax, [planes_todo]
606
	mov	eax, [planes_todo]
611
	dec	eax
607
	dec	eax
612
	jz	.p1
608
	jz	.p1
613
	dec	eax
609
	dec	eax
614
	jz	.p2
610
	jz	.p2
615
	dec	eax
611
	dec	eax
616
	jz	.p3
612
	jz	.p3
617
	jmp	.p4
613
	jmp	.p4
618
  .p1:
614
  .p1:
619
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
615
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
620
	add	edi, 1
616
	add	edi, 1
621
	stdcall	xcf._.fill_color, [tile_width], [tile_height], [_total_bpl], [_bytes_pp], [color_step]
617
	stdcall	xcf._.fill_color, [tile_width], [tile_height], [_total_bpl], [_bytes_pp], [color_step]
622
	jmp	.quit
618
	jmp	.quit
623
  .p2:
619
  .p2:
624
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
620
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
625
	add	edi, 1
621
	add	edi, 1
626
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
622
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
627
	jmp	.quit
623
	jmp	.quit
628
  .p3:
624
  .p3:
629
	add	edi, 2
625
	add	edi, 2
630
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
626
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
631
	sub	edi, 1
627
	sub	edi, 1
632
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
628
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
633
	sub	edi, 1
629
	sub	edi, 1
634
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
630
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
635
	add	edi, 3
631
	add	edi, 3
636
	stdcall	xcf._.fill_color, [tile_width], [tile_height], [_total_bpl], [_bytes_pp], [color_step]
632
	stdcall	xcf._.fill_color, [tile_width], [tile_height], [_total_bpl], [_bytes_pp], [color_step]
637
	jmp	.quit
633
	jmp	.quit
638
  .p4:
634
  .p4:
639
	add	edi, 2
635
	add	edi, 2
640
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
636
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
641
	sub	edi, 1
637
	sub	edi, 1
642
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
638
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
643
	sub	edi, 1
639
	sub	edi, 1
644
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
640
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
645
	add	edi, 3
641
	add	edi, 3
646
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
642
	stdcall	xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
647
;	jmp	.quit
643
;	jmp	.quit
648
 
644
 
649
  .quit:
645
  .quit:
650
	pop	edi esi edx ecx ebx
646
	pop	edi esi edx ecx ebx
651
	ret
647
	ret
652
endp
648
endp
653
 
649
 
654
 
650
 
655
proc	xcf._.fill_color _tile_width, _tile_height, _total_bpl, _bytes_pp, _color_step
651
proc	xcf._.fill_color _tile_width, _tile_height, _total_bpl, _bytes_pp, _color_step
656
	push	ebx
652
	push	ebx
657
	mov	edx, [_color_step]
653
	mov	edx, [_color_step]
658
	mov	ebx, [_total_bpl]
654
	mov	ebx, [_total_bpl]
659
	mov	eax, [_bytes_pp]
655
	mov	eax, [_bytes_pp]
660
	mul	byte[_tile_width]
656
	mul	byte[_tile_width]
661
	sub	ebx, eax
657
	sub	ebx, eax
662
 
658
 
663
	mov	ch, byte[_tile_height]
659
	mov	ch, byte[_tile_height]
664
	mov	al, 0xff
660
	mov	al, 0xff
665
  .line:
661
  .line:
666
	mov	cl, byte[_tile_width]
662
	mov	cl, byte[_tile_width]
667
    @@:
663
    @@:
668
	stosb
664
	stosb
669
	add	edi, edx
665
	add	edi, edx
670
	dec	cl
666
	dec	cl
671
	jnz	@b
667
	jnz	@b
672
	add	edi, ebx
668
	add	edi, ebx
673
	dec	ch
669
	dec	ch
674
	jnz	.line
670
	jnz	.line
675
	pop	ebx
671
	pop	ebx
676
	ret
672
	ret
677
endp
673
endp
678
 
674
 
679
 
675
 
680
proc	xcf._.decode_color _tile_width, _tile_height, _color_step, _total_bpl, _bytes_pp
676
proc	xcf._.decode_color _tile_width, _tile_height, _color_step, _total_bpl, _bytes_pp
681
locals
677
locals
682
	level_width		rd	1
678
	level_width		rd	1
683
	level_height		rd	1
679
	level_height		rd	1
684
	line_step		rd	1	; [_total_bpl] - [_tile_width]*[_bytes_pp]
680
	line_step		rd	1	; [_total_bpl] - [_tile_width]*[_bytes_pp]
685
endl
681
endl
686
 
682
 
687
	push	edi
683
	push	edi
688
 
684
 
689
	mov	ebx, [_total_bpl]
685
	mov	ebx, [_total_bpl]
690
	movzx	eax, byte[_bytes_pp]
686
	movzx	eax, byte[_bytes_pp]
691
	mul	byte[_tile_width]
687
	mul	byte[_tile_width]
692
	sub	ebx, eax
688
	sub	ebx, eax
693
	mov	[line_step], ebx
689
	mov	[line_step], ebx
694
	mov	ebx, [_tile_height]
690
	mov	ebx, [_tile_height]
695
	mov	edx, [_tile_width]
691
	mov	edx, [_tile_width]
696
 
692
 
697
  .decode:
693
  .decode:
698
	lodsb
694
	lodsb
699
	cmp	al, 127
695
	cmp	al, 127
700
	je	.long_identical
696
	je	.long_identical
701
	jb	.short_identical
697
	jb	.short_identical
702
	test	al, 0x7f
698
	test	al, 0x7f
703
	jz	.long_different
699
	jz	.long_different
704
	jmp	.short_different
700
	jmp	.short_different
705
 
701
 
706
  .short_identical:
702
  .short_identical:
707
	movzx	ecx, al
703
	movzx	ecx, al
708
	add	ecx, 1
704
	add	ecx, 1
709
	lodsb
705
	lodsb
710
	jmp	.step1
706
	jmp	.step1
711
  .long_identical:
707
  .long_identical:
712
	mov	ecx, 0
708
	mov	ecx, 0
713
	lodsw
709
	lodsw
714
	mov	cx, ax
710
	mov	cx, ax
715
	xchg	cl, ch
711
	xchg	cl, ch
716
	lodsb
712
	lodsb
717
  .step1:
713
  .step1:
718
	cmp	cx, dx
714
	cmp	cx, dx
719
	je	.step2
715
	je	.step2
720
	jl	.step3
716
	jl	.step3
721
	xchg	cx, dx
717
	xchg	cx, dx
722
	sub	dx, cx
718
	sub	dx, cx
723
	sub	bx, 1
719
	sub	bx, 1
724
    @@:
720
    @@:
725
	stosb
721
	stosb
726
	add	edi, [_color_step]
722
	add	edi, [_color_step]
727
	loop	@b
723
	loop	@b
728
	mov	cx, dx
724
	mov	cx, dx
729
	mov	edx, [_tile_width]
725
	mov	edx, [_tile_width]
730
	add	edi, [line_step]
726
	add	edi, [line_step]
731
	jmp	.step1
727
	jmp	.step1
732
 
728
 
733
  .step2:
729
  .step2:
734
    @@:
730
    @@:
735
	stosb
731
	stosb
736
	add	edi, [_color_step]
732
	add	edi, [_color_step]
737
	loop	@b
733
	loop	@b
738
	mov	edx, [_tile_width]
734
	mov	edx, [_tile_width]
739
	add	edi, [line_step]
735
	add	edi, [line_step]
740
	dec	bx
736
	dec	bx
741
	jz	.quit
737
	jz	.quit
742
	jmp	.decode
738
	jmp	.decode
743
  .step3:
739
  .step3:
744
	sub	dx, cx
740
	sub	dx, cx
745
    @@:
741
    @@:
746
	stosb
742
	stosb
747
	add	edi, [_color_step]
743
	add	edi, [_color_step]
748
	loop	@b
744
	loop	@b
749
	jmp	.decode
745
	jmp	.decode
750
 
746
 
751
 
747
 
752
  .short_different:
748
  .short_different:
753
	movzx	ecx, al
749
	movzx	ecx, al
754
	neg	cx
750
	neg	cx
755
	add	cx, 256
751
	add	cx, 256
756
	jmp	.step4
752
	jmp	.step4
757
  .long_different:
753
  .long_different:
758
	mov	ecx, 0
754
	mov	ecx, 0
759
	lodsb
755
	lodsb
760
	mov	ch, al
756
	mov	ch, al
761
	lodsb
757
	lodsb
762
	mov	cl, al
758
	mov	cl, al
763
  .step4:
759
  .step4:
764
	cmp	cx, dx
760
	cmp	cx, dx
765
	je	.step5
761
	je	.step5
766
	jl	.step6
762
	jl	.step6
767
	xchg	cx, dx
763
	xchg	cx, dx
768
	sub	dx, cx
764
	sub	dx, cx
769
	sub	bx, 1
765
	sub	bx, 1
770
    @@:
766
    @@:
771
	movsb
767
	movsb
772
	add	edi, [_color_step]
768
	add	edi, [_color_step]
773
	loop	@b
769
	loop	@b
774
	mov	cx, dx
770
	mov	cx, dx
775
	mov	edx, [_tile_width]
771
	mov	edx, [_tile_width]
776
	add	edi, [line_step]
772
	add	edi, [line_step]
777
	jmp	.step4
773
	jmp	.step4
778
 
774
 
779
  .step5:
775
  .step5:
780
    @@:
776
    @@:
781
	movsb
777
	movsb
782
	add	edi, [_color_step]
778
	add	edi, [_color_step]
783
	loop	@b
779
	loop	@b
784
	mov	edx, [_tile_width]
780
	mov	edx, [_tile_width]
785
	add	edi, [line_step]
781
	add	edi, [line_step]
786
	dec	bx
782
	dec	bx
787
	jz	.quit
783
	jz	.quit
788
	jmp	.decode
784
	jmp	.decode
789
 
785
 
790
  .step6:
786
  .step6:
791
	sub	dx, cx
787
	sub	dx, cx
792
    @@:
788
    @@:
793
	movsb
789
	movsb
794
	add	edi, [_color_step]
790
	add	edi, [_color_step]
795
	loop	@b
791
	loop	@b
796
	jmp	.decode
792
	jmp	.decode
797
 
793
 
798
  .quit:
794
  .quit:
799
	pop	edi
795
	pop	edi
800
	ret
796
	ret
801
endp
797
endp
802
 
798
 
803
 
799
 
804
proc	xcf._.merge_down _img, _bottom, _layer_number
800
proc	xcf._.merge_down _img, _bottom, _layer_number
805
locals
801
locals
806
	copy_width		rd	1
802
	copy_width		rd	1
807
	copy_height		rd	1
803
	copy_height		rd	1
808
	img_x1			rd	1
804
	img_x1			rd	1
809
	img_y1			rd	1
805
	img_y1			rd	1
810
	bottom_x1		rd	1
806
	bottom_x1		rd	1
811
	bottom_y1		rd	1
807
	bottom_y1		rd	1
812
	img_total_bpl		rd	1
808
	img_total_bpl		rd	1
813
	bottom_total_bpl	rd	1
809
	bottom_total_bpl	rd	1
814
	img_length		rd	1
810
	img_length		rd	1
815
	bottom_length		rd	1
811
	bottom_length		rd	1
816
endl
812
endl
817
	push	ebx esi edi
813
	push	ebx esi edi
818
 
814
 
819
	mov	ebx, [_bottom]
815
	mov	ebx, [_bottom]
820
	mov	edx, [_img]
816
	mov	edx, [_img]
821
 
817
 
822
	mov	[img_x1], 0
818
	mov	[img_x1], 0
823
	push	[edx + Image.Width]
819
	push	[edx + Image.Width]
824
	pop	[img_length]
820
	pop	[img_length]
825
 
821
 
826
	mov	[bottom_x1], 0
822
	mov	[bottom_x1], 0
827
	mov	ecx, [ebx + Image.Width]
823
	mov	ecx, [ebx + Image.Width]
828
	mov	[bottom_length], ecx        
824
	mov	[bottom_length], ecx        
829
 
825
 
830
	mov	eax, [edx + Image.Extended]
826
	mov	eax, [edx + Image.Extended]
831
	movsx	eax, word[eax + xcf_ext.offset_x]
827
	movsx	eax, word[eax + xcf_ext.offset_x]
832
	cmp	eax, 0
828
	cmp	eax, 0
833
	jg	.greater_x
829
	jg	.greater_x
834
	jl	.lesser_x
830
	jl	.lesser_x
835
	mov	[copy_width], ecx
831
	mov	[copy_width], ecx
836
	jmp	.done_x
832
	jmp	.done_x
837
  .greater_x:
833
  .greater_x:
838
	add	[bottom_x1], eax
834
	add	[bottom_x1], eax
839
	sub	[bottom_length], eax
835
	sub	[bottom_length], eax
840
	jns	.label_x
836
	jns	.label_x
841
	mov	[copy_width], 0
837
	mov	[copy_width], 0
842
	jmp	.done_x
838
	jmp	.done_x
843
  .lesser_x:
839
  .lesser_x:
844
	sub	[img_x1], eax
840
	sub	[img_x1], eax
845
	add	[img_length], eax
841
	add	[img_length], eax
846
	jns	.label_x
842
	jns	.label_x
847
	mov	[copy_width], 0
843
	mov	[copy_width], 0
848
	jmp	.done_x
844
	jmp	.done_x
849
  .label_x:
845
  .label_x:
850
	mov	ecx, [img_length]
846
	mov	ecx, [img_length]
851
	cmp	ecx, [bottom_length]
847
	cmp	ecx, [bottom_length]
852
	jng	@f
848
	jng	@f
853
	mov	ecx, [bottom_length]
849
	mov	ecx, [bottom_length]
854
    @@:
850
    @@:
855
	mov	[copy_width], ecx
851
	mov	[copy_width], ecx
856
  .done_x:
852
  .done_x:
857
 
853
 
858
 
854
 
859
	mov	[img_y1], 0
855
	mov	[img_y1], 0
860
	push	[edx + Image.Height]
856
	push	[edx + Image.Height]
861
	pop	[img_length]
857
	pop	[img_length]
862
 
858
 
863
	mov	[bottom_y1], 0
859
	mov	[bottom_y1], 0
864
	mov	ecx, [ebx + Image.Height]
860
	mov	ecx, [ebx + Image.Height]
865
	mov	[bottom_length], ecx        
861
	mov	[bottom_length], ecx        
866
 
862
 
867
	mov	eax, [edx + Image.Extended]
863
	mov	eax, [edx + Image.Extended]
868
	movsx	eax, word[eax + xcf_ext.offset_y]
864
	movsx	eax, word[eax + xcf_ext.offset_y]
869
	cmp	eax, 0
865
	cmp	eax, 0
870
	jg	.greater_y
866
	jg	.greater_y
871
	jl	.lesser_y
867
	jl	.lesser_y
872
	mov	[copy_height], ecx
868
	mov	[copy_height], ecx
873
	jmp	.done_y
869
	jmp	.done_y
874
  .greater_y:
870
  .greater_y:
875
	add	[bottom_y1], eax
871
	add	[bottom_y1], eax
876
	sub	[bottom_length], eax
872
	sub	[bottom_length], eax
877
	jns	.label_y
873
	jns	.label_y
878
	mov	[copy_height], 0
874
	mov	[copy_height], 0
879
	jmp	.done_y
875
	jmp	.done_y
880
  .lesser_y:
876
  .lesser_y:
881
	sub	[img_y1], eax
877
	sub	[img_y1], eax
882
	add	[img_length], eax
878
	add	[img_length], eax
883
	jns	.label_y
879
	jns	.label_y
884
	mov	[copy_height], 0
880
	mov	[copy_height], 0
885
	jmp	.done_y
881
	jmp	.done_y
886
  .label_y:
882
  .label_y:
887
	mov	ecx, [img_length]
883
	mov	ecx, [img_length]
888
	cmp	ecx, [bottom_length]
884
	cmp	ecx, [bottom_length]
889
	jng	@f
885
	jng	@f
890
	mov	ecx, [bottom_length]
886
	mov	ecx, [bottom_length]
891
    @@:
887
    @@:
892
	mov	[copy_height], ecx
888
	mov	[copy_height], ecx
893
  .done_y:
889
  .done_y:
894
 
890
 
895
	mov	esi, [edx + Image.Data]
891
	mov	esi, [edx + Image.Data]
896
	mov	edi, [ebx + Image.Data]
892
	mov	edi, [ebx + Image.Data]
897
 
893
 
898
	mov	eax, [edx + Image.Width]
894
	mov	eax, [edx + Image.Width]
899
	imul	eax, [img_y1]
895
	imul	eax, [img_y1]
900
	add	eax, [img_x1]
896
	add	eax, [img_x1]
901
	shl	eax, 1
897
	shl	eax, 1
902
	cmp	[edx + Image.Width], Image.bpp8a
898
	cmp	[edx + Image.Width], Image.bpp8a
903
	je	@f
899
	je	@f
904
	shl	eax, 1
900
	shl	eax, 1
905
    @@:
901
    @@:
906
	add	esi, eax
902
	add	esi, eax
907
 
903
 
908
	mov	eax, [ebx + Image.Width]
904
	mov	eax, [ebx + Image.Width]
909
	imul	eax, [bottom_y1]
905
	imul	eax, [bottom_y1]
910
	add	eax, [bottom_x1]
906
	add	eax, [bottom_x1]
911
	shl	eax, 1
907
	shl	eax, 1
912
	cmp	[ebx + Image.Width], Image.bpp8i
908
	cmp	[ebx + Image.Width], Image.bpp8i
913
	je	@f
909
	je	@f
914
	shl	eax, 1
910
	shl	eax, 1
915
    @@:
911
    @@:
916
	add	edi, eax
912
	add	edi, eax
917
 
913
 
918
 
914
 
919
	mov	eax, [edx + Image.Width]
915
	mov	eax, [edx + Image.Width]
920
	sub	eax, [copy_width]
916
	sub	eax, [copy_width]
921
	shl	eax, 1
917
	shl	eax, 1
922
	cmp	[edx + Image.Width], Image.bpp8a
918
	cmp	[edx + Image.Width], Image.bpp8a
923
	je	@f
919
	je	@f
924
	shl	eax, 1
920
	shl	eax, 1
925
    @@:
921
    @@:
926
	mov	[img_total_bpl], eax
922
	mov	[img_total_bpl], eax
927
 
923
 
928
	mov	eax, [ebx + Image.Width]
924
	mov	eax, [ebx + Image.Width]
929
	sub	eax, [copy_width]
925
	sub	eax, [copy_width]
930
	shl	eax, 1
926
	shl	eax, 1
931
	cmp	[ebx + Image.Width], Image.bpp8i
927
	cmp	[ebx + Image.Width], Image.bpp8i
932
	je	@f
928
	je	@f
933
	shl	eax, 1
929
	shl	eax, 1
934
    @@:
930
    @@:
935
	mov	[bottom_total_bpl], eax
931
	mov	[bottom_total_bpl], eax
936
 
932
 
937
	cmp	[_layer_number], 0
933
	cmp	[_layer_number], 0
938
	jne	.not_first
934
	jne	.not_first
939
	mov	ecx, [copy_width]
935
	mov	ecx, [copy_width]
940
	imul	ecx, [copy_height]
936
	imul	ecx, [copy_height]
941
	cmp	[ebx + Image.Type], Image.bpp8i
937
	cmp	[ebx + Image.Type], Image.bpp8i
942
	je	.bpp8a
938
	je	.bpp8a
943
  .bpp32:
939
  .bpp32:
944
	rep	movsd
940
	rep	movsd
945
	jmp	.done
941
	jmp	.done
946
  .bpp8a:
942
  .bpp8a:
947
	rep	movsw
943
	rep	movsw
948
	jmp	.done
944
	jmp	.done
949
  .not_first:
945
  .not_first:
950
 
946
 
951
	push	edi
947
	push	edi
952
	mov	ecx, [edx + Image.Extended]
948
	mov	ecx, [edx + Image.Extended]
953
	mov	eax, [ecx + xcf_ext.layer_mode]
949
	mov	eax, [ecx + xcf_ext.layer_mode]
954
 
950
 
955
	mov	ecx, [ebx + Image.Extended]
951
	mov	ecx, [ebx + Image.Extended]
956
	mov	ecx, [ecx + xcf_ext.type]
952
	mov	ecx, [ecx + xcf_ext.type]
957
 
953
 
958
	cmp	ecx, XCF_BASETYPE_RGB
954
	cmp	ecx, XCF_BASETYPE_RGB
959
	jne	@f
955
	jne	@f
960
	mov	edx, 4
956
	mov	edx, 4
961
	jmp	.type_defined
957
	jmp	.type_defined
962
    @@:
958
    @@:
963
	cmp	ecx, XCF_BASETYPE_GRAY
959
	cmp	ecx, XCF_BASETYPE_GRAY
964
	jne	@f
960
	jne	@f
965
	mov	edx, 8
961
	mov	edx, 8
966
	jmp	.type_defined
962
	jmp	.type_defined
967
    @@:
963
    @@:
968
	mov	edx, 12
964
	mov	edx, 12
969
  .type_defined:
965
  .type_defined:
970
	mov	ecx, (xcf._.composite_table.end - xcf._.composite_table.begin) / 8
966
	mov	ecx, (xcf._.composite_table.end - xcf._.composite_table.begin) / 8
971
	mov	edi, xcf._.composite_table.begin
967
	mov	edi, xcf._.composite_table.begin
972
 
968
 
973
  .still:
969
  .still:
974
	cmp	eax, [edi]
970
	cmp	eax, [edi]
975
	jne	@f
971
	jne	@f
976
	add	edi, edx
972
	add	edi, edx
977
	mov	edx, [edi]
973
	mov	edx, [edi]
978
	jmp	.composite_found
974
	jmp	.composite_found
979
    @@: 
975
    @@: 
980
	add	edi, 16
976
	add	edi, 16
981
	dec	ecx
977
	dec	ecx
982
	jnz	.still
978
	jnz	.still
983
 
979
 
984
  .composite_found:
980
  .composite_found:
985
	pop	edi
981
	pop	edi
986
 
982
 
987
	mov	ecx, [ebx + Image.Extended]
983
	mov	ecx, [ebx + Image.Extended]
988
	cmp	[ecx + xcf_ext.type], XCF_BASETYPE_INDEXED
984
	cmp	[ecx + xcf_ext.type], XCF_BASETYPE_INDEXED
989
	jne	@f
985
	jne	@f
990
	stdcall	edx, [copy_width], [copy_height], [bottom_total_bpl], [img_total_bpl]
986
	stdcall	edx, [copy_width], [copy_height], [bottom_total_bpl], [img_total_bpl]
991
	jmp	.done
987
	jmp	.done
992
    @@:
988
    @@:
993
	cmp	eax, 1
989
	cmp	eax, 1
994
	ja	@f
990
	ja	@f
995
	stdcall	edx, [copy_width], [copy_height], [bottom_total_bpl], [img_total_bpl]
991
	stdcall	edx, [copy_width], [copy_height], [bottom_total_bpl], [img_total_bpl]
996
	jmp	.done
992
	jmp	.done
997
    @@:
993
    @@:
998
 
994
 
999
 
995
 
1000
	cmp	[ebx + Image.Type], Image.bpp8i
996
	cmp	[ebx + Image.Type], Image.bpp8i
1001
	jne	@f
997
	jne	@f
1002
	stdcall	xcf._.merge_8a, [copy_width], [copy_height], [img_total_bpl], [bottom_total_bpl]
998
	stdcall	xcf._.merge_8a, [copy_width], [copy_height], [img_total_bpl], [bottom_total_bpl]
1003
	jmp	.done
999
	jmp	.done
1004
    @@:
1000
    @@:
1005
	stdcall	xcf._.merge_32, [copy_width], [copy_height], [img_total_bpl], [bottom_total_bpl]
1001
	stdcall	xcf._.merge_32, [copy_width], [copy_height], [img_total_bpl], [bottom_total_bpl]
1006
;	jmp	.done
1002
;	jmp	.done
1007
  .done:
1003
  .done:
1008
	stdcall	img.destroy, [_img]
1004
	stdcall	img.destroy, [_img]
1009
	pop	edi esi ebx
1005
	pop	edi esi ebx
1010
	ret
1006
	ret
1011
endp
1007
endp
1012
 
1008
 
1013
 
1009
 
1014
proc	xcf._.pack_8a _img
1010
proc	xcf._.pack_8a _img
1015
	mov	ebx, [_img]
1011
	mov	ebx, [_img]
1016
	mov	esi, [ebx + Image.Data]
1012
	mov	esi, [ebx + Image.Data]
1017
	mov	edi, esi
1013
	mov	edi, esi
1018
	mov	ecx, [ebx + Image.Width]
1014
	mov	ecx, [ebx + Image.Width]
1019
	imul	ecx, [ebx + Image.Height]
1015
	imul	ecx, [ebx + Image.Height]
1020
    @@:
1016
    @@:
1021
	lodsw
1017
	lodsw
1022
	stosb
1018
	stosb
1023
	dec	ecx
1019
	dec	ecx
1024
	jnz	@b
1020
	jnz	@b
1025
	ret
1021
	ret
1026
endp
1022
endp
1027
 
1023
 
1028
 
1024
 
1029
proc	xcf._.apply_opacity _img, _color_step
1025
proc	xcf._.apply_opacity _img, _color_step
1030
 
1026
 
1031
	push	ebx
1027
	push	ebx
1032
 
1028
 
1033
	mov	edx, [ebx + Image.Extended]
1029
	mov	edx, [ebx + Image.Extended]
1034
	mov	edx, [edx + xcf_ext.opacity]
1030
	mov	edx, [edx + xcf_ext.opacity]
1035
	cmp	dl, 0xff
1031
	cmp	dl, 0xff
1036
	je	.quit
1032
	je	.quit
1037
 
1033
 
1038
	mov	ecx, [ebx + Image.Width]
1034
	mov	ecx, [ebx + Image.Width]
1039
	imul	ecx, [ebx + Image.Height]
1035
	imul	ecx, [ebx + Image.Height]
1040
	mov	esi, [ebx + Image.Data]
1036
	mov	esi, [ebx + Image.Data]
1041
	mov	ebx, [_color_step]
1037
	mov	ebx, [_color_step]
1042
	add	esi, ebx
1038
	add	esi, ebx
1043
	mov	edi, esi
1039
	mov	edi, esi
1044
    @@:
1040
    @@:
1045
	lodsb
1041
	lodsb
1046
	mul	dl
1042
	mul	dl
1047
	shr	ax, 8
1043
	shr	ax, 8
1048
	stosb
1044
	stosb
1049
	add	esi, ebx
1045
	add	esi, ebx
1050
	add	edi, ebx
1046
	add	edi, ebx
1051
	dec	ecx
1047
	dec	ecx
1052
	jnz	@b
1048
	jnz	@b
1053
 
1049
 
1054
  .quit:
1050
  .quit:
1055
	pop	ebx
1051
	pop	ebx
1056
	ret
1052
	ret
1057
endp
1053
endp
1058
 
1054
 
1059
 
1055
 
1060
proc	xcf._.apply_alpha_mask _img, _mask, _color_step
1056
proc	xcf._.apply_alpha_mask _img, _mask, _color_step
1061
 
1057
 
1062
	push	ebx
1058
	push	ebx
1063
 
1059
 
1064
	mov	ebx, [_img]
1060
	mov	ebx, [_img]
1065
	mov	esi, [_mask]
1061
	mov	esi, [_mask]
1066
	mov	esi, [esi + Image.Data]
1062
	mov	esi, [esi + Image.Data]
1067
	mov	edi, [ebx + Image.Data]
1063
	mov	edi, [ebx + Image.Data]
1068
	mov	ecx, [ebx + Image.Width]
1064
	mov	ecx, [ebx + Image.Width]
1069
	imul	ecx, [ebx + Image.Height]
1065
	imul	ecx, [ebx + Image.Height]
1070
	mov	ebx, [_color_step]
1066
	mov	ebx, [_color_step]
1071
	add	edi, ebx
1067
	add	edi, ebx
1072
    @@:
1068
    @@:
1073
	lodsb
1069
	lodsb
1074
	mul	byte[edi]
1070
	mul	byte[edi]
1075
	shr	ax, 8
1071
	shr	ax, 8
1076
	stosb
1072
	stosb
1077
	add	edi, ebx
1073
	add	edi, ebx
1078
	dec	ecx
1074
	dec	ecx
1079
	jnz	@b
1075
	jnz	@b
1080
 
1076
 
1081
	stdcall	img.destroy, [_mask]
1077
	stdcall	img.destroy, [_mask]
1082
	pop	ebx
1078
	pop	ebx
1083
	ret
1079
	ret
1084
endp
1080
endp
1085
 
1081
 
1086
 
1082
 
1087
;;================================================================================================;;
1083
;;================================================================================================;;
1088
proc	xcf._.rgb2hsv ;///////////////////////////////////////////////////////////////////////////;;
1084
proc	xcf._.rgb2hsv ;///////////////////////////////////////////////////////////////////////////;;
1089
;;------------------------------------------------------------------------------------------------;;
1085
;;------------------------------------------------------------------------------------------------;;
1090
;? convert color from RGB to HSV space                                                            ;;
1086
;? convert color from RGB to HSV space                                                            ;;
1091
;;------------------------------------------------------------------------------------------------;;
1087
;;------------------------------------------------------------------------------------------------;;
1092
;> eax = color (0xAARRGGBB)                                                                       ;;
1088
;> eax = color (0xAARRGGBB)                                                                       ;;
1093
;;------------------------------------------------------------------------------------------------;;
1089
;;------------------------------------------------------------------------------------------------;;
1094
;< eax = color (0xAAHHSSVV)                                                                       ;;
1090
;< eax = color (0xAAHHSSVV)                                                                       ;;
1095
;;================================================================================================;;
1091
;;================================================================================================;;
1096
locals
1092
locals
1097
	vsha		rd	1
1093
	vsha		rd	1
1098
	max		rd	1
1094
	max		rd	1
1099
	min		rd	1
1095
	min		rd	1
1100
	med		rd	1
1096
	med		rd	1
1101
endl
1097
endl
1102
	push	ebx ecx edx
1098
	push	ebx ecx edx
1103
 
1099
 
1104
	mov	[vsha], eax
1100
	mov	[vsha], eax
1105
	movzx	eax, byte[vsha]		; eax = al = blue
1101
	movzx	eax, byte[vsha]		; eax = al = blue
1106
	movzx	ecx, byte[vsha+1]	; ecx = cl = green
1102
	movzx	ecx, byte[vsha+1]	; ecx = cl = green
1107
	movzx	edx, byte[vsha+2]	; edx = dl = red
1103
	movzx	edx, byte[vsha+2]	; edx = dl = red
1108
 
1104
 
1109
	cmp	al, cl
1105
	cmp	al, cl
1110
	jne	@f
1106
	jne	@f
1111
	cmp	al, dl
1107
	cmp	al, dl
1112
	jne	@f
1108
	jne	@f
1113
	ror	eax, 8
1109
	ror	eax, 8
1114
	mov	ax, 0
1110
	mov	ax, 0
1115
	rol	eax, 8
1111
	rol	eax, 8
1116
	jmp	.quit
1112
	jmp	.quit
1117
 
1113
 
1118
    @@:
1114
    @@:
1119
	cmp	dl, cl
1115
	cmp	dl, cl
1120
	ja	@f
1116
	ja	@f
1121
	cmp	dl, al
1117
	cmp	dl, al
1122
	ja	@f
1118
	ja	@f
1123
	mov	byte[min], dl
1119
	mov	byte[min], dl
1124
	jmp	.min_found
1120
	jmp	.min_found
1125
    @@:
1121
    @@:
1126
	cmp	cl, al
1122
	cmp	cl, al
1127
	ja	@f
1123
	ja	@f
1128
	cmp	cl, dl
1124
	cmp	cl, dl
1129
	ja	@f
1125
	ja	@f
1130
	mov	byte[min], cl
1126
	mov	byte[min], cl
1131
	jmp	.min_found
1127
	jmp	.min_found
1132
    @@:
1128
    @@:
1133
	mov	byte[min], al
1129
	mov	byte[min], al
1134
;	jmp	.min_found
1130
;	jmp	.min_found
1135
  .min_found:
1131
  .min_found:
1136
 
1132
 
1137
	cmp	dl, cl
1133
	cmp	dl, cl
1138
	jb	@f
1134
	jb	@f
1139
	cmp	dl, al
1135
	cmp	dl, al
1140
	jb	@f
1136
	jb	@f
1141
	mov	byte[max], dl
1137
	mov	byte[max], dl
1142
	sub	cx, ax
1138
	sub	cx, ax
1143
	mov	dx, cx
1139
	mov	dx, cx
1144
	mov	cx, 0
1140
	mov	cx, 0
1145
	jmp	.max_found
1141
	jmp	.max_found
1146
    @@:
1142
    @@:
1147
	cmp	cl, al
1143
	cmp	cl, al
1148
	jb	@f
1144
	jb	@f
1149
	cmp	cl, dl
1145
	cmp	cl, dl
1150
	jb	@f
1146
	jb	@f
1151
	mov	byte[max], cl
1147
	mov	byte[max], cl
1152
	sub	ax, dx
1148
	sub	ax, dx
1153
	mov	dx, ax
1149
	mov	dx, ax
1154
	mov	cx, 85
1150
	mov	cx, 85
1155
	jmp	.max_found
1151
	jmp	.max_found
1156
    @@:
1152
    @@:
1157
	mov	byte[max], al
1153
	mov	byte[max], al
1158
	sub	dx, cx
1154
	sub	dx, cx
1159
	mov	cx, 171
1155
	mov	cx, 171
1160
;	jmp	.max_found
1156
;	jmp	.max_found
1161
  .max_found:
1157
  .max_found:
1162
 
1158
 
1163
	mov	al, byte[max]
1159
	mov	al, byte[max]
1164
	sub	al, byte[min]
1160
	sub	al, byte[min]
1165
	mov	byte[med], al
1161
	mov	byte[med], al
1166
 
1162
 
1167
 
1163
 
1168
	imul	dx, 43
1164
	imul	dx, 43
1169
	movsx	eax, dx
1165
	movsx	eax, dx
1170
	ror	eax, 16
1166
	ror	eax, 16
1171
	mov	dx, ax
1167
	mov	dx, ax
1172
	rol	eax, 16
1168
	rol	eax, 16
1173
	mov	byte[med + 1], 0
1169
	mov	byte[med + 1], 0
1174
	idiv	word[med]
1170
	idiv	word[med]
1175
	add	al, cl
1171
	add	al, cl
1176
	mov	byte[vsha + 2], al
1172
	mov	byte[vsha + 2], al
1177
 
1173
 
1178
	mov	al, byte[max]
1174
	mov	al, byte[max]
1179
	mov	byte[vsha], al
1175
	mov	byte[vsha], al
1180
 
1176
 
1181
	mov	byte[vsha + 1], 0
1177
	mov	byte[vsha + 1], 0
1182
	test	al, al
1178
	test	al, al
1183
	jz	@f
1179
	jz	@f
1184
	mov	byte[vsha + 1], 0xff
1180
	mov	byte[vsha + 1], 0xff
1185
	cmp	al, byte[med]
1181
	cmp	al, byte[med]
1186
	je	@f
1182
	je	@f
1187
	mov	al, byte[med]
1183
	mov	al, byte[med]
1188
	shl	ax, 8
1184
	shl	ax, 8
1189
	div	byte[max]
1185
	div	byte[max]
1190
	mov	byte[vsha + 1], al
1186
	mov	byte[vsha + 1], al
1191
    @@:
1187
    @@:
1192
	mov	eax, [vsha]
1188
	mov	eax, [vsha]
1193
 
1189
 
1194
  .quit:
1190
  .quit:
1195
	pop	edx ecx ebx
1191
	pop	edx ecx ebx
1196
	ret
1192
	ret
1197
endp
1193
endp
1198
 
1194
 
1199
 
1195
 
1200
;;================================================================================================;;
1196
;;================================================================================================;;
1201
proc	xcf._.hsv2rgb ;///////////////////////////////////////////////////////////////////////////;;
1197
proc	xcf._.hsv2rgb ;///////////////////////////////////////////////////////////////////////////;;
1202
;;------------------------------------------------------------------------------------------------;;
1198
;;------------------------------------------------------------------------------------------------;;
1203
;? convert color from HSV to RGB space                                                            ;;
1199
;? convert color from HSV to RGB space                                                            ;;
1204
;;------------------------------------------------------------------------------------------------;;
1200
;;------------------------------------------------------------------------------------------------;;
1205
;> eax = color (0xAAHHSSVV)                                                                       ;;
1201
;> eax = color (0xAAHHSSVV)                                                                       ;;
1206
;;------------------------------------------------------------------------------------------------;;
1202
;;------------------------------------------------------------------------------------------------;;
1207
;< eax = color (0xAARRGGBB)                                                                       ;;
1203
;< eax = color (0xAARRGGBB)                                                                       ;;
1208
;;================================================================================================;;
1204
;;================================================================================================;;
1209
locals
1205
locals
1210
	vsha	rd	1
1206
	vsha	rd	1
1211
	f	rb	1
1207
	f	rb	1
1212
	c	rb	1
1208
	c	rb	1
1213
	x	rb	1
1209
	x	rb	1
1214
endl
1210
endl
1215
 
1211
 
1216
	push	ebx ecx edx
1212
	push	ebx ecx edx
1217
 
1213
 
1218
 
1214
 
1219
	mov	[vsha], eax
1215
	mov	[vsha], eax
1220
	mov	bl, byte[vsha + 1]
1216
	mov	bl, byte[vsha + 1]
1221
	mul	bl
1217
	mul	bl
1222
	mov	byte[c], ah
1218
	mov	byte[c], ah
1223
 
1219
 
1224
	movzx	eax, byte[vsha + 2]
1220
	movzx	eax, byte[vsha + 2]
1225
	cmp	eax, 43
1221
	cmp	eax, 43
1226
	ja	@f
1222
	ja	@f
1227
	lea	eax, [eax*3]
1223
	lea	eax, [eax*3]
1228
	shl	eax, 1
1224
	shl	eax, 1
1229
	mov	ebx, eax
1225
	mov	ebx, eax
1230
	shr	ebx, 7
1226
	shr	ebx, 7
1231
	sub	eax, ebx
1227
	sub	eax, ebx
1232
	shr	ebx, 1
1228
	shr	ebx, 1
1233
	sub	eax, ebx
1229
	sub	eax, ebx
1234
	jmp	.ok
1230
	jmp	.ok
1235
 
1231
 
1236
    @@:
1232
    @@:
1237
	cmp	eax, 86
1233
	cmp	eax, 86
1238
	ja	@f
1234
	ja	@f
1239
	sub	eax, 44
1235
	sub	eax, 44
1240
	lea	eax, [eax*3]
1236
	lea	eax, [eax*3]
1241
	shl	eax, 1
1237
	shl	eax, 1
1242
	neg	al
1238
	neg	al
1243
	add	al, 0xff
1239
	add	al, 0xff
1244
	jmp	.ok
1240
	jmp	.ok
1245
 
1241
 
1246
    @@:
1242
    @@:
1247
	cmp	eax, 129
1243
	cmp	eax, 129
1248
	ja	@f
1244
	ja	@f
1249
	sub	eax, 87
1245
	sub	eax, 87
1250
	lea	eax, [eax*3]
1246
	lea	eax, [eax*3]
1251
	shl	eax, 1
1247
	shl	eax, 1
1252
	jmp	.ok
1248
	jmp	.ok
1253
 
1249
 
1254
    @@:
1250
    @@:
1255
	cmp	eax, 171
1251
	cmp	eax, 171
1256
	ja	@f
1252
	ja	@f
1257
	sub	eax, 130
1253
	sub	eax, 130
1258
	lea	eax, [eax*3]
1254
	lea	eax, [eax*3]
1259
	shl	eax, 1
1255
	shl	eax, 1
1260
	neg	al
1256
	neg	al
1261
	add	al, 0xff
1257
	add	al, 0xff
1262
	jmp	.ok
1258
	jmp	.ok
1263
 
1259
 
1264
    @@:
1260
    @@:
1265
	cmp	eax, 214
1261
	cmp	eax, 214
1266
	ja	@f
1262
	ja	@f
1267
	sub	eax, 172
1263
	sub	eax, 172
1268
	lea	eax, [eax*3]
1264
	lea	eax, [eax*3]
1269
	shl	eax, 1
1265
	shl	eax, 1
1270
	jmp	.ok
1266
	jmp	.ok
1271
    @@:
1267
    @@:
1272
	sub	eax, 215
1268
	sub	eax, 215
1273
	lea	eax, [eax*3]
1269
	lea	eax, [eax*3]
1274
	shl	eax, 1
1270
	shl	eax, 1
1275
	neg	al
1271
	neg	al
1276
	add	al, 0xff
1272
	add	al, 0xff
1277
;	jmp	.ok
1273
;	jmp	.ok
1278
  .ok:
1274
  .ok:
1279
 
1275
 
1280
	neg	al
1276
	neg	al
1281
	add	al, 0xff
1277
	add	al, 0xff
1282
	neg	al
1278
	neg	al
1283
	add	al, 0xff
1279
	add	al, 0xff
1284
;	shr	ax, 8
1280
;	shr	ax, 8
1285
	mul	byte[c]
1281
	mul	byte[c]
1286
	mov	byte[x], ah
1282
	mov	byte[x], ah
1287
 
1283
 
1288
 
1284
 
1289
 
1285
 
1290
	mov	al, byte[vsha+2]
1286
	mov	al, byte[vsha+2]
1291
	cmp	al, 43
1287
	cmp	al, 43
1292
	jae	@f
1288
	jae	@f
1293
	mov	eax, [vsha]
1289
	mov	eax, [vsha]
1294
	shr	eax, 8
1290
	shr	eax, 8
1295
	mov	ah, byte[c]
1291
	mov	ah, byte[c]
1296
	shl	eax, 8
1292
	shl	eax, 8
1297
	mov	ah, byte[x]
1293
	mov	ah, byte[x]
1298
	mov	al, 0
1294
	mov	al, 0
1299
	jmp	.done
1295
	jmp	.done
1300
 
1296
 
1301
    @@:
1297
    @@:
1302
	cmp	al, 86
1298
	cmp	al, 86
1303
	jae	@f
1299
	jae	@f
1304
	mov	eax, [vsha]
1300
	mov	eax, [vsha]
1305
	shr	eax, 8
1301
	shr	eax, 8
1306
	mov	ah, byte[x]
1302
	mov	ah, byte[x]
1307
	shl	eax, 8
1303
	shl	eax, 8
1308
	mov	ah, byte[c]
1304
	mov	ah, byte[c]
1309
	mov	al, 0
1305
	mov	al, 0
1310
	jmp	.done
1306
	jmp	.done
1311
 
1307
 
1312
    @@:
1308
    @@:
1313
	cmp	al, 129
1309
	cmp	al, 129
1314
	jae	@f
1310
	jae	@f
1315
	mov	eax, [vsha]
1311
	mov	eax, [vsha]
1316
	shr	eax, 8
1312
	shr	eax, 8
1317
	mov	ah, 0
1313
	mov	ah, 0
1318
	shl	eax, 8
1314
	shl	eax, 8
1319
	mov	ah, byte[c]
1315
	mov	ah, byte[c]
1320
	mov	al, byte[x]
1316
	mov	al, byte[x]
1321
	jmp	.done
1317
	jmp	.done
1322
 
1318
 
1323
    @@:
1319
    @@:
1324
	cmp	al, 171
1320
	cmp	al, 171
1325
	jae	@f
1321
	jae	@f
1326
	mov	eax, [vsha]
1322
	mov	eax, [vsha]
1327
	shr	eax, 8
1323
	shr	eax, 8
1328
	mov	ah, 0
1324
	mov	ah, 0
1329
	shl	eax, 8
1325
	shl	eax, 8
1330
	mov	ah, byte[x]
1326
	mov	ah, byte[x]
1331
	mov	al, byte[c]
1327
	mov	al, byte[c]
1332
	jmp	.done
1328
	jmp	.done
1333
 
1329
 
1334
    @@:
1330
    @@:
1335
	cmp	al, 214
1331
	cmp	al, 214
1336
	jae	@f
1332
	jae	@f
1337
	mov	eax, [vsha]
1333
	mov	eax, [vsha]
1338
	shr	eax, 8
1334
	shr	eax, 8
1339
	mov	ah, byte[x]
1335
	mov	ah, byte[x]
1340
	shl	eax, 8
1336
	shl	eax, 8
1341
	mov	ah, 0
1337
	mov	ah, 0
1342
	mov	al, byte[c]
1338
	mov	al, byte[c]
1343
	jmp	.done
1339
	jmp	.done
1344
 
1340
 
1345
    @@:
1341
    @@:
1346
	mov	eax, [vsha]
1342
	mov	eax, [vsha]
1347
	shr	eax, 8
1343
	shr	eax, 8
1348
	mov	ah, byte[c]
1344
	mov	ah, byte[c]
1349
	shl	eax, 8
1345
	shl	eax, 8
1350
	mov	ah, 0
1346
	mov	ah, 0
1351
	mov	al, byte[x]
1347
	mov	al, byte[x]
1352
;	jmp	.done
1348
;	jmp	.done
1353
 
1349
 
1354
  .done:
1350
  .done:
1355
	mov	bl, byte[vsha]
1351
	mov	bl, byte[vsha]
1356
	sub	bl, byte[c]
1352
	sub	bl, byte[c]
1357
	ror	eax, 8
1353
	ror	eax, 8
1358
	add	ah, bl
1354
	add	ah, bl
1359
	rol	eax, 8
1355
	rol	eax, 8
1360
	add	ah, bl
1356
	add	ah, bl
1361
	add	al, bl
1357
	add	al, bl
1362
 
1358
 
1363
  .quit:
1359
  .quit:
1364
	pop	edx ecx ebx
1360
	pop	edx ecx ebx
1365
	ret
1361
	ret
1366
endp
1362
endp
1367
 
1363
 
1368
 
1364
 
1369
;;================================================================================================;;
1365
;;================================================================================================;;
1370
proc	xcf._.rgb2hsl ;///////////////////////////////////////////////////////////////////////////;;
1366
proc	xcf._.rgb2hsl ;///////////////////////////////////////////////////////////////////////////;;
1371
;;------------------------------------------------------------------------------------------------;;
1367
;;------------------------------------------------------------------------------------------------;;
1372
;? convert color from RGB to HSL space                                                            ;;
1368
;? convert color from RGB to HSL space                                                            ;;
1373
;;------------------------------------------------------------------------------------------------;;
1369
;;------------------------------------------------------------------------------------------------;;
1374
;> eax = color (0xAARRGGBB)                                                                       ;;
1370
;> eax = color (0xAARRGGBB)                                                                       ;;
1375
;;------------------------------------------------------------------------------------------------;;
1371
;;------------------------------------------------------------------------------------------------;;
1376
;< eax = color (0xAAHHSSLL)                                                                       ;;
1372
;< eax = color (0xAAHHSSLL)                                                                       ;;
1377
;;================================================================================================;;
1373
;;================================================================================================;;
1378
; http://www.asmcommunity.net/board/index.php?topic=7425
1374
; http://www.asmcommunity.net/board/index.php?topic=7425
1379
; iblis: "I don't know what X-Filez is, but yes you may use it however you wish.  That's why I made this post, to share."
1375
; iblis: "I don't know what X-Filez is, but yes you may use it however you wish.  That's why I made this post, to share."
1380
; so pixel_rgb2hsl procedure is based on code by Greg Hoyer (iblis). thanks!
1376
; so pixel_rgb2hsl procedure is based on code by Greg Hoyer (iblis). thanks!
1381
;--------------------------------------------------------------;
1377
;--------------------------------------------------------------;
1382
; By Greg Hoyer aka "Iblis"                                    ;
1378
; By Greg Hoyer aka "Iblis"                                    ;
1383
;                                                              ;
1379
;                                                              ;
1384
; RGB2HSL converts a COLORREF  oriented dword filled with 8bit ;
1380
; RGB2HSL converts a COLORREF  oriented dword filled with 8bit ;
1385
; Red/Green/Blue  values  (00ggbbrr) to  a similarly  oriented ;
1381
; Red/Green/Blue  values  (00ggbbrr) to  a similarly  oriented ;
1386
; dword filled with Hue/Saturation/Luminance values (00llsshh) ;
1382
; dword filled with Hue/Saturation/Luminance values (00llsshh) ;
1387
; This procedure  returns the  full range,  from 0-255.   This ;
1383
; This procedure  returns the  full range,  from 0-255.   This ;
1388
; offers slightly more  precision over Windows' "color picker" ;
1384
; offers slightly more  precision over Windows' "color picker" ;
1389
; common dialog, which displays HSL values ranging from 0-240. ;
1385
; common dialog, which displays HSL values ranging from 0-240. ;
1390
;                                                              ;
1386
;                                                              ;
1391
; It is important to note  that true HSL  values are  normally ;
1387
; It is important to note  that true HSL  values are  normally ;
1392
; represented as  floating point  fractions from  0.0 to  1.0. ;
1388
; represented as  floating point  fractions from  0.0 to  1.0. ;
1393
; As such, this  algorithm cannot  be used to  do the precise, ;
1389
; As such, this  algorithm cannot  be used to  do the precise, ;
1394
; consistent conversions  that may  be required  by heavy-duty ;
1390
; consistent conversions  that may  be required  by heavy-duty ;
1395
; graphics  applications.  To  get the  decimal  fraction  for ;
1391
; graphics  applications.  To  get the  decimal  fraction  for ;
1396
; the  returned values,  convert  the Hue,  Saturation, and/or ;
1392
; the  returned values,  convert  the Hue,  Saturation, and/or ;
1397
; Luminance values to floating  point, and then divide by 255. ;
1393
; Luminance values to floating  point, and then divide by 255. ;
1398
;--------------------------------------------------------------;
1394
;--------------------------------------------------------------;
1399
locals
1395
locals
1400
	bgra	rd	1
1396
	bgra	rd	1
1401
endl
1397
endl
1402
	push	ebx esi edi
1398
	push	ebx esi edi
1403
 
1399
 
1404
	mov	[bgra], eax
1400
	mov	[bgra], eax
1405
 
1401
 
1406
	movzx	esi, byte[bgra + 0]
1402
	movzx	esi, byte[bgra + 0]
1407
	movzx	edi, byte[bgra + 1]
1403
	movzx	edi, byte[bgra + 1]
1408
        movzx   ebx, byte[bgra + 2]
1404
        movzx   ebx, byte[bgra + 2]
1409
	mov	cl, -1
1405
	mov	cl, -1
1410
	cmp	esi, edi
1406
	cmp	esi, edi
1411
	ja	.cmp1
1407
	ja	.cmp1
1412
	xchg	esi, edi
1408
	xchg	esi, edi
1413
	neg	cl
1409
	neg	cl
1414
	shl	cl, 1
1410
	shl	cl, 1
1415
  .cmp1:
1411
  .cmp1:
1416
	cmp	edi, ebx
1412
	cmp	edi, ebx
1417
	jb	.cmp2
1413
	jb	.cmp2
1418
	xchg	edi, ebx
1414
	xchg	edi, ebx
1419
	neg	cl
1415
	neg	cl
1420
  .cmp2:
1416
  .cmp2:
1421
	cmp	esi, ebx
1417
	cmp	esi, ebx
1422
	ja	.cmp3
1418
	ja	.cmp3
1423
	xchg	esi, ebx
1419
	xchg	esi, ebx
1424
	not	cl
1420
	not	cl
1425
  .cmp3:
1421
  .cmp3:
1426
	neg	ebx
1422
	neg	ebx
1427
	add	ebx, esi
1423
	add	ebx, esi
1428
	mov	eax, edi
1424
	mov	eax, edi
1429
	add	edi, esi
1425
	add	edi, esi
1430
	jz	.done
1426
	jz	.done
1431
	sub	esi, eax
1427
	sub	esi, eax
1432
	jz	.done
1428
	jz	.done
1433
	mov	eax, esi
1429
	mov	eax, esi
1434
	shl	eax, 8
1430
	shl	eax, 8
1435
	sub	eax, esi
1431
	sub	eax, esi
1436
	push	edi
1432
	push	edi
1437
	cmp	edi, 0xff
1433
	cmp	edi, 0xff
1438
	jbe	.csat
1434
	jbe	.csat
1439
	neg	edi
1435
	neg	edi
1440
	add	edi, 510
1436
	add	edi, 510
1441
  .csat:
1437
  .csat:
1442
	xor	edx, edx
1438
	xor	edx, edx
1443
	div	edi
1439
	div	edi
1444
	pop      edi
1440
	pop      edi
1445
	shr	edi, 1
1441
	shr	edi, 1
1446
	shl	eax, 8
1442
	shl	eax, 8
1447
	or	edi, eax
1443
	or	edi, eax
1448
	add	cl, 3
1444
	add	cl, 3
1449
	jnc	.noneg
1445
	jnc	.noneg
1450
	neg	ebx
1446
	neg	ebx
1451
  .noneg:
1447
  .noneg:
1452
	shl	cl, 2
1448
	shl	cl, 2
1453
	mov	eax, 0x13135db9
1449
	mov	eax, 0x13135db9
1454
	shr	eax, cl
1450
	shr	eax, cl
1455
	and	eax, 7
1451
	and	eax, 7
1456
	mul	esi
1452
	mul	esi
1457
	add	eax, ebx
1453
	add	eax, ebx
1458
	mov	ebx, eax
1454
	mov	ebx, eax
1459
	shl	eax, 8
1455
	shl	eax, 8
1460
	sub	eax, ebx
1456
	sub	eax, ebx
1461
	mov	ebx, esi
1457
	mov	ebx, esi
1462
	shl	esi, 1
1458
	shl	esi, 1
1463
	lea	ebx, [ebx*4 + esi]
1459
	lea	ebx, [ebx*4 + esi]
1464
	xor	edx, edx
1460
	xor	edx, edx
1465
	div	ebx
1461
	div	ebx
1466
	shl	eax, 16
1462
	shl	eax, 16
1467
	or	eax, edi
1463
	or	eax, edi
1468
  .done:
1464
  .done:
1469
	bswap	eax
1465
	bswap	eax
1470
	shr	eax, 8
1466
	shr	eax, 8
1471
 
1467
 
1472
	mov	bl, byte[bgra + 3]
1468
	mov	bl, byte[bgra + 3]
1473
	bswap	eax
1469
	bswap	eax
1474
	mov	al, bl
1470
	mov	al, bl
1475
	ror	eax, 8
1471
	ror	eax, 8
1476
 
1472
 
1477
 
1473
 
1478
	pop	edi esi ebx
1474
	pop	edi esi ebx
1479
	ret
1475
	ret
1480
endp
1476
endp
1481
 
1477
 
1482
 
1478
 
1483
;;================================================================================================;;
1479
;;================================================================================================;;
1484
proc	xcf._.hsl2rgb ;///////////////////////////////////////////////////////////////////////////;;
1480
proc	xcf._.hsl2rgb ;///////////////////////////////////////////////////////////////////////////;;
1485
;;------------------------------------------------------------------------------------------------;;
1481
;;------------------------------------------------------------------------------------------------;;
1486
;? convert color from HSL to RGB space                                                            ;;
1482
;? convert color from HSL to RGB space                                                            ;;
1487
;;------------------------------------------------------------------------------------------------;;
1483
;;------------------------------------------------------------------------------------------------;;
1488
;> eax = color (0xAAHHSSLL)                                                                       ;;
1484
;> eax = color (0xAAHHSSLL)                                                                       ;;
1489
;;------------------------------------------------------------------------------------------------;;
1485
;;------------------------------------------------------------------------------------------------;;
1490
;< eax = color (0xAARRGGBB)                                                                       ;;
1486
;< eax = color (0xAARRGGBB)                                                                       ;;
1491
;;================================================================================================;;
1487
;;================================================================================================;;
1492
; http://www.asmcommunity.net/board/index.php?topic=7425
1488
; http://www.asmcommunity.net/board/index.php?topic=7425
1493
; iblis: "I don't know what X-Filez is, but yes you may use it however you wish.  That's why I made this post, to share."
1489
; iblis: "I don't know what X-Filez is, but yes you may use it however you wish.  That's why I made this post, to share."
1494
; so pixel_hsl2rgb procedure is based on code by Greg Hoyer (iblis). thanks!
1490
; so pixel_hsl2rgb procedure is based on code by Greg Hoyer (iblis). thanks!
1495
;--------------------------------------------------------------;
1491
;--------------------------------------------------------------;
1496
; By Greg Hoyer aka "Iblis"                                    ;
1492
; By Greg Hoyer aka "Iblis"                                    ;
1497
;                                                              ;
1493
;                                                              ;
1498
; HSL2RGB  does  the  opposite  of  RGB2HSL.   It  converts  a ;
1494
; HSL2RGB  does  the  opposite  of  RGB2HSL.   It  converts  a ;
1499
; Hue/Saturation/Luminance  (00llsshh)  dword  back  into  its ;
1495
; Hue/Saturation/Luminance  (00llsshh)  dword  back  into  its ;
1500
; corresponding  RGB  COLORREF  (00bbggrr).  This  function is ;
1496
; corresponding  RGB  COLORREF  (00bbggrr).  This  function is ;
1501
; intented  to be  used exclusively  with RGB2HSL  (see above) ;
1497
; intented  to be  used exclusively  with RGB2HSL  (see above) ;
1502
;                                                              ;
1498
;                                                              ;
1503
; If  you're  using  this for  your own  custom  color-chooser ;
1499
; If  you're  using  this for  your own  custom  color-chooser ;
1504
; dialog, remember that the  values are in the range of 0-255. ;
1500
; dialog, remember that the  values are in the range of 0-255. ;
1505
; If you MUST emulate the Windows'  color-chooser, convert HSL ;
1501
; If you MUST emulate the Windows'  color-chooser, convert HSL ;
1506
; values this way before you display them:                     ;
1502
; values this way before you display them:                     ;
1507
;                                                              ;
1503
;                                                              ;
1508
; display_value = ( x * 240 ) / 255                            ;
1504
; display_value = ( x * 240 ) / 255                            ;
1509
;                                                              ;
1505
;                                                              ;
1510
; ...where x represents any one of the HSL values.             ;
1506
; ...where x represents any one of the HSL values.             ;
1511
;--------------------------------------------------------------;
1507
;--------------------------------------------------------------;
1512
locals
1508
locals
1513
	lsha	rd	1
1509
	lsha	rd	1
1514
endl
1510
endl
1515
 
1511
 
1516
	push	ebx esi edi
1512
	push	ebx esi edi
1517
 
1513
 
1518
	mov	[lsha], eax
1514
	mov	[lsha], eax
1519
 
1515
 
1520
	movzx	ebx, byte[lsha + 0]
1516
	movzx	ebx, byte[lsha + 0]
1521
	lea	esi, [ebx*2]
1517
	lea	esi, [ebx*2]
1522
	movzx	edi, byte[lsha + 1]
1518
	movzx	edi, byte[lsha + 1]
1523
	xor	eax, eax
1519
	xor	eax, eax
1524
	mov	cl, 1
1520
	mov	cl, 1
1525
	cmp	bl, 0x7f
1521
	cmp	bl, 0x7f
1526
	ja	.lcase
1522
	ja	.lcase
1527
	dec	al
1523
	dec	al
1528
	xor	ecx, ecx
1524
	xor	ecx, ecx
1529
  .lcase:
1525
  .lcase:
1530
	add	eax, edi
1526
	add	eax, edi
1531
	mul	ebx
1527
	mul	ebx
1532
	or	ecx, ecx
1528
	or	ecx, ecx
1533
	jz	.scase
1529
	jz	.scase
1534
	neg	eax
1530
	neg	eax
1535
	mov	ecx, ebx
1531
	mov	ecx, ebx
1536
	add	ecx, edi
1532
	add	ecx, edi
1537
	mov	edx, ecx
1533
	mov	edx, ecx
1538
	shl	ecx, 8
1534
	shl	ecx, 8
1539
	sub	ecx, edx
1535
	sub	ecx, edx
1540
	add	eax, ecx
1536
	add	eax, ecx
1541
  .scase:
1537
  .scase:
1542
	xor	edx, edx
1538
	xor	edx, edx
1543
	xor	ecx, ecx
1539
	xor	ecx, ecx
1544
	dec	cl
1540
	dec	cl
1545
	mov	edi, ecx
1541
	mov	edi, ecx
1546
	div	ecx
1542
	div	ecx
1547
	jz	.done
1543
	jz	.done
1548
	mov	ecx, eax
1544
	mov	ecx, eax
1549
	sub	esi, eax
1545
	sub	esi, eax
1550
	movzx	eax, byte[lsha + 2]
1546
	movzx	eax, byte[lsha + 2]
1551
	mov	ebx, eax
1547
	mov	ebx, eax
1552
	shl	eax, 1
1548
	shl	eax, 1
1553
	lea	eax, [ebx*4 + eax]
1549
	lea	eax, [ebx*4 + eax]
1554
	xor	edx, edx
1550
	xor	edx, edx
1555
	div	edi
1551
	div	edi
1556
	mov	ebx, eax
1552
	mov	ebx, eax
1557
	mov	eax, ecx
1553
	mov	eax, ecx
1558
	sub	eax, esi
1554
	sub	eax, esi
1559
	mul	edx
1555
	mul	edx
1560
	push	ebx
1556
	push	ebx
1561
	mov	ebx, ecx
1557
	mov	ebx, ecx
1562
	shl	ebx, 8
1558
	shl	ebx, 8
1563
	sub	ebx, ecx
1559
	sub	ebx, ecx
1564
	sub	ebx, eax
1560
	sub	ebx, eax
1565
	xchg	eax, ebx
1561
	xchg	eax, ebx
1566
	xor	edx, edx
1562
	xor	edx, edx
1567
	div	edi
1563
	div	edi
1568
	shl	eax, 24
1564
	shl	eax, 24
1569
	or	ecx, eax
1565
	or	ecx, eax
1570
	mov	eax, esi
1566
	mov	eax, esi
1571
	shl	eax, 8
1567
	shl	eax, 8
1572
	sub	eax, esi
1568
	sub	eax, esi
1573
	shl	esi, 16
1569
	shl	esi, 16
1574
	or	ecx, esi
1570
	or	ecx, esi
1575
	add	eax, ebx
1571
	add	eax, ebx
1576
	xor	edx, edx
1572
	xor	edx, edx
1577
	div	edi
1573
	div	edi
1578
	mov	ch, al
1574
	mov	ch, al
1579
	mov	eax, ecx
1575
	mov	eax, ecx
1580
	pop	ecx
1576
	pop	ecx
1581
	cmp	cl, 6
1577
	cmp	cl, 6
1582
	jz	.done
1578
	jz	.done
1583
	or	ecx, ecx
1579
	or	ecx, ecx
1584
	jz	.done
1580
	jz	.done
1585
	bswap	eax
1581
	bswap	eax
1586
	rol	eax, 8
1582
	rol	eax, 8
1587
	xchg	ah, al
1583
	xchg	ah, al
1588
	dec	ecx
1584
	dec	ecx
1589
	jz	.done
1585
	jz	.done
1590
	ror	eax, 8
1586
	ror	eax, 8
1591
	xchg	ah, al
1587
	xchg	ah, al
1592
	dec	ecx
1588
	dec	ecx
1593
	jz	.done
1589
	jz	.done
1594
	rol	eax, 8
1590
	rol	eax, 8
1595
	xchg	ah, al
1591
	xchg	ah, al
1596
	dec	ecx
1592
	dec	ecx
1597
	jz	.done
1593
	jz	.done
1598
	bswap	eax
1594
	bswap	eax
1599
	rol	eax, 8
1595
	rol	eax, 8
1600
	xchg	ah, al
1596
	xchg	ah, al
1601
	dec	ecx
1597
	dec	ecx
1602
	jz	.done
1598
	jz	.done
1603
	ror	eax, 8
1599
	ror	eax, 8
1604
	xchg	ah, al
1600
	xchg	ah, al
1605
  .done:
1601
  .done:
1606
	and	eax, 0x00ffffff
1602
	and	eax, 0x00ffffff
1607
 
1603
 
1608
	mov	bl, byte[lsha + 3]
1604
	mov	bl, byte[lsha + 3]
1609
	bswap	eax
1605
	bswap	eax
1610
	mov	al, bl
1606
	mov	al, bl
1611
	ror	eax, 8
1607
	ror	eax, 8
1612
 
1608
 
1613
	pop	edi esi ebx
1609
	pop	edi esi ebx
1614
 
1610
 
1615
 
1611
 
1616
	ret
1612
	ret
1617
endp
1613
endp
1618
 
-
 
1619
 
-
 
1620
match =MMX,	COMPOSITE_MODE{include	'composite_mmx.asm'}
-
 
1621
match =SSE,	COMPOSITE_MODE{include	'composite_sse.asm'}
-
 
1622
 
1614
 
1623
;;================================================================================================;;
1615
;;================================================================================================;;
1624
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1616
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1625
;;================================================================================================;;
1617
;;================================================================================================;;
1626
;! Below is private data you should never use directly from your code                             ;;
1618
;! Below is private data you should never use directly from your code                             ;;
1627
;;================================================================================================;;
1619
;;================================================================================================;;
1628
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1620
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1629
;;================================================================================================;;
1621
;;================================================================================================;;
1630
xcf._.prop_table_begin:
1622
xcf._.prop_table_begin:
1631
		dd	00, xcf._.parse_properties.00
1623
		dd	00, xcf._.parse_properties.00
1632
		dd	01, xcf._.parse_properties.01
1624
		dd	01, xcf._.parse_properties.01
1633
		dd	06, xcf._.parse_properties.06
1625
		dd	06, xcf._.parse_properties.06
1634
		dd	07, xcf._.parse_properties.07
1626
		dd	07, xcf._.parse_properties.07
1635
		dd	08, xcf._.parse_properties.08
1627
		dd	08, xcf._.parse_properties.08
1636
		dd	11, xcf._.parse_properties.11
1628
		dd	11, xcf._.parse_properties.11
1637
		dd	15, xcf._.parse_properties.15
1629
		dd	15, xcf._.parse_properties.15
1638
xcf._.prop_table_end:
1630
xcf._.prop_table_end:
1639
 
-
 
1640
xcf._.composite_table.begin:
-
 
1641
  .p00	dd 00, xcf._.composite_rgb_00, xcf._.composite_gray_00, xcf._.composite_indexed_00	; Normal
-
 
1642
  .p01	dd 01, xcf._.composite_rgb_01, xcf._.composite_gray_01, xcf._.composite_gray_01		; Dissolve	: random dithering to discrete alpha
-
 
1643
;  .p02	dd 02, xcf._.composite_rgb_02, 0,			xcf._.composite_indexed_02	; Behind	: not selectable in the GIMP UI. not implemented
-
 
1644
  .p03	dd 03, xcf._.composite_rgb_03, xcf._.composite_rgb_03, xcf._.composite_indexed_00	; Multiply
-
 
1645
  .p04	dd 04, xcf._.composite_rgb_04, xcf._.composite_rgb_04, xcf._.composite_indexed_00	; Screen
-
 
1646
  .p05	dd 05, xcf._.composite_rgb_05, xcf._.composite_rgb_05, xcf._.composite_indexed_00	; Overlay
-
 
1647
  .p06	dd 06, xcf._.composite_rgb_06, xcf._.composite_rgb_06, xcf._.composite_indexed_00	; Difference
-
 
1648
  .p07	dd 07, xcf._.composite_rgb_07, xcf._.composite_rgb_07, xcf._.composite_indexed_00	; Addition
-
 
1649
  .p08	dd 08, xcf._.composite_rgb_08, xcf._.composite_rgb_08, xcf._.composite_indexed_00	; Subtract
-
 
1650
  .p09	dd 09, xcf._.composite_rgb_09, xcf._.composite_rgb_09, xcf._.composite_indexed_00	; Darken Only
-
 
1651
  .p10	dd 10, xcf._.composite_rgb_10, xcf._.composite_rgb_10, xcf._.composite_indexed_00	; Lighten Only
-
 
1652
  .p11	dd 11, xcf._.composite_rgb_11, xcf._.composite_gray_00, xcf._.composite_indexed_00	; Hue (H of HSV)
-
 
1653
  .p12	dd 12, xcf._.composite_rgb_12, xcf._.composite_gray_00, xcf._.composite_indexed_00	; Saturation (S of HSV)
-
 
1654
  .p13	dd 13, xcf._.composite_rgb_13, xcf._.composite_gray_00, xcf._.composite_indexed_00	; Color (H and S of HSL)
-
 
1655
  .p14	dd 14, xcf._.composite_rgb_14, xcf._.composite_gray_00, xcf._.composite_indexed_00	; Value (V of HSV)
-
 
1656
  .p15	dd 15, xcf._.composite_rgb_15, xcf._.composite_rgb_15, xcf._.composite_indexed_00	; Divide
-
 
1657
  .p16	dd 16, xcf._.composite_rgb_16, xcf._.composite_rgb_16, xcf._.composite_indexed_00	; Dodge
-
 
1658
  .p17	dd 17, xcf._.composite_rgb_17, xcf._.composite_rgb_17, xcf._.composite_indexed_00	; Burn
-
 
1659
  .p18	dd 18, xcf._.composite_rgb_18, xcf._.composite_rgb_18, xcf._.composite_indexed_00	; Hard Light
-
 
1660
  .p19	dd 19, xcf._.composite_rgb_05, xcf._.composite_rgb_05, xcf._.composite_indexed_00	; Soft Light	: XCF >= 2 only ('soft light' == 'overlay')
-
 
1661
  .p20	dd 20, xcf._.composite_rgb_20, xcf._.composite_rgb_20, xcf._.composite_indexed_00	; Grain Extract	: XCF >= 2 only
-
 
1662
  .p21	dd 21, xcf._.composite_rgb_21, xcf._.composite_rgb_21, xcf._.composite_indexed_00	; Grain Merge	: XCF >= 2 only
-
 
1663
xcf._.composite_table.end:
-