WebP Imageplugin

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

WebP Imageplugin

Post by Rescator »

https://developers.google.com/speed/webp/

v0.2.0 seems very mature, and is the one used in Chrome AFAIK.

A image plugin is kind of a must for PureBasic since trying to use libwebp.lib with PB is kinda cumbersome as the image is upside down and a raw bitmap, so you have to use startdrawing() and imageoutput() and drawingbuffer() and a loop to flip the image vertically, while ideally the webp image should just be decoded and written directly to a image bitmap buffer in the right order.

WebP (Lossless) has aprox. 25% better compression than PNG.
WebP (Lossy) has aprox. 25% better compression than JPG.
WebP lossless with alpha takes up around the same size as a PNG without alpha.
WebP can have a lossy image but lossless alpha.
WebP can also have lossy alpha.
Both lossy and lossless have either quality or compression settings.

If a WebP plugin is made loading and saving would be like this:
LoadImage() is the same as the others.


SaveImage(#Image, Filename$ [, ImagePlugin [, Flags [, Depth]]]) ;this one is a little more complex.

New constant #PB_ImagePlugin_WEBP (or #PB_ImagePlugin_WebP ?)

Flags: Quality, a value from 0 to 100, with 100 being the same as WebP lossless mode, 100 to 106 being lossless compression speed 0 to 6 with 100 being fastest and 106 slowest.
Depth: optional, 8, 24, 32 (1 and 4 as well?)

Why this way? Because by the looks of it the webp example tools either use floating point from 0.0 to 1.0 or from 0 to 100 for lossy quality. And Lossless WebP is a different mode and has 7 different compression speeds (and thus compression rates, but they all are lossless) ranging 0 to 6. And this avoids having to change the function params.

And is WebP worth the effort? Absolutely. First of all it's under a similar license to the xml library. (basically it's the BSD license) so it ca be used in closed source/proprietary/commercial projects.

And more importantly the size reduction. A PNG image here that was 219KB (after optimized using 3 different PNG optimizers) became only 167KB with WebP lossless mode, that's around 30% size reduction.
See http://en.wikipedia.org/wiki/WebP#Support for a growing list of what supports WebP. Also lates Firefox releases also support WebP, so the list on wikipedia is a little outdated.

For WebP lossless decoding speed (which is as important as the compression IMO) https://developers.google.com/speed/web ... lpha_study (look at Table 3. Average decoding time).


OK! I'll stop gushing and shut up now... But WebP has really impressed me.
User avatar
Pforzheimer
User
User
Posts: 21
Joined: Thu Sep 25, 2008 7:12 am
Location: Germany
Contact:

Re: WebP Imageplugin

Post by Pforzheimer »

+1

EncodeImage() would be most important for me right now.

UseWebPImageDecoder(), UseWebPImageEncoder(), SaveImage(), LoadImage()

Nice Greetings
and thank you for the nice work in the last years :D[/b]
Still awaiting real brain interface for computers :-)
[ REGISTERED PB OWNER since years ] [Wind0ws + LINUX]
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: WebP Imageplugin

Post by Mijikai »

Seems that their (especially lossy) compression is worse than anything else quality wise.
I dont see any good reason why this would be a preferable or needed option.
Further the bad quality should not be a suprise since google uses a videocodec on still images!
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: WebP Imageplugin

Post by Seymour Clufley »

As the WebP format is now viewable on 80% of web browsers, it would seem like a format worth adding to PB.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: WebP Imageplugin

Post by BarryG »

+1, and for HEIF if possible because it's very common now for online images.
Post Reply