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 / IcoImagePlugin.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2001-12-25  |  2KB  |  48 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 BmpImagePlugin
  8.  
  9. def i16(c):
  10.     return ord(c[0]) + (ord(c[1]) << 8)
  11.  
  12.  
  13. def i32(c):
  14.     return ord(c[0]) + (ord(c[1]) << 8) + (ord(c[2]) << 16) + (ord(c[3]) << 24)
  15.  
  16.  
  17. def _accept(prefix):
  18.     return prefix[:4] == '\x00\x00\x01\x00'
  19.  
  20.  
  21. class IcoImageFile(BmpImagePlugin.BmpImageFile):
  22.     format = 'ICO'
  23.     format_description = 'Windows Icon'
  24.     
  25.     def _open(self):
  26.         s = self.fp.read(6)
  27.         if not _accept(s):
  28.             raise SyntaxError, 'not an ICO file'
  29.         
  30.         m = ''
  31.         for i in range(i16(s[4:])):
  32.             s = self.fp.read(16)
  33.             if not m:
  34.                 m = s
  35.             elif ord(s[0]) > ord(m[0]) and ord(s[1]) > ord(m[1]):
  36.                 m = s
  37.             
  38.         
  39.         self._bitmap(i32(m[12:]))
  40.         self.size = (self.size[0], self.size[1] / 2)
  41.         (d, e, o, a) = self.tile[0]
  42.         self.tile[0] = (d, (0, 0) + self.size, o, a)
  43.         return None
  44.  
  45.  
  46. Image.register_open('ICO', IcoImageFile, _accept)
  47. Image.register_extension('ICO', '.ico')
  48.