virtual L_INT LMemoryFile::StartCompressBuffer(uInputBytes, uOutputBytes, nOutputType, nQFactor=2, pSaveFileOption=NULL)
The size of user allocated buffer that will hold the raw data. This has to be a multiple of 8 lines or 16 lines depending on the output compression method specified. For LEAD1JTIF, LEAD1JFIF, or any LEAD Qfactor that is greater than 100, or a predefined setting of MC, SQT, or MCQ, you must allocate 16-line multiples. For all other compression factors and methods, manually set or predefined, 8-line multiples are required.
To simplify your coding, you can always allocate 16-line multiples.
The size of user allocated compressed buffer.
Type of compression to use. Possible values are:
|LEAD|| LEAD CMP compression format.|
|JFIF|| JPEG File Interchange Format using YUV 4:4:4 color spacing.|
|LEAD2JFIF|| JPEG File Interchange Format using YUV 4:2:2 color spacing.|
|LEAD1JFIF|| JPEG File Interchange Format using YUV 4:1:1 color spacing.|
|JTIF|| JPEG JTIF using YUV 4:4:4 color spacing.|
|LEAD2JTIF|| JPEG JTIF using YUV 4:2:2 color spacing.|
|LEAD1JTIF|| JPEG JTIF using YUV 4:1:1 color spacing.|
Compression quality factor to use for the specified compression format. This value can be any integer ranging from 2 to 255 for all the supported compression methods.
Alternatively, for LEAD CMP compression only, LEADTOOLS provides enhanced Q factors which are defined as follows:
|PQ1||[-1] Perfect Quality compression Option 1.|
|PQ2||[-2] Perfect Quality compression Option 2.|
|QFS||[-3] Quality Far more important than Size.|
|QMS||[-4] Quality More important than Size.|
|QS||[-5] Quality and Size are equally important.|
|SQS||[-6] Size more important than Quality - Sharp.|
|SQT||[-7] Size more important than Quality - less Tilling.|
|MCQ||[-8] Maximum Compression, keeping quality as good as possible.|
|MC||[-9] Maximum Compression.|
Pointer to optional extended save options. Pass NULL to use the default save options.
|SUCCESS||The function was successful.|
|< 1||An error occurred. Refer to Return Codes.|
You must declare and initialize m_pBitmap calling this function, but you do not have to allocate the bitmap. In the bitmap handle, the Order field must be ORDER_BGR, and the ViewPerspective field must be TOP_LEFT. Then, the data that you put into the input buffer must be BGR and loaded from top left.
The compression process starts after the first call to LMemoryFile::CompressBuffer. You must override LMemoryFile::CompressBufferCallBack, which will be called when the output buffer is filled with compressed data or after completing the compression process. The callback function is responsible for emptying the output buffer storing it, sending it, or doing other processing.
NOTE: 4:1:1 and 4:2:2 formats use subsampling for the color components. In the case of 4:1:1, the color components for 4 pixels are averaged during compression. This will cause a color shift, but the shift is tolerable for low compression ratios. If you have high compression and repeated savings, then the color shift will increase. Due to this characteristic of the JPEG algorithm, the only ways to avoid this are to: (a) use 4:4:4 (which has no subsampling), or (b) avoid repeated load and resave.
This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.
// define user LMemoryFile class to override its CallBacks
class LUserMemoryFileSCB : public LMemoryFile
LUserMemoryFileSCB () ;
virtual ~LUserMemoryFileSCB () ;
virtual L_INT CompressBufferCallBack(LBitmapBase * pLBitmap, LBuffer * pLBuffer);
L_INT LUserMemoryFileSCB::CompressBufferCallBack(LBitmapBase* pLBitmap, LBuffer* pLBuffer)
MessageBox(NULL, TEXT("Here Compress Buffer CallBack"), TEXT("CompressBufferCallBack"), MB_OK);
return SUCCESS ;
L_INT LMemoryFile__StartCompressBufferExample(LBitmapBase& LeadBitmap)
LUserMemoryFileSCB userLeadMemFile ;
LBuffer LeadBuffer ;
L_UINT uLineBytes ;
uLineBytes = LeadBitmap.GetBytesPerLine();
// Initialize the compression engine
nRet = userLeadMemFile.StartCompressBuffer(16 * uLineBytes,
if(nRet != SUCCESS)
LBuffer Buffer16Rows(16 * uLineBytes) ;
for( j = 0; j < LeadBitmap.GetHeight(); j+=16)
L_CHAR* pTmp = (L_CHAR*)Buffer16Rows.Lock() ;
// Compress the data
for( i = 0; i < 16 && (j + i < LeadBitmap.GetHeight()); i++)
// Get one line at time
zRet = LeadBitmap.GetRow(&LeadBuffer, j+i);
if(zRet < 1)
return (L_INT) zRet;
// This is the main function that will do the actual Compression.
nRet = userLeadMemFile.CompressBuffer(&Buffer16Rows);
if(nRet != SUCCESS)
// Reset the compression engine
nRet = userLeadMemFile.EndCompressBuffer();
if(nRet != SUCCESS)
Medical Web Viewer .NET
.NET, Java, Android, and iOS/macOS Assemblies
C API/C++ Class Libraries