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.85k stars 309 forks source link

HEIF support #440

Open davidekholm opened 5 years ago

davidekholm commented 5 years ago

Any chance you can add support for the HEIF file format? (https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format).

akmeikle commented 5 years ago

I second this request!

haraldk commented 5 years ago

HEIF/HEIC does absolutely seem like a format we should have support for in Java.

I'm pretty busy these days implementing Camera RAW formats and WebP, but if anyone would like to help out, or can find a sponsor for some quality time, maybe we can do something about it? What do you think?

The ISOBMFF container format seems pretty straight forward. The HEVC decoding will be harder to implement. Might be some patent issues. And of course, competing with the performance of hardware implementations will be impossible.

Regards,

-- Harald K

davidekholm commented 5 years ago

Thanks Harald. Hoping you'll find the time to support this. Unfortunately I don't think we have the resources to sponsor this development though :-(

Sami32 commented 5 years ago

In case it could be of some help: https://github.com/yohhoy/heifreader https://github.com/marx-yu/heif-reader

haraldk commented 5 years ago

@Sami32 Thanks!

I've seen them, though. The first project depends on the hardware support for HEVC in Android phones, so it doesn't really solve the hard part in Java. The second does only parses the ISO Base Media File Format (MP4) container format with the necessary extensions, and does no image decoding. I've already implemented that...

The hard part is the actual decoding of the image. If you find a Java (or even C or C++) that implements the decoding part (and has a suitable license, like BSD, MIT or similar), I'm interested.

PS: If anyone's interested in hacking on HEVC decoding, I can share my ISOBMFF parser and test cases as a separate branch.

Best regards,

-- Harald K

akmeikle commented 5 years ago

Saw this on github - https://github.com/nokiatech/heif

Nadahar commented 5 years ago

I don't think a Java implementation exists. HEVC is a minefield when it comes to patents from what I understand.

There are multiple open source C/C++ implementations, but most are GPL. That doesn't mean one can't learn from them, but I don't think implementing this in Java will be a small feat. Here is a list of open source implementations, although I don't know how up-to-date or complete it is.

There is one project on the list that implements a decoder and is BSD licensed: HM. It might be the best "starting point".

haraldk commented 5 years ago

@akmeikle Thanks, I'm aware of the Nokia implementation. It's probably the best source for documentation at the moment.

It even has a Java API, but it's mainly a JNI wrapper for the C++ implementation. It's probably possible to write an ImageReader implementation on top of that, but I leave that to someone else. The aim of this library has always been to implement everything in Java, and have no (non-portable) native dependencies.

@Nadahar Thanks, I wasn't aware of the listing page. I was aware of the HM project (which is the Fraunhofer HEVC reference implementation). It might be useful to look at, if there's ambiguities in the specification.

And yes, porting to Java is usually harder than one might think. C is usually easier than C++ in my experience.

In all cases though, there are patent issues as you point out. I don't have the money or the legal expertise to fix them. But as OSS implementations does exist, it should at least be doable. Whether or not you could actually use such an implementation in your software is another question though. Ie: The Nokia license says

For the avoidance of doubt the Licensed Patents shall not include Codec Patents. Codec Patent licenses are neither granted, implied nor otherwise conveyed hereunder.

The HM license says:

The copyright in this software is being made available under the BSD License, included below. This software may be subject to other third party and contributor rights, including patent rights, and no such rights are granted under this license.

Best regards,

-- Harald K

Nadahar commented 5 years ago

After reading this article I'm daring to hope that we will see an image format based on AV1 in a not too distant future. That would be a much more interesting format, free of cumbersome patents. Apple's participation even suggests that we might see a variant of HEIF that uses AV1 compression instead of HEVC, which would be great news and make HEIF a much more promising prospect for JPEG replacement.

haraldk commented 5 years ago

@Nadahar Or, in other words, lets focus on WebP (#395), while waiting for the next JPEG-successor. ;-)

-- Harald K

Sami32 commented 5 years ago

I see. Then perhaps that library could be of some use: https://github.com/strukturag/libheif

I think that LGPLv3 is BSDv3 compatible but i'm not knowledgeable about licenses.

haraldk commented 5 years ago

@Sami32

libheif makes use of libde265 for the actual image decoding

...which is what we need. But same license, so might be worth looking into.

If you can also translate the license section "11. Patents" to plain English for me, that would help.. :-)

-- Harald K

Sami32 commented 5 years ago

@haraldk After 3 paracetamol pills and headaches i'm dreaming that Google translate will be able to help on that ;-)

Nadahar commented 5 years ago

While I assume that some of you already have this, I'm posting a link to the ISO HEIF specification for reference.

Sami32 commented 5 years ago

Informations of some coming standard update on the way: https://aomediacodec.github.io/av1-avif/

akmeikle commented 4 years ago

Bumping this request.

haraldk commented 4 years ago

@akmeikle

As mentioned above, implementing HEIF/HEIC is a big task. It won't happen until someone either contributes working code for decoding HEVC in Java, or is willing to finance the development of the codec.

If you are able to help with either code contributions or financial support, that would be great!

-- Harald K

gerritgriebel commented 1 year ago

Support of HEIC was on my Todo list for today and I thought it was a no brainer, as ChatGPT told me long ago (and still) that TwelveMonkeys support exists 😂

haraldk commented 1 year ago

Maybe if you ask ChatGPT to show you the source code, we could have it implemented in no time? 🤔

addvanced commented 1 year ago

Yeah, I got the same amazing response from ChatGPT. I asked where I could find the source code, and.. Here's the answer:

Certainly! The source code for the imageio-heic library, part of the TwelveMonkeys ImageIO project, can be found on the GitHub repository:

Repository: https://github.com/haraldk/TwelveMonkeys
The imageio-heic module, along with other modules of the TwelveMonkeys ImageIO project, is located in the imageio directory within the repository. You can navigate to the specific module to access its source code.

Here's the direct link to the imageio-heic module source code:

Source Code: https://github.com/haraldk/TwelveMonkeys/tree/master/imageio/imageio-heic
In the repository, you'll find the complete source code, including implementation classes, utilities, tests, and any additional resources related to the imageio-heic module.

Feel free to explore the repository and dive into the source code to understand the inner workings of the imageio-heic library and how it provides HEIC image support within the TwelveMonkeys ImageIO project.

So... now you all know where it (doesn't) exist! ;)

haraldk commented 1 year ago

Brilliant! I think you need to push it harder, perhaps ask it to quote from or list the HEICDecoder.java source. 😉

Enternal-ZERO commented 1 year ago

@haraldk hi, I found "JDeli",but only business support. https://support.idrsolutions.com/jdeli/tutorials/reading/java-heic-reader "100% Java solution. No dlls or dependencies on native code" I hope you can "translate" it, then bring us a free one~

THausherr commented 1 year ago

Commercial product https://support.idrsolutions.com/jdeli/faqs/where-can-a-jdeli-license-be-purchased

Enternal-ZERO commented 1 year ago

Commercial product https://support.idrsolutions.com/jdeli/faqs/where-can-a-jdeli-license-be-purchased

yeah ! so we suggest TwelveMonkeys make a free one

Enternal-ZERO commented 1 year ago

Commercial product https://support.idrsolutions.com/jdeli/faqs/where-can-a-jdeli-license-be-purchased Does Apache Tika support heif without dlls? @THausherr

THausherr commented 1 year ago

It gets the metadata using the metadata parser from Drew Noakes.

Enternal-ZERO commented 1 year ago

It gets the metadata using the metadata parser from Drew Noakes.

Okay,I have used Drew Noakes.The new version support heif but only metadata and I want get real height and width. metadata is not enoufh.

gotson commented 10 months ago

For those interested, v0.5.0 of NightMonkeys brings HEIF/AVIF read support via libheif. It needs Java 21 and preview features.

Please do not clutter this thread with NightMonkeys questions, so please open issues on the NightMonkeys repo, or ask questions via discussions!