|
| 1 | +classWebpPixbufLoader <Formula |
| 2 | +desc"WebP Image format GdkPixbuf loader" |
| 3 | +homepage"https://github.com/aruiz/webp-pixbuf-loader" |
| 4 | +url"https://github.com/aruiz/webp-pixbuf-loader/archive/0.0.4.tar.gz" |
| 5 | +sha256"cd6e4ec44755e8df3e298688c0aeb72b9467bbdd03009989c0d94b219b30fb51" |
| 6 | +license"LGPL-2.0-or-later" |
| 7 | + |
| 8 | +depends_on"meson"=>:build |
| 9 | +depends_on"ninja"=>:build |
| 10 | +depends_on"pkg-config"=>[:build,:test] |
| 11 | +depends_on"gdk-pixbuf" |
| 12 | +depends_on"webp" |
| 13 | + |
| 14 | +# Constants for gdk-pixbuf's multiple version numbers, which are the same as |
| 15 | +# the constants in the gdk-pixbuf formula. |
| 16 | +defgdk_so_ver |
| 17 | +Formula["gdk-pixbuf"].gdk_so_ver |
| 18 | +end |
| 19 | + |
| 20 | +defgdk_module_ver |
| 21 | +Formula["gdk-pixbuf"].gdk_module_ver |
| 22 | +end |
| 23 | + |
| 24 | +# Subfolder that pixbuf loaders are installed into. |
| 25 | +defmodule_subdir |
| 26 | +"lib/gdk-pixbuf-#{gdk_so_ver}/#{gdk_module_ver}/loaders" |
| 27 | +end |
| 28 | + |
| 29 | +definstall |
| 30 | +mkdir"build"do |
| 31 | +system"meson", *std_meson_args,"-Dgdk_pixbuf_moduledir=#{prefix}/#{module_subdir}",".." |
| 32 | +system"ninja","-v" |
| 33 | +system"ninja","install","-v" |
| 34 | +end |
| 35 | +end |
| 36 | + |
| 37 | +# After the loader is linked in, update the global cache of pixbuf loaders |
| 38 | +defpost_install |
| 39 | +ENV["GDK_PIXBUF_MODULEDIR"]="#{HOMEBREW_PREFIX}/#{module_subdir}" |
| 40 | +system"#{Formula["gdk-pixbuf"].opt_bin}/gdk-pixbuf-query-loaders","--update-cache" |
| 41 | +end |
| 42 | + |
| 43 | +testdo |
| 44 | +# Generate a .webp file to test with. |
| 45 | +system"#{Formula["webp"].opt_bin}/cwebp",test_fixtures("test.png"),"-o","test.webp" |
| 46 | + |
| 47 | +# Sample program to load a .webp file via gdk-pixbuf. |
| 48 | +(testpath/"test.c").write<<~EOS |
| 49 | + #include <gdk-pixbuf/gdk-pixbuf.h> |
| 50 | +
|
| 51 | + gint main (gint argc, gchar **argv) { |
| 52 | + GError *error = NULL; |
| 53 | + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (argv[1], &error); |
| 54 | + if (error) { |
| 55 | + g_error("%s", error->message); |
| 56 | + return 1; |
| 57 | + }; |
| 58 | +
|
| 59 | + g_assert(gdk_pixbuf_get_width(pixbuf) == 8); |
| 60 | + g_assert(gdk_pixbuf_get_height(pixbuf) == 8); |
| 61 | + g_object_unref(pixbuf); |
| 62 | + return 0; |
| 63 | + } |
| 64 | + EOS |
| 65 | + |
| 66 | +flags=shell_output("pkg-config --cflags --libs gdk-pixbuf-#{gdk_so_ver}").chomp.split |
| 67 | +systemENV.cc,"test.c","-o","test_loader", *flags |
| 68 | +system"./test_loader","test.webp" |
| 69 | +end |
| 70 | +end |