PcdImagePlugin.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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):
  26. # rough
  27. self.fp.seek(2048)
  28. s = self.fp.read(2048)
  29. if s[:4] != b"PCD_":
  30. msg = "not a PCD file"
  31. raise SyntaxError(msg)
  32. orientation = s[1538] & 3
  33. self.tile_post_rotate = None
  34. if orientation == 1:
  35. self.tile_post_rotate = 90
  36. elif orientation == 3:
  37. self.tile_post_rotate = -90
  38. self._mode = "RGB"
  39. self._size = 768, 512 # FIXME: not correct for rotated images!
  40. self.tile = [("pcd", (0, 0) + self.size, 96 * 2048, None)]
  41. def load_end(self):
  42. if self.tile_post_rotate:
  43. # Handle rotated PCDs
  44. self.im = self.im.rotate(self.tile_post_rotate)
  45. self._size = self.im.size
  46. #
  47. # registry
  48. Image.register_open(PcdImageFile.format, PcdImageFile)
  49. Image.register_extension(PcdImageFile.format, ".pcd")