LBase::DecodeABIC

#include "ltwrappr.h"

static L_INT LBase::DecodeABIC(pInputData, nLength, ppOutputData, nAlign, nWidth, nHeight, bBiLevel);

L_UCHAR * pInputData;

/* input data buffer */

L_INT nLength;

/* size of input data */

L_UCHAR ** ppOutputData;

/* output data buffer to be updated */

L_INT nAlign;

/* number of bytes used for alignment */

L_INT nWidth;

/* image width in pixels */

L_INT nHeight;

/* image height in pixels */

L_BOOL bBiLevel;

/* flag */

Decodes the ABIC data and updates the ppOutputData parameter with the uncompressed raw data.

Parameter

Description

pInputData

Pointer to the input buffer that contains the ABIC compressed data.

nLength

Size of the compressed data.

ppOutputData

Pointer to a pointer to an output buffer to be updated with the uncompressed raw data.

nAlign

Number of bytes used for aligning the uncompressed raw data pointed to by ppOutputData.

nWidth

Width of the compressed ABIC data image, in pixels.

nHeight:

Height of the compressed data image, in pixels.

bBiLevel

Flag that indicates whether the input data is bi-level or grayscale. Possible values are:

 

Value

Meaning

 

TRUE

Input data pointed to by pInputData is 1-bit Bi-level.

 

FALSE

Input data pointed to by pInputData is 4-bit Grayscale.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function decompresses 1-bit bi-level or 4-bit grayscale ABIC raw data.

The output buffer pointed to by ppOutputData is allocated automatically by the function. The user is responsible for freeing this ppOutputData buffer by calling GlobalFreePtr() function. The length of the output buffer can be calculated as follows:

bBiLevel = TRUE

nLength = ( ( (nWidth + 31) >> 3) & ~3)

bBiLevel = FALSE

nLength = ( ( (nWidth * 4 + 31) >> 3) & ~3)

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:

LBase::EncodeABIC

Topics:

Compressing and Decompressing Buffers

 

Raster Image Functions: Compression Functions

Example

#define DIB_WIDTH_BYTES(b) (((L_UINT) ((((L_UINT32) (b)) + 31) >> 3)) & ~3)
#define ROUNDEDBYTESPERLINE(w, b) DIB_WIDTH_BYTES((L_UINT32) (w) * (L_UINT32) (b)) 
L_INT myDecodeABIC( LBitmapBase&  Bitmap ) 
{
   L_INT  nRet; 
   L_INT  nLength; 
   L_UCHAR  *pData; 
   L_INT  nOutLength; 
   L_UCHAR  *pOutData; 
   FILE  *pFile; 
   RGBQUAD  MyGrayPal[ 16 ]; 
   
   /* open file */ 
   pFile = fopen( "Image2Raw.ica", "rb+" ); 
   if( NULL != pFile ) 
   {
      /* calculate length of data and load it from the file */ 
      fseek( pFile, 0, SEEK_END ); 
      nLength = ftell( pFile ); 
      fseek( pFile, 0, SEEK_SET ); 
      
      pData = (L_UCHAR *)GlobalAllocPtr( GMEM_FIXED, nLength ); 
      if( NULL == pData ) 
      {
         fclose( pFile ); 
         return -1; /* no memory */ 
      }
      
      if( fread( pData, sizeof( L_UCHAR ), nLength, pFile ) != (L_UINT)nLength ) 
      {
         GlobalFreePtr( pData ); 
         fclose( pFile ); 
         return -1; /* failed while reading */ 
      }
      
      fclose( pFile ); 
      
      /* decode the data */ 
      pOutData = NULL; 
      nRet = LBase::DecodeABIC( pData, nLength, &pOutData, 4, 472 /* width */, 221 /* height */, FALSE ); 
      GlobalFreePtr( pData ); 
      if( SUCCESS == nRet ) 
      {
         if(Bitmap.IsAllocated())
            Bitmap.Free();
         
         nOutLength = 221 * ROUNDEDBYTESPERLINE( 472, 4 ); 
         
         struct 
         {
            BITMAPINFO  info; 
            RGBQUAD     colors[ 15 ]; 
         } BitmapInfo; 
         
         memset(&BitmapInfo, 0, sizeof(BitmapInfo)); 
         BitmapInfo.info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
         BitmapInfo.info.bmiHeader.biWidth = 472; 
         BitmapInfo.info.bmiHeader.biHeight = 221; 
         BitmapInfo.info.bmiHeader.biBitCount = 4; 
         
         nRet = Bitmap.ConvertFromDIB( &BitmapInfo.info, pOutData); 
         
         /* prepare gray scale 16-color palette */ 
         for( L_INT k = 0 ; k < 16 ; k++ ) 
         {
            MyGrayPal[ k ].rgbBlue = 0x11 * k; 
            MyGrayPal[ k ].rgbRed = 0x11 * k; 
            MyGrayPal[ k ].rgbGreen = 0x11 * k; 
            MyGrayPal[ k ].rgbReserved = 0; 
         }

         nRet =  Bitmap.PutColors( 0, 16, MyGrayPal ); 

         GlobalFreePtr( pOutData ); 
         return ( SUCCESS == nRet ? 0 : -1 ); 
      }
   }
   return -1; 
}