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 / GbrImagePlugin.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2001-12-25  |  2KB  |  51 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. import Image
  5. import ImageFile
  6.  
  7. def i32(c):
  8.     return ord(c[3]) + (ord(c[2]) << 8) + (ord(c[1]) << 16) + (ord(c[0]) << 24)
  9.  
  10.  
  11. def _accept(prefix):
  12.     if i32(prefix) >= 20:
  13.         pass
  14.     return i32(prefix[4:8]) == 1
  15.  
  16.  
  17. class GbrImageFile(ImageFile.ImageFile):
  18.     format = 'GBR'
  19.     format_description = 'GIMP brush file'
  20.     
  21.     def _open(self):
  22.         header_size = i32(self.fp.read(4))
  23.         version = i32(self.fp.read(4))
  24.         if header_size < 20 or version != 1:
  25.             raise SyntaxError, 'not a GIMP brush'
  26.         
  27.         width = i32(self.fp.read(4))
  28.         height = i32(self.fp.read(4))
  29.         bytes = i32(self.fp.read(4))
  30.         if width <= 0 and height <= 0 or bytes != 1:
  31.             raise SyntaxError, 'not a GIMP brush'
  32.         
  33.         comment = self.fp.read(header_size - 20)[:-1]
  34.         self.mode = 'L'
  35.         self.size = (width, height)
  36.         self.info['comment'] = comment
  37.         self.data = self.fp.read(width * height)
  38.  
  39.     
  40.     def load(self):
  41.         if not (self.data):
  42.             return None
  43.         
  44.         self.im = Image.core.new(self.mode, self.size)
  45.         self.im.fromstring(self.data)
  46.         self.data = ''
  47.  
  48.  
  49. Image.register_open('GBR', GbrImageFile, _accept)
  50. Image.register_extension('GBR', '.gbr')
  51.