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
« 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#
20import olefile
22from . import Image, TiffImagePlugin
24#
25# --------------------------------------------------------------------
28def _accept(prefix):
29 return prefix[:8] == olefile.MAGIC
32##
33# Image plugin for Microsoft's Image Composer file format.
36class MicImageFile(TiffImagePlugin.TiffImageFile):
38 format = "MIC"
39 format_description = "Microsoft Image Composer"
40 _close_exclusive_fp_after_loading = False
42 def _open(self):
44 # read the OLE directory and see if this is a likely
45 # to be a Microsoft Image Composer file
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
52 # find ACI subfiles with Image members (maybe not the
53 # best way to identify MIC files, but what the... ;-)
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)
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")
65 self.frame = None
66 self._n_frames = len(self.images)
67 self.is_animated = self._n_frames > 1
69 if len(self.images) > 1:
70 self._category = Image.CONTAINER
72 self.seek(0)
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
82 self.fp = self.ole.openstream(filename)
84 TiffImagePlugin.TiffImageFile._open(self)
86 self.frame = frame
88 def tell(self):
89 return self.frame
92#
93# --------------------------------------------------------------------
95Image.register_open(MicImageFile.format, MicImageFile, _accept)
97Image.register_extension(MicImageFile.format, ".mic")