2010-07-31 06:52:47 +04:00
|
|
|
#
|
|
|
|
# The Python Imaging Library.
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# DCX file handling
|
|
|
|
#
|
|
|
|
# DCX is a container file format defined by Intel, commonly used
|
|
|
|
# for fax applications. Each DCX file consists of a directory
|
|
|
|
# (a list of file offsets) followed by a set of (usually 1-bit)
|
|
|
|
# PCX files.
|
|
|
|
#
|
|
|
|
# History:
|
|
|
|
# 1995-09-09 fl Created
|
|
|
|
# 1996-03-20 fl Properly derived from PcxImageFile.
|
|
|
|
# 1998-07-15 fl Renamed offset attribute to avoid name clash
|
|
|
|
# 2002-07-30 fl Fixed file handling
|
|
|
|
#
|
|
|
|
# Copyright (c) 1997-98 by Secret Labs AB.
|
|
|
|
# Copyright (c) 1995-96 by Fredrik Lundh.
|
|
|
|
#
|
|
|
|
# See the README file for information on usage and redistribution.
|
|
|
|
#
|
|
|
|
|
2017-01-17 16:22:18 +03:00
|
|
|
from . import Image
|
|
|
|
from ._binary import i32le as i32
|
|
|
|
from .PcxImagePlugin import PcxImageFile
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2014-07-17 02:21:56 +04:00
|
|
|
MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then?
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2014-07-17 02:21:56 +04:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
def _accept(prefix):
|
2015-06-18 03:12:12 +03:00
|
|
|
return len(prefix) >= 4 and i32(prefix) == MAGIC
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2014-07-17 02:21:56 +04:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
##
|
|
|
|
# Image plugin for the Intel DCX format.
|
|
|
|
|
2019-03-21 16:28:20 +03:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
class DcxImageFile(PcxImageFile):
|
|
|
|
|
|
|
|
format = "DCX"
|
|
|
|
format_description = "Intel DCX"
|
2017-03-15 02:16:38 +03:00
|
|
|
_close_exclusive_fp_after_loading = False
|
2018-01-27 09:02:56 +03:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
def _open(self):
|
|
|
|
|
|
|
|
# Header
|
|
|
|
s = self.fp.read(4)
|
|
|
|
if i32(s) != MAGIC:
|
2012-10-11 07:52:53 +04:00
|
|
|
raise SyntaxError("not a DCX file")
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
# Component directory
|
|
|
|
self._offset = []
|
|
|
|
for i in range(1024):
|
|
|
|
offset = i32(self.fp.read(4))
|
|
|
|
if not offset:
|
|
|
|
break
|
|
|
|
self._offset.append(offset)
|
|
|
|
|
|
|
|
self.__fp = self.fp
|
2017-09-30 06:32:43 +03:00
|
|
|
self.frame = None
|
2020-04-13 07:37:49 +03:00
|
|
|
self.n_frames = len(self._offset)
|
|
|
|
self.is_animated = self.n_frames > 1
|
2010-07-31 06:52:47 +04:00
|
|
|
self.seek(0)
|
|
|
|
|
|
|
|
def seek(self, frame):
|
2017-09-30 06:32:43 +03:00
|
|
|
if not self._seek_check(frame):
|
|
|
|
return
|
2010-07-31 06:52:47 +04:00
|
|
|
self.frame = frame
|
|
|
|
self.fp = self.__fp
|
|
|
|
self.fp.seek(self._offset[frame])
|
|
|
|
PcxImageFile._open(self)
|
|
|
|
|
|
|
|
def tell(self):
|
|
|
|
return self.frame
|
|
|
|
|
2018-11-17 13:56:06 +03:00
|
|
|
def _close__fp(self):
|
|
|
|
try:
|
2019-01-04 04:29:23 +03:00
|
|
|
if self.__fp != self.fp:
|
|
|
|
self.__fp.close()
|
2018-11-17 13:56:06 +03:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
self.__fp = None
|
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2015-07-04 16:29:58 +03:00
|
|
|
Image.register_open(DcxImageFile.format, DcxImageFile, _accept)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2015-07-04 16:29:58 +03:00
|
|
|
Image.register_extension(DcxImageFile.format, ".dcx")
|