PcdImagePlugin.py 1.5 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 . import Image, ImageFile
  17. from ._binary import i8
  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. raise SyntaxError("not a PCD file")
  31. orientation = i8(s[1538]) & 3
  32. self.tile_post_rotate = None
  33. if orientation == 1:
  34. self.tile_post_rotate = 90
  35. elif orientation == 3:
  36. self.tile_post_rotate = -90
  37. self.mode = "RGB"
  38. self._size = 768, 512 # FIXME: not correct for rotated images!
  39. self.tile = [("pcd", (0, 0) + self.size, 96 * 2048, None)]
  40. def load_end(self):
  41. if self.tile_post_rotate:
  42. # Handle rotated PCDs
  43. self.im = self.im.rotate(self.tile_post_rotate)
  44. self._size = self.im.size
  45. #
  46. # registry
  47. Image.register_open(PcdImageFile.format, PcdImageFile)
  48. Image.register_extension(PcdImageFile.format, ".pcd")