home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / test / test_imageop.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  4.1 KB  |  136 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. '''Test script for the imageop module.  This has the side
  5.    effect of partially testing the imgfile module as well.
  6.    Roger E. Masse
  7. '''
  8. unlink
  9. import imageop
  10. import uu
  11.  
  12. def main(use_rgbimg = 1):
  13.     uu.decode(get_qualified_path('testrgb.uue'), 'test.rgb')
  14.     if use_rgbimg:
  15.         (image, width, height) = getrgbimage('test.rgb')
  16.     else:
  17.         (image, width, height) = getimage('test.rgb')
  18.     if verbose:
  19.         print 'crop'
  20.     
  21.     newimage = imageop.crop(image, 4, width, height, 0, 0, 1, 1)
  22.     if verbose:
  23.         print 'scale'
  24.     
  25.     scaleimage = imageop.scale(image, 4, width, height, 1, 1)
  26.     if verbose:
  27.         print 'tovideo'
  28.     
  29.     videoimage = imageop.tovideo(image, 4, width, height)
  30.     if verbose:
  31.         print 'rgb2rgb8'
  32.     
  33.     greyimage = imageop.rgb2rgb8(image, width, height)
  34.     if verbose:
  35.         print 'rgb82rgb'
  36.     
  37.     image = imageop.rgb82rgb(greyimage, width, height)
  38.     if verbose:
  39.         print 'rgb2grey'
  40.     
  41.     greyimage = imageop.rgb2grey(image, width, height)
  42.     if verbose:
  43.         print 'grey2rgb'
  44.     
  45.     image = imageop.grey2rgb(greyimage, width, height)
  46.     if verbose:
  47.         print 'grey2mono'
  48.     
  49.     monoimage = imageop.grey2mono(greyimage, width, height, 0)
  50.     if verbose:
  51.         print 'mono2grey'
  52.     
  53.     greyimage = imageop.mono2grey(monoimage, width, height, 0, 255)
  54.     if verbose:
  55.         print 'dither2mono'
  56.     
  57.     monoimage = imageop.dither2mono(greyimage, width, height)
  58.     if verbose:
  59.         print 'grey2grey4'
  60.     
  61.     grey4image = imageop.grey2grey4(greyimage, width, height)
  62.     if verbose:
  63.         print 'grey2grey2'
  64.     
  65.     grey2image = imageop.grey2grey2(greyimage, width, height)
  66.     if verbose:
  67.         print 'dither2grey2'
  68.     
  69.     grey2image = imageop.dither2grey2(greyimage, width, height)
  70.     if verbose:
  71.         print 'grey42grey'
  72.     
  73.     greyimage = imageop.grey42grey(grey4image, width, height)
  74.     if verbose:
  75.         print 'grey22grey'
  76.     
  77.     image = imageop.grey22grey(grey2image, width, height)
  78.     unlink('test.rgb')
  79.  
  80.  
  81. def getrgbimage(name):
  82.     """return a tuple consisting of image (in 'imgfile' format but
  83.     using rgbimg instead) width and height"""
  84.     import rgbimg
  85.     
  86.     try:
  87.         sizes = rgbimg.sizeofimage(name)
  88.     except rgbimg.error:
  89.         name = get_qualified_path(name)
  90.         sizes = rgbimg.sizeofimage(name)
  91.  
  92.     if verbose:
  93.         print 'rgbimg opening test image: %s, sizes: %s' % (name, str(sizes))
  94.     
  95.     image = rgbimg.longimagedata(name)
  96.     return (image, sizes[0], sizes[1])
  97.  
  98.  
  99. def getimage(name):
  100.     """return a tuple consisting of
  101.        image (in 'imgfile' format) width and height
  102.     """
  103.     import imgfile
  104.     
  105.     try:
  106.         sizes = imgfile.getsizes(name)
  107.     except imgfile.error:
  108.         name = get_qualified_path(name)
  109.         sizes = imgfile.getsizes(name)
  110.  
  111.     if verbose:
  112.         print 'imgfile opening test image: %s, sizes: %s' % (name, str(sizes))
  113.     
  114.     image = imgfile.read(name)
  115.     return (image, sizes[0], sizes[1])
  116.  
  117.  
  118. def get_qualified_path(name):
  119.     ''' return a more qualified path to name'''
  120.     import sys
  121.     import os
  122.     path = sys.path
  123.     
  124.     try:
  125.         path = [
  126.             os.path.dirname(__file__)] + path
  127.     except NameError:
  128.         pass
  129.  
  130.     for dir in path:
  131.         fullname = os.path.join(dir, name)
  132.     
  133.     return name
  134.  
  135. main(use_rgbimg = 1)
  136.