Initial version of imgcheck.

PIL is failing to extract color tables from some images.  
This needs to be investigated.
This commit is contained in:
Eric S. Raymond 2010-10-12 05:29:45 +00:00
parent 4713542863
commit be8d4512cc

48
data/tools/imgcheck Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env python
"""
imgcheck - check a sequence of images for exiguous colors
usage: imgcheck baseframe imgframe...
In a sequence of images, treat the first as a baseframe and the rest
as animation images. Report on colors not present in the baseframe.
The Python Imaging Library must be available for this tool to work
"""
import sys, Image
# Extract a color table list from the images
colortables = []
for filename in sys.argv[1:]:
img = Image.open(filename).convert("RGB")
colortable = img.getcolors()
if colortable:
colortables.append([filename, colortable])
else:
print "imgcheck: %s has no color table" % filename
#img.close()
# Perform cxolor table subtraction
basecolors = map(lambda (n, rgb): rgb, colortables[0][1])
basecolors.sort()
subtracted = []
for i in range(1, len(colortables)):
exiguous = []
for (n, rgb) in colortables[i][1]:
if rgb not in basecolors:
exiguous.append((n, rgb))
exiguous.sort(lambda (an, argb), (bn, brgb): cmp(argb, brgb))
subtracted.append((colortables[i][0], exiguous))
print "Base colors:"
print basecolors
for (filename, colors) in subtracted:
print filename + ":"
for (n, rgb) in colors:
print `rgb` + " * " + `n`