def test_builtin_list(self): self.assertEqual(list(SequenceClass(5)), range(5)) self.assertEqual(list(SequenceClass(0)), []) self.assertEqual(list(()), []) self.assertEqual(list(range(10, -1, -1)), range(10, -1, -1)) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(list(d), d.keys()) self.assertRaises(TypeError, list, list) self.assertRaises(TypeError, list, 42) f = open(TESTFN, "w") try: for i in range(5): f.write("%d\n" % i) finally: f.close() f = open(TESTFN, "r") try: self.assertEqual(list(f), ["0\n", "1\n", "2\n", "3\n", "4\n"]) f.seek(0, 0) self.assertEqual(list(f.xreadlines()), ["0\n", "1\n", "2\n", "3\n", "4\n"]) finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_countOf(self): from operator import countOf self.assertEqual(countOf([1,2,2,3,2,5], 2), 3) self.assertEqual(countOf((1,2,2,3,2,5), 2), 3) self.assertEqual(countOf("122325", "2"), 3) self.assertEqual(countOf("122325", "6"), 0) self.assertRaises(TypeError, countOf, 42, 1) self.assertRaises(TypeError, countOf, countOf, countOf) d = {"one": 3, "two": 3, "three": 3, 1j: 2j} for k in d: self.assertEqual(countOf(d, k), 1) self.assertEqual(countOf(d.itervalues(), 3), 3) self.assertEqual(countOf(d.itervalues(), 2j), 1) self.assertEqual(countOf(d.itervalues(), 1j), 0) f = open(TESTFN, "w") try: f.write("a\n" "b\n" "c\n" "b\n") finally: f.close() f = open(TESTFN, "r") try: for letter, count in ("a", 1), ("b", 2), ("c", 1), ("d", 0): f.seek(0, 0) self.assertEqual(countOf(f, letter + "\n"), count) finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_builtin_max_min(self): self.assertEqual(max(SequenceClass(5)), 4) self.assertEqual(min(SequenceClass(5)), 0) self.assertEqual(max(8, -1), 8) self.assertEqual(min(8, -1), -1) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(max(d), "two") self.assertEqual(min(d), "one") self.assertEqual(max(d.itervalues()), 3) self.assertEqual(min(iter(d.itervalues())), 1) f = open(TESTFN, "w") try: f.write("medium line\n") f.write("xtra large line\n") f.write("itty-bitty line\n") finally: f.close() f = open(TESTFN, "r") try: self.assertEqual(min(f), "itty-bitty line\n") f.seek(0, 0) self.assertEqual(max(f), "xtra large line\n") finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_builtin_tuple(self): self.assertEqual(tuple(SequenceClass(5)), (0, 1, 2, 3, 4)) self.assertEqual(tuple(SequenceClass(0)), ()) self.assertEqual(tuple([]), ()) self.assertEqual(tuple(()), ()) self.assertEqual(tuple("abc"), ("a", "b", "c")) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(tuple(d), tuple(d.keys())) self.assertRaises(TypeError, tuple, list) self.assertRaises(TypeError, tuple, 42) f = open(TESTFN, "w") try: for i in range(5): f.write("%d\n" % i) finally: f.close() f = open(TESTFN, "r") try: self.assertEqual(tuple(f), ("0\n", "1\n", "2\n", "3\n", "4\n")) f.seek(0, 0) self.assertEqual(tuple(f.xreadlines()), ("0\n", "1\n", "2\n", "3\n", "4\n")) finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_builtin_map(self): self.assertEqual(map(None, SequenceClass(5)), range(5)) self.assertEqual(map(lambda x: x+1, SequenceClass(5)), range(1, 6)) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(map(None, d), d.keys()) self.assertEqual(map(lambda k, d=d: (k, d[k]), d), d.items()) dkeys = d.keys() expected = [(i < len(d) and dkeys[i] or None, i, i < len(d) and dkeys[i] or None) for i in range(5)] self.assertEqual(map(None, d, SequenceClass(5), iter(d.iterkeys())), expected) f = open(TESTFN, "w") try: for i in range(10): f.write("xy" * i + "\n") # line i has len 2*i+1 finally: f.close() f = open(TESTFN, "r") try: self.assertEqual(map(len, f), range(1, 21, 2)) finally: f.close() try: unlink(TESTFN) except OSError: pass
def main(): testtype('c', 'c') for type in (['b', 'h', 'i', 'l', 'f', 'd']): testtype(type, 1) unlink(TESTFN)
def test_print(self): d = deque(xrange(200)) d.append(d) test_support.unlink(test_support.TESTFN) fo = open(test_support.TESTFN, "wb") try: print >> fo, d, fo.close() fo = open(test_support.TESTFN, "rb") self.assertEqual(fo.read(), repr(d)) finally: fo.close() test_support.unlink(test_support.TESTFN)
def main(): uu.decode(findfile('testrgb.uue'), 'test.rgb') uu.decode(findfile('greyrgb.uue'), 'greytest.rgb') # Test a 3 byte color image testimage('test.rgb') # Test a 1 byte greyscale image testimage('greytest.rgb') unlink('test.rgb') unlink('greytest.rgb')
def test_writelines(self): f = file(TESTFN, "w") try: self.assertRaises(TypeError, f.writelines, None) self.assertRaises(TypeError, f.writelines, 42) f.writelines(["1\n", "2\n"]) f.writelines(("3\n", "4\n")) f.writelines({'5\n': None}) f.writelines({}) # Try a big chunk too. class Iterator: def __init__(self, start, finish): self.start = start self.finish = finish self.i = self.start def next(self): if self.i >= self.finish: raise StopIteration result = str(self.i) + '\n' self.i += 1 return result def __iter__(self): return self class Whatever: def __init__(self, start, finish): self.start = start self.finish = finish def __iter__(self): return Iterator(self.start, self.finish) f.writelines(Whatever(6, 6+2000)) f.close() f = file(TESTFN) expected = [str(i) + "\n" for i in range(1, 2006)] self.assertEqual(list(f), expected) finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_iter_file(self): f = open(TESTFN, "w") try: for i in range(5): f.write("%d\n" % i) finally: f.close() f = open(TESTFN, "r") try: self.check_for_loop(f, ["0\n", "1\n", "2\n", "3\n", "4\n"]) self.check_for_loop(f, []) finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_builtin_zip(self): self.assertRaises(TypeError, zip) self.assertRaises(TypeError, zip, None) self.assertRaises(TypeError, zip, range(10), 42) self.assertRaises(TypeError, zip, range(10), zip) self.assertEqual(zip(IteratingSequenceClass(3)), [(0,), (1,), (2,)]) self.assertEqual(zip(SequenceClass(3)), [(0,), (1,), (2,)]) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(d.items(), zip(d, d.itervalues())) # Generate all ints starting at constructor arg. class IntsFrom: def __init__(self, start): self.i = start def __iter__(self): return self def next(self): i = self.i self.i = i+1 return i f = open(TESTFN, "w") try: f.write("a\n" "bbb\n" "cc\n") finally: f.close() f = open(TESTFN, "r") try: self.assertEqual(zip(IntsFrom(0), f, IntsFrom(-100)), [(0, "a\n", -100), (1, "bbb\n", -99), (2, "cc\n", -98)]) finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_unicode_join_endcase(self): # This class inserts a Unicode object into its argument's natural # iteration, in the 3rd position. class OhPhooey: def __init__(self, seq): self.it = iter(seq) self.i = 0 def __iter__(self): return self def next(self): i = self.i self.i = i+1 if i == 2: return unicode("fooled you!") return self.it.next() f = open(TESTFN, "w") try: f.write("a\n" + "b\n" + "c\n") finally: f.close() f = open(TESTFN, "r") # Nasty: string.join(s) can't know whether unicode.join() is needed # until it's seen all of s's elements. But in this case, f's # iterator cannot be restarted. So what we're testing here is # whether string.join() can manage to remember everything it's seen # and pass that on to unicode.join(). try: got = " - ".join(OhPhooey(f)) self.assertEqual(got, unicode("a\n - b\n - fooled you! - c\n")) finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_indexOf(self): from operator import indexOf self.assertEqual(indexOf([1,2,2,3,2,5], 1), 0) self.assertEqual(indexOf((1,2,2,3,2,5), 2), 1) self.assertEqual(indexOf((1,2,2,3,2,5), 3), 3) self.assertEqual(indexOf((1,2,2,3,2,5), 5), 5) self.assertRaises(ValueError, indexOf, (1,2,2,3,2,5), 0) self.assertRaises(ValueError, indexOf, (1,2,2,3,2,5), 6) self.assertEqual(indexOf("122325", "2"), 1) self.assertEqual(indexOf("122325", "5"), 5) self.assertRaises(ValueError, indexOf, "122325", "6") self.assertRaises(TypeError, indexOf, 42, 1) self.assertRaises(TypeError, indexOf, indexOf, indexOf) f = open(TESTFN, "w") try: f.write("a\n" "b\n" "c\n" "d\n" "e\n") finally: f.close() f = open(TESTFN, "r") try: fiter = iter(f) self.assertEqual(indexOf(fiter, "b\n"), 1) self.assertEqual(indexOf(fiter, "d\n"), 1) self.assertEqual(indexOf(fiter, "e\n"), 0) self.assertRaises(ValueError, indexOf, fiter, "a\n") finally: f.close() try: unlink(TESTFN) except OSError: pass iclass = IteratingSequenceClass(3) for i in range(3): self.assertEqual(indexOf(iclass, i), i) self.assertRaises(ValueError, indexOf, iclass, -1)
def test_summaryinfo_getproperty_issue1104(self): db, db_path = init_database() try: sum_info = db.GetSummaryInformation(99) title = sum_info.GetProperty(msilib.PID_TITLE) self.assertEqual(title, b"Installation Database") sum_info.SetProperty(msilib.PID_TITLE, "a" * 999) title = sum_info.GetProperty(msilib.PID_TITLE) self.assertEqual(title, b"a" * 999) sum_info.SetProperty(msilib.PID_TITLE, "a" * 1000) title = sum_info.GetProperty(msilib.PID_TITLE) self.assertEqual(title, b"a" * 1000) sum_info.SetProperty(msilib.PID_TITLE, "a" * 1001) title = sum_info.GetProperty(msilib.PID_TITLE) self.assertEqual(title, b"a" * 1001) finally: db = None sum_info = None unlink(db_path)
def test_in_and_not_in(self): for sc5 in IteratingSequenceClass(5), SequenceClass(5): for i in range(5): self.assert_(i in sc5) for i in "abc", -1, 5, 42.42, (3, 4), [], {1: 1}, 3-12j, sc5: self.assert_(i not in sc5) self.assertRaises(TypeError, lambda: 3 in 12) self.assertRaises(TypeError, lambda: 3 not in map) d = {"one": 1, "two": 2, "three": 3, 1j: 2j} for k in d: self.assert_(k in d) self.assert_(k not in d.itervalues()) for v in d.values(): self.assert_(v in d.itervalues()) self.assert_(v not in d) for k, v in d.iteritems(): self.assert_((k, v) in d.iteritems()) self.assert_((v, k) not in d.iteritems()) f = open(TESTFN, "w") try: f.write("a\n" "b\n" "c\n") finally: f.close() f = open(TESTFN, "r") try: for chunk in "abc": f.seek(0, 0) self.assert_(chunk not in f) f.seek(0, 0) self.assert_((chunk + "\n") in f) finally: f.close() try: unlink(TESTFN) except OSError: pass
def test_maxlen(self): self.assertRaises(ValueError, deque, "abc", -1) self.assertRaises(ValueError, deque, "abc", -2) it = iter(range(10)) d = deque(it, maxlen=3) self.assertEqual(list(it), []) self.assertEqual(repr(d), "deque([7, 8, 9], maxlen=3)") self.assertEqual(list(d), range(7, 10)) self.assertEqual(d, deque(range(10), 3)) d.append(10) self.assertEqual(list(d), range(8, 11)) d.appendleft(7) self.assertEqual(list(d), range(7, 10)) d.extend([10, 11]) self.assertEqual(list(d), range(9, 12)) d.extendleft([8, 7]) self.assertEqual(list(d), range(7, 10)) d = deque(xrange(200), maxlen=10) d.append(d) test_support.unlink(test_support.TESTFN) fo = open(test_support.TESTFN, "wb") try: print >> fo, d, fo.close() fo = open(test_support.TESTFN, "rb") self.assertEqual(fo.read(), repr(d)) finally: fo.close() test_support.unlink(test_support.TESTFN) d = deque(range(10), maxlen=None) self.assertEqual(repr(d), "deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])") fo = open(test_support.TESTFN, "wb") try: print >> fo, d, fo.close() fo = open(test_support.TESTFN, "rb") self.assertEqual(fo.read(), repr(d)) finally: fo.close() test_support.unlink(test_support.TESTFN)
def test_maxlen(self): self.assertRaises(ValueError, deque, 'abc', -1) self.assertRaises(ValueError, deque, 'abc', -2) it = iter(range(10)) d = deque(it, maxlen=3) self.assertEqual(list(it), []) self.assertEqual(repr(d), 'deque([7, 8, 9], maxlen=3)') self.assertEqual(list(d), range(7, 10)) self.assertEqual(d, deque(range(10), 3)) d.append(10) self.assertEqual(list(d), range(8, 11)) d.appendleft(7) self.assertEqual(list(d), range(7, 10)) d.extend([10, 11]) self.assertEqual(list(d), range(9, 12)) d.extendleft([8, 7]) self.assertEqual(list(d), range(7, 10)) d = deque(xrange(200), maxlen=10) d.append(d) test_support.unlink(test_support.TESTFN) fo = open(test_support.TESTFN, "wb") try: print >> fo, d, fo.close() fo = open(test_support.TESTFN, "rb") self.assertEqual(fo.read(), repr(d)) finally: fo.close() test_support.unlink(test_support.TESTFN) d = deque(range(10), maxlen=None) self.assertEqual(repr(d), 'deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])') fo = open(test_support.TESTFN, "wb") try: print >> fo, d, fo.close() fo = open(test_support.TESTFN, "rb") self.assertEqual(fo.read(), repr(d)) finally: fo.close() test_support.unlink(test_support.TESTFN)
#! /usr/bin/env python
def test_unpack_iter(self): a, b = 1, 2 self.assertEqual((a, b), (1, 2)) a, b, c = IteratingSequenceClass(3) self.assertEqual((a, b, c), (0, 1, 2)) try: # too many values a, b = IteratingSequenceClass(3) except ValueError: pass else: self.fail("should have raised ValueError") try: # not enough values a, b, c = IteratingSequenceClass(2) except ValueError: pass else: self.fail("should have raised ValueError") try: # not iterable a, b, c = len except TypeError: pass else: self.fail("should have raised TypeError") a, b, c = {1: 42, 2: 42, 3: 42}.itervalues() self.assertEqual((a, b, c), (42, 42, 42)) f = open(TESTFN, "w") lines = ("a\n", "bb\n", "ccc\n") try: for line in lines: f.write(line) finally: f.close() f = open(TESTFN, "r") try: a, b, c = f self.assertEqual((a, b, c), lines) finally: f.close() try: unlink(TESTFN) except OSError: pass (a, b), (c,) = IteratingSequenceClass(2), {42: 24} self.assertEqual((a, b, c), (0, 1, 42)) # Test reference count behavior class C(object): count = 0 def __new__(cls): cls.count += 1 return object.__new__(cls) def __del__(self): cls = self.__class__ assert cls.count > 0 cls.count -= 1 x = C() self.assertEqual(C.count, 1) del x self.assertEqual(C.count, 0) l = [C(), C(), C()] self.assertEqual(C.count, 3) try: a, b = iter(l) except ValueError: pass del l self.assertEqual(C.count, 0)
def main(use_rgbimg=1): # Create binary test files uu.decode(get_qualified_path('testrgb' + os.extsep + 'uue'), 'test' + os.extsep + 'rgb') if use_rgbimg: image, width, height = getrgbimage('test' + os.extsep + 'rgb') else: image, width, height = getimage('test' + os.extsep + 'rgb') # Return the selected part of image, which should by width by height # in size and consist of pixels of psize bytes. if verbose: print 'crop' newimage = imageop.crop(image, 4, width, height, 0, 0, 1, 1) # Return image scaled to size newwidth by newheight. No interpolation # is done, scaling is done by simple-minded pixel duplication or removal. # Therefore, computer-generated images or dithered images will # not look nice after scaling. if verbose: print 'scale' scaleimage = imageop.scale(image, 4, width, height, 1, 1) # Run a vertical low-pass filter over an image. It does so by computing # each destination pixel as the average of two vertically-aligned source # pixels. The main use of this routine is to forestall excessive flicker # if the image two vertically-aligned source pixels, hence the name. if verbose: print 'tovideo' videoimage = imageop.tovideo(image, 4, width, height) # Convert an rgb image to an 8 bit rgb if verbose: print 'rgb2rgb8' greyimage = imageop.rgb2rgb8(image, width, height) # Convert an 8 bit rgb image to a 24 bit rgb image if verbose: print 'rgb82rgb' image = imageop.rgb82rgb(greyimage, width, height) # Convert an rgb image to an 8 bit greyscale image if verbose: print 'rgb2grey' greyimage = imageop.rgb2grey(image, width, height) # Convert an 8 bit greyscale image to a 24 bit rgb image if verbose: print 'grey2rgb' image = imageop.grey2rgb(greyimage, width, height) # Convert a 8-bit deep greyscale image to a 1-bit deep image by # thresholding all the pixels. The resulting image is tightly packed # and is probably only useful as an argument to mono2grey. if verbose: print 'grey2mono' monoimage = imageop.grey2mono(greyimage, width, height, 0) # monoimage, width, height = getimage('monotest.rgb') # Convert a 1-bit monochrome image to an 8 bit greyscale or color image. # All pixels that are zero-valued on input get value p0 on output and # all one-value input pixels get value p1 on output. To convert a # monochrome black-and-white image to greyscale pass the values 0 and # 255 respectively. if verbose: print 'mono2grey' greyimage = imageop.mono2grey(monoimage, width, height, 0, 255) # Convert an 8-bit greyscale image to a 1-bit monochrome image using a # (simple-minded) dithering algorithm. if verbose: print 'dither2mono' monoimage = imageop.dither2mono(greyimage, width, height) # Convert an 8-bit greyscale image to a 4-bit greyscale image without # dithering. if verbose: print 'grey2grey4' grey4image = imageop.grey2grey4(greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image without # dithering. if verbose: print 'grey2grey2' grey2image = imageop.grey2grey2(greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image with # dithering. As for dither2mono, the dithering algorithm is currently # very simple. if verbose: print 'dither2grey2' grey2image = imageop.dither2grey2(greyimage, width, height) # Convert a 4-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey42grey' greyimage = imageop.grey42grey(grey4image, width, height) # Convert a 2-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey22grey' image = imageop.grey22grey(grey2image, width, height) # Cleanup unlink('test' + os.extsep + 'rgb')
# Test iterators.
def test_unpack_iter(self): a, b = 1, 2 self.assertEqual((a, b), (1, 2)) a, b, c = IteratingSequenceClass(3) self.assertEqual((a, b, c), (0, 1, 2)) try: # too many values a, b = IteratingSequenceClass(3) except ValueError: pass else: self.fail("should have raised ValueError") try: # not enough values a, b, c = IteratingSequenceClass(2) except ValueError: pass else: self.fail("should have raised ValueError") try: # not iterable a, b, c = len except TypeError: pass else: self.fail("should have raised TypeError") a, b, c = {1: 42, 2: 42, 3: 42}.itervalues() self.assertEqual((a, b, c), (42, 42, 42)) f = open(TESTFN, "w") lines = ("a\n", "bb\n", "ccc\n") try: for line in lines: f.write(line) finally: f.close() f = open(TESTFN, "r") try: a, b, c = f self.assertEqual((a, b, c), lines) finally: f.close() try: unlink(TESTFN) except OSError: pass (a, b), (c,) = IteratingSequenceClass(2), {42: 24} self.assertEqual((a, b, c), (0, 1, 42)) # Test reference count behavior class C(object): count = 0 def __new__(cls): cls.count += 1 return object.__new__(cls) def __del__(self): cls = self.__class__ assert cls.count > 0 cls.count -= 1
# Testing rgbimg module import rgbimg, os, uu from test_support import verbose, unlink, findfile class error(Exception): pass print 'RGBimg test suite:' def testimg(rgb_file, raw_file): rgb_file = findfile(rgb_file) raw_file = findfile(raw_file) width, height = rgbimg.sizeofimage(rgb_file) rgb = rgbimg.longimagedata(rgb_file) if len(rgb) != width * height * 4: raise error, 'bad image length' raw = open(raw_file, 'rb').read() if rgb != raw: raise error, \ 'images don\'t match for '+rgb_file+' and '+raw_file for depth in [1, 3, 4]: rgbimg.longstoimage(rgb, width, height, depth, '@.rgb') os.unlink('@.rgb') table = [ ('testrgb' + os.extsep + 'uue', 'test' + os.extsep + 'rgb'), ('testimg' + os.extsep + 'uue', 'test' + os.extsep + 'rawimg'), ('testimgr' + os.extsep + 'uue', 'test' + os.extsep + 'rawimg' + os.extsep + 'rev'), ]
target = findfile(target) if verbose: print "uudecoding", source, "->", target, "..." uu.decode(source, target) if verbose: print "testing..." ttob = rgbimg.ttob(0) if ttob != 0: raise error, 'ttob should start out as zero' testimg('test.rgb', 'test.rawimg') ttob = rgbimg.ttob(1) if ttob != 0: raise error, 'ttob should be zero' testimg('test.rgb', 'test.rawimg.rev') ttob = rgbimg.ttob(0) if ttob != 1: raise error, 'ttob should be one' ttob = rgbimg.ttob(0) if ttob != 0: raise error, 'ttob should be zero' for source, target in table: unlink(findfile(target))
def main(use_rgbimg=1): # Create binary test files uu.decode(get_qualified_path('testrgb'+os.extsep+'uue'), 'test'+os.extsep+'rgb') if use_rgbimg: image, width, height = getrgbimage('test'+os.extsep+'rgb') else: image, width, height = getimage('test'+os.extsep+'rgb') # Return the selected part of image, which should by width by height # in size and consist of pixels of psize bytes. if verbose: print 'crop' newimage = imageop.crop (image, 4, width, height, 0, 0, 1, 1) # Return image scaled to size newwidth by newheight. No interpolation # is done, scaling is done by simple-minded pixel duplication or removal. # Therefore, computer-generated images or dithered images will # not look nice after scaling. if verbose: print 'scale' scaleimage = imageop.scale(image, 4, width, height, 1, 1) # Run a vertical low-pass filter over an image. It does so by computing # each destination pixel as the average of two vertically-aligned source # pixels. The main use of this routine is to forestall excessive flicker # if the image two vertically-aligned source pixels, hence the name. if verbose: print 'tovideo' videoimage = imageop.tovideo (image, 4, width, height) # Convert an rgb image to an 8 bit rgb if verbose: print 'rgb2rgb8' greyimage = imageop.rgb2rgb8(image, width, height) # Convert an 8 bit rgb image to a 24 bit rgb image if verbose: print 'rgb82rgb' image = imageop.rgb82rgb(greyimage, width, height) # Convert an rgb image to an 8 bit greyscale image if verbose: print 'rgb2grey' greyimage = imageop.rgb2grey(image, width, height) # Convert an 8 bit greyscale image to a 24 bit rgb image if verbose: print 'grey2rgb' image = imageop.grey2rgb(greyimage, width, height) # Convert a 8-bit deep greyscale image to a 1-bit deep image by # thresholding all the pixels. The resulting image is tightly packed # and is probably only useful as an argument to mono2grey. if verbose: print 'grey2mono' monoimage = imageop.grey2mono (greyimage, width, height, 0) # monoimage, width, height = getimage('monotest.rgb') # Convert a 1-bit monochrome image to an 8 bit greyscale or color image. # All pixels that are zero-valued on input get value p0 on output and # all one-value input pixels get value p1 on output. To convert a # monochrome black-and-white image to greyscale pass the values 0 and # 255 respectively. if verbose: print 'mono2grey' greyimage = imageop.mono2grey (monoimage, width, height, 0, 255) # Convert an 8-bit greyscale image to a 1-bit monochrome image using a # (simple-minded) dithering algorithm. if verbose: print 'dither2mono' monoimage = imageop.dither2mono (greyimage, width, height) # Convert an 8-bit greyscale image to a 4-bit greyscale image without # dithering. if verbose: print 'grey2grey4' grey4image = imageop.grey2grey4 (greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image without # dithering. if verbose: print 'grey2grey2' grey2image = imageop.grey2grey2 (greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image with # dithering. As for dither2mono, the dithering algorithm is currently # very simple. if verbose: print 'dither2grey2' grey2image = imageop.dither2grey2 (greyimage, width, height) # Convert a 4-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey42grey' greyimage = imageop.grey42grey (grey4image, width, height) # Convert a 2-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey22grey' image = imageop.grey22grey (grey2image, width, height) # Cleanup unlink('test'+os.extsep+'rgb')