3 """Test script for the imageop module. This has the side
4 effect of partially testing the imgfile module as well.
8 from test
.test_support
import verbose
, unlink
, import_module
10 imageop
= import_module('imageop', deprecated
=True)
11 import uu
, os
, imgfile
15 # Create binary test files
16 uu
.decode(get_qualified_path('testrgb'+os
.extsep
+'uue'), 'test'+os
.extsep
+'rgb')
18 image
, width
, height
= getimage('test'+os
.extsep
+'rgb')
20 # Return the selected part of image, which should by width by height
21 # in size and consist of pixels of psize bytes.
24 newimage
= imageop
.crop (image
, 4, width
, height
, 0, 0, 1, 1)
26 # Return image scaled to size newwidth by newheight. No interpolation
27 # is done, scaling is done by simple-minded pixel duplication or removal.
28 # Therefore, computer-generated images or dithered images will
29 # not look nice after scaling.
32 scaleimage
= imageop
.scale(image
, 4, width
, height
, 1, 1)
34 # Run a vertical low-pass filter over an image. It does so by computing
35 # each destination pixel as the average of two vertically-aligned source
36 # pixels. The main use of this routine is to forestall excessive flicker
37 # if the image two vertically-aligned source pixels, hence the name.
40 videoimage
= imageop
.tovideo (image
, 4, width
, height
)
42 # Convert an rgb image to an 8 bit rgb
45 greyimage
= imageop
.rgb2rgb8(image
, width
, height
)
47 # Convert an 8 bit rgb image to a 24 bit rgb image
50 image
= imageop
.rgb82rgb(greyimage
, width
, height
)
52 # Convert an rgb image to an 8 bit greyscale image
55 greyimage
= imageop
.rgb2grey(image
, width
, height
)
57 # Convert an 8 bit greyscale image to a 24 bit rgb image
60 image
= imageop
.grey2rgb(greyimage
, width
, height
)
62 # Convert a 8-bit deep greyscale image to a 1-bit deep image by
63 # thresholding all the pixels. The resulting image is tightly packed
64 # and is probably only useful as an argument to mono2grey.
67 monoimage
= imageop
.grey2mono (greyimage
, width
, height
, 0)
69 # monoimage, width, height = getimage('monotest.rgb')
70 # Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
71 # All pixels that are zero-valued on input get value p0 on output and
72 # all one-value input pixels get value p1 on output. To convert a
73 # monochrome black-and-white image to greyscale pass the values 0 and
77 greyimage
= imageop
.mono2grey (monoimage
, width
, height
, 0, 255)
79 # Convert an 8-bit greyscale image to a 1-bit monochrome image using a
80 # (simple-minded) dithering algorithm.
83 monoimage
= imageop
.dither2mono (greyimage
, width
, height
)
85 # Convert an 8-bit greyscale image to a 4-bit greyscale image without
89 grey4image
= imageop
.grey2grey4 (greyimage
, width
, height
)
91 # Convert an 8-bit greyscale image to a 2-bit greyscale image without
95 grey2image
= imageop
.grey2grey2 (greyimage
, width
, height
)
97 # Convert an 8-bit greyscale image to a 2-bit greyscale image with
98 # dithering. As for dither2mono, the dithering algorithm is currently
102 grey2image
= imageop
.dither2grey2 (greyimage
, width
, height
)
104 # Convert a 4-bit greyscale image to an 8-bit greyscale image.
107 greyimage
= imageop
.grey42grey (grey4image
, width
, height
)
109 # Convert a 2-bit greyscale image to an 8-bit greyscale image.
112 image
= imageop
.grey22grey (grey2image
, width
, height
)
115 unlink('test'+os
.extsep
+'rgb')
118 """return a tuple consisting of
119 image (in 'imgfile' format) width and height
122 sizes
= imgfile
.getsizes(name
)
123 except imgfile
.error
:
124 name
= get_qualified_path(name
)
125 sizes
= imgfile
.getsizes(name
)
127 print 'imgfile opening test image: %s, sizes: %s' % (name
, str(sizes
))
129 image
= imgfile
.read(name
)
130 return (image
, sizes
[0], sizes
[1])
132 def get_qualified_path(name
):
133 """ return a more qualified path to name"""
138 path
= [os
.path
.dirname(__file__
)] + path
142 fullname
= os
.path
.join(dir, name
)
143 if os
.path
.exists(fullname
):
147 if __name__
== '__main__':