Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Craazer

help me whit this 24 to 16 bmp convertor, will u

This topic is 5848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I cant figure out the right pattern to convert 24bit bmp to 16bit bmp.. now i know another way to do this; by loading the file and then convert, but i also need to do it this way. So heres the code: bitmap.buffer24 // type is BYTE and its loaded full of 24bit bmp data bitmap.buffer24 // type is WORD and it empty becose here i want the new bits go red green and blue are BYTEs // i know some code is missing like memory allocation but that isnt the problem, becose this is just the heart of the process. for(int y=0;y[edited by - Craazer on September 15, 2002 10:18:27 AM]

Share this post


Link to post
Share on other sites
Advertisement
As far as i can tell you are computing your buffer positions wrong and accessing each byte multiple times.
And your loop declarations are just typos i hope

try it this way:


    
int w = bitmap.bitmapinfoheader.biWidth;
int h = bitmap.bitmapinfoheader.biHeight;

for( int y = 0; y < h; y++ )
for( int x = 0; x < 3*w; x+=3 )
{
long newpos = y * 3* w + 3 * x;

blue = bitmap.buffer24[newpos];
green = bitmap.buffer24[newpos + 1];
red = bitmap.buffer24[newpos + 2];

bitmap.buffer16[y*w + (x/3)] = RGB16(red,green,blue);
}


you have 3 bytes for each RGB value, thus you have multiply w and x with 3 and step 3 positions in the x loop so you dont access each byte 3 times.

Hope that helps






Runicsoft -- home of my open source Function Parser and more

[edited by - Burning_Ice on September 15, 2002 9:51:53 AM]

Share this post


Link to post
Share on other sites
Actually, don''t multiply y by w*3, but multiply by int stride24 = (w * 3 + 3) & ~3;. That way, you will also handle bitmaps correctly where the width is not a multiple of 4 pixels.

For the 16bit data, you have int stride16 = (w * 2 + 3) & ~3;

Share this post


Link to post
Share on other sites
Kippesoep: i think this is not really neccessary since all .bmps are DWORD-aligned.

And sorry, i just see i made an error:
it shoud be
long newpos = y * 3* w + x;

since in the x loop its already incremented by 3 each time.





Runicsoft -- home of my open source Function Parser and more

Share this post


Link to post
Share on other sites
quote:
Original post by Burning_Ice
Kippesoep: i think this is not really neccessary since all .bmps are DWORD-aligned.

And sorry, i just see i made an error:
it shoud be
long newpos = y * 3* w + x;

since in the x loop its already incremented by 3 each time.





Runicsoft -- home of my open source Function Parser and more


It works! Thank u wery much! and about that for i cant get the code shown proberly becose i dont know how to use code tags (or what ever u use)?

Share this post


Link to post
Share on other sites
youre welcome

and the tags are [ source ] ... [ /source ] without the whitespaces in the tags




Runicsoft -- home of my open source Function Parser and more

[edited by - Burning_Ice on September 15, 2002 10:32:42 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Burning_Ice
youre welcome

and the tags are [ source ] ... [ /source ] without the whitespaces in the tags




Runicsoft -- home of my open source Function Parser and more

[edited by - Burning_Ice on September 15, 2002 10:32:42 AM]


Thanks again

Soon my BMP class will be ready...

Share this post


Link to post
Share on other sites
quote:
Original post by Burning_Ice
Kippesoep: i think this is not really neccessary since all .bmps are DWORD-aligned.



They are, that''s why it''s necessary. If bitmapinfoheader.biWidth is 319, which is quite possible, the DWORD alighment will make the actual stride 320.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!