LMemoryFile::StartCompressBuffer

Summary

Initializes the buffered compression engine. The compression is then carried out using the LMemoryFile::CompressBuffer function. It is ended by the LMemoryFile::EndCompressBuffer function.

Syntax

#include "ltwrappr.h"

virtual L_INT LMemoryFile::StartCompressBuffer(uInputBytes, uOutputBytes, nOutputType, nQFactor=2, pSaveFileOption=NULL)

Parameters

L_UINT32 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.

L_UINT uOutputBytes

The size of user allocated compressed buffer.

L_INT 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.

L_INT 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 pSaveFileOption

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

Returns

Value Meaning
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.

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.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

// define user LMemoryFile class to override its CallBacks 
class LUserMemoryFileSCB : public LMemoryFile 
{ 
public: 
   LUserMemoryFileSCB () ; 
   virtual ~LUserMemoryFileSCB () ; 
   virtual L_INT CompressBufferCallBack(LBitmapBase * pLBitmap, LBuffer * pLBuffer); 
}; 
 
LUserMemoryFileSCB::LUserMemoryFileSCB() 
{ 
} 
 
LUserMemoryFileSCB::~LUserMemoryFileSCB () 
{ 
} 
 
L_INT LUserMemoryFileSCB::CompressBufferCallBack(LBitmapBase* pLBitmap, LBuffer* pLBuffer) 
{ 
   UNREFERENCED_PARAMETER(pLBitmap); 
   UNREFERENCED_PARAMETER(pLBuffer); 
 
   MessageBox(NULL, TEXT("Here Compress Buffer CallBack"), TEXT("CompressBufferCallBack"), MB_OK); 
   return SUCCESS ; 
} 
 
L_INT LMemoryFile__StartCompressBufferExample(LBitmapBase& LeadBitmap) 
{ 
   L_INT nRet; 
   L_SIZE_T zRet; 
   LUserMemoryFileSCB userLeadMemFile ; 
   LBuffer LeadBuffer ; 
   L_UINT uLineBytes ; 
   L_INT i,j; 
 
   userLeadMemFile.SetBitmap(&LeadBitmap) ; 
   userLeadMemFile.EnableCallBack(TRUE) ; 
 
   uLineBytes = LeadBitmap.GetBytesPerLine(); 
 
   // Initialize the compression engine 
   nRet = userLeadMemFile.StartCompressBuffer(16 * uLineBytes, 
                                       1024, 
                                       LEAD, 
                                       QFS, 
                                       NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   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; 
 
         memcpy(pTmp,LeadBuffer.Lock(),uLineBytes); 
         LeadBuffer.Unlock(); 
          
         pTmp+=uLineBytes; 
      } 
 
      Buffer16Rows.Unlock() ; 
         // This is the main function that will do the actual Compression. 
      nRet = userLeadMemFile.CompressBuffer(&Buffer16Rows); 
      if(nRet != SUCCESS) 
         return nRet; 
   } 
 
   // Reset the compression engine 
   nRet = userLeadMemFile.EndCompressBuffer(); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   return SUCCESS; 
} 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.