Subversion Repositories Kolibri OS

Rev

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