diff --git a/TODO b/TODO index 6f65a300..eda52a4b 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,13 @@ +- something screwy in compass def? + + $ python2 ./test_convolution.py TestConvolution.test_x + +- configure should check for pygobject too + + PKG_CHECK_MODULES(PYTHON, [pygobject-3.0 >= $PYGOBJECT_REQUIRED]) + + have separate conditionals for old py and new py + - use vips_resize() in vipsthumbnail? should the sharpening filter be selectable? diff --git a/configure.ac b/configure.ac index cf655bf1..54bffd86 100644 --- a/configure.ac +++ b/configure.ac @@ -755,7 +755,9 @@ if test x"$with_python" != "xno"; then with_python=no AC_MSG_WARN([C++ is off, disabling Python binding]) else - AM_PATH_PYTHON(2.2,, + AM_PATH_PYTHON(2.7, + [pyoverridesdir="\$(pyexecdir)/gi/overrides" + AC_SUBST(pyoverridesdir)], [with_python=no AC_MSG_WARN([Python not found; disabling Python binding])]) fi diff --git a/python/Makefile.am b/python/Makefile.am index ef08f882..6a8d54a5 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -1,7 +1,5 @@ -pygioverridesdir = $(pyexecdir)/gi/overrides - -pygioverrides_PYTHON = \ - Vips.py +vips_overridesdir = $(pyoverridesdir) +vips_overrides_PYTHON = Vips.py EXTRA_DIST = \ README.md @@ -10,7 +8,7 @@ EXTRA_DIST = \ # source tree; Python does not accept the extensions and modules in different # paths build_pylinks: - for f in $(pygioverrides_PYTHON); do \ + for f in $(vips_overrides_PYTHON); do \ [ -e $(builddir)/$$f ] || $(LN_S) $(srcdir)/$$f $(builddir)/$$f; \ done diff --git a/test/test_convolution.py b/test/test_convolution.py index 73a5637a..5520abf4 100755 --- a/test/test_convolution.py +++ b/test/test_convolution.py @@ -6,6 +6,7 @@ from builtins import range from numbers import Number import unittest +import operator import math #import logging @@ -56,10 +57,20 @@ def conv(image, mask, x_position, y_position): for y in range(0, mask.height): m = mask.getpoint(x, y) i = image.getpoint(x + x_position, y + y_position) - p = run_fn2(lambda a, b: a * b, m, i) - s = run_fn2(lambda a, b: a + b, s, p) + p = run_fn2(operator.mul, m, i) + s = run_fn2(operator.add, s, p) - return run_fn2(lambda a, b: a / b, s, mask.get_scale()) + return run_fn2(operator.div, s, mask.get_scale()) + +def compass(image, mask, x_position, y_position, n_rot, fn): + acc = [] + for i in range(0, n_rot): + result = conv(image, mask, x_position, y_position) + result = run_fn(abs, result) + acc.append(result) + mask = mask.rot45() + + return reduce(lambda a, b: run_fn2(fn, a, b), acc) class TestConvolution(unittest.TestCase): # test a pair of things which can be lists for approx. equality @@ -73,15 +84,19 @@ class TestConvolution(unittest.TestCase): self.colour = im * [1, 2, 3] + [2, 3, 4] self.mono = self.colour.extract_band(1) self.all_images = [self.mono, self.colour] - sharp = Vips.Image.new_from_array([[-1, -1, -1], - [-1, 16, -1], - [-1, -1, -1]], scale = 8) - blur = Vips.Image.new_from_array([[1, 1, 1], - [1, 1, 1], - [1, 1, 1]], scale = 9) - line = Vips.Image.new_from_array([[1, 1, 1], [-2, -2, -2], [1, 1, 1]]) - sobel = Vips.Image.new_from_array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]]) - self.all_masks = [sharp, blur, line, sobel] + self.sharp = Vips.Image.new_from_array([[-1, -1, -1], + [-1, 16, -1], + [-1, -1, -1]], scale = 8) + self.blur = Vips.Image.new_from_array([[1, 1, 1], + [1, 1, 1], + [1, 1, 1]], scale = 9) + self.line = Vips.Image.new_from_array([[ 1, 1, 1], + [-2, -2, -2], + [ 1, 1, 1]]) + self.sobel = Vips.Image.new_from_array([[ 1, 2, 1], + [ 0, 0, 0], + [-1, -2, -1]]) + self.all_masks = [self.sharp, self.blur, self.line, self.sobel] def test_conv(self): for im in self.all_images: @@ -97,7 +112,29 @@ class TestConvolution(unittest.TestCase): true = conv(im, msk, 49, 49) self.assertAlmostEqualObjects(result, true) + def test_x(self): + im = self.mono + msk = self.sobel + result = conv(im, msk, 24, 49) + msk = msk.rot45() + + result = conv(im, msk, 24, 49) + msk = msk.rot45() + + def test_compass(self): + for im in self.all_images: + for msk in self.all_masks: + for prec in [Vips.Precision.INTEGER, Vips.Precision.FLOAT]: + convolved = im.compass(msk, + times = 3, + angle = Vips.Angle45.D45, + combine = Vips.Combine.MAX, + precision = prec) + + result = convolved.getpoint(25, 50) + true = compass(im, msk, 24, 49, 3, max) + self.assertAlmostEqualObjects(result, true) if __name__ == '__main__': unittest.main()