Message 385434 - Python tracker

Message385434

Author terry.reedy
Recipients Bryan.Oakley, cheryl.sabella, serhiy.storchaka, terry.reedy, vstinner
Date 2021-01-21.17:31:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611250311.56.0.0107055117495.issue33289@roundup.psfhosted.org>
In-reply-to
Content
65535 = 35536 - 1 = 256 * 256 - 1 == 255 * 257

On Windows, each r, g, b value is n * 257 for n in range(256) (see attached file).  The precision loss happens when colors are stored, before the division in winfo_rgb.  Perhaps 8 bits/channel (including alpha) is baked in.

Since divmod(n * 257, 257) = (n, 0) and divmod(n * 257, 256) = (n, n),
(n*257) // m = divmod(n*257, m)[0] = n whether m is 256 or 257.
---

macOS appears (from limited experiments) to handle 1 and 2 digits the same as Windows (repeat 4 or 2 times): val('#a00') = val('#aaaa00000000') = 0xaaaa, val('#ab0000') = val('#abab00000000') = 0xabab.  4 digits are left alone while 3 digits use the 1st as the 4th val('#abc000000') = val('#abca00000000') = 0xabca.
History
Date User Action Args
2021-01-21 17:31:51terry.reedysetrecipients: + terry.reedy, vstinner, serhiy.storchaka, Bryan.Oakley, cheryl.sabella
2021-01-21 17:31:51terry.reedysetmessageid: <1611250311.56.0.0107055117495.issue33289@roundup.psfhosted.org>
2021-01-21 17:31:51terry.reedylinkissue33289 messages
2021-01-21 17:31:51terry.reedycreate