Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ArrayIndexOutOfBoundsException: 1 #12

Open
Ali-RS opened this issue Feb 1, 2021 · 3 comments
Open

java.lang.ArrayIndexOutOfBoundsException: 1 #12

Ali-RS opened this issue Feb 1, 2021 · 3 comments

Comments

@Ali-RS
Copy link

Ali-RS commented Feb 1, 2021

Hi

When trying to convert an emissive map (glow map) from jpg to webp using ImageIO and this plugin, I am getting this error:


SEVERE: Uncaught exception thrown in Thread[main,5,main]
java.lang.ArrayIndexOutOfBoundsException: 1
	at com.luciad.imageio.webp.WebPWriter.extractComponentRGBByte(WebPWriter.java:216)
	at com.luciad.imageio.webp.WebPWriter.getRGB(WebPWriter.java:129)
	at com.luciad.imageio.webp.WebPWriter.encode(WebPWriter.java:99)
	at com.luciad.imageio.webp.WebPWriter.write(WebPWriter.java:72)
	at app.Main.convertTexturesToWebP(Main.java:706)

this is the texture:

Seeker_emissive

When I am converting it to webp with Gimp it converts Ok.

@fleminra
Copy link

What's the type of the output image? I notice that I get that error when I try to write an image of type TYPE_BYTE_GRAY.

@fleminra
Copy link

What's the type of the output image? I notice that I get that error when I try to write an image of type TYPE_BYTE_GRAY.

And upon further investigation, it appears that lossless variant of the WebP format supports only ARGB. Someone correct me if I'm wrong. So this is a limitation of WebP, not a bug in webp-imageio. Although maybe webp-imageio should check the image type when encoding to WebP, and throw an IllegalArgumentException for types it doesn't support.

@Ali-RS
Copy link
Author

Ali-RS commented Feb 11, 2021

Hi @fleminra

I am using the default settings. Can you please let me know how I can specify it and what output type should I use for the glow map?

This the code snippet I am using to export the image

                    // Obtain image
                    try {
                        BufferedImage image = ImageIO.read(new File(convert.getSourceRoot(), key.getName()));

                        // Obtain a WebP ImageWriter instance
                        ImageWriter writer = ImageIO.getImageWritersByMIMEType("image/webp").next();

                        // Configure encoding parameters
                        WebPWriteParam writeParam = new WebPWriteParam(writer.getLocale());

                        writeParam.setCompressionMode(WebPWriteParam.MODE_DEFAULT);

                        // writeParam.setCompressionMode(WebPWriteParam.MODE_EXPLICIT);
                        // writeParam.setCompressionType(writeParam.getCompressionTypes()[WebPWriteParam.LOSSY_COMPRESSION]);
                        // writeParam.setCompressionQuality(0.9f);

                        // Configure the output on the ImageWriter
                        writer.setOutput(new FileImageOutputStream(outputFile));

                        // Encode
                        writer.write(null, new IIOImage(image, null, null), writeParam);
                    } catch (Exception e) {
                        log.error("Error converting texture to WebP. Using original texture instead.", e);
                        convertedTextures.remove(outputFile.getPath());
                        continue;
                    }

joostoudeman pushed a commit to joostoudeman/webp-imageio that referenced this issue Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants