Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/PIL/McIdasImagePlugin.py: 64%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

33 statements  

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# 

18from __future__ import annotations 

19 

20__lazy_modules__ = {"struct"} 

21 

22import struct 

23 

24from . import Image, ImageFile 

25 

26 

27def _accept(prefix: bytes) -> bool: 

28 return prefix.startswith(b"\x00\x00\x00\x00\x00\x00\x00\x04") 

29 

30 

31## 

32# Image plugin for McIdas area images. 

33 

34 

35class McIdasImageFile(ImageFile.ImageFile): 

36 format = "MCIDAS" 

37 format_description = "McIdas area file" 

38 

39 def _open(self) -> None: 

40 # parse area file directory 

41 assert self.fp is not None 

42 

43 s = self.fp.read(256) 

44 if not _accept(s) or len(s) != 256: 

45 msg = "not an McIdas area file" 

46 raise SyntaxError(msg) 

47 

48 self.area_descriptor_raw = s 

49 self.area_descriptor = w = [0, *struct.unpack("!64i", s)] 

50 

51 # get mode 

52 if w[11] == 1: 

53 mode = rawmode = "L" 

54 elif w[11] == 2: 

55 mode = rawmode = "I;16B" 

56 elif w[11] == 4: 

57 # FIXME: add memory map support 

58 mode = "I" 

59 rawmode = "I;32B" 

60 else: 

61 msg = "unsupported McIdas format" 

62 raise SyntaxError(msg) 

63 

64 self._mode = mode 

65 self._size = w[10], w[9] 

66 

67 offset = w[34] + w[15] 

68 stride = w[15] + w[10] * w[11] * w[14] 

69 

70 self.tile = [ImageFile._Tile("raw", None, offset, (rawmode, stride, 1))] 

71 

72 

73# -------------------------------------------------------------------- 

74# registry 

75 

76Image.register_open(McIdasImageFile.format, McIdasImageFile, _accept) 

77 

78# no default extension