PixarImagePlugin.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # PIXAR raster support for PIL
  6. #
  7. # history:
  8. # 97-01-29 fl Created
  9. #
  10. # notes:
  11. # This is incomplete; it is based on a few samples created with
  12. # Photoshop 2.5 and 3.0, and a summary description provided by
  13. # Greg Coats <gcoats@labiris.er.usgs.gov>. Hopefully, "L" and
  14. # "RGBA" support will be added in future versions.
  15. #
  16. # Copyright (c) Secret Labs AB 1997.
  17. # Copyright (c) Fredrik Lundh 1997.
  18. #
  19. # See the README file for information on usage and redistribution.
  20. #
  21. from . import Image, ImageFile
  22. from ._binary import i16le as i16
  23. # __version__ is deprecated and will be removed in a future version. Use
  24. # PIL.__version__ instead.
  25. __version__ = "0.1"
  26. #
  27. # helpers
  28. def _accept(prefix):
  29. return prefix[:4] == b"\200\350\000\000"
  30. ##
  31. # Image plugin for PIXAR raster images.
  32. class PixarImageFile(ImageFile.ImageFile):
  33. format = "PIXAR"
  34. format_description = "PIXAR raster image"
  35. def _open(self):
  36. # assuming a 4-byte magic label
  37. s = self.fp.read(4)
  38. if s != b"\200\350\000\000":
  39. raise SyntaxError("not a PIXAR file")
  40. # read rest of header
  41. s = s + self.fp.read(508)
  42. self._size = i16(s[418:420]), i16(s[416:418])
  43. # get channel/depth descriptions
  44. mode = i16(s[424:426]), i16(s[426:428])
  45. if mode == (14, 2):
  46. self.mode = "RGB"
  47. # FIXME: to be continued...
  48. # create tile descriptor (assuming "dumped")
  49. self.tile = [("raw", (0, 0) + self.size, 1024, (self.mode, 0, 1))]
  50. #
  51. # --------------------------------------------------------------------
  52. Image.register_open(PixarImageFile.format, PixarImageFile, _accept)
  53. Image.register_extension(PixarImageFile.format, ".pxr")