fbGFX: BUG in Paint statement

General FreeBASIC programming questions.
Posts: 9408
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: fbGFX: BUG in Paint statement

Postby fxm » Apr 12, 2019 18:16

I copied from the first sentence:
dodicat wrote:Perhaps
If the border is drawn with a transparent color (in conjunction with the GFX_ALPHA_PRIMITIVES option flag) and some pixels on it are overdrawn, the resultant (blending) color of these overdrawn pixels can cause a leak point, through which the fill color escapes outside the border.

Otherwise, I would rather agree with you, but it is out of pure politeness with him.
Posts: 6081
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: fbGFX: BUG in Paint statement

Postby dodicat » Apr 12, 2019 21:04

Blended is maybe better than blending.
Out of the Gaelic, as spoken in Western France, Cornwall, Wales, Ireland, Scotland and the Isle of Man (some locations very little now), only Ireland didn't include a past tense.
The wouldn't have the word BLENDED, but for a workaround they would say AFTER BLENDING.
You often hear Irish saying things like e.g. "I am just after finishing it".
I learned this fact from a documentary by (the late) Terry Wogan.
Anyway, after finishing up my blender, here it is for foreground of RGBA on top of a background of RGB, as might be encountered drawing a box with a transparent border on a screen with a solid background colour set.

Code: Select all


Function BlendColours(ForegroundRGBA As Ulong,BackgroundRGB as ulong) As Ulong
    dim as ubyte r2=Cast(Ubyte Ptr,@ForegroundRGBA)[2],g2=Cast(Ubyte Ptr,@ForegroundRGBA)[1], _
                 b2=Cast(Ubyte Ptr,@ForegroundRGBA)[0],a2=Cast(Ubyte Ptr,@ForegroundRGBA)[3]
    dim as ubyte r1=Cast(Ubyte Ptr,@BackgroundRGB)[2],g1=Cast(Ubyte Ptr,@BackgroundRGB)[1], _
                 b1=Cast(Ubyte Ptr,@BackgroundRGB)[0],a1=Cast(Ubyte Ptr,@BackgroundRGB)[3]
    Dim As Single f=a2/256   
    If Sizeof(Integer)=4 Then '32 bit
        Return Rgba(Int(f*r2+(1-f)*r1), _
                    Int(f*g2+(1-f)*g1), _
                    Int(f*b2+(1-f)*b1), _
    End If
        Return Rgba(Int(f*r2+(1-f)*r1), _
                    Int(f*g2+(1-f)*g1), _
                    Int(f*b2+(1-f)*b1), _
End Function

function truecol(c as ulong) as ulong
    return rgb(cast(ubyte ptr,@c)[2],cast(ubyte ptr,@c)[1],cast(ubyte ptr,@c)[0])
end function

function show(b as ulong,msg as string="") as string
    dim as string msg2="Rgba"
    if Cast(Ubyte Ptr,@b)[3]=255 then msg2="Rgb"
    select case msg2
    case "Rgba"
 return msg2+"("+ str(Cast(Ubyte Ptr,@b)[2])+","+str(Cast(Ubyte Ptr,@b)[1])+","+str(Cast(Ubyte Ptr,@b)[0])+","+str(Cast(Ubyte Ptr,@b)[3])+")"+"   "+msg
    case "Rgb"
 return msg2+"("+ str(Cast(Ubyte Ptr,@b)[2])+","+str(Cast(Ubyte Ptr,@b)[1])+","+str(Cast(Ubyte Ptr,@b)[0])+")"+"   "+msg
    end select
end function

screen 19,32,,64
dim as ulong fore,back,blend



circle (400,500),50,truecol(BlendColours(fore,back)),,,,f
locate 9,7
print show(back,"Background")
locate 9,60
print show(fore,"foreground")
locate 1,1
print show(BlendColours(fore,back),"colour with Blender function")
print show(point(400,200),"colour with point-- at screen centre")

loop until inkey=chr(27)

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest