From 36331739abe760a0d7703955c9fff189df665383 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 26 May 2015 10:32:15 +0100 Subject: [PATCH] add bandand() bandor() bandeor() to py convenience funcs --- ChangeLog | 1 + python/Vips.py | 12 ++++++++++++ test/test_conversion.py | 6 +++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 539d7017..1b7ccbee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ - vipsthumbnail uses vips_resize() rather than its own code - vipsthumbnail uses vips_premultiply() for better alpha quality - vips_copy() can turn 1xN or Nx1 M-band images into MxN one-band images +- added bandand() bandor() bandeor() convenience funcs to Python 7/5/15 started 8.0.3 - dzsave and tif pyr write could fail for some image dimensions, thanks Jonas diff --git a/python/Vips.py b/python/Vips.py index bbf97682..a739d290 100644 --- a/python/Vips.py +++ b/python/Vips.py @@ -840,6 +840,18 @@ class Image(Vips.Image): """Return the nearest integral value.""" return self.round(Vips.OperationRound.RINT) + def bandand(self): + """AND image bands together.""" + return self.bandbool(Vips.OperationBoolean.AND) + + def bandor(self): + """OR image bands together.""" + return self.bandbool(Vips.OperationBoolean.OR) + + def bandeor(self): + """EOR image bands together.""" + return self.bandbool(Vips.OperationBoolean.EOR) + def bandsplit(self): """Split an n-band image into n separate images.""" return [x for x in self] diff --git a/test/test_conversion.py b/test/test_conversion.py index cc737bf4..fd0c7859 100755 --- a/test/test_conversion.py +++ b/test/test_conversion.py @@ -146,7 +146,7 @@ class TestConversion(unittest.TestCase): def test_band_and(self): def band_and(x): if isinstance(x, Vips.Image): - return x.bandbool(Vips.OperationBoolean.AND) + return x.bandand() else: return [reduce(lambda a, b: int(a) & int(b), x)] @@ -155,7 +155,7 @@ class TestConversion(unittest.TestCase): def test_band_or(self): def band_or(x): if isinstance(x, Vips.Image): - return x.bandbool(Vips.OperationBoolean.OR) + return x.bandor() else: return [reduce(lambda a, b: int(a) | int(b), x)] @@ -164,7 +164,7 @@ class TestConversion(unittest.TestCase): def test_band_eor(self): def band_eor(x): if isinstance(x, Vips.Image): - return x.bandbool(Vips.OperationBoolean.EOR) + return x.bandeor() else: return [reduce(lambda a, b: int(a) ^ int(b), x)]