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

« back to all changes in this revision

Viewing changes to PIL/PaletteFile.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:
13
13
# See the README file for information on usage and redistribution.
14
14
#
15
15
 
16
 
import string
 
16
from ._binary import o8
17
17
 
18
18
##
19
19
# File handler for Teragon-style palette files.
24
24
 
25
25
    def __init__(self, fp):
26
26
 
27
 
        self.palette = map(lambda i: (i, i, i), range(256))
 
27
        self.palette = [(i, i, i) for i in range(256)]
28
28
 
29
 
        while 1:
 
29
        while True:
30
30
 
31
31
            s = fp.readline()
32
32
 
33
33
            if not s:
34
34
                break
35
 
            if s[0] == "#":
 
35
            if s[0:1] == b"#":
36
36
                continue
37
37
            if len(s) > 100:
38
 
                raise SyntaxError, "bad palette file"
 
38
                raise SyntaxError("bad palette file")
39
39
 
40
 
            v = map(int, string.split(s))
 
40
            v = [int(x) for x in s.split()]
41
41
            try:
42
42
                [i, r, g, b] = v
43
43
            except ValueError:
45
45
                g = b = r
46
46
 
47
47
            if 0 <= i <= 255:
48
 
                self.palette[i] = chr(r) + chr(g) + chr(b)
 
48
                self.palette[i] = o8(r) + o8(g) + o8(b)
49
49
 
50
 
        self.palette = string.join(self.palette, "")
 
50
        self.palette = b"".join(self.palette)
51
51
 
52
52
 
53
53
    def getpalette(self):