## 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.#from__future__importannotationsfrom.importImagefrom._binaryimporti32leasi32from._utilimportDeferredErrorfrom.PcxImagePluginimportPcxImageFileMAGIC=0x3ADE68B1# QUIZ: what's this value, then?def_accept(prefix:bytes)->bool:returnlen(prefix)>=4andi32(prefix)==MAGIC### Image plugin for the Intel DCX format.
[docs]classDcxImageFile(PcxImageFile):format="DCX"format_description="Intel DCX"_close_exclusive_fp_after_loading=Falsedef_open(self)->None:# Headers=self.fp.read(4)ifnot_accept(s):msg="not a DCX file"raiseSyntaxError(msg)# Component directoryself._offset=[]foriinrange(1024):offset=i32(self.fp.read(4))ifnotoffset:breakself._offset.append(offset)self._fp=self.fpself.frame=-1self.n_frames=len(self._offset)self.is_animated=self.n_frames>1self.seek(0)