home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pypil112.zip / PIL-1.1.2.zip / Lib / site-packages / PIL / SgiImagePlugin.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2001-12-25  |  3KB  |  61 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. __version__ = '0.1'
  5. import string
  6. import Image
  7. import ImageFile
  8.  
  9. def i16(c):
  10.     return ord(c[1]) + (ord(c[0]) << 8)
  11.  
  12.  
  13. def i32(c):
  14.     return ord(c[3]) + (ord(c[2]) << 8) + (ord(c[1]) << 16) + (ord(c[0]) << 24)
  15.  
  16.  
  17. def _accept(prefix):
  18.     return i16(prefix) == 474
  19.  
  20.  
  21. class SgiImageFile(ImageFile.ImageFile):
  22.     format = 'SGI'
  23.     format_description = 'SGI Image File Format'
  24.     
  25.     def _open(self):
  26.         s = self.fp.read(512)
  27.         if i16(s) != 474:
  28.             raise SyntaxError, 'not an SGI image file'
  29.         
  30.         compression = ord(s[2])
  31.         layout = (ord(s[3]), i16(s[4:]), i16(s[10:]))
  32.         if layout == (1, 2, 1):
  33.             self.mode = 'L'
  34.         elif layout == (1, 3, 3):
  35.             self.mode = 'RGB'
  36.         else:
  37.             raise SyntaxError, 'unsupported SGI image mode'
  38.         self.size = (i16(s[6:]), i16(s[8:]))
  39.         if compression == 0:
  40.             if self.mode == 'RGB':
  41.                 size = self.size[0] * self.size[1]
  42.                 self.tile = [
  43.                     ('raw', (0, 0) + self.size, 512, ('R', 0, 1)),
  44.                     ('raw', (0, 0) + self.size, 512 + size, ('G', 0, 1)),
  45.                     ('raw', (0, 0) + self.size, 512 + 2 * size, ('B', 0, 1))]
  46.             else:
  47.                 self.tile = [
  48.                     ('raw', (0, 0) + self.size, 512, (self.mode, 0, 1))]
  49.         
  50.         if compression == 1:
  51.             self.tile = [
  52.                 ('sgi_rle', (0, 0) + self.size, 512, (self.mode, 0, 1))]
  53.         
  54.  
  55.  
  56. Image.register_open('SGI', SgiImageFile, _accept)
  57. Image.register_extension('SGI', '.bw')
  58. Image.register_extension('SGI', '.rgb')
  59. Image.register_extension('SGI', '.rgba')
  60. Image.register_extension('SGI', '.sgi')
  61.