openmedialibrary_platform_w.../Lib/site-packages/PIL/ImageMode.py

57 lines
1.6 KiB
Python
Raw Permalink Normal View History

2016-01-31 14:44:46 +00:00
#
# The Python Imaging Library.
# $Id$
#
# standard mode descriptors
#
# History:
# 2006-03-20 fl Added
#
# Copyright (c) 2006 by Secret Labs AB.
# Copyright (c) 2006 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#
# mode descriptor cache
2019-01-20 10:35:31 +00:00
_modes = None
2016-01-31 14:44:46 +00:00
class ModeDescriptor(object):
2019-01-20 10:35:31 +00:00
"""Wrapper for mode strings."""
2016-01-31 14:44:46 +00:00
def __init__(self, mode, bands, basemode, basetype):
self.mode = mode
self.bands = bands
self.basemode = basemode
self.basetype = basetype
def __str__(self):
return self.mode
def getmode(mode):
2019-01-20 10:35:31 +00:00
"""Gets a mode descriptor for the given mode."""
global _modes
2016-01-31 14:44:46 +00:00
if not _modes:
# initialize mode cache
2019-01-20 10:35:31 +00:00
from . import Image
modes = {}
2016-01-31 14:44:46 +00:00
# core modes
for m, (basemode, basetype, bands) in Image._MODEINFO.items():
2019-01-20 10:35:31 +00:00
modes[m] = ModeDescriptor(m, bands, basemode, basetype)
2016-01-31 14:44:46 +00:00
# extra experimental modes
2019-01-20 10:35:31 +00:00
modes["RGBa"] = ModeDescriptor("RGBa",
("R", "G", "B", "a"), "RGB", "L")
modes["LA"] = ModeDescriptor("LA", ("L", "A"), "L", "L")
modes["La"] = ModeDescriptor("La", ("L", "a"), "L", "L")
modes["PA"] = ModeDescriptor("PA", ("P", "A"), "RGB", "L")
2016-01-31 14:44:46 +00:00
# mapping modes
2019-01-20 10:35:31 +00:00
modes["I;16"] = ModeDescriptor("I;16", "I", "L", "L")
modes["I;16L"] = ModeDescriptor("I;16L", "I", "L", "L")
modes["I;16B"] = ModeDescriptor("I;16B", "I", "L", "L")
# set global mode cache atomically
_modes = modes
2016-01-31 14:44:46 +00:00
return _modes[mode]