I think I've discovered a bug when using named colors, due to using integer division too early in getcolor, which makes it disagree with the color conversion done in ImagingConvert for a large number of colors (106 of the 147 named colors).

To start off, I'm assuming that for grays where r=g=b, that getcolor(name, 'L') should return the same as getcolor(name, 'RGB') [0]. Integer division done too early rounds down, so grays end up slightly too dark in grayscale modes. Here's the line in question (PIL 1.1.6, ImageColor.py line 108):

        return r*299/1000 + g*587/1000 + b*114/1000

All the true grays except black (that is, darkgray, dimgray, gray, lightgray, and white) exhibit this issue. The one that made me notice this is that 'white' means 254 instead of 255. With the attached patch, it now behaves sanely, i.e.:

Image.new('RGB', (1, 1), color).convert('L').getpixel((0, 0)) == Image.new('L', (1, 1), color).getpixel((0, 0))

for all named colors, and

        ImageColor.getcolor(color, 'L') == ImageColor.getcolor(color, 'RGB')[0]

for the grays.

Tim

Attachment: imagecolor-rounding.diff
Description: Binary data


_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to