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

« back to all changes in this revision

Viewing changes to PIL/XbmImagePlugin.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:
21
21
 
22
22
__version__ = "0.6"
23
23
 
24
 
import re, string
25
 
import Image, ImageFile
 
24
import re
 
25
from . import Image, ImageFile
26
26
 
27
27
# XBM header
28
28
xbm_head = re.compile(
29
 
    "\s*#define[ \t]+[^_]*_width[ \t]+(?P<width>[0-9]+)[\r\n]+"
30
 
    "#define[ \t]+[^_]*_height[ \t]+(?P<height>[0-9]+)[\r\n]+"
31
 
    "(?P<hotspot>"
32
 
    "#define[ \t]+[^_]*_x_hot[ \t]+(?P<xhot>[0-9]+)[\r\n]+"
33
 
    "#define[ \t]+[^_]*_y_hot[ \t]+(?P<yhot>[0-9]+)[\r\n]+"
34
 
    ")?"
35
 
    "[\\000-\\377]*_bits\\[\\]"
 
29
    b"\s*#define[ \t]+[^_]*_width[ \t]+(?P<width>[0-9]+)[\r\n]+"
 
30
    b"#define[ \t]+[^_]*_height[ \t]+(?P<height>[0-9]+)[\r\n]+"
 
31
    b"(?P<hotspot>"
 
32
    b"#define[ \t]+[^_]*_x_hot[ \t]+(?P<xhot>[0-9]+)[\r\n]+"
 
33
    b"#define[ \t]+[^_]*_y_hot[ \t]+(?P<yhot>[0-9]+)[\r\n]+"
 
34
    b")?"
 
35
    b"[\\000-\\377]*_bits\\[\\]"
36
36
)
37
37
 
38
38
def _accept(prefix):
39
 
    return string.lstrip(prefix)[:7] == "#define"
 
39
    return prefix.lstrip()[:7] == b"#define"
40
40
 
41
41
##
42
42
# Image plugin for X11 bitmaps.
69
69
def _save(im, fp, filename):
70
70
 
71
71
    if im.mode != "1":
72
 
        raise IOError, "cannot write mode %s as XBM" % im.mode
 
72
        raise IOError("cannot write mode %s as XBM" % im.mode)
73
73
 
74
 
    fp.write("#define im_width %d\n" % im.size[0])
75
 
    fp.write("#define im_height %d\n" % im.size[1])
 
74
    fp.write(("#define im_width %d\n" % im.size[0]).encode('ascii'))
 
75
    fp.write(("#define im_height %d\n" % im.size[1]).encode('ascii'))
76
76
 
77
77
    hotspot = im.encoderinfo.get("hotspot")
78
78
    if hotspot:
79
 
        fp.write("#define im_x_hot %d\n" % hotspot[0])
80
 
        fp.write("#define im_y_hot %d\n" % hotspot[1])
 
79
        fp.write(("#define im_x_hot %d\n" % hotspot[0]).encode('ascii'))
 
80
        fp.write(("#define im_y_hot %d\n" % hotspot[1]).encode('ascii'))
81
81
 
82
 
    fp.write("static char im_bits[] = {\n")
 
82
    fp.write(b"static char im_bits[] = {\n")
83
83
 
84
84
    ImageFile._save(im, fp, [("xbm", (0,0)+im.size, 0, None)])
85
85
 
86
 
    fp.write("};\n")
 
86
    fp.write(b"};\n")
87
87
 
88
88
 
89
89
Image.register_open("XBM", XbmImageFile, _accept)