Page 1 of 1
Clipboard 32bit Images
Posted: Fri Mar 30, 2018 2:35 pm
by chi
SetClipboardImage() seems to have problems with 32bit images!
The source image imported from the clipboard into XnView (Gimp,...) introduces artifacts near the round corner. The same clipboard image imported into paint.net even comes without the alpha channel.
Source:

XnView:

paint.net:
Code: Select all
UsePNGImageDecoder()
LoadImage(0, "clp_00.png") ;#PB_Compiler_Home + "Examples\3D\Data\Textures\grass2.png")
SetClipboardImage(0)
Re: Clipboard 32bit Images
Posted: Thu Apr 12, 2018 2:12 pm
by chi
plot twist ^^
SetClipboardImage() works fine! All you have to do is to "premultiply alpha"
Code: Select all
RGBA((r * alpha + 127) * 0.003921, (g * alpha + 127) * 0.003921, (b * alpha + 127) * 0.003921, alpha)
Re: Clipboard 32bit Images
Posted: Sat Apr 08, 2023 12:08 pm
by Fred
Tried to reproduce without success, it paste OK in GIMP (no artifact)
Re: Clipboard 32bit Images
Posted: Sat Apr 08, 2023 1:52 pm
by chi
Save the clp_00.png file from the Source image (in the 1st post) and open it in Gimp. You will see a rounded edge without artifacts. Now run the above code with clp_00.png and copy the clipboard into Gimp. The rounded edge has a darker line on it (like the XnView image 1st post).
To fix this problem we should apply Premultiply Alpha calculations:
Code: Select all
Procedure PreMultiplyAlpha(image)
StartDrawing(ImageOutput(image))
DrawingMode(#PB_2DDrawing_AllChannels)
w = ImageWidth(image) - 1
h = ImageHeight(image) - 1
For y=0 To h
For x=0 To w
color = Point(x, y)
Plot(x, y, RGBA((Red(color) * Alpha(color) + 127) * 0.00392156, (Green(color) * Alpha(color) + 127) * 0.00392156, (Blue(color) * Alpha(color) + 127) * 0.00392156, Alpha(color)))
Next
Next
StopDrawing()
ProcedureReturn image
EndProcedure
UsePNGImageDecoder()
LoadImage(0, "clp_00.png")
PreMultiplyAlpha(0)
SetClipboardImage(0)