CreateImage() and #PB_Image_Transparent: Accept RGBA values
Posted: Thu Apr 11, 2024 8:12 pm
Greetings.
During my vector escapades, I noticed some blending discrepancies on images.
Currently, color values in 32 bit images affect alpha blending, even when the alpha component is 0.
This by itself is not a problem.

Left: Equal to RGBA(0, 0, 0, 0)
Right: Equal to RGBA(128, 128, 128, 0)
Most blending engines use a neutral color value to prevent the dark border on the left that is visible here.
#PB_Image_Transparent is currently a -1 value for a special case handing on CreateImage(). CreateImage() does not take an RGBA value for its background color.
I propose:
-Alias #PB_Image_Transparent to RGBA(128, 128, 128, 0)
-Make CreateImage accept RGBA values for its background color
During my vector escapades, I noticed some blending discrepancies on images.
Currently, color values in 32 bit images affect alpha blending, even when the alpha component is 0.
This by itself is not a problem.
Code: Select all
CreateImage(0, 500, 300, 32, #PB_Image_Transparent)
If StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(OutputWidth()/2, 0, OutputWidth()/2, OutputHeight(), RGBA(128, 128, 128, 0))
StopDrawing()
EndIf
If StartVectorDrawing(ImageVectorOutput(0, #PB_Unit_Pixel))
AddPathCircle(125, 125, 100)
VectorSourceColor(RGBA(200, 200, 200, 255))
FillPath()
AddPathCircle(125*3, 125, 100)
VectorSourceColor(RGBA(200, 200, 200, 255))
FillPath()
StopVectorDrawing()
EndIf
UsePNGImageEncoder()
SaveImage(0, "test1.png", #PB_ImagePlugin_PNG , 0, 32)

Left: Equal to RGBA(0, 0, 0, 0)
Right: Equal to RGBA(128, 128, 128, 0)
Most blending engines use a neutral color value to prevent the dark border on the left that is visible here.
#PB_Image_Transparent is currently a -1 value for a special case handing on CreateImage(). CreateImage() does not take an RGBA value for its background color.
I propose:
-Alias #PB_Image_Transparent to RGBA(128, 128, 128, 0)
-Make CreateImage accept RGBA values for its background color