PixarImagePlugin.py 1.8 KB

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