~asdfghjkl-deactivatedaccount1/python-imaging/gif-fix

« back to all changes in this revision

Viewing changes to PIL/ImageMode.py

  • Committer: effbot
  • Date: 2006-07-05 20:36:11 UTC
  • Revision ID: svn-v4:be285980-f00d-0410-a9fe-d4747b46ecd0:pil:348
Load Imaging-1.1.6b1 into pil.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# The Python Imaging Library.
 
3
# $Id: /work/modules/pil/PIL/ImageFilter.py 486 2004-10-06T08:55:20.930352Z fredrik  $
 
4
#
 
5
# standard mode descriptors
 
6
#
 
7
# History:
 
8
# 2006-03-20 fl   Added
 
9
#
 
10
# Copyright (c) 2006 by Secret Labs AB.
 
11
# Copyright (c) 2006 by Fredrik Lundh.
 
12
#
 
13
# See the README file for information on usage and redistribution.
 
14
#
 
15
 
 
16
# mode descriptor cache
 
17
_modes = {}
 
18
 
 
19
##
 
20
# Wrapper for mode strings.
 
21
 
 
22
class ModeDescriptor:
 
23
 
 
24
    def __init__(self, mode, bands, basemode, basetype):
 
25
        self.mode = mode
 
26
        self.bands = bands
 
27
        self.basemode = basemode
 
28
        self.basetype = basetype
 
29
 
 
30
    def __str__(self):
 
31
        return self.mode
 
32
 
 
33
##
 
34
# Gets a mode descriptor for the given mode.
 
35
 
 
36
def getmode(mode):
 
37
    if not _modes:
 
38
        # initialize mode cache
 
39
        import Image
 
40
        # core modes
 
41
        for m, (basemode, basetype, bands) in Image._MODEINFO.items():
 
42
            _modes[m] = ModeDescriptor(m, bands, basemode, basetype)
 
43
        # extra experimental modes
 
44
        _modes["LA"] = ModeDescriptor("LA", ("L", "A"), "L", "L")
 
45
        _modes["PA"] = ModeDescriptor("PA", ("P", "A"), "RGB", "L")
 
46
    return _modes[mode]
 
47