Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/PIL/McIdasImagePlugin.py: 26%

28 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

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 

19import struct 

20 

21from . import Image, ImageFile 

22 

23 

24def _accept(s): 

25 return s[:8] == b"\x00\x00\x00\x00\x00\x00\x00\x04" 

26 

27 

28## 

29# Image plugin for McIdas area images. 

30 

31 

32class McIdasImageFile(ImageFile.ImageFile): 

33 

34 format = "MCIDAS" 

35 format_description = "McIdas area file" 

36 

37 def _open(self): 

38 

39 # parse area file directory 

40 s = self.fp.read(256) 

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

42 raise SyntaxError("not an McIdas area file") 

43 

44 self.area_descriptor_raw = s 

45 self.area_descriptor = w = [0] + list(struct.unpack("!64i", s)) 

46 

47 # get mode 

48 if w[11] == 1: 

49 mode = rawmode = "L" 

50 elif w[11] == 2: 

51 # FIXME: add memory map support 

52 mode = "I" 

53 rawmode = "I;16B" 

54 elif w[11] == 4: 

55 # FIXME: add memory map support 

56 mode = "I" 

57 rawmode = "I;32B" 

58 else: 

59 raise SyntaxError("unsupported McIdas format") 

60 

61 self.mode = mode 

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

63 

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

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

66 

67 self.tile = [("raw", (0, 0) + self.size, offset, (rawmode, stride, 1))] 

68 

69 

70# -------------------------------------------------------------------- 

71# registry 

72 

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

74 

75# no default extension