Reading palette
Vladimir Shevchenko (2094) 88 posts |
Reading PRMs, I had an idea that the palette is a device with 16 four-digit binary registers. Is this correct ? (Especially for RPi). |
Martin Avison (27) 1494 posts |
Which mode are you trying to read the palette for? |
Vladimir Shevchenko (2094) 88 posts |
Mode 28. |
Steve Pampling (1551) 8170 posts |
I’m confused, you seem to have changed between one post and the next. SYS “OS_ReadPalette”,1,16 TO ,,R2,R3 will return the details of one logical colour (colour 1) The value isn’t a number per se, it’s a set of bits representing a mix of blue green and red. ColourTrans_ReadPalette reads the screen palette or sprite palette. |
Vladimir Shevchenko (2094) 88 posts |
I see a discrepancy in the description of OS_ReadPalette. |
Jon Abbott (1421) 2651 posts |
The Exit register list for OS_ReadPalette doesn’t even list R2, R3 as being possible exit registers. It needs correcting (which I’m working on as we speak). EDIT: Now updated, assuming behaviour hasn’t changed since RO3.x |
Julie Stamp (8365) 474 posts |
Did anyone figure out how to make this work? I am in a C16M mode. I want to read the VDU 4 palette. I understand that I can set the text foreground to one of 256 colours by a combination of I would like to find out the &RRGGBB00 value for each of these 256 colours. If I try OS_ReadPalette as above I get back what I put in, e.g. &01010110 for 1. If I try ColourTrans_ReadPalette I get “Not supported in this depth of display”. |
Julie Stamp (8365) 474 posts |
Ok, I think palettes are a red herring for what I want. Correct me if I’m wrong but it seems palettes aren’t in use in 32bpp modes. To read out the current mode colour numbers for the 256 possible GCOLs (same thing as text colours) from the VDU drivers we can do
The table colours% then gives colour numbers indexed by GCOLs 4_BGRT (i.e. %BBGGRRTT) Where does the actual conversion from 8-bit to 24-bit happen? The kernel generates a 24-bit value for a VDU 17 in the routine ConvertGCOLToColourNumber and then uses ColourTrans_RetrunColourNumber to get the appropriate physical colour. (The temptingly named ColourTrans_GCOLToColourNumber gives the 8-bit colour number regardless of mode.) |
Jeffrey Lee (213) 6048 posts |
Yeah, RISC OS’s palette handling is pretty convoluted. In 32bpp modes there isn’t a palette, but because a lot of the APIs originated on the Archimedes & BBC Micro (or maybe even the Atom?), most of them are restricted to byte-wide colour values (or less – like the fact that you have to set the two GCOL ‘tint’ bits in a separate VDU sequence to the main colour). GCOLs can map to the default 256 colour palette that was used on the Archimedes (but it’s not a direct mapping, due to the funky way that the 256 colour modes were implemented – the Archimedes only had 16 palette registers, so for each pixel four bits are used to index the palette and the remaining four are used to provide some of the RGB bits directly). Extra confusion arrived with RISC OS 3.5, which introduced 16bpp & 32bpp true-colour modes, which lack a hardware palette. So some of the APIs which used palette indices (like VDU 17) now interpret the palette index as a GCOL number when in a true-colour mode. Also in true colour modes some of the palette APIs are actually used to control the gamma table, which I think is why OS_ReadPalette was returning the values you were seeing. Really the gamma table should have been put under a new API, but I guess it’s a bit late for that. I don’t think the wiki fully covers all the nuances (and neither does the StrongHelp manual I’m looking at), so it’s generally a case of learning by experimentation.
Inside ConvertGCOLToColourNumber. The %TTBBGGRR input gets expanded out to %BBTTBBTTGGTTGGTTRRTTRRTT00000000. ColourTrans_ReturnColourNumber then converts that to the actual value that will get written to screen memory. This value can then be passed directly to OS_SetColour (for setting either the text or graphics colour). Or ColourTrans_SetTextColour will accept a 32bpp colour value directly. (edited to remove the inaccurate statement that ColourTrans_SetTextColour maps things down to GCOL values – that’s an old code path for the Archimedes) |
Chris Hall (132) 3554 posts |
I seem to remember that I found it difficult to use colour values that worked equally well in both 16 and 256 colour modes when plotting using EOR. Some machines would give a 16 colour mode and some a 256 colour mode as they couldn’t handle the other… The programme concerned was Fruit Machine which also had to operate on Pico. |
David J. Ruck (33) 1635 posts |
Not only are palettes are a red herring in 16M colour modes, but so are the old GCOL and COLOUR numbers. If using BASIC just use the new RGB aware keywords. For graphics set the colour using GCOL red,green,blue and for text COLOUR red,green,blue. |