Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting hexadecimal HTML-color to Amiga colorregister hex (and back)

HTML hexadecimal colors are written with 6 digits (3 bytes, a so called, A hex triplet). The Amiga's color registers takes a word (2 bytes, 16-bits) which defines a color.

Example:

  • Yellow - HTML hexadecimal #FFFF00
  • Yellow - Amiga color register $0FF0

There must be some kind of algorithm (or/and) some tools for converting between HTML-colors and Amiga colorregisters in an easy way? Or?... Please help:)

like image 951
Beamie Avatar asked Dec 21 '22 07:12

Beamie


2 Answers

http://en.wikipedia.org/wiki/List_of_monochrome_and_RGB_palettes#12-bit_RGB says that there are just 4 bits used for each of R, G, and B.

In other words - I suspect that if you take the top half of each 16 bit hex pair, and string them together, you get the Amiga color.

In your example:

R = 0xFF
G = 0xFF
B = 0xF0

Take the top half (bold above):

AmigaRGB = ((R & 0xF0) << 4) + (G & 0xF0) + ( B >> 4 )

This does indeed result in 0x0FF0

Going in the other direction:

R = AmigaRGB & (0x0F00) >> 4
G = AmigaRGB & (0x00F0)
B = AmigaRGB & (0x000F) << 4

If you wanted to be fancy you could add some rounding, dithering etc.

Of course the final value used in HTML is

HTML_RGB = R<<16 + G<<8 + B

I hope this helps.

like image 137
Floris Avatar answered Dec 22 '22 20:12

Floris


It depends on where you want to use the value, direct hardware access or graphics.library.

For direct hardware access or graphics.library -> setRGB4/loadRGB4 you need to convert to 16 bit-word where bits 15-12 are don't cares: xRGB (each nibble 4 bits). Just throw away each second digit of the HTML hex value.

For graphics.library (version >=39) -> setRGB32/loadRGB32 you need 3x32 bits with the MSB adjusted to the left (bit 31). That means you take the HTML value and split it into R, G and B (2 digts each) and pad it with six zeros to the right.

HTML: #123456 setRGB32: #$12000000, #$34000000, #$56000000

For direct hardware access to the AA-color registers, just google it. Its goddamn complicated, because there are only 32 12-bit color registers and bank-switching via a control register to select bank and lower/upper half.

like image 41
Durandal Avatar answered Dec 22 '22 20:12

Durandal