PcdImagePlugin.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. ##
  18. # Image plugin for PhotoCD images. This plugin only reads the 768x512
  19. # image from the file; higher resolutions are encoded in a proprietary
  20. # encoding.
  21. class PcdImageFile(ImageFile.ImageFile):
  22. format = "PCD"
  23. format_description = "Kodak PhotoCD"
  24. def _open(self):
  25. # rough
  26. self.fp.seek(2048)
  27. s = self.fp.read(2048)
  28. if s[:4] != b"PCD_":
  29. raise SyntaxError("not a PCD file")
  30. orientation = s[1538] & 3
  31. self.tile_post_rotate = None
  32. if orientation == 1:
  33. self.tile_post_rotate = 90
  34. elif orientation == 3:
  35. self.tile_post_rotate = -90
  36. self.mode = "RGB"
  37. self._size = 768, 512 # FIXME: not correct for rotated images!
  38. self.tile = [("pcd", (0, 0) + self.size, 96 * 2048, None)]
  39. def load_end(self):
  40. if self.tile_post_rotate:
  41. # Handle rotated PCDs
  42. self.im = self.im.rotate(self.tile_post_rotate)
  43. self._size = self.im.size
  44. #
  45. # registry
  46. Image.register_open(PcdImageFile.format, PcdImageFile)
  47. Image.register_extension(PcdImageFile.format, ".pcd")