LMemoryFile::StartCompressBuffer
#include "ltwrappr.h"
virtual L_INT LMemoryFile::StartCompressBuffer(uInputBytes, uOutputBytes, nOutputType, nQFactor=2, pSaveFileOption=NULL)
| L_UINT32 uInputBytes; | /* size of the user allocated buffer that will hold the raw data */ | 
| L_UINT uOutputBytes; | /* size of the user allocated compressed buffer */ | 
| L_INT nOutputType; | /* type of compression to use */ | 
| L_INT nQFactor; | /* quality factor */ | 
| pSAVEFILEOPTION pSaveFileOption; | /* pointer to optional extended save options */ | 
Initializes the buffered compression engine. The compression is then carried out using the LMemoryFile::CompressBuffer function. It is ended by the LMemoryFile::EndCompressBuffer function.
| Parameter | Description | |
| uInputBytes | 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. | |
| uOutputBytes | The size of user allocated compressed buffer. | |
| nOutputType | Type of compression to use. Possible values are: | |
| 
 | Value | Meaning | 
| 
 | LEAD | [0] LEAD CMP compression format. | 
| 
 | JFIF | [1] JPEG File Interchange Format using YUV 4:4:4 color spacing. | 
| 
 | LEAD2JFIF | [5] JPEG File Interchange Format using YUV 4:2:2 color spacing. | 
| 
 | LEAD1JFIF | [3] JPEG File Interchange Format using YUV 4:1:1 color spacing. | 
| 
 | JTIF | [2] JPEG JTIF using YUV 4:4:4 color spacing. | 
| 
 | LEAD2JTIF | [6] JPEG JTIF using YUV 4:2:2 color spacing. | 
| 
 | LEAD1JTIF | [4] JPEG JTIF using YUV 4:1:1 color spacing. | 
| nQFactor | 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. | 
| pSaveFileOption | 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
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.
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.
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. | 
See Also
| Functions: | |
| Topics: | 
Example
// define user LMemoryFile class to override its CallBacks
class LUserMemoryFile : public LMemoryFile
{
public:
   LUserMemoryFile () ;
   virtual ~LUserMemoryFile () ;
   virtual L_INT CompressBufferCallBack(LBitmapBase L_FAR* pLBitmap,
 LBuffer L_FAR* pLBuffer);
};
LUserMemoryFile::LUserMemoryFile()
{
}
LUserMemoryFile::~LUserMemoryFile ()
{
}
L_INT LUserMemoryFile::CompressBufferCallBack(
                                LBitmapBase L_FAR* pLBitmap,
   LBuffer L_FAR* pLBuffer)
{
   MessageBox(NULL, TEXT("Here Compress Buffer CallBack"), TEXT("CompressBufferCallBack"), MB_OK);
   return SUCCESS ;
}
L_VOID TestCompBuff(LBitmapBase& LeadBitmap)
{
   LUserMemoryFile userLeadMemFile ;
   LBuffer LeadBuffer ;
   L_UINT uLineBytes ;
   L_INT i;
   userLeadMemFile.SetBitmap(&LeadBitmap) ;
   userLeadMemFile.EnableCallBack(TRUE) ;
   uLineBytes = LeadBitmap.GetWidth() * 3 ;
   
   // Initialize the compression engine
   userLeadMemFile.StartCompressBuffer(16 * uLineBytes,
                                       1024,
                                       LEAD,
                                       QFS,
                                       NULL);
   // Compress the data 
   for( i = 0; i < LeadBitmap.GetHeight(); i++) // i is incremented at the end
   {    
      // Get one line at time
      LeadBitmap.GetRow(&LeadBuffer, i);
      // This is the main function that will do the actual Compression.
      userLeadMemFile.CompressBuffer(&LeadBuffer);
   }
   // Reset the compression engine
   userLeadMemFile.EndCompressBuffer();
}