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

QOI format support #699

Open jxtps opened 2 years ago

jxtps commented 2 years ago

The QOI image format ( https://qoiformat.org/ ) offers similar compression performance to PNG, but with greatly reduced CPU load for both encoding & decoding. This makes it an excellent format for internal CPU bound image processing where lossless serialization is necessary.

There are at least three java implementations:

  1. https://github.com/MarkJeronimus/qoi-java-spi
    1. Looks promising!?
  2. https://github.com/saharNooby/qoi-java
    1. Issues: It doesn't work with Play Framework's reload feature (qoi-java-awt plugin goes missing), and it doesn't read meta-data efficiently (it just reads the whole image)
  3. https://github.com/pfusik/qoi-ci
    1. Issues: it just provides raw arrays, no BufferedImage

Maybe one of them could be incorporated into TwelveMonkeys? Thanks!

jxtps commented 2 years ago

Personal pet peeve: MarkJeronimus' implementation selects BufferedImage.TYPE_3/4BYTE_BGR over BufferedImage.TYPE_INT_A/RGB, whereas I much prefer the latter.

I know it's possible to force the format used when reading (as you so graciously answered about in https://stackoverflow.com/questions/71212279/is-there-a-way-to-get-java-to-read-a-png-as-type-int-rgb-type-int-argb but that reduces performance for JPEG and PNG, so it requires more clever logic.

haraldk commented 2 years ago

Hi @jxtps,

While certainly doable, it's not necessarily a goal to support as many formats as possible in the library. Any new plugin comes with a cost (for the maintainers, which is.. me). And this format doen't really seem very widespread... If there are other good Java implementations (even ImageIO support), maybe it's better to help out there, to make it support the stuff you like. Have you been in contact with the author? But yes, https://github.com/MarkJeronimus/qoi-java-spi looks promising! 😉

Personally, I would also select TYPE_3BYTE_BGR over TYPE_INT_RGB for most formats, just because it saves 25% memory. And allow the client to select something else if desired, with reasonable performance.

The qoi-java-awt reload issue sounds like a variation on the issues of deploying ImageIO plugins in a web app, but I'm not familiar with the Play Framework so I may be wrong.

Anyway, thanks for bringing this up! I'll think about it... 😎

-- Harald K