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.

McIdasImagePlugin.py 1.8KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # Basic McIdas support for PIL
  6. #
  7. # History:
  8. # 1997-05-05 fl Created (8-bit images only)
  9. # 2009-03-08 fl Added 16/32-bit support.
  10. #
  11. # Thanks to Richard Jones and Craig Swank for specs and samples.
  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 struct
  19. from . import Image, ImageFile
  20. def _accept(s):
  21. return s[:8] == b"\x00\x00\x00\x00\x00\x00\x00\x04"
  22. ##
  23. # Image plugin for McIdas area images.
  24. class McIdasImageFile(ImageFile.ImageFile):
  25. format = "MCIDAS"
  26. format_description = "McIdas area file"
  27. def _open(self):
  28. # parse area file directory
  29. s = self.fp.read(256)
  30. if not _accept(s) or len(s) != 256:
  31. msg = "not an McIdas area file"
  32. raise SyntaxError(msg)
  33. self.area_descriptor_raw = s
  34. self.area_descriptor = w = [0] + list(struct.unpack("!64i", s))
  35. # get mode
  36. if w[11] == 1:
  37. mode = rawmode = "L"
  38. elif w[11] == 2:
  39. # FIXME: add memory map support
  40. mode = "I"
  41. rawmode = "I;16B"
  42. elif w[11] == 4:
  43. # FIXME: add memory map support
  44. mode = "I"
  45. rawmode = "I;32B"
  46. else:
  47. msg = "unsupported McIdas format"
  48. raise SyntaxError(msg)
  49. self.mode = mode
  50. self._size = w[10], w[9]
  51. offset = w[34] + w[15]
  52. stride = w[15] + w[10] * w[11] * w[14]
  53. self.tile = [("raw", (0, 0) + self.size, offset, (rawmode, stride, 1))]
  54. # --------------------------------------------------------------------
  55. # registry
  56. Image.register_open(McIdasImageFile.format, McIdasImageFile, _accept)
  57. # no default extension