From: Colin Clark Date: Sat, 6 Jul 2019 16:28:35 +0000 (+0100) Subject: Fix #590: Do you have plan to support webp format X-Git-Tag: v1.6~181 X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=commitdiff_plain;h=72355b884bff0309109b423c54b876c038ce324e Fix #590: Do you have plan to support webp format 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. --- diff --git a/README.md b/README.md index d4eda969..be2afd5a 100644 --- 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 diff --git a/configure.ac b/configure.ac index 4a14918f..f7a532ca 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/doc/docbook/GuideReferencePixbufLoaders.xml b/doc/docbook/GuideReferencePixbufLoaders.xml index f49fb446..e316df3d 100644 --- a/doc/docbook/GuideReferencePixbufLoaders.xml +++ b/doc/docbook/GuideReferencePixbufLoaders.xml @@ -11,25 +11,6 @@ wmf libwmf0.2-7-gtk -
- webp - - https://github.com/aruiz/webp-pixbuf-loader - - - Example installation script: - - sudo apt-get install libglib2.0-dev libgdk-pixbuf2.0-dev libwebp-dev - wget https://github.com/aruiz/webp-pixbuf-loader/archive/master.zip - unzip master.zip - cd webp-pixbuf-loader-master - ./waf configure - ./waf build - sudo ./waf install - - - -
xcf diff --git a/doc/docbook/GuideReferenceSupportedFormats.xml b/doc/docbook/GuideReferenceSupportedFormats.xml index 8d93f6c2..6f422912 100644 --- a/doc/docbook/GuideReferenceSupportedFormats.xml +++ b/doc/docbook/GuideReferenceSupportedFormats.xml @@ -1,7 +1,7 @@
Supported File Formats - 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. + 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. Refer to diff --git a/src/Makefile.am b/src/Makefile.am index 38a7e935..32565e04 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) diff --git a/src/filefilter.c b/src/filefilter.c index 1fc53285..0ea3d083 100644 --- a/src/filefilter.c +++ b/src/filefilter.c @@ -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) diff --git a/src/image-load.c b/src/image-load.c index 24e5845b..11045c4f 100644 --- a/src/image-load.c +++ b/src/image-load.c @@ -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 index 00000000..e6b614e1 --- /dev/null +++ b/src/image_load_webp.c @@ -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 + +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 index 00000000..7e4c3a93 --- /dev/null +++ b/src/image_load_webp.h @@ -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: */ diff --git a/web/geeqie-install-debian.sh b/web/geeqie-install-debian.sh index d72896a6..07e1ce35 100755 --- a/web/geeqie-install-debian.sh +++ b/web/geeqie-install-debian.sh @@ -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 ;;