Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.11.1
LEADTOOLS Raster Imaging C DLL Help

L_LoadMemory

Show in webframe

#include "l_bitmap.h"

L_LTFIL_API L_INT L_LoadMemory(pBuffer, pBitmap, uStructSize, nBitsPerPixel, nOrder, uFlags, pfnCallback, pUserData, nBufferSize, pLoadOptions, pFileInfo)

L_UCHAR* pBuffer;

/* pointer to the file in memory to be loaded */

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_UINT uStructSize;

/* size in bytes, of the structure pointed to by pBitmap */

L_INT nBitsPerPixel;

/* resulting bitmap pixel depth */

L_INT nOrder;

/* desired color order */

L_UINT uFlags;

/* flags that determine function behavior */

FILEREADCALLBACK pfnCallback;

/* optional callback function */

L_VOID* pUserData;

/* pointer to more parameters for the callback */

L_SSIZE_T nBufferSize;

/* size of the file in memory (in bytes) */

pLOADFILEOPTION pLoadOptions;

/* pointer to optional extended load options */

pFILEINFO pFileInfo;

/* pointer to a structure */

Loads any supported file from memory using a callback function.

Parameter

Description

pBuffer

Pointer to the file in memory to be loaded.

pBitmap

Pointer to the bitmap handle referencing the bitmap to be filled with image data.

uStructSize

Size in bytes, of the structure pointed to by pBitmap, for versioning. Use sizeof(BITMAPHANDLE).

nBitsPerPixel

Resulting bitmap pixel depth. The following are valid values:

 

Value

Meaning

 

0

Keep the original file's pixel depth (Do not convert). A special note about loading 12 and 16-bit grayscale images.

 

1 to 8

The specified bits per pixel in the resultant bitmap

 

12

12 bits per pixel in the resultant bitmap.

 

16

16 bits per pixel in the resultant bitmap

 

24

24 bits per pixel in the resultant bitmap

 

32

32 bits per pixel in the resultant bitmap

 

48

48 bits per pixel in the resultant bitmap

 

64

64 bits per pixel in the resultant bitmap

 

nOrder

The desired color order. Possible values are:

 

Value

Meaning

 

ORDER_RGB

[0] Red-green-blue order.

 

ORDER_BGR

[1] Blue-green-red order.

 

ORDER_GRAY

[2] 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are only supported in  Document and Medical Imaging toolkits.

 

0

The data is 8 bits per pixel or less.

 

ORDER_RGBORGRAY

[3] Load the image as red, green, blue OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in  Document and Medical Imaging toolkits.

 

ORDER_BGRORGRAY

[4] Load the image as blue, green, red OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in Document and Medical Imaging toolkits.

 

ORDER_ROMM

[5] ROMM order. ROMM only supports 24 and 48-bit images.

 

ORDER_BGRORGRAYORROMM

[6] Load the image as red, green, blue OR as a 12 or 16-bit grayscale image OR as ROMM. 12 and 16-bit grayscale images are supported in  Document and Medical Imaging toolkits. ROMM only supports 24 and 48-bit color images.

uFlags

Binary flags that determine the behavior of L_LoadMemory. You can specify one or more of the following values:

 

Value

Meaning

 

LOADFILE_ALLOCATE

[0x0001] The function allocates memory for the specified bitmap.

 

LOADFILE_STORE

[0x0002] The function loads data into the specified bitmap. (This takes place in addition to the actions of your callback function.)

 

LOADFILE_FIXEDPALETTE

[0x0004] This flag will force a palletized image to be dithered to a fixed palette.

 

LOADFILE_NOINTERLACE

[0x0008] The function passes image data in the order that is displayed, regardless of how it is stored in the file. (Set this flag if your program does not handle interlaced file formats.)

 

LOADFILE_ALLPAGES

[0x0010] The function loads all pages of a multi-page file. Use this flag only if you are creating a bitmap list using the L_AppendPlayback function.

  LOADFILE_NOINITBITMAP

[0x0020] The function does not initialize the bitmap handle when it loads the file. Use this flag only if you are supplying all of the required information in the BITMAPHANDLE structure.

 

LOADFILE_COMPRESSED

[0x0040] (Document and Medical Imaging toolkits) If possible, load the file as a 1-bit RLE-compressed image. For more information, refer to Speeding Up 1-Bit Documents.

pfnCallback

Optional callback function for additional processing.

 

If you do not provide a callback function, use NULL as the value of this parameter.

 

If you do provide a callback function, use the function pointer as the value of this parameter.

 

The callback function must adhere to the function prototype described in FILEREADCALLBACK Function.

pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

 

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID  *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

 

If the additional parameters are not needed, you can pass NULL in this parameter.

nBufferSize

Size of the file in memory (in bytes).

pLoadOptions

Pointer to optional extended load options. Pass NULL to use the default load options.

pFileInfo

Pointer to a FILEINFO structure. This structure may contain file information used in loading an image, or it may be updated with information about the file being loaded.

 

If nothing is known about the file, pass NULL for this parameter, or declare a variable of type FILEINFO and set the FILEINFO.Flags to 0, then pass the address of the FILEINFO structure in this parameter. In this case, if the address of a FILEINFO structure is passed, the FILEINFO structure will be updated with the results of L_FileInfo.

 

If only the file type is known, set pFileInfo.Format to the file type and set pFileInfo.Flags to FILEINFO_FORMATVALID. This can also be done if L_FileInfo has been called previously, but values that affect the size of the image loaded have been changed (for example, by calling L_SetPCDResolution or L_SetWMFResolution). In this case the FILEINFO structure pointed to by pFileInfo will be updated with the results of L_FileInfo.

 

If L_FileInfo has been called prior to calling this function, and no changes have been made to the contents of the structure filled by L_FileInfo, then the address of the filled FILEINFO structure can be passed for this parameter. In this case, the FILEINFO.Flags member should be set to FILEINFO_INFOVALID. The L_FileInfo function will set the FILEINFO.Flags to FILEINFO_INFOVALID. In this case the load will be faster since this function does not have to query the file filters for the file type.

 

Note: Local variables are not initialized (since they are placed on the stack). So if you have a FILEINFO structure as a local variable, the value of its Flags parameter is undefined, possibly having FILEINFO_INFOVALID or FILEINFO_FORMATVALID set. That is why it is important to initialize FILEINFO.Flags before passing the address of the FILEINFO structure to the function.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Support for 12 and 16-bit grayscale images is only available in  Document and Medical Imaging toolkits.

The callback function can display the image to the screen, write to a file, or do other useful things.

This function will create a buffer and fill it with the actual image data. Once the buffer is full, the callback function is called.

Before calling this function, you may need to get or set file information, such as the page number of a multi-page file. Refer to Getting and Setting File Information.

This function cannot be used in combination with L_RedirectIO.

Note:

Redirected IO is not supported for some file formats.  For more information, refer to File Formats for Which Redirected IO is Not Supported.

Note:

More options are available in the LOADFILEOPTION structure.

Note: You should never pass an uninitialized FILEINFO structure to this function.

Required DLLs and Libraries

LTFIL
File format DLLs

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64, Linux.

See Also

Functions:

L_LoadBitmapMemory, L_LoadBitmapMemory, L_LoadMemory, L_SetWMFResolution, L_SetLoadInfoCallback, L_DlgOpen, L_CreatePanWindow, L_SetLoadResolution, L_SetPCDResolution,
For Vector files: L_2DGetViewMode, L_2DGetViewPort, L_2DSetViewMode, L_2DSetViewPort

Topics:

Raster Image Functions: Loading Files

 

Raster Image Functions: Redirecting Input and Output

 

Raster Image Functions: Input and Output

 

Loading and Saving Images

 

Using a PanWindow

 

For a list of functions that utilize the LOADFILEOPTION or SAVEFILEOPTION structures, refer to Functions Utilizing the LOADFILEOPTION or SAVEFILEOPTION structures.

Example

For complete sample code, refer to the MEMORYCB example. This example loads a temporary bitmap, saves it as a file in memory, then loads the memory-resident file into the global bitmap handle. It uses L_LoadMemory with a callback function to implement a paint-while-load feature. Refer to the FILEREADCALLBACK function to see how the callback function paints the image data.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName



/* Structure used for the callback function's user data */
typedef struct tagIMAGECBPARM
{
   HWND hwnd;     /* Current window                        */
   HDC  hdc;      /* Device context for the current window */
} IMAGECBPARM;

static L_INT EXT_CALLBACK LoadImageCB(pFILEINFO     pFileInfo,
                                      pBITMAPHANDLE pBitmap,
                                      L_UCHAR     * pBuffer,
                                      L_UINT        uFlags,
                                      L_INT         nRow,
                                      L_INT         nLines,
                                      L_VOID      * pUserData)
{
   static RECT rLeadSource;
   static RECT rLeadDest;
   IMAGECBPARM *pData = (IMAGECBPARM*)pUserData;

   /* If this is the first call (row 0), select and realize the palette */
   if((uFlags & FILEREAD_FIRSTPASS) && (uFlags & FILEREAD_FIRSTROW) )
   {
      /* Set the source rectangle to use the whole bitmap */
      SetRect(&rLeadSource, 0, 0, pFileInfo->Width, pFileInfo->Height);
      /* Set the dest rectangle to use the whole client area */
      GetClientRect(pData->hwnd, &rLeadDest);
   }

   /* Paint the buffer to the specified device context */
   L_PaintDCBuffer( pData->hdc, /* Device context - from function parameter */
                    pBitmap, /* Bitmap handle - from function parameter */
                    &rLeadSource, /* Source rect - set globally in WM_CREATE */
                    &rLeadSource, /* Source clip rect - same as source rect */
                    &rLeadDest, /* Destination rect - set globally in WM_CREATE */
                    &rLeadDest, /* Destination clip rect - same as destination rect */
                    SRCCOPY, /* ROP code for normal painting */ 
                    pBuffer, /* Input buffer - from function parameter */ 
                    nRow, /* First row in the buffer - from function parameter */ 
                   (uFlags & FILEREAD_COMPRESSED) ? -nLines : nLines );
   return( SUCCESS );
}

 L_INT LoadMemoryExample(HWND hWnd)
{
   L_INT nRet; 
   BITMAPHANDLE TmpBitmap;       /* Bitmap handle for the initial image */
   HGLOBAL hFileInMemory=NULL;   /* Memory handle                       */
   L_SIZE_T uMemSize;            /* Size of the data in memory          */
   L_UCHAR *pData;               /* Pointer to the data in memory       */
   static IMAGECBPARM UserData;  /* Structure used for the callback function's user data */
   FILEREADCALLBACK lpfnCallBack;

   /* Load a bitmap at its own bits per pixel  */
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Save the image as a CMP file in memory */
   nRet = L_SaveBitmapMemory(&hFileInMemory, &TmpBitmap, FILE_CMP, 24, QS, &uMemSize, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Free the temporary bitmap */
   L_FreeBitmap(&TmpBitmap);

   /* Get the pointer to the memory-resident file */
   pData = (L_UCHAR *) GlobalLock (hFileInMemory);

   /* Set the user data used for the callback in the nRet = L_LoadFile function */
   UserData.hwnd = hWnd;         /* Current window */
   UserData.hdc = GetDC( hWnd ); /* Device context for the current window */

   /* Set the callback function for the L_LoadFile function.*/
   lpfnCallBack = (FILEREADCALLBACK)LoadImageCB;

   /* Load the file, calling lpfnCallBack to paint the bitmap. */
   nRet = L_LoadMemory(pData,
                      &TmpBitmap, sizeof(BITMAPHANDLE),
                      0,
                      ORDER_BGR,
                      LOADFILE_ALLOCATE |  LOADFILE_STORE,
                      lpfnCallBack,
                      &UserData,
                      uMemSize,
                      NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Clean up */
   GlobalUnlock (hFileInMemory);
   GlobalFree (hFileInMemory);
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &TmpBitmap, FILE_BMP, 24, 0, NULL);
   L_FreeBitmap(&TmpBitmap);

   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}

/*******************************************************************************/
Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.