Code : Tout sélectionner
;*******************************************************************************
;Titre : Filter_enboss
;Date : 12/03/2022
;Version PB : PureBasic 5.70 LTS
; x64 seulement
; Windows
; linux - non testé
; ios - non testé
;
;Info : ne fonctionne qu'avec des images 32bits ( source , cible et masque )
; "la fonction "load_image" convertis les images 24bits en 32bits"
;
; : "Global Dim param(256)" est a declarer dans le programme principal
;*******************************************************************************
; NewPixel = Pixel1 - pixel2
; power : 1 < power < 50 : default = 10 : renfore ou diminue les details
; light : 0 < lihgt < 255 : defaut = 128 :
; si light = 0 => similaire a un filtre detection de contour
; si light = 255 => silimaire a un filtre sketch ( dessin crayon papier)
; option: 0 < option < 35
;Filter_Emboss( source , cible , power , light , option )
;Filter_Emboss( source , cible , power , light , option , mask )
Macro Filter_Emboss_grayscale_macro()
!PMULLd xmm0,xmm4 ; rgb = (r* $55 + g* $55 + b* $55) ; grayscale
!pshufd xmm1,xmm0,1 ; xmm1 = g * $55
!pshufd xmm2,xmm0,2 ; xmm2 = r * $55
!paddd xmm0,xmm1
!paddd xmm0,xmm2
!psrad xmm0,8
!movd eax,xmm0
!mov ecx,255 ; if eax > 255 : eax = 255 : endif
!cmp eax,ecx
!cmovg eax,ecx
!mov ecx,0 ; if eax < 0 : eax = 0 : endif
!cmp eax,ecx
!cmovl eax,ecx
!mov ah,al ; eax = eax * $10101
!shl eax,8
!mov al,ah
EndMacro
Macro Filter_Emboss_pos_macro()
!mov rdx,r8
!shl rdx,2
!add rcx,rdx
!mov ecx,[rcx]
!mov rax,[r9+24] ; param(3)
!mul rcx
!shl rax,2
!add rax,[r9+00] ; param(0)
EndMacro
Macro Filter_Emboss_pokel_macro()
!mov rax,[r9+24]
!mov rcx,r8
!mul rcx
!shl rax,2
!add rax,[r9+08]
EndMacro
Procedure Filter_EmbossV1(i) ; 2 pixels
Protected start,stop , p , s , d.f , p1,p2,p3
p=@param()
start =( param(4) / param(5) ) * i
stop = ( param(4) / param(5) ) * ( i + 1 )
If i = param(5) - 1
If stop < param(4) : stop = param(4) : EndIf
EndIf
d.f = param(6)
d = d / 10
Protected Dim Reg_memory.q(3*16)
s=@reg_memory()
!mov rax,[p.v_s]
!movdqu [rax+000],xmm4
!movdqu [rax+016],xmm5
!movdqu [rax+032],xmm6
!pxor xmm5,xmm5
!mov eax,$55
!movd xmm4,eax
!pshufd xmm4,xmm4,0
!movups xmm3,[p.v_d]
!pshufd xmm3,xmm3,0 ; xmm3 = d : d : d : d
!mov rax,[p.v_p]
!movd xmm12,[rax+56] ; light
!pshufd xmm12,xmm12,0 ; xmm2 = param(7)(32bits) : param(7)(32bits) : param(7)(32bits) : param(7)(32bits)
;For y=start To stop
!mov r8,[p.v_start]
!Filter_EmbossV1_boucle_y:
!mov r9,[p.v_p]
;p1 = param(0) + (PeekL(param(9) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+72] ; param(9)
Filter_Emboss_pos_macro()
!mov [p.v_p1],rax
;p2 = param(0) + (PeekL(param(11) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+88] ; param(11)
Filter_Emboss_pos_macro()
!mov [p.v_p2],rax
;p3 = param(1) + (y * (param(3)) << 2)
Filter_Emboss_pokel_macro()
!mov [p.v_p3],rax
!xor rdx,rdx
!Filter_EmbossV1_boucle_x: ; For x=0 To param(3)-1
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+64] ; (param(10) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p1]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+80] ; (param(12) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p2]
!movd xmm1,[rcx]
!punpcklbw xmm1,xmm5 ; coversion 8bits -> 16bits
!punpcklwd xmm0,xmm5 ; coversion 16bits -> 32bits
!punpcklwd xmm1,xmm5 ; coversion 16bits -> 32bits
!psubd xmm0,xmm1 ; r = (r1 - r2) : g = (g1 - g2) : b = (b1 - b2)
!cvtdq2ps xmm0,xmm0 ; r.f = r.i : g.f = g.i : b.f = b.i
!mulps xmm0,xmm3 ; r * d : g * d : b * d
!cvtps2dq xmm0,xmm0 ; r.i = r.f ...
!paddd xmm0,xmm12 ; param(7) + ( r * d ) ...
Filter_Emboss_grayscale_macro()
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add rcx,[p.v_p3]
!mov [rcx],eax
!inc rdx
!cmp rdx,[r9+24]
!jb Filter_EmbossV1_boucle_x ; next
!inc r8
!cmp r8,[p.v_stop]
!jb Filter_EmbossV1_boucle_y ; next
!mov rax,[p.v_s]
!movdqu xmm4,[rax+000]
!movdqu xmm5,[rax+016]
!movdqu xmm6,[rax+032]
FreeArray(Reg_memory())
EndProcedure
Procedure Filter_EmbossV2(i) ; 3 pixerls
Protected start,stop , p , s , d.f , p1,p2,p3,p4
p=@param()
start =( param(4) / param(5) ) * i
stop = ( param(4) / param(5) ) * ( i + 1 )
If i = param(5) - 1
If stop < param(4) : stop = param(4) : EndIf
EndIf
d.f = param(6)
d = d / 10
Protected Dim Reg_memory.q(3*16)
s=@reg_memory()
!mov rax,[p.v_s]
!movdqu [rax+000],xmm4
!movdqu [rax+016],xmm5
!movdqu [rax+032],xmm6
!pxor xmm5,xmm5
!mov eax,$55
!movd xmm4,eax
!pshufd xmm4,xmm4,0
!movups xmm3,[p.v_d]
!pshufd xmm3,xmm3,0 ; xmm3 = d : d : d : d
!mov rax,[p.v_p]
!movd xmm12,[rax+56] ; light
!pshufd xmm12,xmm12,0 ; xmm2 = param(7)(32bits) : param(7)(32bits) : param(7)(32bits) : param(7)(32bits)
;For y=start To stop
!mov r8,[p.v_start]
!Filter_EmbossV2_boucle_y:
!mov r9,[p.v_p]
;p1 = param(0) + (PeekL(param(9) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+72] ; param(9)
Filter_Emboss_pos_macro()
!mov [p.v_p1],rax
;p2 = param(0) + (PeekL(param(11) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+88] ; param(11)
Filter_Emboss_pos_macro()
!mov [p.v_p2],rax
;p3 = param(0) + (PeekL(param(13) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+104] ; param(13)
Filter_Emboss_pos_macro()
!mov [p.v_p3],rax
;p4 = param(1) + (y * (param(3)) << 2)
Filter_Emboss_pokel_macro()
!mov [p.v_p4],rax
!xor rdx,rdx
!Filter_EmbossV2_boucle_x: ; For x=0 To param(3)-1
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+64] ; (param(10) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p1]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+80] ; (param(11) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p2]
!movd xmm1,[rcx]
!punpcklbw xmm1,xmm5 ; coversion 8bits -> 16bits
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+96] ; (param(12) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p3]
!movd xmm2,[rcx]
!punpcklbw xmm2,xmm5 ; coversion 8bits -> 16bits
!punpcklwd xmm1,xmm5 ; coversion 16bits -> 32bits
;r=(param(7)+ ((r1*2)-(r2+r3)) * p)
!paddd xmm1,xmm1 ; r2=r2*2
!paddw xmm0,xmm2 ; r1 = r1 + r3
!punpcklwd xmm0,xmm5 ; coversion 16bits -> 32bits
!psubd xmm0,xmm1 ; r = (r1 + r3) - ( r2 * 2 )
!cvtdq2ps xmm0,xmm0 ; r.f = r.i : g.f = g.i : b.f = b.i
!mulps xmm0,xmm3 ; r * d : g * d : b * d
!cvtps2dq xmm0,xmm0 ; r.i = r.f ...
!paddd xmm0,xmm12 ; param(7) + ( r * d ) ...
Filter_Emboss_grayscale_macro()
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add rcx,[p.v_p4]
!mov [rcx],eax
!inc rdx
!cmp rdx,[r9+24]
!jb Filter_EmbossV2_boucle_x ; next
!inc r8
!cmp r8,[p.v_stop]
!jb Filter_EmbossV2_boucle_y ; next
!mov rax,[p.v_s]
!movdqu xmm4,[rax+000]
!movdqu xmm5,[rax+016]
!movdqu xmm6,[rax+032]
FreeArray(Reg_memory())
EndProcedure
Procedure Filter_EmbossV3(i) ; 5 pixerls
Protected start,stop , p , s , d.f , p0,p1,p2,p3,p4,p5
p=@param()
start =( param(4) / param(5) ) * i
stop = ( param(4) / param(5) ) * ( i + 1 )
If i = param(5) - 1
If stop < param(4) : stop = param(4) : EndIf
EndIf
d.f = param(6)
d = d / 10
Protected Dim Reg_memory.q(3*16)
s=@reg_memory()
!mov rax,[p.v_s]
!movdqu [rax+000],xmm4
!movdqu [rax+016],xmm5
!movdqu [rax+032],xmm6
!pxor xmm5,xmm5
!mov eax,$55
!movd xmm4,eax
!pshufd xmm4,xmm4,0
!movups xmm6,[p.v_d]
!pshufd xmm6,xmm6,0 ; xmm3 = d : d : d : d
!mov rax,[p.v_p]
!movd xmm12,[rax+56] ; light
!pshufd xmm12,xmm12,0 ; xmm2 = param(7)(32bits) : param(7)(32bits) : param(7)(32bits) : param(7)(32bits)
;For y=start To stop
!mov r8,[p.v_start]
!Filter_EmbossV3_boucle_y:
!mov r9,[p.v_p]
;p1 = param(0) + ( y * 4 * (param(3)) << 2)
!mov rdx,r8
!mov rax,[r9+24] ; param(3)
!mul rdx
!shl rax,2
!add rax,[r9+00] ; param(0)
!mov [p.v_p0],rax
;p1 = param(0) + (PeekL(param(9) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+72] ; param(9)
Filter_Emboss_pos_macro()
!mov [p.v_p1],rax
;p2 = param(0) + (PeekL(param(11) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+88] ; param(11)
Filter_Emboss_pos_macro()
!mov [p.v_p2],rax
;p3 = param(0) + (PeekL(param(13) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+104] ; param(13)
Filter_Emboss_pos_macro()
!mov [p.v_p3],rax
;p4 = param(0) + (PeekL(param(15) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+120] ; param(15)
Filter_Emboss_pos_macro()
!mov [p.v_p4],rax
;p5 = param(1) + (y * (param(3)) << 2)
Filter_Emboss_pokel_macro()
!mov [p.v_p5],rax
!xor rdx,rdx
!Filter_EmbossV3_boucle_x: ; For x=0 To param(3)-1
!pxor xmm0,xmm0
!pxor xmm1,xmm1
!mov r9,[p.v_p]
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+64] ; (param(10) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p1]
!movd xmm1,[rcx]
!punpcklbw xmm1,xmm5 ; coversion 8bits -> 16bits
!mov r9,[p.v_p]
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+80] ; (param(11) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p2]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov r9,[p.v_p]
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+96] ; (param(12) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p3]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov r9,[p.v_p]
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add ecx,[r9+112] ; (param(13) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p4]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!punpcklwd xmm1,xmm5 ; coversion 16bits -> 32bits
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add rcx,[p.v_p0]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!punpcklwd xmm0,xmm5 ; coversion 16bits -> 32bits
!paddd xmm0,xmm0
!paddd xmm0,xmm0
;r=(param(7)+ (r0 * 4) - (r1+r2+r3+r4)
!psubd xmm0,xmm1 ;
!cvtdq2ps xmm0,xmm0 ; r.f = r.i : g.f = g.i : b.f = b.i
!mulps xmm0,xmm6 ; r * d : g * d : b * d
!cvtps2dq xmm0,xmm0 ; r.i = r.f ...
!paddd xmm0,xmm12 ; param(7) + ( r * d ) ...
Filter_Emboss_grayscale_macro()
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add rcx,[p.v_p5]
!mov [rcx],eax
!mov rax,[p.v_p]
!inc rdx
!cmp rdx,[rax+24]
!jb Filter_EmbossV3_boucle_x ; next
!inc r8
!cmp r8,[p.v_stop]
!jb Filter_EmbossV3_boucle_y ; next
!mov rax,[p.v_s]
!movdqu xmm4,[rax+000]
!movdqu xmm5,[rax+016]
!movdqu xmm6,[rax+032]
FreeArray(Reg_memory())
EndProcedure
Procedure Filter_EmbossV4(i) ; 6 pixerls
Protected start,stop , p , s , d.f , p1,p2,p3,p4,p5,p6,p7
p=@param()
start =( param(4) / param(5) ) * i
stop = ( param(4) / param(5) ) * ( i + 1 )
If i = param(5) - 1
If stop < param(4) : stop = param(4) : EndIf
EndIf
d.f = param(6)
d = d / 10
Protected Dim Reg_memory.q(3*16)
s=@reg_memory()
!mov rax,[p.v_s]
!movdqu [rax+000],xmm4
!movdqu [rax+016],xmm5
!movdqu [rax+032],xmm6
!pxor xmm5,xmm5
!mov eax,$55
!movd xmm4,eax
!pshufd xmm4,xmm4,0
!movups xmm6,[p.v_d]
!pshufd xmm6,xmm6,0 ; xmm3 = d : d : d : d
!mov rax,[p.v_p]
!movd xmm12,[rax+56] ; light
!pshufd xmm12,xmm12,0 ; xmm2 = param(7)(32bits) : param(7)(32bits) : param(7)(32bits) : param(7)(32bits)
;For y=start To stop
!mov r8,[p.v_start]
!Filter_EmbossV4_boucle_y:
!mov r9,[p.v_p]
;p1 = param(0) + (PeekL(param(9) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+72] ; param(9)
Filter_Emboss_pos_macro()
!mov [p.v_p1],rax
;p2 = param(0) + (PeekL(param(11) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+88] ; param(11)
Filter_Emboss_pos_macro()
!mov [p.v_p2],rax
;p3 = param(0) + (PeekL(param(13) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+104] ; param(13)
Filter_Emboss_pos_macro()
!mov [p.v_p3],rax
;p4 = param(0) + (PeekL(param(15) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+120] ; param(15)
Filter_Emboss_pos_macro()
!mov [p.v_p4],rax
;p5 = param(0) + (PeekL(param(15) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+136] ; param(15)
Filter_Emboss_pos_macro()
!mov [p.v_p5],rax
;p6 = param(0) + (PeekL(param(15) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+152] ; param(15)
Filter_Emboss_pos_macro()
!mov [p.v_p6],rax
;p5 = param(1) + (y * (param(3)) << 2)
Filter_Emboss_pokel_macro()
!mov [p.v_p7],rax
!xor rdx,rdx
!Filter_EmbossV4_boucle_x: ; For x=0 To param(3)-1
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!mov rax,rcx
!add ecx,[r9+64] ; (param(10) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p1]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm0,xmm0 ; X2
!mov rcx,rax
!add ecx,[r9+80] ; (param(11) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p2]
!movd xmm1,[rcx]
!punpcklbw xmm1,xmm5 ; coversion 8bits -> 16bits
!mov rcx,rax
!add ecx,[r9+96] ; (param(12) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p3]
!movd xmm2,[rcx]
!punpcklbw xmm2,xmm5 ; coversion 8bits -> 16bits
!paddw xmm0,xmm1
!paddw xmm0,xmm2
!mov rcx,rax
!add ecx,[r9+112] ; (param(13) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p4]
!movd xmm1,[rcx]
!punpcklbw xmm1,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm1
!mov rcx,rax
!add ecx,[r9+128] ; (param(11) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p5]
!movd xmm2,[rcx]
!punpcklbw xmm2,xmm5 ; coversion 8bits -> 16bits
!mov rcx,rax
!add ecx,[r9+144] ; (param(12) + x*4)
!mov ecx,[rcx]
!add rcx,[p.v_p6]
!movd xmm3,[rcx]
!punpcklbw xmm3,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm2
!paddw xmm1,xmm3
!punpcklwd xmm0,xmm5 ; coversion 16bits -> 32bits
!punpcklwd xmm1,xmm5 ; coversion 16bits -> 32bits
;r=(param(7)+ (r0*2+r1+r2) - (r3*2+r4+r5)
!psubd xmm0,xmm1 ;
!cvtdq2ps xmm0,xmm0 ; r.f = r.i : g.f = g.i : b.f = b.i
!mulps xmm0,xmm6 ; r * d : g * d : b * d
!cvtps2dq xmm0,xmm0 ; r.i = r.f ...
!paddd xmm0,xmm12 ; param(7) + ( r * d ) ...
Filter_Emboss_grayscale_macro()
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add rcx,[p.v_p7]
!mov [rcx],eax
!mov rax,[p.v_p]
!inc rdx
!cmp rdx,[rax+24]
!jb Filter_EmbossV4_boucle_x ; next
!inc r8
!cmp r8,[p.v_stop]
!jb Filter_EmbossV4_boucle_y ; next
!mov rax,[p.v_s]
!movdqu xmm4,[rax+000]
!movdqu xmm5,[rax+016]
!movdqu xmm6,[rax+032]
FreeArray(Reg_memory())
EndProcedure
Procedure Filter_EmbossV5(i) ; 9 pixerls
Protected start,stop , p , s , d.f , p0,p1,p2,p3,p4,p5,p6,p7,p8,p9
p=@param()
start =( param(4) / param(5) ) * i
stop = ( param(4) / param(5) ) * ( i + 1 )
If i = param(5) - 1
If stop < param(4) : stop = param(4) : EndIf
EndIf
d.f = param(6)
d = d / 10
Protected Dim Reg_memory.q(3*16)
s=@reg_memory()
!mov rax,[p.v_s]
!movdqu [rax+000],xmm4
!movdqu [rax+016],xmm5
!movdqu [rax+032],xmm6
!pxor xmm5,xmm5
!mov eax,$55
!movd xmm4,eax
!pshufd xmm4,xmm4,0
!movups xmm6,[p.v_d]
!pshufd xmm6,xmm6,0 ; xmm3 = d : d : d : d
!mov rax,[p.v_p]
!movd xmm12,[rax+56] ; light
!pshufd xmm12,xmm12,0 ; xmm2 = param(7)(32bits) : param(7)(32bits) : param(7)(32bits) : param(7)(32bits)
;For y=start To stop
!mov r8,[p.v_start]
!Filter_EmbossV5_boucle_y:
!mov r9,[p.v_p]
;p1 = param(0) + (PeekL(param(9) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+72] ; param(9)
Filter_Emboss_pos_macro()
!mov [p.v_p1],rax
!mov [p.v_p2],rax
!mov [p.v_p3],rax
;p2 = param(0) + (PeekL(param(11) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+88] ; param(11)
Filter_Emboss_pos_macro()
!mov [p.v_p4],rax
!mov [p.v_p5],rax
!mov [p.v_p9],rax
;p3 = param(0) + (PeekL(param(13) + y * 4) * (param(3)) << 2)
!mov rcx,[r9+104] ; param(13)
Filter_Emboss_pos_macro()
!mov [p.v_p6],rax
!mov [p.v_p7],rax
!mov [p.v_p8],rax
;p5 = param(1) + (y * (param(3)) << 2)
Filter_Emboss_pokel_macro()
!mov [p.v_p0],rax
!xor rdx,rdx
!Filter_EmbossV5_boucle_x: ; For x=0 To param(3)-1
!mov rcx,rdx
!shl rcx,2
!add ecx,[r9+64] ; (param(10) + x*4)
!mov ecx,[rcx]
!mov eax,ecx
!add rcx,[p.v_p1]
!movd xmm1,[rcx]
!punpcklbw xmm1,xmm5 ; coversion 8bits -> 16bits
!mov ecx,eax
!add rcx,[p.v_p4]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov ecx,eax
!add rcx,[p.v_p6]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov rcx,rdx
!shl rcx,2
!add ecx,[r9+96] ; (param(12) + x*4)
!mov ecx,[rcx]
!mov eax,ecx
!add rcx,[p.v_p3]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov ecx,eax
!add rcx,[p.v_p5]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov ecx,eax
!add rcx,[p.v_p8]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov rcx,rdx
!shl rcx,2
!add ecx,[r9+80] ; (param(11) + x*4)
!mov ecx,[rcx]
!mov eax,ecx
!add rcx,[p.v_p7]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov ecx,eax
!add rcx,[p.v_p2]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!paddw xmm1,xmm0
!mov ecx,eax
!add rcx,[p.v_p9]
!movd xmm0,[rcx]
!punpcklbw xmm0,xmm5 ; coversion 8bits -> 16bits
!punpcklwd xmm0,xmm5 ; coversion 16bits -> 32bits
!pslld xmm0,3 ; X8
!punpcklwd xmm1,xmm5 ; coversion 16bits -> 32bits
;r=(r9*8) - (r1+r2+...r7+r8)
!psubd xmm0,xmm1 ;
!cvtdq2ps xmm0,xmm0 ; r.f = r.i : g.f = g.i : b.f = b.i
!mulps xmm0,xmm6 ; r * d : g * d : b * d
!cvtps2dq xmm0,xmm0 ; r.i = r.f ...
!paddd xmm0,xmm12 ; param(7) + ( r * d ) ...
Filter_Emboss_grayscale_macro()
!mov rcx,rdx;[p.v_x]
!shl rcx,2
!add rcx,[p.v_p0]
!mov [rcx],eax
!inc rdx
!cmp rdx,[r9+24]
!jb Filter_EmbossV5_boucle_x ; next
!inc r8
!cmp r8,[p.v_stop]
!jb Filter_EmbossV5_boucle_y ; next
!mov rax,[p.v_s]
!movdqu xmm4,[rax+000]
!movdqu xmm5,[rax+016]
!movdqu xmm6,[rax+032]
FreeArray(Reg_memory())
EndProcedure
Procedure Filter_Emboss(Filter_Emboss_source,Filter_Emboss_cible,Filter_Emboss_power,Filter_Emboss_light,Filter_Emboss_opt,Filter_Emboss_mask = 0)
If Filter_Emboss_source = 0 Or Filter_Emboss_cible = 0 : ProcedureReturn : EndIf
Protected thread , Psource , Pcible , Pmask , lg , ht , i
thread=CountCPUs(#PB_System_CPUs)
If thread<2:thread=1:EndIf
Protected Dim tr.q(thread)
StartDrawing(ImageOutput(Filter_Emboss_source))
Psource = DrawingBuffer()
lg = ImageWidth(Filter_Emboss_source)
ht = ImageHeight(Filter_Emboss_source)
StopDrawing()
StartDrawing(ImageOutput(Filter_Emboss_cible))
Pcible = DrawingBuffer()
StopDrawing()
If Filter_Emboss_mask <> 0
StartDrawing(ImageOutput(Filter_Emboss_mask))
Pmask = DrawingBuffer()
StopDrawing()
EndIf
Protected Dim tx1.l(lg + 3)
Protected Dim ty1.l(ht + 3)
Protected Dim tx2.l(lg + 3)
Protected Dim ty2.l(ht + 3)
Protected Dim tx3.l(lg + 3)
Protected Dim ty3.l(ht + 3)
Protected Dim tx4.l(lg + 3)
Protected Dim ty4.l(ht + 3)
Protected Dim tx5.l(lg + 3)
Protected Dim ty5.l(ht + 3)
Protected Dim tx6.l(lg + 3)
Protected Dim ty6.l(ht + 3)
; coordonnees de chaque pixel pour le precalcul de position
Select Filter_Emboss_opt
Case 0,16
nx1 = -1 : ny1 = -1 : nx2 = 0 : ny2 = 0 : nx3 = 1 : ny3 = 1
Case 1,17
nx1 = -1 : ny1 = -0 : nx2 = 0 : ny2 = 0 : nx3 = 1 : ny3 = 0
Case 2,18
nx1 = -1 : ny1 = 1 : nx2 = 0 : ny2 = 0 : nx3 = 1 : ny3 = -1
Case 3,19
nx1 = 0 : ny1 = 1 : nx2 = 0 : ny2 = 0 : nx3 = 0 : ny3 = -1
Case 4,20
nx1 = 1 : ny1 = 1 : nx2 = 0 : ny2 = 0 : nx3 = -1 : ny3 = -1
Case 5,21
nx1 = 1 : ny1 = 0 : nx2 = 0 : ny2 = 0 : nx3 = -1 : ny3 = 0
Case 6,22
nx1 = 1 : ny1 = -1 : nx2 = 0 : ny2 = 0 : nx3 = -1 : ny3 = 1
Case 7,23
nx1 = 0 : ny1 = -1 : nx2 = 0 : ny2 = 0 : nx3 = 0 : ny3 = 1
Case 8
nx1 = -1 : ny1 = -1 : nx2 = 1 : ny2 = 1
Case 9
nx1 = -1 : ny1 = -0 : nx2 = 1 : ny2 = 0
Case 10
nx1 = -1 : ny1 = 1 : nx2 = 1 : ny2 = -1
Case 11
nx1 = 0 : ny1 = 1 : nx2 = 0 : ny2 = -1
Case 12
nx1 = 1 : ny1 = 1 : nx2 = -1 : ny2 = -1
Case 13
nx1 = 1 : ny1 = 0 : nx2 = -1 : ny2 = 0
Case 14
nx1 = 1 : ny1 = -1 : nx2 = -1 : ny2 = 1
Case 15
nx1 = 0 : ny1 = -1 : nx2 = 0 : ny2 = 1
Case 24
nx1 = 0 : ny1 = -1 : nx2 = -1 : ny2 = -1 : nx3 = -1 : ny3 = 0
Case 25
nx1 = -1 : ny1 = 0 : nx2 = -1 : ny2 = 1 : nx3 = 0 : ny3 = 1
Case 26
nx1 = 0 : ny1 = 1 : nx2 = 1 : ny2 = 1 : nx3 = 1 : ny3 = 0
Case 27
nx1 = 1 : ny1 = 0 : nx2 = 1 : ny2 = -1 : nx3 = 0 : ny3 = -1
Case 28
nx1 = -1 : ny1 = 0 : nx2 = 0 : ny2 = 1 : nx3 = 1 : ny3 = 0 : nx4 = 0 : ny4 = -1
Case 29
nx1 = -1 : ny1 = 1 : nx2 = 1 : ny2 = 1 : nx3 = 1 : ny3 = -1 : nx4 = -1 : ny4 = -1
Case 30
nx1 = -1 : ny1 = -1 : nx2 = 0 : ny2 = -1 : nx3 = -1 : ny3 = 0 : nx4 = 1 : ny4 = 1 : nx5 = 0 : ny5 = 1 : nx6 = 1 : ny6 = 0
Case 31
nx1 = -1 : ny1 = 1 : nx2 = 0 : ny2 = 1 : nx3 = -1 : ny3 = 0 : nx4 = 1 : ny4 = -1 : nx5 = 0 : ny5 = -1 : nx6 = 1 : ny6 = 0
Case 32
nx1 = 1 : ny1 = 1 : nx2 = 0 : ny2 = 1 : nx3 = 1 : ny3 = 0 : nx4 = -1 : ny4 = -1 : nx5 = 0 : ny5 = -1 : nx6 = -1 : ny6 = 0
Case 33
nx1 = 1 : ny1 = -1 : nx2 = 0 : ny2 = -1 : nx3 = 1 : ny3 = 0 : nx4 = -1 : ny4 = 1 : nx5 = 0 : ny5 = 1 : nx6 = -1 : ny6 = 0
Case 34
nx1 = -1 : ny1 = -1 : nx2 = 0 : ny2 = 0 : nx3 = 1 : ny3 = 1
EndSelect
;precalcul des pixel en "x" et en "y"
;permet supprimer les tests de depassement de chaque pixel hors "ecran"
For i=0 To lg - 1
px1 = i + nx1 : If px1< 0 : px1 = 0 : EndIf : If px1 > ( lg - 1 ) : px1 = lg - 1 : EndIf : tx1(i) = px1 * 4
px2 = i + nx2 : If px2< 0 : px2 = 0 : EndIf : If px2 > ( lg - 1 ) : px2 = lg - 1 : EndIf : tx2(i) = px2 * 4
px3 = i + nx3 : If px3< 0 : px3 = 0 : EndIf : If px3 > ( lg - 1 ) : px3 = lg - 1 : EndIf : tx3(i) = px3 * 4
px4 = i + nx4 : If px4< 0 : px4 = 0 : EndIf : If px4 > ( lg - 1 ) : px4 = lg - 1 : EndIf : tx4(i) = px4 * 4
px5 = i + nx5 : If px5< 0 : px5 = 0 : EndIf : If px5 > ( lg - 1 ) : px5 = lg - 1 : EndIf : tx5(i) = px5 * 4
px6 = i + nx6 : If px6< 0 : px6 = 0 : EndIf : If px6 > ( lg - 1 ) : px6 = lg - 1 : EndIf : tx6(i) = px6 * 4
Next
For i=0 To ht + 1
py1 = i + ny1 : If py1 < 0 : py1 = 0 : EndIf : If py1 > ( ht - 1 ) : py1 = ht - 1 : EndIf : ty1(i) = py1
py2 = i + ny2 : If py2 < 0 : py2 = 0 : EndIf : If py2 > ( ht - 1 ) : py2 = ht - 1 : EndIf : ty2(i) = py2
py3 = i + ny3 : If py3 < 0 : py3 = 0 : EndIf : If py3 > ( ht - 1 ) : py3 = ht - 1 : EndIf : ty3(i) = py3
py4 = i + ny4 : If py4 < 0 : py4 = 0 : EndIf : If py4 > ( ht - 1 ) : py4 = ht - 1 : EndIf : ty4(i) = py4
py5 = i + ny5 : If py5 < 0 : py5 = 0 : EndIf : If py5 > ( ht - 1 ) : py5 = ht - 1 : EndIf : ty5(i) = py4
py6 = i + ny6 : If py6 < 0 : py6 = 0 : EndIf : If py6 > ( ht - 1 ) : py6 = ht - 1 : EndIf : ty6(i) = py4
Next
param(0)=Psource; 00
param(1)=Pcible ; 08
param(2)=Pmask ; 16
param(3)=lg ; 24
param(4)=ht ; 32
param(5)= thread ; 40
param(6)= Filter_Emboss_power ; 48
param(7)= Filter_Emboss_light ; 56
param(8)= @tx1() ; 64
param(9)= @ty1() ; 72
param(10)= @tx2() ; 80
param(11)= @ty2() ; 88
param(12)= @tx3() ; 96
param(13)= @ty3() ; 104
param(14)= @tx4() ; 112
param(15)= @ty4() ; 120
param(16)= @tx5() ; 128
param(17)= @ty5() ; 136
param(18)= @tx6() ; 144
param(19)= @ty6() ; 152
For i=0 To thread-1 : tr(i)=0 : Next
Select Filter_Emboss_opt
Case 0 To 15
For i=0 To thread-1
While tr(i)=0
tr(i)=CreateThread(@Filter_EmbossV1(),i)
Wend
Next
Case 16 To 27
For i=0 To thread-1
While tr(i)=0
tr(i)=CreateThread(@Filter_EmbossV2(),i)
Wend
Next
Case 28,29
For i=0 To thread-1
While tr(i)=0
tr(i)=CreateThread(@Filter_EmbossV3(),i)
Wend
Next
Case 30 To 33
For i=0 To thread-1
While tr(i)=0
tr(i)=CreateThread(@Filter_EmbossV4(),i)
Wend
Next
Case 34
For i=0 To thread-1
While tr(i)=0
tr(i)=CreateThread(@Filter_EmbossV5(),i)
Wend
Next
EndSelect
For i=0 To thread-1
If IsThread(tr(i))>0 : WaitThread(tr(i)) : EndIf
Next
FreeArray(tr())
Protected Dim Reg_memory.q(3*8)
s=@reg_memory()
!mov rax,[p.v_s]
!mov [rax+000],r10
!mov [rax+008],r11
!mov [rax+016],r12
If Filter_Emboss_mask<>0
taille = lg * ht
!mov rcx,[p.v_Pmask]
!mov r8,[p.v_Psource]
!mov r9,[p.v_Pcible]
!xor rdx,rdx
!saut01:
!mov r10d,[rcx+rdx*4];,[p.v_Pmask]
!mov r11d,[r8+rdx*4];r8,[p.v_Psource]
!mov r12d,[r9+rdx*4];,[p.v_Pcible]
!and r12d,r10d
!xor r10d,$ffffffff
!and r11d,r10d
!or r11d,r12d
!mov [r9+rdx*4],r11d
!inc rdx
!cmp rdx,[p.v_taille]
!jb saut01
!mov rax,[p.v_s]
!mov r10,[rax+000]
!mov r11,[rax+008]
!mov r12,[rax+016]
FreeArray(Reg_memory())
EndIf
FreeArray(tx1())
FreeArray(ty1())
FreeArray(tx2())
FreeArray(ty2())
FreeArray(tx3())
FreeArray(ty3())
FreeArray(tx4())
FreeArray(ty4())
FreeArray(tx5())
FreeArray(ty5())
FreeArray(tx6())
FreeArray(ty6())
EndProcedure