RISC OS Open
A fast and easily customised operating system for ARM devices
ROOL
Home | News | Software | Bugs | Bounties | Forum | Documents | Photos | Contact us
Account

ColourTrans Finding A Colour

Programmer's Reference Manuals
» Part 8 - Non-kernel input/output
» ColourTrans
» Technical Details
» 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

Palette Pointers

ColourTrans SWIs use palette pointers, and the following conventions apply:

Value Meaning
-1 Current palette to be used
0 Default palette for specified screen mode to be used

Modes

SWIs often use the mode term, and the following conventions apply:

Value Meaning
-1 Current mode to be used

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~d~, B~d~, G~d~), and the trial colour is (R~t~, B~t~, G~t~), then the distance formula is thus:

Distance = redweight x (R~t~-R~d~)^2^ + greenweight x (G~t~-G~d~)^2^ + blueweight x (B~t~-B~d~)^2^

Where redweight =2, greenweight =4 and blueweight = 1. These weights are set to provide the optimum solution.

Revised on September 24, 2009 16:03:50 by Alan Robertson (52)? (127.0.0.1)
Edit | Back in time (1 revision) | See changes | History | Views: Print | Source | Linked from: ColourTrans Technical Details

Search the Wiki

Commercial use

For commercial enquiries, please contact the owners of RISC OS, Castle Technology Ltd.

ROOL Store

The official C/C++ Development kit and more here.

Donate! Why?

Help ROOL make things happen – please consider donating!

Navigation

  • Home Page
  • All Pages
  • Recently Revised
  • Authors
  • Feeds
Site design © RISC OS Open Limited 2011 except where indicated
The RISC OS Open Instiki theme is based on Insitki's default layout

Valid XHTML 1.0  |  Valid CSS

Instiki 0.19.1(MML+)
This site runs on Rails

Hosted by Arachsys