~ubuntu-branches/ubuntu/saucy/python-imaging/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/git-updates.diff/PIL/CurImagePlugin.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-03-20 16:44:01 UTC
  • mfrom: (2.1.13 experimental)
  • Revision ID: package-import@ubuntu.com-20130320164401-ptf6m0ttg4zw72az
Tags: 1.1.7+2.0.0-1
Pillow 2.0.0 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#
18
 
 
19
 
 
20
 
__version__ = "0.1"
21
 
 
22
 
import Image, BmpImagePlugin
23
 
 
24
 
 
25
 
#
26
 
# --------------------------------------------------------------------
27
 
 
28
 
def i16(c):
29
 
    return ord(c[0]) + (ord(c[1])<<8)
30
 
 
31
 
def i32(c):
32
 
    return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24)
33
 
 
34
 
 
35
 
def _accept(prefix):
36
 
    return prefix[:4] == "\0\0\2\0"
37
 
 
38
 
##
39
 
# Image plugin for Windows Cursor files.
40
 
 
41
 
class CurImageFile(BmpImagePlugin.BmpImageFile):
42
 
 
43
 
    format = "CUR"
44
 
    format_description = "Windows Cursor"
45
 
 
46
 
    def _open(self):
47
 
 
48
 
        offset = self.fp.tell()
49
 
 
50
 
        # check magic
51
 
        s = self.fp.read(6)
52
 
        if not _accept(s):
53
 
            raise SyntaxError, "not an CUR file"
54
 
 
55
 
        # pick the largest cursor in the file
56
 
        m = ""
57
 
        for i in range(i16(s[4:])):
58
 
            s = self.fp.read(16)
59
 
            if not m:
60
 
                m = s
61
 
            elif ord(s[0]) > ord(m[0]) and ord(s[1]) > ord(m[1]):
62
 
                m = s
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:])
71
 
 
72
 
        # load as bitmap
73
 
        self._bitmap(i32(m[12:]) + offset)
74
 
 
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
79
 
 
80
 
        return
81
 
 
82
 
 
83
 
#
84
 
# --------------------------------------------------------------------
85
 
 
86
 
Image.register_open("CUR", CurImageFile, _accept)
87
 
 
88
 
Image.register_extension("CUR", ".cur")