Clipboard 32bit Images

Post bugreports for the Windows version here
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Clipboard 32bit Images

Post 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:Image
XnView:Image
paint.net:Image

Code: Select all

UsePNGImageDecoder()
LoadImage(0, "clp_00.png") ;#PB_Compiler_Home + "Examples\3D\Data\Textures\grass2.png")
SetClipboardImage(0)
Et cetera is my worst enemy
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Clipboard 32bit Images

Post 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)
Et cetera is my worst enemy
Fred
Administrator
Administrator
Posts: 16623
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Clipboard 32bit Images

Post by Fred »

Tried to reproduce without success, it paste OK in GIMP (no artifact)
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Clipboard 32bit Images

Post 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)
Et cetera is my worst enemy
Post Reply