Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Support for WebP image format #82

Open
nejento opened this issue Jun 4, 2017 · 26 comments
Open

Support for WebP image format #82

nejento opened this issue Jun 4, 2017 · 26 comments

Comments

@nejento
Copy link

nejento commented Jun 4, 2017

Hello,
I'd like to ask, whether it would be possible to add a new render image format WebP. It's now widely supported by all Chromium browsers and if it would be optional as the jpg format is, it would be quite handy because we would be able to create maps in higher quality with smaller size.
I know that it's not supported by Gecko (Firefox) but it will be hopefully supported soon and it wouldn't be set as the default one.

Thank you for your response.

@bmarwell
Copy link
Contributor

bmarwell commented Dec 1, 2017

@mikeprimm do you accept pull requests? i saw the project has not been updated for a while.

@rhylos
Copy link
Contributor

rhylos commented Dec 1, 2017 via email

@bmarwell
Copy link
Contributor

bmarwell commented Dec 1, 2017

I thought that would be an easy one. Sadly, the library https://bitbucket.org/luciad/webp-imageio does require native libraries. I'm not sure shipping native libraries and need to configure them is wanted. :-(

@bmarwell
Copy link
Contributor

bmarwell commented Jan 1, 2018

I found out that there are Java classes provided by Google. I'll take a look into this issue soon.

@mikeprimm
Copy link
Member

mikeprimm commented Jan 3, 2018

Support could be added - I'd just be concerned about the span of browser support: see https://caniuse.com/#feat=webp

@bmarwell
Copy link
Contributor

bmarwell commented Jan 5, 2018

@mikeprimm
Don't have time for tests right now, but can you please take a quick look?

https://github.com/bmhm/DynmapCore/commit/c94057707312ea198c871ba0dd9ddc289b0030e2

@bmarwell
Copy link
Contributor

bmarwell commented Jan 5, 2018

@bmarwell
Copy link
Contributor

bmarwell commented Jan 5, 2018

@nejento @rhylos @mikeprimm

while my commits will add native webp support, one might opt to use mod_pagespeed and nginx instead for performance. This way there will be both jpg and webp files generated (webp in nginx process) which are only served to capable clients.

Anyway, webp would still be interesting as soon as you configure lossless or another lossy compression factor and more browsers will support it.

@nejento
Copy link
Author

nejento commented Jan 5, 2018

Regarding the browser support, it's actually not that hot with the browser support for the WebP format when you keep in mind that Chrome (and Chromium based browsers) are widely used by most of the web users. And when you implement the dynmap into your website you can always create a warning about unsupported browser or you can have secondary map in lower quality in jpg-80 so that it doesn't take up that much space and users of other browsers still can see the map.

The main thing about WebP is especially saving the space when keeping the high resolution and thus saving the space on servers hostings which offer for example only 10 GB space for you map.

@rautamiekka
Copy link

rautamiekka commented Jan 5, 2018

^ Not everyone is gonna change. Like me, I'm not changing from Firefox for WebP, and such thinking is just wrong.

@nejento
Copy link
Author

nejento commented Jan 5, 2018

I'm definitely not forcing anyone to switch to Chrome nor Opera nor Vivaldi nor to anything else. I'm just pointing out that since there is a majority of users using Chromium based browser that there can be the option to use WebP as smaller sized high quality image format.

Not everyone is using dynmap as a public thing. Just as some kind of supervision or just for great renders of the world. For that and many more reasons is implementing WebP a good step. :)

@bmarwell
Copy link
Contributor

bmarwell commented Jan 5, 2018

So, would you test and accept a pull request with the commits from above?? ^^

@mikeprimm
Copy link
Member

mikeprimm commented Jan 6, 2018

I'd accept it as a format option (so long as the library support for encoding WebP is pure Java - not getting in to building and distributing JNI libraries for every platform in creation....). Definitely wouldn't be default, nor a suggested format option: I really don't think the browser support is broad enough, and while the gains exist they aren't compelling enough to impact user's browser selection (latest data puts Chrome at 55% overall, 60% of desktop - that's majority, but the unsupported browser users represent at least 1/3 of the likely user community) - and, if you wind up using something that just-in-time converts the webp images to jpeg or png for non-supporting browsers, you're adding a bunch of runtime compute load.
Most folks with size sensitivity just opt for the JPEG format with some dialing in on the quality (since this will save a lot - more than lossless WebP vs PNG- even at relatively high quality (the default for our jpeg format (85% quality) tends to result in 60+% file size reduction versus PNG, with almost no perceivable difference in appearance)). I don't doubt that, lossy vs lossy, WebP will outperform classic JPEG (on size, cannot say for encoding performance), but I'd take the relatively slow adoption by non-Google browsers as supporting the notion that it isn't exactly a level of advantage that is being found to be particularly compelling.

@bmarwell
Copy link
Contributor

bmarwell commented Jan 6, 2018

@mikeprimm
Pure Java is not possible yet. No one has published this with acceptable licence and/or performance. Good thing is: There is no need to compile C libraries. For those interested, just drop the .dll file or .so file into the java native lib path. That's it.

So, even with these restrictions -- why not give the user a choice? Is it our choice to make that the user may not use WebP, because it is not adopted widely yet? If that were true, we have a hen-and-egg-problem. Someone just has to start using it. If someone wants to use it and it works, why stop them from using it?

Just my 2 cents. I'd still be happy if someone could test it. I'd also volunteer to write a wiki page on how to use it (java native lib path plus configuring).

mikeprimm added a commit that referenced this issue Jul 7, 2018
Provide webp support (#82)
mikeprimm pushed a commit that referenced this issue Jul 7, 2018
mikeprimm added a commit that referenced this issue Jul 7, 2018
mikeprimm added a commit that referenced this issue Jul 7, 2018
@sachk
Copy link

sachk commented Jun 25, 2019

So what's happening with this - is this ever going to be properly implemented? It'd make Dynmap far more usable.

@ghost
Copy link

ghost commented Jul 26, 2020

@mikeprimm @bmhm It took quite a few years to get here, but we've finally reached the point where virtually all browsers (including Firefox and Safari) support WEBP: https://caniuse.com/#search=webp

Any chance for official WEBP support in Dynmap to make use of these advancements?

@mikeprimm
Copy link
Member

mikeprimm commented Jul 26, 2020

The biggest issue is we need either the JVM to support the encoding to the format, or a pure java implementation of such an encoder. Dynmap is used on LOTS of platforms - Windows, Linux (ARM and Intel), MacOS, and more - so incorporating platform and OS version sensitive native shared libraries is a problem. The browser support isn't really a concern, as support for the format would always be optional to the server user - but I'm not willing to field support requests every other week because the native library in question doesn't support 32 bit vs 64 bit linux, or glibc vs uclibc, or Debian vs Redhat versus Alpine, etc, etc. If there is a good ENCODING library that is pure java - no JNI or other native dependencies (e.g. running tools like GIMP on the command line), I'd be happy to add support.

@mikeprimm
Copy link
Member

The biggest thing, honestly, is that the improvement in size is OK, but not something Earth shaking, so I'm not willing to add support load that I already don't have time to handle for the sake of '25-34% smaller size' (Google's claim - but versus the reference obsolete JPEG codec) or 'about 11% vs modern JPEG codecs' (per https://siipo.la/blog/is-webp-really-better-than-jpeg ).

@sachk
Copy link

sachk commented Jul 26, 2020

The biggest thing, honestly, is that the improvement in size is OK, but not something Earth shaking, so I'm not willing to add support load that I already don't have time to handle for the sake of '25-34% smaller size' (Google's claim - but versus the reference obsolete JPEG codec) or 'about 11% vs modern JPEG codecs' (per https://siipo.la/blog/is-webp-really-better-than-jpeg ).

This doesn't match up to my experience with screenshots from Minecraft -from what I've observed the difference appears to be much greater for images with large areas of the same colour and non-contiguous repeating patterns. The compression performance difference and lack of Java support makes it seem a lot less practical though.

@bmarwell
Copy link
Contributor

bmarwell commented Jul 26, 2020

I agree, it is not worth it as long as there is no easy native java support. Also, https://bitbucket.org/luciad/webp-imageio/src/default/ hasn't been updated in years. Same with other libraries, like https://github.com/lonnyj/webp-imageio.

There is also a library from spreadshirt, which also requires building a native library. All do.


about

to handle for the sake of '25-34% smaller size' […] or 'about 11% vs modern JPEG codecs'

and

This doesn't match up to my experience with screenshots from Minecraft

Why don't you just convert all generated images and see for yourself if it is worth it?
https://developers.google.com/speed/webp/docs/img2webp

Maybe it is more than 30% better for tiles, maybe it isn't. We will not know if we dont try it.

@bmarwell
Copy link
Contributor

// addendum
Maybe you want to open a JDK bug. Similar to this one?
https://bugs.openjdk.java.net/browse/JDK-8249136

Maybe it will be inlcuded in JDK17 if you hurry (which is the next LTS) =)

@sachk
Copy link

sachk commented Jul 26, 2020

I made a quick set of comparisons.

Flat Renders
Isometric Renders

To my eye, WEBP looks like much more than a 34% improvement and that's even with MozJPEG, which I think is quite a bit better than Java's built-in JPEG encoder.

I didn't bother comparing encoding speed since there's too many extra variables considering how small the results will be (PNG decompression, the analysis output cwebp prints, etc). I don't think that cwebp is slow enough to significantly decrease render times, but I could be wrong.

@mikeprimm
Copy link
Member

Cool - the main point is still this: I'm not adding something that will create a problem with cross-platform support: we need to find a non-JNI/non-CLI-tool solution to encoding WEBP, because of the previously stated reasons (besides the additional ones of many hosting folks not allowing the addition of native libraries and the like). This position isn't going to change, as support for WEBP is a 'nice to have' but introducing something that makes folks who are successfully using Dynmap already not be able to continue functioning properly - whether that is them running on a Raspberry Pi, or running Alpine Linux in a docker container, or running on old Sparc hardware (all of these are currently among the cases across the 18000 servers currently running just the Spigot/Paper version).

On the timeline side, we do have some time - https://caniuse.com/#search=webp shows it being in the 'technology preview' for Safari14, but not in the latest release version (which is 13.1.2). Breaking Safari a non-starter for the feature to even be offered in Dynmap, and the lack of IE 11 support is also a problem.

@bmarwell
Copy link
Contributor

Well, there's a solution for both problems.

  1. Browsers

Just put a warning in and let the server admins decide. That's an easy one. They can't blame dynmap, because the documentation will have started this.

  1. libraries

Well, you can ship the libs in a jar file, unpack them to a temporary directory at startup and load them in the runtime. In fact, I started a library project for this. I haven't completed it, but it's useable already. I can post the link later.
That will make the jni stuff easy to use. No setup required by server admins. No dependencies on a particular JVM or OS.

Webp library for jni would only needed to be compiled for each target system, but that's not too complicated.

@sachk
Copy link

sachk commented Jul 26, 2020 via email

@bmarwell
Copy link
Contributor

Here's the library I mentioned

https://github.com/bmhm/libloader

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants