[IMAGE-SIG] problem reading .xbm files in PIL 0.3a1
Fredrik Lundh
Fredrik Lundh" <fredrik_lundh@ivab.se
Mon, 7 Jul 1997 10:25:54 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_01BC8AC0.2696C420
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
>Will the next release be able to read the [bitmap] format?
Because of this &%&" mailer, I'm not sure if there were tabs in
there, or multiple spaces. Anyway, the current implementation
expects a single space (on the other hand, it works perfectly fine
with files created on bitmap on my machine). The spec I have
shows a single space only, but doesn't say anything on how to
tokenize the file. Oh well...
I've attached a version of XbmImagePlugin.py that hopefully
works better (if not, mail me an uu/mime-encoded version of
the file).
Cheers /F
------=_NextPart_000_01BC8AC0.2696C420
Content-Type: application/octet-stream;
name="xbmimageplugin.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="xbmimageplugin.py"
#
# The Python Imaging Library.
# $Id: XbmImagePlugin.py,v 1.3 1996/11/10 17:52:14 fredrik Exp $
#
# XBM File handling
#
# History:
# 95-09-08 fl Created
# 96-11-01 fl Added save support
# 97-07-07 fl Made header parser more tolerant
#
# Copyright (c) Fredrik Lundh 1996-97. All rights reserved.
#
# See the README file for information on usage and redistribution.
#
__version__ = "0.2"
import regex, string
import Image, ImageFile
# XBM header
xbm_head = regex.compile("^#define[ \t]+[^_]*_width[ \t]+\([0-9]*\)\n"
"#define[ \t]+[^_]*_height[ \t]+\([0-9]*\)\n"
".*char[ \t]+[^_]*_bits\[\]")
class XbmImageFile(ImageFile.ImageFile):
format = "XBM"
format_description = "X11 Bitmap"
def _open(self):
s = xbm_head.match(self.fp.read(512))
if s > 0:
xsize = string.atoi(xbm_head.group(1))
ysize = string.atoi(xbm_head.group(2))
self.mode = "1"
self.size = xsize, ysize
self.tile = [("xbm", (0, 0)+self.size, s, None)]
def _save(im, fp, filename):
if im.mode != "1":
raise IOError, "cannot write mode %s as XBM" % im.mode
fp.write("#define im_width %d\n" % im.size[0])
fp.write("#define im_height %d\n" % im.size[1])
fp.write("static char im_bits[] = {\n")
ImageFile._save(im, fp, [("xbm", (0,0)+im.size, 0, None)])
fp.write("};\n")
Image.register_open("XBM", XbmImageFile)
Image.register_save("XBM", _save)
Image.register_extension("XBM", ".xbm")
Image.register_mime("XBM", "image/xbm")
------=_NextPart_000_01BC8AC0.2696C420--
_______________
IMAGE-SIG - SIG on Image Processing with Python
send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org
_______________