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.

GribStubImagePlugin.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #
  2. # The Python Imaging Library
  3. # $Id$
  4. #
  5. # GRIB stub adapter
  6. #
  7. # Copyright (c) 1996-2003 by Fredrik Lundh
  8. #
  9. # See the README file for information on usage and redistribution.
  10. #
  11. from . import Image, ImageFile
  12. _handler = None
  13. def register_handler(handler):
  14. """
  15. Install application-specific GRIB image handler.
  16. :param handler: Handler object.
  17. """
  18. global _handler
  19. _handler = handler
  20. # --------------------------------------------------------------------
  21. # Image adapter
  22. def _accept(prefix):
  23. return prefix[:4] == b"GRIB" and prefix[7] == 1
  24. class GribStubImageFile(ImageFile.StubImageFile):
  25. format = "GRIB"
  26. format_description = "GRIB"
  27. def _open(self):
  28. offset = self.fp.tell()
  29. if not _accept(self.fp.read(8)):
  30. msg = "Not a GRIB file"
  31. raise SyntaxError(msg)
  32. self.fp.seek(offset)
  33. # make something up
  34. self.mode = "F"
  35. self._size = 1, 1
  36. loader = self._load()
  37. if loader:
  38. loader.open(self)
  39. def _load(self):
  40. return _handler
  41. def _save(im, fp, filename):
  42. if _handler is None or not hasattr(_handler, "save"):
  43. msg = "GRIB save handler not installed"
  44. raise OSError(msg)
  45. _handler.save(im, fp, filename)
  46. # --------------------------------------------------------------------
  47. # Registry
  48. Image.register_open(GribStubImageFile.format, GribStubImageFile, _accept)
  49. Image.register_save(GribStubImageFile.format, _save)
  50. Image.register_extension(GribStubImageFile.format, ".grib")