renpy / pygame_sdl2

Reimplementation of portions of the pygame API using SDL2.
GNU Lesser General Public License v2.1
328 stars 65 forks source link

Save surface to file efficiently #121

Open Beuc opened 4 years ago

Beuc commented 4 years ago

Hi,

While experimenting with generating low-res (highly pixellated through renpy.display.module.pixellate) image placeholders for RenPyWeb with on-demand resource download, generated from the Laucher, I needed an efficient way to save such placeholders on disk (for inclusion in game.zip, downloaded on game startup).

The JPG function is not well suited for this: even with a 0 quality the file size is still pretty high compared to other options.

The PNG function works but does not compare with e.g. GIMP or ImageMagick wrt size efficiency (which requires some PNG line filters heuristic and/or brute-force AFAIU). In addition, it does not support 8-bit colors which would help in this context.

There is no WEBP support, and my tests indicate that this format would be more size-efficient for saving such placeholders on disk. So adding WEBP support to pygame_sdl2.image.save would help.

I may or may not find another trick to save image placeholders efficiently (I plan to experiment with shrinking+scaling back). I'm tentatively posting this to know whether WEBP saving support would be welcome.