I am writing a program to save a bitmap from a DirectDraw surface, and I''m having trouble getting it to save in different color modes. The type I really want to save are 16 bit, so I''ll just give you the code for that. I know that 16 bit is the hardest to save (due to different bit arrangements). I HAVE tried finding something on the internet to help me, but none of what I found worked. Well, here''s the code:
if ( ddsd.ddpfPixelFormat.dwGBitMask == 0x07E0)
{
for ( loop = Height - 1; loop >= 0; loop-- ) //Loop bottom up
{
for ( loop2 = 0; loop2 < Width; loop2++ )
{
outpixel = *( ( WORD * )( Bitmap_in + loop2*2 + loop*Pitch ) ); //Load a word
//Load up the Blue component and output it
outbyte = ( 8 * ( ( outpixel ) & 0x001f ) );//blue
WriteBuffer[BufferIndex++] = outbyte;
//Load up the green component and output it
outbyte = ( 4 * ( ( outpixel >> 5 ) & 0x003f ) );
WriteBuffer[BufferIndex++] = outbyte;
//Load up the red component and output it
outbyte = ( 8 * ( ( outpixel>>11 ) & 0x001f ) );
WriteBuffer[BufferIndex++] = outbyte;
}
}
}
else //Assume 555 mode. 15-bit mode
{
OutputDebugString( "AUTOCROPPER: 555 bit mode.\n" );
for (loop =Height-1;loop>=0;loop--) //Loop bottom up
{
for (loop2=0;loop2>5)&0x001f));
WriteBuffer [BufferIndex++] = outbyte;
//Load up the red component and output it
outbyte = (8*((outpixel>>10)&0x001f)); //BUG FIX here
WriteBuffer [BufferIndex++] = outbyte;
}
}
}
I have a Diamond Viper V550, if that has anything to do with the trouble. I know my card uses the first bit arrangement (0x07E0), but I still can''t get it to work.
Thanks for the help!!
- mallen22@concentric.net
- http://mxf_entertainment.tripod.com/
bitmap saving problems
i cant tell you what is wrong in your code, but if you want, take a look at the code i wrote 2 days ago to take a screen shot, here is the loop
surface+=pitch/2*600; // to start at the bottom
pligne = (COULEUR*)ligne;
for(y=0;y<600;y++)
{
surface-=pitch/2;
for(x=0;x<800;x++)
{
pixel=surface[x];
ligne[x].rouge=(pixel & 0xF800) >> 8;
ligne[x].vert=(pixel & 0x07E0) >> 3;
ligne[x].bleu=(pixel & 0x001F) << 3;
}
WriteFile(Fichier, pligne, 2400, &ByteWritten,NULL);
}
and there is the structure that "ligne" is declared
typedef struct couleur {
unsigned char bleu;
unsigned char vert;
unsigned char rouge;
} COULEUR;
heum sorry for the some words in french, hehe, i cant resist to write some word of my first language![](smile.gif)
i hope this will help you a bit
cyberg
surface+=pitch/2*600; // to start at the bottom
pligne = (COULEUR*)ligne;
for(y=0;y<600;y++)
{
surface-=pitch/2;
for(x=0;x<800;x++)
{
pixel=surface[x];
ligne[x].rouge=(pixel & 0xF800) >> 8;
ligne[x].vert=(pixel & 0x07E0) >> 3;
ligne[x].bleu=(pixel & 0x001F) << 3;
}
WriteFile(Fichier, pligne, 2400, &ByteWritten,NULL);
}
and there is the structure that "ligne" is declared
typedef struct couleur {
unsigned char bleu;
unsigned char vert;
unsigned char rouge;
} COULEUR;
heum sorry for the some words in french, hehe, i cant resist to write some word of my first language
![](smile.gif)
i hope this will help you a bit
cyberg
cyberg- cyberg_coder@hotmail.com- http://members.xoom.com/cybergsoft
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement