PcdImagePlugin.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # PCD file handling
  6. #
  7. # History:
  8. # 96-05-10 fl Created
  9. # 96-05-27 fl Added draft mode (128x192, 256x384)
  10. #
  11. # Copyright (c) Secret Labs AB 1997.
  12. # Copyright (c) Fredrik Lundh 1996.
  13. #
  14. # See the README file for information on usage and redistribution.
  15. #
  16. from __future__ import annotations
  17. from . import Image, ImageFile
  18. ##
  19. # Image plugin for PhotoCD images. This plugin only reads the 768x512
  20. # image from the file; higher resolutions are encoded in a proprietary
  21. # encoding.
  22. class PcdImageFile(ImageFile.ImageFile):
  23. format = "PCD"
  24. format_description = "Kodak PhotoCD"
  25. def _open(self) -> None:
  26. # rough
  27. assert self.fp is not None
  28. self.fp.seek(2048)
  29. s = self.fp.read(2048)
  30. if s[:4] != b"PCD_":
  31. msg = "not a PCD file"
  32. raise SyntaxError(msg)
  33. orientation = s[1538] & 3
  34. self.tile_post_rotate = None
  35. if orientation == 1:
  36. self.tile_post_rotate = 90
  37. elif orientation == 3:
  38. self.tile_post_rotate = -90
  39. self._mode = "RGB"
  40. self._size = 768, 512 # FIXME: not correct for rotated images!
  41. self.tile = [ImageFile._Tile("pcd", (0, 0) + self.size, 96 * 2048)]
  42. def load_end(self) -> None:
  43. if self.tile_post_rotate:
  44. # Handle rotated PCDs
  45. self.im = self.im.rotate(self.tile_post_rotate)
  46. self._size = self.im.size
  47. #
  48. # registry
  49. Image.register_open(PcdImageFile.format, PcdImageFile)
  50. Image.register_extension(PcdImageFile.format, ".pcd")