L_StartDecompressBuffer
#include "l_bitmap.h"
L_INT EXT_FUNCTION L_StartDecompressBuffer(phDecompress, pStartDecompressData)
HGLOBAL phDecompress; |
/* pointer to the decompression handle */ |
pSTARTDECOMPRESSDATA pStartDecompressData; |
/* pointer to a structure */ |
Initializes the buffered decompression engine. The decompression is then carried out using the L_DecompressBuffer function. It is ended by the L_StopDecompressBuffer function.
Parameter |
Description |
phDecompress |
Pointer to the handle that identifies the decompression process. |
pStartDecompressData |
Pointer to a structure that contains information about the decompression process. |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
You must declare a handle of type HGLOBAL before calling this function. Pass the address of this handle to this function and the function will initialize the handle.
If this function is called for an unsupported format, it will return ERROR_INV_PARAMETER.
Currently, raw JPEG must contain all the Huffman tables encoded. That is, it must be a readable JPEG file.
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. |
Platforms
Windows 95 / 98 / Me, Windows 2000 / XP, Windows CE.
See Also
Functions: |
L_DecompressBuffer, L_StopDecompressBuffer, L_StartCompressBuffer, L_CompressBuffer, L_EndCompressBuffer |
Topics: |
|
|
Example
#include <fcntl.h>
#include <io.h>
#define TAG_STRIPOFFSETS 0x111
#define TAG_STRIPBYTECOUNTS 0x117
#define TAG_ROWSPERSTRIP 0x116
#define MAX_STRIPS 1000
// Returns maximum index
L_INT ReadTag(L_TCHAR *pszFileName, L_UINT16 uTag, int StripArray[])
{
L_UINT16 uType;
L_UINT32 uCount;
L_ReadFileTag(pszFileName, uTag, &uType, &uCount, StripArray, NULL);
return uCount;
}
// Example 1
// This sample loads raw data from packbits.tif
// packbits.tif is a 24-bit tif packbits compressed file
// packbits.tif has 46 strips of packbits data
// The strip information is obtained by reading the TIF tags TAG_STRIPOFFSETS and TAG_STRIPBYTECOUNTS
// The strips are directly read and fed to the L_Compress APIs
static L_VOID LoadRawPackbitsStrips()
{
L_TCHAR *szFileName = TEXT("e:\\images\\packbits.tif");
L_INT fd;
L_CHAR *pBuf = NULL;
BITMAPHANDLE Bitmap;
L_INT nRet = SUCCESS;
FILEINFO TempFileInfo;
long nRowsPerStrip=0;
STARTDECOMPRESSDATA StartDecompressData;
DECOMPRESSDATA DecompressData;
L_INT nIndex = 0;
HGLOBAL hDecompress;
int StripOffsets[MAX_STRIPS];
int StripSizes[MAX_STRIPS];
int nMaxIndex;
TempFileInfo.uStructSize = sizeof(TempFileInfo);
L_FileInfo (szFileName, &TempFileInfo, sizeof(FILEINFO), 0, NULL);
//******************************
//*** L_StartDecompressBuffer
//******************************
memset(&StartDecompressData, 0, sizeof(STARTDECOMPRESSDATA) );
memset(&DecompressData, 0, sizeof(DECOMPRESSDATA) );
StartDecompressData.uStructSize = sizeof(STARTDECOMPRESSDATA);
StartDecompressData.pBitmap = &Bitmap;
StartDecompressData.uBitmapStructSize = sizeof(BITMAPHANDLE);
StartDecompressData.uStripsOrTiles = DECOMPRESS_STRIPS;
StartDecompressData.uFormat = FILE_RAW_PACKBITS;
StartDecompressData.nWidth = TempFileInfo.Width;
StartDecompressData.nHeight = TempFileInfo.Height;
StartDecompressData.nBitsPerPixel = TempFileInfo.BitsPerPixel;
StartDecompressData.nViewPerspective = TempFileInfo.ViewPerspective;
StartDecompressData.nRawOrder = TempFileInfo.Order;
StartDecompressData.nLoadOrder = ORDER_BGRORGRAY;
StartDecompressData.nXResolution = TempFileInfo.XResolution;
StartDecompressData.nYResolution = TempFileInfo.YResolution;
StartDecompressData.pfnReadCallback = NULL;
StartDecompressData.uFlags = 0;
StartDecompressData.pUserData = NULL;
StartDecompressData.nPhotoInt = 2; // TIFF tag 0-6 WhiteIsZero(0) BlackIsZero(1) RGB(2)
L_StartDecompressBuffer(&hDecompress, &StartDecompressData);
//******************************
//*** L_DecompressBuffer
//******************************
nMaxIndex = ReadTag(szFileName, TAG_STRIPOFFSETS, StripOffsets);
ReadTag(szFileName, TAG_STRIPBYTECOUNTS, StripSizes);
ReadTag(szFileName, TAG_ROWSPERSTRIP, &nRowsPerStrip);
#ifdef UNICODE
fd = _wopen(szFileName, _O_RDONLY);
#else
fd = _open(szFileName, _O_RDONLY);
#endif
DecompressData.nRow = 0;//Note--this field is ignored for strips
for (nIndex = 0; nIndex < nMaxIndex; nIndex++)
{
//seek to the first strip
_lseek(fd, StripOffsets[nIndex], 0);
pBuf = (char *)malloc(StripSizes[nIndex]);
_read(fd, pBuf, StripSizes[nIndex]);
DecompressData.uStructSize = sizeof(DECOMPRESSDATA);
DecompressData.pBuffer = pBuf; //pointer to raw data
DecompressData.nWidth = TempFileInfo.Width; //Width of uncompressed strip/tile
DecompressData.nHeight = nRowsPerStrip; //Height of uncompressed strip/tile
if (nIndex == (nMaxIndex - 1 ))
{
//fewer rows per strip
DecompressData.nHeight = TempFileInfo.Height - (nMaxIndex - 1) * nRowsPerStrip;
}
DecompressData.uOffset = 0; //Offset of strip relative to buffer
DecompressData.nBufferSize = StripSizes[nIndex];//Size of strip after compression
DecompressData.nCol = 0; //Col offset of tile
DecompressData.uFlags = DECOMPRESS_CHUNK_COMPLETE,
DecompressData.nReserved1 = 0; //Reserved for future use
L_DecompressBuffer ( hDecompress, &DecompressData);
free(pBuf);
}
_close(fd);
//******************************
//*** L_StopDecompressBuffer
//******************************
L_StopDecompressBuffer (hDecompress);
// Bitmap contains the uncompressed bitmap
L_SaveBitmap (TEXT("e:\\erase\\Uncompressed.bmp"), &Bitmap, FILE_BMP, 24, 0, NULL);
}
// Example 2
// This sample is similar to LoadRawPackbitsStrips(), except the data
// is fed to L_Decompress APIs as tiles instead of strips and the image
// created is 4x the size of the original image, consisting of four of the original images
// This sample loads raw data from packbits.tif
// packbits.tif is a 24-bit tif packbits compressed file
// packbits.tif has 46 strips of packbits data
// The strip information is obtained by reading the TIF tags TAG_STRIPOFFSETS and TAG_STRIPBYTECOUNTS
// The strips are directly read and fed to the L_Compress APIs
static L_VOID LoadRawPackbitsTiles()
{
L_TCHAR *szFileName = TEXT("e:\\images\\packbits.tif");
L_INT fd;
L_CHAR *pBuf = NULL;
BITMAPHANDLE Bitmap;
L_INT nRet = SUCCESS;
FILEINFO TempFileInfo;
long nRowsPerStrip=0;
STARTDECOMPRESSDATA StartDecompressData;
DECOMPRESSDATA DecompressData;
L_INT nIndex = 0;
HGLOBAL hDecompress;
L_INT nCurrentRow = 0;
int StripOffsets[MAX_STRIPS];
int StripSizes[MAX_STRIPS];
int nMaxIndex;
TempFileInfo.uStructSize = sizeof(TempFileInfo);
L_FileInfo (szFileName, &TempFileInfo, sizeof(FILEINFO), 0, NULL);
//******************************
//*** L_StartDecompressBuffer
//******************************
memset(&StartDecompressData, 0, sizeof(STARTDECOMPRESSDATA) );
memset(&DecompressData, 0, sizeof(DECOMPRESSDATA) );
StartDecompressData.uStructSize = sizeof(STARTDECOMPRESSDATA); // For versioning
StartDecompressData.pBitmap = &Bitmap;
StartDecompressData.uBitmapStructSize = sizeof(BITMAPHANDLE);
StartDecompressData.uStripsOrTiles = DECOMPRESS_TILES;
StartDecompressData.uFormat = FILE_RAW_PACKBITS;
StartDecompressData.nWidth = TempFileInfo.Width * 2; //
StartDecompressData.nHeight = TempFileInfo.Height * 2; //
StartDecompressData.nBitsPerPixel = TempFileInfo.BitsPerPixel; //
StartDecompressData.nViewPerspective = TempFileInfo.ViewPerspective; //
StartDecompressData.nRawOrder = TempFileInfo.Order; // ORDER_RGB, ORDER_BGR
StartDecompressData.nLoadOrder = ORDER_BGRORGRAY; // ORDER_RGB, ORDER_BGR
StartDecompressData.nXResolution = TempFileInfo.XResolution;
StartDecompressData.nYResolution = TempFileInfo.YResolution;
StartDecompressData.pfnReadCallback = NULL; // optional callback function
StartDecompressData.uFlags = 0; // DECOMPRESS_LSB, DECOMPRESS_PAD4, DECOMPRESS_WHITEONBLACK, DECOMPRESS_PALETTE
StartDecompressData.pUserData = NULL; //
StartDecompressData.nPhotoInt = 2; // TIFF tag 0-6 WhiteIsZero(0) BlackIsZero(1) RGB(2)
//StartDecompressData.nPlanarConfig; // TIFF tag 1 = Chunky, 2 = Planar format
L_StartDecompressBuffer(&hDecompress, &StartDecompressData);
//******************************
//*** L_DecompressBuffer
//******************************
nMaxIndex = ReadTag(szFileName, TAG_STRIPOFFSETS, StripOffsets);
ReadTag(szFileName, TAG_STRIPBYTECOUNTS, StripSizes);
ReadTag(szFileName, TAG_ROWSPERSTRIP, &nRowsPerStrip);
#ifdef UNICODE
fd = _wopen(szFileName, _O_RDONLY);
#else
fd = _open(szFileName, _O_RDONLY);
#endif
nCurrentRow = 0;
for (nIndex = 0; nIndex < nMaxIndex; nIndex++)
{
//seek to the first strip
_lseek(fd, StripOffsets[nIndex], 0);
pBuf = (char *)malloc(StripSizes[nIndex]);
_read(fd, pBuf, StripSizes[nIndex]);
DecompressData.uStructSize = sizeof(DECOMPRESSDATA);
DecompressData.pBuffer = pBuf; //pointer to raw data
DecompressData.nWidth = TempFileInfo.Width; //Width of uncompressed strip/tile
DecompressData.nHeight = nRowsPerStrip; //Height of uncompressed strip/tile
if (nIndex == (nMaxIndex - 1 ))
{
//fewer rows per strip
DecompressData.nHeight = TempFileInfo.Height - (nMaxIndex - 1) * nRowsPerStrip;
}
DecompressData.uOffset = 0; //Offset of strip relative to buffer
DecompressData.nBufferSize = StripSizes[nIndex]; //Size of strip after compression
DecompressData.nRow = nCurrentRow; //Row offset of tile
DecompressData.nCol = 0; //Col offset of tile
DecompressData.uFlags = DECOMPRESS_CHUNK_COMPLETE,
DecompressData.nReserved1 = 0; //Reserved for future use
//Strips in upper left corner
L_DecompressBuffer ( hDecompress, &DecompressData);
//Strips in upper right corner
DecompressData.nRow = nCurrentRow;
DecompressData.nCol = TempFileInfo.Width;
L_DecompressBuffer( hDecompress, &DecompressData);
//Strips in lower left corner
DecompressData.nRow = TempFileInfo.Height + nCurrentRow;
DecompressData.nCol = 0;
L_DecompressBuffer( hDecompress, &DecompressData);
//Strips in lower right corner
DecompressData.nRow = TempFileInfo.Height + nCurrentRow;
DecompressData.nCol = TempFileInfo.Width;
L_DecompressBuffer( hDecompress, &DecompressData);
free(pBuf);
nCurrentRow += DecompressData.nHeight;
}
_close(fd);
//******************************
//*** L_StopDecompressBuffer
//******************************
L_StopDecompressBuffer(hDecompress);
// Bitmap contains the uncompressed bitmap
L_SaveBitmap(TEXT("e:\\erase\\Uncompressed.bmp"), &Bitmap, FILE_BMP, 24, 0, NULL);
}
// Example 3
// This sample loads raw data from eagleccittg3.tif
// This file is a tif ccitt group3 compressed with a single strip
// The strip information is obtained by reading the TIF tags TAG_STRIPOFFSETS and TAG_STRIPBYTECOUNTS
// The strip is directly read and fed to the L_Decompress APIs
static L_VOID LoadRawCCITT31DStrips()
{
L_TCHAR *szFileName = TEXT("e:\\images\\eagleccittg3.tif");
L_INT fd;
L_CHAR *pBuf = NULL;
BITMAPHANDLE Bitmap;
L_INT nRet = SUCCESS;
FILEINFO TempFileInfo;
long nRowsPerStrip=0;
STARTDECOMPRESSDATA StartDecompressData;
DECOMPRESSDATA DecompressData;
L_INT nIndex = 0;
HGLOBAL hDecompress;
int StripOffsets[MAX_STRIPS];
int StripSizes[MAX_STRIPS];
int nMaxIndex;
TempFileInfo.uStructSize = sizeof(TempFileInfo);
L_FileInfo(szFileName, &TempFileInfo, sizeof(FILEINFO), 0, NULL);
//******************************
//*** L_StartDecompressBuffer
//******************************
memset(&StartDecompressData, 0, sizeof(STARTDECOMPRESSDATA) );
memset(&DecompressData, 0, sizeof(DECOMPRESSDATA) );
StartDecompressData.uStructSize = sizeof(STARTDECOMPRESSDATA);
StartDecompressData.pBitmap = &Bitmap;
StartDecompressData.uBitmapStructSize = sizeof(BITMAPHANDLE);
StartDecompressData.uStripsOrTiles = DECOMPRESS_TILES;
StartDecompressData.uFormat = FILE_FAX_G3_1D;
StartDecompressData.nWidth = TempFileInfo.Width;
StartDecompressData.nHeight = TempFileInfo.Height;
StartDecompressData.nBitsPerPixel = TempFileInfo.BitsPerPixel;
StartDecompressData.nViewPerspective = TempFileInfo.ViewPerspective;
StartDecompressData.nRawOrder = TempFileInfo.Order; // ORDER_RGB, ORDER_BGR
StartDecompressData.nLoadOrder = ORDER_BGRORGRAY;
StartDecompressData.nXResolution = TempFileInfo.XResolution;
StartDecompressData.nYResolution = TempFileInfo.YResolution;
StartDecompressData.pfnReadCallback = NULL;
StartDecompressData.uFlags = 0;
StartDecompressData.pUserData = NULL; //
StartDecompressData.nPhotoInt = 0; // TIFF tag 0-6 TIFF tag 0=WhiteIsZero, 1=BlackIsZero
L_StartDecompressBuffer(&hDecompress, &StartDecompressData);
//******************************
//*** L_DecompressBuffer
//******************************
nMaxIndex = ReadTag(szFileName, TAG_STRIPOFFSETS, StripOffsets);
nMaxIndex = ReadTag(szFileName, TAG_STRIPBYTECOUNTS, StripSizes);
ReadTag(szFileName, TAG_ROWSPERSTRIP, &nRowsPerStrip);
#ifdef UNICODE
fd = _wopen(szFileName, _O_RDONLY);
#else
fd = _open(szFileName, _O_RDONLY);
#endif
DecompressData.nRow = 0; //This field is ignored with strips
for (nIndex = 0; nIndex < nMaxIndex; nIndex++)
{
//seek to the first strip
_lseek(fd, StripOffsets[nIndex], 0);
pBuf = (char *)malloc(StripSizes[nIndex]);
_read(fd, pBuf, StripSizes[nIndex]);
DecompressData.uStructSize = sizeof(DECOMPRESSDATA);
DecompressData.pBuffer = pBuf; //pointer to raw data
DecompressData.nWidth = TempFileInfo.Width; //Width of uncompressed strip/tile
DecompressData.nHeight = nRowsPerStrip; //Height of uncompressed strip/tile
if (nIndex == (nMaxIndex - 1 ))
{
//fewer rows per strip
DecompressData.nHeight = TempFileInfo.Height - (nMaxIndex - 1) * nRowsPerStrip;
}
DecompressData.uOffset = 0; //Offset of strip relative to buffer
DecompressData.nBufferSize = StripSizes[nIndex];//Size of strip after compression
DecompressData.nCol = 0; //Col offset of tile
DecompressData.uFlags = DECOMPRESS_CHUNK_COMPLETE;
DecompressData.nReserved1 = 0; //Reserved for future use
L_DecompressBuffer( hDecompress, &DecompressData);
free(pBuf);
}
_close(fd);
//******************************
//*** L_StopDecompressBuffer
//******************************
L_StopDecompressBuffer(hDecompress);
// Bitmap contains the uncompressed bitmap
L_SaveBitmap(TEXT("e:\\erase\\Uncompressed.bmp"), &Bitmap, FILE_BMP, 24, 0, NULL);
}