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

36 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# DCX file handling 

6# 

7# DCX is a container file format defined by Intel, commonly used 

8# for fax applications. Each DCX file consists of a directory 

9# (a list of file offsets) followed by a set of (usually 1-bit) 

10# PCX files. 

11# 

12# History: 

13# 1995-09-09 fl Created 

14# 1996-03-20 fl Properly derived from PcxImageFile. 

15# 1998-07-15 fl Renamed offset attribute to avoid name clash 

16# 2002-07-30 fl Fixed file handling 

17# 

18# Copyright (c) 1997-98 by Secret Labs AB. 

19# Copyright (c) 1995-96 by Fredrik Lundh. 

20# 

21# See the README file for information on usage and redistribution. 

22# 

23 

24from . import Image 

25from ._binary import i32le as i32 

26from .PcxImagePlugin import PcxImageFile 

27 

28MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then? 

29 

30 

31def _accept(prefix): 

32 return len(prefix) >= 4 and i32(prefix) == MAGIC 

33 

34 

35## 

36# Image plugin for the Intel DCX format. 

37 

38 

39class DcxImageFile(PcxImageFile): 

40 

41 format = "DCX" 

42 format_description = "Intel DCX" 

43 _close_exclusive_fp_after_loading = False 

44 

45 def _open(self): 

46 

47 # Header 

48 s = self.fp.read(4) 

49 if not _accept(s): 

50 raise SyntaxError("not a DCX file") 

51 

52 # Component directory 

53 self._offset = [] 

54 for i in range(1024): 

55 offset = i32(self.fp.read(4)) 

56 if not offset: 

57 break 

58 self._offset.append(offset) 

59 

60 self._fp = self.fp 

61 self.frame = None 

62 self.n_frames = len(self._offset) 

63 self.is_animated = self.n_frames > 1 

64 self.seek(0) 

65 

66 def seek(self, frame): 

67 if not self._seek_check(frame): 

68 return 

69 self.frame = frame 

70 self.fp = self._fp 

71 self.fp.seek(self._offset[frame]) 

72 PcxImageFile._open(self) 

73 

74 def tell(self): 

75 return self.frame 

76 

77 

78Image.register_open(DcxImageFile.format, DcxImageFile, _accept) 

79 

80Image.register_extension(DcxImageFile.format, ".dcx")