PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Easyce stuff

hello
I would like to know how getpixel function work?
does it return the color of the pixel,(in witch format?)
or just 1 for black and 0 for white?

PIXEL getpixel( int x1, int y1 )
It returns a PIXEL value; that's a 16bit unsigned short consisting of 5 bits for red, 6 for green, and 5 for blue (in that order). Check out the tutorials at http://www.pocketmatrix.com/phantom/tech.htm for more info on the pixel format.
I  read the tutorial,and I can't understand how to translate a color value(R:236,G:202,B:76,for example its a yellow color that i want to detect on the screen)
Do I have to convert to binary or something and
is the 16bit color value in binary?
ok,i think i understand a 'bit' more
thanks for explaining this convertion,I was going into hexa to binary and all was wrong..
So I just have to add those 3 color components?
like this:

unsigned short color = 88;

then i make the test
if(getpixel( x+32, y+32 ) == color)break;



8)
sorry, damn faces...
the face with cigarrette - 8) - should be "8 )" (without the space, but I use it so I don't get this face again...)
Hey ,your explanation is great,
You just have to shift to the left by 11, 5 and 0,to place the correct bits in correct places(RGB) and add them.
So the correct color is like this
unsigned short color = (29<<11)+(50<<5)+(8) ;

I make the test,and it won't detect the color on the screen(but shure it is displayed)
I just look the format of my image,its 8bpp
does it make the color wrong?
I'll convert it to 16bpp
hehe, nah, 8bpp images are yet another story. In short, instead keeping exact description of every RGB value per pixel they have an array of 256 colors (with RGB values there) and the picture itself is just a number between 0 and 255.
So while loading such a picture you encounter for ex. 1 in the image - then you go and check the array under "1" what are the RGB values and that's your pixel value. Not sure exactly how EasyCE handles it.
Well, just use GETPIXEL to get one color value and check it vs your expected value etc. I don't really have time to explain you everything... please use a search engine first before you ask some more questions
well,thanks for your help
well, you're close, but still you don't understand it completely.
R=29,G=50 and B=8 , but you don't add it like R+G+B. 16bpp pixel looks like this
RRRRRGGGGGGBBBBB - as you can see R,G and B color values aren't mixed but they take separate bits.
example:(I used | to separate R/G/B bits)
00001|000010|00001
means R=1,G=2,B=1
and
00110|000000|00000
means R=6,G=0,B=0;
and
11111|111111|00000
means R=31,G=63,B=0
note color G has 6 bits while R and B have 5 bits, as far as I know it's chosen so because human eye recognizes green color more exact then R/B therefore this color component is most important.
and now back to your color, you have got
R=29,G=50,B=8
that's in binary
R=11101 (5 bits)
G=110010 (6 bits)
B=01000 (5 bits)
and now you have to add those values and shift them some bits to have them placed at correct places
16bpp R+G+B:(separated with |)
11101|110010|01000
and how to make such a calculation fast?
you use >>/<< bit shifts, << means move one bit left while >> means move one bit right (in practice it means mul by 2/div by 2)
so your calculation looks like
(R<<11)+(G<<5)+(B) - this makes all the bits appear in correct positions.
to fully convert a 24bpp RGB color to 16bpp you make this: (RGB is 24bpp color, RGB2 is 16bpp color)
R=RGB>>16; (get R value)
G=(RGB>>8)&255; (get G value)
B=RGB&255; (get B value)
R=R>>3;(8bits->5bits)
G=G>>2;(8bits->6bits)
B=B>>3;(8bits->5bits)
RGB2=(R<<11)+(G<<5)+(B);
the above code would be slow... so here'a a much better version
RGB2=((RGB>>8)&0xF800)+((RGB>>5)&0x07E0)+((RGB>>3)&0x001F)

the 0x001F is a hex number, you can use windows calculator to change it into dec/binary value.
to show you shortly how the last calculation works and why it uses so little steps I will show you how you convert the G value(do the same for R/B value to understand it better)
you start with 24bpp color like this(I use 32bits to describe our number in every stage)
00000000RRRRRRRRGGGGGGGGBBBBBBBB
now you move it >>5 (5 bits right)
0000000000000RRRRRRRRGGGGGGGGBBB
perform an AND operation with 0x07E0
0x07e0 in binary is:
000000000000000000000GGGGGG00000
(note, we are left with the most important G bits)
now that's a 32bit number, because we're only interested in lower 16bits we will "hide" the other 16bits so we have something like this:
00000GGGGGG00000
which is what we need for 16bpp RGB color
RRRRRGGGGGGBBBBB
so you do quite the same for R and B values and you have your 16bpp color. In PPC development you should save all your bitmaps in 16bpp color to save space, because the display is 16bpp anyway so it doesn't make much sense to keep 24bpp images and perform additional calculations to convert it to 16bpp at the end (unless you're doing A LOT of alpha-blending and similar things and you want to have top-quality...)

hope it helps, I have wrote too much already, there are tons of docs on the net so if you still don't get it just search on google or so. start with byte/bits and hex/dec/binary values conversion and work your way up from there. It's pretty simple once you understand it.Last modification: Mirek Czerwinski - 12/18/01 at 13:38:06
laurent:you're speaking about 24bpp(bits per pixel) mode while PPCs work at 16bpp(bits per pixel) mode(or lower - older devices) the difference is like that:
24bit mode
RRRRRRRRGGGGGGGGBBBBBBB - 8 red, 8 green and 8 blue bits per pixel. Maximum value for R/G/B - 255
16bpp mode
RRRRRGGGGGGBBBBB - 5 red 6 green and 5 blue bits per pixel. Maximum value for R and B is 31 and for G it's 63. (this represents the maximum value you can store in x bits)
so to convert a color value from 24bit mode to 16bit mode you do something like this:
RGB->((R>>3)>>5)+((G>>2)>>3)+(B>>3) - THIS IS FALSE, LOOK LOWER FOR A CORRECTED VERSION
your example
R:236,G:202,B:76
R and B values are stored in 5 bits instead 8, so you divide them by 8 (or use >>3 for much faster calculations - bits shift)
G value is stored in 6 bits so you divide it by 4 (or use >>2)
a lil math shows you, that new values are:
R:29,G:50,B:9
As you will probably notice there's a decrease in image quality because you're using fewer colors, althrought it looks very good on little PPC screens so nothing to worry much about. If you're doing some complicated color-calculations and would like to make them exact you might want to store your pixels in 24bpp format and then transfer it to 16bpp at the time of transfering data to screen/after all calculations are finished.

hope it helpsLast modification: Mirek Czerwinski - 12/18/01 at 13:39:43