🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

getting the RGB-values from a 16-bit pixel

Started by
2 comments, last by draggy18 23 years, 9 months ago
Hi let''s say my pixel is stored in "unsigned short pixel" and I want the value for red, green, blue separatly, how can I do that ?? THX in advance Stefan Thomas FS Productions
The street to success is always under constuction
Advertisement
You mean unsigned short, right?
Here''s how you''d do it:

    LPDIRECTDRAWSURFACE7 dds; // Our surfaceint lpitch; // Will hold the pitch for usDDSURFACEDESC2 ddsd; // The surface descriptionunsigned short Color;unsigned short *surface; // This will hold our surfaceint red,green,blue; // red, green and blue values// Let''s lock the surfacememset(&ddsd,0,sizeof(ddsd));ddsd.dwSize = sizeof(ddsd);dds->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);lpitch = ddsd.lPitch>>1;surface = (unsigned short *)ddsd.lpSurface; // Get a pointer to the surfaceint x=50; // the x of the pixelint y=60; // the y of the pixelColor = (unsigned short)surface[x+y*lpitch]; // get the pixel// Get the valuesred = Color >> 11;green = Color >> 5;blue = Color << 11;dds->Unlock();    


Not sure about where you get the RGB values.



The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
Don''t forget there''s besides 565 also a 555 pixel format!
Instead of 6 bits, green has only 5 bits for its value.
Red moves one bit lower.

QTheBrain
I''m not sure what I wrote will work...
This will work for sure:

red = (Color & 0xF800) >> 11;
green = (Color & 0x07E0) >> 6;
blue = Color & 0x001F;

Remember, This will only work for 565



The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction

This topic is closed to new replies.

Advertisement