Search code examples
htmlassemblyhex68000amiga

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:)


Solution

  • Mostly regarding to Floris answer I was led on the right track outside of stackoverflow. Summary and converting:

    Amiga has some different graphics modes, noteably 12-bit (called OCS) and 24-bit (called AGA) amongst others. For converting to AGA/24-bit nothing needs to be done. For converting to OCS/12-bit we need to reduce values.

    One quick way is to cut the 4 LSB for every RGB-component, like Floris suggested so 0RGB = #RRGGBB.

    or another way, with a bit more precision:

    24-bit RGB color components values ranges from 0-255 (ie. RGB(255,255,0)) and so on. HTML-hex is also 24-bit. 12-bit RGB color components has values in the range 0-15.

    To convert a 24-bit RGB color to 12-bit and just keep the integer part do this for every 24-bit R,G and B component:

    downSizedColor = colToDownSize * maxOfRangeToDownConvertTo / maxOfRangeToDownConvertFrom

    maxOfRangeToDownConvertTo = 15 (12-bit maxrange)

    maxOfRangeToDownConvertFrom = 255 (24-bit maxrange)

    Example for RGB(200, 143, 96) the first RGB component (200) would be downSized RGB-color 11 *11=200*15 / 255*

    Reverting to 24-bit from 12-bit

    upSizedColor = maxOfRangeToDownConvertFrom / maxOfRangeToDownConvertTo * colToUpSize

    Example 187=255/15*11

    There are some very good retro-oriented explanation here and here for doing this stuff, plus that they got an online color-bit-depth-reducer. Highly recommended!

    Note: EAB also has some info. Thanks all for helping! Admins, even though I set this as the correct answer, feel free to Give Floris the points as it led on me the right track, thanks.