<div dir="ltr"><div>Hi,</div><div>while looking at Color, I noticed this (I think that i already wrote about it years ago...):</div><div><br></div><div>(Color fromString: '#F40072') printHtmlString ->  'F30071'</div><div>it truncates each (10 bit component / 1023.0) * 255<br></div><div><br></div><div>This does not work:</div><div><br>((0 to: 255) reject: [:e | (((e/255) * 1023.0) rounded / 1023.0 * 255) truncated  = e]) <br>= ((1 to: 42) , (86 to: 127) , (171 to: 212)).</div><div><br>
</div><div>Using rounded instead of asInteger (truncated) would fix it though<br></div><div><br></div><div>((0 to: 255) reject: [:e | (((e/255) * 1023.0) rounded / 1023.0 * 255) rounded= e]) <br>= #().

</div><div><br></div><div>asHTMLColor does it differently<br></div><div>1) truncate 10 bits components to 8 bits (by shifting)<br></div><div>2) print 8 bits components (more exactly print each 4 bits nibble)<br></div><div>(Color fromString: '#F40072') asHTMLColor -> '#F40072'</div><div><br></div><div>Note that the last two bits of (10 bits components) are not necessarily set to (00) when specifying the Color via 8 bits component / 255</div><div><br></div><div>((0 to: 255) select: [:e | ((e/255) * 1023.0) rounded = (e<<2)])</div><div> = (0 to: 42) asArray.</div><div><br></div><div>
<div>((0 to: 255) select: [:e | ((e/255) * 1023.0) rounded = (e<<2+2r01)])
<div> = (43 to: 127) asArray.
<div><br></div><div>
<div>((0 to: 255) select: [:e | ((e/255) * 1023.0) rounded = (e<<2+2r10)])

<div> = (128 to: 212) asArray.

<div><br></div><div>
<div>((0 to: 255) select: [:e | ((e/255) * 1023.0) rounded = (e<<2+2r11)])

<div> = (213 to: 255) asArray.</div><div><br></div><div></div><div>It also works the same with /255.0.<br></div><div>So truncating like asHTMLColor does, is the right thing and always works.</div><div><br></div><div><br></div><div><br></div><div><br></div>

</div></div>

</div>

</div></div>

</div>

</div>

</div><div><br></div></div>