Archived

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

trigger

1bit raw images

Recommended Posts

trigger    123
hi all, i am trying to convert a 1bit raw image(256*256 sized one bit per pixel) to a 256*256*24bit image. how can i do this... i suppose that i have to check every bit of a byte...anybody can help? maybe some example source? thanx best regards trigger

Share this post


Link to post
Share on other sites
terminate    259
IF it is anything like a 1bpp windows BMP you have to check every bit. Im going to assume that a '0' bit is equal to RGB(0,0,0) and a '1' bit is equal to RGB(255,255,255).
  
void ConvertImage(char * filename, unsigned char * imagedata)
{
unsigned char buffer;
int bytecounter;
FILE * f = fopen(filename, "rb");
NumOfBytes = ((256 * 256) / 8); //256 * 256 pixels, 8 pixles per byte (1bpp)

imagedata = (unsigned char *)malloc(256 * 256 * 3); //256x256 pixels at 3 bytes per pixel (24bpp)

for(int x = 0; x < NumOfBytes; x++)
{
fread(&buffer, sizeof(unsigned char), 1, f);
for(int y = 1; y <= 128; y *=2)
{
if((buffer & y) == y)//bit is '1'

{
imagedata[bytecounter] = 255;
imagedata[bytecounter + 1] = 255;
imagedata[bytecounter + 2] = 255;
bytecounter +=3;
}
else
{
imagedata[bytecounter] = 0;
imagedata[bytecounter + 1] = 0;
imagedata[bytecounter + 2] = 0;
bytecounter +=3;
}
}
}
}



I didnt test that code soi cant guarentee it works. It is also probally not the most optimized way to do it. You could replace either of the colors with whatever you like, green or orange or yellow or whatever. Good luck


Edited by - terminate on August 4, 2001 1:43:40 PM

Edited by - terminate on August 4, 2001 1:45:45 PM

Share this post


Link to post
Share on other sites
trigger    123
re terminate,

thanx...its exactly what i was serching for. nice to see another solution for it. i should have known that its done with the bitwise and

best regards
trigger

Share this post


Link to post
Share on other sites