mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 10:16:17 +03:00
py3k: map and filter to list comprehensions
What's really going on is that map() and filter() return iterators in py3k. I've just gone ahead and turned them all into list comprehensions, because I find them much easier to read.
This commit is contained in:
parent
e514912378
commit
fc035814bd
|
@ -69,8 +69,8 @@ def bdf_char(f):
|
|||
bitmap.append(s[:-1])
|
||||
bitmap = "".join(bitmap)
|
||||
|
||||
[x, y, l, d] = map(int, props["BBX"].split())
|
||||
[dx, dy] = map(int, props["DWIDTH"].split())
|
||||
[x, y, l, d] = [int(s) for s in props["BBX"].split()]
|
||||
[dx, dy] = [int(s) for s in props["DWIDTH"].split()]
|
||||
|
||||
bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y)
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
|||
# Note: The DSC spec says that BoundingBox
|
||||
# fields should be integers, but some drivers
|
||||
# put floating point values there anyway.
|
||||
box = map(int, map(float, v.split()))
|
||||
box = [int(float(s)) for s in v.split()]
|
||||
self.size = box[2] - box[0], box[3] - box[1]
|
||||
self.tile = [("eps", (0,0) + self.size, offset,
|
||||
(length, box))]
|
||||
|
|
|
@ -63,7 +63,7 @@ class FliImageFile(ImageFile.ImageFile):
|
|||
self.info["duration"] = duration
|
||||
|
||||
# look for palette
|
||||
palette = map(lambda a: (a,a,a), range(256))
|
||||
palette = [(a,a,a) for a in range(256)]
|
||||
|
||||
s = self.fp.read(16)
|
||||
|
||||
|
@ -82,7 +82,7 @@ class FliImageFile(ImageFile.ImageFile):
|
|||
elif i16(s[4:6]) == 4:
|
||||
self._palette(palette, 0)
|
||||
|
||||
palette = map(lambda (r,g,b): chr(r)+chr(g)+chr(b), palette)
|
||||
palette = [chr(r)+chr(g)+chr(b) for (r,g,b) in palette]
|
||||
self.palette = ImagePalette.raw("RGB", "".join(palette))
|
||||
|
||||
# set things up to decode first frame
|
||||
|
|
|
@ -105,7 +105,7 @@ class GimpGradientFile(GradientFile):
|
|||
for i in range(count):
|
||||
|
||||
s = fp.readline().split()
|
||||
w = map(float, s[:11])
|
||||
w = [float(x) for x in s[:11]]
|
||||
|
||||
x0, x1 = w[0], w[2]
|
||||
xm = w[1]
|
||||
|
|
|
@ -25,7 +25,7 @@ class GimpPaletteFile:
|
|||
|
||||
def __init__(self, fp):
|
||||
|
||||
self.palette = map(lambda i: chr(i)*3, range(256))
|
||||
self.palette = [chr(i)*3 for i in range(256)]
|
||||
|
||||
if fp.readline()[:12] != "GIMP Palette":
|
||||
raise SyntaxError("not a GIMP palette file")
|
||||
|
|
|
@ -209,7 +209,7 @@ class ImImageFile(ImageFile.ImageFile):
|
|||
if self.mode == "L" or self.mode == "LA":
|
||||
if greyscale:
|
||||
if not linear:
|
||||
self.lut = map(ord, palette[:256])
|
||||
self.lut = [ord(c) for c in palette[:256]]
|
||||
else:
|
||||
if self.mode == "L":
|
||||
self.mode = self.rawmode = "P"
|
||||
|
@ -218,7 +218,7 @@ class ImImageFile(ImageFile.ImageFile):
|
|||
self.palette = ImagePalette.raw("RGB;L", palette)
|
||||
elif self.mode == "RGB":
|
||||
if not greyscale or not linear:
|
||||
self.lut = map(ord, palette)
|
||||
self.lut = [ord(c) for c in palette]
|
||||
|
||||
self.frame = 0
|
||||
|
||||
|
|
|
@ -930,7 +930,7 @@ class Image:
|
|||
|
||||
self.load()
|
||||
try:
|
||||
return map(ord, self.im.getpalette())
|
||||
return [ord(c) for c in self.im.getpalette()]
|
||||
except ValueError:
|
||||
return None # no palette
|
||||
|
||||
|
@ -959,7 +959,7 @@ class Image:
|
|||
|
||||
self.load()
|
||||
x, y = self.im.getprojection()
|
||||
return map(ord, x), map(ord, y)
|
||||
return [ord(c) for c in x], [ord(c) for c in y]
|
||||
|
||||
##
|
||||
# Returns a histogram for the image. The histogram is returned as
|
||||
|
@ -1129,7 +1129,7 @@ class Image:
|
|||
scale, offset = _getscaleoffset(lut)
|
||||
return self._new(self.im.point_transform(scale, offset))
|
||||
# for other modes, convert the function to a table
|
||||
lut = map(lut, range(256)) * self.im.bands
|
||||
lut = [lut(i) for i in range(256)] * self.im.bands
|
||||
|
||||
if self.mode == "F":
|
||||
# FIXME: _imaging returns a confusing error message for this case
|
||||
|
|
|
@ -209,7 +209,7 @@ def equalize(image, mask=None):
|
|||
h = image.histogram(mask)
|
||||
lut = []
|
||||
for b in range(0, len(h), 256):
|
||||
histo = filter(None, h[b:b+256])
|
||||
histo = [_f for _f in h[b:b+256] if _f]
|
||||
if len(histo) <= 1:
|
||||
lut.extend(range(256))
|
||||
else:
|
||||
|
|
|
@ -59,7 +59,7 @@ class ImagePalette:
|
|||
except KeyError:
|
||||
# allocate new color slot
|
||||
if Image.isStringType(self.palette):
|
||||
self.palette = map(int, self.palette)
|
||||
self.palette = [int(x) for x in self.palette]
|
||||
index = len(self.colors)
|
||||
if index >= 256:
|
||||
raise ValueError("cannot allocate more than 256 colors")
|
||||
|
|
|
@ -307,7 +307,7 @@ class OleFileIO:
|
|||
if ix == -2 or ix == -1: # ix == 0xFFFFFFFEL or ix == 0xFFFFFFFFL:
|
||||
break
|
||||
s = self.getsect(ix)
|
||||
fat = fat + map(lambda i, s=s: i32(s, i), range(0, len(s), 4))
|
||||
fat = fat + [i32(s, i) for i in range(0, len(s), 4)]
|
||||
self.fat = fat
|
||||
|
||||
def loadminifat(self):
|
||||
|
@ -316,7 +316,7 @@ class OleFileIO:
|
|||
|
||||
s = self._open(self.minifatsect).read()
|
||||
|
||||
self.minifat = map(lambda i, s=s: i32(s, i), range(0, len(s), 4))
|
||||
self.minifat = [i32(s, i) for i in range(0, len(s), 4)]
|
||||
|
||||
def getsect(self, sect):
|
||||
# Read given sector
|
||||
|
|
|
@ -22,7 +22,7 @@ class PaletteFile:
|
|||
|
||||
def __init__(self, fp):
|
||||
|
||||
self.palette = map(lambda i: (i, i, i), range(256))
|
||||
self.palette = [(i, i, i) for i in range(256)]
|
||||
|
||||
while 1:
|
||||
|
||||
|
@ -35,7 +35,7 @@ class PaletteFile:
|
|||
if len(s) > 100:
|
||||
raise SyntaxError("bad palette file")
|
||||
|
||||
v = map(int, s.split())
|
||||
v = [int(x) for x in s.split()]
|
||||
try:
|
||||
[i, r, g, b] = v
|
||||
except ValueError:
|
||||
|
|
|
@ -701,7 +701,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
|||
# fixup palette descriptor
|
||||
|
||||
if self.mode == "P":
|
||||
palette = map(lambda a: chr(a / 256), self.tag[COLORMAP])
|
||||
palette = [chr(a / 256) for a in self.tag[COLORMAP]]
|
||||
self.palette = ImagePalette.raw("RGB;L", "".join(palette))
|
||||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
@ -823,7 +823,7 @@ def _save(im, fp, filename):
|
|||
|
||||
if im.mode == "P":
|
||||
lut = im.im.getpalette("RGB", "RGB;L")
|
||||
ifd[COLORMAP] = tuple(map(lambda v: ord(v) * 256, lut))
|
||||
ifd[COLORMAP] = tuple(ord(v) * 256 for v in lut)
|
||||
|
||||
# data orientation
|
||||
stride = len(bits) * ((im.size[0]*bits[0]+7)/8)
|
||||
|
|
Loading…
Reference in New Issue
Block a user