L_SaveFileOffset

#include "l_bitmap.h"

L_LTFIL_API L_INT L_SaveFileOffset(fd, nOffsetBegin, nSizeWritten, pBitmap, nFormat, nBitsPerPixel, nQFactor, uFlags, pfnCallback, pUserData, pSaveOptions)

L_HFILE fd;

/* Windows file handle of the file to save */

L_SSIZE_T nOffsetBegin;

/* offset within the file to embed the image file */

L_SSIZE_T* nSizeWritten;

/* address of a file-size variable to be updated */

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap */

L_INT nFormat;

/* output file format */

L_INT nBitsPerPixel;

/* resulting file's pixel depth */

L_INT nQFactor;

/* quality factor */

L_UINT uFlags;

/* flags that determine function behavior */

FILESAVECALLBACK pfnCallback;

/* optional callback function */

L_VOID* pUserData;

/* pointer to more parameters for the callback */

pSAVEFILEOPTION pSaveOptions;

/* pointer to optional extended save options */

Saves a bitmap to a file in any supported format, using a callback function, and letting you specify an offset within the file to begin saving. This enables you to embed an image file in another file.

Parameter

Description

fd

The Windows file handle of the file to save.

nOffsetBegin

The offset within the specified file to embed the saved image file. For example, if you specify 5, then 5 bytes of other data will precede the embedded file.

nSizeWritten

Address of a variable to be updated with the size of the embedded image file.

pBitmap

Pointer to the bitmap handle that describes the data to be saved. The bitmap handle can contain the actual data, but does not have to, since your callback function can supply the data.

 

However, the bitmap handle must contain values for the following fields: Width, Height, BitsPerPixel, BytesPerLine, nColors, ViewPerspective, Order, and DitheringMethod. (The BytesPerLine value must be a multiple of four.)

nFormat

Output file format. For valid values, refer to Files To Be Included With Your Application.

nBitsPerPixel

Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Formats of Output Files. If nBitsPerPixel is 0, the file will be stored using the closet BitsPerPixel value supported by that format. For example, if a file format supports 1, 4, and 24 BitsPerPixel, and the pBitmap->BitsPerPixel is 5, the file will be stored as 24 bit. Likewise, if the pBitmap->BitsPerPixel is 2, the file will be stored as 4 bit.

nQFactor

This parameter is used when saving an image file to FILE_CMP, FILE_JPEG, FILE_JPEG_411, FILE_JPEG_422, FILE_TIF_JPEG, FILE_LEAD1JTIF, FILE_LEAD2JTIF, FILE_FPX_JPEG_QFACTOR, and FILE_EXIF_JPEG. Qfactor is a number that determines the degree of loss in the compression process.

 

For possible values, refer to Compression Quality Factors.

uFlags

Binary flags that determine the behavior of L_SaveFile. You can specify one of the following values:

 

Value

Meaning

 

SAVEFILE_FIXEDPALETTE

[0x0001] The function uses the fixed palette for images that are saved as 8 bits per pixel or less.

 

SAVEFILE_OPTIMIZEDPALETTE

[0x0002] The function uses the individual image's optimized palette for images that are saved as 8 bits per pixel or less. The optimized palette must be included in the bitmap handle.

 

SAVEFILE_MULTIPAGE

[0x0004] The function saves the image in a multi-page file. It appends the image as the last one in the file. You can save multi-page images in PCX, GIF, and most TIFF file formats (including JTIF, but excluding EXIF).

pfnCallback

Optional callback function for additional processing.

 

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

 

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

 

The callback function must adhere to the syntax described in FILESAVECALLBACK 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.

pSaveOptions

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

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function overwrites existing data at the specified location in the file.

You can use this function to update an image that you loaded with the L_LoadFileOffset function.

The offset is specified in bytes. You must open the file and get a Windows file handle before calling this function. You must also declare a variable to receive the resulting size of the embedded image file (in the nSizeWritten parameter).

If you use a callback and save the bitmap as a MacPaint (MAC) file, the image to be saved must have a width of 576 and a height of 720 (the required dimensions of that format).

Support for writing AVI files is only available in the Multimedia toolkits.

Note:

More options are available in the SAVEFILEOPTION structure.

This function supports signed data images, but only DICOM and TIFF formats support signed data. This function will return an error if you attempt to save a signed image to a format other than DICOM or TIFF.

For information on saving bitmaps that have been window leveled, refer to Saving Window-Leveled Bitmaps.

If the bitmap has a region, the region stored in the bitmap will be saved, if the image is saved as one of the TIFF file formats.

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

Windows 2000 / XP/Vista, Windows CE.

See Also

Functions:

L_SaveBitmap, L_SaveFile, L_SaveFile, L_FileConvert, L_SetComment, L_DlgSave, L_SaveFileMemory, L_ReadFileCommentOffset

Topics:

Raster Image Functions: Saving Files

 

Raster Image Functions: Maintaining File Comments and Tags

 

Raster Image Functions: Low-Level Compression Functions

 

Raster Image Functions: Loading and Saving Stamp Images

 

Raster Image Functions: Redirecting Input and Output

 

Raster Image Functions: Input and Output

 

Loading and Saving Images

 

Saving a Region

 

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 OFFSET example. This example saves an image file with a 30-byte offset. It then loads the file that it just saved. Note that the zSizeWritten variable from the save is reused when loading. A real application would have to get this information another way when loading.

 
 L_INT SaveFileOffsetExample(pBITMAPHANDLE LeadBitmap)
{
   L_INT nRet;              /* Return value                     */
   L_TCHAR szMessage[80];   /* Buffer for the MessageBox string */
   HANDLE  OffsetFile=NULL; /* File handle                      */
   L_SSIZE_T zSizeWritten;  /* Variable to be updated with the size written */
   DWORD     dwSizeWrite;

   /* Create a file */
   OffsetFile = CreateFile(TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\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, &dwSizeWrite, NULL);

   /* Save the image file with an offset inside the TOFFSET.TST file */
   nRet = L_SaveFileOffset((L_HFILE)OffsetFile, 30, &zSizeWritten, LeadBitmap, FILE_BMP, 8, 0, SAVEFILE_FIXEDPALETTE, NULL, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Close the file */
   CloseHandle(OffsetFile);

   /* Notify the user with a message box */
   if (nRet == SUCCESS)
   {
      MessageBox (NULL, TEXT("File was saved"), TEXT("Notice"), MB_OK);
   }
   else
   {
      wsprintf (szMessage, TEXT("Error %d saving the file"), nRet);
      MessageBox (NULL, szMessage, TEXT("Error"), MB_OK);
      return nRet;
   }

   /* Free the bitmap */
   L_FreeBitmap (LeadBitmap);

   /* Now load the file we just saved */
   /* Open the file and get the file handle */
   OffsetFile = CreateFile (TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\TOFFSET.TST"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

   /* Load the file with a 30-byte offset */
   nRet = L_LoadFileOffset((L_HFILE) OffsetFile, 30, zSizeWritten,
                           LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR,
                           LOADFILE_ALLOCATE | LOADFILE_STORE,
                           NULL, NULL, NULL, 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->BitsPerPixel);
      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 nRet;
   }
   return SUCCESS;
}