~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (1.1.4)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130131204920-7tnuhqhlsqdza4c2
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# The Python Imaging Library.
 
3
# $Id$
 
4
#
 
5
# XV Thumbnail file handler by Charles E. "Gene" Cash
 
6
# (gcash@magicnet.net)
 
7
#
 
8
# see xvcolor.c and xvbrowse.c in the sources to John Bradley's XV,
 
9
# available from ftp://ftp.cis.upenn.edu/pub/xv/
 
10
#
 
11
# history:
 
12
# 98-08-15 cec  created (b/w only)
 
13
# 98-12-09 cec  added color palette
 
14
# 98-12-28 fl   added to PIL (with only a few very minor modifications)
 
15
#
 
16
# To do:
 
17
# FIXME: make save work (this requires quantization support)
 
18
#
 
19
 
 
20
__version__ = "0.1"
 
21
 
 
22
import string
 
23
import Image, ImageFile, ImagePalette
 
24
 
 
25
# standard color palette for thumbnails (RGB332)
 
26
PALETTE = ""
 
27
for r in range(8):
 
28
    for g in range(8):
 
29
        for b in range(4):
 
30
            PALETTE = PALETTE + (chr((r*255)/7)+chr((g*255)/7)+chr((b*255)/3))
 
31
 
 
32
##
 
33
# Image plugin for XV thumbnail images.
 
34
 
 
35
class XVThumbImageFile(ImageFile.ImageFile):
 
36
 
 
37
    format = "XVThumb"
 
38
    format_description = "XV thumbnail image"
 
39
 
 
40
    def _open(self):
 
41
 
 
42
        # check magic
 
43
        s = self.fp.read(6)
 
44
        if s != "P7 332":
 
45
            raise SyntaxError, "not an XV thumbnail file"
 
46
 
 
47
        # Skip to beginning of next line
 
48
        self.fp.readline()
 
49
 
 
50
        # skip info comments
 
51
        while 1:
 
52
            s = self.fp.readline()
 
53
            if not s:
 
54
                raise SyntaxError, "Unexpected EOF reading XV thumbnail file"
 
55
            if s[0] != '#':
 
56
                break
 
57
 
 
58
        # parse header line (already read)
 
59
        s = string.split(s.strip())
 
60
 
 
61
        self.mode = "P"
 
62
        self.size = int(s[0]), int(s[1])
 
63
 
 
64
        self.palette = ImagePalette.raw("RGB", PALETTE)
 
65
 
 
66
        self.tile = [
 
67
            ("raw", (0, 0)+self.size,
 
68
             self.fp.tell(), (self.mode, 0, 1)
 
69
             )]
 
70
 
 
71
# --------------------------------------------------------------------
 
72
 
 
73
Image.register_open("XVThumb", XVThumbImageFile)