haraldk / TwelveMonkeys

TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO
https://haraldk.github.io/TwelveMonkeys/
BSD 3-Clause "New" or "Revised" License
1.84k stars 309 forks source link

WebP: Images decoded with yellow tint #864

Open gotson opened 7 months ago

gotson commented 7 months ago

Describe the bug Some WebP images are decoded with a yellow tint.

Version information

  1. The version of the TwelveMonkeys ImageIO library in use. 3.10.1

  2. The exact output of java --version (or java -version for older Java releases).

openjdk 21 2023-09-19 LTS OpenJDK Runtime Environment Temurin-21+35 (build 21+35-LTS) OpenJDK 64-Bit Server VM Temurin-21+35 (build 21+35-LTS, mixed mode)

  1. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc. Please state exact version numbers where applicable.

To Reproduce Steps to reproduce the behavior:

  1. Add the attached files as test resources for imageio-webp
  2. Run the below unit tests
  3. Check the generated PNG images, and compare to their JPG equivalent

Expected behavior Images should look alike.

Example code

@Test
    public void test1() throws IOException {
        testReadTestData(new TestData(getClassLoaderResource("/webp/Example1.webp"), new Dimension(2144, 3200)));
    }

    @Test
    public void test2() throws IOException {
        testReadTestData(new TestData(getClassLoaderResource("/webp/Example2.webp"), new Dimension(2144, 3200)));
    }

    public void testReadTestData(TestData data) throws IOException {
        ImageReader reader = createReader();

        reader.setInput(data.getInputStream());

        for (int i = 0; i < data.getImageCount(); i++) {
            BufferedImage image = null;

            try {
                image = reader.read(i);
                File tempActual = File.createTempFile("junit-testRead-", ".png");
                System.out.println("tempActual.getAbsolutePath(): " + tempActual.getAbsolutePath());
                ImageIO.write(image, "PNG", tempActual);
            }
            catch (Exception e) {
                e.printStackTrace();
                failBecause(String.format("Image %s index %s could not be read: %s", data.getInput(), i, e), e);
            }

            assertNotNull(String.format("Image %s index %s was null!", data.getInput(), i), image);

            assertEquals(
                String.format("Image %s index %s has wrong width: %s", data.getInput(), i, image.getWidth()),
                data.getDimension(i).width,
                image.getWidth()
            );
            assertEquals(
                String.format("Image %s index %s has wrong height: %s", data.getInput(), i, image.getHeight()),
                data.getDimension(i).height, image.getHeight()
            );
        }

        reader.dispose();
    }

Sample file(s) JPG.zip WEBP.zip

Screenshots 282593440-845e8b38-7de4-463d-8dc8-ec5c35127e52

Additional context I tested those images in NightMonkeys, and they decode correctly.

haraldk commented 7 months ago

Hi @gotson!

Thanks for the samples! I believe this is the same issue as reported in #785 .

I haven't been able to find the exact problem, but I believe there is some small rounding or other error that accumulates during decoding, as the problem is typically most visible in the lower right corner of the decoded image.

I will look into it, but any help on pinpointing or fixing the issue would be greatly appreciated! 😀