Skip to content

Commit

Permalink
libavif: build gdk-pixbuf loader and thumbnailer
Browse files Browse the repository at this point in the history
AOMediaCodec/libavif#182
AOMediaCodec/libavif#977

Mostly mirrors webp-pixbuf-loader.

Also use prefixed names for `loaders.cache` so that users can install
multiple loaders in a profile without collisions.
  • Loading branch information
mkg20001 authored and ncfavier committed Jul 22, 2023
1 parent 4b7ad2c commit 6b98ff1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkgs/development/libraries/gdk-pixbuf/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ stdenv.mkDerivation (finalAttrs: {
pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
};

# gdk_pixbuf_moduledir variable from gdk-pixbuf-2.0.pc
moduleDir = "lib/gdk-pixbuf-2.0/2.10.0/loaders";
# gdk_pixbuf_binarydir and gdk_pixbuf_moduledir variables from gdk-pixbuf-2.0.pc
binaryDir = "lib/gdk-pixbuf-2.0/2.10.0";
moduleDir = "${finalAttrs.passthru.binaryDir}/loaders";
};

meta = with lib; {
Expand Down
28 changes: 28 additions & 0 deletions pkgs/development/libraries/libavif/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
, libjpeg
, dav1d
, libyuv
, gdk-pixbuf
, makeWrapper
}:

let
gdkPixbufModuleDir = "${placeholder "out"}/${gdk-pixbuf.moduleDir}";
gdkPixbufModuleFile = "${placeholder "out"}/${gdk-pixbuf.binaryDir}/avif-loaders.cache";
in

stdenv.mkDerivation rec {
pname = "libavif";
version = "0.11.1";
Expand All @@ -29,14 +36,18 @@ stdenv.mkDerivation rec {
"-DAVIF_CODEC_DAV1D=ON" # best decoder (fast)
"-DAVIF_CODEC_AOM_DECODE=OFF"
"-DAVIF_BUILD_APPS=ON"
"-DAVIF_BUILD_GDK_PIXBUF=ON"
];

nativeBuildInputs = [
cmake
pkg-config
gdk-pixbuf
makeWrapper
];

buildInputs = [
gdk-pixbuf
libaom
zlib
libpng
Expand All @@ -45,6 +56,23 @@ stdenv.mkDerivation rec {
libyuv
];

postPatch = ''
substituteInPlace contrib/gdk-pixbuf/avif.thumbnailer.in \
--replace '@CMAKE_INSTALL_FULL_BINDIR@/gdk-pixbuf-thumbnailer' "$out/libexec/gdk-pixbuf-thumbnailer-avif"
'';

env.PKG_CONFIG_GDK_PIXBUF_2_0_GDK_PIXBUF_MODULEDIR = gdkPixbufModuleDir;

postInstall = ''
GDK_PIXBUF_MODULEDIR=${gdkPixbufModuleDir} \
GDK_PIXBUF_MODULE_FILE=${gdkPixbufModuleFile} \
gdk-pixbuf-query-loaders --update-cache
mkdir -p "$out/bin"
makeWrapper ${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer "$out/libexec/gdk-pixbuf-thumbnailer-avif" \
--set GDK_PIXBUF_MODULE_FILE ${gdkPixbufModuleFile}
'';

meta = with lib; {
description = "C implementation of the AV1 Image File Format";
longDescription = ''
Expand Down
5 changes: 1 addition & 4 deletions pkgs/development/libraries/webp-pixbuf-loader/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

let
inherit (gdk-pixbuf) moduleDir;

# turning lib/gdk-pixbuf-#.#/#.#.#/loaders into lib/gdk-pixbuf-#.#/#.#.#/loaders.cache
# removeSuffix is just in case moduleDir gets a trailing slash
loadersPath = (lib.strings.removeSuffix "/" gdk-pixbuf.moduleDir) + ".cache";
loadersPath = "${gdk-pixbuf.binaryDir}/webp-loaders.cache";
in
stdenv.mkDerivation rec {
pname = "webp-pixbuf-loader";
Expand Down

0 comments on commit 6b98ff1

Please sign in to comment.