123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|649|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> Load BMP?

Sun, 24 Oct 2010, 03:07
spinal
I'm trying to load a bmp, but it doesn't seem to work
My C isn't all that good, can anyone see what I'm doing wrong here?



-=-=-
Check out my excellent homepage!
Sun, 24 Oct 2010, 03:37
shroom_monk
For some of the BBC BASIC things I've been doing as a side-project in my Computing lessons (and I may eventually put up here at some point), I recently wrote a BBC BASIC program to read in bitmaps (to then do some other stuff with them).

Here's the bitmap reading stuff in BASIC:

That should be the bit of code that loads the image into memory. I only wanted the brightnesses of each pixel, but you can see where the colours come from.

See if that helps, but I'll have a read over your code too.

|edit| OK, I've never done C, only C++, and I really can't make heads or tails of how C manipulates files. But by the looks of things you're trying to read the width and height from the header, then skip to the byte where the image data starts? When I was researching the file type for the above program, I found that different formats of BMP can have wildly different header sizes and data starting locations. Hence the reason why my code only likes 24-bit bitmaps (to keep it simple), and why I read in each part of the header, rather than trying to skip to a certain location. You could always try that, and then ignore the useless data. |edit|

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Sun, 24 Oct 2010, 04:23
Afr0
Yeah, as shroom_monk says, the header sizes vary. Always do your research properly when trying to load a fileformat!
Here are the most common ones:

  • 12 OS/2 V1 BITMAPCOREHEADER OS/2 and also all Windows versions since Windows 3.0
  • 64 OS/2 V2 BITMAPCOREHEADER2
  • 40 Windows V3 BITMAPINFOHEADER all Windows versions since Windows 3.0
  • 108 Windows V4 BITMAPV4HEADER all Windows versions since Windows 95/NT4
  • 124 Windows V5 BITMAPV5HEADER Windows 98/2000 and newer

    For the BMP format, you can actually find most of the information you need right at Wikipedia!

    Here's the C struct for the Windows V3 BMP:



    -=-=-
    Afr0 Games

    Project Dollhouse on Github - Please fork!
  • Sun, 24 Oct 2010, 04:43
    shroom_monk
    Yup, good ol' Wikipedia was where I did the research for my program!

    -=-=-
    A mushroom a day keeps the doctor away...

    Keep It Simple, Shroom!