This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Mats Luspa
Recipients Mats Luspa
Date 2016-02-05.14:00:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1454680812.05.0.172060571572.issue26296@psf.upfronthosting.co.za>
In-reply-to
Content
In the colorsys library function rgb_to_hls the algorithm is not implemented quite correctly.

According to algorithm the correct implementation should be (the error is in the condition r == maxc). In the current code g<b is not tested:

def rgb_to_hls(r, g, b):
    maxc = max(r, g, b)
    minc = min(r, g, b)
    # XXX Can optimize (maxc+minc) and (maxc-minc)
    l = (minc+maxc)/2.0
    if minc == maxc:
        return 0.0, l, 0.0
    if l <= 0.5:
        s = (maxc-minc) / (maxc+minc)
    else:
        s = (maxc-minc) / (2.0-maxc-minc)
    rc = (maxc-r) / (maxc-minc)
    gc = (maxc-g) / (maxc-minc)
    bc = (maxc-b) / (maxc-minc)
    if r == maxc:
        if (g<b):
            h = bc-gc+6
        else:
            h = bc-gc
    elif g == maxc:
        h = 2.0+rc-bc
    else:
        h = 4.0+gc-rc
    h = (h/6.0) % 1.0
    return h, l, s
History
Date User Action Args
2016-02-05 14:00:12Mats Luspasetrecipients: + Mats Luspa
2016-02-05 14:00:12Mats Luspasetmessageid: <1454680812.05.0.172060571572.issue26296@psf.upfronthosting.co.za>
2016-02-05 14:00:12Mats Luspalinkissue26296 messages
2016-02-05 14:00:11Mats Luspacreate