Fix #590: Do you have plan to support webp format
authorColin Clark <colin.clark@cclark.uk>
Sat, 6 Jul 2019 16:28:35 +0000 (17:28 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sat, 6 Jul 2019 16:28:35 +0000 (17:28 +0100)
https://github.com/BestImageViewer/geeqie/issues/590

The package gdk-pixbuf-loader-webp is not in Debian. The loader can be
complied from source from:
https://github.com/aruiz/webp-pixbuf-loader

However at the moment it is easier for the user if it is compiled in to
Geeqie.

README.md
configure.ac
doc/docbook/GuideReferencePixbufLoaders.xml
doc/docbook/GuideReferenceSupportedFormats.xml
src/Makefile.am
src/filefilter.c
src/image-load.c
src/image_load_webp.c [new file with mode: 0644]
src/image_load_webp.h [new file with mode: 0644]
web/geeqie-install-debian.sh

index d4eda96..be2afd5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -70,7 +70,7 @@ Geeqie is a graphics file viewer. Basic features:
     * output: single image, anaglyph, SBS, mirror, SBS half size (3DTV)
 
 *   Viewing raster and vector images, in the following formats:
-3FR, ANI, APM, ARW, BMP, CR2, CRW, CUR, DNG, ERF, GIF, ICNS, ICO, JPE/JPEG/JPG, JPS, KDC, MEF, MPO, MOS, MRW, NEF, ORF, PEF, PTX, PBM/PGM/PNM/PPM, PNG, QIF/QTIF (QuickTime Image Format), RAF, RAW, RW2, SR2, SRF, SVG/SVGZ, TGA/TARGA, TIF/TIFF, WMF, XBM, XPM, HEIF (primary image only). Animated GIFs are supported.
+3FR, ANI, APM, ARW, BMP, CR2, CRW, CUR, DNG, ERF, GIF, ICNS, ICO, JPE/JPEG/JPG, JPS, KDC, MEF, MPO, MOS, MRW, NEF, ORF, PEF, PTX, PBM/PGM/PNM/PPM, PNG, QIF/QTIF (QuickTime Image Format), RAF, RAW, RW2, SR2, SRF, SVG/SVGZ, TGA/TARGA, TIF/TIFF, WMF, XBM, XPM, HEIF (primary image only), WEBP. Animated GIFs are supported.
 
 * Preview and thumbnails of video clips can be displayed. Clips can be run via a defined external program.
 
@@ -260,6 +260,12 @@ And either the ChangeLog file or [Geeqie ChangeLog](http://geeqie.org/cgi-bin/gi
      exiv2
         Additional command-line tools for various operations
 
+    libheif
+        For displaying HEIF images
+
+    libwebp
+        For displaying webp images
+
 ### Code hackers:
 
 If you plan on making any major changes to the code that will be offered for
index 4a14918..f7a532c 100644 (file)
@@ -601,6 +601,31 @@ AM_CONDITIONAL(HAVE_HEIF, [test "x$HAVE_HEIF" = xyes])
 AC_SUBST(HEIF_CFLAGS)
 AC_SUBST(HEIF_LIBS)
 
+#  WebP support
+# ----------------------------------------------------------------------
+
+AC_ARG_ENABLE([webp],
+  AC_HELP_STRING([--disable-webp], [disable webp support]),
+    [libwebp=$enableval], [libwebp=auto])
+
+if test "x${libwebp}" != "xno"; then
+  PKG_CHECK_MODULES(WEBP, libwebp >= 0.6.1,
+    [
+      HAVE_WEBP=yes
+      AC_DEFINE(HAVE_WEBP, 1, [define to enable webp support])
+    ],
+    [
+      HAVE_WEBP=no
+      AC_MSG_WARN([$WEBP_PKG_ERRORS])
+    ])
+else
+    HAVE_WEBP=disabled
+fi
+
+AM_CONDITIONAL(HAVE_WEBP, [test "x$HAVE_WEBP" = xyes])
+AC_SUBST(WEBP_CFLAGS)
+AC_SUBST(WEBP_LIBS)
+
 #  Markdown support
 # ----------------------------------------------------------------------
 
@@ -706,7 +731,8 @@ Support:
   Lua:          $HAVE_LUA
   FFmpegthumbnailer:   $HAVE_FFMPEGTHUMBNAILER
   Pdf:          $HAVE_PDF
-  Heif:                 $HAVE_HEIF
+  HEIF:                 $HAVE_HEIF
+  WebP:                 $HAVE_WEBP
 
 Documentation:
   Doxygen:       $DX_DOXYGEN
index f49fb44..e316df3 100644 (file)
     <title>wmf</title>\r
     <para>libwmf0.2-7-gtk</para>\r
   </section>\r
-  <section id="webp">\r
-    <title>webp</title>\r
-    <para>\r
-      <programlisting>https://github.com/aruiz/webp-pixbuf-loader</programlisting>\r
-    </para>\r
-    <para>\r
-      Example installation script:\r
-      <programlisting>\r
-        sudo apt-get install libglib2.0-dev libgdk-pixbuf2.0-dev libwebp-dev\r
-        wget https://github.com/aruiz/webp-pixbuf-loader/archive/master.zip\r
-        unzip master.zip\r
-        cd webp-pixbuf-loader-master\r
-        ./waf configure\r
-        ./waf build\r
-        sudo ./waf install\r
-      </programlisting>\r
-    </para>\r
-    <para />\r
-  </section>\r
   <section id="xcf">\r
     <title>xcf</title>\r
     <para>\r
index 8d93f6c..6f42291 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>\r
 <section id="GuideReferenceSupportedFormats">\r
   <title id="titleGuideReferenceSupportedFormats">Supported File Formats</title>\r
-  <para>3FR, ANI, APM, ARW, BMP, CR2, CRW, CUR, DDS, DNG, ERF, GIF, ICNS, ICO, JPE/JPEG/JPG, JPS, KDC, MEF, MPO, MOS, MRW, NEF, ORF, PEF, PTX, PBM/PGM/PNM/PPM, PNG, QIF/QTIF (QuickTime Image Format), RAF, RAW, RW2, SR2, SRF, SVG/SVGZ, TGA/TARGA, TIF/TIFF, WMF, XBM, XPM, HEIF (primary image only). Animated GIFs are supported.</para>\r
+  <para>3FR, ANI, APM, ARW, BMP, CR2, CRW, CUR, DDS, DNG, ERF, GIF, ICNS, ICO, JPE/JPEG/JPG, JPS, KDC, MEF, MPO, MOS, MRW, NEF, ORF, PEF, PTX, PBM/PGM/PNM/PPM, PNG, QIF/QTIF (QuickTime Image Format), RAF, RAW, RW2, SR2, SRF, SVG/SVGZ, TGA/TARGA, TIF/TIFF, WMF, XBM, XPM, HEIF (primary image only), WebP. Animated GIFs are supported.</para>\r
   <para>\r
     Refer to\r
     <link linkend="GuideReferencePixbufLoaders" endterm="titleGuideReferencePixbufLoaders" />\r
index 38a7e93..32565e0 100644 (file)
@@ -13,6 +13,7 @@ AM_CFLAGS =                           \
        $(FFMPEGTHUMBNAILER_CFLAGS)     \
        $(PDF_CFLAGS)   \
        $(HEIF_CFLAGS)  \
+       $(WEBP_CFLAGS)  \
        -I$(top_srcdir)                 \
        -I$(top_builddir)
 
@@ -29,6 +30,7 @@ AM_CXXFLAGS =                         \
        $(FFMPEGTHUMBNAILER_CFLAGS)     \
        $(PDF_CFLAGS)   \
        $(HEIF_CFLAGS)  \
+       $(WEBP_CFLAGS)  \
        -I$(top_srcdir)                 \
        -I$(top_builddir)
 
@@ -191,6 +193,8 @@ geeqie_SOURCES = \
        image_load_pdf.h\
        image_load_heif.c\
        image_load_heif.h\
+       image_load_webp.c\
+       image_load_webp.h\
        image_load_ffmpegthumbnailer.c\
        image_load_ffmpegthumbnailer.h\
        image-overlay.c \
@@ -280,7 +284,7 @@ geeqie_SOURCES = \
        zonedetect.c    \
        zonedetect.h
 
-geeqie_LDADD = $(GTK_LIBS) $(GLIB_LIBS) $(INTLLIBS) $(JPEG_LIBS) $(TIFF_LIBS) $(LCMS_LIBS) $(EXIV2_LIBS) $(LIBCHAMPLAIN_LIBS) $(LIBCHAMPLAIN_GTK_LIBS) $(LUA_LIBS) $(CLUTTER_LIBS) $(CLUTTER_GTK_LIBS) $(FFMPEGTHUMBNAILER_LIBS) $(PDF_LIBS) $(HEIF_LIBS)
+geeqie_LDADD = $(GTK_LIBS) $(GLIB_LIBS) $(INTLLIBS) $(JPEG_LIBS) $(TIFF_LIBS) $(LCMS_LIBS) $(EXIV2_LIBS) $(LIBCHAMPLAIN_LIBS) $(LIBCHAMPLAIN_GTK_LIBS) $(LUA_LIBS) $(CLUTTER_LIBS) $(CLUTTER_GTK_LIBS) $(FFMPEGTHUMBNAILER_LIBS) $(PDF_LIBS) $(HEIF_LIBS) $(WEBP_LIBS)
 
 EXTRA_DIST = \
        $(extra_SLIK)
index 1fc5328..0ea3d08 100644 (file)
@@ -293,6 +293,7 @@ void filter_add_defaults(void)
        filter_add_if_missing("dds", "DirectDraw Surface", ".dds", FORMAT_CLASS_IMAGE, FALSE, FALSE, TRUE);
        filter_add_if_missing("pdf", "Portable Document Format", ".pdf", FORMAT_CLASS_PDF, FALSE, FALSE, TRUE);
        filter_add_if_missing("HEIF", "HEIF Format", ".heic", FORMAT_CLASS_IMAGE, FALSE, FALSE, TRUE);
+       filter_add_if_missing("webp", "WebP Format", ".webp", FORMAT_CLASS_IMAGE, FALSE, FALSE, TRUE);
 }
 
 GList *filter_to_list(const gchar *extensions)
index 24e5845..11045c4 100644 (file)
@@ -29,6 +29,7 @@
 #include "image_load_heif.h"
 #include "image_load_ffmpegthumbnailer.h"
 #include "image_load_collection.h"
+#include "image_load_webp.h"
 
 #include "exif.h"
 #include "filedata.h"
@@ -637,6 +638,16 @@ static void image_loader_setup_loader(ImageLoader *il)
                }
        else
 #endif
+#ifdef HAVE_WEBP
+       if (il->bytes_total >= 12 &&
+               (memcmp(il->mapped_file, "RIFF", 4) == 0) &&
+               (memcmp(il->mapped_file + 8, "WEBP", 4) == 0))
+               {
+               DEBUG_1("Using custom webp loader");
+               image_loader_backend_set_webp(&il->backend);
+               }
+       else
+#endif
 #ifdef HAVE_JPEG
        if (il->bytes_total >= 2 && il->mapped_file[0] == 0xff && il->mapped_file[1] == 0xd8)
                {
diff --git a/src/image_load_webp.c b/src/image_load_webp.c
new file mode 100644 (file)
index 0000000..e6b614e
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 20019 - The Geeqie Team
+ *
+ * Author: Colin Clark
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "main.h"
+
+#include "image-load.h"
+#include "image_load_webp.h"
+
+#ifdef HAVE_WEBP
+#include <webp/decode.h>
+
+typedef struct _ImageLoaderWEBP ImageLoaderWEBP;
+struct _ImageLoaderWEBP {
+       ImageLoaderBackendCbAreaUpdated area_updated_cb;
+       ImageLoaderBackendCbSize size_cb;
+       ImageLoaderBackendCbAreaPrepared area_prepared_cb;
+       gpointer data;
+       GdkPixbuf *pixbuf;
+       guint requested_width;
+       guint requested_height;
+       gboolean abort;
+};
+
+static void free_buffer(guchar *pixels, gpointer data)
+{
+       g_free(pixels);
+}
+
+static gboolean image_loader_webp_load(gpointer loader, const guchar *buf, gsize count, GError **error)
+{
+       ImageLoaderWEBP *ld = (ImageLoaderWEBP *) loader;
+       guint8* data;
+       gint width, height;
+       gboolean res_info;
+       WebPBitstreamFeatures features;
+       VP8StatusCode status_code;
+
+       res_info = WebPGetInfo(buf, count, &width, &height);
+       if (!res_info)
+               {
+               log_printf("warning: webp reader error\n");
+               return FALSE;
+               }
+
+       status_code = WebPGetFeatures(buf, count, &features);
+       if (status_code != VP8_STATUS_OK)
+               {
+               log_printf("warning: webp reader error\n");
+               return FALSE;
+               }
+
+       if (features.has_alpha)
+               {
+               data = WebPDecodeRGBA(buf, count, &width, &height);
+               }
+       else
+               {
+               data = WebPDecodeRGB(buf, count, &width, &height);
+               }
+
+       ld->pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, features.has_alpha, 8, width, height, width * (features.has_alpha ? 4 : 3), free_buffer, NULL);
+
+       ld->area_updated_cb(loader, 0, 0, width, height, ld->data);
+
+       return TRUE;
+}
+
+static gpointer image_loader_webp_new(ImageLoaderBackendCbAreaUpdated area_updated_cb, ImageLoaderBackendCbSize size_cb, ImageLoaderBackendCbAreaPrepared area_prepared_cb, gpointer data)
+{
+       ImageLoaderWEBP *loader = g_new0(ImageLoaderWEBP, 1);
+       loader->area_updated_cb = area_updated_cb;
+       loader->size_cb = size_cb;
+       loader->area_prepared_cb = area_prepared_cb;
+       loader->data = data;
+       return (gpointer) loader;
+}
+
+static void image_loader_webp_set_size(gpointer loader, int width, int height)
+{
+       ImageLoaderWEBP *ld = (ImageLoaderWEBP *) loader;
+       ld->requested_width = width;
+       ld->requested_height = height;
+}
+
+static GdkPixbuf* image_loader_webp_get_pixbuf(gpointer loader)
+{
+       ImageLoaderWEBP *ld = (ImageLoaderWEBP *) loader;
+       return ld->pixbuf;
+}
+
+static gchar* image_loader_webp_get_format_name(gpointer loader)
+{
+       return g_strdup("webp");
+}
+
+static gchar** image_loader_webp_get_format_mime_types(gpointer loader)
+{
+       static gchar *mime[] = {"image/webp", NULL};
+       return g_strdupv(mime);
+}
+
+static gboolean image_loader_webp_close(gpointer loader, GError **error)
+{
+       return TRUE;
+}
+
+static void image_loader_webp_abort(gpointer loader)
+{
+       ImageLoaderWEBP *ld = (ImageLoaderWEBP *) loader;
+       ld->abort = TRUE;
+}
+
+static void image_loader_webp_free(gpointer loader)
+{
+       ImageLoaderWEBP *ld = (ImageLoaderWEBP *) loader;
+       if (ld->pixbuf) g_object_unref(ld->pixbuf);
+       g_free(ld);
+}
+
+void image_loader_backend_set_webp(ImageLoaderBackend *funcs)
+{
+       funcs->loader_new = image_loader_webp_new;
+       funcs->set_size = image_loader_webp_set_size;
+       funcs->load = image_loader_webp_load;
+       funcs->write = NULL;
+       funcs->get_pixbuf = image_loader_webp_get_pixbuf;
+       funcs->close = image_loader_webp_close;
+       funcs->abort = image_loader_webp_abort;
+       funcs->free = image_loader_webp_free;
+       funcs->get_format_name = image_loader_webp_get_format_name;
+       funcs->get_format_mime_types = image_loader_webp_get_format_mime_types;
+}
+
+#endif
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
diff --git a/src/image_load_webp.h b/src/image_load_webp.h
new file mode 100644 (file)
index 0000000..7e4c3a9
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 20019 - The Geeqie Team
+ *
+ * Author: Colin Clark
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef IMAGE_LOAD_WEBP_H
+#define IMAGE_LOAD_WEBP_H
+
+#ifdef HAVE_WEBP
+void image_loader_backend_set_webp(ImageLoaderBackend *funcs);
+#endif
+
+#endif
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index d72896a..07e1ce3 100755 (executable)
@@ -77,8 +77,6 @@ optional_gtk3_array=(
 
 # Optional pixbuf loaders
 optional_loaders_array=(
-".webp WebP images"
-"webp"
 ".psd Photoshop images"
 "psd"
 ".xcf Gimp files"
@@ -205,22 +203,6 @@ install_options()
        fi
 }
 
-install_webp()
-{
-       rm -rf webp-pixbuf-loader-master
-       package_install libglib2.0-dev libgdk-pixbuf2.0-dev libwebp-dev python-minimal
-       wget https://github.com/aruiz/webp-pixbuf-loader/archive/master.zip
-       unzip master.zip
-       cd webp-pixbuf-loader-master
-       ./waf configure
-       ./waf build
-       sudo --askpass ./waf install
-       sudo --askpass gdk-pixbuf-query-loaders --update-cache
-       cd -
-       rm -rf webp-pixbuf-loader-master
-       rm master.zip
-}
-
 install_psd()
 {
        rm -rf gdk-pixbuf-psd
@@ -270,9 +252,6 @@ install_extra_loaders()
                while [ $# -gt 0 ];
                do
                        case $1 in
-                       "webp" )
-                               install_webp
-                       ;;
                        "psd" )
                                install_psd
                        ;;