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.89k stars 313 forks source link

WebP: Image decoded as green #734

Open gotson opened 1 year ago

gotson commented 1 year ago

Describe the bug A specific webp image turns green when converted to jpeg or png.

Version information

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

3.9.4. I also tried with 3.10.0-SNAPSHOT.

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

openjdk version "1.8.0_332" OpenJDK Runtime Environment Corretto-8.332.08.1 (build 1.8.0_332-b08) OpenJDK 64-Bit Server VM Corretto-8.332.08.1 (build 25.332-b08, 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.

I tested on macOS 13.2.1.

User reported on Windows 11.

Expected behavior The converted image should look like the original.

Sample file(s)

001e.zip

Screenshots

Additional context This was reported in https://github.com/gotson/komga/issues/1077

gotson commented 1 year ago

Hi Harald, i tested this with NightMonkeys ImageIO, and it works fine, so it seems to be an issue with TwelveMonkeys.

The webp image doesn't seem to have any specific features:

> webpinfo 001e.webp2023
File: 001e.webp
RIFF HEADER:
  File size: 563282
Chunk VP8  at offset     12, length 563270
  Width: 1920
  Height: 3001
  Alpha: 0
  Animation: 0
  Format: Lossy (1)
No error detected.
haraldk commented 1 year ago

Thanks for reporting!

I can reproduce the result with your attached sample file.

I don't have an immediate fix, unfortunately, so I need to look into why this is happening... Any help appreciated! 😀

KoenDG commented 1 year ago

I thought I'd try my hand at this, but after 2 days I give up.

It happens for JPG, BMP, PNG, TGA and TIFF. Other file types marked as writable don't generate a file. So I concluded it wasn't a writer issue.

Having learned that, I focused on the WebPImageReader, but comparing to other webp images, nothing seems out of the ordinary.

So in the end, I wasn't able to find anything.

Except for the fact that the example images here: https://developers.google.com/speed/webp/gallery2#webp_links

Only write PNG and TGA, but not JPG and BMP. I didn't check with the others. With the same code I used to test the image provided here.

Which is just the example code from the readme that does

try (ImageInputStream input = ImageIO.createImageInputStream(file)) {

With only default params and a write to the format I want added at the end.

Nothing serious, just thought I'd try this out.

haraldk commented 1 year ago

Thanks @KoenDG!

True, it's not a writer issue, you can see the images decodes as green only by reading and displaying the image (in Java).

(The fact that some formats don't write all images probably has to do with the pixel layout, more specifically, standard JPEG and BMP plugins doesn't write images with alpha, see the respective plugin Spi's canEncodeImage(ImageTypeSpecifier) method)

KoenDG commented 1 year ago

Something in general I'd like to vent frustration at, is the lack of tools around the internet to properly analyze images for their technical details. Or maybe I'm just not "in the know" for this.

Given how this happens for non of the google example images, I thought "there's probably something really specific going on, what tool could print out the technical details for this image, stuff at the bit level or in hexadecimal".

But even looking at it with a hex editor was gibberish.

I also couldn't find another webp image with 24 pixel depth like the one at issue here to compare.

haraldk commented 1 year ago

@KoenDG Not sure what kind of details you expect to find? Tools like ExifTool or other command line imaging tools like ImageMagick might help? There are also more sophisticated tools in the "forensics" category that might help here.

Most of the time I'm just using a plain hex viewer/editor and do my own parsing. Especially when looking at corrupted or malformed files, this might be the only way... But as each file format is different, you often need to have an understanding of the specification for the format to make sense out of it. It's not gibberish. It's just image data... 😀