Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

MicImagePlugin.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # Microsoft Image Composer support for PIL
  6. #
  7. # Notes:
  8. # uses TiffImagePlugin.py to read the actual image streams
  9. #
  10. # History:
  11. # 97-01-20 fl Created
  12. #
  13. # Copyright (c) Secret Labs AB 1997.
  14. # Copyright (c) Fredrik Lundh 1997.
  15. #
  16. # See the README file for information on usage and redistribution.
  17. #
  18. import olefile
  19. from . import Image, TiffImagePlugin
  20. #
  21. # --------------------------------------------------------------------
  22. def _accept(prefix):
  23. return prefix[:8] == olefile.MAGIC
  24. ##
  25. # Image plugin for Microsoft's Image Composer file format.
  26. class MicImageFile(TiffImagePlugin.TiffImageFile):
  27. format = "MIC"
  28. format_description = "Microsoft Image Composer"
  29. _close_exclusive_fp_after_loading = False
  30. def _open(self):
  31. # read the OLE directory and see if this is a likely
  32. # to be a Microsoft Image Composer file
  33. try:
  34. self.ole = olefile.OleFileIO(self.fp)
  35. except OSError as e:
  36. msg = "not an MIC file; invalid OLE file"
  37. raise SyntaxError(msg) from e
  38. # find ACI subfiles with Image members (maybe not the
  39. # best way to identify MIC files, but what the... ;-)
  40. self.images = []
  41. for path in self.ole.listdir():
  42. if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image":
  43. self.images.append(path)
  44. # if we didn't find any images, this is probably not
  45. # an MIC file.
  46. if not self.images:
  47. msg = "not an MIC file; no image entries"
  48. raise SyntaxError(msg)
  49. self.frame = None
  50. self._n_frames = len(self.images)
  51. self.is_animated = self._n_frames > 1
  52. if len(self.images) > 1:
  53. self._category = Image.CONTAINER
  54. self.seek(0)
  55. def seek(self, frame):
  56. if not self._seek_check(frame):
  57. return
  58. try:
  59. filename = self.images[frame]
  60. except IndexError as e:
  61. msg = "no such frame"
  62. raise EOFError(msg) from e
  63. self.fp = self.ole.openstream(filename)
  64. TiffImagePlugin.TiffImageFile._open(self)
  65. self.frame = frame
  66. def tell(self):
  67. return self.frame
  68. def close(self):
  69. self.ole.close()
  70. super().close()
  71. def __exit__(self, *args):
  72. self.ole.close()
  73. super().__exit__()
  74. #
  75. # --------------------------------------------------------------------
  76. Image.register_open(MicImageFile.format, MicImageFile, _accept)
  77. Image.register_extension(MicImageFile.format, ".mic")