nathan-osman / gimp-webp

Gimp plugin for loading and saving WebP images
GNU General Public License v3.0
69 stars 8 forks source link

Add magic format string #2

Open nathan-osman opened 9 years ago

nathan-osman commented 9 years ago

Gimp provides plugins with a function gimp_register_magic_load_handler() that can be used to select an appropriate loader based on the file contents. It would be nice if this plugin could provide such functionality.

The first few bytes of a WEBP image appear to match:

52 49 46 46 B0 EC 00 00 57 45 42 50 56 50 38    RIFF....WEBPVP8
draekko commented 8 years ago

Actually the 4 bytes in between RIFF and WEBP are file data size for the full payload. So it wouldn't work since that will vary for each file. See https://developers.google.com/speed/webp/docs/riff_container

phw commented 8 years ago

As I see it the gimp_register_magic_load_handler() function accepts a pattern where you can define an offset. If I interpret the examples at https://github.com/GNOME/gimp/search?p=3&q=gimp_register_magic_load_handler&utf8=%E2%9C%93 correctly something like 8,string,WEBPVP8 could work. Not sure if there is a way to also test for the leading RIFF in addition.

draekko commented 8 years ago

I've added it to my branch, adding only the check for WEBP at offset 8 seems enough to me.