2
# The Python Imaging Library.
8
# 1996-04-12 fl Created
10
# Copyright (c) 1997 by Secret Labs AB.
11
# Copyright (c) 1996 by Fredrik Lundh.
13
# See the README file for information on usage and redistribution.
17
# NOTE: This format cannot be automatically recognized, so the
18
# class is not registered for use with Image.open(). To open a
19
# gd file, use the GdImageFile.open() function instead.
21
# THE GD FORMAT IS NOT DESIGNED FOR DATA INTERCHANGE. This
22
# implementation is provided for convenience and demonstrational
28
import ImageFile, ImagePalette
31
return ord(c[1]) + (ord(c[0])<<8)
34
# Image plugin for the GD uncompressed format. Note that this format
35
# is not supported by the standard <b>Image.open</b> function. To use
36
# this plugin, you have to import the <b>GdImageFile</b> module and
37
# use the <b>GdImageFile.open</b> function.
39
class GdImageFile(ImageFile.ImageFile):
42
format_description = "GD uncompressed images"
49
self.mode = "L" # FIXME: "P"
50
self.size = i16(s[0:2]), i16(s[2:4])
55
self.info["transparent"] = tindex
57
self.palette = ImagePalette.raw("RGB", s[7:])
59
self.tile = [("raw", (0,0)+self.size, 775, ("L", 0, -1))]
62
# Load texture from a GD image file.
64
# @param filename GD file name, or an opened file handle.
65
# @param mode Optional mode. In this version, if the mode argument
66
# is given, it must be "r".
67
# @return An image instance.
68
# @exception IOError If the image could not be read.
70
def open(fp, mode = "r"):
73
raise ValueError("bad mode")
75
if type(fp) == type(""):
78
fp = __builtin__.open(fp, "rb")
83
return GdImageFile(fp, filename)
85
raise IOError("cannot identify this image file")