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
2388 dunkaist 1
proc	xcf._.blend_rgb
2
 
3
	push		eax ebx
4
 
5
	xchg		al, bh
6
	mov		ah, bh
7
	neg		ax
8
	add		ax, 0xffff
9
	mul		ah
10
	neg		ah
11
	add		ah, 0xff
12
	xchg		ah, bh
13
 
14
	mov		al, 0xff
15
	cmp		ah, bh
16
	je		@f
17
	not		al
18
	div		bh
19
    @@:
20
	mov		ah, al
21
	movd		xmm1, eax
22
 
23
	pop		ebx eax
24
	push		ebx
25
 
26
	shr		eax, 8
27
	shr		ebx, 8
28
 
29
	xchg		al, bh
30
	mov		ah, bh
31
	neg		ax
32
	add		ax, 0xffff
33
	mul		ah
34
	neg		ah
35
	add		ah, 0xff
36
	xchg		ah, bh
37
 
38
	mov		al, 0xff
39
	cmp		ah, bh
40
	je		@f
41
	not		al
42
	div		bh
43
    @@:
44
	mov		ah, al
45
	movd		ebx, xmm1
46
	ror		ebx, 16
47
	mov		bx, ax
48
	rol		ebx, 16
49
	movd		xmm1, ebx
50
 
51
	pop		ebx
52
 
53
;	movdqu		xmm1, xword[xcf._.xmm_000000ff]
54
;	movdqa		xmm4, xmm1
55
;	movdqa		xmm5, xmm1
56
;	movdqa		xmm6, xmm2
57
;	psrldq		xmm6, 3
58
;	pand		xmm6, xmm1
59
;	psubw		xmm4, xmm6
60
;	movdqa		xmm6, xmm3
61
;	psrldq		xmm6, 3
62
;	pand		xmm6, xmm1
63
;	psubw		xmm5, xmm6
64
;	pmullw		xmm4, xmm5
65
;	psrlw		xmm4, 8
66
;	psubw		xmm1, xmm4
67
;	movdqa		xmm4, xmm1
68
;	movdqa		xmm1, xmm6
69
;	divps		xmm1, xmm4
70
;	packuswb	xmm1, xmm0
71
;	packuswb	xmm1, xmm0
72
;	punpcklbw	xmm1, xmm1
73
 
74
	punpcklbw	xmm1, xmm1
75
	punpcklbw	xmm1, xmm0
76
 
77
	movdqa		xmm7, xmm1
78
	psrlw		xmm7, 7
79
	paddw		xmm1, xmm7
80
 
81
	psubw		xmm3, xmm2
82
	pmullw		xmm3, xmm1
83
	psllw		xmm2, 8
84
	paddw		xmm3, xmm2
85
	pinsrw		xmm3, ebx, 3
86
	shr		ebx, 8
87
	pinsrw		xmm3, ebx, 7
88
	psrlw		xmm3, 8
89
	packuswb	xmm3, xmm0
90
 
91
	ret
92
endp
93
 
94
 
95
proc	xcf._.blend_gray
96
 
97
	xchg		al, bh
98
	mov		ah, bh
99
	neg		ax
100
	add		ax, 0xffff
101
	mul		ah
102
	neg		ah
103
	add		ah, 0xff
104
	xchg		ah, bh
105
 
106
	mov		al, 0xff
107
	cmp		ah, bh
108
	je		@f
109
	not		al
110
	div		bh
111
    @@:
112
 
113
	mov		ah, al
114
 
115
	movd		xmm1, eax
116
	punpcklbw	xmm1, xmm1
117
	punpcklbw	xmm1, xmm0
118
 
119
	movq		xmm7, xmm1
120
	psrlw		xmm7, 7
121
	paddw		xmm1, xmm7
122
 
123
	psubw		xmm3, xmm2
124
	pmullw		xmm3, xmm1
125
	psllw		xmm2, 8
126
	paddw		xmm3, xmm2
127
	pinsrw		xmm3, ebx, 1
128
	psrlw		xmm3, 8
129
	packuswb	xmm3, xmm0
130
 
131
	ret
132
endp
133
 
134
 
135
proc	xcf._.merge_32 _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
136
 
137
	pxor		xmm0, xmm0
138
 
139
  .line:
140
	mov		ecx, [_copy_width]
141
	bt		ecx, 0
142
	jnc		.even
143
  .odd:
144
	movd		xmm2, [edi]
145
	movd		xmm3, [esi]
146
	add		esi, 4
147
 
148
	movdqa		xmm4, xmm2
149
	pminub		xmm4, xmm3
150
	pextrw		eax, xmm4, 3
151
	pextrw		ebx, xmm4, 1
152
	mov		al, bh
153
 
154
	push		eax
155
	pextrw		eax, xmm2, 3
156
	pextrw		ebx, xmm2, 1
157
	mov		bl, ah
158
	shl		ebx, 8
159
	pop		eax
160
 
161
	call		edx
162
	call		xcf._.blend_rgb
163
	movd		[edi], xmm3
164
	add		edi, 4
165
 
166
	cmp		ecx, 1
167
	je		.done
168
 
169
  .even:
170
	sub		ecx, 2
171
  .pixel:
172
	movq		xmm2, [edi]
173
	movq		xmm3, [esi]
174
	add		esi, 8
175
 
176
	movdqa		xmm4, xmm2
177
	pminub		xmm4, xmm3
178
	pextrw		eax, xmm4, 3
179
	pextrw		ebx, xmm4, 1
180
	mov		al, bh
181
 
182
	push		eax
183
	pextrw		eax, xmm2, 3
184
	pextrw		ebx, xmm2, 1
185
	mov		bl, ah
186
	shl		ebx, 8
187
	pop		eax
188
 
189
	call		edx
190
	call		xcf._.blend_rgb
191
	movq		[edi], xmm3
192
	add		edi, 8
193
	sub		ecx, 2
194
	jns		.pixel
195
	add		esi, [_img_total_bpl]
196
	add		edi, [_bottom_total_bpl]
197
	dec		[_copy_height]
198
	jnz		.line
199
  .done:
200
	ret
201
endp
202
 
203
 
204
proc	xcf._.merge_8a _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
205
  .gray_line:
206
	mov		ecx, [_copy_width]
207
  .gray_pixel:
208
	mov		bx,  word[edi]
209
	lodsw
210
	movd		xmm2, ebx
211
	movd		xmm3, eax
212
	shr		eax, 8
213
	cmp		al, bh
214
	jna		@f
215
	mov		al, bh
216
    @@:
217
	pxor		xmm0, xmm0
218
	call		edx
219
	call		xcf._.blend_gray
220
	movd		eax, xmm3
221
	stosw
222
	dec		ecx
223
	jnz		.gray_pixel
224
	add		esi, [_img_total_bpl]
225
	add		edi, [_bottom_total_bpl]
226
	dec		[_copy_height]
227
	jnz		.gray_line
228
	ret
229
endp
230
 
231
 
232
proc	xcf._.composite_rgb_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
233
 
234
	pxor		xmm0, xmm0
235
 
236
  .line:
237
	mov		ecx, [_copy_width]
238
	bt		ecx, 0
239
	jnc		.even
240
  .odd:
241
	movlpd		xmm2, [edi]
242
	movlpd		xmm3, [esi]
243
	add		esi, 4
244
 
245
	pextrw		eax, xmm3, 3
246
	pextrw		ebx, xmm3, 1
247
	mov		al, bh
248
 
249
	push		eax
250
	pextrw		eax, xmm2, 3
251
	pextrw		ebx, xmm2, 1
252
	mov		bl, ah
253
	shl		ebx, 8
254
	pop		eax
255
 
256
	xchg		al, bh
257
	mov		ah, bh
258
	neg		al
259
	neg		ah
260
	dec		al
261
	dec		ah
262
	mul		ah
263
	neg		ah
264
	dec		ah
265
	xchg		ah, bh
266
 
267
	mov		al, 0xff
268
	cmp		ah, bh
269
	je		@f
270
	inc		al
271
	div		bh
272
    @@:
273
	mov		ah, al
274
	movd		xmm1, eax
275
 
276
	punpcklbw	xmm1, xmm1
277
	punpcklbw	xmm1, xmm0
278
	punpcklbw	xmm2, xmm0
279
	punpcklbw	xmm3, xmm0
280
 
281
	psubsw		xmm3, xmm2
282
	pmullw		xmm3, xmm1
283
	psllw		xmm2, 8
284
	paddw		xmm3, xmm2
285
	pinsrw		xmm3, ebx, 3
286
	shr		ebx, 8
287
	pinsrw		xmm3, ebx, 7
288
	psrlw		xmm3, 8
289
	packuswb	xmm3, xmm0
290
 
291
	movd		[edi], xmm3
292
	add		edi, 4
293
 
294
	cmp		ecx, 1
295
	je		.done
296
 
297
  .even:
298
	sub		ecx, 2
299
  .pixel:
300
	movlpd		xmm2, [edi]
301
	movlpd		xmm3, [esi]
302
	add		esi, 8
303
 
304
	pextrw		eax, xmm3, 3
305
	pextrw		ebx, xmm3, 1
306
	mov		al, bh
307
 
308
	push		eax
309
	pextrw		eax, xmm2, 3
310
	pextrw		ebx, xmm2, 1
311
	mov		bl, ah
312
	shl		ebx, 8
313
	pop		eax
314
 
315
 
316
	push		eax ebx
317
 
318
	xchg		al, bh
319
	mov		ah, bh
320
	neg		al
321
	neg		ah
322
	dec		al
323
	dec		ah
324
	mul		ah
325
	neg		ah
326
	dec		ah
327
	xchg		ah, bh
328
 
329
	mov		al, 0xff
330
	cmp		ah, bh
331
	je		@f
332
	inc		al
333
	div		bh
334
    @@:
335
	mov		ah, al
336
	movd		xmm1, eax
337
 
338
	pop		ebx eax
339
	push		ebx
340
 
341
	shr		eax, 8
342
	shr		ebx, 8
343
 
344
	xchg		al, bh
345
	mov		ah, bh
346
	neg		ax
347
	add		ax, 0xffff
348
	mul		ah
349
	neg		ah
350
	add		ah, 0xff
351
	xchg		ah, bh
352
 
353
	mov		al, 0xff
354
	cmp		ah, bh
355
	je		@f
356
	not		al
357
	div		bh
358
    @@:
359
	mov		ah, al
360
	movd		ebx, xmm1
361
	ror		ebx, 16
362
	mov		bx, ax
363
	rol		ebx, 16
364
	movd		xmm1, ebx
365
 
366
	pop		ebx
367
 
368
	punpcklbw	xmm1, xmm1
369
	punpcklbw	xmm1, xmm0
370
	punpcklbw	xmm2, xmm0
371
	punpcklbw	xmm3, xmm0
372
 
373
	psubsw		xmm3, xmm2
374
	pmullw		xmm3, xmm1
375
	psllw		xmm2, 8
376
	paddw		xmm3, xmm2
377
	pinsrw		xmm3, ebx, 3
378
	shr		ebx, 8
379
	pinsrw		xmm3, ebx, 7
380
	psrlw		xmm3, 8
381
	packuswb	xmm3, xmm0
382
 
383
	movq		[edi], xmm3
384
	add		edi, 8
385
	sub		ecx, 2
386
	jns		.pixel
387
	add		esi, [_img_total_bpl]
388
	add		edi, [_bottom_total_bpl]
389
	dec		[_copy_height]
390
	jnz		.line
391
  .done:
392
	ret
393
endp
394
 
395
 
396
proc	xcf._.composite_gray_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
397
 
398
  .line:
399
	mov		ecx, [_copy_width]
400
  .pixel:
401
	mov		bx, [edi]
402
	lodsw
403
	movd		xmm2, ebx
404
	movd		xmm3, eax
405
 
406
	shr		eax, 8
407
 
408
	xchg		al, bh
409
	mov		ah, bh
410
	neg		ax
411
	add		ax, 0xffff
412
	mul		ah
413
	neg		ah
414
	add		ah, 0xff
415
	xchg		ah, bh
416
 
417
	mov		al, 0xff
418
	cmp		ah, bh
419
	je		@f
420
	not		al
421
	div		bh
422
    @@:
423
 
424
	mov		ah, al
425
 
426
	movd		xmm1, eax
427
	pxor		xmm0, xmm0
428
	punpcklbw	xmm1, xmm1
429
	punpcklbw	xmm1, xmm0
430
	punpcklbw	xmm2, xmm0
431
	punpcklbw	xmm3, xmm0
432
 
433
	psubw		xmm3, xmm2
434
	pmullw		xmm3, xmm1
435
	psllw		xmm2, 8
436
	paddw		xmm3, xmm2
437
	pinsrw		xmm3, ebx, 1
438
	psrlw		xmm3, 8
439
	packuswb	xmm3, xmm0
440
	movd		eax, xmm3
441
	stosw
442
 
443
	dec		ecx
444
	jnz		.pixel
445
	add		esi, [_img_total_bpl]
446
	add		edi, [_bottom_total_bpl]
447
	dec		[_copy_height]
448
	jnz		.line
449
 
450
	ret
451
endp
452
 
453
 
454
proc	xcf._.composite_indexed_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
455
 
456
  .line:
457
	mov		ecx, [_copy_width]
458
  .pixel:
459
	mov		bx, [edi]
460
	lodsw
461
 
462
	or		ah, 0x7f
463
	test		ah, 0x80
464
	jnz		@f
465
	mov		ax, bx
466
    @@:
467
	stosw
468
 
469
	dec		ecx
470
	jnz		.pixel
471
	add		esi, [_img_total_bpl]
472
	add		edi, [_bottom_total_bpl]
473
	dec		[_copy_height]
474
	jnz		.line
475
	ret
476
endp
477
 
478
 
479
proc	xcf._.composite_rgb_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
480
	pushad
481
 
482
	pxor		xmm4, xmm4
483
	movd		xmm4, [xcf._.random_b]
484
	movd		xmm1, [xcf._.random_a]
485
	movd		xmm2, [xcf._.random_c]
486
 
487
  .line:
488
	mov		ecx, [_copy_width]
489
  .pixel:
490
	mov		ebx, [edi]
491
	lodsd
492
 
493
	movq		xmm0, xmm4
494
	pmuludq		xmm0, xmm1
495
	paddq		xmm0, xmm2
496
	movd		edx, xmm0
497
	movd		xmm4, edx
498
	pxor		xmm0, xmm0
499
 
500
	rol		eax, 8
501
	test		al, al
502
	jz		@f
503
	shr		edx, 17
504
	cmp		dl, al
505
	ja		@f
506
	ror		eax, 8
507
	or		eax, 0xff000000
508
	jmp		.done
509
    @@:
510
	mov		eax, ebx
511
  .done:
512
	stosd
513
	dec		ecx
514
	jnz		.pixel
515
	add		esi, [_img_total_bpl]
516
	add		edi, [_bottom_total_bpl]
517
	dec		[_copy_height]
518
	jnz		.line
519
 
520
  .quit:
521
	popad
522
	ret
523
endp
524
 
525
 
526
proc	xcf._.composite_gray_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
527
	pushad
528
 
529
	pxor		xmm4, xmm4
530
	movd		xmm4, [xcf._.random_b]
531
	movd		xmm1, [xcf._.random_a]
532
	movd		xmm2, [xcf._.random_c]
533
 
534
  .line:
535
	mov		ecx, [_copy_width]
536
  .pixel:
537
	mov		ebx, [edi]
538
	lodsw
539
 
540
	movq		xmm0, xmm4
541
	pmuludq		xmm0, xmm1
542
	paddq		xmm0, xmm2
543
	movd		edx, xmm0
544
	movd		xmm4, edx
545
	pxor		xmm0, xmm0
546
 
547
	test		ah, ah
548
	jz		@f
549
	shr		edx, 17
550
	cmp		dl, ah
551
	ja		@f
552
	or		ax, 0xff00
553
	jmp		.done
554
    @@:
555
	mov		eax, ebx
556
  .done:
557
	stosw
558
	dec		ecx
559
	jnz		.pixel
560
	add		esi, [_img_total_bpl]
561
	add		edi, [_bottom_total_bpl]
562
	dec		[_copy_height]
563
	jnz		.line
564
 
565
  .quit:
566
	popad
567
	ret
568
endp
569
 
570
 
571
proc	xcf._.composite_rgb_03			; Multiply
572
 
573
	punpcklbw	xmm2, xmm0
574
	punpcklbw	xmm3, xmm0
575
	pmullw		xmm3, xmm2
576
	psrlw		xmm3, 8
577
 
578
	ret
579
endp
580
 
581
 
582
proc	xcf._.composite_rgb_04			; Screen
583
 
584
	punpcklbw	xmm2, xmm0
585
	punpcklbw	xmm3, xmm0
2733 dunkaist 586
	movdqu		xmm4, xword[xcf._.xmm_00ff]
587
	movdqa		xmm5, xmm4
588
	psubw		xmm5, xmm3
589
	movdqa		xmm3, xmm4
2388 dunkaist 590
	psubw		xmm4, xmm2
2733 dunkaist 591
	pmullw		xmm4, xmm5
592
	psrlw		xmm4, 8
593
	psubw		xmm3, xmm4
2388 dunkaist 594
	ret
595
endp
596
 
597
 
598
proc	xcf._.composite_rgb_05			; Overlay
599
 
600
	punpcklbw	xmm2, xmm0
601
	punpcklbw	xmm3, xmm0
602
	movdqu		xmm4, xword[xcf._.xmm_00ff]
603
	psubw		xmm4, xmm2
604
	pmullw		xmm3, xmm4
605
	psrlw		xmm3, 7
606
	paddw		xmm3, xmm2
607
	pmullw		xmm3, xmm2
608
	psrlw		xmm3, 8
609
 
610
	ret
611
endp
612
 
613
 
614
proc	xcf._.composite_rgb_06			; Difference
615
 
616
	movdqa		xmm4, xmm3
617
	pminub		xmm4, xmm2
618
	pmaxub		xmm3, xmm2
619
	psubusb		xmm3, xmm4
620
	punpcklbw	xmm2, xmm0
621
	punpcklbw	xmm3, xmm0
622
 
623
	ret
624
endp
625
 
626
 
627
proc	xcf._.composite_rgb_07			; Addition
628
 
629
	paddusb		xmm3, xmm2
630
	punpcklbw	xmm2, xmm0
631
	punpcklbw	xmm3, xmm0
632
 
633
	ret
634
endp
635
 
636
 
637
proc	xcf._.composite_rgb_08			; Subtract
638
 
639
	movdqa		xmm4, xmm2
640
	psubusb		xmm4, xmm3
641
	movq		xmm3, xmm4
642
	punpcklbw	xmm2, xmm0
643
	punpcklbw	xmm3, xmm0
644
 
645
	ret
646
endp
647
 
648
 
649
proc	xcf._.composite_rgb_09			; Darken Only
650
 
651
	pminub		xmm3, xmm2
652
	punpcklbw	xmm2, xmm0
653
	punpcklbw	xmm3, xmm0
654
 
655
	ret
656
endp
657
 
658
 
659
proc	xcf._.composite_rgb_10			; Lighten Only
660
 
661
	pmaxub		xmm3, xmm2
662
	punpcklbw	xmm2, xmm0
663
	punpcklbw	xmm3, xmm0
664
 
665
	ret
666
endp
667
 
668
 
669
proc	xcf._.composite_rgb_11			; Hue (H of HSV)
670
	push		eax ebx ecx edx
671
 
672
	movd		eax, xmm3
673
	movd		ebx, xmm2
674
 
675
	call		xcf._.rgb2hsv
676
	xchg		eax, ebx
677
	call		xcf._.rgb2hsv
678
	xchg		eax, ebx
679
 
680
	test		ah, ah
681
	jnz		@f
682
	ror		eax, 8
683
	ror		ebx, 8
684
	mov		ah, bh
685
	rol		eax, 8
686
	rol		ebx, 8
687
    @@:
688
	mov		ax, bx
689
 
690
	call		xcf._.hsv2rgb
691
 
692
	push		eax
693
 
694
	movq		xmm1, xmm3
695
	psrldq		xmm1, 4
696
	movd		eax, xmm1
697
	movq		xmm1, xmm2
698
	psrldq		xmm1, 4
699
	movd		ebx, xmm1
700
 
701
	call		xcf._.rgb2hsv
702
	xchg		eax, ebx
703
	call		xcf._.rgb2hsv
704
	xchg		eax, ebx
705
 
706
	test		ah, ah
707
	jnz		@f
708
	ror		eax, 8
709
	ror		ebx, 8
710
	mov		ah, bh
711
	rol		eax, 8
712
	rol		ebx, 8
713
    @@:
714
	mov		ax, bx
715
 
716
	call		xcf._.hsv2rgb
717
 
718
	movd		xmm3, eax
719
	pslldq		xmm3, 4
720
	pop		eax
721
	movd		xmm1, eax
722
	paddq		xmm3, xmm1
723
 
724
	punpcklbw	xmm2, xmm0
725
	punpcklbw	xmm3, xmm0
726
 
727
  .quit:
728
	pop		edx ecx ebx eax
729
	ret
730
endp
731
 
732
 
733
proc	xcf._.composite_rgb_12			; Saturation (S of HSV)
734
	push		eax ebx ecx edx
735
 
736
	movd		eax, xmm3
737
	movd		ebx, xmm2
738
 
739
	call		xcf._.rgb2hsv
740
	xchg		eax, ebx
741
	call		xcf._.rgb2hsv
742
	xchg		eax, ebx
743
 
744
	ror		eax, 8
745
	ror		ebx, 8
746
	mov		ah, bh
747
	rol		eax, 8
748
	rol		ebx, 8
749
	mov		al, bl
750
 
751
	call		xcf._.hsv2rgb
752
 
753
	push		eax
754
	movq		xmm1, xmm3
755
	psrldq		xmm1, 4
756
	movd		eax, xmm1
757
	movq		xmm1, xmm2
758
	psrldq		xmm1, 4
759
	movd		ebx, xmm1
760
 
761
	call		xcf._.rgb2hsv
762
	xchg		eax, ebx
763
	call		xcf._.rgb2hsv
764
	xchg		eax, ebx
765
 
766
	ror		eax, 8
767
	ror		ebx, 8
768
	mov		ah, bh
769
	rol		eax, 8
770
	rol		ebx, 8
771
	mov		al, bl
772
 
773
	call		xcf._.hsv2rgb
774
 
775
 
776
	movd		xmm3, eax
777
	pslldq		xmm3, 4
778
	pop		eax
779
	movd		xmm1, eax
780
	paddq		xmm3, xmm1
781
 
782
	punpcklbw	xmm2, xmm0
783
	punpcklbw	xmm3, xmm0
784
 
785
  .quit:
786
	pop		edx ecx ebx eax
787
	ret
788
endp
789
 
790
 
791
proc	xcf._.composite_rgb_13			; Color (H and S of HSL)
792
	push		eax ebx ecx edx
793
 
794
	movd		eax, xmm3
795
	movd		ebx, xmm2
796
 
797
	call		xcf._.rgb2hsl
798
	xchg		eax,    ebx
799
	call		xcf._.rgb2hsl
800
	xchg		eax,    ebx
801
 
802
	mov		al, bl
803
 
804
	call		xcf._.hsl2rgb
805
 
806
	push		eax
807
	movq		xmm1, xmm3
808
	psrldq		xmm1, 4
809
	movd		eax, xmm1
810
	movq		xmm1, xmm2
811
	psrldq		xmm1, 4
812
	movd		ebx, xmm1
813
 
814
	call		xcf._.rgb2hsl
815
	xchg		eax,    ebx
816
	call		xcf._.rgb2hsl
817
	xchg		eax,    ebx
818
 
819
	mov		al, bl
820
 
821
	call		xcf._.hsl2rgb
822
 
823
	movd		xmm3, eax
824
	pslldq		xmm3, 4
825
	pop		eax
826
	movd		xmm1, eax
827
	paddq		xmm3, xmm1
828
 
829
	punpcklbw	xmm2, xmm0
830
	punpcklbw	xmm3, xmm0
831
 
832
  .quit:
833
	pop		edx ecx ebx eax
834
	ret
835
endp
836
 
837
 
838
proc	xcf._.composite_rgb_14			; Value (V of HSV)
839
	push		eax ebx ecx edx
840
 
841
	movd		eax, xmm3
842
	movd		ebx, xmm2
843
 
844
	call		xcf._.rgb2hsv
845
	xchg		eax, ebx
846
	call		xcf._.rgb2hsv
847
	xchg		eax, ebx
848
 
849
	ror		eax, 8
850
	ror		ebx, 8
851
	mov		ax, bx
852
	rol		eax, 8
853
	rol		ebx, 8
854
 
855
	call		xcf._.hsv2rgb
856
 
857
	push		eax
858
	movq		xmm1, xmm3
859
	psrldq		xmm1, 4
860
	movd		eax, xmm1
861
	movq		xmm1, xmm2
862
	psrldq		xmm1, 4
863
	movd		ebx, xmm1
864
 
865
	call		xcf._.rgb2hsv
866
	xchg		eax, ebx
867
	call		xcf._.rgb2hsv
868
	xchg		eax, ebx
869
 
870
	ror		eax, 8
871
	ror		ebx, 8
872
	mov		ax, bx
873
	rol		eax, 8
874
	rol		ebx, 8
875
 
876
	call		xcf._.hsv2rgb
877
 
878
	movd		xmm3, eax
879
	pslldq		xmm3, 4
880
	pop		eax
881
	movd		xmm1, eax
882
	paddq		xmm3, xmm1
883
 
884
	punpcklbw	xmm2, xmm0
885
	punpcklbw	xmm3, xmm0
886
 
887
  .quit:
888
	pop		edx ecx ebx eax
889
	ret
890
endp
891
 
892
 
893
proc	xcf._.composite_rgb_15			; Divide
894
	push		eax ebx ecx
895
 
896
	movd		eax, xmm3
897
	movd		ebx, xmm2
898
 
899
	rol		eax, 8
900
	rol		ebx, 8
901
 
902
	xchg		eax, ebx
903
 
904
	mov		ecx, 3
905
 
906
  .color:
907
	rol		eax, 8
908
	rol		ebx, 8
909
	shl		ax, 8
910
	test		bl, bl
911
	jz		.clamp1
912
	cmp		ah, bl
913
	jae		.clamp2
914
	div		bl
915
	jmp		.done
916
  .clamp1:
917
	mov		al, 0xff
918
	test		ah, ah
919
	jnz		@f
920
	not		al
921
    @@:
922
	jmp		.done
923
  .clamp2:
924
	mov		al, 0xff
925
	jmp		.done
926
  .done:
927
	mov		ah, al
928
	loop		.color
929
 
930
	ror		eax, 8
931
 
932
 
933
	push		eax
934
	movq		xmm1, xmm3
935
	psrldq		xmm1, 4
936
	movd		eax, xmm1
937
	movq		xmm1, xmm2
938
	psrldq		xmm1, 4
939
	movd		ebx, xmm1
940
 
941
 
942
	rol		eax, 8
943
	rol		ebx, 8
944
 
945
	xchg		eax, ebx
946
 
947
	mov		ecx, 3
948
 
949
  .color2:
950
	rol		eax, 8
951
	rol		ebx, 8
952
	shl		ax, 8
953
	test		bl, bl
954
	jz		.clamp12
955
	cmp		ah, bl
956
	jae		.clamp22
957
	div		bl
958
	jmp		.done2
959
  .clamp12:
960
	mov		al, 0xff
961
	test		ah, ah
962
	jnz		@f
963
	not		al
964
    @@:
965
	jmp		.done2
966
  .clamp22:
967
	mov		al, 0xff
968
	jmp		.done2
969
  .done2:
970
	mov		ah, al
971
	loop		.color2
972
 
973
	ror		eax, 8
974
 
975
 
976
	movd		xmm3, eax
977
	pslldq		xmm3, 4
978
	pop		eax
979
	movd		xmm1, eax
980
	paddq		xmm3, xmm1
981
 
982
	punpcklbw	xmm2, xmm0
983
	punpcklbw	xmm3, xmm0
984
 
985
	pop		ecx ebx eax
986
	ret
987
endp
988
 
989
 
990
proc	xcf._.composite_rgb_16			; Dodge
991
	push		eax ebx ecx
992
 
993
	movd		eax, xmm3
994
	movd		ebx, xmm2
995
 
996
	rol		eax, 8
997
	rol		ebx, 8
998
 
999
	xchg		eax, ebx
1000
 
1001
	mov		ecx, 3
1002
 
1003
  .color:
1004
	rol		eax, 8
1005
	rol		ebx, 8
1006
	shl		ax, 8
1007
	neg		bl
1008
	add		bl, 0xff
1009
	test		bl, bl
1010
	jz		.clamp1
1011
	cmp		ah,  bl
1012
	jae		.clamp2
1013
	div		bl
1014
	jmp		.done
1015
  .clamp1:
1016
	mov		al, 0xff
1017
	test		ah, ah
1018
	jnz		@f
1019
	not		al
1020
    @@:
1021
	jmp		.done
1022
  .clamp2:
1023
	mov		al, 0xff
1024
	jmp		.done
1025
  .done:
1026
	mov		ah, al
1027
	loop		.color
1028
 
1029
	ror		eax, 8
1030
 
1031
 
1032
	push		eax
1033
	movq		xmm1, xmm3
1034
	psrldq		xmm1, 4
1035
	movd		eax, xmm1
1036
	movq		xmm1, xmm2
1037
	psrldq		xmm1, 4
1038
	movd		ebx, xmm1
1039
 
1040
 
1041
	rol		eax, 8
1042
	rol		ebx, 8
1043
 
1044
	xchg		eax, ebx
1045
 
1046
	mov		ecx, 3
1047
 
1048
  .color2:
1049
	rol		eax, 8
1050
	rol		ebx, 8
1051
	shl		ax, 8
1052
	neg		bl
1053
	add		bl, 0xff
1054
	test		bl, bl
1055
	jz		.clamp12
1056
	cmp		ah,  bl
1057
	jae		.clamp22
1058
	div		bl
1059
	jmp		.done2
1060
  .clamp12:
1061
	mov		al, 0xff
1062
	test		ah, ah
1063
	jnz		@f
1064
	not		al
1065
    @@:
1066
	jmp		.done2
1067
  .clamp22:
1068
	mov		al, 0xff
1069
	jmp		.done2
1070
  .done2:
1071
	mov		ah, al
1072
	loop		.color2
1073
 
1074
	ror		eax, 8
1075
 
1076
 
1077
	movd		xmm3, eax
1078
	pslldq		xmm3, 4
1079
	pop		eax
1080
	movd		xmm1, eax
1081
	paddq		xmm3, xmm1
1082
 
1083
	punpcklbw	xmm2, xmm0
1084
	punpcklbw	xmm3, xmm0
1085
 
1086
	pop		ecx ebx eax
1087
	ret
1088
endp
1089
 
1090
 
1091
proc	xcf._.composite_rgb_17			; Burn
1092
	push		eax ebx ecx
1093
 
1094
	movd		eax, xmm3
1095
	movd		ebx, xmm2
1096
 
1097
	rol		eax, 8
1098
	rol		ebx, 8
1099
 
1100
	xchg		eax, ebx
1101
 
1102
	mov		ecx, 3
1103
 
1104
  .color:
1105
	rol		eax, 8
1106
	rol		ebx, 8
1107
	shl		ax, 8
1108
	neg		ah
1109
	add		ah, 0xff
1110
	test		bl, bl
1111
	jz		.clamp1
1112
	cmp		ah, bl
1113
	jae		.clamp2
1114
	div		bl
1115
	jmp		.done
1116
  .clamp1:
1117
	mov		al, 0xff
1118
	test		ah, ah
1119
	jnz		@f
1120
	not		al
1121
    @@:
1122
	jmp		.done
1123
  .clamp2:
1124
	mov		al, 0xff
1125
	jmp		.done
1126
  .done:
1127
	mov		ah, al
1128
	neg		ah
1129
	add		ah, 0xff
1130
	loop		.color
1131
 
1132
	ror		eax, 8
1133
 
1134
 
1135
	push		eax
1136
	movq		xmm1, xmm3
1137
	psrldq		xmm1, 4
1138
	movd		eax, xmm1
1139
	movq		xmm1, xmm2
1140
	psrldq		xmm1, 4
1141
	movd		ebx, xmm1
1142
 
1143
 
1144
	rol		eax, 8
1145
	rol		ebx, 8
1146
 
1147
	xchg		eax, ebx
1148
 
1149
	mov		ecx, 3
1150
 
1151
  .color2:
1152
	rol		eax, 8
1153
	rol		ebx, 8
1154
	shl		ax, 8
1155
	neg		ah
1156
	add		ah, 0xff
1157
	test		bl, bl
1158
	jz		.clamp12
1159
	cmp		ah, bl
1160
	jae		.clamp22
1161
	div		bl
1162
	jmp		.done2
1163
  .clamp12:
1164
	mov		al, 0xff
1165
	test		ah, ah
1166
	jnz		@f
1167
	not		al
1168
    @@:
1169
	jmp		.done2
1170
  .clamp22:
1171
	mov		al, 0xff
1172
	jmp		.done2
1173
  .done2:
1174
	mov		ah, al
1175
	neg		ah
1176
	add		ah, 0xff
1177
	loop		.color2
1178
 
1179
	ror		eax, 8
1180
 
1181
 
1182
	movd		xmm3, eax
1183
	pslldq		xmm3, 4
1184
	pop		eax
1185
	movd		xmm1, eax
1186
	paddq		xmm3, xmm1
1187
 
1188
	punpcklbw	xmm2, xmm0
1189
	punpcklbw	xmm3, xmm0
1190
 
1191
	pop		ecx ebx eax
1192
	ret
1193
endp
1194
 
1195
 
1196
proc	xcf._.composite_rgb_18			; Hard Light
1197
	push		eax ebx ecx
1198
 
1199
	movd		eax, xmm3
1200
	movd		ebx, xmm2
1201
 
1202
	rol		eax, 8
1203
	rol		ebx, 8
1204
 
1205
	mov		ecx, 3
1206
 
1207
  .color:
1208
	rol		eax, 8
1209
	rol		ebx, 8
1210
	cmp		al, 127
1211
	jna		.part1
1212
	mov		ah, 0xff
1213
	sub		ah, bl
1214
	neg		al
1215
	add		al, 0xff
1216
	mul		ah
1217
	shl		ax, 1
1218
	neg		ah
1219
	add		ah, 0xff
1220
	jmp		.done
1221
  .part1:
1222
	mul		bl
1223
	shl		ax, 1
1224
  .done:
1225
	loop		.color
1226
 
1227
	ror		eax, 8
1228
 
1229
 
1230
	push		eax
1231
	movq		xmm1, xmm3
1232
	psrldq		xmm1, 4
1233
	movd		eax, xmm1
1234
	movq		xmm1, xmm2
1235
	psrldq		xmm1, 4
1236
	movd		ebx, xmm1
1237
 
1238
 
1239
	rol		eax, 8
1240
	rol		ebx, 8
1241
 
1242
	mov		ecx, 3
1243
 
1244
  .color2:
1245
	rol		eax, 8
1246
	rol		ebx, 8
1247
	cmp		al, 127
1248
	jna		.part12
1249
	mov		ah, 0xff
1250
	sub		ah, bl
1251
	neg		al
1252
	add		al, 0xff
1253
	mul		ah
1254
	shl		ax, 1
1255
	neg		ah
1256
	add		ah, 0xff
1257
	jmp		.done2
1258
  .part12:
1259
	mul		bl
1260
	shl		ax, 1
1261
  .done2:
1262
	loop		.color2
1263
 
1264
	ror		eax, 8
1265
 
1266
 
1267
	movd		xmm3, eax
1268
	pslldq		xmm3, 4
1269
	pop		eax
1270
	movd		xmm1, eax
1271
	paddq		xmm3, xmm1
1272
 
1273
	punpcklbw	xmm2, xmm0
1274
	punpcklbw	xmm3, xmm0
1275
 
1276
	pop		ecx ebx eax
1277
	ret
1278
endp
1279
 
1280
 
1281
proc	xcf._.composite_rgb_20			; Grain Extract
1282
 
1283
	punpcklbw	xmm2, xmm0
1284
	punpcklbw	xmm3, xmm0
1285
	movdqu		xmm4, xmm2
1286
	psubw		xmm3, xword[xcf._.xmm_0080]
1287
	psubw		xmm4, xmm3
1288
	movdqa		xmm3, xmm4
1289
	packuswb	xmm3, xmm0
1290
	punpcklbw	xmm3, xmm0
1291
	ret
1292
endp
1293
 
1294
 
1295
proc	xcf._.composite_rgb_21			; Grain Merge
1296
 
1297
	punpcklbw	xmm2, xmm0
1298
	punpcklbw	xmm3, xmm0
1299
	paddw		xmm3, xmm2
1300
	psubusw		xmm3, xword[xcf._.xmm_0080]
1301
	packuswb	xmm3, xmm0
1302
	punpcklbw	xmm3, xmm0
1303
	ret
1304
endp
1305
 
1306
 
1307
; starting numbers for pseudo-random number generator
1308
xcf._.random_a		dd	1103515245
1309
xcf._.random_b		dd	777
1310
xcf._.random_c		dd	12345
1311
 
1312
xcf._.xmm_8080		dq	0x8080808080808080, 0x8080808080808080
1313
xcf._.xmm_0080		dq	0x0080008000800080, 0x0080008000800080
1314
xcf._.xmm_00ff		dq	0x00ff00ff00ff00ff, 0x00ff00ff00ff00ff
1315
xcf._.xmm_0100		dq	0x0100010001000100, 0x0100010001000100
1316
xcf._.xmm_000000ff	dq	0x000000ff000000ff, 0x0000000000000000