mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
py3k: Fix up uses of dictionary views, ranges, and has_key()
y.has_key(x) is gone (use x in y), and keys(), values(), items(), and range() all return views. Some iterables needed to be packed into lists, either because the code expected a list (such as "range(256) * 3") or because the original collection was being modified (automatic global declarations). The Tiff ImageFileDictionary is a special case and will be dealt with in another commit.
This commit is contained in:
parent
b386ed14dd
commit
09f1081c95
|
@ -131,7 +131,7 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||||
if colors == 2:
|
if colors == 2:
|
||||||
indices = (0, 255)
|
indices = (0, 255)
|
||||||
else:
|
else:
|
||||||
indices = range(colors)
|
indices = list(range(colors))
|
||||||
for i in indices:
|
for i in indices:
|
||||||
rgb = read(lutsize)[:3]
|
rgb = read(lutsize)[:3]
|
||||||
if rgb != chr(i)*3:
|
if rgb != chr(i)*3:
|
||||||
|
|
|
@ -108,7 +108,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
||||||
self.jpeg = {}
|
self.jpeg = {}
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
id = 0x3000001|(i << 16)
|
id = 0x3000001|(i << 16)
|
||||||
if prop.has_key(id):
|
if id in prop:
|
||||||
self.jpeg[i] = prop[id]
|
self.jpeg[i] = prop[id]
|
||||||
|
|
||||||
# print len(self.jpeg), "tables loaded"
|
# print len(self.jpeg), "tables loaded"
|
||||||
|
|
|
@ -125,7 +125,7 @@ class IcnsFile:
|
||||||
sizes = []
|
sizes = []
|
||||||
for size, fmts in self.SIZES.items():
|
for size, fmts in self.SIZES.items():
|
||||||
for (fmt, reader) in fmts:
|
for (fmt, reader) in fmts:
|
||||||
if self.dct.has_key(fmt):
|
if fmt in self.dct:
|
||||||
sizes.append(size)
|
sizes.append(size)
|
||||||
break
|
break
|
||||||
return sizes
|
return sizes
|
||||||
|
|
|
@ -162,20 +162,20 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
v = tuple(map(number, v.split(",")))
|
v = tuple(map(number, v.split(",")))
|
||||||
if len(v) == 1:
|
if len(v) == 1:
|
||||||
v = v[0]
|
v = v[0]
|
||||||
elif k == MODE and OPEN.has_key(v):
|
elif k == MODE and v in OPEN:
|
||||||
v, self.rawmode = OPEN[v]
|
v, self.rawmode = OPEN[v]
|
||||||
|
|
||||||
# Add to dictionary. Note that COMMENT tags are
|
# Add to dictionary. Note that COMMENT tags are
|
||||||
# combined into a list of strings.
|
# combined into a list of strings.
|
||||||
if k == COMMENT:
|
if k == COMMENT:
|
||||||
if self.info.has_key(k):
|
if k in self.info:
|
||||||
self.info[k].append(v)
|
self.info[k].append(v)
|
||||||
else:
|
else:
|
||||||
self.info[k] = [v]
|
self.info[k] = [v]
|
||||||
else:
|
else:
|
||||||
self.info[k] = v
|
self.info[k] = v
|
||||||
|
|
||||||
if TAGS.has_key(k):
|
if k in TAGS:
|
||||||
n = n + 1
|
n = n + 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -195,7 +195,7 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
if not s:
|
if not s:
|
||||||
raise SyntaxError("File truncated")
|
raise SyntaxError("File truncated")
|
||||||
|
|
||||||
if self.info.has_key(LUT):
|
if LUT in self.info:
|
||||||
# convert lookup table to palette or lut attribute
|
# convert lookup table to palette or lut attribute
|
||||||
palette = self.fp.read(768)
|
palette = self.fp.read(768)
|
||||||
greyscale = 1 # greyscale palette
|
greyscale = 1 # greyscale palette
|
||||||
|
|
|
@ -224,7 +224,7 @@ def _conv_type_shape(im):
|
||||||
return shape+(extra,), typ
|
return shape+(extra,), typ
|
||||||
|
|
||||||
|
|
||||||
MODES = _MODEINFO.keys()
|
MODES = list(_MODEINFO.keys())
|
||||||
MODES.sort()
|
MODES.sort()
|
||||||
|
|
||||||
# raw modes that may be memory mapped. NOTE: if you change this, you
|
# raw modes that may be memory mapped. NOTE: if you change this, you
|
||||||
|
@ -343,7 +343,7 @@ def init():
|
||||||
# only check directories (including current, if present in the path)
|
# only check directories (including current, if present in the path)
|
||||||
for directory in filter(isDirectory, directories):
|
for directory in filter(isDirectory, directories):
|
||||||
fullpath = os.path.abspath(directory)
|
fullpath = os.path.abspath(directory)
|
||||||
if visited.has_key(fullpath):
|
if fullpath in visited:
|
||||||
continue
|
continue
|
||||||
for file in os.listdir(directory):
|
for file in os.listdir(directory):
|
||||||
if file[-14:] == "ImagePlugin.py":
|
if file[-14:] == "ImagePlugin.py":
|
||||||
|
@ -610,7 +610,7 @@ class Image:
|
||||||
self.palette.dirty = 0
|
self.palette.dirty = 0
|
||||||
self.palette.mode = "RGB"
|
self.palette.mode = "RGB"
|
||||||
self.palette.rawmode = None
|
self.palette.rawmode = None
|
||||||
if self.info.has_key("transparency"):
|
if "transparency" in self.info:
|
||||||
self.im.putpalettealpha(self.info["transparency"], 0)
|
self.im.putpalettealpha(self.info["transparency"], 0)
|
||||||
self.palette.mode = "RGBA"
|
self.palette.mode = "RGBA"
|
||||||
if self.im:
|
if self.im:
|
||||||
|
|
|
@ -175,7 +175,7 @@ def imagemath_convert(self, mode):
|
||||||
return _Operand(self.im.convert(mode))
|
return _Operand(self.im.convert(mode))
|
||||||
|
|
||||||
ops = {}
|
ops = {}
|
||||||
for k, v in globals().items():
|
for k, v in list(globals().items()):
|
||||||
if k[:10] == "imagemath_":
|
if k[:10] == "imagemath_":
|
||||||
ops[k[10:]] = v
|
ops[k[10:]] = v
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ def eval(expression, _dict={}, **kw):
|
||||||
args = ops.copy()
|
args = ops.copy()
|
||||||
args.update(_dict)
|
args.update(_dict)
|
||||||
args.update(kw)
|
args.update(kw)
|
||||||
for k, v in args.items():
|
for k, v in list(args.items()):
|
||||||
if hasattr(v, "im"):
|
if hasattr(v, "im"):
|
||||||
args[k] = _Operand(v)
|
args[k] = _Operand(v)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class ImagePalette:
|
||||||
def __init__(self, mode = "RGB", palette = None):
|
def __init__(self, mode = "RGB", palette = None):
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.rawmode = None # if set, palette contains raw data
|
self.rawmode = None # if set, palette contains raw data
|
||||||
self.palette = palette or range(256)*len(self.mode)
|
self.palette = palette or list(range(256))*len(self.mode)
|
||||||
self.colors = {}
|
self.colors = {}
|
||||||
self.dirty = None
|
self.dirty = None
|
||||||
if len(self.mode)*256 != len(self.palette):
|
if len(self.mode)*256 != len(self.palette):
|
||||||
|
@ -119,7 +119,7 @@ def new(mode, data):
|
||||||
return Image.core.new_palette(mode, data)
|
return Image.core.new_palette(mode, data)
|
||||||
|
|
||||||
def negative(mode="RGB"):
|
def negative(mode="RGB"):
|
||||||
palette = range(256)
|
palette = list(range(256))
|
||||||
palette.reverse()
|
palette.reverse()
|
||||||
return ImagePalette(mode, palette * len(mode))
|
return ImagePalette(mode, palette * len(mode))
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ def sepia(white="#fff0c0"):
|
||||||
return ImagePalette("RGB", r + g + b)
|
return ImagePalette("RGB", r + g + b)
|
||||||
|
|
||||||
def wedge(mode="RGB"):
|
def wedge(mode="RGB"):
|
||||||
return ImagePalette(mode, range(256) * len(mode))
|
return ImagePalette(mode, list(range(256)) * len(mode))
|
||||||
|
|
||||||
def load(filename):
|
def load(filename):
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Stat:
|
||||||
self.h = image_or_list # assume it to be a histogram list
|
self.h = image_or_list # assume it to be a histogram list
|
||||||
if type(self.h) != type([]):
|
if type(self.h) != type([]):
|
||||||
raise TypeError("first argument must be image or list")
|
raise TypeError("first argument must be image or list")
|
||||||
self.bands = range(len(self.h) / 256)
|
self.bands = list(range(len(self.h) // 256))
|
||||||
|
|
||||||
def __getattr__(self, id):
|
def __getattr__(self, id):
|
||||||
"Calculate missing attribute"
|
"Calculate missing attribute"
|
||||||
|
|
|
@ -81,10 +81,10 @@ class PhotoImage:
|
||||||
|
|
||||||
# Tk compatibility: file or data
|
# Tk compatibility: file or data
|
||||||
if image is None:
|
if image is None:
|
||||||
if kw.has_key("file"):
|
if "file" in kw:
|
||||||
image = Image.open(kw["file"])
|
image = Image.open(kw["file"])
|
||||||
del kw["file"]
|
del kw["file"]
|
||||||
elif kw.has_key("data"):
|
elif "data" in kw:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
image = Image.open(StringIO(kw["data"]))
|
image = Image.open(StringIO(kw["data"]))
|
||||||
del kw["data"]
|
del kw["data"]
|
||||||
|
@ -213,10 +213,10 @@ class BitmapImage:
|
||||||
|
|
||||||
# Tk compatibility: file or data
|
# Tk compatibility: file or data
|
||||||
if image is None:
|
if image is None:
|
||||||
if kw.has_key("file"):
|
if "file" in kw:
|
||||||
image = Image.open(kw["file"])
|
image = Image.open(kw["file"])
|
||||||
del kw["file"]
|
del kw["file"]
|
||||||
elif kw.has_key("data"):
|
elif "data" in kw:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
image = Image.open(StringIO(kw["data"]))
|
image = Image.open(StringIO(kw["data"]))
|
||||||
del kw["data"]
|
del kw["data"]
|
||||||
|
|
|
@ -119,7 +119,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
tagdata = self.fp.read(size)
|
tagdata = self.fp.read(size)
|
||||||
else:
|
else:
|
||||||
tagdata = None
|
tagdata = None
|
||||||
if tag in self.info.keys():
|
if tag in list(self.info.keys()):
|
||||||
if isinstance(self.info[tag], list):
|
if isinstance(self.info[tag], list):
|
||||||
self.info[tag].append(tagdata)
|
self.info[tag].append(tagdata)
|
||||||
else:
|
else:
|
||||||
|
@ -132,7 +132,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
# mode
|
# mode
|
||||||
layers = ord(self.info[(3,60)][0])
|
layers = ord(self.info[(3,60)][0])
|
||||||
component = ord(self.info[(3,60)][1])
|
component = ord(self.info[(3,60)][1])
|
||||||
if self.info.has_key((3,65)):
|
if (3,65) in self.info:
|
||||||
id = ord(self.info[(3,65)][0])-1
|
id = ord(self.info[(3,65)][0])-1
|
||||||
else:
|
else:
|
||||||
id = 0
|
id = 0
|
||||||
|
|
|
@ -293,7 +293,7 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
i = i16(s)
|
i = i16(s)
|
||||||
|
|
||||||
if MARKER.has_key(i):
|
if i in MARKER:
|
||||||
name, description, handler = MARKER[i]
|
name, description, handler = MARKER[i]
|
||||||
# print hex(i), name, description
|
# print hex(i), name, description
|
||||||
if handler is not None:
|
if handler is not None:
|
||||||
|
@ -458,9 +458,9 @@ def _save(im, fp, filename):
|
||||||
# "progressive" is the official name, but older documentation
|
# "progressive" is the official name, but older documentation
|
||||||
# says "progression"
|
# says "progression"
|
||||||
# FIXME: issue a warning if the wrong form is used (post-1.1.7)
|
# FIXME: issue a warning if the wrong form is used (post-1.1.7)
|
||||||
info.has_key("progressive") or info.has_key("progression"),
|
"progressive" in info or "progression" in info,
|
||||||
info.get("smooth", 0),
|
info.get("smooth", 0),
|
||||||
info.has_key("optimize"),
|
"optimize" in info,
|
||||||
info.get("streamtype", 0),
|
info.get("streamtype", 0),
|
||||||
dpi[0], dpi[1],
|
dpi[0], dpi[1],
|
||||||
subsampling,
|
subsampling,
|
||||||
|
|
|
@ -65,7 +65,7 @@ VT_VECTOR=0x1000;
|
||||||
# map property id to name (for debugging purposes)
|
# map property id to name (for debugging purposes)
|
||||||
|
|
||||||
VT = {}
|
VT = {}
|
||||||
for k, v in vars().items():
|
for k, v in list(vars().items()):
|
||||||
if k[:3] == "VT_":
|
if k[:3] == "VT_":
|
||||||
VT[v] = k
|
VT[v] = k
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ if __name__ == "__main__":
|
||||||
if file[-1][0] == "\005":
|
if file[-1][0] == "\005":
|
||||||
print file
|
print file
|
||||||
props = ole.getproperties(file)
|
props = ole.getproperties(file)
|
||||||
props = props.items()
|
props = list(props.items())
|
||||||
props.sort()
|
props.sort()
|
||||||
for k, v in props:
|
for k, v in props:
|
||||||
print " ", k, v
|
print " ", k, v
|
||||||
|
|
|
@ -51,7 +51,7 @@ class PSDraw:
|
||||||
self.fp.flush()
|
self.fp.flush()
|
||||||
|
|
||||||
def setfont(self, font, size):
|
def setfont(self, font, size):
|
||||||
if not self.isofont.has_key(font):
|
if font not in self.isofont:
|
||||||
# reencode font
|
# reencode font
|
||||||
self.fp.write("/PSDraw-%s ISOLatin1Encoding /%s E\n" %\
|
self.fp.write("/PSDraw-%s ISOLatin1Encoding /%s E\n" %\
|
||||||
(font, font))
|
(font, font))
|
||||||
|
|
|
@ -80,7 +80,7 @@ _Palm8BitColormapValues = (
|
||||||
# so build a prototype image to be used for palette resampling
|
# so build a prototype image to be used for palette resampling
|
||||||
def build_prototype_image():
|
def build_prototype_image():
|
||||||
image = Image.new("L", (1,len(_Palm8BitColormapValues),))
|
image = Image.new("L", (1,len(_Palm8BitColormapValues),))
|
||||||
image.putdata(range(len(_Palm8BitColormapValues)))
|
image.putdata(list(range(len(_Palm8BitColormapValues))))
|
||||||
palettedata = ()
|
palettedata = ()
|
||||||
for i in range(len(_Palm8BitColormapValues)):
|
for i in range(len(_Palm8BitColormapValues)):
|
||||||
palettedata = palettedata + _Palm8BitColormapValues[i]
|
palettedata = palettedata + _Palm8BitColormapValues[i]
|
||||||
|
@ -127,7 +127,7 @@ def _save(im, fp, filename, check=0):
|
||||||
bpp = 8
|
bpp = 8
|
||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
elif im.mode == "L" and im.encoderinfo.has_key("bpp") and im.encoderinfo["bpp"] in (1, 2, 4):
|
elif im.mode == "L" and "bpp" in im.encoderinfo and im.encoderinfo["bpp"] in (1, 2, 4):
|
||||||
|
|
||||||
# this is 8-bit grayscale, so we shift it to get the high-order bits, and invert it because
|
# this is 8-bit grayscale, so we shift it to get the high-order bits, and invert it because
|
||||||
# Palm does greyscale from white (0) to black (1)
|
# Palm does greyscale from white (0) to black (1)
|
||||||
|
@ -138,7 +138,7 @@ def _save(im, fp, filename, check=0):
|
||||||
rawmode = "P;" + str(bpp)
|
rawmode = "P;" + str(bpp)
|
||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
elif im.mode == "L" and im.info.has_key("bpp") and im.info["bpp"] in (1, 2, 4):
|
elif im.mode == "L" and "bpp" in im.info and im.info["bpp"] in (1, 2, 4):
|
||||||
|
|
||||||
# here we assume that even though the inherent mode is 8-bit grayscale, only
|
# here we assume that even though the inherent mode is 8-bit grayscale, only
|
||||||
# the lower bpp bits are significant. We invert them to match the Palm.
|
# the lower bpp bits are significant. We invert them to match the Palm.
|
||||||
|
@ -177,7 +177,7 @@ def _save(im, fp, filename, check=0):
|
||||||
compression_type = _COMPRESSION_TYPES["none"]
|
compression_type = _COMPRESSION_TYPES["none"]
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
if im.mode == "P" and im.info.has_key("custom-colormap"):
|
if im.mode == "P" and "custom-colormap" in im.info:
|
||||||
flags = flags & _FLAGS["custom-colormap"]
|
flags = flags & _FLAGS["custom-colormap"]
|
||||||
colormapsize = 4 * 256 + 2;
|
colormapsize = 4 * 256 + 2;
|
||||||
colormapmode = im.palette.mode
|
colormapmode = im.palette.mode
|
||||||
|
@ -185,7 +185,7 @@ def _save(im, fp, filename, check=0):
|
||||||
else:
|
else:
|
||||||
colormapsize = 0
|
colormapsize = 0
|
||||||
|
|
||||||
if im.info.has_key("offset"):
|
if "offset" in im.info:
|
||||||
offset = (rowbytes * rows + 16 + 3 + colormapsize) / 4;
|
offset = (rowbytes * rows + 16 + 3 + colormapsize) / 4;
|
||||||
else:
|
else:
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
|
@ -469,7 +469,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
||||||
#
|
#
|
||||||
# attempt to minimize storage requirements for palette images
|
# attempt to minimize storage requirements for palette images
|
||||||
|
|
||||||
if im.encoderinfo.has_key("bits"):
|
if "bits" in im.encoderinfo:
|
||||||
|
|
||||||
# number of bits specified by user
|
# number of bits specified by user
|
||||||
n = 1 << im.encoderinfo["bits"]
|
n = 1 << im.encoderinfo["bits"]
|
||||||
|
@ -492,12 +492,12 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
||||||
mode = "%s;%d" % (mode, bits)
|
mode = "%s;%d" % (mode, bits)
|
||||||
|
|
||||||
# encoder options
|
# encoder options
|
||||||
if im.encoderinfo.has_key("dictionary"):
|
if "dictionary" in im.encoderinfo:
|
||||||
dictionary = im.encoderinfo["dictionary"]
|
dictionary = im.encoderinfo["dictionary"]
|
||||||
else:
|
else:
|
||||||
dictionary = ""
|
dictionary = ""
|
||||||
|
|
||||||
im.encoderconfig = (im.encoderinfo.has_key("optimize"), dictionary)
|
im.encoderconfig = ("optimize" in im.encoderinfo, dictionary)
|
||||||
|
|
||||||
# get the corresponding PNG mode
|
# get the corresponding PNG mode
|
||||||
try:
|
try:
|
||||||
|
@ -523,7 +523,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
||||||
if im.mode == "P":
|
if im.mode == "P":
|
||||||
chunk(fp, "PLTE", im.im.getpalette("RGB"))
|
chunk(fp, "PLTE", im.im.getpalette("RGB"))
|
||||||
|
|
||||||
if im.encoderinfo.has_key("transparency"):
|
if "transparency" in im.encoderinfo:
|
||||||
if im.mode == "P":
|
if im.mode == "P":
|
||||||
transparency = max(0, min(255, im.encoderinfo["transparency"]))
|
transparency = max(0, min(255, im.encoderinfo["transparency"]))
|
||||||
chunk(fp, "tRNS", chr(255) * transparency + chr(0))
|
chunk(fp, "tRNS", chr(255) * transparency + chr(0))
|
||||||
|
@ -553,7 +553,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
||||||
chunk(fp, cid, data)
|
chunk(fp, cid, data)
|
||||||
|
|
||||||
# ICC profile writing support -- 2008-06-06 Florian Hoech
|
# ICC profile writing support -- 2008-06-06 Florian Hoech
|
||||||
if im.info.has_key("icc_profile"):
|
if "icc_profile" in im.info:
|
||||||
# ICC profile
|
# ICC profile
|
||||||
# according to PNG spec, the iCCP chunk contains:
|
# according to PNG spec, the iCCP chunk contains:
|
||||||
# Profile name 1-79 bytes (character string)
|
# Profile name 1-79 bytes (character string)
|
||||||
|
|
|
@ -174,7 +174,7 @@ def _layerinfo(file):
|
||||||
# image info
|
# image info
|
||||||
info = []
|
info = []
|
||||||
mode = []
|
mode = []
|
||||||
types = range(i16(read(2)))
|
types = list(range(i16(read(2))))
|
||||||
if len(types) > 4:
|
if len(types) > 4:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -402,7 +402,7 @@ class ImageFileDirectory:
|
||||||
fp.write(o16(len(self.tags)))
|
fp.write(o16(len(self.tags)))
|
||||||
|
|
||||||
# always write in ascending tag order
|
# always write in ascending tag order
|
||||||
tags = self.tags.items()
|
tags = list(self.tags.items())
|
||||||
tags.sort()
|
tags.sort()
|
||||||
|
|
||||||
directory = []
|
directory = []
|
||||||
|
@ -417,7 +417,7 @@ class ImageFileDirectory:
|
||||||
|
|
||||||
typ = None
|
typ = None
|
||||||
|
|
||||||
if self.tagtype.has_key(tag):
|
if tag in self.tagtype:
|
||||||
typ = self.tagtype[tag]
|
typ = self.tagtype[tag]
|
||||||
|
|
||||||
if typ == 1:
|
if typ == 1:
|
||||||
|
@ -569,18 +569,18 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
args = (rawmode, 0, 1)
|
args = (rawmode, 0, 1)
|
||||||
elif compression == "jpeg":
|
elif compression == "jpeg":
|
||||||
args = rawmode, ""
|
args = rawmode, ""
|
||||||
if self.tag.has_key(JPEGTABLES):
|
if JPEGTABLES in self.tag:
|
||||||
# Hack to handle abbreviated JPEG headers
|
# Hack to handle abbreviated JPEG headers
|
||||||
self.tile_prefix = self.tag[JPEGTABLES]
|
self.tile_prefix = self.tag[JPEGTABLES]
|
||||||
elif compression == "packbits":
|
elif compression == "packbits":
|
||||||
args = rawmode
|
args = rawmode
|
||||||
elif compression == "tiff_lzw":
|
elif compression == "tiff_lzw":
|
||||||
args = rawmode
|
args = rawmode
|
||||||
if self.tag.has_key(317):
|
if 317 in self.tag:
|
||||||
# Section 14: Differencing Predictor
|
# Section 14: Differencing Predictor
|
||||||
self.decoderconfig = (self.tag[PREDICTOR][0],)
|
self.decoderconfig = (self.tag[PREDICTOR][0],)
|
||||||
|
|
||||||
if self.tag.has_key(ICCPROFILE):
|
if ICCPROFILE in self.tag:
|
||||||
self.info['icc_profile'] = self.tag[ICCPROFILE]
|
self.info['icc_profile'] = self.tag[ICCPROFILE]
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
@ -588,7 +588,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
def _setup(self):
|
def _setup(self):
|
||||||
"Setup this image object based on current tags"
|
"Setup this image object based on current tags"
|
||||||
|
|
||||||
if self.tag.has_key(0xBC01):
|
if 0xBC01 in self.tag:
|
||||||
raise IOError("Windows Media Photo files not yet supported")
|
raise IOError("Windows Media Photo files not yet supported")
|
||||||
|
|
||||||
getscalar = self.tag.getscalar
|
getscalar = self.tag.getscalar
|
||||||
|
@ -658,7 +658,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
# build tile descriptors
|
# build tile descriptors
|
||||||
x = y = l = 0
|
x = y = l = 0
|
||||||
self.tile = []
|
self.tile = []
|
||||||
if self.tag.has_key(STRIPOFFSETS):
|
if STRIPOFFSETS in self.tag:
|
||||||
# striped image
|
# striped image
|
||||||
h = getscalar(ROWSPERSTRIP, ysize)
|
h = getscalar(ROWSPERSTRIP, ysize)
|
||||||
w = self.size[0]
|
w = self.size[0]
|
||||||
|
@ -675,7 +675,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
x = y = 0
|
x = y = 0
|
||||||
l = l + 1
|
l = l + 1
|
||||||
a = None
|
a = None
|
||||||
elif self.tag.has_key(TILEOFFSETS):
|
elif TILEOFFSETS in self.tag:
|
||||||
# tiled image
|
# tiled image
|
||||||
w = getscalar(322)
|
w = getscalar(322)
|
||||||
h = getscalar(323)
|
h = getscalar(323)
|
||||||
|
@ -769,28 +769,28 @@ def _save(im, fp, filename):
|
||||||
if hasattr(im, 'tag'):
|
if hasattr(im, 'tag'):
|
||||||
# preserve tags from original TIFF image file
|
# preserve tags from original TIFF image file
|
||||||
for key in (RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION):
|
for key in (RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION):
|
||||||
if im.tag.tagdata.has_key(key):
|
if key in im.tag.tagdata:
|
||||||
ifd[key] = im.tag.tagdata.get(key)
|
ifd[key] = im.tag.tagdata.get(key)
|
||||||
# preserve some more tags from original TIFF image file
|
# preserve some more tags from original TIFF image file
|
||||||
# -- 2008-06-06 Florian Hoech
|
# -- 2008-06-06 Florian Hoech
|
||||||
ifd.tagtype = im.tag.tagtype
|
ifd.tagtype = im.tag.tagtype
|
||||||
for key in (IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK, XMP):
|
for key in (IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK, XMP):
|
||||||
if im.tag.has_key(key):
|
if key in im.tag:
|
||||||
ifd[key] = im.tag[key]
|
ifd[key] = im.tag[key]
|
||||||
# preserve ICC profile (should also work when saving other formats
|
# preserve ICC profile (should also work when saving other formats
|
||||||
# which support profiles as TIFF) -- 2008-06-06 Florian Hoech
|
# which support profiles as TIFF) -- 2008-06-06 Florian Hoech
|
||||||
if im.info.has_key("icc_profile"):
|
if "icc_profile" in im.info:
|
||||||
ifd[ICCPROFILE] = im.info["icc_profile"]
|
ifd[ICCPROFILE] = im.info["icc_profile"]
|
||||||
if im.encoderinfo.has_key("description"):
|
if "description" in im.encoderinfo:
|
||||||
ifd[IMAGEDESCRIPTION] = im.encoderinfo["description"]
|
ifd[IMAGEDESCRIPTION] = im.encoderinfo["description"]
|
||||||
if im.encoderinfo.has_key("resolution"):
|
if "resolution" in im.encoderinfo:
|
||||||
ifd[X_RESOLUTION] = ifd[Y_RESOLUTION] \
|
ifd[X_RESOLUTION] = ifd[Y_RESOLUTION] \
|
||||||
= _cvt_res(im.encoderinfo["resolution"])
|
= _cvt_res(im.encoderinfo["resolution"])
|
||||||
if im.encoderinfo.has_key("x resolution"):
|
if "x resolution" in im.encoderinfo:
|
||||||
ifd[X_RESOLUTION] = _cvt_res(im.encoderinfo["x resolution"])
|
ifd[X_RESOLUTION] = _cvt_res(im.encoderinfo["x resolution"])
|
||||||
if im.encoderinfo.has_key("y resolution"):
|
if "y resolution" in im.encoderinfo:
|
||||||
ifd[Y_RESOLUTION] = _cvt_res(im.encoderinfo["y resolution"])
|
ifd[Y_RESOLUTION] = _cvt_res(im.encoderinfo["y resolution"])
|
||||||
if im.encoderinfo.has_key("resolution unit"):
|
if "resolution unit" in im.encoderinfo:
|
||||||
unit = im.encoderinfo["resolution unit"]
|
unit = im.encoderinfo["resolution unit"]
|
||||||
if unit == "inch":
|
if unit == "inch":
|
||||||
ifd[RESOLUTION_UNIT] = 2
|
ifd[RESOLUTION_UNIT] = 2
|
||||||
|
@ -798,13 +798,13 @@ def _save(im, fp, filename):
|
||||||
ifd[RESOLUTION_UNIT] = 3
|
ifd[RESOLUTION_UNIT] = 3
|
||||||
else:
|
else:
|
||||||
ifd[RESOLUTION_UNIT] = 1
|
ifd[RESOLUTION_UNIT] = 1
|
||||||
if im.encoderinfo.has_key("software"):
|
if "software" in im.encoderinfo:
|
||||||
ifd[SOFTWARE] = im.encoderinfo["software"]
|
ifd[SOFTWARE] = im.encoderinfo["software"]
|
||||||
if im.encoderinfo.has_key("date time"):
|
if "date time" in im.encoderinfo:
|
||||||
ifd[DATE_TIME] = im.encoderinfo["date time"]
|
ifd[DATE_TIME] = im.encoderinfo["date time"]
|
||||||
if im.encoderinfo.has_key("artist"):
|
if "artist" in im.encoderinfo:
|
||||||
ifd[ARTIST] = im.encoderinfo["artist"]
|
ifd[ARTIST] = im.encoderinfo["artist"]
|
||||||
if im.encoderinfo.has_key("copyright"):
|
if "copyright" in im.encoderinfo:
|
||||||
ifd[COPYRIGHT] = im.encoderinfo["copyright"]
|
ifd[COPYRIGHT] = im.encoderinfo["copyright"]
|
||||||
|
|
||||||
dpi = im.encoderinfo.get("dpi")
|
dpi = im.encoderinfo.get("dpi")
|
||||||
|
@ -843,7 +843,7 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
|
|
||||||
# -- helper for multi-page save --
|
# -- helper for multi-page save --
|
||||||
if im.encoderinfo.has_key("_debug_multipage"):
|
if "_debug_multipage" in im.encoderinfo:
|
||||||
#just to access o32 and o16 (using correct byte order)
|
#just to access o32 and o16 (using correct byte order)
|
||||||
im._debug_multipage = ifd
|
im._debug_multipage = ifd
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ class SaneDev:
|
||||||
def __setattr__(self, key, value):
|
def __setattr__(self, key, value):
|
||||||
dev=self.__dict__['dev']
|
dev=self.__dict__['dev']
|
||||||
optdict=self.__dict__['opt']
|
optdict=self.__dict__['opt']
|
||||||
if not optdict.has_key(key):
|
if key not in optdict:
|
||||||
self.__dict__[key]=value ; return
|
self.__dict__[key]=value ; return
|
||||||
opt=optdict[key]
|
opt=optdict[key]
|
||||||
if opt.type==TYPE_GROUP:
|
if opt.type==TYPE_GROUP:
|
||||||
|
@ -186,10 +186,10 @@ class SaneDev:
|
||||||
dev=self.__dict__['dev']
|
dev=self.__dict__['dev']
|
||||||
optdict=self.__dict__['opt']
|
optdict=self.__dict__['opt']
|
||||||
if key=='optlist':
|
if key=='optlist':
|
||||||
return self.opt.keys()
|
return list(self.opt.keys())
|
||||||
if key=='area':
|
if key=='area':
|
||||||
return (self.tl_x, self.tl_y),(self.br_x, self.br_y)
|
return (self.tl_x, self.tl_y),(self.br_x, self.br_y)
|
||||||
if not optdict.has_key(key):
|
if key not in optdict:
|
||||||
raise AttributeError('No such attribute: '+key)
|
raise AttributeError('No such attribute: '+key)
|
||||||
opt=optdict[key]
|
opt=optdict[key]
|
||||||
if opt.type==TYPE_BUTTON:
|
if opt.type==TYPE_BUTTON:
|
||||||
|
|
|
@ -58,7 +58,7 @@ for o, a in opt:
|
||||||
id.sort()
|
id.sort()
|
||||||
print "Supported formats (* indicates output format):"
|
print "Supported formats (* indicates output format):"
|
||||||
for i in id:
|
for i in id:
|
||||||
if Image.SAVE.has_key(i):
|
if i in Image.SAVE:
|
||||||
print i+"*",
|
print i+"*",
|
||||||
else:
|
else:
|
||||||
print i,
|
print i,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user