Jump to content
  • Advertisement
Sign in to follow this  
snisarenko

Loading Bitmap Article

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In this article I don't understand one part where the author deals with padding
DWORD diff;
int offset;
LONG height;

height=bmih.biHeight;
//set diff to the actual image size(no padding)
diff=height*byteWidth;
//allocate memory for the image
pixelData=new BYTE[diff];
if(pixelData==NULL) {
    fclose(in);
    return false;
}
//bitmap is inverted, so the padding needs to be removed
//and the image reversed
//Here you can start from the back of the file or the front,
//after the header.  The only problem is that some programs
//will pad not only the data, but also the file size to
//be divisible by 4 bytes.
if(height>0) {
    int j==size-3;
    offset=padWidth-byteWidth;
    for(int i=0;i<size;i+=3) {
        if((i+1)%padWidth==0) {
            i+=offset;
        }
        *(pixelData+j+2)=*(tempPixelData+i);
        *(pixelData+j+1)=*(tempPixelData+i+1);
        *(pixelData+j)=*(tempPixelData+i+2);
        j++;
    }
}
//the image is not reversed.  Only the padding needs to be removed.
else {
    height=height*-1;
    offset=0;
    do {
        memcpy((pixelData+(offset*byteWidth)),
               (tempPixelData+(offset*padWidth)),
                byteWidth);
        offset++;
    } while(offset<height);
}

I don't get how this part if((i+1)%padWidth==0) { i+=offset; } is supposed to take care of the padding in the pixel data

Share this post


Link to post
Share on other sites
Advertisement
Hi Snisarenko,
Scan lines in windows bitmaps must be padded to finish on a LONG boundary.
from the Windows SDK:
Quote:
Remarks

A device-independent bitmap consists of two distinct parts: a BITMAPINFO structure describing the dimensions and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in the array are packed together, but each scan line must be padded with zeroes to end on a LONG boundary. If the height is positive, the origin of the bitmap is the lower-left corner. If the height is negative, the origin is the upper-left corner.


HTH,
Cambo_frog

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!