LFile::LoadOffset

#include "ltwrappr.h"

virtual L_INT LFile::LoadOffset(fd, nOffsetBegin, nBytesToLoad, nBitsPerPixel=0, nOrder=ORDER_BGRORGRAY, uFlags=LOADFILE_ALLOCATE|LOADFILE_STORE, pLoadFileOption=NULL, pFileInfo=NULL)

L_HFILE fd;

/* file handle */

L_SSIZE_T nOffsetBegin;

/* position of the first byte to load */

L_SSIZE_T nBytesToLoad;

/* size of the embedded file */

L_INT nBitsPerPixel;

/* resulting bitmap pixel depth */

L_INT nOrder;

/* color order */

L_UINT uFlags;

/* flag that indicates the behavior of the function */

pLOADFILEOPTION pLoadFileOption;

/* pointer to optional extended load options */

pFILEINFO pFileInfo;

/* pointer to a structure */

Loads an image from a file letting you specify the location of the image data within the file. This enables you to load an image file that is embedded in another file.

Parameter

Description

fd

The Windows file handle of the file to load.

nOffsetBegin

The position, from the beginning of the file, of the first byte to load.

nBytesToLoad

The size of the embedded image file. (The embedded file may be a record within the larger file, and in such cases, this is the record size.)

nBitsPerPixel

Resulting bitmap pixel depth. Possible values are:

 

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 the Document/Medical toolkits.

 

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.

 

0

The data is 8 bits per pixel or less.

uFlags

Binary flags that determine the behavior of LFile::LoadOffset. 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_SUPERCOMPRESSED

[0x0080] (Document/Medical only) Load 1-bit, 8-bit, and 24-bit images as super compressed. This flag is ignored if the bitmaps are not loaded as 1-bit, 8-bit, or 24-bit. Please note that 8-bit images will be loaded as grayscale, even if the source image is color.

pLoadFileOption

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

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function supports the LFile::LoadFileOffsetCallBack virtual function.

Note: More information is available in the LOADFILEOPTION structure.

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

The location of the image is specified as shown in the following simple illustration:

image\loadoff.gif

Note: For information on loading and saving large TIFF files faster, refer to Loading and Saving Large TIFF Files.

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, LBitmapBase::GetLoadStatus, LFile::LoadCMYKArray, LFile::SaveCMYKArray, LPaint::PaintDCCMYKArray, LFileSettings::GetLoadResolution, LFileSettings::GetPCDResolution, LFileSettings::GetWMFResolution, LFileSettings::SetLoadResolution, LFileSettings::SetPCDResolution, LFileSettings::SetWMFResolution, LFileSettings::GetViewMode2D, LFileSettings::GetViewPort2D, LFileSettings::SetViewMode2D, LFileSettings::SetViewPort2D, LFileSettings::GetWMFResolution, LFileSettings::SetWMFResolution

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

Example

class LUserFile : public LFile
{
   public:
      LUserFile ();
      virtual ~LUserFile ();
      virtual L_INT LoadFileOffsetCallBack(pFILEINFO pFileInfo,
      LBitmapBase * pLBitmap,
      LBuffer * pLBuffer,
      L_UINT uFlags,
      L_INT nRow,
      L_INT nLines);
      virtual L_INT SaveFileOffsetCallBack(LBitmapBase * pLBitmap,
             LBuffer * pLBuffer,
             L_UINT uRow,
             L_UINT uLines);
};
LUserFile::LUserFile ()
{
}
LUserFile::~LUserFile ()
{
}
L_INT LUserFile::LoadFileOffsetCallBack(pFILEINFO pFileInfo,
                                       LBitmapBase * pLBitmap,
                                       LBuffer * pLBuffer,
                                       L_UINT uFlags,
                                       L_INT nRow,
                                       L_INT nLines)
{
   UNREFERENCED_PARAMETER(pFileInfo);
   UNREFERENCED_PARAMETER(pLBitmap);
   UNREFERENCED_PARAMETER(pLBuffer);
   UNREFERENCED_PARAMETER(uFlags);
   UNREFERENCED_PARAMETER(nRow);
   UNREFERENCED_PARAMETER(nLines);
   MessageBox(NULL,TEXT("Here the user can set his code for LoadOffset"),
   TEXT("LoadOffset"),MB_OK);
   return SUCCESS ;
}
L_INT LUserFile:: SaveFileOffsetCallBack(LBitmapBase * pLBitmap,
                                         LBuffer * pLBuffer,
                                         L_UINT uRow,
                                         L_UINT uLines)
{
   UNREFERENCED_PARAMETER(pLBitmap);
   UNREFERENCED_PARAMETER(pLBuffer);
   UNREFERENCED_PARAMETER(uRow);
   UNREFERENCED_PARAMETER(uLines);
   MessageBox(NULL,TEXT("Here the user can set his code for SaveOffset"),
   TEXT("SaveOffset"),MB_OK);
   return SUCCESS ;
}
L_INT LFile__LoadOffsetExample(LBitmapBase& LeadBitmap,HWND hWnd)
{
   L_INT nRet; // Return value 
   L_TCHAR szMessage[80]; // Buffer for the MessageBox string
   L_HANDLE OffsetFile; // File handle 
   L_SSIZE_T SizeWritten; // Variable to be updated with the size written 
   LUserFile UserLeadFile ;
   DWORD wWriteBytes;
   UserLeadFile.SetBitmap(&LeadBitmap);
   // Create a file 
   OffsetFile = CreateFile(TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\TOFFSET.TST"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
   // Write some text in the file -- 29 characters and a terminator 
   WriteFile(OffsetFile, TEXT("This is a 29-character string"), 30, &wWriteBytes, NULL);
   // Save the image file with an offset inside the TOFFSET.TST file 
   nRet = UserLeadFile.SaveOffset((L_HFILE)OffsetFile, 30, &SizeWritten, FILE_BMP, 8, 0, SAVEFILE_FIXEDPALETTE, NULL);
   if(nRet != SUCCESS)
      return nRet;
   // Close the file 
   CloseHandle(OffsetFile);
   // Notify the user with a message box 
   if (nRet == SUCCESS)
   {
      MessageBox (hWnd, TEXT("File was saved"), TEXT("Notice"), MB_OK);
   }
   else
   {
      wsprintf (szMessage, TEXT("Error %d saving the file"), nRet);
      MessageBox (hWnd, szMessage, TEXT("Error"), MB_OK);
      return nRet;
   }
   // Free the bitmap 
   LeadBitmap.Free();
   /***** Now load the file we just saved ****/
   /* Open the file and get the file handle **/
   OffsetFile = CreateFile(TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\TOFFSET.TST"), GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
   // Load the file with a 30-byte offset
   nRet = UserLeadFile.LoadOffset((L_HFILE) OffsetFile, 30, SizeWritten,
                                  0, ORDER_BGR, LOADFILE_ALLOCATE | LOADFILE_STORE, NULL);
   // Close the file 
   CloseHandle(OffsetFile);
   /* Notify the user with a message box. The BPS in the message confirms
   that it is a new image. */
   if (nRet == SUCCESS)
   {
      wsprintf (szMessage, TEXT("New file loaded at %d BPS"), LeadBitmap.GetBitsPerPixel());
      MessageBox (NULL, szMessage, TEXT("Notice"), MB_OK);
   }
   else
   {
      wsprintf (szMessage, TEXT("Error %d loading the file"), nRet);
      MessageBox (NULL, szMessage, TEXT("Error"), MB_OK);
   }
   return SUCCESS;
}