~ubuntu-branches/ubuntu/trusty/python-imaging/trusty

« back to all changes in this revision

Viewing changes to .pc/git-updates.diff/PIL/GimpPaletteFile.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
 
# Python Imaging Library
3
 
# $Id$
4
 
#
5
 
# stuff to read GIMP palette files
6
 
#
7
 
# History:
8
 
# 1997-08-23 fl     Created
9
 
# 2004-09-07 fl     Support GIMP 2.0 palette files.
10
 
#
11
 
# Copyright (c) Secret Labs AB 1997-2004.  All rights reserved.
12
 
# Copyright (c) Fredrik Lundh 1997-2004.
13
 
#
14
 
# See the README file for information on usage and redistribution.
15
 
#
16
 
 
17
 
import re, string
18
 
 
19
 
##
20
 
# File handler for GIMP's palette format.
21
 
 
22
 
class GimpPaletteFile:
23
 
 
24
 
    rawmode = "RGB"
25
 
 
26
 
    def __init__(self, fp):
27
 
 
28
 
        self.palette = map(lambda i: chr(i)*3, range(256))
29
 
 
30
 
        if fp.readline()[:12] != "GIMP Palette":
31
 
            raise SyntaxError, "not a GIMP palette file"
32
 
 
33
 
        i = 0
34
 
 
35
 
        while i <= 255:
36
 
 
37
 
            s = fp.readline()
38
 
 
39
 
            if not s:
40
 
                break
41
 
            # skip fields and comment lines
42
 
            if re.match("\w+:|#", s):
43
 
                continue
44
 
            if len(s) > 100:
45
 
                raise SyntaxError, "bad palette file"
46
 
 
47
 
            v = tuple(map(int, string.split(s)[:3]))
48
 
            if len(v) != 3:
49
 
                raise ValueError, "bad palette entry"
50
 
 
51
 
            if 0 <= i <= 255:
52
 
                self.palette[i] = chr(v[0]) + chr(v[1]) + chr(v[2])
53
 
 
54
 
            i = i + 1
55
 
 
56
 
        self.palette = string.join(self.palette, "")
57
 
 
58
 
 
59
 
    def getpalette(self):
60
 
 
61
 
        return self.palette, self.rawmode