This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Easyce stuff


Easyce stuff

Postby laurnet » Nov 30, 2001 @ 1:30pm

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


Re: Easyce stuff

Postby Phantom » Nov 30, 2001 @ 2:05pm

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.
Give me some good data and
I will give you the world
User avatar
Phantom
pm Insider
 
Posts: 913
Joined: Feb 21, 2001 @ 8:14am
Location: Houten, Netherlands


Re: Easyce stuff

Postby laurnet » Nov 30, 2001 @ 2:59pm

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)<br>Do I have to convert to binary or something and <br>is the 16bit color value in binary?
laurnet
 


Re: Easyce stuff

Postby laurnet » Nov 30, 2001 @ 9:01pm

ok,i think i understand a 'bit' more<br>thanks for explaining this convertion,I was going into hexa to binary and all was wrong..<br>So I just have to add those 3 color components?<br>like this:<br><br>unsigned short color = 88;<br><br>then i make the test<br>if(getpixel( x+32, y+32 ) == color)break;<br><br><br><br>
laurnet
 


Re: Easyce stuff

Postby MirekCz » Dec 1, 2001 @ 5:24am

8)
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Re: Easyce stuff

Postby MirekCz » Dec 1, 2001 @ 5:25am

sorry, damn faces...<br>the face with cigarrette - 8) - should be "8 )" (without the space, but I use it so I don't get this face again...)
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Re: Easyce stuff

Postby laurnet » Dec 1, 2001 @ 7:11am

Hey ,your explanation is great,<br>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.<br>So the correct color is like this<br>unsigned short color = (29<<11)+(50<<5)+(8) ;<br><br>I make the test,and it won't detect the color on the screen(but shure it is displayed)<br>I just look the format of my image,its 8bpp<br>does it make the color wrong?<br>I'll convert it to 16bpp
laurnet
 


Re: Easyce stuff

Postby MirekCz » Dec 1, 2001 @ 7:55am

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.<br>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.<br>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
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Re: Easyce stuff

Postby laurnet » Dec 1, 2001 @ 4:54pm

well,thanks for your help <br>
laurnet
 


Re: Easyce stuff

Postby MirekCz » Dec 18, 2001 @ 4:38pm

well, you're close, but still you don't understand it completely.<br>R=29,G=50 and B=8 , but you don't add it like R+G+B. 16bpp pixel looks like this<br>RRRRRGGGGGGBBBBB - as you can see R,G and B color values aren't mixed but they take separate bits.<br>example:(I used | to separate R/G/B bits)<br>00001|000010|00001<br>means R=1,G=2,B=1<br>and<br>00110|000000|00000<br>means R=6,G=0,B=0;<br>and<br>11111|111111|00000<br>means R=31,G=63,B=0<br>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.<br>and now back to your color, you have got<br>R=29,G=50,B=8<br>that's in binary<br>R=11101 (5 bits)<br>G=110010 (6 bits)<br>B=01000 (5 bits)<br>and now you have to add those values and shift them some bits to have them placed at correct places<br>16bpp R+G+B:(separated with |)<br>11101|110010|01000<br>and how to make such a calculation fast?<br>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)<br>so your calculation looks like<br>(R<<11)+(G<<5)+(B) - this makes all the bits appear in correct positions.<br>to fully convert a 24bpp RGB color to 16bpp you make this: (RGB is 24bpp color, RGB2 is 16bpp color)<br>R=RGB>>16; (get R value)<br>G=(RGB>>8)&255; (get G value)<br>B=RGB&255; (get B value)<br>R=R>>3;(8bits->5bits)<br>G=G>>2;(8bits->6bits)<br>B=B>>3;(8bits->5bits)<br>RGB2=(R<<11)+(G<<5)+(B);<br>the above code would be slow... so here'a a much better version<br>RGB2=((RGB>>8)&0xF800)+((RGB>>5)&0x07E0)+((RGB>>3)&0x001F) <br><br>the 0x001F is a hex number, you can use windows calculator to change it into dec/binary value.<br>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)<br>you start with 24bpp color like this(I use 32bits to describe our number in every stage)<br>00000000RRRRRRRRGGGGGGGGBBBBBBBB<br>now you move it >>5 (5 bits right)<br>0000000000000RRRRRRRRGGGGGGGGBBB<br>perform an AND operation with 0x07E0<br>0x07e0 in binary is:<br>000000000000000000000GGGGGG00000<br>(note, we are left with the most important G bits)<br>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:<br>00000GGGGGG00000<br>which is what we need for 16bpp RGB color<br>RRRRRGGGGGGBBBBB<br>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...)<br><br>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
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Re: Easyce stuff

Postby MirekCz » Dec 18, 2001 @ 4:39pm

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:<br>24bit mode<br>RRRRRRRRGGGGGGGGBBBBBBB - 8 red, 8 green and 8 blue bits per pixel. Maximum value for R/G/B - 255<br>16bpp mode<br>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)<br>so to convert a color value from 24bit mode to 16bit mode you do something like this:<br>RGB->((R>>3)>>5)+((G>>2)>>3)+(B>>3) - THIS IS FALSE, LOOK LOWER FOR A CORRECTED VERSION <br>your example<br>R:236,G:202,B:76<br>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)<br>G value is stored in 6 bits so you divide it by 4 (or use >>2)<br>a lil math shows you, that new values are:<br>R:29,G:50,B:9<br>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.<br><br>hope it helpsLast modification: Mirek Czerwinski - 12/18/01 at 13:39:43
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Return to Phantom's Forum


Sort


Forum Description

Discuss any of Phantom's projects here (Operation Nutcracker, etc.)

Moderators:

sponge, RICoder, Phantom

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron