Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
8341 dunkaist 1
;;================================================================================================;;
2
;;//// blend_mmx.asm //// (c) dunkaist, 2011-2012 ////////////////////////////////////////////////;;
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
 
2388 dunkaist 20
proc	xcf._.blend_rgb
1921 dunkaist 21
 
2388 dunkaist 22
	xchg		al, bh
23
	mov		ah, bh
24
	neg		ax
25
	add		ax, 0xffff
26
	mul		ah
27
	neg		ah
28
	add		ah, 0xff
29
	xchg		ah, bh
1921 dunkaist 30
 
2388 dunkaist 31
	mov		al, 0xff
32
	cmp		ah, bh
33
	je		@f
34
	not		al
35
	div		bh
36
    @@:
1921 dunkaist 37
 
2388 dunkaist 38
	mov		ah, al
1921 dunkaist 39
 
2388 dunkaist 40
	movd		mm1, eax
41
	punpcklbw	mm1, mm1
42
	punpcklbw	mm1, mm0
1921 dunkaist 43
 
2388 dunkaist 44
	movq		mm7, mm1
45
	psrlw		mm7, 7
46
	paddw		mm1, mm7
1921 dunkaist 47
 
2388 dunkaist 48
	psubw		mm3, mm2
49
	pmullw		mm3, mm1
50
	psllw		mm2, 8
51
	paddw		mm3, mm2
52
	psrlw		mm3, 8
53
	packuswb	mm3, mm0
54
	movd		eax, mm3
9273 dunkaist 55
	rol		eax, 8
56
	mov		al, bh
57
	ror		eax, 8
2388 dunkaist 58
	ret
1921 dunkaist 59
endp
60
 
61
 
2388 dunkaist 62
proc	xcf._.blend_gray
1921 dunkaist 63
 
2388 dunkaist 64
	xchg		al, bh
65
	mov		ah, bh
66
	neg		ax
67
	add		ax, 0xffff
68
	mul		ah
69
	neg		ah
70
	add		ah, 0xff
71
	xchg		ah, bh
1921 dunkaist 72
 
2388 dunkaist 73
	mov		al, 0xff
74
	cmp		ah, bh
75
	je		@f
76
	not		al
77
	div		bh
78
    @@:
1921 dunkaist 79
 
2388 dunkaist 80
	mov		ah, al
1921 dunkaist 81
 
2388 dunkaist 82
	movd		mm1, eax
83
	punpcklbw	mm1, mm1
84
	punpcklbw	mm1, mm0
1921 dunkaist 85
 
2388 dunkaist 86
	movq		mm7, mm1
87
	psrlw		mm7, 7
88
	paddw		mm1, mm7
1921 dunkaist 89
 
2388 dunkaist 90
	psubw		mm3, mm2
91
	pmullw		mm3, mm1
92
	psllw		mm2, 8
93
	paddw		mm3, mm2
94
	psrlw		mm3, 8
95
	packuswb	mm3, mm0
96
	movd		eax, mm3
9273 dunkaist 97
	mov		ah, bh
2388 dunkaist 98
 
99
	ret
1921 dunkaist 100
endp
101
 
102
 
2388 dunkaist 103
proc	xcf._.merge_32 _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
104
  .rgb_line:
105
	mov		ecx, [_copy_width]
106
  .rgb_pixel:
107
	mov		ebx, [edi]
108
	lodsd
109
 
110
	movd		mm2, ebx
111
	movd		mm3, eax
112
	shr		eax, 24
113
	shr		ebx, 16
114
	cmp		al, bh
115
	jna		@f
116
	mov		al, bh
117
    @@:
118
	pxor		mm0, mm0
119
	call		edx
120
	call		xcf._.blend_rgb
121
	stosd
122
	dec		ecx
123
	jnz		.rgb_pixel
124
	add		esi, [_img_total_bpl]
125
	add		edi, [_bottom_total_bpl]
126
	dec		[_copy_height]
127
	jnz		.rgb_line
128
	emms
129
	ret
1921 dunkaist 130
endp
131
 
132
 
2388 dunkaist 133
proc	xcf._.merge_8a _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
134
  .gray_line:
135
	mov		ecx, [_copy_width]
136
  .gray_pixel:
137
	mov		bx,  word[edi]
138
	lodsw
139
	movd		mm2, ebx
140
	movd		mm3, eax
141
	shr		eax, 8
142
	cmp		al, bh
143
	jna		@f
144
	mov		al, bh
145
    @@:
146
	pxor		mm0, mm0
147
	call		edx
148
	call		xcf._.blend_gray
149
	stosw
150
	dec		ecx
151
	jnz		.gray_pixel
152
	add		esi, [_img_total_bpl]
153
	add		edi, [_bottom_total_bpl]
154
	dec		[_copy_height]
155
	jnz		.gray_line
156
	emms
157
	ret
1921 dunkaist 158
endp
159
 
160
 
2388 dunkaist 161
proc	xcf._.composite_rgb_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
1921 dunkaist 162
 
2388 dunkaist 163
  .line:
164
	mov		ecx, [_copy_width]
165
  .pixel:
166
	mov		ebx, [edi]
167
	lodsd
168
	movd		mm2, ebx
169
	movd		mm3, eax
1921 dunkaist 170
 
2388 dunkaist 171
	shr		eax, 24
172
	shr		ebx, 16
1921 dunkaist 173
 
2388 dunkaist 174
	xchg		al, bh
175
	mov		ah, bh
176
	neg		ax
177
	add		ax, 0xffff
178
	mul		ah
179
	neg		ah
180
	add		ah, 0xff
181
	xchg		ah, bh
1921 dunkaist 182
 
2388 dunkaist 183
	mov		al, 0xff
184
	cmp		ah, bh
185
	je		@f
186
	not		al
187
	div		bh
188
    @@:
1921 dunkaist 189
 
2388 dunkaist 190
	mov		ah, al
1921 dunkaist 191
 
2388 dunkaist 192
	movd		mm1, eax
193
	pxor		mm0, mm0
194
	punpcklbw	mm1, mm1
195
	punpcklbw	mm1, mm0
196
	punpcklbw	mm2, mm0
197
	punpcklbw	mm3, mm0
1921 dunkaist 198
 
2388 dunkaist 199
	psubsw		mm3, mm2
200
	pmullw		mm3, mm1
201
	psllw		mm2, 8
202
	paddw		mm3, mm2
203
	psrlw		mm3, 8
204
	packuswb	mm3, mm0
205
	movd		eax, mm3
9273 dunkaist 206
	rol		eax, 8
207
	mov		al, bh
208
	ror		eax, 8
2388 dunkaist 209
	stosd
210
 
211
	dec		ecx
212
	jnz		.pixel
213
	add		esi, [_img_total_bpl]
214
	add		edi, [_bottom_total_bpl]
215
	dec		[_copy_height]
216
	jnz		.line
217
 
218
	ret
1921 dunkaist 219
endp
220
 
221
 
2388 dunkaist 222
proc	xcf._.composite_gray_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
1921 dunkaist 223
 
2388 dunkaist 224
  .line:
225
	mov		ecx, [_copy_width]
226
  .pixel:
227
	mov		bx, [edi]
228
	lodsw
229
	movd		mm2, ebx
230
	movd		mm3, eax
1921 dunkaist 231
 
2388 dunkaist 232
	shr		eax, 8
1921 dunkaist 233
 
2388 dunkaist 234
	xchg		al, bh
235
	mov		ah, bh
236
	neg		ax
237
	add		ax, 0xffff
238
	mul		ah
239
	neg		ah
240
	add		ah, 0xff
241
	xchg		ah, bh
1921 dunkaist 242
 
2388 dunkaist 243
	mov		al, 0xff
244
	cmp		ah, bh
245
	je		@f
246
	not		al
247
	div		bh
248
    @@:
1921 dunkaist 249
 
2388 dunkaist 250
	mov		ah, al
1921 dunkaist 251
 
2388 dunkaist 252
	movd		mm1, eax
253
	pxor		mm0, mm0
254
	punpcklbw	mm1, mm1
255
	punpcklbw	mm1, mm0
256
	punpcklbw	mm2, mm0
257
	punpcklbw	mm3, mm0
1921 dunkaist 258
 
2388 dunkaist 259
	psubw		mm3, mm2
260
	pmullw		mm3, mm1
261
	psllw		mm2, 8
262
	paddw		mm3, mm2
263
	psrlw		mm3, 8
264
	packuswb	mm3, mm0
265
	movd		eax, mm3
9273 dunkaist 266
	mov		ah, bh
2388 dunkaist 267
	stosw
268
 
269
	dec		ecx
270
	jnz		.pixel
271
	add		esi, [_img_total_bpl]
272
	add		edi, [_bottom_total_bpl]
273
	dec		[_copy_height]
274
	jnz		.line
275
 
276
	ret
1921 dunkaist 277
endp
278
 
279
 
2388 dunkaist 280
proc	xcf._.composite_indexed_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
1921 dunkaist 281
 
2388 dunkaist 282
  .line:
283
	mov		ecx, [_copy_width]
284
  .pixel:
285
	mov		bx, [edi]
286
	lodsw
1921 dunkaist 287
 
2388 dunkaist 288
	or		ah, 0x7f
289
	test		ah, 0x80
290
	jnz		@f
291
	mov		ax, bx
292
    @@:
293
	stosw
1921 dunkaist 294
 
2388 dunkaist 295
	dec		ecx
296
	jnz		.pixel
297
	add		esi, [_img_total_bpl]
298
	add		edi, [_bottom_total_bpl]
299
	dec		[_copy_height]
300
	jnz		.line
301
	ret
1921 dunkaist 302
endp
303
 
304
 
2388 dunkaist 305
proc	xcf._.composite_rgb_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
306
	pushad
1921 dunkaist 307
 
2388 dunkaist 308
	pxor		mm4, mm4
309
	movd		mm4, [xcf._.random_b]
310
	movd		mm1, [xcf._.random_a]
311
	movd		mm2, [xcf._.random_c]
1921 dunkaist 312
 
2388 dunkaist 313
  .line:
314
	mov		ecx, [_copy_width]
315
  .pixel:
316
	mov		ebx, [edi]
317
	lodsd
1921 dunkaist 318
 
2388 dunkaist 319
	movq		mm0, mm4
320
	pmuludq		mm0, mm1
321
	paddq		mm0, mm2
322
	movd		edx, mm0
323
	movd		mm4, edx
324
	pxor		mm0, mm0
325
 
326
	rol		eax, 8
327
	test		al, al
328
	jz		@f
329
	shr		edx, 17
330
	cmp		dl, al
331
	ja		@f
332
	ror		eax, 8
333
	or		eax, 0xff000000
334
	jmp		.done
335
    @@:
336
	mov		eax, ebx
337
  .done:
338
	stosd
339
	dec		ecx
340
	jnz		.pixel
341
	add		esi, [_img_total_bpl]
342
	add		edi, [_bottom_total_bpl]
343
	dec		[_copy_height]
344
	jnz		.line
345
 
346
  .quit:
347
	popad
348
	ret
1921 dunkaist 349
endp
350
 
351
 
2388 dunkaist 352
proc	xcf._.composite_gray_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
353
	pushad
1921 dunkaist 354
 
2388 dunkaist 355
	pxor		mm4, mm4
356
	movd		mm4, [xcf._.random_b]
357
	movd		mm1, [xcf._.random_a]
358
	movd		mm2, [xcf._.random_c]
1921 dunkaist 359
 
2388 dunkaist 360
  .line:
361
	mov		ecx, [_copy_width]
362
  .pixel:
363
	mov		ebx, [edi]
364
	lodsw
365
 
366
	movq		mm0, mm4
367
	pmuludq		mm0, mm1
368
	paddq		mm0, mm2
369
	movd		edx, mm0
370
	movd		mm4, edx
371
	pxor		mm0, mm0
372
 
373
	test		ah, ah
374
	jz		@f
375
	shr		edx, 17
376
	cmp		dl, ah
377
	ja		@f
378
	or		ax, 0xff00
379
	jmp		.done
380
    @@:
381
	mov		eax, ebx
382
  .done:
383
	stosw
384
	dec		ecx
385
	jnz		.pixel
386
	add		esi, [_img_total_bpl]
387
	add		edi, [_bottom_total_bpl]
388
	dec		[_copy_height]
389
	jnz		.line
390
 
391
  .quit:
392
	popad
393
	ret
1921 dunkaist 394
endp
395
 
396
 
2388 dunkaist 397
proc	xcf._.composite_rgb_03			; Multiply
1921 dunkaist 398
 
2388 dunkaist 399
	punpcklbw	mm2, mm0
400
	punpcklbw	mm3, mm0
401
	pmullw		mm3, mm2
402
	psrlw		mm3, 8
1921 dunkaist 403
 
2388 dunkaist 404
	ret
1921 dunkaist 405
endp
406
 
407
 
2388 dunkaist 408
proc	xcf._.composite_rgb_04			; Screen
1921 dunkaist 409
 
2388 dunkaist 410
	punpcklbw	mm2, mm0
411
	punpcklbw	mm3, mm0
2733 dunkaist 412
	movq		mm4, [xcf._.mmx_00ff]
413
	movq		mm5, mm4
414
	psubw		mm5, mm3
415
	movq		mm3, mm4
2388 dunkaist 416
	psubw		mm4, mm2
2733 dunkaist 417
	pmullw		mm4, mm5
418
	psrlw		mm4, 8
419
	psubw		mm3, mm4
420
 
2388 dunkaist 421
	ret
1921 dunkaist 422
endp
423
 
424
 
2388 dunkaist 425
proc	xcf._.composite_rgb_05			; Overlay
1921 dunkaist 426
 
2388 dunkaist 427
	punpcklbw	mm2, mm0
428
	punpcklbw	mm3, mm0
429
	movq		mm4, [xcf._.mmx_00ff]
430
	psubw		mm4, mm2
431
	pmullw		mm3, mm4
432
	psrlw		mm3, 7
433
	paddw		mm3, mm2
434
	pmullw		mm3, mm2
435
	psrlw		mm3, 8
436
 
437
	ret
1921 dunkaist 438
endp
439
 
440
 
2388 dunkaist 441
proc	xcf._.composite_rgb_06			; Difference
1921 dunkaist 442
 
2388 dunkaist 443
	movq		mm4, mm3
444
	pminub		mm4, mm2
445
	pmaxub		mm3, mm2
446
	psubusb		mm3, mm4
447
	punpcklbw	mm2, mm0
448
	punpcklbw	mm3, mm0
1921 dunkaist 449
 
2388 dunkaist 450
	ret
1921 dunkaist 451
endp
452
 
453
 
2388 dunkaist 454
proc	xcf._.composite_rgb_07			; Addition
1921 dunkaist 455
 
2388 dunkaist 456
	paddusb		mm3, mm2
457
	punpcklbw	mm2, mm0
458
	punpcklbw	mm3, mm0
1921 dunkaist 459
 
2388 dunkaist 460
	ret
1921 dunkaist 461
endp
462
 
463
 
2388 dunkaist 464
proc	xcf._.composite_rgb_08			; Subtract
1921 dunkaist 465
 
2388 dunkaist 466
	movq		mm4, mm2
467
	psubusb		mm4, mm3
468
	movq		mm3, mm4
469
	punpcklbw	mm2, mm0
470
	punpcklbw	mm3, mm0
1921 dunkaist 471
 
2388 dunkaist 472
	ret
1921 dunkaist 473
endp
474
 
475
 
2388 dunkaist 476
proc	xcf._.composite_rgb_09			; Darken Only
1921 dunkaist 477
 
2388 dunkaist 478
	pminub		mm3, mm2
479
	punpcklbw	mm2, mm0
480
	punpcklbw	mm3, mm0
1921 dunkaist 481
 
2388 dunkaist 482
	ret
1921 dunkaist 483
endp
484
 
485
 
2388 dunkaist 486
proc	xcf._.composite_rgb_10			; Lighten Only
1921 dunkaist 487
 
2388 dunkaist 488
	pmaxub		mm3, mm2
489
	punpcklbw	mm2, mm0
490
	punpcklbw	mm3, mm0
1921 dunkaist 491
 
2388 dunkaist 492
	ret
1921 dunkaist 493
endp
494
 
495
 
2388 dunkaist 496
proc	xcf._.composite_rgb_11			; Hue (H of HSV)
497
	push		eax ebx ecx edx
1921 dunkaist 498
 
2388 dunkaist 499
	movd		eax, mm3
500
	movd		ebx, mm2
1921 dunkaist 501
 
2388 dunkaist 502
	call		xcf._.rgb2hsv
503
	xchg		eax, ebx
504
	call		xcf._.rgb2hsv
505
	xchg		eax, ebx
1921 dunkaist 506
 
2388 dunkaist 507
	test		ah, ah
508
	jnz		@f
509
	ror		eax, 8
510
	ror		ebx, 8
511
	mov		ah, bh
512
	rol		eax, 8
513
	rol		ebx, 8
514
    @@:
515
	mov		ax, bx
516
 
517
	call		xcf._.hsv2rgb
518
 
519
	movd		mm3, eax
520
 
521
	punpcklbw	mm2, mm0
522
	punpcklbw	mm3, mm0
523
 
524
  .quit:
525
	pop		edx ecx ebx eax
526
	ret
1921 dunkaist 527
endp
528
 
529
 
2388 dunkaist 530
proc	xcf._.composite_rgb_12			; Saturation (S of HSV)
531
	push		eax ebx ecx edx
1921 dunkaist 532
 
2388 dunkaist 533
	movd		eax, mm3
534
	movd		ebx, mm2
1921 dunkaist 535
 
2388 dunkaist 536
	call		xcf._.rgb2hsv
537
	xchg		eax, ebx
538
	call		xcf._.rgb2hsv
539
	xchg		eax, ebx
1921 dunkaist 540
 
2388 dunkaist 541
	ror		eax, 8
542
	ror		ebx, 8
543
	mov		ah, bh
544
	rol		eax, 8
545
	rol		ebx, 8
546
	mov		al, bl
1921 dunkaist 547
 
2388 dunkaist 548
	call		xcf._.hsv2rgb
1921 dunkaist 549
 
550
 
2388 dunkaist 551
	movd		mm3, eax
1921 dunkaist 552
 
2388 dunkaist 553
	punpcklbw	mm2, mm0
554
	punpcklbw	mm3, mm0
1921 dunkaist 555
 
2388 dunkaist 556
  .quit:
557
	pop		edx ecx ebx eax
558
	ret
1921 dunkaist 559
endp
560
 
561
 
2388 dunkaist 562
proc	xcf._.composite_rgb_13			; Color (H and S of HSL)
563
	push		eax ebx ecx edx
1921 dunkaist 564
 
2388 dunkaist 565
	movd		eax, mm3
566
	movd		ebx, mm2
1921 dunkaist 567
 
2388 dunkaist 568
	call		xcf._.rgb2hsl
569
	xchg		eax,    ebx
570
	call		xcf._.rgb2hsl
571
	xchg		eax,    ebx
1921 dunkaist 572
 
2388 dunkaist 573
	mov		al, bl
574
 
575
	call		xcf._.hsl2rgb
576
 
577
 
578
	movd		mm3, eax
579
 
580
	punpcklbw	mm2, mm0
581
	punpcklbw	mm3, mm0
582
 
583
  .quit:
584
	pop		edx ecx ebx eax
585
	ret
1921 dunkaist 586
endp
587
 
588
 
2388 dunkaist 589
proc	xcf._.composite_rgb_14			; Value (V of HSV)
590
	push		eax ebx ecx edx
1921 dunkaist 591
 
2388 dunkaist 592
	movd		eax, mm3
593
	movd		ebx, mm2
1921 dunkaist 594
 
2388 dunkaist 595
	call		xcf._.rgb2hsv
596
	xchg		eax, ebx
597
	call		xcf._.rgb2hsv
598
	xchg		eax, ebx
1921 dunkaist 599
 
2388 dunkaist 600
	ror		eax, 8
601
	ror		ebx, 8
602
	mov		ax, bx
603
	rol		eax, 8
604
	rol		ebx, 8
1921 dunkaist 605
 
2388 dunkaist 606
	call		xcf._.hsv2rgb
1921 dunkaist 607
 
608
 
2388 dunkaist 609
	movd		mm3, eax
1921 dunkaist 610
 
2388 dunkaist 611
	punpcklbw	mm2, mm0
612
	punpcklbw	mm3, mm0
1921 dunkaist 613
 
2388 dunkaist 614
  .quit:
615
	pop		edx ecx ebx eax
616
	ret
1921 dunkaist 617
endp
618
 
619
 
2388 dunkaist 620
proc	xcf._.composite_rgb_15			; Divide
621
	push		eax ebx ecx
1921 dunkaist 622
 
2388 dunkaist 623
	movd		eax, mm3
624
	movd		ebx, mm2
1921 dunkaist 625
 
2388 dunkaist 626
	rol		eax, 8
627
	rol		ebx, 8
1921 dunkaist 628
 
2388 dunkaist 629
	xchg		eax, ebx
1921 dunkaist 630
 
2388 dunkaist 631
	mov		ecx, 3
1921 dunkaist 632
 
2388 dunkaist 633
  .color:
634
	rol		eax, 8
635
	rol		ebx, 8
636
	shl		ax, 8
637
	test		bl, bl
638
	jz		.clamp1
639
	cmp		ah, bl
640
	jae		.clamp2
641
	div		bl
642
	jmp		.done
643
  .clamp1:
644
	mov		al, 0xff
645
	test		ah, ah
646
	jnz		@f
647
	not		al
648
    @@:
649
	jmp		.done
650
  .clamp2:
651
	mov		al, 0xff
652
	jmp		.done
653
  .done:
654
	mov		ah, al
655
	loop		.color
1921 dunkaist 656
 
2388 dunkaist 657
	ror		eax, 8
658
	movd		mm3, eax
1921 dunkaist 659
 
2388 dunkaist 660
	punpcklbw	mm2, mm0
661
	punpcklbw	mm3, mm0
662
 
663
	pop		ecx ebx eax
664
	ret
1921 dunkaist 665
endp
666
 
667
 
2388 dunkaist 668
proc	xcf._.composite_rgb_16			; Dodge
669
	push		eax ebx ecx
1921 dunkaist 670
 
2388 dunkaist 671
	movd		eax, mm3
672
	movd		ebx, mm2
1921 dunkaist 673
 
2388 dunkaist 674
	rol		eax, 8
675
	rol		ebx, 8
1921 dunkaist 676
 
2388 dunkaist 677
	xchg		eax, ebx
1921 dunkaist 678
 
2388 dunkaist 679
	mov		ecx, 3
1921 dunkaist 680
 
2388 dunkaist 681
  .color:
682
	rol		eax, 8
683
	rol		ebx, 8
684
	shl		ax, 8
685
	neg		bl
686
	add		bl, 0xff
687
	test		bl, bl
688
	jz		.clamp1
689
	cmp		ah,  bl
690
	jae		.clamp2
691
	div		bl
692
	jmp		.done
693
  .clamp1:
694
	mov		al, 0xff
695
	test		ah, ah
696
	jnz		@f
697
	not		al
698
    @@:
699
	jmp		.done
700
  .clamp2:
701
	mov		al, 0xff
702
	jmp		.done
703
  .done:
704
	mov		ah, al
705
	loop		.color
1921 dunkaist 706
 
2388 dunkaist 707
	ror		eax, 8
708
	movd		mm3, eax
1921 dunkaist 709
 
2388 dunkaist 710
	punpcklbw	mm2, mm0
711
	punpcklbw	mm3, mm0
712
 
713
	pop		ecx ebx eax
714
	ret
1921 dunkaist 715
endp
716
 
717
 
2388 dunkaist 718
proc	xcf._.composite_rgb_17			; Burn
719
	push		eax ebx ecx
1921 dunkaist 720
 
2388 dunkaist 721
	movd		eax, mm3
722
	movd		ebx, mm2
1921 dunkaist 723
 
2388 dunkaist 724
	rol		eax, 8
725
	rol		ebx, 8
1921 dunkaist 726
 
2388 dunkaist 727
	xchg		eax, ebx
1921 dunkaist 728
 
2388 dunkaist 729
	mov		ecx, 3
1921 dunkaist 730
 
2388 dunkaist 731
  .color:
732
	rol		eax, 8
733
	rol		ebx, 8
734
	shl		ax, 8
735
	neg		ah
736
	add		ah, 0xff
737
	test		bl, bl
738
	jz		.clamp1
739
	cmp		ah, bl
740
	jae		.clamp2
741
	div		bl
742
	jmp		.done
743
  .clamp1:
744
	mov		al, 0xff
745
	test		ah, ah
746
	jnz		@f
747
	not		al
748
    @@:
749
	jmp		.done
750
  .clamp2:
751
	mov		al, 0xff
752
	jmp		.done
753
  .done:
754
	mov		ah, al
755
	neg		ah
756
	add		ah, 0xff
757
	loop		.color
1921 dunkaist 758
 
2388 dunkaist 759
	ror		eax, 8
760
	movd		mm3, eax
1921 dunkaist 761
 
2388 dunkaist 762
	punpcklbw	mm2, mm0
763
	punpcklbw	mm3, mm0
764
 
765
	pop		ecx ebx eax
766
	ret
1921 dunkaist 767
endp
768
 
769
 
2388 dunkaist 770
proc	xcf._.composite_rgb_18			; Hard Light
771
	push		eax ebx ecx
1921 dunkaist 772
 
2388 dunkaist 773
	movd		eax, mm3
774
	movd		ebx, mm2
1921 dunkaist 775
 
2388 dunkaist 776
	rol		eax, 8
777
	rol		ebx, 8
778
 
779
	mov		ecx, 3
780
 
781
  .color:
782
	rol		eax, 8
783
	rol		ebx, 8
784
	cmp		al, 127
785
	jna		.part1
786
	mov		ah, 0xff
787
	sub		ah, bl
788
	neg		al
789
	add		al, 0xff
790
	mul		ah
791
	shl		ax, 1
792
	neg		ah
793
	add		ah, 0xff
794
	jmp		.done
795
  .part1:
796
	mul		bl
797
	shl		ax, 1
798
  .done:
799
	loop		.color
800
 
801
	ror		eax, 8
802
	movd		mm3, eax
803
 
804
	punpcklbw	mm2, mm0
805
	punpcklbw	mm3, mm0
806
 
807
	pop		ecx ebx eax
808
	ret
1921 dunkaist 809
endp
810
 
811
 
2388 dunkaist 812
proc	xcf._.composite_rgb_20			; Grain Extract
1921 dunkaist 813
 
2388 dunkaist 814
	punpcklbw	mm2, mm0
815
	punpcklbw	mm3, mm0
816
	movq		mm4, mm2
817
	psubw		mm3, [xcf._.mmx_0080]
818
	psubw		mm4, mm3
819
	movq		mm3, mm4
820
	packuswb	mm3, mm0
821
	punpcklbw	mm3, mm0
822
	ret
823
endp
1921 dunkaist 824
 
2388 dunkaist 825
 
826
proc	xcf._.composite_rgb_21			; Grain Merge
827
 
828
	punpcklbw	mm2, mm0
829
	punpcklbw	mm3, mm0
830
	paddw		mm3, mm2
831
	psubusw		mm3, [xcf._.mmx_0080]
832
	packuswb	mm3, mm0
833
	punpcklbw	mm3, mm0
834
	ret
1921 dunkaist 835
endp
836
 
837
 
2388 dunkaist 838
; starting numbers for pseudo-random number generator
839
xcf._.random_a		dd	1103515245
840
xcf._.random_b		dd	777
841
xcf._.random_c		dd	12345
842
 
843
xcf._.mmx_0080		dq	0x0080008000800080
844
xcf._.mmx_00ff		dq	0x00ff00ff00ff00ff
845
xcf._.mmx_0100		dq	0x0100010001000100