virtual L_INT LFile::StartFeedLoad(nBitsPerPixel=0, nOrder=ORDER_BGRORGRAY, uFlags=LOADFILE_ALLOCATE|LOADFILE_STORE, pLoadFileOption=NULL, pFileInfo)
Initializes a file-load process in which you control the input stream. You must call the LFile::FeedLoad function to supply buffered data, and you must call LFile::StopFeedLoad when the loading is complete.
Resulting bitmap pixel depth. Possible values are:
Value | Meaning |
---|---|
0 | Keep the original file's pixel depth (Do not convert). |
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 |
48 | 48 bits per pixel in the resulting bitmap |
64 | 64 bits per pixel in the resulting bitmap |
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/Medical 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/Medical toolkits only. |
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/Medical toolkits only. |
Binary flags that determine the behavior of LFile::FeedLoad. 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 multipage file. Use this flag only if you are creating a bitmap list using the LPlayback::Append function. |
LOADFILE_COMPRESSED | [0x0040] (Document/Medical only) 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 |
LFile::LoadFileCallBack Function from a thread other than the thread which called StartFeedLoad. This will result in better performance.
This is best if you do not use a LFile::LoadFileCallBack Function Function, or if you call the LFile::LoadFileCallBack Function function from a worker thread.
Pointer to optional extended load options. Pass NULL to use the default load options.
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 LFile::GetInfo.
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 LFile::GetInfo has been called previously, but values that affect the size of the image loaded have been changed (for example, by calling LFileSettings::SetPCDResolution or LFileSettings::SetWMFResolution). In this case the FILEINFO structure pointed to by pFileInfo will be updated with the results of LFile::GetInfo.
If LFile::GetInfo has been called prior to calling this function, and no changes have been made to the contents of the structure filled by LFile::GetInfo, 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 LFile::GetInfo 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.
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 LFile::LoadFile function, except that your code supplies the image data. The file-load process works as follows:
You call the [LFile:StartFeedLoad function to initialize the file-load process and identify the process with a handle (phLoad).
You create a buffer, and each time you fill it with information, you call the LFile::FeedLoad function, which sends the data to the file-load process just as if the data were being read from a file on disk.
Whenever it has enough data to do so, the file-load process behaves the same as in the LFile::LoadFile function. It allocates and begins loading the bitmap, according to the flags that you specify in the [LFile:StartFeedLoad function. It calls LFile::FeedLoadCallBack callback function if the callback is enabled, 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 the callback function whenever this information is available.
To end the file-load process, you call the LFile::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/Medical toolkits.
This function cannot be used in combination with the Redirect input / output functions.
Note: You should never pass an uninitialized FILEINFO structure to this function.
Win32, x64.
typedef struct tagDATA
{
L_INT32 dwSize; // Size of the buffer.
L_INT32 dwUsed; // Number of bytes used.
L_CHAR *pData; // Pointer to the buffer.
L_CHAR *pCurData; // Current pointer location.
} DATA, * LPDATA;
// define user LFile class to override CallBacks
class LUserFileSFL : public LFile
{
private:
DATA Data;
public:
HDC m_hDC ;
public:
LUserFileSFL() ;
virtual ~LUserFileSFL() ;
virtual L_INT FeedLoadCallBack(pFILEINFO pFileInfo,
LBitmapBase * pLBitmap,
LBuffer * pLBuffer,
L_UINT uFlags,
L_INT nRow,
L_INT nLines);
virtual L_INT LoadInfoCallBack(L_INT fd,pLOADINFO pInfo);
virtual L_INT RedirectOpenCallBack(
L_TCHAR *pFile,
L_INT nMode,
L_INT nShare);
virtual L_INT RedirectCloseCallBack(L_INT FD);
virtual L_UINT RedirectReadCallBack(
L_INT FD,
L_CHAR *pBuf,
L_INT nCount);
virtual L_UINT RedirectWriteCallBack(
L_INT FD,
L_CHAR *pBuf,
L_INT nCount);
virtual L_INT32 RedirectSeekCallBack(
L_INT FD,
L_INT32 lnPos,
L_INT nCount);
};
LUserFileSFL::LUserFileSFL()
{
}
LUserFileSFL::~LUserFileSFL()
{
}
L_INT LUserFileSFL::FeedLoadCallBack(pFILEINFO pFileInfo, LBitmapBase * pLBitmap,
LBuffer * pLBuffer, L_UINT uFlags,
L_INT nRow, L_INT nLines)
{
UNREFERENCED_PARAMETER(pFileInfo);
UNREFERENCED_PARAMETER(uFlags);
UNREFERENCED_PARAMETER(nLines);
pLBitmap->Paint()->SetDC(m_hDC);
pLBitmap->Paint()->PaintDCBuffer( *pLBuffer, nRow);
return SUCCESS ;
}
/* This LOADINFOCALLBACK function provides information for a raw fax
file. This example uses hard-coded and saved information. Your application
probably would get the information in some other way. */
L_INT LUserFileSFL::LoadInfoCallBack(L_INT fd,pLOADINFO pInfo)
{
UNREFERENCED_PARAMETER(fd);
// Set the LOADINFO structure's fields
pInfo->BitsPerPixel = 1;
pInfo->Flags = LOADINFO_TOPLEFT;
pInfo->Format = FILE_FAX_G3_2D;
pInfo->Height = m_pBitmap->GetHeight(); // Value set before we created the file
pInfo->Offset = 0;
pInfo->Width = m_pBitmap->GetWidth(); // Value set before we created the file
return SUCCESS;
}
/* This procedure is a replacement to the built in Open procedure.
It returns the number 5 (which looks like a file handle)
to indicate that the function was successful. */
L_INT LUserFileSFL::RedirectOpenCallBack( L_TCHAR *pFile,
L_INT nMode, L_INT nShare)
{
UNREFERENCED_PARAMETER(pFile);
UNREFERENCED_PARAMETER(nMode);
UNREFERENCED_PARAMETER(nShare);
Data.pCurData = Data.pData;
Data.dwUsed = 0;
return (5);
}
/* This procedure is a replacement to the built in Close procedure.
This may be called many times, especially by L_FileInfo, so
we need to reset the internal data structure to the defaults. */
L_INT LUserFileSFL::RedirectCloseCallBack(L_INT FD)
{
UNREFERENCED_PARAMETER(FD);
Data.pCurData = Data.pData;
Data.dwUsed = 0;
return (TRUE);
}
/* This procedure is a replacement to the built in read procedure.
It reads the data from the allocated memory and adjusts the internal data. */
L_UINT LUserFileSFL::RedirectReadCallBack( L_INT FD,
L_CHAR *pBuf, L_INT uCount)
{
UNREFERENCED_PARAMETER(FD);
// Is the request for more data than is left in memory?
if (uCount + Data.pCurData > Data.pData + Data.dwSize)
uCount = (L_UINT) (Data.dwSize - Data.dwUsed); // adjust request
// Copy data to the buffer of the caller.
memcpy (pBuf, Data.pCurData, uCount);
// Adjust internal data.
Data.pCurData += uCount;
Data.dwUsed += uCount;
return ((L_UINT)uCount);
}
/* This procedure is a replacement to the built in Write procedure.
In this example no I/O operation will be done, so we do nothing. */
L_UINT LUserFileSFL::RedirectWriteCallBack( L_INT FD,
L_CHAR *pBuf, L_INT uCount)
{
UNREFERENCED_PARAMETER(FD);
UNREFERENCED_PARAMETER(pBuf);
return ((L_UINT)uCount);
}
/* This procedure is a replacement to the built-in seek procedure.
This emulates the whole seek operation on a memory block, and
adjusts the internal data structures accordingly. */
L_INT32 LUserFileSFL::RedirectSeekCallBack( L_INT FD,
L_INT32 lnPos, L_INT nCount)
{
UNREFERENCED_PARAMETER(FD);
switch (nCount)
{
case 0: /* SEEK_SET */
Data.pCurData = Data.pData + lnPos;
Data.dwUsed = lnPos;
break;
case 1: /* SEEK_CUR */
Data.pCurData += lnPos;
Data.dwUsed += lnPos;
break;
case 2: /* SEEK_END */
if (0 <= lnPos) /* Positive value, but at the end, so go to
the end. */
lnPos = 0;
else
lnPos = -(lnPos); /* Seek backwards from the end of the buffer. */
Data.pCurData = Data.pData + Data.dwSize - lnPos;
Data.dwUsed = Data.dwSize - lnPos;
break;
}
return (L_INT) (Data.pCurData - Data.pData);
}
L_INT LFile__StartFeedLoadExample(HWND hWnd)
{
L_INT nRet;
HANDLE hf; // File handle
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
RECT rClientSize; // RECT for the client area
RECT rLeadDest; // Destination rectangle for painting
LBitmapBase LeadBitmap ;
LUserFileSFL userFile ;
DWORD wReadBytes;
if (userFile.IsLoadInfoCallBackEnabled() == FALSE)
userFile.EnableLoadInfoCallBack(TRUE);
if((userFile.GetRedirectIOFlags() & (IO_REDIRECT_ALL)) != (IO_REDIRECT_ALL))
userFile.SetRedirectIOFlags(IO_REDIRECT_ALL);
if (userFile.IsRedirectIOEnabled() == TRUE)
userFile.EnableRedirectIO(TRUE) ;
// 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")), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
/* Get the client area of the window. We assume that elsewhere in the program, the
L_FileInfo function has been used to update the FileInfo structure and that the
window dimensions have been adjusted to the bitmap's aspect ratio. */
GetClientRect(hWnd,&rClientSize);
// Make the destination rectangle for painting the same as the client area
rLeadDest = rClientSize;
userFile.SetBitmap(&LeadBitmap) ;
userFile.SetFileName(MAKE_IMAGE_PATH(TEXT("image1.cmp"))) ;
userFile.EnableCallBack(TRUE) ;
userFile.m_hDC = GetDC(hWnd) ;
// Initialize the file-load process
nRet = userFile.StartFeedLoad ( 0, ORDER_BGR, LOADFILE_ALLOCATE | LOADFILE_STORE, 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)
continue;
// Try to read the expected amount of data from the file into cBuf
nRead = (L_INT) ReadFile (hf, cBuf, nRead, &wReadBytes, NULL);
// We are finished if nothing was read
if(!nRead)
break;
LBuffer LeadBuffer(cBuf,1024) ;
// Supply image data from cBuf to the file-load process
nRet = userFile.FeedLoad ( &LeadBuffer);
if(nRet != SUCCESS)
return nRet;
// Update the amount of data actually processed so far
dwReceiveRead += (L_UINT32) nRead;
}
// Close the file and clean up the file-load process
CloseHandle (hf);
nRet = userFile.StopFeedLoad ();
if(nRet != SUCCESS)
return nRet;
// Avoid an unnecessary repaint
ValidateRect(hWnd, &rLeadDest);
ReleaseDC( hWnd, userFile.m_hDC);
return SUCCESS;
}