mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
commit
86616dfc0a
|
@ -248,7 +248,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
# Note: The DSC spec says that BoundingBox
|
# Note: The DSC spec says that BoundingBox
|
||||||
# fields should be integers, but some drivers
|
# fields should be integers, but some drivers
|
||||||
# put floating point values there anyway.
|
# put floating point values there anyway.
|
||||||
box = [int(float(s)) for s in v.split()]
|
box = [int(float(i)) for i in v.split()]
|
||||||
self.size = box[2] - box[0], box[3] - box[1]
|
self.size = box[2] - box[0], box[3] - box[1]
|
||||||
self.tile = [("eps", (0, 0) + self.size, offset,
|
self.tile = [("eps", (0, 0) + self.size, offset,
|
||||||
(length, box))]
|
(length, box))]
|
||||||
|
@ -288,7 +288,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
if s[:11] == "%ImageData:":
|
if s[:11] == "%ImageData:":
|
||||||
# Encoded bitmapped image.
|
# Encoded bitmapped image.
|
||||||
[x, y, bi, mo, z3, z4, en, id] = s[11:].split(None, 7)
|
x, y, bi, mo = s[11:].split(None, 7)[:4]
|
||||||
|
|
||||||
if int(bi) != 8:
|
if int(bi) != 8:
|
||||||
break
|
break
|
||||||
|
|
|
@ -17,11 +17,6 @@
|
||||||
import os
|
import os
|
||||||
from PIL import Image, _binary
|
from PIL import Image, _binary
|
||||||
|
|
||||||
try:
|
|
||||||
import zlib
|
|
||||||
except ImportError:
|
|
||||||
zlib = None
|
|
||||||
|
|
||||||
WIDTH = 800
|
WIDTH = 800
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +78,8 @@ class FontFile:
|
||||||
glyph = self[i]
|
glyph = self[i]
|
||||||
if glyph:
|
if glyph:
|
||||||
d, dst, src, im = glyph
|
d, dst, src, im = glyph
|
||||||
xx, yy = src[2] - src[0], src[3] - src[1]
|
xx = src[2] - src[0]
|
||||||
|
# yy = src[3] - src[1]
|
||||||
x0, y0 = x, y
|
x0, y0 = x, y
|
||||||
x = x + xx
|
x = x + xx
|
||||||
if x > WIDTH:
|
if x > WIDTH:
|
||||||
|
|
|
@ -39,8 +39,8 @@ class GbrImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
width = i32(self.fp.read(4))
|
width = i32(self.fp.read(4))
|
||||||
height = i32(self.fp.read(4))
|
height = i32(self.fp.read(4))
|
||||||
bytes = i32(self.fp.read(4))
|
color_depth = i32(self.fp.read(4))
|
||||||
if width <= 0 or height <= 0 or bytes != 1:
|
if width <= 0 or height <= 0 or color_depth != 1:
|
||||||
raise SyntaxError("not a GIMP brush")
|
raise SyntaxError("not a GIMP brush")
|
||||||
|
|
||||||
comment = self.fp.read(header_size - 20)[:-1]
|
comment = self.fp.read(header_size - 20)[:-1]
|
||||||
|
|
|
@ -94,7 +94,7 @@ def read_32(fobj, start_length, size):
|
||||||
|
|
||||||
def read_mk(fobj, start_length, size):
|
def read_mk(fobj, start_length, size):
|
||||||
# Alpha masks seem to be uncompressed
|
# Alpha masks seem to be uncompressed
|
||||||
(start, length) = start_length
|
start = start_length[0]
|
||||||
fobj.seek(start)
|
fobj.seek(start)
|
||||||
pixel_size = (size[0] * size[2], size[1] * size[2])
|
pixel_size = (size[0] * size[2], size[1] * size[2])
|
||||||
sizesq = pixel_size[0] * pixel_size[1]
|
sizesq = pixel_size[0] * pixel_size[1]
|
||||||
|
|
|
@ -313,7 +313,7 @@ SAVE = {
|
||||||
def _save(im, fp, filename, check=0):
|
def _save(im, fp, filename, check=0):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
type, rawmode = SAVE[im.mode]
|
image_type, rawmode = SAVE[im.mode]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError("Cannot save %s images as IM" % im.mode)
|
raise ValueError("Cannot save %s images as IM" % im.mode)
|
||||||
|
|
||||||
|
@ -325,7 +325,7 @@ def _save(im, fp, filename, check=0):
|
||||||
if check:
|
if check:
|
||||||
return check
|
return check
|
||||||
|
|
||||||
fp.write(("Image type: %s image\r\n" % type).encode('ascii'))
|
fp.write(("Image type: %s image\r\n" % image_type).encode('ascii'))
|
||||||
if filename:
|
if filename:
|
||||||
fp.write(("Name: %s\r\n" % filename).encode('ascii'))
|
fp.write(("Name: %s\r\n" % filename).encode('ascii'))
|
||||||
fp.write(("Image size (x*y): %d*%d\r\n" % im.size).encode('ascii'))
|
fp.write(("Image size (x*y): %d*%d\r\n" % im.size).encode('ascii'))
|
||||||
|
|
|
@ -322,6 +322,7 @@ class Parser:
|
||||||
image = None
|
image = None
|
||||||
data = None
|
data = None
|
||||||
decoder = None
|
decoder = None
|
||||||
|
offset = 0
|
||||||
finished = 0
|
finished = 0
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
# See the README file for information on usage and redistribution.
|
# See the README file for information on usage and redistribution.
|
||||||
#
|
#
|
||||||
|
|
||||||
from functools import reduce
|
import functools
|
||||||
|
|
||||||
|
|
||||||
class Filter(object):
|
class Filter(object):
|
||||||
|
@ -43,7 +43,7 @@ class Kernel(Filter):
|
||||||
def __init__(self, size, kernel, scale=None, offset=0):
|
def __init__(self, size, kernel, scale=None, offset=0):
|
||||||
if scale is None:
|
if scale is None:
|
||||||
# default scale is sum of kernel
|
# default scale is sum of kernel
|
||||||
scale = reduce(lambda a, b: a+b, kernel)
|
scale = functools.reduce(lambda a, b: a+b, kernel)
|
||||||
if size[0] * size[1] != len(kernel):
|
if size[0] * size[1] != len(kernel):
|
||||||
raise ValueError("not enough coefficients in kernel")
|
raise ValueError("not enough coefficients in kernel")
|
||||||
self.filterargs = size, scale, offset, kernel
|
self.filterargs = size, scale, offset, kernel
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL._util import isStringType
|
from PIL._util import isStringType
|
||||||
import operator
|
import operator
|
||||||
from functools import reduce
|
import functools
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -213,7 +213,7 @@ def equalize(image, mask=None):
|
||||||
if len(histo) <= 1:
|
if len(histo) <= 1:
|
||||||
lut.extend(list(range(256)))
|
lut.extend(list(range(256)))
|
||||||
else:
|
else:
|
||||||
step = (reduce(operator.add, histo) - histo[-1]) // 255
|
step = (functools.reduce(operator.add, histo) - histo[-1]) // 255
|
||||||
if not step:
|
if not step:
|
||||||
lut.extend(list(range(256)))
|
lut.extend(list(range(256)))
|
||||||
else:
|
else:
|
||||||
|
@ -233,7 +233,6 @@ def expand(image, border=0, fill=0):
|
||||||
:param fill: Pixel fill value (a color value). Default is 0 (black).
|
:param fill: Pixel fill value (a color value). Default is 0 (black).
|
||||||
:return: An image.
|
:return: An image.
|
||||||
"""
|
"""
|
||||||
"Add border to image"
|
|
||||||
left, top, right, bottom = _border(border)
|
left, top, right, bottom = _border(border)
|
||||||
width = left + image.size[0] + right
|
width = left + image.size[0] + right
|
||||||
height = top + image.size[1] + bottom
|
height = top + image.size[1] + bottom
|
||||||
|
|
|
@ -225,8 +225,8 @@ def load(filename):
|
||||||
p = PaletteFile.PaletteFile(fp)
|
p = PaletteFile.PaletteFile(fp)
|
||||||
lut = p.getpalette()
|
lut = p.getpalette()
|
||||||
except (SyntaxError, ValueError):
|
except (SyntaxError, ValueError):
|
||||||
import traceback
|
#import traceback
|
||||||
traceback.print_exc()
|
#traceback.print_exc()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not lut:
|
if not lut:
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import operator
|
import operator
|
||||||
from functools import reduce
|
import functools
|
||||||
|
|
||||||
|
|
||||||
class Stat:
|
class Stat:
|
||||||
|
@ -71,7 +71,7 @@ class Stat:
|
||||||
|
|
||||||
v = []
|
v = []
|
||||||
for i in range(0, len(self.h), 256):
|
for i in range(0, len(self.h), 256):
|
||||||
v.append(reduce(operator.add, self.h[i:i+256]))
|
v.append(functools.reduce(operator.add, self.h[i:i+256]))
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def _getsum(self):
|
def _getsum(self):
|
||||||
|
@ -79,10 +79,10 @@ class Stat:
|
||||||
|
|
||||||
v = []
|
v = []
|
||||||
for i in range(0, len(self.h), 256):
|
for i in range(0, len(self.h), 256):
|
||||||
sum = 0.0
|
layerSum = 0.0
|
||||||
for j in range(256):
|
for j in range(256):
|
||||||
sum += j * self.h[i + j]
|
layerSum += j * self.h[i + j]
|
||||||
v.append(sum)
|
v.append(layerSum)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def _getsum2(self):
|
def _getsum2(self):
|
||||||
|
|
|
@ -222,7 +222,7 @@ def getiptcinfo(im):
|
||||||
offset += 2
|
offset += 2
|
||||||
# resource name (usually empty)
|
# resource name (usually empty)
|
||||||
name_len = i8(app[offset])
|
name_len = i8(app[offset])
|
||||||
name = app[offset+1:offset+1+name_len]
|
# name = app[offset+1:offset+1+name_len]
|
||||||
offset = 1 + offset + name_len
|
offset = 1 + offset + name_len
|
||||||
if offset & 1:
|
if offset & 1:
|
||||||
offset += 1
|
offset += 1
|
||||||
|
|
|
@ -454,13 +454,13 @@ def _getmp(self):
|
||||||
data = self.info["mp"]
|
data = self.info["mp"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
file = io.BytesIO(data)
|
file_contents = io.BytesIO(data)
|
||||||
head = file.read(8)
|
head = file_contents.read(8)
|
||||||
endianness = '>' if head[:4] == b'\x4d\x4d\x00\x2a' else '<'
|
endianness = '>' if head[:4] == b'\x4d\x4d\x00\x2a' else '<'
|
||||||
mp = {}
|
mp = {}
|
||||||
# process dictionary
|
# process dictionary
|
||||||
info = TiffImagePlugin.ImageFileDirectory(head)
|
info = TiffImagePlugin.ImageFileDirectory(head)
|
||||||
info.load(file)
|
info.load(file_contents)
|
||||||
for key, value in info.items():
|
for key, value in info.items():
|
||||||
mp[key] = _fixup(value)
|
mp[key] = _fixup(value)
|
||||||
# it's an error not to have a number of images
|
# it's an error not to have a number of images
|
||||||
|
|
|
@ -21,7 +21,7 @@ __version__ = "0.1"
|
||||||
|
|
||||||
|
|
||||||
from PIL import Image, TiffImagePlugin
|
from PIL import Image, TiffImagePlugin
|
||||||
from PIL.OleFileIO import *
|
from PIL.OleFileIO import MAGIC, OleFileIO
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -54,9 +54,9 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
|
||||||
# best way to identify MIC files, but what the... ;-)
|
# best way to identify MIC files, but what the... ;-)
|
||||||
|
|
||||||
self.images = []
|
self.images = []
|
||||||
for file in self.ole.listdir():
|
for path in self.ole.listdir():
|
||||||
if file[1:] and file[0][-4:] == ".ACI" and file[1] == "Image":
|
if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image":
|
||||||
self.images.append(file)
|
self.images.append(path)
|
||||||
|
|
||||||
# if we didn't find any images, this is probably not
|
# if we didn't find any images, this is probably not
|
||||||
# an MIC file.
|
# an MIC file.
|
||||||
|
|
|
@ -49,10 +49,10 @@ class MspImageFile(ImageFile.ImageFile):
|
||||||
raise SyntaxError("not an MSP file")
|
raise SyntaxError("not an MSP file")
|
||||||
|
|
||||||
# Header checksum
|
# Header checksum
|
||||||
sum = 0
|
checksum = 0
|
||||||
for i in range(0, 32, 2):
|
for i in range(0, 32, 2):
|
||||||
sum = sum ^ i16(s[i:i+2])
|
checksum = checksum ^ i16(s[i:i+2])
|
||||||
if sum != 0:
|
if checksum != 0:
|
||||||
raise SyntaxError("bad MSP checksum")
|
raise SyntaxError("bad MSP checksum")
|
||||||
|
|
||||||
self.mode = "1"
|
self.mode = "1"
|
||||||
|
@ -83,10 +83,10 @@ def _save(im, fp, filename):
|
||||||
header[6], header[7] = 1, 1
|
header[6], header[7] = 1, 1
|
||||||
header[8], header[9] = im.size
|
header[8], header[9] = im.size
|
||||||
|
|
||||||
sum = 0
|
checksum = 0
|
||||||
for h in header:
|
for h in header:
|
||||||
sum = sum ^ h
|
checksum = checksum ^ h
|
||||||
header[12] = sum # FIXME: is this the right field?
|
header[12] = checksum # FIXME: is this the right field?
|
||||||
|
|
||||||
# header
|
# header
|
||||||
for h in header:
|
for h in header:
|
||||||
|
|
|
@ -204,7 +204,7 @@ class PcfFontFile(FontFile.FontFile):
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
bitmapSizes.append(i32(fp.read(4)))
|
bitmapSizes.append(i32(fp.read(4)))
|
||||||
|
|
||||||
byteorder = format & 4 # non-zero => MSB
|
# byteorder = format & 4 # non-zero => MSB
|
||||||
bitorder = format & 8 # non-zero => MSB
|
bitorder = format & 8 # non-zero => MSB
|
||||||
padindex = format & 3
|
padindex = format & 3
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ class _PyAccessI16_L(PyAccess):
|
||||||
pixel = self.pixels[y][x]
|
pixel = self.pixels[y][x]
|
||||||
try:
|
try:
|
||||||
color = min(color, 65535)
|
color = min(color, 65535)
|
||||||
except:
|
except TypeError:
|
||||||
color = min(color[0], 65535)
|
color = min(color[0], 65535)
|
||||||
|
|
||||||
pixel.l = color & 0xFF
|
pixel.l = color & 0xFF
|
||||||
|
|
|
@ -48,7 +48,7 @@ def isInt(f):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
except:
|
except ValueError:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
iforms = [1, 3, -11, -12, -21, -22]
|
iforms = [1, 3, -11, -12, -21, -22]
|
||||||
|
@ -173,11 +173,11 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# returns a byte image after rescaling to 0..255
|
# returns a byte image after rescaling to 0..255
|
||||||
def convert2byte(self, depth=255):
|
def convert2byte(self, depth=255):
|
||||||
(min, max) = self.getextrema()
|
(minimum, maximum) = self.getextrema()
|
||||||
m = 1
|
m = 1
|
||||||
if max != min:
|
if maximum != minimum:
|
||||||
m = depth / (max-min)
|
m = depth / (maximum-minimum)
|
||||||
b = -m * min
|
b = -m * minimum
|
||||||
return self.point(lambda i, m=m, b=b: i * m + b).convert("L")
|
return self.point(lambda i, m=m, b=b: i * m + b).convert("L")
|
||||||
|
|
||||||
# returns a ImageTk.PhotoImage object, after rescaling to 0..255
|
# returns a ImageTk.PhotoImage object, after rescaling to 0..255
|
||||||
|
@ -271,7 +271,7 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
def _save_spider(im, fp, filename):
|
def _save_spider(im, fp, filename):
|
||||||
# get the filename extension and register it with Image
|
# get the filename extension and register it with Image
|
||||||
fn, ext = os.path.splitext(filename)
|
ext = os.path.splitext(filename)[1]
|
||||||
Image.register_extension("SPIDER", ext)
|
Image.register_extension("SPIDER", ext)
|
||||||
_save(im, fp, filename)
|
_save(im, fp, filename)
|
||||||
|
|
||||||
|
|
|
@ -731,8 +731,8 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# (self._compression, (extents tuple),
|
# (self._compression, (extents tuple),
|
||||||
# 0, (rawmode, self._compression, fp))
|
# 0, (rawmode, self._compression, fp))
|
||||||
ignored, extents, ignored_2, args = self.tile[0]
|
extents = self.tile[0][1]
|
||||||
args = args + (self.ifd.offset,)
|
args = self.tile[0][3] + (self.ifd.offset,)
|
||||||
decoder = Image._getdecoder(self.mode, 'libtiff', args,
|
decoder = Image._getdecoder(self.mode, 'libtiff', args,
|
||||||
self.decoderconfig)
|
self.decoderconfig)
|
||||||
try:
|
try:
|
||||||
|
@ -978,7 +978,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
# fixup palette descriptor
|
# fixup palette descriptor
|
||||||
|
|
||||||
if self.mode == "P":
|
if self.mode == "P":
|
||||||
palette = [o8(a // 256) for a in self.tag[COLORMAP]]
|
palette = [o8(b // 256) for b in self.tag[COLORMAP]]
|
||||||
self.palette = ImagePalette.raw("RGB;L", b"".join(palette))
|
self.palette = ImagePalette.raw("RGB;L", b"".join(palette))
|
||||||
#
|
#
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from tkinter import *
|
from tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from Tkinter import *
|
from Tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL
|
||||||
|
|
||||||
from PIL import Image, ImageTk, ImageEnhance
|
from PIL import Image, ImageTk, ImageEnhance
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from tkinter import *
|
from tkinter import Tk, Canvas, NW
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from Tkinter import *
|
from Tkinter import Tk, Canvas, NW
|
||||||
|
|
||||||
from PIL import Image, ImageTk
|
from PIL import Image, ImageTk
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -49,7 +49,7 @@ except getopt.error as v:
|
||||||
print(v)
|
print(v)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
format = None
|
output_format = None
|
||||||
convert = None
|
convert = None
|
||||||
|
|
||||||
options = {}
|
options = {}
|
||||||
|
@ -68,7 +68,7 @@ for o, a in opt:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
elif o == "-c":
|
elif o == "-c":
|
||||||
format = a
|
output_format = a
|
||||||
|
|
||||||
if o == "-g":
|
if o == "-g":
|
||||||
convert = "L"
|
convert = "L"
|
||||||
|
@ -90,8 +90,8 @@ try:
|
||||||
if convert and im.mode != convert:
|
if convert and im.mode != convert:
|
||||||
im.draft(convert, im.size)
|
im.draft(convert, im.size)
|
||||||
im = im.convert(convert)
|
im = im.convert(convert)
|
||||||
if format:
|
if output_format:
|
||||||
im.save(argv[1], format, **options)
|
im.save(argv[1], output_format, **options)
|
||||||
else:
|
else:
|
||||||
im.save(argv[1], **options)
|
im.save(argv[1], **options)
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import site
|
|
||||||
import getopt
|
import getopt
|
||||||
import glob
|
import glob
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -24,8 +24,8 @@ from PIL import PSDraw
|
||||||
letter = (1.0*72, 1.0*72, 7.5*72, 10.0*72)
|
letter = (1.0*72, 1.0*72, 7.5*72, 10.0*72)
|
||||||
|
|
||||||
|
|
||||||
def description(file, image):
|
def description(filepath, image):
|
||||||
title = os.path.splitext(os.path.split(file)[1])[0]
|
title = os.path.splitext(os.path.split(filepath)[1])[0]
|
||||||
format = " (%dx%d "
|
format = " (%dx%d "
|
||||||
if image.format:
|
if image.format:
|
||||||
format = " (" + image.format + " %dx%d "
|
format = " (" + image.format + " %dx%d "
|
||||||
|
@ -65,12 +65,12 @@ for o, a in opt:
|
||||||
# printer channel
|
# printer channel
|
||||||
printer = "lpr -P%s" % a
|
printer = "lpr -P%s" % a
|
||||||
|
|
||||||
for file in argv:
|
for filepath in argv:
|
||||||
try:
|
try:
|
||||||
|
|
||||||
im = Image.open(file)
|
im = Image.open(filepath)
|
||||||
|
|
||||||
title = description(file, im)
|
title = description(filepath, im)
|
||||||
|
|
||||||
if monochrome and im.mode not in ["1", "L"]:
|
if monochrome and im.mode not in ["1", "L"]:
|
||||||
im.draft("L", im.size)
|
im.draft("L", im.size)
|
||||||
|
|
|
@ -32,7 +32,7 @@ class UI(Frame):
|
||||||
self.canvas.pack()
|
self.canvas.pack()
|
||||||
|
|
||||||
scale = Scale(self, orient=HORIZONTAL, from_=0, to=255,
|
scale = Scale(self, orient=HORIZONTAL, from_=0, to=255,
|
||||||
resolution=1, command=self.update, length=256)
|
resolution=1, command=self.update_scale, length=256)
|
||||||
scale.set(value)
|
scale.set(value)
|
||||||
scale.bind("<ButtonRelease-1>", self.redraw)
|
scale.bind("<ButtonRelease-1>", self.redraw)
|
||||||
scale.pack()
|
scale.pack()
|
||||||
|
@ -41,7 +41,7 @@ class UI(Frame):
|
||||||
# be too slow on some platforms)
|
# be too slow on some platforms)
|
||||||
# self.redraw()
|
# self.redraw()
|
||||||
|
|
||||||
def update(self, value):
|
def update_scale(self, value):
|
||||||
self.value = eval(value)
|
self.value = eval(value)
|
||||||
|
|
||||||
self.redraw()
|
self.redraw()
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from tkinter import *
|
from tkinter import Tk, Label
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from Tkinter import *
|
from Tkinter import Tk, Label
|
||||||
|
|
||||||
from PIL import Image, ImageTk
|
from PIL import Image, ImageTk
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ def bench(mode):
|
||||||
get = im.im.getpixel
|
get = im.im.getpixel
|
||||||
xy = 50, 50 # position shouldn't really matter
|
xy = 50, 50 # position shouldn't really matter
|
||||||
t0 = timeit.default_timer()
|
t0 = timeit.default_timer()
|
||||||
for i in range(1000000):
|
for _ in range(1000000):
|
||||||
get(xy)
|
get(xy)
|
||||||
print(mode, timeit.default_timer() - t0, "us")
|
print(mode, timeit.default_timer() - t0, "us")
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class TestJpegLeaks(PillowTestCase):
|
||||||
from resource import setrlimit, RLIMIT_AS, RLIMIT_STACK
|
from resource import setrlimit, RLIMIT_AS, RLIMIT_STACK
|
||||||
setrlimit(RLIMIT_STACK, (stack_size, stack_size))
|
setrlimit(RLIMIT_STACK, (stack_size, stack_size))
|
||||||
setrlimit(RLIMIT_AS, (mem_limit, mem_limit))
|
setrlimit(RLIMIT_AS, (mem_limit, mem_limit))
|
||||||
for count in range(iterations):
|
for _ in range(iterations):
|
||||||
with Image.open(test_file) as im:
|
with Image.open(test_file) as im:
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
@ -29,13 +29,13 @@ class TestJpegLeaks(PillowTestCase):
|
||||||
from resource import setrlimit, RLIMIT_AS, RLIMIT_STACK
|
from resource import setrlimit, RLIMIT_AS, RLIMIT_STACK
|
||||||
setrlimit(RLIMIT_STACK, (stack_size, stack_size))
|
setrlimit(RLIMIT_STACK, (stack_size, stack_size))
|
||||||
setrlimit(RLIMIT_AS, (mem_limit, mem_limit))
|
setrlimit(RLIMIT_AS, (mem_limit, mem_limit))
|
||||||
for count in range(iterations):
|
for _ in range(iterations):
|
||||||
with Image.open(test_file) as im:
|
with Image.open(test_file) as im:
|
||||||
im.load()
|
im.load()
|
||||||
test_output = BytesIO()
|
test_output = BytesIO()
|
||||||
im.save(test_output, "JPEG2000")
|
im.save(test_output, "JPEG2000")
|
||||||
test_output.seek(0)
|
test_output.seek(0)
|
||||||
output = test_output.read()
|
test_output.read()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from helper import unittest, PillowTestCase, hopper
|
from helper import unittest, PillowTestCase, hopper
|
||||||
from PIL import Image
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -102,7 +101,7 @@ post-patch:
|
||||||
qtables = [standard_l_qtable,
|
qtables = [standard_l_qtable,
|
||||||
standard_chrominance_qtable]
|
standard_chrominance_qtable]
|
||||||
|
|
||||||
for count in range(iterations):
|
for _ in range(iterations):
|
||||||
test_output = BytesIO()
|
test_output = BytesIO()
|
||||||
im.save(test_output, "JPEG", qtables=qtables)
|
im.save(test_output, "JPEG", qtables=qtables)
|
||||||
|
|
||||||
|
@ -166,10 +165,11 @@ post patch:
|
||||||
im = hopper('RGB')
|
im = hopper('RGB')
|
||||||
exif = b'12345678'*4096
|
exif = b'12345678'*4096
|
||||||
|
|
||||||
for count in range(iterations):
|
for _ in range(iterations):
|
||||||
test_output = BytesIO()
|
test_output = BytesIO()
|
||||||
im.save(test_output, "JPEG", exif=exif)
|
im.save(test_output, "JPEG", exif=exif)
|
||||||
|
|
||||||
|
def test_base_save(self):
|
||||||
"""
|
"""
|
||||||
base case:
|
base case:
|
||||||
MB
|
MB
|
||||||
|
@ -196,11 +196,9 @@ base case:
|
||||||
0 +----------------------------------------------------------------------->Gi
|
0 +----------------------------------------------------------------------->Gi
|
||||||
0 7.882
|
0 7.882
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_base_save(self):
|
|
||||||
im = hopper('RGB')
|
im = hopper('RGB')
|
||||||
|
|
||||||
for count in range(iterations):
|
for _ in range(iterations):
|
||||||
test_output = BytesIO()
|
test_output = BytesIO()
|
||||||
im.save(test_output, "JPEG")
|
im.save(test_output, "JPEG")
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class TestWebPLeaks(PillowTestCase):
|
||||||
with open(test_file, 'rb') as f:
|
with open(test_file, 'rb') as f:
|
||||||
im_data = f.read()
|
im_data = f.read()
|
||||||
start_mem = self._get_mem_usage()
|
start_mem = self._get_mem_usage()
|
||||||
for count in range(iterations):
|
for _ in range(iterations):
|
||||||
with Image.open(BytesIO(im_data)) as im:
|
with Image.open(BytesIO(im_data)) as im:
|
||||||
im.load()
|
im.load()
|
||||||
mem = (self._get_mem_usage() - start_mem)
|
mem = (self._get_mem_usage() - start_mem)
|
||||||
|
|
|
@ -58,10 +58,10 @@ class TestBmpReference(PillowTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_compare(f):
|
def get_compare(f):
|
||||||
(head, name) = os.path.split(f)
|
name = os.path.split(f)[1]
|
||||||
if name in file_map:
|
if name in file_map:
|
||||||
return os.path.join(base, 'html', file_map[name])
|
return os.path.join(base, 'html', file_map[name])
|
||||||
(name, ext) = os.path.splitext(name)
|
name = os.path.splitext(name)[0]
|
||||||
return os.path.join(base, 'html', "%s.png" % name)
|
return os.path.join(base, 'html', "%s.png" % name)
|
||||||
|
|
||||||
for f in self.get_files('g'):
|
for f in self.get_files('g'):
|
||||||
|
|
|
@ -49,9 +49,9 @@ class TestCffi(PillowTestCase):
|
||||||
self.skipTest("No cffi")
|
self.skipTest("No cffi")
|
||||||
|
|
||||||
def _test_get_access(self, im):
|
def _test_get_access(self, im):
|
||||||
""" Do we get the same thing as the old pixel access """
|
"""Do we get the same thing as the old pixel access
|
||||||
|
|
||||||
""" Using private interfaces, forcing a capi access and
|
Using private interfaces, forcing a capi access and
|
||||||
a pyaccess for the same image"""
|
a pyaccess for the same image"""
|
||||||
caccess = im.im.pixel_access(False)
|
caccess = im.im.pixel_access(False)
|
||||||
access = PyAccess.new(im, False)
|
access = PyAccess.new(im, False)
|
||||||
|
@ -90,9 +90,9 @@ class TestCffi(PillowTestCase):
|
||||||
# self._test_get_access(im)
|
# self._test_get_access(im)
|
||||||
|
|
||||||
def _test_set_access(self, im, color):
|
def _test_set_access(self, im, color):
|
||||||
""" Are we writing the correct bits into the image? """
|
"""Are we writing the correct bits into the image?
|
||||||
|
|
||||||
""" Using private interfaces, forcing a capi access and
|
Using private interfaces, forcing a capi access and
|
||||||
a pyaccess for the same image"""
|
a pyaccess for the same image"""
|
||||||
caccess = im.im.pixel_access(False)
|
caccess = im.im.pixel_access(False)
|
||||||
access = PyAccess.new(im, False)
|
access = PyAccess.new(im, False)
|
||||||
|
|
|
@ -5,14 +5,14 @@ from PIL import Image
|
||||||
# sample ppm stream
|
# sample ppm stream
|
||||||
# created as an export of a palette image from Gimp2.6
|
# created as an export of a palette image from Gimp2.6
|
||||||
# save as...-> hopper.fli, default options.
|
# save as...-> hopper.fli, default options.
|
||||||
file = "Tests/images/hopper.fli"
|
test_file = "Tests/images/hopper.fli"
|
||||||
data = open(file, "rb").read()
|
data = open(test_file, "rb").read()
|
||||||
|
|
||||||
|
|
||||||
class TestFileFli(PillowTestCase):
|
class TestFileFli(PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
im.load()
|
im.load()
|
||||||
self.assertEqual(im.mode, "P")
|
self.assertEqual(im.mode, "P")
|
||||||
self.assertEqual(im.size, (128, 128))
|
self.assertEqual(im.size, (128, 128))
|
||||||
|
|
|
@ -36,9 +36,9 @@ class TestFileGif(PillowTestCase):
|
||||||
|
|
||||||
def test_bilevel(optimize):
|
def test_bilevel(optimize):
|
||||||
im = Image.new("1", (1, 1), 0)
|
im = Image.new("1", (1, 1), 0)
|
||||||
file = BytesIO()
|
test_file = BytesIO()
|
||||||
im.save(file, "GIF", optimize=optimize)
|
im.save(test_file, "GIF", optimize=optimize)
|
||||||
return len(file.getvalue())
|
return len(test_file.getvalue())
|
||||||
|
|
||||||
self.assertEqual(test_grayscale(0), 800)
|
self.assertEqual(test_grayscale(0), 800)
|
||||||
self.assertEqual(test_grayscale(1), 38)
|
self.assertEqual(test_grayscale(1), 38)
|
||||||
|
@ -49,8 +49,8 @@ class TestFileGif(PillowTestCase):
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
im = Image.frombytes("L", (16, 16), bytes(bytearray(range(256))))
|
im = Image.frombytes("L", (16, 16), bytes(bytearray(range(256))))
|
||||||
file = BytesIO()
|
test_file = BytesIO()
|
||||||
im.save(file, "GIF", optimize=True)
|
im.save(test_file, "GIF", optimize=True)
|
||||||
self.assertEqual(im.mode, "L")
|
self.assertEqual(im.mode, "L")
|
||||||
|
|
||||||
def test_roundtrip(self):
|
def test_roundtrip(self):
|
||||||
|
|
|
@ -5,8 +5,8 @@ from PIL import Image
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# sample icon file
|
# sample icon file
|
||||||
file = "Tests/images/pillow.icns"
|
test_file = "Tests/images/pillow.icns"
|
||||||
data = open(file, "rb").read()
|
data = open(test_file, "rb").read()
|
||||||
|
|
||||||
enable_jpeg2k = hasattr(Image.core, 'jp2klib_version')
|
enable_jpeg2k = hasattr(Image.core, 'jp2klib_version')
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class TestFileIcns(PillowTestCase):
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
# Loading this icon by default should result in the largest size
|
# Loading this icon by default should result in the largest size
|
||||||
# (512x512@2x) being loaded
|
# (512x512@2x) being loaded
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
im.load()
|
im.load()
|
||||||
self.assertEqual(im.mode, "RGBA")
|
self.assertEqual(im.mode, "RGBA")
|
||||||
self.assertEqual(im.size, (1024, 1024))
|
self.assertEqual(im.size, (1024, 1024))
|
||||||
|
@ -39,11 +39,11 @@ class TestFileIcns(PillowTestCase):
|
||||||
def test_sizes(self):
|
def test_sizes(self):
|
||||||
# Check that we can load all of the sizes, and that the final pixel
|
# Check that we can load all of the sizes, and that the final pixel
|
||||||
# dimensions are as expected
|
# dimensions are as expected
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
for w, h, r in im.info['sizes']:
|
for w, h, r in im.info['sizes']:
|
||||||
wr = w * r
|
wr = w * r
|
||||||
hr = h * r
|
hr = h * r
|
||||||
im2 = Image.open(file)
|
im2 = Image.open(test_file)
|
||||||
im2.size = (w, h, r)
|
im2.size = (w, h, r)
|
||||||
im2.load()
|
im2.load()
|
||||||
self.assertEqual(im2.mode, 'RGBA')
|
self.assertEqual(im2.mode, 'RGBA')
|
||||||
|
|
|
@ -23,10 +23,10 @@ class TestFileJpeg(PillowTestCase):
|
||||||
def roundtrip(self, im, **options):
|
def roundtrip(self, im, **options):
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
im.save(out, "JPEG", **options)
|
im.save(out, "JPEG", **options)
|
||||||
bytes = out.tell()
|
test_bytes = out.tell()
|
||||||
out.seek(0)
|
out.seek(0)
|
||||||
im = Image.open(out)
|
im = Image.open(out)
|
||||||
im.bytes = bytes # for testing only
|
im.bytes = test_bytes # for testing only
|
||||||
return im
|
return im
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
|
|
|
@ -22,10 +22,10 @@ class TestFileJpeg2k(PillowTestCase):
|
||||||
def roundtrip(self, im, **options):
|
def roundtrip(self, im, **options):
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
im.save(out, "JPEG2000", **options)
|
im.save(out, "JPEG2000", **options)
|
||||||
bytes = out.tell()
|
test_bytes = out.tell()
|
||||||
out.seek(0)
|
out.seek(0)
|
||||||
im = Image.open(out)
|
im = Image.open(out)
|
||||||
im.bytes = bytes # for testing only
|
im.bytes = test_bytes # for testing only
|
||||||
im.load()
|
im.load()
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
|
@ -39,22 +39,22 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
def test_g4_tiff(self):
|
def test_g4_tiff(self):
|
||||||
"""Test the ordinary file path load path"""
|
"""Test the ordinary file path load path"""
|
||||||
|
|
||||||
file = "Tests/images/hopper_g4_500.tif"
|
test_file = "Tests/images/hopper_g4_500.tif"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
self.assertEqual(im.size, (500, 500))
|
self.assertEqual(im.size, (500, 500))
|
||||||
self._assert_noerr(im)
|
self._assert_noerr(im)
|
||||||
|
|
||||||
def test_g4_large(self):
|
def test_g4_large(self):
|
||||||
file = "Tests/images/pport_g4.tif"
|
test_file = "Tests/images/pport_g4.tif"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
self._assert_noerr(im)
|
self._assert_noerr(im)
|
||||||
|
|
||||||
def test_g4_tiff_file(self):
|
def test_g4_tiff_file(self):
|
||||||
"""Testing the string load path"""
|
"""Testing the string load path"""
|
||||||
|
|
||||||
file = "Tests/images/hopper_g4_500.tif"
|
test_file = "Tests/images/hopper_g4_500.tif"
|
||||||
with open(file, 'rb') as f:
|
with open(test_file, 'rb') as f:
|
||||||
im = Image.open(f)
|
im = Image.open(f)
|
||||||
|
|
||||||
self.assertEqual(im.size, (500, 500))
|
self.assertEqual(im.size, (500, 500))
|
||||||
|
@ -62,9 +62,9 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
|
|
||||||
def test_g4_tiff_bytesio(self):
|
def test_g4_tiff_bytesio(self):
|
||||||
"""Testing the stringio loading code path"""
|
"""Testing the stringio loading code path"""
|
||||||
file = "Tests/images/hopper_g4_500.tif"
|
test_file = "Tests/images/hopper_g4_500.tif"
|
||||||
s = io.BytesIO()
|
s = io.BytesIO()
|
||||||
with open(file, 'rb') as f:
|
with open(test_file, 'rb') as f:
|
||||||
s.write(f.read())
|
s.write(f.read())
|
||||||
s.seek(0)
|
s.seek(0)
|
||||||
im = Image.open(s)
|
im = Image.open(s)
|
||||||
|
@ -89,8 +89,8 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
|
|
||||||
def test_g4_write(self):
|
def test_g4_write(self):
|
||||||
"""Checking to see that the saved image is the same as what we wrote"""
|
"""Checking to see that the saved image is the same as what we wrote"""
|
||||||
file = "Tests/images/hopper_g4_500.tif"
|
test_file = "Tests/images/hopper_g4_500.tif"
|
||||||
orig = Image.open(file)
|
orig = Image.open(test_file)
|
||||||
|
|
||||||
out = self.tempfile("temp.tif")
|
out = self.tempfile("temp.tif")
|
||||||
rot = orig.transpose(Image.ROTATE_90)
|
rot = orig.transpose(Image.ROTATE_90)
|
||||||
|
@ -108,8 +108,8 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
self.assertNotEqual(orig.tobytes(), reread.tobytes())
|
self.assertNotEqual(orig.tobytes(), reread.tobytes())
|
||||||
|
|
||||||
def test_adobe_deflate_tiff(self):
|
def test_adobe_deflate_tiff(self):
|
||||||
file = "Tests/images/tiff_adobe_deflate.tif"
|
test_file = "Tests/images/tiff_adobe_deflate.tif"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
self.assertEqual(im.mode, "RGB")
|
self.assertEqual(im.mode, "RGB")
|
||||||
self.assertEqual(im.size, (278, 374))
|
self.assertEqual(im.size, (278, 374))
|
||||||
|
@ -215,8 +215,8 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
|
|
||||||
def test_g4_string_info(self):
|
def test_g4_string_info(self):
|
||||||
"""Tests String data in info directory"""
|
"""Tests String data in info directory"""
|
||||||
file = "Tests/images/hopper_g4_500.tif"
|
test_file = "Tests/images/hopper_g4_500.tif"
|
||||||
orig = Image.open(file)
|
orig = Image.open(test_file)
|
||||||
|
|
||||||
out = self.tempfile("temp.tif")
|
out = self.tempfile("temp.tif")
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ class TestFileLibTiffSmall(LibTiffTestCase):
|
||||||
def test_g4_hopper_file(self):
|
def test_g4_hopper_file(self):
|
||||||
"""Testing the open file load path"""
|
"""Testing the open file load path"""
|
||||||
|
|
||||||
file = "Tests/images/hopper_g4.tif"
|
test_file = "Tests/images/hopper_g4.tif"
|
||||||
with open(file, 'rb') as f:
|
with open(test_file, 'rb') as f:
|
||||||
im = Image.open(f)
|
im = Image.open(f)
|
||||||
|
|
||||||
self.assertEqual(im.size, (128, 128))
|
self.assertEqual(im.size, (128, 128))
|
||||||
|
@ -28,9 +28,9 @@ class TestFileLibTiffSmall(LibTiffTestCase):
|
||||||
def test_g4_hopper_bytesio(self):
|
def test_g4_hopper_bytesio(self):
|
||||||
"""Testing the bytesio loading code path"""
|
"""Testing the bytesio loading code path"""
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
file = "Tests/images/hopper_g4.tif"
|
test_file = "Tests/images/hopper_g4.tif"
|
||||||
s = BytesIO()
|
s = BytesIO()
|
||||||
with open(file, 'rb') as f:
|
with open(test_file, 'rb') as f:
|
||||||
s.write(f.read())
|
s.write(f.read())
|
||||||
s.seek(0)
|
s.seek(0)
|
||||||
im = Image.open(s)
|
im = Image.open(s)
|
||||||
|
@ -41,8 +41,8 @@ class TestFileLibTiffSmall(LibTiffTestCase):
|
||||||
def test_g4_hopper(self):
|
def test_g4_hopper(self):
|
||||||
"""The 128x128 lena image failed for some reason."""
|
"""The 128x128 lena image failed for some reason."""
|
||||||
|
|
||||||
file = "Tests/images/hopper_g4.tif"
|
test_file = "Tests/images/hopper_g4.tif"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
self.assertEqual(im.size, (128, 128))
|
self.assertEqual(im.size, (128, 128))
|
||||||
self._assert_noerr(im)
|
self._assert_noerr(im)
|
||||||
|
|
|
@ -17,10 +17,10 @@ class TestFileMpo(PillowTestCase):
|
||||||
# Note that for now, there is no MPO saving functionality
|
# Note that for now, there is no MPO saving functionality
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
im.save(out, "MPO", **options)
|
im.save(out, "MPO", **options)
|
||||||
bytes = out.tell()
|
test_bytes = out.tell()
|
||||||
out.seek(0)
|
out.seek(0)
|
||||||
im = Image.open(out)
|
im = Image.open(out)
|
||||||
im.bytes = bytes # for testing only
|
im.bytes = test_bytes # for testing only
|
||||||
return im
|
return im
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
|
|
|
@ -31,8 +31,8 @@ class TestFilePcx(PillowTestCase):
|
||||||
def test_pil184(self):
|
def test_pil184(self):
|
||||||
# Check reading of files where xmin/xmax is not zero.
|
# Check reading of files where xmin/xmax is not zero.
|
||||||
|
|
||||||
file = "Tests/images/pil184.pcx"
|
test_file = "Tests/images/pil184.pcx"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
self.assertEqual(im.size, (447, 144))
|
self.assertEqual(im.size, (447, 144))
|
||||||
self.assertEqual(im.tile[0][1], (0, 0, 447, 144))
|
self.assertEqual(im.tile[0][1], (0, 0, 447, 144))
|
||||||
|
|
|
@ -19,9 +19,9 @@ MAGIC = PngImagePlugin._MAGIC
|
||||||
|
|
||||||
|
|
||||||
def chunk(cid, *data):
|
def chunk(cid, *data):
|
||||||
file = BytesIO()
|
test_file = BytesIO()
|
||||||
PngImagePlugin.putchunk(*(file, cid) + data)
|
PngImagePlugin.putchunk(*(test_file, cid) + data)
|
||||||
return file.getvalue()
|
return test_file.getvalue()
|
||||||
|
|
||||||
o32 = PngImagePlugin.o32
|
o32 = PngImagePlugin.o32
|
||||||
|
|
||||||
|
@ -56,37 +56,37 @@ class TestFilePng(PillowTestCase):
|
||||||
self.assertRegexpMatches(
|
self.assertRegexpMatches(
|
||||||
Image.core.zlib_version, "\d+\.\d+\.\d+(\.\d+)?$")
|
Image.core.zlib_version, "\d+\.\d+\.\d+(\.\d+)?$")
|
||||||
|
|
||||||
file = self.tempfile("temp.png")
|
test_file = self.tempfile("temp.png")
|
||||||
|
|
||||||
hopper("RGB").save(file)
|
hopper("RGB").save(test_file)
|
||||||
|
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
im.load()
|
im.load()
|
||||||
self.assertEqual(im.mode, "RGB")
|
self.assertEqual(im.mode, "RGB")
|
||||||
self.assertEqual(im.size, (128, 128))
|
self.assertEqual(im.size, (128, 128))
|
||||||
self.assertEqual(im.format, "PNG")
|
self.assertEqual(im.format, "PNG")
|
||||||
|
|
||||||
hopper("1").save(file)
|
hopper("1").save(test_file)
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
hopper("L").save(file)
|
hopper("L").save(test_file)
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
hopper("P").save(file)
|
hopper("P").save(test_file)
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
hopper("RGB").save(file)
|
hopper("RGB").save(test_file)
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
hopper("I").save(file)
|
hopper("I").save(test_file)
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
def test_broken(self):
|
def test_broken(self):
|
||||||
# Check reading of totally broken files. In this case, the test
|
# Check reading of totally broken files. In this case, the test
|
||||||
# file was checked into Subversion as a text file.
|
# file was checked into Subversion as a text file.
|
||||||
|
|
||||||
file = "Tests/images/broken.png"
|
test_file = "Tests/images/broken.png"
|
||||||
self.assertRaises(IOError, lambda: Image.open(file))
|
self.assertRaises(IOError, lambda: Image.open(test_file))
|
||||||
|
|
||||||
def test_bad_text(self):
|
def test_bad_text(self):
|
||||||
# Make sure PIL can read malformed tEXt chunks (@PIL152)
|
# Make sure PIL can read malformed tEXt chunks (@PIL152)
|
||||||
|
@ -167,16 +167,16 @@ class TestFilePng(PillowTestCase):
|
||||||
|
|
||||||
def test_interlace(self):
|
def test_interlace(self):
|
||||||
|
|
||||||
file = "Tests/images/pil123p.png"
|
test_file = "Tests/images/pil123p.png"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
self.assert_image(im, "P", (162, 150))
|
self.assert_image(im, "P", (162, 150))
|
||||||
self.assertTrue(im.info.get("interlace"))
|
self.assertTrue(im.info.get("interlace"))
|
||||||
|
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
file = "Tests/images/pil123rgba.png"
|
test_file = "Tests/images/pil123rgba.png"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
self.assert_image(im, "RGBA", (162, 150))
|
self.assert_image(im, "RGBA", (162, 150))
|
||||||
self.assertTrue(im.info.get("interlace"))
|
self.assertTrue(im.info.get("interlace"))
|
||||||
|
@ -184,8 +184,8 @@ class TestFilePng(PillowTestCase):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
def test_load_transparent_p(self):
|
def test_load_transparent_p(self):
|
||||||
file = "Tests/images/pil123p.png"
|
test_file = "Tests/images/pil123p.png"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
self.assert_image(im, "P", (162, 150))
|
self.assert_image(im, "P", (162, 150))
|
||||||
im = im.convert("RGBA")
|
im = im.convert("RGBA")
|
||||||
|
@ -195,8 +195,8 @@ class TestFilePng(PillowTestCase):
|
||||||
self.assertEqual(len(im.split()[3].getcolors()), 124)
|
self.assertEqual(len(im.split()[3].getcolors()), 124)
|
||||||
|
|
||||||
def test_load_transparent_rgb(self):
|
def test_load_transparent_rgb(self):
|
||||||
file = "Tests/images/rgb_trns.png"
|
test_file = "Tests/images/rgb_trns.png"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
self.assert_image(im, "RGB", (64, 64))
|
self.assert_image(im, "RGB", (64, 64))
|
||||||
im = im.convert("RGBA")
|
im = im.convert("RGBA")
|
||||||
|
@ -209,22 +209,22 @@ class TestFilePng(PillowTestCase):
|
||||||
in_file = "Tests/images/pil123p.png"
|
in_file = "Tests/images/pil123p.png"
|
||||||
im = Image.open(in_file)
|
im = Image.open(in_file)
|
||||||
|
|
||||||
file = self.tempfile("temp.png")
|
test_file = self.tempfile("temp.png")
|
||||||
im.save(file)
|
im.save(test_file)
|
||||||
|
|
||||||
def test_save_p_single_transparency(self):
|
def test_save_p_single_transparency(self):
|
||||||
in_file = "Tests/images/p_trns_single.png"
|
in_file = "Tests/images/p_trns_single.png"
|
||||||
im = Image.open(in_file)
|
im = Image.open(in_file)
|
||||||
|
|
||||||
file = self.tempfile("temp.png")
|
test_file = self.tempfile("temp.png")
|
||||||
im.save(file)
|
im.save(test_file)
|
||||||
|
|
||||||
def test_save_l_transparency(self):
|
def test_save_l_transparency(self):
|
||||||
in_file = "Tests/images/l_trns.png"
|
in_file = "Tests/images/l_trns.png"
|
||||||
im = Image.open(in_file)
|
im = Image.open(in_file)
|
||||||
|
|
||||||
file = self.tempfile("temp.png")
|
test_file = self.tempfile("temp.png")
|
||||||
im.save(file)
|
im.save(test_file)
|
||||||
|
|
||||||
# There are 559 transparent pixels.
|
# There are 559 transparent pixels.
|
||||||
im = im.convert('RGBA')
|
im = im.convert('RGBA')
|
||||||
|
@ -234,8 +234,8 @@ class TestFilePng(PillowTestCase):
|
||||||
in_file = "Tests/images/caption_6_33_22.png"
|
in_file = "Tests/images/caption_6_33_22.png"
|
||||||
im = Image.open(in_file)
|
im = Image.open(in_file)
|
||||||
|
|
||||||
file = self.tempfile("temp.png")
|
test_file = self.tempfile("temp.png")
|
||||||
im.save(file)
|
im.save(test_file)
|
||||||
|
|
||||||
def test_load_verify(self):
|
def test_load_verify(self):
|
||||||
# Check open/load/verify exception (@PIL150)
|
# Check open/load/verify exception (@PIL150)
|
||||||
|
@ -245,7 +245,7 @@ class TestFilePng(PillowTestCase):
|
||||||
|
|
||||||
im = Image.open(TEST_PNG_FILE)
|
im = Image.open(TEST_PNG_FILE)
|
||||||
im.load()
|
im.load()
|
||||||
self.assertRaises(RuntimeError, lambda: im.verify())
|
self.assertRaises(RuntimeError, im.verify)
|
||||||
|
|
||||||
def test_roundtrip_dpi(self):
|
def test_roundtrip_dpi(self):
|
||||||
# Check dpi roundtripping
|
# Check dpi roundtripping
|
||||||
|
@ -329,8 +329,8 @@ class TestFilePng(PillowTestCase):
|
||||||
# Check writing and reading of tRNS chunks for RGB images.
|
# Check writing and reading of tRNS chunks for RGB images.
|
||||||
# Independent file sample provided by Sebastian Spaeth.
|
# Independent file sample provided by Sebastian Spaeth.
|
||||||
|
|
||||||
file = "Tests/images/caption_6_33_22.png"
|
test_file = "Tests/images/caption_6_33_22.png"
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
self.assertEqual(im.info["transparency"], (248, 248, 248))
|
self.assertEqual(im.info["transparency"], (248, 248, 248))
|
||||||
|
|
||||||
# check saving transparency by default
|
# check saving transparency by default
|
||||||
|
|
|
@ -3,14 +3,14 @@ from helper import unittest, PillowTestCase
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
# sample ppm stream
|
# sample ppm stream
|
||||||
file = "Tests/images/hopper.ppm"
|
test_file = "Tests/images/hopper.ppm"
|
||||||
data = open(file, "rb").read()
|
data = open(test_file, "rb").read()
|
||||||
|
|
||||||
|
|
||||||
class TestFilePpm(PillowTestCase):
|
class TestFilePpm(PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
im.load()
|
im.load()
|
||||||
self.assertEqual(im.mode, "RGB")
|
self.assertEqual(im.mode, "RGB")
|
||||||
self.assertEqual(im.size, (128, 128))
|
self.assertEqual(im.size, (128, 128))
|
||||||
|
|
|
@ -3,14 +3,14 @@ from helper import unittest, PillowTestCase
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
# sample ppm stream
|
# sample ppm stream
|
||||||
file = "Tests/images/hopper.psd"
|
test_file = "Tests/images/hopper.psd"
|
||||||
data = open(file, "rb").read()
|
data = open(test_file, "rb").read()
|
||||||
|
|
||||||
|
|
||||||
class TestImagePsd(PillowTestCase):
|
class TestImagePsd(PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
im.load()
|
im.load()
|
||||||
self.assertEqual(im.mode, "RGB")
|
self.assertEqual(im.mode, "RGB")
|
||||||
self.assertEqual(im.size, (128, 128))
|
self.assertEqual(im.size, (128, 128))
|
||||||
|
|
|
@ -41,12 +41,12 @@ class TestFileWebpMetadata(PillowTestCase):
|
||||||
image = Image.open(file_path)
|
image = Image.open(file_path)
|
||||||
expected_exif = image.info['exif']
|
expected_exif = image.info['exif']
|
||||||
|
|
||||||
buffer = BytesIO()
|
test_buffer = BytesIO()
|
||||||
|
|
||||||
image.save(buffer, "webp", exif=expected_exif)
|
image.save(test_buffer, "webp", exif=expected_exif)
|
||||||
|
|
||||||
buffer.seek(0)
|
test_buffer.seek(0)
|
||||||
webp_image = Image.open(buffer)
|
webp_image = Image.open(test_buffer)
|
||||||
|
|
||||||
webp_exif = webp_image.info.get('exif', None)
|
webp_exif = webp_image.info.get('exif', None)
|
||||||
self.assertTrue(webp_exif)
|
self.assertTrue(webp_exif)
|
||||||
|
@ -76,12 +76,12 @@ class TestFileWebpMetadata(PillowTestCase):
|
||||||
image = Image.open(file_path)
|
image = Image.open(file_path)
|
||||||
expected_icc_profile = image.info['icc_profile']
|
expected_icc_profile = image.info['icc_profile']
|
||||||
|
|
||||||
buffer = BytesIO()
|
test_buffer = BytesIO()
|
||||||
|
|
||||||
image.save(buffer, "webp", icc_profile=expected_icc_profile)
|
image.save(test_buffer, "webp", icc_profile=expected_icc_profile)
|
||||||
|
|
||||||
buffer.seek(0)
|
test_buffer.seek(0)
|
||||||
webp_image = Image.open(buffer)
|
webp_image = Image.open(test_buffer)
|
||||||
|
|
||||||
webp_icc_profile = webp_image.info.get('icc_profile', None)
|
webp_icc_profile = webp_image.info.get('icc_profile', None)
|
||||||
|
|
||||||
|
@ -96,14 +96,14 @@ class TestFileWebpMetadata(PillowTestCase):
|
||||||
|
|
||||||
file_path = "Tests/images/flower.jpg"
|
file_path = "Tests/images/flower.jpg"
|
||||||
image = Image.open(file_path)
|
image = Image.open(file_path)
|
||||||
image.info['exif']
|
self.assertTrue('exif' in image.info)
|
||||||
|
|
||||||
buffer = BytesIO()
|
test_buffer = BytesIO()
|
||||||
|
|
||||||
image.save(buffer, "webp")
|
image.save(test_buffer, "webp")
|
||||||
|
|
||||||
buffer.seek(0)
|
test_buffer.seek(0)
|
||||||
webp_image = Image.open(buffer)
|
webp_image = Image.open(test_buffer)
|
||||||
|
|
||||||
self.assertFalse(webp_image._getexif())
|
self.assertFalse(webp_image._getexif())
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ class TestFontBdf(PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
|
|
||||||
file = open(filename, "rb")
|
test_file = open(filename, "rb")
|
||||||
font = BdfFontFile.BdfFontFile(file)
|
font = BdfFontFile.BdfFontFile(test_file)
|
||||||
|
|
||||||
self.assertIsInstance(font, FontFile.FontFile)
|
self.assertIsInstance(font, FontFile.FontFile)
|
||||||
self.assertEqual(len([_f for _f in font.glyph if _f]), 190)
|
self.assertEqual(len([_f for _f in font.glyph if _f]), 190)
|
||||||
|
|
|
@ -17,8 +17,8 @@ class TestFontPcf(PillowTestCase):
|
||||||
self.skipTest("zlib support not available")
|
self.skipTest("zlib support not available")
|
||||||
|
|
||||||
def save_font(self):
|
def save_font(self):
|
||||||
file = open(fontname, "rb")
|
test_file = open(fontname, "rb")
|
||||||
font = PcfFontFile.PcfFontFile(file)
|
font = PcfFontFile.PcfFontFile(test_file)
|
||||||
self.assertIsInstance(font, FontFile.FontFile)
|
self.assertIsInstance(font, FontFile.FontFile)
|
||||||
self.assertEqual(len([_f for _f in font.glyph if _f]), 192)
|
self.assertEqual(len([_f for _f in font.glyph if _f]), 192)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from helper import unittest, PillowTestCase, hopper
|
from helper import unittest, PillowTestCase, hopper
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
class TestImage(PillowTestCase):
|
class TestImage(PillowTestCase):
|
||||||
|
@ -42,8 +41,8 @@ class TestImage(PillowTestCase):
|
||||||
im.paste(0, (0, 0, 100, 100))
|
im.paste(0, (0, 0, 100, 100))
|
||||||
self.assertFalse(im.readonly)
|
self.assertFalse(im.readonly)
|
||||||
|
|
||||||
file = self.tempfile("temp.ppm")
|
test_file = self.tempfile("temp.ppm")
|
||||||
im._dump(file)
|
im._dump(test_file)
|
||||||
|
|
||||||
def test_comparison_with_other_type(self):
|
def test_comparison_with_other_type(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
|
|
@ -76,10 +76,10 @@ class TestImageFilter(PillowTestCase):
|
||||||
# 0 1 2
|
# 0 1 2
|
||||||
# 3 4 5
|
# 3 4 5
|
||||||
# 6 7 8
|
# 6 7 8
|
||||||
min = im.filter(ImageFilter.MinFilter).getpixel((1, 1))
|
minimum = im.filter(ImageFilter.MinFilter).getpixel((1, 1))
|
||||||
med = im.filter(ImageFilter.MedianFilter).getpixel((1, 1))
|
med = im.filter(ImageFilter.MedianFilter).getpixel((1, 1))
|
||||||
max = im.filter(ImageFilter.MaxFilter).getpixel((1, 1))
|
maximum = im.filter(ImageFilter.MaxFilter).getpixel((1, 1))
|
||||||
return min, med, max
|
return minimum, med, maximum
|
||||||
|
|
||||||
self.assertEqual(rankfilter("1"), (0, 4, 8))
|
self.assertEqual(rankfilter("1"), (0, 4, 8))
|
||||||
self.assertEqual(rankfilter("L"), (0, 4, 8))
|
self.assertEqual(rankfilter("L"), (0, 4, 8))
|
||||||
|
|
|
@ -18,7 +18,7 @@ class TestImageLoad(PillowTestCase):
|
||||||
def test_close(self):
|
def test_close(self):
|
||||||
im = Image.open("Tests/images/hopper.gif")
|
im = Image.open("Tests/images/hopper.gif")
|
||||||
im.close()
|
im.close()
|
||||||
self.assertRaises(ValueError, lambda: im.load())
|
self.assertRaises(ValueError, im.load)
|
||||||
self.assertRaises(ValueError, lambda: im.getpixel((0, 0)))
|
self.assertRaises(ValueError, lambda: im.getpixel((0, 0)))
|
||||||
|
|
||||||
def test_contextmanager(self):
|
def test_contextmanager(self):
|
||||||
|
|
|
@ -45,13 +45,13 @@ class TestImageSplit(PillowTestCase):
|
||||||
codecs = dir(Image.core)
|
codecs = dir(Image.core)
|
||||||
|
|
||||||
if 'zip_encoder' in codecs:
|
if 'zip_encoder' in codecs:
|
||||||
file = self.tempfile("temp.png")
|
test_file = self.tempfile("temp.png")
|
||||||
else:
|
else:
|
||||||
file = self.tempfile("temp.pcx")
|
test_file = self.tempfile("temp.pcx")
|
||||||
|
|
||||||
def split_open(mode):
|
def split_open(mode):
|
||||||
hopper(mode).save(file)
|
hopper(mode).save(test_file)
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
return len(im.split())
|
return len(im.split())
|
||||||
self.assertEqual(split_open("1"), 1)
|
self.assertEqual(split_open("1"), 1)
|
||||||
self.assertEqual(split_open("L"), 1)
|
self.assertEqual(split_open("L"), 1)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from helper import unittest, PillowTestCase, hopper
|
import helper
|
||||||
|
from helper import unittest, PillowTestCase
|
||||||
|
|
||||||
from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180,
|
from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180,
|
||||||
ROTATE_270, TRANSPOSE)
|
ROTATE_270, TRANSPOSE)
|
||||||
|
@ -7,8 +8,8 @@ from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180,
|
||||||
class TestImageTranspose(PillowTestCase):
|
class TestImageTranspose(PillowTestCase):
|
||||||
|
|
||||||
hopper = {
|
hopper = {
|
||||||
'L': hopper('L').crop((0, 0, 121, 127)).copy(),
|
'L': helper.hopper('L').crop((0, 0, 121, 127)).copy(),
|
||||||
'RGB': hopper('RGB').crop((0, 0, 121, 127)).copy(),
|
'RGB': helper.hopper('RGB').crop((0, 0, 121, 127)).copy(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_flip_left_right(self):
|
def test_flip_left_right(self):
|
||||||
|
|
|
@ -24,11 +24,11 @@ class TestImageFile(PillowTestCase):
|
||||||
if format in ("MSP", "XBM"):
|
if format in ("MSP", "XBM"):
|
||||||
im = im.convert("1")
|
im = im.convert("1")
|
||||||
|
|
||||||
file = BytesIO()
|
test_file = BytesIO()
|
||||||
|
|
||||||
im.save(file, format)
|
im.save(test_file, format)
|
||||||
|
|
||||||
data = file.getvalue()
|
data = test_file.getvalue()
|
||||||
|
|
||||||
parser = ImageFile.Parser()
|
parser = ImageFile.Parser()
|
||||||
parser.feed(data)
|
parser.feed(data)
|
||||||
|
|
|
@ -94,7 +94,8 @@ try:
|
||||||
def _render(self, font):
|
def _render(self, font):
|
||||||
txt = "Hello World!"
|
txt = "Hello World!"
|
||||||
ttf = ImageFont.truetype(font, FONT_SIZE)
|
ttf = ImageFont.truetype(font, FONT_SIZE)
|
||||||
w, h = ttf.getsize(txt)
|
ttf.getsize(txt)
|
||||||
|
|
||||||
img = Image.new("RGB", (256, 64), "white")
|
img = Image.new("RGB", (256, 64), "white")
|
||||||
d = ImageDraw.Draw(img)
|
d = ImageDraw.Draw(img)
|
||||||
d.text((10, 10), txt, font=ttf, fill='black')
|
d.text((10, 10), txt, font=ttf, fill='black')
|
||||||
|
|
|
@ -17,11 +17,11 @@ class TestImagePalette(PillowTestCase):
|
||||||
|
|
||||||
palette = ImagePalette()
|
palette = ImagePalette()
|
||||||
|
|
||||||
map = {}
|
test_map = {}
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
map[palette.getcolor((i, i, i))] = i
|
test_map[palette.getcolor((i, i, i))] = i
|
||||||
|
|
||||||
self.assertEqual(len(map), 256)
|
self.assertEqual(len(test_map), 256)
|
||||||
self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3)))
|
self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3)))
|
||||||
|
|
||||||
def test_file(self):
|
def test_file(self):
|
||||||
|
@ -117,7 +117,7 @@ class TestImagePalette(PillowTestCase):
|
||||||
palette = raw("RGB", list(range(256))*3)
|
palette = raw("RGB", list(range(256))*3)
|
||||||
|
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
self.assertRaises(ValueError, lambda: palette.tobytes())
|
self.assertRaises(ValueError, palette.tobytes)
|
||||||
self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3)))
|
self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3)))
|
||||||
f = self.tempfile("temp.lut")
|
f = self.tempfile("temp.lut")
|
||||||
self.assertRaises(ValueError, lambda: palette.save(f))
|
self.assertRaises(ValueError, lambda: palette.save(f))
|
||||||
|
|
|
@ -7,10 +7,10 @@ class TestImageSequence(PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
|
|
||||||
file = self.tempfile("temp.im")
|
test_file = self.tempfile("temp.im")
|
||||||
|
|
||||||
im = hopper("RGB")
|
im = hopper("RGB")
|
||||||
im.save(file)
|
im.save(test_file)
|
||||||
|
|
||||||
seq = ImageSequence.Iterator(im)
|
seq = ImageSequence.Iterator(im)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ class TestImageShow(PillowTestCase):
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
dir(Image)
|
dir(Image)
|
||||||
dir(ImageShow)
|
dir(ImageShow)
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -8,7 +8,6 @@ class TestImageWin(PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
dir(ImageWin)
|
dir(ImageWin)
|
||||||
pass
|
|
||||||
|
|
||||||
def test_hdc(self):
|
def test_hdc(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
@ -101,8 +100,8 @@ class TestImageWinDib(PillowTestCase):
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
# Make one the same as the using tobytes()/frombytes()
|
# Make one the same as the using tobytes()/frombytes()
|
||||||
buffer = dib1.tobytes()
|
test_buffer = dib1.tobytes()
|
||||||
dib2.frombytes(buffer)
|
dib2.frombytes(test_buffer)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
# Confirm they're the same
|
# Confirm they're the same
|
||||||
|
@ -112,11 +111,11 @@ class TestImageWinDib(PillowTestCase):
|
||||||
# Arrange
|
# Arrange
|
||||||
im = hopper()
|
im = hopper()
|
||||||
dib = ImageWin.Dib(im)
|
dib = ImageWin.Dib(im)
|
||||||
buffer = dib.tobytes()
|
test_buffer = dib.tobytes()
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.assert_warning(DeprecationWarning, lambda: dib.tostring())
|
self.assert_warning(DeprecationWarning, dib.tostring)
|
||||||
self.assert_warning(DeprecationWarning, lambda: dib.fromstring(buffer))
|
self.assert_warning(DeprecationWarning, lambda: dib.fromstring(test_buffer))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -64,15 +64,15 @@ class TestModeI16(PillowTestCase):
|
||||||
self.assertEqual(imIn.getpixel((0, 0)), 2)
|
self.assertEqual(imIn.getpixel((0, 0)), 2)
|
||||||
|
|
||||||
if mode == "L":
|
if mode == "L":
|
||||||
max = 255
|
maximum = 255
|
||||||
else:
|
else:
|
||||||
max = 32767
|
maximum = 32767
|
||||||
|
|
||||||
imIn = Image.new(mode, (1, 1), 256)
|
imIn = Image.new(mode, (1, 1), 256)
|
||||||
self.assertEqual(imIn.getpixel((0, 0)), min(256, max))
|
self.assertEqual(imIn.getpixel((0, 0)), min(256, maximum))
|
||||||
|
|
||||||
imIn.putpixel((0, 0), 512)
|
imIn.putpixel((0, 0), 512)
|
||||||
self.assertEqual(imIn.getpixel((0, 0)), min(512, max))
|
self.assertEqual(imIn.getpixel((0, 0)), min(512, maximum))
|
||||||
|
|
||||||
basic("L")
|
basic("L")
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class TestPickle(PillowTestCase):
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
for file in [
|
for test_file in [
|
||||||
"Tests/images/test-card.png",
|
"Tests/images/test-card.png",
|
||||||
"Tests/images/zero_bb.png",
|
"Tests/images/zero_bb.png",
|
||||||
"Tests/images/zero_bb_scale2.png",
|
"Tests/images/zero_bb_scale2.png",
|
||||||
|
@ -69,7 +69,7 @@ class TestPickle(PillowTestCase):
|
||||||
"Tests/images/p_trns_single.png",
|
"Tests/images/p_trns_single.png",
|
||||||
"Tests/images/pil123p.png"
|
"Tests/images/pil123p.png"
|
||||||
]:
|
]:
|
||||||
self.helper_pickle_string(pickle, file=file)
|
self.helper_pickle_string(pickle, file=test_file)
|
||||||
|
|
||||||
def test_pickle_l_mode(self):
|
def test_pickle_l_mode(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
|
|
@ -6,10 +6,7 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
try:
|
test_format = sys.argv[1] if len(sys.argv) > 1 else "PNG"
|
||||||
format = sys.argv[1]
|
|
||||||
except:
|
|
||||||
format = "PNG"
|
|
||||||
|
|
||||||
im = Image.open("Tests/images/hopper.ppm")
|
im = Image.open("Tests/images/hopper.ppm")
|
||||||
im.load()
|
im.load()
|
||||||
|
@ -28,7 +25,7 @@ class Worker(threading.Thread):
|
||||||
sys.stdout.write("x")
|
sys.stdout.write("x")
|
||||||
break
|
break
|
||||||
f = io.BytesIO()
|
f = io.BytesIO()
|
||||||
im.save(f, format, optimize=1)
|
im.save(f, test_format, optimize=1)
|
||||||
data = f.getvalue()
|
data = f.getvalue()
|
||||||
result.append(len(data))
|
result.append(len(data))
|
||||||
im = Image.open(io.BytesIO(data))
|
im = Image.open(io.BytesIO(data))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user