PcdImagePlugin.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(1539)
  30. if not s.startswith(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 = 270
  39. self._mode = "RGB"
  40. self._size = (512, 768) if orientation in (1, 3) else (768, 512)
  41. self.tile = [ImageFile._Tile("pcd", (0, 0, 768, 512), 96 * 2048)]
  42. def load_prepare(self) -> None:
  43. if self._im is None and self.tile_post_rotate:
  44. self.im = Image.core.new(self.mode, (768, 512))
  45. ImageFile.ImageFile.load_prepare(self)
  46. def load_end(self) -> None:
  47. if self.tile_post_rotate:
  48. # Handle rotated PCDs
  49. self.im = self.rotate(self.tile_post_rotate, expand=True).im
  50. #
  51. # registry
  52. Image.register_open(PcdImageFile.format, PcdImageFile)
  53. Image.register_extension(PcdImageFile.format, ".pcd")