bitmap processing in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cyrak
    New Member
    • Mar 2008
    • 9

    bitmap processing in C

    I'm trying to do some processing in .bmp files and I need to use C, I've used it quite a bit except for image processing...an d I'm trying to read the header block and pretty much from there just travel through the pixels and compare it with other file.

    I haven't really worked on images before...so any pointers would be appreciated
    this is what I'm trying to do to open the file..but I don't seem to be able to parse through the Header....any ideas, or other paths that I can take ?

    FILE *fp;
    fp = fopen("kitty.bm p","r");
    unsigned char Header[0x435], image[256][256];
    fread(Header,1, 0x435,fp); // copy image header to Header array
    fseek(fp,0x436, SEEK_SET); // Move file pointer to start of image data
    fread(image,1,2 56*256,fp); // read image data and copy to ImageIn1[][] array

    thanks in advance
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    This would be the pseudo code for loadin in the bitmap

    Code:
    If open Bitmap file
    Read two bytes (type) and if different than 0x4D42 stop
    Ignore eight bytes
    Read four bytes (start of image data)
    Ignore four bytes
    Read four bytes (width of bitmap)
    Read four bytes (height of bitmap)
    Ignore two bytes
    Read two bytes (bit count of bitmap) and if different than 24 stop//24bit BMP only
    Read four bytes (compression of bitmap) and if different than BI_RGB stop//No compression
    Move to start of image data
    Allocate memory for image data (3(one byte for red, other for 
    green other for blue) * ImageWidth * ImageHeight)
    Read (3 * ImageWidth * ImageHeight) bytes from file to buffer
    Swap the red and blue components of buffer
    If ImageHeight is negative
    Flip the buffer lines
    End if
    Close file
    Do you see now,where have you gone wrong?

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Are you using Windows? These bitmap funcitons are already written and are part of Win32.

      Comment

      Working...