Merge pull request #4091 from nulano/libimagequant-features

Add libimagequant to features.py
This commit is contained in:
Hugo van Kemenade 2019-11-02 21:31:09 +02:00 committed by GitHub
commit 6060ed3d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 67 deletions

View File

@ -70,11 +70,14 @@ class TestFeatures(PillowTestCase):
lines = out.splitlines()
self.assertEqual(lines[0], "-" * 68)
self.assertTrue(lines[1].startswith("Pillow "))
self.assertEqual(lines[2], "-" * 68)
self.assertTrue(lines[3].startswith("Python modules loaded from "))
self.assertTrue(lines[4].startswith("Binary modules loaded from "))
self.assertEqual(lines[5], "-" * 68)
self.assertTrue(lines[6].startswith("Python "))
self.assertTrue(lines[2].startswith("Python "))
lines = lines[3:]
while lines[0].startswith(" "):
lines = lines[1:]
self.assertEqual(lines[0], "-" * 68)
self.assertTrue(lines[1].startswith("Python modules loaded from "))
self.assertTrue(lines[2].startswith("Binary modules loaded from "))
self.assertEqual(lines[3], "-" * 68)
jpeg = (
"\n"
+ "-" * 68

View File

@ -18,11 +18,14 @@ class TestMain(TestCase):
lines = out.splitlines()
self.assertEqual(lines[0], "-" * 68)
self.assertTrue(lines[1].startswith("Pillow "))
self.assertEqual(lines[2], "-" * 68)
self.assertTrue(lines[3].startswith("Python modules loaded from "))
self.assertTrue(lines[4].startswith("Binary modules loaded from "))
self.assertEqual(lines[5], "-" * 68)
self.assertTrue(lines[6].startswith("Python "))
self.assertTrue(lines[2].startswith("Python "))
lines = lines[3:]
while lines[0].startswith(" "):
lines = lines[1:]
self.assertEqual(lines[0], "-" * 68)
self.assertTrue(lines[1].startswith("Python modules loaded from "))
self.assertTrue(lines[2].startswith("Binary modules loaded from "))
self.assertEqual(lines[3], "-" * 68)
jpeg = (
os.linesep
+ "-" * 68

View File

@ -2,7 +2,6 @@
# minimal sanity check
from __future__ import print_function
import os
import sys
from PIL import Image, features
@ -162,32 +161,7 @@ if __name__ == "__main__":
exit_status = 0
print("-" * 68)
print("Pillow", Image.__version__, "TEST SUMMARY ")
print("-" * 68)
print("Python modules loaded from", os.path.dirname(Image.__file__))
print("Binary modules loaded from", os.path.dirname(Image.core.__file__))
print("-" * 68)
for name, feature in [
("pil", "PIL CORE"),
("tkinter", "TKINTER"),
("freetype2", "FREETYPE2"),
("littlecms2", "LITTLECMS2"),
("webp", "WEBP"),
("transp_webp", "WEBP Transparency"),
("webp_mux", "WEBPMUX"),
("webp_anim", "WEBP Animation"),
("jpg", "JPEG"),
("jpg_2000", "OPENJPEG (JPEG2000)"),
("zlib", "ZLIB (PNG/ZIP)"),
("libtiff", "LIBTIFF"),
("raqm", "RAQM (Bidirectional Text)"),
]:
if features.check(name):
print("---", feature, "support ok")
else:
print("***", feature, "support not installed")
print("-" * 68)
features.pilinfo(sys.stdout, False)
# use doctest to make sure the test program behaves as documented!
import doctest

View File

@ -56,6 +56,7 @@ features = {
"transp_webp": ("PIL._webp", "HAVE_TRANSPARENCY"),
"raqm": ("PIL._imagingft", "HAVE_RAQM"),
"libjpeg_turbo": ("PIL._imaging", "HAVE_LIBJPEGTURBO"),
"libimagequant": ("PIL._imaging", "HAVE_LIBIMAGEQUANT"),
}
@ -94,7 +95,7 @@ def get_supported():
return ret
def pilinfo(out=None):
def pilinfo(out=None, supported_formats=True):
if out is None:
out = sys.stdout
@ -102,6 +103,10 @@ def pilinfo(out=None):
print("-" * 68, file=out)
print("Pillow {}".format(PIL.__version__), file=out)
py_version = sys.version.splitlines()
print("Python {}".format(py_version[0].strip()), file=out)
for py_version in py_version[1:]:
print(" {}".format(py_version.strip()), file=out)
print("-" * 68, file=out)
print(
"Python modules loaded from {}".format(os.path.dirname(Image.__file__)),
@ -113,12 +118,6 @@ def pilinfo(out=None):
)
print("-" * 68, file=out)
v = sys.version.splitlines()
print("Python {}".format(v[0].strip()), file=out)
for v in v[1:]:
print(" {}".format(v.strip()), file=out)
print("-" * 68, file=out)
for name, feature in [
("pil", "PIL CORE"),
("tkinter", "TKINTER"),
@ -133,6 +132,7 @@ def pilinfo(out=None):
("zlib", "ZLIB (PNG/ZIP)"),
("libtiff", "LIBTIFF"),
("raqm", "RAQM (Bidirectional Text)"),
("libimagequant", "LIBIMAGEQUANT (Quantization method)"),
]:
if check(name):
print("---", feature, "support ok", file=out)
@ -140,6 +140,7 @@ def pilinfo(out=None):
print("***", feature, "support not installed", file=out)
print("-" * 68, file=out)
if supported_formats:
extensions = collections.defaultdict(list)
for ext, i in Image.EXTENSION.items():
extensions[i].append(ext)
@ -151,7 +152,9 @@ def pilinfo(out=None):
print(line, file=out)
if i in extensions:
print("Extensions: {}".format(", ".join(sorted(extensions[i]))), file=out)
print(
"Extensions: {}".format(", ".join(sorted(extensions[i]))), file=out
)
features = []
if i in Image.OPEN:

View File

@ -3934,6 +3934,12 @@ setup_module(PyObject* m) {
PyModule_AddObject(m, "HAVE_LIBJPEGTURBO", Py_False);
#endif
#ifdef HAVE_LIBIMAGEQUANT
PyModule_AddObject(m, "HAVE_LIBIMAGEQUANT", Py_True);
#else
PyModule_AddObject(m, "HAVE_LIBIMAGEQUANT", Py_False);
#endif
#ifdef HAVE_LIBZ
/* zip encoding strategies */
PyModule_AddIntConstant(m, "DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY);