h6. [[ColourTrans]] h6(. » [[ColourTrans Technical Details|Technical Details]] h6((. » Finding a Colour h2(#finding_a_colour). Finding a Colour Finding a colour given a particular palette or screen mode is provided via several different SWIs. The list below details the methods of finding the appropriate colour. |_<^. Input|_<^. Output| |<^. Palette entry|<^. Nearest/furthest GCOL| |<^. Palette entry|<^. Nearest/furthest colour number| |<^. Palette entry, mode & palette pointer|<^. Nearest/furthest GCOL| |<^. Palette entry, mode & palette pointer|<^. Nearest/furthest colour number| h2(#palette_pointers). Palette Pointers ColourTrans SWIs use palette pointers, and the following conventions apply: |_<^{width:4em}. Value|_<^. Meaning| |<^. -1|<^. Current palette to be used| |<^. 0|<^. Default palette for specified screen mode to be used| h2(#modes). Modes SWIs often use the mode term, and the following conventions apply: |_<^{width:4em}. Value|_<^. Meaning| |<^. -1|<^. Current mode to be used| h2(#best_fit_colour). Best Fit Colour ColourTrans uses a _weighted least squares_ function algorithm to calculate the colour in the palette that most closely matches the specified colour. The algorithm works by calculating the distance between the colours. Where the desired colour is (R<sub>d</sub>, B<sub>d</sub>, G<sub>d</sub>), and the trial colour is (R<sub>t</sub>, B<sub>t</sub>, G<sub>t</sub>), then the distance formula is thus: Distance = redweight x (R<sub>t</sub>-R<sub>d</sub>)<sup>2</sup> + greenweight x (G<sub>t</sub>-G<sub>d</sub>)<sup>2</sup> + blueweight x (B<sub>t</sub>-B<sub>d</sub>)<sup>2</sup> Where redweight = 2, greenweight = 4 and blueweight = 1. These weights are set to provide the optimum solution.