Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do browsers handle rgb(percentage); for strange numbers
    primarykey
    data
    text
    <p>This is related to CSS color codes:</p> <p>For hexcode we can represent 16,777,216 colors from #000000 to #FFFFFF</p> <p>According to W3C Specs, Valid RGB percentages fit in a range from (0.0% to 100.0%) essentially giving you 1,003,003,001 color combinations. (1001^3)</p> <p>According to the specs:</p> <blockquote> <p>Values outside the device gamut should be clipped or mapped into the gamut when the gamut is known: the red, green, and blue values must be changed to fall within the range supported by the device. Users agents may perform higher quality mapping of colors from one gamut to another. For a typical CRT monitor, whose device gamut is the same as sRGB, the four rules below are equivalent:</p> </blockquote> <p>I'm doubtful if browsers actually can render all these values. (but if they do please tell me and ignore the rest of this post)</p> <p>Im assuming there's some mapping from rgb(percentage) to hex. (but again Im not really sure how this works)</p> <p>Ideally I'd like to find out the function rgb(percentage)->HEX </p> <p>If I had to guess it would probably be one of these 3.</p> <p>1) Round to the nearest HEX</p> <p>2) CEIL to the nearest HEX</p> <p>3) FLOOR to the nearest HEX</p> <p>Problem is I need to be accurate on the mapping and I have no idea where to search. There's no way my eyes can differentiate color at that level, but maybe there's some clever way to test each of these 3.</p> <p>It might also be browser dependent. Can this be tested?</p> <p><strong>EDIT:</strong></p> <pre><code>Firefox seems to round from empirical testing. </code></pre> <p><strong>EDIT:</strong></p> <p>I'm looking through Firefox's source code right now,</p> <pre><code>nsColor.h // A color is a 32 bit unsigned integer with four components: R, G, B // and A. typedef PRUint32 nscolor; </code></pre> <p>It seems Fiefox only has room for 255 values for each R,G and B. Hinting that rounding might be the answer, but maybe somethings being done with the alpha channel.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload