Page 1 of 1

I need some help REALLY quick =D

PostPosted: Fri Apr 06, 2012 6:46 pm
by SuperSonic
Can anybody make me a quick bmp loading function?

All I need it to do is load the red values from a 64x64 bmp.

Here's the vars that I have:
Code: Select all
unsigned char gameoverscreen[64][64]

All I need is a function that loads a bmp and stores ONLY the red values in the "gameoverscreen" array :D

+1 to whoever can do this for me :wink:

Re: I need some help REALLY quick =D

PostPosted: Fri Apr 06, 2012 7:22 pm
by skydereign
I assume you already have a bmp loading function, right? If so, you can just remove the gb from it. Or when you display it, just set g and b. Really the most dynamic way to go about this is to create a function that displays the colors, but you can input a mask. That'll allow you to do all kinds of neat effects. In fact, you should be able to change the rgb of the canvas you are using to create the masking effect (and you wouldn't have to redraw the image every frame).

Re: I need some help REALLY quick =D

PostPosted: Fri Apr 06, 2012 7:28 pm
by SuperSonic
Well first of all, I don't have a function. I've tried bmp loading before but I could never get it to work. Secondly, I want the bmp to be displayed as a greyscale image so there's no reason to waist space with g and b, when I could simply just create the image with red colors and load it into ge like that. Does that make sense? Basically, I'm just going to treat red as a brightness factor :D

Re: I need some help REALLY quick =D

PostPosted: Fri Apr 06, 2012 8:34 pm
by skydereign
Well this does what you want I believe. It only reads in the red.
Code: Select all
void
readin_red (char* filenamename)
{
    FILE* file = fopen(filename, "r");
    unsigned char temp;
    int i, j;
 
    fseek(file, 54, 0); // jump to the part where colors are stored

    for(i=0;i<64;i++)
    {
        for(j=0;j<64;j++)
        {
            fscanf(file, "%c%c%c", &temp, &temp, &(red[j][i])); // reads in order bgr
            // this part draws it but I commented it out
            // setpen(red[j][i], 0, 0, 0, 1);
            // putpixel(j, i);
        }
    }
    fclose(file);
}

Re: I need some help REALLY quick =D

PostPosted: Sat Apr 07, 2012 1:49 am
by SuperSonic
Sky, you rock :P

+1 as promised :wink:

Re: I need some help REALLY quick =D

PostPosted: Wed Apr 11, 2012 11:26 pm
by tim4
Hey now... How did we know bitmap headers are always 54 chars long? I'm kamazed. I guess that's the same for PNGs and others too? I mean after decompression.


...Not that this is on-topic or anything, of course. :)

Re: I need some help REALLY quick =D

PostPosted: Wed Apr 11, 2012 11:38 pm
by skydereign
bmp's format is pretty simple, and well enough documented. If you want to know more about them, all you need to do is google it. png files though are far more complex, and really you should be using libpng to deal with pngs (namely don't try it in gE, unless you plan to reverse engineer libpng).