Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

Re: How to load/decompress a file into your own buffer
Started by Travis at 05-18-2006 15:34. Topic has 2 replies.

Print Search « Previous Thread Next Thread »
  05-18-2006, 15:34
Travis is not online. Last active: 9/26/2008 11:27:59 AM Travis



Top 10 Posts
Joined on 07-07-2003
In house
Posts 286
How to load/decompress a file into your own buffer

Attachment: API - V14 - Load Image into user buffer.zip
Reply Quote

Attached is an example (written in VC 6.0 using MFC and using LEAD's API functions) that shows how to load an image into a buffer the developer allocates.  The bulk of the code is below:

1. When you call L_CreateBitmap, the last parameter must be the EXACT required size. 

L_UINT32 GetRequiredSize(L_INT nWidth, L_INT nHeight, L_INT nBitsPerPixel)

   L_INT nSize = 0;
   BITMAPHANDLE TempBitmap;
   memset(&TempBitmap, 0, sizeof(TempBitmap));
  
   nRet = L_InitBitmap(&TempBitmap, sizeof(TempBitmap), nWidth, nHeight, nBitsPerPixel);
   if (nRet == SUCCESS)
   {
      nSize =  TempBitmap.Size;
   }
   return nSize;
}
 


2.
When calling LoadFile, you must pass the flags (LOADFILE_STORE | LOADFILE_NOINITBITMAP) like so:

 

BOOL MyLoadBitmap(L_CHAR *pszFile, pBITMAPHANDLE pBitmap, L_INT nWidth, L_INT nHeight, L_INT nBitsPerPixel)
{
   L_INT nRet; 
   L_INT nSize = 0;
   L_UCHAR *pData = NULL;
  
   if (!pBitmap)
      return FALSE;
  
   nSize = GetRequiredSize(nWidth,nHeight,nBitsPerPixel);
   if (nSize == 0)
      return FALSE;
  
   pData = (L_UCHAR *)malloc(nSize);
   if (!pData)
      return FALSE;
  
   nRet = L_CreateBitmap(pBitmap, sizeof(BITMAPHANDLE), TYPE_USER, nWidth, nHeight, nBitsPerPixel, ORDER_BGR, 0, BOTTOM_LEFT, pData, nSize);
   if (nRet != SUCCESS)
   {
      free(pData);
      return FALSE;
   }
  
   nRet = L_LoadFile(pszFile, pBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR,
      LOADFILE_STORE | LOADFILE_NOINITBITMAP, NULL, NULL, NULL, NULL);
  
   return (nRet == SUCCESS);
}


Travis Montgomery
LEAD Technical Support
   Report 
  05-21-2008, 18:24
DCurtis is not online. Last active: 6/11/2008 2:40:59 PM DCurtis

Top 150 Posts
Joined on 02-09-2007
Posts 18
Re: How to load/decompress a file into your own buffer

Attachment: ViewPerspective.jpg
Reply Quote
That seems to work fine most of the time, but there are cases when it doesn't work. How can I make this code work when there is a different view perspective set in the file that I'm loading?

For example, the attached file has a view perspective of RIGHT_TOP which makes the L_LoadFile call fail. I need to be able to handle this case. What should I do?


   Report 
  05-22-2008, 15:41
GregR is not online. Last active: 9/30/2008 12:26:32 PM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,607
Re: How to load/decompress a file into your own buffer
Reply Quote
You should set the ELO_IGNOREVIEWPERSPECTIVE flag in the LOADFILEOPTION.Flags property.  If you use this for both the call to L_FileInfo and L_LoadFile, then it should work. 

Though not necessary for L_LoadFile to return SUCCESS, I would also suggest using the view perspective reported by L_FileInfo as well.  Here's the modified code snippet:


void CTutorDlg::OnLoad()
{
    L_INT nRet;
   L_INT nSize = 0;
   L_UCHAR *pData = NULL;
    BITMAPHANDLE Bitmap;
    FILEINFO fi;

    L_INT nWidth, nHeight, nBitsPerPixel, nViewPerspective;

    LOADFILEOPTION lfo;
    L_GetDefaultLoadFileOption(&lfo, sizeof(LOADFILEOPTION));
    lfo.Flags = ELO_IGNOREVIEWPERSPECTIVE;
   
    nRet = L_FileInfo("Test.jpg", &fi, sizeof(FILEINFO), 0, &lfo);
    nWidth = fi.Width;
    nHeight = fi.Height;
    nBitsPerPixel = fi.BitsPerPixel;
    nViewPerspective = fi.ViewPerspective;
     
   nSize = GetRequiredSize(nWidth,nHeight,nBitsPerPixel);
   if (nSize == 0)
      return;
  
   pData = (L_UCHAR *)malloc(nSize);
   if (!pData)
      return;
  
   nRet = L_CreateBitmap(&Bitmap, sizeof(BITMAPHANDLE), TYPE_USER, nWidth, nHeight, nBitsPerPixel, ORDER_BGR, 0, nViewPerspective, pData, nSize);
   if (nRet != SUCCESS)
   {
      free(pData);
      return;
   }
  
   nRet = L_LoadFile("Test.jpg", &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR,
      LOADFILE_STORE | LOADFILE_NOINITBITMAP, NULL, NULL, &lfo, NULL);
  
   return;
}


Greg Ross
LEADTOOLS Technical Support
   Report 
Post
LEAD Support Fo... » Developer » Image Compressi... » Re: How to load/decompress a file into your own buffer

Powered by Community Server, by Telligent Systems