#### Archived

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

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

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

## 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 on other sites
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 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 on other sites
Using that code the bitmap looks litle bit better but still so mest up

##### 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 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 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 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 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.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999986
×