Subversion Repositories Kolibri OS

Rev

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

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