2010-07-31 06:52:47 +04:00
|
|
|
#
|
|
|
|
# The Python Imaging Library.
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# Basic McIdas support for PIL
|
|
|
|
#
|
|
|
|
# History:
|
|
|
|
# 1997-05-05 fl Created (8-bit images only)
|
|
|
|
# 2009-03-08 fl Added 16/32-bit support.
|
|
|
|
#
|
|
|
|
# Thanks to Richard Jones and Craig Swank for specs and samples.
|
|
|
|
#
|
|
|
|
# Copyright (c) Secret Labs AB 1997.
|
|
|
|
# Copyright (c) Fredrik Lundh 1997.
|
|
|
|
#
|
|
|
|
# See the README file for information on usage and redistribution.
|
|
|
|
#
|
2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
import struct
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2017-01-17 16:22:18 +03:00
|
|
|
from . import Image, ImageFile
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2014-08-26 17:47:10 +04:00
|
|
|
|
2024-01-15 08:11:48 +03:00
|
|
|
def _accept(prefix: bytes) -> bool:
|
|
|
|
return prefix[:8] == b"\x00\x00\x00\x00\x00\x00\x00\x04"
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2014-08-26 17:47:10 +04:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
##
|
|
|
|
# Image plugin for McIdas area images.
|
|
|
|
|
2019-03-21 16:28:20 +03:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
class McIdasImageFile(ImageFile.ImageFile):
|
|
|
|
format = "MCIDAS"
|
|
|
|
format_description = "McIdas area file"
|
|
|
|
|
2024-01-15 08:11:48 +03:00
|
|
|
def _open(self) -> None:
|
2010-07-31 06:52:47 +04:00
|
|
|
# parse area file directory
|
2024-01-15 08:11:48 +03:00
|
|
|
assert self.fp is not None
|
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
s = self.fp.read(256)
|
|
|
|
if not _accept(s) or len(s) != 256:
|
2022-12-22 00:51:35 +03:00
|
|
|
msg = "not an McIdas area file"
|
|
|
|
raise SyntaxError(msg)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
self.area_descriptor_raw = s
|
|
|
|
self.area_descriptor = w = [0] + list(struct.unpack("!64i", s))
|
|
|
|
|
|
|
|
# get mode
|
|
|
|
if w[11] == 1:
|
|
|
|
mode = rawmode = "L"
|
|
|
|
elif w[11] == 2:
|
|
|
|
# FIXME: add memory map support
|
|
|
|
mode = "I"
|
|
|
|
rawmode = "I;16B"
|
|
|
|
elif w[11] == 4:
|
|
|
|
# FIXME: add memory map support
|
|
|
|
mode = "I"
|
|
|
|
rawmode = "I;32B"
|
|
|
|
else:
|
2022-12-22 00:51:35 +03:00
|
|
|
msg = "unsupported McIdas format"
|
|
|
|
raise SyntaxError(msg)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2023-07-29 02:28:18 +03:00
|
|
|
self._mode = mode
|
2018-09-30 05:58:02 +03:00
|
|
|
self._size = w[10], w[9]
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
offset = w[34] + w[15]
|
|
|
|
stride = w[15] + w[10] * w[11] * w[14]
|
|
|
|
|
|
|
|
self.tile = [("raw", (0, 0) + self.size, offset, (rawmode, stride, 1))]
|
|
|
|
|
2017-05-28 16:11:16 +03:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# registry
|
|
|
|
|
2015-12-25 06:15:01 +03:00
|
|
|
Image.register_open(McIdasImageFile.format, McIdasImageFile, _accept)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
# no default extension
|