Copy to Clipboard IOException (ARGB channel no longer supported for JPEGs)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
lynnskii
Posts: 5
Joined: Wed Apr 20, 2016 8:37 am
antibot: No, of course not.

Copy to Clipboard IOException (ARGB channel no longer supported for JPEGs)

Post by lynnskii » Fri May 24, 2019 11:37 pm

I'm in the process of migrating my applications to OpenJDK 11, I've discovered that copying a ChartPanel image to the WIndows clipboard now gives an IOException:

java.io.IOException: Registered service providers failed to encode BufferedImage@228e6026: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width = 765 height = 420 #Bands = 4 xOff = 0 yOff = 0 dataOffset[0] 0 to image/jpeg
at java.desktop/sun.awt.datatransfer.DataTransferer.imageToStandardBytesImpl(DataTransferer.java:1799)
at java.desktop/sun.awt.datatransfer.DataTransferer.imageToStandardBytes(DataTransferer.java:1713)
at java.desktop/sun.awt.windows.WDataTransferer.imageToPlatformBytes(WDataTransferer.java:353)
at java.desktop/sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:855)
at java.desktop/sun.awt.windows.WDataTransferer.translateTransferable(WDataTransferer.java:220)
at java.desktop/sun.awt.windows.WClipboard.setContentsNative(WClipboard.java:83)
at java.desktop/sun.awt.datatransfer.SunClipboard.setContents(SunClipboard.java:105)
at org.jfree.chart.ChartPanel.doCopy(ChartPanel.java:2702)

Have done some research, it seems that the alpha channel of the JPEG image is no longer supported in the OpenJDK implementation.

I've tracked it down to org.jfree.chart.ChartTransferable.ChartTransferable.createBufferedImage(…)
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

If BufferedImage.TYPE_INT_ARGB is replaced by BufferedImage.TYPE_INT_RGB, it works. Not sure if there are any other places with similar issues.

Here are some links from my research:
https://github.com/fesch/Structorizer.D ... issues/685
Apparently, the clipboard converts the image into JPG format instead of PNG as the menu item promises. As you would expect, the stack trace vanishes if the image type BufferedImage.TYPE_INT_RGB is used to prepare the image for transfer. The visual result doesn't differ.

https://bugs.openjdk.java.net/browse/JDK-8176556
https://bugs.openjdk.java.net/browse/JDK-8204188
JDK-8204187 removed support for ARGB channel for JPEG. Test uses ARGB input to encode JPEG image and we get IOException.

IanMayo
Posts: 9
Joined: Mon Oct 31, 2005 10:15 am
Location: UK

Re: Copy to Clipboard IOException (ARGB channel no longer supported for JPEGs)

Post by IanMayo » Tue Nov 19, 2019 10:07 am

Hi @lynnskii - have you thought about creating a Pull Request to provide your fix?

It seems a straightforward fix, you can create a PR here:
https://github.com/jfree/jfreechart/pulls

I'm also _suffering_ from the issue, so if you don't I'm quite happy to.

Locked