anton
New Member
Posts: 9
|
Post by anton on Feb 7, 2023 12:58:44 GMT -5
Hi all. I am trying to call the GdiAlphaBlend function. I am not having much luck. Below is my code. If someone could tell me what I am doing wrong I would appreciate it. One problem I have is in the BLENDFUNCTION struct calls for type byte.
'GdiAlphaBlend trial
nomainwin
WindowWidth=640
WindowHeight=500
UpperLeftX=-0
UpperLeftY=0
open "Alphablend-src" for graphics as #left
#left "trapclose [quit]"
UpperLeftX=800
UpperLeftY=0
WindowWidth=640
WindowHeight=500
open "Alphablend-dest" for graphics as #right
#right "trapclose [quit]"
loadbmp "pic1","pic1.bmp"
loadbmp "pic2","pic2.bmp"
#left "down;drawbmp pic1 0 0"
#right "down;drawbmp pic2 0 0"
#right "when leftButtonUp [drawalphablend]"
#left "when leftButtonUp [drawalphablend]"
wait
[quit]
unloadbmp "pic1"
unloadbmp "pic2"
close #left
close #right
end
[drawalphablend]
s=hwnd(#left)
d=hwnd(#right)
src=GetDC(s)
dest=GetDC(d)
struct BLENDFUNCTION,_
BlendOp as ushort,_
BlendFlags as ushort,_
SourceConstantAlpha as ushort,_
AlphaFormat as ushort
BLENDFUNCTION.BlendOp.struct=0
BLENDFUNCTION.BlendFlags.struct=0
BLENDFUNCTION.SourceConstantAlpha.struct=128
BLENDFUNCTION.AlphaFormat.struct=0
call alphablend,src,dest,128
wait
sub alphablend src,dest,amt
calldll #gdi32, "GdiAlphaBlend",_
src as ulong,_
0 as ulong,_
0 as ulong,_
640 as ulong,_
480 as ulong,_
dest as ulong,_
0 as ulong,_
0 as ulong,_
640 as ulong,_
480 as ulong,_
BLENDFUNCTION as struct,_
result as boolean
notice result
end sub
Function GetDC(hWnd)
CallDLL #user32, "GetDC",hWnd as uLong,GetDC as ulong
End Function
|
|
|
Post by Rod on Feb 7, 2023 14:40:37 GMT -5
Well byte values can be set as chr types in API calls. Not sure how any of this will work since Liberty is 24bit graphics. It usually crashes when 32bit graphics are loaded. But the GDI dlls may work. The LBPE has info on API including Struct formation.
You would get better help if you told us exactly what was failing with what error message.
|
|
|
Post by tsh73 on Feb 7, 2023 16:14:12 GMT -5
I got it return 1 by changing 4 bytes struct to single ulong (not sure which byte should be 127 - tried both nothing seen) but I still see nothing
'GdiAlphaBlend trial
nomainwin WindowWidth=640 WindowHeight=500 UpperLeftX=-0 UpperLeftY=0
open "Alphablend-src" for graphics as #left #left "trapclose [quit]" UpperLeftX=800 UpperLeftY=0 WindowWidth=640 WindowHeight=500
open "Alphablend-dest" for graphics as #right #right "trapclose [quit]" loadbmp "pic1","pic1.bmp" loadbmp "pic2","pic2.bmp" #left "down;drawbmp pic1 0 0" #right "down;drawbmp pic2 0 0" #right "when leftButtonUp [drawalphablend]" #left "when leftButtonUp [drawalphablend]"
wait
[quit] unloadbmp "pic1" unloadbmp "pic2" close #left close #right end
[drawalphablend] s=hwnd(#left) d=hwnd(#right) src=GetDC(s) dest=GetDC(d)
struct BLENDFUNCTION,_ BlendOp as ushort,_ BlendFlags as ushort,_ SourceConstantAlpha as ushort,_ AlphaFormat as ushort
BLENDFUNCTION.BlendOp.struct=0 BLENDFUNCTION.BlendFlags.struct=0 BLENDFUNCTION.SourceConstantAlpha.struct=128 BLENDFUNCTION.AlphaFormat.struct=1 '0 BLENDFUNCTION.AlphaFormat.struct=0 num = 127*256+0 'num = 127*256*256+0 'num = 256*256*256*1 +256*256*127+256*0+0 'num = 256*256*256*0 +256*256*0+256*127+1
call alphablend,src,dest,128 wait
sub alphablend src,dest,amt calldll #gdi32, "GdiAlphaBlend",_ src as ulong,_ 0 as ulong,_ 0 as ulong,_ 100 as ulong,_ 100 as ulong,_ dest as ulong,_ 0 as ulong,_ 0 as ulong,_ 100 as ulong,_ 100 as ulong,_ num as ulong,_ result as boolean
'put ulong num instead of 4 bytes 'BLENDFUNCTION as struct,_ 'got result 1 but nothing visible
notice result end sub
Function GetDC(hWnd) CallDLL #user32, "GetDC",hWnd as uLong,GetDC as ulong End Function
|
|
|
Post by Rod on Feb 8, 2023 6:08:01 GMT -5
I struggle to find the decimal values of AC_SCR_ALPHA and AC_SCR_OVER without those its a bit of a lottery knowing whats working or not. char[2] is what we need in the struct then chr$(x) to assign values. Still not sure if anything will work on 24bit bmps. Are we working with 32bit bmps? which tool creates them?
Aha its SRC not SCR, others have made the same mistake. So _AC_SRC_OVER should be 0 and _AC_SRC_ALPHA should be 1. Sourceconstantalpha can be anything from 0 to 255.
But it still fails for me. Anatoly's version produces a result of 1 but you can put anything in the num and it still reports 1. So I get a result of 0, failed. Is that because I am using 24 bit bmps? If someone has access to 32 bit bmp what is the result?
'GdiAlphaBlend trial
nomainwin WindowWidth=640 WindowHeight=500 UpperLeftX=-0 UpperLeftY=0
open "Alphablend-src" for graphics as #left #left "trapclose [quit]" UpperLeftX=800 UpperLeftY=0 WindowWidth=640 WindowHeight=500
open "Alphablend-dest" for graphics as #right #right "trapclose [quit]" loadbmp "pic1","pic1.bmp" loadbmp "pic2","pic2.bmp" #left "down;drawbmp pic1 0 0" #right "down;drawbmp pic2 0 0" #right "when leftButtonUp [drawalphablend]" #left "when leftButtonUp [drawalphablend]"
wait
[quit] unloadbmp "pic1" unloadbmp "pic2" close #left close #right end
[drawalphablend] s=hwnd(#left) d=hwnd(#right) src=GetDC(s) dest=GetDC(d)
struct BLENDFUNCTION,_ BlendOp as char[2],_ BlendFlags as char[2],_ SourceConstantAlpha as char[2],_ AlphaFormat as char[2]
BLENDFUNCTION.BlendOp.struct=chr$(0) BLENDFUNCTION.BlendFlags.struct=chr$(0) BLENDFUNCTION.SourceConstantAlpha.struct=chr$(128) BLENDFUNCTION.AlphaFormat.struct=chr$(1)
call alphablend,src,dest wait
sub alphablend src,dest calldll #gdi32, "GdiAlphaBlend",_ src as ulong,_ 0 as long,_ 0 as long,_ 100 as long,_ 100 as long,_ dest as ulong,_ 0 as long,_ 0 as long,_ 100 as ulong,_ 100 as ulong,_ BLENDFUNCTION as struct,_ result as long
notice result end sub
Function GetDC(hWnd) CallDLL #user32, "GetDC",hWnd as uLong,GetDC as ulong End Function
|
|
|
Post by Rod on Feb 8, 2023 7:33:10 GMT -5
Ah success using Anatoly's method.
'GdiAlphaBlend trial
nomainwin WindowWidth=640 WindowHeight=500 UpperLeftX=-0 UpperLeftY=0
open "Alphablend-src" for graphics as #left #left "trapclose [quit]" UpperLeftX=800 UpperLeftY=0 WindowWidth=640 WindowHeight=500
open "Alphablend-dest" for graphics as #right #right "trapclose [quit]" loadbmp "pic1","pic1.bmp" loadbmp "pic2","pic2.bmp" #left "down;drawbmp pic1 0 0" #right "down;drawbmp pic2 0 0" #right "when leftButtonUp [drawalphablend]" #left "when leftButtonUp [drawalphablend]"
wait
[quit] unloadbmp "pic1" unloadbmp "pic2" close #left close #right end
[drawalphablend] s=hwnd(#left) d=hwnd(#right) src=GetDC(s) dest=GetDC(d)
call alphablend,src,dest wait
sub alphablend src,dest num= 128*256*256+1*256*256*256 calldll #gdi32, "GdiAlphaBlend",_ src as ulong,_ 0 as long,_ 0 as long,_ 100 as long,_ 100 as long,_ dest as ulong,_ 0 as long,_ 0 as long,_ 100 as ulong,_ 100 as ulong,_ num as long,_ result as long
notice result end sub
Function GetDC(hWnd) CallDLL #user32, "GetDC",hWnd as uLong,GetDC as ulong End Function
|
|
|
Post by Rod on Feb 8, 2023 8:43:57 GMT -5
So we are packing four bytes into a long value. byte one is just itself, byte two needs multiplied by 256, byte three by 256*256 and byte four by 256*256*256
BlendOp must be AC_SRC_OVER which is 0 BlendFlags must be 0 SourceConstantAlpha can be anything from 0 to 255 say 128 AlphaFormat must be AC_SRC_ALPHA which is 1
the long value is calculated thus 0+0*256+128*256*256+1*256*256*256
|
|
|
Post by tsh73 on Feb 8, 2023 12:12:26 GMT -5
Interesting for me under Win 7, and with pictures 1 and 2 - red circle and blure cros on white BG: Place where 128 in long number is "hardness" of effect, setting it to 30 goes more slowly (effect build up as you click several times!) and place where 1, makes circle white out on the form of a cross While setting it to 0 make images blend ending with red and white on one picture. (and obviously source and destination are messed up - either in program or in API call)
|
|
|
Post by Rod on Feb 8, 2023 12:30:45 GMT -5
Yes the 127/128 value merges the pictures evenly. But with 24bit bmps we are applying a simple global 128 value across the entire bmp. The real interesting stuff will happen when there is an alpha channel value and the effect changes pixel by pixel.
|
|
anton
New Member
Posts: 9
|
Post by anton on Feb 8, 2023 13:02:43 GMT -5
Thank you so much. I am using this to produce a fade effect in video program I am making. Thanks again. It does just what I want.
|
|
|
Post by Rod on Feb 8, 2023 14:16:16 GMT -5
A demo of your working code would be good.
|
|