-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
WebP: Expose animation frame data #711
Comments
I see that GifImageReader is public. It also implements
One change I would like to see is for GIFImageReader.getImageMetadata to specify exact return type (GIFImageMetadata) to avoid the cast. I think WebpImageReader should follow suit. |
It appears even the GIFImageMetadata is not com.drew, but JDK and using it gives compilation error due to the java module system:
That is rather unfortunate. |
Hi, I'm a bit confused right now, but I think you are mixing up a lot of different libraries here... This is the TwelveMonkeys ImageIO issue tracker. We cannot help with OpenJDK GIF plugin (com.sun...) or MetadataExtractor (com.drew...) issues. But to your initial request, yes, we don't yet expose the WebP animation control data, but the plan is to do so. Through the standard image metadata interface, using a native WebP metadata format. The plan is to model this format kind of similar to the one found in the OpenJDK Feel free to propose a PR with the needed changes! -- |
I had a look at the getImageMetadata and IIOMetadataFormat classes and I remain confused. Pls confirm:
My ideal: fun ImageReader.getAnimationDelay(index: Int) = when (val m = getImageMetadata(index)) {
is GifImageMetadata-> m.delay
is WebpImageMetadata -> m.duration
else -> fail { "unsupported } // or return null or whatever
} What I see from your response:
which is ridiculous, particularly if the readers already have this information available in a type-safe way, without parsing, converting, intermediate xmls and so on. Because of the modules, I can not even do an instanceof on the reader to handle gif an webp differently. I feel I am completely missing something here. As I said, I could create a PR if there is a clear and useful pathway here, but so far I dont see any. I need a bone thrown my way. So far im using this solution that relies on Java reflection:
|
As I already said:
In addition:
Let's focus on the things we can fix.
|
There is no way to obtain animated webp frame data, such as duration of the frame. This is necessary to be able to read webp and show animation with correct speed. Currently, WebpImageReader does not expose any information about animation duration. This information is already read and stored in
WebpImageReader.header: List<AnimationFrame>
, however it is not publicly obtainable.I have managed to obtain this information with reflection and read all frames with correct duration times and display correct animation in a JavaFX Application (using JavaFX Timeline). The pseudocode regarding the reader is:
The methods
reader.getWidth
andreader.getHeight
delegate internally toframes[imageIndex].width
andframes[imageIndex].height
respectively. Similarly, a methodreader.getDuration(i: Int)
could be added, which is the requested feature here. This would allow clients to avoid using reflection.The problem however is also that WebpImageReader is not public class and as such, no non-inherited API could be used by clients. In my opinion, making the class public and adding an API is proper solution, as subclasses providing specific APIs is fine design. However, I feel, the Reader classes in imageio were purposefully hidden, so I would like to know what the proper strategy is here.
Another concern is how the new methods would work if the image is not animated. Either return some synthetic value or throw exception.
I can put in necessary work and create PR for this. I'd like to hear from the authors first though, so to avoid implementing a dead end solution.
MetadataReader consistency
In addition, WebPMetadataReader seems inconsistent with GifMetadataReader, which returns directories containing all gif Control tags, with each frame's animation duration. Webp metadata does not contain any of this information, though it does contain flag whether it is animated. The code to print this data is:
Checking if image is animated
For completeness' sake, here is a way to check whether gif image is animated (maybe there is better way):
I do not like reading all image metadata for this check - it seems like a heavy operation. Particularly for webp, there is a better way to check this flag, but it requires custom reading of the file's input stream as shown here https://stackoverflow.com/a/73170213.
I feel like there is missing API here - WebpMetadataReader.readFirstDirectoryOfType(file: File, directoryType: Class<?>), which would be as efficient as the SO answer, that only reads what's specified. I'd like to hear author's opinion about this.
Ideally, ImageReader would be able to return animation aspect of the loaded image, however since BufferedImage and the like have no proeprties/userData, there is little that can be done here. This is exactly why reading animation frames as BufferedImages does not provide the duration information - there is nowhere to store it.
The text was updated successfully, but these errors were encountered: