Hi All:

I have an application that allows the user to capture signatures on pre Palm
OS 3.5 devices then transfer them to a PC. That works fine.

I recently attempted to port it to Palm OS 3.5 and higher and was able to do
that successfully as well on the device. The problem lies in the conduit. I
am attempting to use the same conduit that I use for the pre Palm OS 3.5
application (since my signatures are using 1 pixel depth and only supported
on non-color devices), but when I save the signatures to the PC they all
start in the middle of the bitmap and wrap around to the beginning. Not
being an image or bitmap expert I am having problems resolving this issue.

I have attached the code below that writes the bitmap (this was originally
extracted from Signature++). Any impute would be appreciated.

- Martin

void WriteOutBitmap(CStdioFile& theLocalFile, WORD* theBitmapPtr)
{
 BYTE    theTempByte=0;
 WORD*    theData = theBitmapPtr;
 WORD*    theScanLine;
 LONG    theWidth, theHeight, theRowBytes;
 LONG    theBMPRowBytes;
 BITMAPFILEHEADER theBitmapHeader;  // 14 bytes
 BITMAPINFOHEADER theBitmapInfo;   // 40 bytes
 RGBQUAD    theBitmapColors[2];  // 8  bytes
 int     i, j;

 // First, grab the important information from the pointer to the Palm OS
 // bitmap.
 theWidth = SyncHHToHostWord( *(theData++) );
 theHeight = SyncHHToHostWord( *(theData++) );
 theRowBytes = SyncHHToHostWord( *(theData++) );

 // Advance past the rest of the Palm OS bitmap header information so that
 // our pointer is sitting at the actual bitmap data.
 theData+=5;

 // Each scan line must end on a four-byte boundary, so calculate
 // our BMP row bytes.
 theBMPRowBytes = ((theRowBytes + 3)/4) * 4;

 // First, fill in the file information structure
 // Since we are writing a version 3 BMP file, the file size is the size of
the file header
 // plus the size of the bitmap header plus the size of the color palette
plus the size of
 // the bitmap data
 theBitmapHeader.bfType  = 0x4D42; // is always "BM";
 theBitmapHeader.bfSize  = sizeof( BITMAPFILEHEADER ) + sizeof(
BITMAPINFOHEADER ) + sizeof( theBitmapColors ) + (theHeight *
theBMPRowBytes);
 theBitmapHeader.bfReserved1 = 0;
 theBitmapHeader.bfReserved2 = 0;
 theBitmapHeader.bfOffBits = sizeof( BITMAPFILEHEADER ) + sizeof(
BITMAPINFOHEADER ) + sizeof( theBitmapColors );

 // Write out the header information to the file
 theLocalFile.Write( &theBitmapHeader, sizeof(BITMAPFILEHEADER) );

 // Next fill in the bitmap information structure
 theBitmapInfo.biSize   = sizeof( BITMAPINFOHEADER );
 theBitmapInfo.biWidth   = theWidth;
 theBitmapInfo.biHeight   = theHeight;
 theBitmapInfo.biPlanes   = 1;
 theBitmapInfo.biBitCount  = 1;
 theBitmapInfo.biCompression  = BI_RGB;
 theBitmapInfo.biSizeImage  = theHeight * theBMPRowBytes;
 theBitmapInfo.biXPelsPerMeter = 0x0B13; // Default value
 theBitmapInfo.biYPelsPerMeter = 0x0B13; // Default value
 theBitmapInfo.biClrUsed   = 2;
 theBitmapInfo.biClrImportant = 2;

 // Write out the bitmap information to the file
 theLocalFile.Write( &theBitmapInfo, sizeof(BITMAPINFOHEADER) );

 theBitmapColors[0].rgbBlue  = 255;
 theBitmapColors[0].rgbRed  = 255;
 theBitmapColors[0].rgbGreen  = 255;
 theBitmapColors[0].rgbReserved  = 0;
 theBitmapColors[1].rgbBlue  = 0;
 theBitmapColors[1].rgbRed  = 0;
 theBitmapColors[1].rgbGreen  = 0;
 theBitmapColors[1].rgbReserved  = 0;

 // Write out the header information to the file
 theLocalFile.Write( &theBitmapColors, sizeof(theBitmapColors) );

 // Write out each scan line from the bottom up, adding
 // padding if necessary.
 theTempByte = 0;
 for (i=(theHeight-1); i>=0; i--)
 {
  // Grab a pointer to the scan line
  theScanLine = theData + (i*(theRowBytes/2));
  theLocalFile.Write( theScanLine, theRowBytes );

  // Finally, add padding if necessary so that the
  // bitmap is word aligned
  if (theRowBytes != theBMPRowBytes)
  {
   for (j=theRowBytes; j<theBMPRowBytes; j++)
    theLocalFile.Write( &theTempByte, 1 );
  }
 }
}




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to