#include "l_bitmap.h"

L_LTFIL_API L_INT L_StartFeedLoad(pBitmap, uStructSize, nBitsPerPixel, nOrder, uFlags, pfnCallback, pUserData, phLoad, pLoadOptions, pFileInfo)

Initializes a file-load process in which you control the input stream. You must call the L_FeedLoad function to supply buffered data, and you must call L_StopFeedLoad when loading is complete.



Pointer to the bitmap handle to load the image to.

L_UINT uStructSize

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

L_INT nBitsPerPixel

Pixel depth of the resulting bitmap. The following are valid values:

Value Meaning
0 Keep the original file's pixel depth (Do not convert). For more information, see A special note about loading 12- and 16-bit grayscale images.
1 to 8 The specified bits per pixel in the resulting bitmap
12 12 bits per pixel in the resulting bitmap.
16 16 bits per pixel in the resulting bitmap
24 24 bits per pixel in the resulting bitmap
32 32 bits per pixel in the resulting bitmap


L_INT 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 the 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 the 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 the Document and Medical Imaging toolkits.

L_UINT uFlags

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

Value Meaning
LOADFILE_ALLOCATE [0x0001] Allocate memory for the specified bitmap.
LOADFILE_STORE [0x0002] Load data into the specified bitmap. (This takes place in addition to the actions of your callback function.)
LOADFILE_FIXEDPALETTE [0x0004] Force a palletized image to be dithered to a fixed palette.
LOADFILE_NOINTERLACE [0x0008] Pass 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] Load all pages of a multipage file. Use this flag only if you are creating a bitmap list using the L_AppendPlayback function.
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.
LOADFILE_CALLINANYTHREAD 0x00004000] If this flag is set, LEADTOOLS will call the [FILEREADCALLBACK Function from a thread other than the thread which called L_StartFeedLoad. This will result in better performance.

This is best if you do not use a FILEREADCALLBACK Function, or if you call the FILEREADCALLBACK function from a worker thread.


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.

L_VOID* pUserData

Void pointer that allows passing 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 needed. 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 the variable or structure.

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


Handle that identifies the loading process. Use this handle with the L_FeedLoad and L_StopFeedLoad functions.


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


Pointer to a FILEINFO structure. This structure can contain file information used in loading an image, or it can 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.


Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.


This file-load process is useful when receiving transmitted images, such as those on the Internet. It works the same way as the L_LoadFile function, except that your code supplies the image data. The file-load process works as follows:

  1. Call the L_StartFeedLoad function to initialize the file-load process and identify the process with a handle phLoad.

  2. Create a buffer, and each time you fill it with information, call the L_FeedLoad function, which sends the data to the file-load process just as if the data were being read from a file on disk.

  3. Whenever it has enough data to do so, the file-load process behaves the same as in the L_LoadFile function. It allocates and begins loading the bitmap, according to the flags that you specify in the L_StartFeedLoad function. It calls your callback function, if one is specified, whenever it has enough data in its input buffer.

    The file-load process does not update information in the bitmap handle until it has received enough information to do so. (Usually, the information, such as the bitmap height and width, is in the file header.) The file-load process will make the first call to your callback function whenever this information is available.

  4. To end the file-load process, call the L_StopFeedLoad function, which cleans up the process. If you call this function before supplying the complete file, it will successfully clean up the process, but will return a file-read error. You should trap the error if the load is canceled purposely.

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

This function cannot be used in combination with L_RedirectIO.

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

Required DLLs and Libraries


Win32, x64, Linux.

See Also




For complete sample code, refer to the FEEDLOAD example.
This example demonstrates the feed-load feature by using the Windows
GetTickCount function to simulate receiving a transmitted image.
This example also uses 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.

/* Structure used for the callback function's user data */ 
typedef struct tagIMAGECBPARM 
   HWND hwnd;     /* Current window */ 
   HDC hdc;       /* Device context for the current window */ 
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; 
   /* 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 StartFeedLoadExample(HWND hWnd, pBITMAPHANDLE pBitmap) 
   L_INT nRet; 
   HANDLE hf;                    /* File handle */ 
   HGLOBAL hLoad;                /* Handle that identifies the loading process */ 
   L_UCHAR cBuf[1024];           /* Buffer for receiving data */ 
   L_INT nRead;                  /* Amount of data read in one pass of the reading loop */ 
   L_UINT32 dwBaseTime;          /* Value of the first call to GetTickCount */ 
   L_UINT32 dwReceiveTotal;      /* Data received so far from the simulated transmission */ 
   L_UINT32 dwReceiveRead;       /* Data actually processed so far */ 
   static IMAGECBPARM UserData;  /* Structure used for the callback function's user data */ 
   /* Initialize variables used for simulating an incoming transmission */ 
   dwBaseTime = GetTickCount(); 
   dwReceiveTotal = 0; 
   dwReceiveRead = 0; 
   /* Open the file to be read */ 
   hf = CreateFile(MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), 
   /* Set the user data used for the callback in the L_StartFeedLoad function */ 
   UserData.hwnd = hWnd;         /* Current window */ 
   UserData.hdc = GetDC( hWnd ); /* Device context for the current window */ 
   /* Initialize the file-load process */ 
   nRet = L_StartFeedLoad (pBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR,  
      LoadImageCB, &UserData, &hLoad, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Use the Windows GetTickCount function to simulate receiving a transmitted image */ 
   for( ; ; ) 
      /* Calculate the data received so far, using a simulated baud rate of 28800 */ 
      dwReceiveTotal = ((GetTickCount() - dwBaseTime) * (28800 / 100) / 100); 
      /* Initialize the amount of data to read in this pass */ 
      nRead = (L_INT) min(dwReceiveTotal - dwReceiveRead, (L_UINT32) sizeof(cBuf)); 
      /* Do nothing if no data was received in this pass */ 
      if(nRead == 0) 
      /* Try to read the expected amount of data from the file into cBuf */ 
      DWORD BytesRead; 
      ReadFile (hf, cBuf, nRead, &BytesRead, NULL); 
      /* We are finished if nothing was read */ 
      /* Supply image data from cBuf to the file-load process */ 
      L_FeedLoad (hLoad, cBuf, BytesRead); 
      /* Update the amount of data actually processed so far */ 
      dwReceiveRead += (L_UINT32) BytesRead; 
   /* Close the file and clean up the file-load process */ 
   CloseHandle (hf); 
   L_StopFeedLoad (hLoad); 
   return SUCCESS; 

Help Version 21.0.2021.4.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help