Traneptora / jxlatte

Java JPEG XL decoder
MIT License
41 stars 6 forks source link

Issue when using BufferedImage#getRGB throwing IndexOutOfBounds #19

Closed Waterpicker closed 2 weeks ago

Waterpicker commented 1 year ago

So I'm a friend of the user Hydos. First off he is apologizing being harsh. I'm just posting his issue with the requested stacktrace. He really does need this issue fixed regardless of your prior interactions. His issue report starts after the line break.


First of all, here is the repo before I leave any information out. The usage of JXLatte is in MaterialUploader.java You can use GitHub's "Go to File" Feature to find this. Here is the complete stack trace from my program

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -144 out of bounds for length 65536 at java.desktop/java.awt.image.ComponentColorModel.getRGBComponent(ComponentColorModel.java:905) at java.desktop/java.awt.image.ComponentColorModel.getRed(ComponentColorModel.java:946) at java.desktop/java.awt.image.ComponentColorModel.getRGB(ComponentColorModel.java:1137) at java.desktop/java.awt.image.BufferedImage.getRGB(BufferedImage.java:918) at com.thepokecraftmod.rks.test.load.MaterialUploader.mergeAndLoad(MaterialUploader.java:74) at com.thepokecraftmod.rks.test.load.MaterialUploader.lambda$new$0(MaterialUploader.java:41) at com.thepokecraftmod.rks.test.load.MaterialUploader.upload(MaterialUploader.java:158) at com.thepokecraftmod.rks.test.tests.PokemonTest.main(PokemonTest.java:43)

https://cdn.discordapp.com/attachments/1080332031914950716/1097396030779166820/body_a_mtl.jxl Here is an image file as well which was being opened at the time to cause the issue.

If you need any more info I request you ask for it.

Traneptora commented 1 year ago

It looks like this file has out-of-range "colors" (I say "colors" because it is grayscale), which is causing issues with the built-in linear grayscale profile's LUT. If you call JXLImage.fillColor() before calling asBufferedImage() and then you draw it on another sRGB BufferedImage (which is the default), it should clamp these values. That being said, I probably should add a clamp() method to JXLImage for convenience, or have it automatically clamp before calling asBufferedImage().

Traneptora commented 2 weeks ago

Closing as JXLImage no longer uses BufferedImage.