You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.5 KiB

4 years ago
  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. __version__ = "0.1"
  19. ##
  20. # Image plugin for PhotoCD images. This plugin only reads the 768x512
  21. # image from the file; higher resolutions are encoded in a proprietary
  22. # encoding.
  23. class PcdImageFile(ImageFile.ImageFile):
  24. format = "PCD"
  25. format_description = "Kodak PhotoCD"
  26. def _open(self):
  27. # rough
  28. self.fp.seek(2048)
  29. s = self.fp.read(2048)
  30. if s[:4] != b"PCD_":
  31. raise SyntaxError("not a PCD file")
  32. orientation = i8(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")