![]() |
Forum Index : Microcontroller and PC projects : CMM2: Inverse map function
Author | Message | ||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Is there a way to easily determine which colour look up table entry a 24 bit colour corresponds to? For example, if I read a pixel, I get a number, say 2176832. I would like to know which map index number that is. I could search the map array to find it, but is there an easier way? I'm porting a program that includes dithering. The colours are modified to give nice gradients, but dithered colours have to stay in the same gradient section. Thus the need to know the colour index, to check if a neighbouring colour is in the same range. Visit Vegipete's *Mite Library for cool programs. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
I think you will have to do a lookup. While experimenting with MAP and colour tables I found an interesting 'feature' Try this program in 8, 12 and 16 bit modes. MODE 1,8 CLS PRINT "Mode ";MM.INFO(MODE) FOR n = 0 TO 255 x = 300+(n MOD 16)*20 y = 100+(n\16)*20 BOX x,y,20,20,1, MAP(n), MAP(n) k = PIXEL(x,y) r = (k AND &hFF0000)/&h10000 g = (k AND &hFF00)/&h100 b = (k AND &hFF) 'box x,y,20,20,1, rgb(r,g,b), rgb(r,g,b) ' use this in 12 bit mode and the image is visible. 'print str$(n,3,0);" RGB(";str$(r,3,0);",";str$(g,3,0);",";str$(b,3,0);")" NEXT n SAVE IMAGE "clut_default.bmp",300,100,320,320 PAUSE 5000 CLS LOAD BMP "clut_default.bmp",300,100 DO:LOOP Modes 1,8 and 1,16 work as expected, drawing the colour chart then overwriting it with the saved copy. mode 1,12 is the interesting one. Nothing appears on the screen but the colour chart does get saved as an image. You can also uncomment line 13 and when the chart is drawn using RGB() it is visible as expected. I assume its the dreaded transparency coming in to play, but unnerving when you can save an image that is invisible. line 15 is what I used to create a copy of the default clut for each mode. Mode 1.16 Mode 1.12 Mode 1.8 0 RGB( 0, 0, 0) 0 RGB( 0, 0, 0) 0 RGB( 0, 0, 0) 1 RGB( 0, 0, 63) 1 RGB( 0, 0, 54) 1 RGB( 0, 0, 84) 2 RGB( 0, 0,127) 2 RGB( 0, 0,127) 2 RGB( 0, 0,168) 3 RGB( 0, 0,191) 3 RGB( 0, 0,200) 3 RGB( 0, 0,255) 4 RGB( 0, 31, 0) 4 RGB( 0, 36, 0) 4 RGB( 0, 36, 0) 5 RGB( 0, 31, 63) 5 RGB( 0, 36, 54) 5 RGB( 0, 36, 84) 6 RGB( 0, 31,127) 6 RGB( 0, 36,127) 6 RGB( 0, 36,168) 7 RGB( 0, 31,191) 7 RGB( 0, 36,200) 7 RGB( 0, 36,255) 8 RGB( 0, 63, 0) 8 RGB( 0, 54, 0) 8 RGB( 0, 72, 0) 9 RGB( 0, 63, 63) 9 RGB( 0, 54, 54) 9 RGB( 0, 72, 84) 10 RGB( 0, 63,127) 10 RGB( 0, 54,127) 10 RGB( 0, 72,168) 11 RGB( 0, 63,191) 11 RGB( 0, 54,200) 11 RGB( 0, 72,255) 12 RGB( 0, 95, 0) 12 RGB( 0, 91, 0) 12 RGB( 0,109, 0) 13 RGB( 0, 95, 63) 13 RGB( 0, 91, 54) 13 RGB( 0,109, 84) 14 RGB( 0, 95,127) 14 RGB( 0, 91,127) 14 RGB( 0,109,168) 15 RGB( 0, 95,191) 15 RGB( 0, 91,200) 15 RGB( 0,109,255) 16 RGB( 0,127, 0) 16 RGB( 0,127, 0) 16 RGB( 0,145, 0) 17 RGB( 0,127, 63) 17 RGB( 0,127, 54) 17 RGB( 0,145, 84) 18 RGB( 0,127,127) 18 RGB( 0,127,127) 18 RGB( 0,145,168) 19 RGB( 0,127,191) 19 RGB( 0,127,200) 19 RGB( 0,145,255) 20 RGB( 0,159, 0) 20 RGB( 0,163, 0) 20 RGB( 0,182, 0) 21 RGB( 0,159, 63) 21 RGB( 0,163, 54) 21 RGB( 0,182, 84) 22 RGB( 0,159,127) 22 RGB( 0,163,127) 22 RGB( 0,182,168) 23 RGB( 0,159,191) 23 RGB( 0,163,200) 23 RGB( 0,182,255) 24 RGB( 0,191, 0) 24 RGB( 0,200, 0) 24 RGB( 0,218, 0) 25 RGB( 0,191, 63) 25 RGB( 0,200, 54) 25 RGB( 0,218, 84) 26 RGB( 0,191,127) 26 RGB( 0,200,127) 26 RGB( 0,218,168) 27 RGB( 0,191,191) 27 RGB( 0,200,200) 27 RGB( 0,218,255) 28 RGB( 0,223, 0) 28 RGB( 0,236, 0) 28 RGB( 0,255, 0) 29 RGB( 0,223, 63) 29 RGB( 0,236, 54) 29 RGB( 0,255, 84) 30 RGB( 0,223,127) 30 RGB( 0,236,127) 30 RGB( 0,255,168) 31 RGB( 0,223,191) 31 RGB( 0,236,200) 31 RGB( 0,255,255) 32 RGB( 27, 0, 0) 32 RGB( 36, 0, 0) 32 RGB( 36, 0, 0) etc... ![]() Jim VK7JH MMedit |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Yes, it is transparency. change line 8 to BOX x,y,20,20,1, MAP(n)+&hF000000, MAP(n)+&hF000000 and all modes work the same. Jim VK7JH MMedit |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Well, Map and inverseMap seem to be beating me up. map set ? map(160) pixel 250,10,map(160) ? pixel(250,10) end Output: 10485760 Is it unreasonable of me to expect the same output value for both prints?11927552 I've tried adding &hF000000 to the pixel colour (line 3.) Using 'map reset' makes no difference. I am confused. Visit Vegipete's *Mite Library for cool programs. |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Ah, a solution! peek(byte mm.info(page address 0) + X + Y * MM.HRES) Visit Vegipete's *Mite Library for cool programs. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
And you will get different results depending on the mode. Jim VK7JH MMedit |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
The map function is very odd in the way it works but for a reason Consider that I set slot 160 to RGB(44,55,66) using the map command. I now need to tell the firmware that I want to use this value and I do this using the MAP function map(160). What the map function does is to pick an RGB value that would have itself caused the firmware to choose lookup value 160. Now there are 65536 different RGB values that will convert to 160 (RGB888 reduced to RGB332) so the value of MAP(160) is not useful to you, it is just a code for getting at the correct slot in the mapping table |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Is there a way to specify which colour number is to used for drawing? Not a 24 bit colour, but rather colour number 0 to 255. This is in 8 bit mode of course. If I fill each map(x) with my desired 24 bit colour, will using map(n) as the specified colour in a drawing command always give me exactly the colour specified in position n in the table? Also, when using some of the lower resolution modes that internally double the number of vertical lines, I gather poking pixels into the screen buffer requires 2 pokes at (mem_location) and (mem_location + MM.HRES). In contrast, a single peek is enough because any drawing commands will have correctly filled both locations. Is that correct? Visit Vegipete's *Mite Library for cool programs. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Yes, that is the intention yes |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |