Advertisement

1bit raw images

Started by August 04, 2001 10:41 AM
1 comment, last by trigger 23 years, 6 months ago
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
http://trigger.xenyon.net/
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
Those who dance are considered insane by those who cannot hear the music.
Advertisement
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
http://trigger.xenyon.net/

This topic is closed to new replies.

Advertisement