Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | 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
586
	movdqu		xmm5, xword[xcf._.xmm_00ff]
587
	movdqa		xmm4, xmm5
588
	psubw		xmm4, xmm2
589
	psubw		xmm3, xmm5
590
	pmullw		xmm3, xmm4
591
	psrlw		xmm3, 8
592
	paddw		xmm3, xmm5
593
	ret
594
endp
595
 
596
 
597
proc	xcf._.composite_rgb_05			; Overlay
598
 
599
	punpcklbw	xmm2, xmm0
600
	punpcklbw	xmm3, xmm0
601
	movdqu		xmm4, xword[xcf._.xmm_00ff]
602
	psubw		xmm4, xmm2
603
	pmullw		xmm3, xmm4
604
	psrlw		xmm3, 7
605
	paddw		xmm3, xmm2
606
	pmullw		xmm3, xmm2
607
	psrlw		xmm3, 8
608
 
609
	ret
610
endp
611
 
612
 
613
proc	xcf._.composite_rgb_06			; Difference
614
 
615
	movdqa		xmm4, xmm3
616
	pminub		xmm4, xmm2
617
	pmaxub		xmm3, xmm2
618
	psubusb		xmm3, xmm4
619
	punpcklbw	xmm2, xmm0
620
	punpcklbw	xmm3, xmm0
621
 
622
	ret
623
endp
624
 
625
 
626
proc	xcf._.composite_rgb_07			; Addition
627
 
628
	paddusb		xmm3, xmm2
629
	punpcklbw	xmm2, xmm0
630
	punpcklbw	xmm3, xmm0
631
 
632
	ret
633
endp
634
 
635
 
636
proc	xcf._.composite_rgb_08			; Subtract
637
 
638
	movdqa		xmm4, xmm2
639
	psubusb		xmm4, xmm3
640
	movq		xmm3, xmm4
641
	punpcklbw	xmm2, xmm0
642
	punpcklbw	xmm3, xmm0
643
 
644
	ret
645
endp
646
 
647
 
648
proc	xcf._.composite_rgb_09			; Darken Only
649
 
650
	pminub		xmm3, xmm2
651
	punpcklbw	xmm2, xmm0
652
	punpcklbw	xmm3, xmm0
653
 
654
	ret
655
endp
656
 
657
 
658
proc	xcf._.composite_rgb_10			; Lighten Only
659
 
660
	pmaxub		xmm3, xmm2
661
	punpcklbw	xmm2, xmm0
662
	punpcklbw	xmm3, xmm0
663
 
664
	ret
665
endp
666
 
667
 
668
proc	xcf._.composite_rgb_11			; Hue (H of HSV)
669
	push		eax ebx ecx edx
670
 
671
	movd		eax, xmm3
672
	movd		ebx, xmm2
673
 
674
	call		xcf._.rgb2hsv
675
	xchg		eax, ebx
676
	call		xcf._.rgb2hsv
677
	xchg		eax, ebx
678
 
679
	test		ah, ah
680
	jnz		@f
681
	ror		eax, 8
682
	ror		ebx, 8
683
	mov		ah, bh
684
	rol		eax, 8
685
	rol		ebx, 8
686
    @@:
687
	mov		ax, bx
688
 
689
	call		xcf._.hsv2rgb
690
 
691
	push		eax
692
 
693
	movq		xmm1, xmm3
694
	psrldq		xmm1, 4
695
	movd		eax, xmm1
696
	movq		xmm1, xmm2
697
	psrldq		xmm1, 4
698
	movd		ebx, xmm1
699
 
700
	call		xcf._.rgb2hsv
701
	xchg		eax, ebx
702
	call		xcf._.rgb2hsv
703
	xchg		eax, ebx
704
 
705
	test		ah, ah
706
	jnz		@f
707
	ror		eax, 8
708
	ror		ebx, 8
709
	mov		ah, bh
710
	rol		eax, 8
711
	rol		ebx, 8
712
    @@:
713
	mov		ax, bx
714
 
715
	call		xcf._.hsv2rgb
716
 
717
	movd		xmm3, eax
718
	pslldq		xmm3, 4
719
	pop		eax
720
	movd		xmm1, eax
721
	paddq		xmm3, xmm1
722
 
723
	punpcklbw	xmm2, xmm0
724
	punpcklbw	xmm3, xmm0
725
 
726
  .quit:
727
	pop		edx ecx ebx eax
728
	ret
729
endp
730
 
731
 
732
proc	xcf._.composite_rgb_12			; Saturation (S of HSV)
733
	push		eax ebx ecx edx
734
 
735
	movd		eax, xmm3
736
	movd		ebx, xmm2
737
 
738
	call		xcf._.rgb2hsv
739
	xchg		eax, ebx
740
	call		xcf._.rgb2hsv
741
	xchg		eax, ebx
742
 
743
	ror		eax, 8
744
	ror		ebx, 8
745
	mov		ah, bh
746
	rol		eax, 8
747
	rol		ebx, 8
748
	mov		al, bl
749
 
750
	call		xcf._.hsv2rgb
751
 
752
	push		eax
753
	movq		xmm1, xmm3
754
	psrldq		xmm1, 4
755
	movd		eax, xmm1
756
	movq		xmm1, xmm2
757
	psrldq		xmm1, 4
758
	movd		ebx, xmm1
759
 
760
	call		xcf._.rgb2hsv
761
	xchg		eax, ebx
762
	call		xcf._.rgb2hsv
763
	xchg		eax, ebx
764
 
765
	ror		eax, 8
766
	ror		ebx, 8
767
	mov		ah, bh
768
	rol		eax, 8
769
	rol		ebx, 8
770
	mov		al, bl
771
 
772
	call		xcf._.hsv2rgb
773
 
774
 
775
	movd		xmm3, eax
776
	pslldq		xmm3, 4
777
	pop		eax
778
	movd		xmm1, eax
779
	paddq		xmm3, xmm1
780
 
781
	punpcklbw	xmm2, xmm0
782
	punpcklbw	xmm3, xmm0
783
 
784
  .quit:
785
	pop		edx ecx ebx eax
786
	ret
787
endp
788
 
789
 
790
proc	xcf._.composite_rgb_13			; Color (H and S of HSL)
791
	push		eax ebx ecx edx
792
 
793
	movd		eax, xmm3
794
	movd		ebx, xmm2
795
 
796
	call		xcf._.rgb2hsl
797
	xchg		eax,    ebx
798
	call		xcf._.rgb2hsl
799
	xchg		eax,    ebx
800
 
801
	mov		al, bl
802
 
803
	call		xcf._.hsl2rgb
804
 
805
	push		eax
806
	movq		xmm1, xmm3
807
	psrldq		xmm1, 4
808
	movd		eax, xmm1
809
	movq		xmm1, xmm2
810
	psrldq		xmm1, 4
811
	movd		ebx, xmm1
812
 
813
	call		xcf._.rgb2hsl
814
	xchg		eax,    ebx
815
	call		xcf._.rgb2hsl
816
	xchg		eax,    ebx
817
 
818
	mov		al, bl
819
 
820
	call		xcf._.hsl2rgb
821
 
822
	movd		xmm3, eax
823
	pslldq		xmm3, 4
824
	pop		eax
825
	movd		xmm1, eax
826
	paddq		xmm3, xmm1
827
 
828
	punpcklbw	xmm2, xmm0
829
	punpcklbw	xmm3, xmm0
830
 
831
  .quit:
832
	pop		edx ecx ebx eax
833
	ret
834
endp
835
 
836
 
837
proc	xcf._.composite_rgb_14			; Value (V of HSV)
838
	push		eax ebx ecx edx
839
 
840
	movd		eax, xmm3
841
	movd		ebx, xmm2
842
 
843
	call		xcf._.rgb2hsv
844
	xchg		eax, ebx
845
	call		xcf._.rgb2hsv
846
	xchg		eax, ebx
847
 
848
	ror		eax, 8
849
	ror		ebx, 8
850
	mov		ax, bx
851
	rol		eax, 8
852
	rol		ebx, 8
853
 
854
	call		xcf._.hsv2rgb
855
 
856
	push		eax
857
	movq		xmm1, xmm3
858
	psrldq		xmm1, 4
859
	movd		eax, xmm1
860
	movq		xmm1, xmm2
861
	psrldq		xmm1, 4
862
	movd		ebx, xmm1
863
 
864
	call		xcf._.rgb2hsv
865
	xchg		eax, ebx
866
	call		xcf._.rgb2hsv
867
	xchg		eax, ebx
868
 
869
	ror		eax, 8
870
	ror		ebx, 8
871
	mov		ax, bx
872
	rol		eax, 8
873
	rol		ebx, 8
874
 
875
	call		xcf._.hsv2rgb
876
 
877
	movd		xmm3, eax
878
	pslldq		xmm3, 4
879
	pop		eax
880
	movd		xmm1, eax
881
	paddq		xmm3, xmm1
882
 
883
	punpcklbw	xmm2, xmm0
884
	punpcklbw	xmm3, xmm0
885
 
886
  .quit:
887
	pop		edx ecx ebx eax
888
	ret
889
endp
890
 
891
 
892
proc	xcf._.composite_rgb_15			; Divide
893
	push		eax ebx ecx
894
 
895
	movd		eax, xmm3
896
	movd		ebx, xmm2
897
 
898
	rol		eax, 8
899
	rol		ebx, 8
900
 
901
	xchg		eax, ebx
902
 
903
	mov		ecx, 3
904
 
905
  .color:
906
	rol		eax, 8
907
	rol		ebx, 8
908
	shl		ax, 8
909
	test		bl, bl
910
	jz		.clamp1
911
	cmp		ah, bl
912
	jae		.clamp2
913
	div		bl
914
	jmp		.done
915
  .clamp1:
916
	mov		al, 0xff
917
	test		ah, ah
918
	jnz		@f
919
	not		al
920
    @@:
921
	jmp		.done
922
  .clamp2:
923
	mov		al, 0xff
924
	jmp		.done
925
  .done:
926
	mov		ah, al
927
	loop		.color
928
 
929
	ror		eax, 8
930
 
931
 
932
	push		eax
933
	movq		xmm1, xmm3
934
	psrldq		xmm1, 4
935
	movd		eax, xmm1
936
	movq		xmm1, xmm2
937
	psrldq		xmm1, 4
938
	movd		ebx, xmm1
939
 
940
 
941
	rol		eax, 8
942
	rol		ebx, 8
943
 
944
	xchg		eax, ebx
945
 
946
	mov		ecx, 3
947
 
948
  .color2:
949
	rol		eax, 8
950
	rol		ebx, 8
951
	shl		ax, 8
952
	test		bl, bl
953
	jz		.clamp12
954
	cmp		ah, bl
955
	jae		.clamp22
956
	div		bl
957
	jmp		.done2
958
  .clamp12:
959
	mov		al, 0xff
960
	test		ah, ah
961
	jnz		@f
962
	not		al
963
    @@:
964
	jmp		.done2
965
  .clamp22:
966
	mov		al, 0xff
967
	jmp		.done2
968
  .done2:
969
	mov		ah, al
970
	loop		.color2
971
 
972
	ror		eax, 8
973
 
974
 
975
	movd		xmm3, eax
976
	pslldq		xmm3, 4
977
	pop		eax
978
	movd		xmm1, eax
979
	paddq		xmm3, xmm1
980
 
981
	punpcklbw	xmm2, xmm0
982
	punpcklbw	xmm3, xmm0
983
 
984
	pop		ecx ebx eax
985
	ret
986
endp
987
 
988
 
989
proc	xcf._.composite_rgb_16			; Dodge
990
	push		eax ebx ecx
991
 
992
	movd		eax, xmm3
993
	movd		ebx, xmm2
994
 
995
	rol		eax, 8
996
	rol		ebx, 8
997
 
998
	xchg		eax, ebx
999
 
1000
	mov		ecx, 3
1001
 
1002
  .color:
1003
	rol		eax, 8
1004
	rol		ebx, 8
1005
	shl		ax, 8
1006
	neg		bl
1007
	add		bl, 0xff
1008
	test		bl, bl
1009
	jz		.clamp1
1010
	cmp		ah,  bl
1011
	jae		.clamp2
1012
	div		bl
1013
	jmp		.done
1014
  .clamp1:
1015
	mov		al, 0xff
1016
	test		ah, ah
1017
	jnz		@f
1018
	not		al
1019
    @@:
1020
	jmp		.done
1021
  .clamp2:
1022
	mov		al, 0xff
1023
	jmp		.done
1024
  .done:
1025
	mov		ah, al
1026
	loop		.color
1027
 
1028
	ror		eax, 8
1029
 
1030
 
1031
	push		eax
1032
	movq		xmm1, xmm3
1033
	psrldq		xmm1, 4
1034
	movd		eax, xmm1
1035
	movq		xmm1, xmm2
1036
	psrldq		xmm1, 4
1037
	movd		ebx, xmm1
1038
 
1039
 
1040
	rol		eax, 8
1041
	rol		ebx, 8
1042
 
1043
	xchg		eax, ebx
1044
 
1045
	mov		ecx, 3
1046
 
1047
  .color2:
1048
	rol		eax, 8
1049
	rol		ebx, 8
1050
	shl		ax, 8
1051
	neg		bl
1052
	add		bl, 0xff
1053
	test		bl, bl
1054
	jz		.clamp12
1055
	cmp		ah,  bl
1056
	jae		.clamp22
1057
	div		bl
1058
	jmp		.done2
1059
  .clamp12:
1060
	mov		al, 0xff
1061
	test		ah, ah
1062
	jnz		@f
1063
	not		al
1064
    @@:
1065
	jmp		.done2
1066
  .clamp22:
1067
	mov		al, 0xff
1068
	jmp		.done2
1069
  .done2:
1070
	mov		ah, al
1071
	loop		.color2
1072
 
1073
	ror		eax, 8
1074
 
1075
 
1076
	movd		xmm3, eax
1077
	pslldq		xmm3, 4
1078
	pop		eax
1079
	movd		xmm1, eax
1080
	paddq		xmm3, xmm1
1081
 
1082
	punpcklbw	xmm2, xmm0
1083
	punpcklbw	xmm3, xmm0
1084
 
1085
	pop		ecx ebx eax
1086
	ret
1087
endp
1088
 
1089
 
1090
proc	xcf._.composite_rgb_17			; Burn
1091
	push		eax ebx ecx
1092
 
1093
	movd		eax, xmm3
1094
	movd		ebx, xmm2
1095
 
1096
	rol		eax, 8
1097
	rol		ebx, 8
1098
 
1099
	xchg		eax, ebx
1100
 
1101
	mov		ecx, 3
1102
 
1103
  .color:
1104
	rol		eax, 8
1105
	rol		ebx, 8
1106
	shl		ax, 8
1107
	neg		ah
1108
	add		ah, 0xff
1109
	test		bl, bl
1110
	jz		.clamp1
1111
	cmp		ah, bl
1112
	jae		.clamp2
1113
	div		bl
1114
	jmp		.done
1115
  .clamp1:
1116
	mov		al, 0xff
1117
	test		ah, ah
1118
	jnz		@f
1119
	not		al
1120
    @@:
1121
	jmp		.done
1122
  .clamp2:
1123
	mov		al, 0xff
1124
	jmp		.done
1125
  .done:
1126
	mov		ah, al
1127
	neg		ah
1128
	add		ah, 0xff
1129
	loop		.color
1130
 
1131
	ror		eax, 8
1132
 
1133
 
1134
	push		eax
1135
	movq		xmm1, xmm3
1136
	psrldq		xmm1, 4
1137
	movd		eax, xmm1
1138
	movq		xmm1, xmm2
1139
	psrldq		xmm1, 4
1140
	movd		ebx, xmm1
1141
 
1142
 
1143
	rol		eax, 8
1144
	rol		ebx, 8
1145
 
1146
	xchg		eax, ebx
1147
 
1148
	mov		ecx, 3
1149
 
1150
  .color2:
1151
	rol		eax, 8
1152
	rol		ebx, 8
1153
	shl		ax, 8
1154
	neg		ah
1155
	add		ah, 0xff
1156
	test		bl, bl
1157
	jz		.clamp12
1158
	cmp		ah, bl
1159
	jae		.clamp22
1160
	div		bl
1161
	jmp		.done2
1162
  .clamp12:
1163
	mov		al, 0xff
1164
	test		ah, ah
1165
	jnz		@f
1166
	not		al
1167
    @@:
1168
	jmp		.done2
1169
  .clamp22:
1170
	mov		al, 0xff
1171
	jmp		.done2
1172
  .done2:
1173
	mov		ah, al
1174
	neg		ah
1175
	add		ah, 0xff
1176
	loop		.color2
1177
 
1178
	ror		eax, 8
1179
 
1180
 
1181
	movd		xmm3, eax
1182
	pslldq		xmm3, 4
1183
	pop		eax
1184
	movd		xmm1, eax
1185
	paddq		xmm3, xmm1
1186
 
1187
	punpcklbw	xmm2, xmm0
1188
	punpcklbw	xmm3, xmm0
1189
 
1190
	pop		ecx ebx eax
1191
	ret
1192
endp
1193
 
1194
 
1195
proc	xcf._.composite_rgb_18			; Hard Light
1196
	push		eax ebx ecx
1197
 
1198
	movd		eax, xmm3
1199
	movd		ebx, xmm2
1200
 
1201
	rol		eax, 8
1202
	rol		ebx, 8
1203
 
1204
	mov		ecx, 3
1205
 
1206
  .color:
1207
	rol		eax, 8
1208
	rol		ebx, 8
1209
	cmp		al, 127
1210
	jna		.part1
1211
	mov		ah, 0xff
1212
	sub		ah, bl
1213
	neg		al
1214
	add		al, 0xff
1215
	mul		ah
1216
	shl		ax, 1
1217
	neg		ah
1218
	add		ah, 0xff
1219
	jmp		.done
1220
  .part1:
1221
	mul		bl
1222
	shl		ax, 1
1223
  .done:
1224
	loop		.color
1225
 
1226
	ror		eax, 8
1227
 
1228
 
1229
	push		eax
1230
	movq		xmm1, xmm3
1231
	psrldq		xmm1, 4
1232
	movd		eax, xmm1
1233
	movq		xmm1, xmm2
1234
	psrldq		xmm1, 4
1235
	movd		ebx, xmm1
1236
 
1237
 
1238
	rol		eax, 8
1239
	rol		ebx, 8
1240
 
1241
	mov		ecx, 3
1242
 
1243
  .color2:
1244
	rol		eax, 8
1245
	rol		ebx, 8
1246
	cmp		al, 127
1247
	jna		.part12
1248
	mov		ah, 0xff
1249
	sub		ah, bl
1250
	neg		al
1251
	add		al, 0xff
1252
	mul		ah
1253
	shl		ax, 1
1254
	neg		ah
1255
	add		ah, 0xff
1256
	jmp		.done2
1257
  .part12:
1258
	mul		bl
1259
	shl		ax, 1
1260
  .done2:
1261
	loop		.color2
1262
 
1263
	ror		eax, 8
1264
 
1265
 
1266
	movd		xmm3, eax
1267
	pslldq		xmm3, 4
1268
	pop		eax
1269
	movd		xmm1, eax
1270
	paddq		xmm3, xmm1
1271
 
1272
	punpcklbw	xmm2, xmm0
1273
	punpcklbw	xmm3, xmm0
1274
 
1275
	pop		ecx ebx eax
1276
	ret
1277
endp
1278
 
1279
 
1280
proc	xcf._.composite_rgb_20			; Grain Extract
1281
 
1282
	punpcklbw	xmm2, xmm0
1283
	punpcklbw	xmm3, xmm0
1284
	movdqu		xmm4, xmm2
1285
	psubw		xmm3, xword[xcf._.xmm_0080]
1286
	psubw		xmm4, xmm3
1287
	movdqa		xmm3, xmm4
1288
	packuswb	xmm3, xmm0
1289
	punpcklbw	xmm3, xmm0
1290
	ret
1291
endp
1292
 
1293
 
1294
proc	xcf._.composite_rgb_21			; Grain Merge
1295
 
1296
	punpcklbw	xmm2, xmm0
1297
	punpcklbw	xmm3, xmm0
1298
	paddw		xmm3, xmm2
1299
	psubusw		xmm3, xword[xcf._.xmm_0080]
1300
	packuswb	xmm3, xmm0
1301
	punpcklbw	xmm3, xmm0
1302
	ret
1303
endp
1304
 
1305
 
1306
; starting numbers for pseudo-random number generator
1307
xcf._.random_a		dd	1103515245
1308
xcf._.random_b		dd	777
1309
xcf._.random_c		dd	12345
1310
 
1311
xcf._.xmm_8080		dq	0x8080808080808080, 0x8080808080808080
1312
xcf._.xmm_0080		dq	0x0080008000800080, 0x0080008000800080
1313
xcf._.xmm_00ff		dq	0x00ff00ff00ff00ff, 0x00ff00ff00ff00ff
1314
xcf._.xmm_0100		dq	0x0100010001000100, 0x0100010001000100
1315
xcf._.xmm_000000ff	dq	0x000000ff000000ff, 0x0000000000000000