2014-09-01 12:32:17 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
#import logging
|
|
|
|
#logging.basicConfig(level = logging.DEBUG)
|
|
|
|
|
|
|
|
from gi.repository import Vips
|
|
|
|
from vips8 import vips
|
|
|
|
|
|
|
|
a = Vips.Image.new_from_file(sys.argv[1])
|
|
|
|
|
2014-09-11 22:54:52 +02:00
|
|
|
def should_equal(test, a, b):
|
|
|
|
if abs(a - b) > 0.01:
|
|
|
|
print '%s: seen %g and %g' % (test, a, b)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def bandsplit(a):
|
|
|
|
return [a.extract_band(i) for i in range(0, a.bands)]
|
|
|
|
|
2014-09-01 12:32:17 +02:00
|
|
|
# test operator overloads
|
2014-09-11 22:54:52 +02:00
|
|
|
|
|
|
|
# addition
|
2014-09-01 12:32:17 +02:00
|
|
|
b = a + 12
|
2014-09-11 22:54:52 +02:00
|
|
|
should_equal('add constant', a.avg() + 12, b.avg())
|
|
|
|
|
|
|
|
b = a + [12, 0, 0]
|
|
|
|
x = map (lambda x: x.avg()) bandsplit(a)
|
|
|
|
y = map (lambda x: x.avg()) bandsplit(b)
|
|
|
|
x[0] += 12
|
|
|
|
should_equal('add multiband constant', sum(x), sum(y))
|
|
|
|
|
|
|
|
|
2014-09-01 12:32:17 +02:00
|
|
|
b = a + [12, 0, 0]
|
|
|
|
b = a + b
|
2014-09-01 16:28:55 +02:00
|
|
|
b = 12 + a
|
|
|
|
b = [12, 0, 0] + a
|
|
|
|
|
|
|
|
b = a - 12
|
|
|
|
b = a - [12, 0, 0]
|
|
|
|
b = a - b
|
|
|
|
b = 12 - a
|
|
|
|
b = [12, 0, 0] - a
|
|
|
|
|
|
|
|
b = a * 12
|
|
|
|
b = a * [12, 1, 1]
|
|
|
|
b = a * b
|
|
|
|
b = 12 * a
|
|
|
|
b = [12, 1, 1] * a
|
|
|
|
|
|
|
|
b = a / 12
|
|
|
|
b = a / [12, 1, 1]
|
|
|
|
b = 12 / a
|
|
|
|
b = [12, 1, 1] / a
|
|
|
|
b = a / b
|
|
|
|
|
|
|
|
b = a // 12
|
|
|
|
b = a // [12, 1, 1]
|
|
|
|
b = 12 // a
|
|
|
|
b = [12, 1, 1] // a
|
|
|
|
b = a // b
|
|
|
|
|
|
|
|
b = a % 12
|
|
|
|
b = a % [12, 1, 1]
|
|
|
|
b = a % b
|
|
|
|
|
|
|
|
b = a ** 12
|
|
|
|
b = a ** [12, 1, 1]
|
|
|
|
b = 12 ** a
|
|
|
|
b = [12, 1, 1] ** a
|
|
|
|
b = a ** b
|
|
|
|
|
|
|
|
b = a << 12
|
|
|
|
b = a << [12, 1, 1]
|
|
|
|
b = a << b
|
|
|
|
|
|
|
|
b = a >> 12
|
|
|
|
b = a >> [12, 1, 1]
|
|
|
|
b = a >> b
|
|
|
|
|
|
|
|
b = a & 12
|
|
|
|
b = a & [12, 1, 1]
|
|
|
|
b = 12 & a
|
|
|
|
b = [12, 1, 1] & a
|
|
|
|
b = a & b
|
|
|
|
|
|
|
|
b = a | 12
|
|
|
|
b = a | [12, 1, 1]
|
|
|
|
b = 12 | a
|
|
|
|
b = [12, 1, 1] | a
|
|
|
|
b = a | b
|
|
|
|
|
|
|
|
b = a ^ 12
|
|
|
|
b = a ^ [12, 1, 1]
|
|
|
|
b = 12 ^ a
|
|
|
|
b = [12, 1, 1] ^ a
|
|
|
|
b = a ^ b
|
|
|
|
|
|
|
|
b = -a
|
|
|
|
b = +a
|
|
|
|
b = abs(a)
|
|
|
|
b = ~a
|
2014-09-01 12:32:17 +02:00
|
|
|
|