#include "l_bitmap.h"
L_LTIMGOPT_API L_INT L_OptOptimizeBuffer(pOrgImgBuffer, uOrgImgBufferSize, phOptImgBuffer, puOptImgBufferSize, pOptImgOptions, pfnOptBufferCB, pUserData)
Optimizes a supported image format buffer using the passed optimization options.
Pointer to the original image buffer in memory. The image format in memory should be one of the LEAD Image optimizer supported formats.
Size, in bytes, of the original image in memory, which is referenced by the pOrgImgBuffer
parameter.
Address of a memory handle to be updated by the optimized image buffer. The user is responsible for freeing it by calling the GlobalFree Windows function.
Pointer to a variable to be updated with the size of the optimized image buffer in memory, which is referenced by phOptImgBuffer
.
Pointer to an OPTIMIZEIMAGEOPTIONS structure that contains the options used in optimization. Pass NULL to use the default optimization options.
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 function prototype described in OPTIMIZEBUFFERCALLBACK Function.
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.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
This function optimizes the specified buffer and reduces its size, based on the specified optimization options.
The function will initialize the phOptImgBuffer
handle and allocate the storage necessary to hold the optimized image. Since the function allocates storage to hold the optimized image, the user must free the allocated memory by calling the Windows GlobalFree function.
Note that the image buffer to be optimized should be one of the LEAD Image optimizer supported formats otherwise the function will return an Error.
You can optimize an image buffer in memory as follows:
Save the image to be optimized (the original image) in memory, and get a pointer to the first byte of this image. Pass this pointer as the pOrgImgBuffer
parameter. Pass the size, in bytes, of the image in memory as the uOrgImgBufferSize
parameter.
Declare a memory handle (HGLOBAL) variable and pass its address as the phOptImgBuffer parameter. This function will allocate and unlock the memory needed to save the optimized image buffer.
Declare a long integer (L_UINT32) variable. Pass the address of this variable as the puOptImgBufferSize
parameter. This function will update this variable with the size, in bytes, of the optimized image buffer.
Determine the optimization options to use, by doing one of the following:
Pass NULL in the pOptImgOptions
parameter to optimize the image buffer using the default optimization options.
Get the default optimization options by calling L_OptGetDefaultOptions function, and update the structure values as you like. Pass the address of the updated optimization options structure in the pOptImgOptions parameter.
Call this function to optimize the image buffer and update the phOptImgBuffer
and puOptImgBufferSize variables with the optimized buffer and buffer size.
This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.
Required DLLs and Libraries
Win32, x64.
This Function will get the default optimization options to optimize the image buffer pointed by phOrgImgBuffer parameter.
L_INT EXT_CALLBACK fnOptBufferCB(L_INT nPercent,
L_VOID * pUserData)
{
UNREFERENCED_PARAMETER(pUserData);
L_TCHAR buf[256]; // Message buffer
wsprintf(buf, TEXT("%d"), nPercent);
MessageBox(NULL, buf, TEXT("Optimizing"), MB_OK);
return SUCCESS;
}
L_INT OptOptimizeBufferExample(L_UCHAR * phOrgImgBuffer,
L_SIZE_T uOrgImgBufferSize,
L_VOID * pUserData)
{
HGLOBAL hOptImgBuffer = NULL; /* Handle to the Optimized Buffer in Memory*/
L_SIZE_T uOptImgBufferSize = 0; /* size of the optimized buffer in Memory*/
OPTIMIZEIMAGEOPTIONS OptImgOptions; /* optimization options structure*/
L_SIZE_T * pOptImgBuffer = NULL;
// Get the default optimization options.
L_INT nRet = L_OptGetDefaultOptions(&OptImgOptions, sizeof(OPTIMIZEIMAGEOPTIONS));
if(nRet == SUCCESS)
{
// Optimize the image buffer
nRet = L_OptOptimizeBuffer(phOrgImgBuffer,
uOrgImgBufferSize,
&hOptImgBuffer, // to be updated.
&uOptImgBufferSize, // to be updated.
&OptImgOptions,
fnOptBufferCB,
pUserData);
if(nRet == SUCCESS)
{
// To work on the optimized buffer, We have to lock it.
pOptImgBuffer = (L_SIZE_T *) GlobalLock(hOptImgBuffer);
if(pOptImgBuffer)
{
/* Now, pOptImgBuffer is ready to work on; for example you can create a disk file
and dump this buffer to it.*/
// .
// .
// .
// Unlock the Memory Buffer.
GlobalUnlock(hOptImgBuffer);
// Free the Meory Buffer allocated by L_OptOptimizeBuffer function.
GlobalFree(hOptImgBuffer);
}
}
}
return nRet;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document