PixarImagePlugin.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 __future__ import annotations
  22. from . import Image, ImageFile
  23. from ._binary import i16le as i16
  24. #
  25. # helpers
  26. def _accept(prefix):
  27. return prefix[:4] == b"\200\350\000\000"
  28. ##
  29. # Image plugin for PIXAR raster images.
  30. class PixarImageFile(ImageFile.ImageFile):
  31. format = "PIXAR"
  32. format_description = "PIXAR raster image"
  33. def _open(self):
  34. # assuming a 4-byte magic label
  35. s = self.fp.read(4)
  36. if not _accept(s):
  37. msg = "not a PIXAR file"
  38. raise SyntaxError(msg)
  39. # read rest of header
  40. s = s + self.fp.read(508)
  41. self._size = i16(s, 418), i16(s, 416)
  42. # get channel/depth descriptions
  43. mode = i16(s, 424), i16(s, 426)
  44. if mode == (14, 2):
  45. self._mode = "RGB"
  46. # FIXME: to be continued...
  47. # create tile descriptor (assuming "dumped")
  48. self.tile = [("raw", (0, 0) + self.size, 1024, (self.mode, 0, 1))]
  49. #
  50. # --------------------------------------------------------------------
  51. Image.register_open(PixarImageFile.format, PixarImageFile, _accept)
  52. Image.register_extension(PixarImageFile.format, ".pxr")