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

« back to all changes in this revision

Viewing changes to PIL/IcoImagePlugin.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
__version__ = "0.1"
21
21
 
22
 
import Image, BmpImagePlugin
 
22
from . import Image, BmpImagePlugin, _binary
23
23
 
24
24
 
25
25
#
26
26
# --------------------------------------------------------------------
27
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)
 
28
i8 = _binary.i8
 
29
i16 = _binary.i16le
 
30
i32 = _binary.i32le
33
31
 
34
32
 
35
33
def _accept(prefix):
36
 
    return prefix[:4] == "\0\0\1\0"
 
34
    return prefix[:4] == b"\0\0\1\0"
37
35
 
38
36
##
39
37
# Image plugin for Windows Icon files.
48
46
        # check magic
49
47
        s = self.fp.read(6)
50
48
        if not _accept(s):
51
 
            raise SyntaxError, "not an ICO file"
 
49
            raise SyntaxError("not an ICO file")
52
50
 
53
51
        # pick the largest icon in the file
54
 
        m = ""
 
52
        m = b""
55
53
        for i in range(i16(s[4:])):
56
54
            s = self.fp.read(16)
57
55
            if not m:
58
56
                m = s
59
 
            elif ord(s[0]) > ord(m[0]) and ord(s[1]) > ord(m[1]):
 
57
            elif i8(s[0]) > i8(m[0]) and i8(s[1]) > i8(m[1]):
60
58
                m = s
61
 
            #print "width", ord(s[0])
62
 
            #print "height", ord(s[1])
63
 
            #print "colors", ord(s[2])
64
 
            #print "reserved", ord(s[3])
 
59
            #print "width", i8(s[0])
 
60
            #print "height", i8(s[1])
 
61
            #print "colors", i8(s[2])
 
62
            #print "reserved", i8(s[3])
65
63
            #print "planes", i16(s[4:])
66
64
            #print "bitcount", i16(s[6:])
67
65
            #print "bytes", i32(s[8:])
71
69
        self._bitmap(i32(m[12:]))
72
70
 
73
71
        # patch up the bitmap height
74
 
        self.size = self.size[0], self.size[1]/2
 
72
        self.size = self.size[0], self.size[1]//2
75
73
        d, e, o, a = self.tile[0]
76
74
        self.tile[0] = d, (0,0)+self.size, o, a
77
75