Skip to main content
GameDev.net gamedev.net
🔒 Locked

16 Bit Conversion

Started by firoz Jun 30, 2000 at 12:28 AM 4 replies 350+ views
Original Post
firoz
firoz
Hi, I was wondering if anyone knew of a image creation/conversion program that would let me save files as 16-bit graphics. If not, how do I manually convert a 24-bit to 16-bit? Sorry if this seems like a newbie question. Truth is, i am a newbie and desperately in need of help. Thanks in advance, Firoz Basha.
ferret
cyberben
cyberben
To start with to my knowledge you cannot have 16-bit bitmaps because some cards run 16-bits as 5bits red - 6bits green - 5 bits blue or 565 mode some run 5 bits red - 5 bit green - 5 bits blue or 555 mode so it''s different on each machine.

So you want a 24-bit file system wheather it be standard bitmaps or your own file format... 24-bit

Then when you load the bitmap you already have some sort of flag set wheather it''s 555 or 565 mode then you can convert the values accordingly...

Sorry I program in 100% assembler so I can''t give you any code samples especially for a newbie, but some wise C or C++ programmer can come along after me and give you an example or link to a page.. :-)

See ya,
Ben
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
Gladiator
Gladiator
Oh c''mon now... Don''t be 100% shy to give code examples in Assembler... I''m sure some of us will have the time to translate it to C/C++ code for the ones who don''t understand what it''s supposed to do...
cyberben
cyberben
Well to be honest my 16bit color macros are taken from Chris Hobbs Assembly game programming tutorials here on GameDev.net so look in the programming sections... he has a zip to download. You can convert the code. He does some good teaching in my oppinion too! So maybe you''ll learn something..
See ya,
Ben
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
zenic
zenic
hi there, figured i would throw some source in.

question: why load/save in 16-bit? to save space?

most cards seem to be 5-6-5 (r-g-b). i would store it in that format. when you read it back in, you will have to convert it to the correct display anyway.

here is some source to convert 24bit into 16bit:
(globals used for simplicity)
this is a quick hack to give the idea.
and i''ll tack on some code to get the shift left and right values based on the pixel format of a direct x surface.

[source]
int iRSHL, iGSHL, iBSHL;
int iRSHR, iGSHR, iBSHR;

void convert_24_16(WORD* pdest, BYTE* psrc, int width, int height)
{
int countx, county;
for (county=0; county{
for (countx=0; countx{
WORD temp1; //optimizing compiler will use a register
WORD temp2; //optimizing compiler will use a register
WORD temp3; //optimizing compiler will use a register
temp1 = psrc[0] >> iRSHR << iRSHL; // red
temp2 = psrc[1] >> iGSHR << iGSHL; // green
temp3 = psrc[2] >> iBSHR << iBSHL; // blue
*pdest++ = temp1 / temp2 / temp3; // combine together
psrc+=3; // skip to next set of red,green,blue bytes
}
}
}

void get_pixel_info()
{
ZeroMemory(&ddPF, sizeof(ddPF));
ddPF.dwSize = sizeof(ddPF);

// get the information from the back surface
ddret = lpSurface->GetPixelFormat(&ddPF);
if (ddret != DD_OK)
return FALSE;

DWORD dwRBM = ddPF.dwRBitMask;
DWORD dwGBM = ddPF.dwGBitMask;
DWORD dwBBM = ddPF.dwBBitMask;
// calculate shift left amount
for (iRSHL=0; (dwRBM&1)!=1; iRSHL++) dwRBM>>=1;
for (iGSHL=0; (dwGBM&1)!=1; iGSHL++) dwGBM>>=1;
for (iBSHL=0; (dwBBM&1)!=1; iBSHL++) dwBBM>>=1;
// calculate shift right amount
for (iRSHR=8; (dwRBM&1)==1; iRSHR--) dwRBM>>=1;
for (iGSHR=8; (dwGBM&1)==1; iGSHR--) dwGBM>>=1;
for (iBSHR=8; (dwBBM&1)==1; iBSHR--) dwBBM>>=1;

}
zenic
zenic
(duplicate message deleting)

Edited by - zenic on July 6, 2000 7:39:48 PM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.