Author Topic: Problem when bad bmp files hang the target  (Read 11327 times)

Offline Kevin

  • Newbie
  • *
  • Posts: 30
    • View Profile
Problem when bad bmp files hang the target
« on: July 29, 2010, 05:40:28 AM »
Mark-

In one of my previous posts I mentioned that my .bmp pictures reduced to fit the tft in photoshop 6.0 had two extra bytes in the length and two extra nulls appended at the end of the file.

When displaying these files utasker would hang.

From what I can tell it looks like fnDisplayBitmap is reading from the file 3 bytes at a time, but at the end there are only two bytes available.  I added the following to fnDisplayBitmap in TFT.c

BMP_Length = (BMP_Length/3) * 3;   //{kevin 1} bmp file must be multiple of color bytes (3 bytes = 24bit)

after BMP_Length is read from the file.  Since it's int math, any file not divisible by 3 is truncated.

This seemed to work fine for me.

-Kevin

Code: [Select]
                    BMP_Length = (ptrBMP_info->biSizeImage[3] << 24);    // bit map content length
                    BMP_Length |= (ptrBMP_info->biSizeImage[2] << 16);
                    BMP_Length |= (ptrBMP_info->biSizeImage[1] << 8);
                    BMP_Length |= (ptrBMP_info->biSizeImage[0]);
                    if (BMP_Length == 0) {
                        BMP_Length = (ptrBMP->bmLength[3] << 24);        // if the content length is zero, take it from the header
                        BMP_Length |= (ptrBMP->bmLength[2] << 16);
                        BMP_Length |= (ptrBMP->bmLength[1] << 8);
                        BMP_Length |= (ptrBMP->bmLength[0]);
                        BMP_Length -= ptrBMP->bmOffBits[0];
                    }
BMP_Length = (BMP_Length/3) * 3; //{kevin 1} bmp file must be multiple of color bytes (3 bytes = 24bit)