2022-12-17 10:02:37 +00:00
|
|
|
{ lib
|
2023-11-16 04:20:00 +00:00
|
|
|
, stdenv
|
2022-12-17 10:02:37 +00:00
|
|
|
, buildPythonPackage
|
|
|
|
, pythonOlder
|
|
|
|
, fetchFromGitHub
|
|
|
|
, opencv4
|
|
|
|
, torch
|
|
|
|
, onnx
|
|
|
|
, onnxruntime
|
|
|
|
, pillow
|
|
|
|
, pywavelets
|
|
|
|
, numpy
|
2023-11-16 04:20:00 +00:00
|
|
|
, callPackage
|
|
|
|
, withOnnx ? false # Enables the rivaGan en- and decoding method
|
2022-12-17 10:02:37 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "invisible-watermark";
|
2023-11-16 04:20:00 +00:00
|
|
|
version = "0.2.0";
|
2022-12-17 10:02:37 +00:00
|
|
|
format = "setuptools";
|
|
|
|
disabled = pythonOlder "3.6";
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ShieldMnt";
|
|
|
|
repo = "invisible-watermark";
|
2023-11-16 04:20:00 +00:00
|
|
|
rev = "e58e451cff7e092457cd915e445b1a20b64a7c8f"; # No git tag, see https://github.com/ShieldMnt/invisible-watermark/issues/22
|
|
|
|
hash = "sha256-6SjVpKFtiiLLU7tZ3hBQr0KT/YEQyywJj0e21/dJRzk=";
|
2022-12-17 10:02:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
opencv4
|
|
|
|
torch
|
|
|
|
pillow
|
|
|
|
pywavelets
|
|
|
|
numpy
|
2023-11-16 04:20:00 +00:00
|
|
|
] ++ lib.optionals withOnnx [
|
|
|
|
onnx
|
|
|
|
onnxruntime
|
2022-12-17 10:02:37 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace setup.py \
|
|
|
|
--replace 'opencv-python>=4.1.0.25' 'opencv'
|
2023-11-16 04:20:00 +00:00
|
|
|
substituteInPlace imwatermark/rivaGan.py --replace \
|
|
|
|
'You can install it with pip: `pip install onnxruntime`.' \
|
|
|
|
'You can install it with an override: `python3Packages.invisible-watermark.override { withOnnx = true; };`.'
|
2022-12-17 10:02:37 +00:00
|
|
|
'';
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
passthru.tests = let
|
|
|
|
image = "${src}/test_vectors/original.jpg";
|
|
|
|
methods = [ "dwtDct" "dwtDctSvd" "rivaGan" ];
|
|
|
|
testCases = builtins.concatMap (method: [
|
|
|
|
{ method = method; withOnnx = true; }
|
|
|
|
{ method = method; withOnnx = false; }
|
|
|
|
]) methods;
|
|
|
|
createTest = { method, withOnnx }: let
|
|
|
|
testName = "${if withOnnx then "withOnnx" else "withoutOnnx"}-${method}";
|
|
|
|
# This test fails in the sandbox on aarch64-linux, see https://github.com/microsoft/onnxruntime/issues/10038
|
|
|
|
skipTest = stdenv.isLinux && stdenv.isAarch64 && withOnnx && method == "rivaGan";
|
|
|
|
in lib.optionalAttrs (!skipTest) {
|
|
|
|
"${testName}" = callPackage ./tests/cli.nix { inherit image method testName withOnnx; };
|
|
|
|
};
|
|
|
|
allTests = builtins.map createTest testCases;
|
|
|
|
in (lib.attrsets.mergeAttrsList allTests) // {
|
|
|
|
python = callPackage ./tests/python { inherit image; };
|
|
|
|
};
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
pythonImportsCheck = [ "imwatermark" ];
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "A library for creating and decoding invisible image watermarks";
|
2024-04-21 15:54:59 +00:00
|
|
|
mainProgram = "invisible-watermark";
|
2022-12-17 10:02:37 +00:00
|
|
|
homepage = "https://github.com/ShieldMnt/invisible-watermark";
|
|
|
|
license = licenses.mit;
|
|
|
|
maintainers = with maintainers; [ Luflosi ];
|
|
|
|
};
|
|
|
|
}
|