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

39 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# Microsoft Image Composer support for PIL 

6# 

7# Notes: 

8# uses TiffImagePlugin.py to read the actual image streams 

9# 

10# History: 

11# 97-01-20 fl Created 

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 

19 

20import olefile 

21 

22from . import Image, TiffImagePlugin 

23 

24# 

25# -------------------------------------------------------------------- 

26 

27 

28def _accept(prefix): 

29 return prefix[:8] == olefile.MAGIC 

30 

31 

32## 

33# Image plugin for Microsoft's Image Composer file format. 

34 

35 

36class MicImageFile(TiffImagePlugin.TiffImageFile): 

37 

38 format = "MIC" 

39 format_description = "Microsoft Image Composer" 

40 _close_exclusive_fp_after_loading = False 

41 

42 def _open(self): 

43 

44 # read the OLE directory and see if this is a likely 

45 # to be a Microsoft Image Composer file 

46 

47 try: 

48 self.ole = olefile.OleFileIO(self.fp) 

49 except OSError as e: 

50 raise SyntaxError("not an MIC file; invalid OLE file") from e 

51 

52 # find ACI subfiles with Image members (maybe not the 

53 # best way to identify MIC files, but what the... ;-) 

54 

55 self.images = [] 

56 for path in self.ole.listdir(): 

57 if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image": 

58 self.images.append(path) 

59 

60 # if we didn't find any images, this is probably not 

61 # an MIC file. 

62 if not self.images: 

63 raise SyntaxError("not an MIC file; no image entries") 

64 

65 self.frame = None 

66 self._n_frames = len(self.images) 

67 self.is_animated = self._n_frames > 1 

68 

69 if len(self.images) > 1: 

70 self._category = Image.CONTAINER 

71 

72 self.seek(0) 

73 

74 def seek(self, frame): 

75 if not self._seek_check(frame): 

76 return 

77 try: 

78 filename = self.images[frame] 

79 except IndexError as e: 

80 raise EOFError("no such frame") from e 

81 

82 self.fp = self.ole.openstream(filename) 

83 

84 TiffImagePlugin.TiffImageFile._open(self) 

85 

86 self.frame = frame 

87 

88 def tell(self): 

89 return self.frame 

90 

91 

92# 

93# -------------------------------------------------------------------- 

94 

95Image.register_open(MicImageFile.format, MicImageFile, _accept) 

96 

97Image.register_extension(MicImageFile.format, ".mic")