Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_imageop.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 2456d8ff9fa8 |
| children | 678a3f1d0c80 |
| rev | line source |
|---|---|
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
5328
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
2 |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
3 """Test script for the imageop module. This has the side |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
4 effect of partially testing the imgfile module as well. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
5 Roger E. Masse |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
6 """ |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
7 |
|
5328
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
8 from test_support import verbose, unlink |
|
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
9 |
|
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
10 import imageop, uu |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
11 |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
12 def main(use_rgbimg=1): |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
13 |
|
5328
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
14 # Create binary test files |
|
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
15 uu.decode(get_qualified_path('testrgb.uue'), 'test.rgb') |
|
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
16 |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
17 if use_rgbimg: |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
18 image, width, height = getrgbimage('test.rgb') |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
19 else: |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
20 image, width, height = getimage('test.rgb') |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
21 |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
22 # Return the selected part of image, which should by width by height |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
23 # in size and consist of pixels of psize bytes. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
24 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
25 print 'crop' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
26 newimage = imageop.crop (image, 4, width, height, 0, 0, 1, 1) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
27 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
28 # Return image scaled to size newwidth by newheight. No interpolation |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
29 # is done, scaling is done by simple-minded pixel duplication or removal. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
30 # Therefore, computer-generated images or dithered images will |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
31 # not look nice after scaling. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
32 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
33 print 'scale' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
34 scaleimage = imageop.scale(image, 4, width, height, 1, 1) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
35 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
36 # Run a vertical low-pass filter over an image. It does so by computing |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
37 # each destination pixel as the average of two vertically-aligned source |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
38 # pixels. The main use of this routine is to forestall excessive flicker |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
39 # if the image two vertically-aligned source pixels, hence the name. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
40 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
41 print 'tovideo' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
42 videoimage = imageop.tovideo (image, 4, width, height) |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
43 |
|
4966
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
44 # Convert an rgb image to an 8 bit rgb |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
45 if verbose: |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
46 print 'rgb2rgb8' |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
47 greyimage = imageop.rgb2rgb8(image, width, height) |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
48 |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
49 # Convert an 8 bit rgb image to a 24 bit rgb image |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
50 if verbose: |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
51 print 'rgb82rgb' |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
52 image = imageop.rgb82rgb(greyimage, width, height) |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
53 |
|
4966
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
54 # Convert an rgb image to an 8 bit greyscale image |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
55 if verbose: |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
56 print 'rgb2grey' |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
57 greyimage = imageop.rgb2grey(image, width, height) |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
58 |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
59 # Convert an 8 bit greyscale image to a 24 bit rgb image |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
60 if verbose: |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
61 print 'grey2rgb' |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
62 image = imageop.grey2rgb(greyimage, width, height) |
|
9bbd57d3609f
Opps. Added tests for the last two methods that were missing from
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4965
diff
changeset
|
63 |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
64 # Convert a 8-bit deep greyscale image to a 1-bit deep image by |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
65 # tresholding all the pixels. The resulting image is tightly packed |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
66 # and is probably only useful as an argument to mono2grey. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
67 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
68 print 'grey2mono' |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
69 monoimage = imageop.grey2mono (greyimage, width, height, 0) |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
70 |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
71 # monoimage, width, height = getimage('monotest.rgb') |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
72 # Convert a 1-bit monochrome image to an 8 bit greyscale or color image. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
73 # All pixels that are zero-valued on input get value p0 on output and |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
74 # all one-value input pixels get value p1 on output. To convert a |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
75 # monochrome black-and-white image to greyscale pass the values 0 and |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
76 # 255 respectively. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
77 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
78 print 'mono2grey' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
79 greyimage = imageop.mono2grey (monoimage, width, height, 0, 255) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
80 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
81 # Convert an 8-bit greyscale image to a 1-bit monochrome image using a |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
82 # (simple-minded) dithering algorithm. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
83 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
84 print 'dither2mono' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
85 monoimage = imageop.dither2mono (greyimage, width, height) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
86 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
87 # Convert an 8-bit greyscale image to a 4-bit greyscale image without |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
88 # dithering. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
89 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
90 print 'grey2grey4' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
91 grey4image = imageop.grey2grey4 (greyimage, width, height) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
92 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
93 # Convert an 8-bit greyscale image to a 2-bit greyscale image without |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
94 # dithering. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
95 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
96 print 'grey2grey2' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
97 grey2image = imageop.grey2grey2 (greyimage, width, height) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
98 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
99 # Convert an 8-bit greyscale image to a 2-bit greyscale image with |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
100 # dithering. As for dither2mono, the dithering algorithm is currently |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
101 # very simple. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
102 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
103 print 'dither2grey2' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
104 grey2image = imageop.dither2grey2 (greyimage, width, height) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
105 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
106 # Convert a 4-bit greyscale image to an 8-bit greyscale image. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
107 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
108 print 'grey42grey' |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
109 greyimage = imageop.grey42grey (grey4image, width, height) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
110 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
111 # Convert a 2-bit greyscale image to an 8-bit greyscale image. |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
112 if verbose: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
113 print 'grey22grey' |
|
5328
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
114 image = imageop.grey22grey (grey2image, width, height) |
|
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
115 |
|
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
116 # Cleanup |
|
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
117 unlink('test.rgb') |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
118 |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
119 def getrgbimage(name): |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
120 """return a tuple consisting of image (in 'imgfile' format but |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
121 using rgbimg instead) width and height""" |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
122 |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
123 import rgbimg |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
124 |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
125 try: |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
126 sizes = rgbimg.sizeofimage(name) |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
127 except rgbimg.error: |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
128 name = get_qualified_path(name) |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
129 sizes = rgbimg.sizeofimage(name) |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
130 if verbose: |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
131 print 'rgbimg opening test image: %s, sizes: %s' % (name, str(sizes)) |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
132 |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
133 image = rgbimg.longimagedata(name) |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
134 return (image, sizes[0], sizes[1]) |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
135 |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
136 def getimage(name): |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
137 """return a tuple consisting of |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
138 image (in 'imgfile' format) width and height |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
139 """ |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
140 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
141 import imgfile |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
142 |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
143 try: |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
144 sizes = imgfile.getsizes(name) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
145 except imgfile.error: |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
146 name = get_qualified_path(name) |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
147 sizes = imgfile.getsizes(name) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
148 if verbose: |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
149 print 'imgfile opening test image: %s, sizes: %s' % (name, str(sizes)) |
|
4801
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
150 |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
151 image = imgfile.read(name) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
152 return (image, sizes[0], sizes[1]) |
|
2d5ee374a73b
Test program for the SGI imageop module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
153 |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
154 def get_qualified_path(name): |
|
5516
2456d8ff9fa8
More rational implementation of get_qualified_path() -- search along
Guido van Rossum <guido@python.org>
parents:
5328
diff
changeset
|
155 """ return a more qualified path to name""" |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
156 import sys |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
157 import os |
|
5516
2456d8ff9fa8
More rational implementation of get_qualified_path() -- search along
Guido van Rossum <guido@python.org>
parents:
5328
diff
changeset
|
158 for dir in sys.path: |
|
2456d8ff9fa8
More rational implementation of get_qualified_path() -- search along
Guido van Rossum <guido@python.org>
parents:
5328
diff
changeset
|
159 fullname = os.path.join(dir, name) |
|
2456d8ff9fa8
More rational implementation of get_qualified_path() -- search along
Guido van Rossum <guido@python.org>
parents:
5328
diff
changeset
|
160 if os.path.exists(fullname): |
|
2456d8ff9fa8
More rational implementation of get_qualified_path() -- search along
Guido van Rossum <guido@python.org>
parents:
5328
diff
changeset
|
161 return fullname |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
162 return name |
|
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
163 |
|
5328
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
164 # rgbimg (unlike imgfile) is portable to platforms other than SGI. |
|
359e8f815a3a
Use uuencoded test images.
Guido van Rossum <guido@python.org>
parents:
4966
diff
changeset
|
165 # So we prefer to use it. |
|
4965
d84ca197868b
Modified to use 'rgbimg' instead of the SGI specific 'imgfile' for reading
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4801
diff
changeset
|
166 main(use_rgbimg=1) |
