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

29 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# Windows Cursor support for PIL 

6# 

7# notes: 

8# uses BmpImagePlugin.py to read the bitmap data. 

9# 

10# history: 

11# 96-05-27 fl Created 

12# 

13# Copyright (c) Secret Labs AB 1997. 

14# Copyright (c) Fredrik Lundh 1996. 

15# 

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

17# 

18from . import BmpImagePlugin, Image 

19from ._binary import i16le as i16 

20from ._binary import i32le as i32 

21 

22# 

23# -------------------------------------------------------------------- 

24 

25 

26def _accept(prefix): 

27 return prefix[:4] == b"\0\0\2\0" 

28 

29 

30## 

31# Image plugin for Windows Cursor files. 

32 

33 

34class CurImageFile(BmpImagePlugin.BmpImageFile): 

35 

36 format = "CUR" 

37 format_description = "Windows Cursor" 

38 

39 def _open(self): 

40 

41 offset = self.fp.tell() 

42 

43 # check magic 

44 s = self.fp.read(6) 

45 if not _accept(s): 

46 raise SyntaxError("not a CUR file") 

47 

48 # pick the largest cursor in the file 

49 m = b"" 

50 for i in range(i16(s, 4)): 

51 s = self.fp.read(16) 

52 if not m: 

53 m = s 

54 elif s[0] > m[0] and s[1] > m[1]: 

55 m = s 

56 if not m: 

57 raise TypeError("No cursors were found") 

58 

59 # load as bitmap 

60 self._bitmap(i32(m, 12) + offset) 

61 

62 # patch up the bitmap height 

63 self._size = self.size[0], self.size[1] // 2 

64 d, e, o, a = self.tile[0] 

65 self.tile[0] = d, (0, 0) + self.size, o, a 

66 

67 return 

68 

69 

70# 

71# -------------------------------------------------------------------- 

72 

73Image.register_open(CurImageFile.format, CurImageFile, _accept) 

74 

75Image.register_extension(CurImageFile.format, ".cur")