L_SaveFileBuffer
#include "l_bitmap.h"
L_INT EXT_FUNCTION L_SaveFileBuffer(pBuffer, uInitialBufferSize, puFinalFileSize, pBitmap, nFormat, nBitsPerPixel, nQFactor, uFlags, pfnFileSaveCB, pfnSaveBufferCB, pUserData, pSaveOptions)
/* pointer to a memory buffer */ | |
L_UINT32 uInitialBufferSize; |
/* size of the memory buffer in bytes */ |
/* pointer to a variable */ | |
pBITMAPHANDLE pBitmap; |
/* pointer to the bitmap handle */ |
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 pfnFileSaveCB; |
/* optional callback function */ |
SAVEBUFFERCALLBACK pfnSaveBufferCB; |
/* optional callback function */ |
/* pointer to more parameters for the callback */ | |
pSAVEFILEOPTION pSaveOptions; |
/* pointer to optional extended save options */ |
Saves a bitmap to a file in a memory buffer that the user must allocate, using input data that the FILESAVECALLBACK callback function supplies. The output can be in any of the supported compressed or uncompressed file formats.
Parameter |
Description |
|
pBuffer |
Pointer to a buffer allocated by the user. Note that if this buffer is not large enough to accommodate the file in memory, the SAVEBUFFERCALLBACK is called to allow the user to reallocate the buffer. |
|
uInitialBufferSize |
Size of pBuffer in bytes. Note that the buffer size can be reallocated in the pfnSaveBufferCB callback. |
|
puFinalSize |
Pointer to a variable that will contain the final size of the file in memory. This is not the final size of the allocated buffer, which may be larger than the memory 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 the 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 Formats of Output Files. |
|
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 closest 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_SaveFileBuffer. 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). |
pfnFileSaveCB |
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 syntax described in FILESAVECALLBACK Function. |
|
pfnSaveBufferCB |
Optional callback function for reallocating the buffer if it is not large enough to accommodate the save. NULL can be passed for this parameter. However, if NULL is passed for this parameter and the buffer is not large enough, the function will fail. |
|
|
The callback function must adhere to the syntax described in SAVEBUFFERCALLBACK 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 L_FAR *. 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
L_SaveFileBuffer saves a bitmap to a file in a memory buffer that the user must allocate. The output can be in any of the supported compressed or uncompressed file formats. This function is similar to L_SaveFileMemory, except the user is responsible for allocating/reallocating buffers. The SAVEBUFFERCALLBACK notifies the user if the buffer is not large enough. The user can then reallocate the buffer. For more information, see SAVEBUFFERCALLBACK.
If the user wants to allocate a buffer that is large enough to hold the file in memory, an upper bound on the file size can be estimated by the following formula:
RequiredBytes = (Image Width) * (Image Height) * (BitsPerPixel) / 8
Note that this is an estimate—this does not include the size of the file header, and it does not take into account any compression. It is best to use a SAVEBUFFERCALLBACK so that the user can be notified if the buffer is not large enough.
Support for 12 and 16-bit grayscale images is only available in the Document/Medical Imaging editions .
This function cannot be used in combination with L_RedirectIO.
Note: More options are available in the SAVEFILEOPTION structure.
Note: FPX, PCD, AWD and AVI files cannot be saved to memory.
This function supports signed data images, but only DICOM and TIFF formats support signed data. This function will return an error code if you attempt to save a signed image to a format other than DICOM or TIFF.
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 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 95 / 98 / Me, Windows 2000 / XP, Windows CE.
See Also
Functions: |
L_SaveBitmapBuffer, L_SaveFileMemory, L_SaveBitmapMemory, L_LoadFile, L_LoadFileOffset, L_GetCompressFileStamp, L_SaveBitmap, L_SaveFileOffset, L_SetLoadResolution, L_SetPCDResolution, L_SetWMFResolution, L_SetLoadInfoCallback |
|
For Vector files: L_2DGetViewMode, L_2DGetViewPort, L_2DSetViewMode, L_2DSetViewPort |
Topics: |
|
|
|
|
|
|
|
|
|
|
Example
//This example loads the file 'pszFile', and then saves it to a memory buffer
//that the caller allocates. Note that when the buffer becomes filled,
//the ExampleSaveBufferCB callback is called to notify the caller to reallocate
//the buffer. After the save is completed, the size of the file in memory is displayed.
//The image 'pszFile' is flipped, and saved as the second page of the memory buffered TIF
//Finally, the second page of the memory buffer containing the file is loaded into pBitmap
typedef struct _tagMYBUFFER
{
L_CHAR *pBuffer;
L_UINT32 dwBufferSize;
} MYBUFFER, *pMYBUFFER;
L_INT SampleSaveFileBuffer(L_TCHAR *pszFile, pBITMAPHANDLE pBitmap)
{
L_INT nRet;
BITMAPHANDLE Bitmap;
L_UINT32 dwFinalFileSize;
L_TCHAR szMsg[100];
SAVEFILEOPTION SaveFileOption;
LOADFILEOPTION LoadFileOption;
MYBUFFER MyBuffer;
MyBuffer.dwBufferSize = 100;
MyBuffer.dwBufferSize = 0;
MyBuffer.pBuffer = NULL;
nRet = L_LoadBitmap(pszFile, &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
if (nRet != SUCCESS)
return nRet;
MyBuffer.pBuffer = (L_CHAR L_FAR *)malloc(MyBuffer.dwBufferSize); //large enough to hold rgbw.bmp
if (MyBuffer.pBuffer == NULL)
return FAILURE;
L_GetDefaultSaveFileOption(&SaveFileOption, sizeof(SAVEFILEOPTION));
L_GetDefaultLoadFileOption(&LoadFileOption, sizeof(LOADFILEOPTION));
SaveFileOption.PageNumber = 1;
L_SaveFileBuffer(MyBuffer.pBuffer,
MyBuffer.dwBufferSize,
&dwFinalFileSize,
&Bitmap,
FILE_TIF,
0,
0,
0,
NULL,
ExampleSaveBufferCB,
&MyBuffer,
&SaveFileOption);
wsprintf(szMsg, TEXT("Buffer Size After First Save: %d"), dwFinalFileSize);
MessageBox(NULL, szMsg, TEXT(""), MB_OK);
L_FlipBitmap(&Bitmap);
SaveFileOption.PageNumber = 2;
L_SaveFileBuffer(MyBuffer.pBuffer,
MyBuffer.dwBufferSize,
&dwFinalFileSize,
&Bitmap,
FILE_TIF,
0,
0,
0,
NULL,
ExampleSaveBufferCB,
&MyBuffer,
&SaveFileOption);
wsprintf(szMsg, TEXT("Final Buffer Size: %d"), dwFinalFileSize);
MessageBox(NULL, szMsg, TEXT(""), MB_OK);
LoadFileOption.PageNumber = 2;
nRet = L_LoadBitmapMemory (MyBuffer.pBuffer, pBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, dwFinalFileSize, &LoadFileOption, NULL);
free(MyBuffer.pBuffer);
return nRet;
}