LFile::StartFeedLoad

#include "ltwrappr.h"

virtual L_INT LFile::StartFeedLoad(nBitsPerPixel=0, nOrder=ORDER_BGRORGRAY, uFlags=LOADFILE_ALLOCATE|LOADFILE_STORE, pLoadFileOption=NULL)

L_INT nBitsPerPixel;

/* resulting bitmap pixel depth */

L_INT nOrder;

/* desired color order */

L_UINT uFlags;

/* flags that determine the behavior of LFile::FeedLoad */

pLOADFILEOPTION pLoadFileOption;

/* pointer to optional extended load options */

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.

Parameter

Description

nBitsPerPixel

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 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 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.

uFlags

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.

pLoadFileOption

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

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

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:

1.

You call the LFile::StartFeedLoad function to initialize the file-load process and identify the process with a handle (phLoad).

2.

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.

3.

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.

4.

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.

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.

See Also

Functions:

Class Members

Topics:

Raster Image Functions: Loading Files

 

Raster Image Functions: Redirecting Input and Output

 

Raster Image Functions: Input and Output

 

Loading and Saving Images

Example

typedef struct tagDATA
{
   L_INT32 dwSize;              // Size of the buffer. 
   L_INT32 dwUsed;              // Number of bytes used. 
   L_CHAR L_HUGE *pData;        // Pointer to the buffer. 
   L_CHAR L_HUGE *pCurData;     // Current pointer location.
} DATA, L_FAR * LPDATA;

// define user LFile class to override CallBacks

class LUserFile : public LFile
{
private:
   DATA Data;

public:
   HDC      m_hDC ;
public:
   LUserFile() ;
   virtual ~LUserFile() ;
   virtual L_INT FeedLoadCallBack(pFILEINFO pFileInfo,
                                  LBitmapBase L_FAR* pLBitmap,
                                  LBuffer L_FAR* 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 L_FAR *pFile,
                                       L_INT nMode,
                                       L_INT nShare);
   virtual  L_INT    RedirectCloseCallBack(L_INT FD);
   virtual  L_UINT   RedirectReadCallBack(
                                       L_INT FD,
                                       L_CHAR L_FAR *pBuf,
                                       L_INT nCount);
   virtual  L_UINT   RedirectWriteCallBack(
                                          L_INT FD,
                                          L_CHAR L_FAR *pBuf,
                                          L_INT nCount);
   virtual  L_INT32  RedirectSeekCallBack(
                                       L_INT FD,
                                       L_INT32 lnPos,
                                       L_INT nCount);
};

LUserFile::LUserFile()
{
}

LUserFile::~LUserFile()
{
}

L_INT LUserFile::FeedLoadCallBack(pFILEINFO pFileInfo, LBitmapBase L_FAR* pLBitmap,
                                  LBuffer L_FAR* pLBuffer, L_UINT uFlags,
                                  L_INT nRow, L_INT 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 LUserFile::LoadInfoCallBack(L_INT fd,pLOADINFO pInfo)
{
   // 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 LUserFile::RedirectOpenCallBack( L_TCHAR L_FAR *pFile, 
                                       L_INT nMode, L_INT 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 LUserFile::RedirectCloseCallBack(L_INT 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 LUserFile::RedirectReadCallBack( L_INT FD, 
                                        L_CHAR L_FAR *pBuf, L_INT uCount)
{
   // 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 LUserFile::RedirectWriteCallBack( L_INT FD, 
                                         L_CHAR L_FAR *pBuf, L_INT uCount)
{
   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 LUserFile::RedirectSeekCallBack( L_INT FD, 
                                         L_INT32 lnPos, L_INT nCount)
{
   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 (Data.pCurData - Data.pData);
}

L_VOID TestFunction(HWND hWnd)
{
   HFILE          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 ;
   LUserFile      userFile ;
   L_INT          nRet = 0 ;
   
   if (userFile.IsLoadInfoCallBackEnabled() == FALSE)
      userFile.EnableLoadInfoCallBack(TRUE);

   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 
#ifdef UNICODE

   hf = _wopen (TEXT("IMAGE3.CMP"), OF_READ);
#else

   hf = _lopen ("IMAGE3.CMP", OF_READ);
#endif
   /* 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(TEXT("image1.cmp")) ;
   userFile.EnableCallBack(TRUE) ;
   
   userFile.m_hDC = GetDC(hWnd) ;

   // Initialize the file-load process
   userFile.StartFeedLoad ( 0, ORDER_BGR, 
                  LOADFILE_ALLOCATE |  LOADFILE_STORE, NULL);

   // 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) _lread (hf, cBuf, nRead);
      // We are finished if nothing was read
      if(!nRead)
         break;

      LBuffer  LeadBuffer(cBuf,1024) ;
      // Supply image data from cBuf to the file-load process
      userFile.FeedLoad ( &LeadBuffer);

      // Update the amount of data actually processed so far
      dwReceiveRead += (L_UINT32) nRead;
   }

   // Close the file and clean up the file-load process
   _lclose (hf);
   userFile.StopFeedLoad ();

   // Avoid an unnecessary repaint
   ValidateRect(hWnd, &rLeadDest);

   ReleaseDC( hWnd, userFile.m_hDC);
   return;
}