4

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

Beamie
  • 647
  • 7
  • 23
  • Do you want something like http://www.symbolengine.com/amiguide/ http://www.unsatisfactorysoftware.co.uk/index.php?pg=guideml – Ritesh Kumar Gupta Apr 01 '13 at 21:24
  • weren't amiga colors 4bit-per-channel so 4bit alpha, 4bit red, 4bit green, 4bit blue? – Marc B Apr 01 '13 at 21:24
  • 1
    References for you: [IFF ILBM graphics format](http://en.wikipedia.org/wiki/ILBM), [HAM graphics mode](http://en.wikipedia.org/wiki/Hold-And-Modify). Bear in mind also that different Amiga models had different graphics capabilities, so there isn't a fixed Amiga colour format; hopefully the links I've given will help, but ideally you'll need to explain more about the format you're targetting to get more help. – Spudley Apr 01 '13 at 22:06

3 Answers3

6

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.

Floris
  • 45,857
  • 6
  • 70
  • 122
  • I'm wondering, regarding the last statement, doesn't the shift operator have a lower precedence than the addition operator? See here: https://en.cppreference.com/w/c/language/operator_precedence –  Jan 24 '23 at 06:56
  • @buckRabbit thanks for pointing that out. I had not intended that to be an executable statement but I added parentheses just to make it unambiguous now. – Floris Jan 28 '23 at 02:48
3

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.

Durandal
  • 19,919
  • 4
  • 36
  • 70
2

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.

Beamie
  • 647
  • 7
  • 23
  • 1
    Thanks for the props - don't worry about "points". It is more important that you mark the best answer (the one that works for you) as "correct", as that's how the SO database becomes more valuable over time. So mark your answer as the best (with the check mark). Glad I was able to point you in the right direction! – Floris Apr 05 '13 at 00:40
  • Thanks, there will also be more 68xxxx assemblerrelated questions quite soon:) – Beamie Apr 07 '13 at 14:24