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.

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 is 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

LTFIL
File format DLLs

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:

Class Members

Topics:

Raster Image Functions: Saving Files

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;
   userLeadMemFile.SetBitmap(&LeadBitmap) ;
   userLeadMemFile.EnableCallBack(TRUE) ;
   uLineBytes = LeadBitmap.GetWidth() * 3 ;
   // Initialize the compression engine
   nRet = userLeadMemFile.StartCompressBuffer(16 * uLineBytes,
                                       1024,
                                       LEAD,
                                       QFS,
                                       NULL);
   if(nRet != SUCCESS)
      return nRet;
   // Compress the data 
   for( i = 0; i < LeadBitmap.GetHeight(); i++) // i is incremented at the end
   {
      // Get one line at time
      zRet = LeadBitmap.GetRow(&LeadBuffer, i);
      if(zRet < 1)
         return (L_INT) zRet;
      // This is the main function that will do the actual Compression.
      nRet = userLeadMemFile.CompressBuffer(&LeadBuffer);
      if(nRet != SUCCESS)
         return nRet;
   }
   // Reset the compression engine
   nRet = userLeadMemFile.EndCompressBuffer();
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}