2
# The Python Imaging Library.
5
# Windows Cursor support for PIL
8
# uses BmpImagePlugin.py to read the bitmap data.
13
# Copyright (c) Secret Labs AB 1997.
14
# Copyright (c) Fredrik Lundh 1996.
16
# See the README file for information on usage and redistribution.
22
import Image, BmpImagePlugin
26
# --------------------------------------------------------------------
29
return ord(c[0]) + (ord(c[1])<<8)
32
return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24)
36
return prefix[:4] == "\0\0\2\0"
39
# Image plugin for Windows Cursor files.
41
class CurImageFile(BmpImagePlugin.BmpImageFile):
44
format_description = "Windows Cursor"
48
offset = self.fp.tell()
53
raise SyntaxError, "not an CUR file"
55
# pick the largest cursor in the file
57
for i in range(i16(s[4:])):
61
elif ord(s[0]) > ord(m[0]) and ord(s[1]) > ord(m[1]):
63
#print "width", ord(s[0])
64
#print "height", ord(s[1])
65
#print "colors", ord(s[2])
66
#print "reserved", ord(s[3])
67
#print "hotspot x", i16(s[4:])
68
#print "hotspot y", i16(s[6:])
69
#print "bytes", i32(s[8:])
70
#print "offset", i32(s[12:])
73
self._bitmap(i32(m[12:]) + offset)
75
# patch up the bitmap height
76
self.size = self.size[0], self.size[1]/2
77
d, e, o, a = self.tile[0]
78
self.tile[0] = d, (0,0)+self.size, o, a
84
# --------------------------------------------------------------------
86
Image.register_open("CUR", CurImageFile, _accept)
88
Image.register_extension("CUR", ".cur")