79553643

Date: 2025-04-03 17:46:58
Score: 2
Natty:
Report link

I realise this question is quite old but was looking for something related, and since I don't have enough rep to comment... Andrey's answer addresses the random numbers and their tendancy to not generate exactly 1 very often, but the reason it's not a bug in all the other code you mention is not that it's 'harmless', it is that in image processing the 0-1 float/s would have been generated by dividing an 8 bit unsigned integer (0-255) by 255 in the first place, so converting them back by multiplying by 255 is correct. Operations on the 0-1 values that take place in the meantime often produce new values greater than 1 which are clamped at 1 before they are converted back, so the 1 * 255 conversion is in effect used for anything greater than 1, and gets used often in programs that do that kind if thing (they're also clamped at 0). Porter-Duff image compositing which is used in transparency and blending uses the values 0-1, whilst bitmaps etc expect 0-255. I believe the resulting 0-255 values are usually just truncated.

Reasons:
  • Blacklisted phrase (1): to comment
  • Long answer (-1):
  • No code block (0.5):
  • Single line (0.5):
  • Low reputation (1):
Posted by: user63872