This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Thursday, August 2, 2007 12:54:44 PM(UTC)
Groups: Registered
Posts: 3
Hello!
I am trying to decompress a .TIF file, then get a pointer to the decompressed image buffer. How can I do this? It seems like it should be obvious, because isn't that the point of the decompression functions? My code is essentially copying the code from the example:
L_INT StartDecompressBufferFirstExample(L_VOID)
{
L_INT nRet;
L_TCHAR *szFileName = TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\packbits.tif");
L_HANDLE fd;
L_UCHAR *pBuf = NULL;
BITMAPHANDLE Bitmap;
FILEINFO TempFileInfo;
L_INT nRowsPerStrip=0;
STARTDECOMPRESSDATA StartDecompressData;
DECOMPRESSDATA DecompressData;
L_INT nIndex = 0;
HGLOBAL hDecompress;
L_INT StripOffsets[MAX_STRIPS];
L_INT StripSizes[MAX_STRIPS];
L_INT nMaxIndex;
DWORD wReadBytes;
TempFileInfo.uStructSize = sizeof(TempFileInfo);
nRet = L_FileInfo (szFileName, &TempFileInfo, sizeof(FILEINFO), 0, NULL);
if(nRet != SUCCESS)
return nRet;
//******************************
//*** 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)
nRet = L_StartDecompressBuffer(&hDecompress, &StartDecompressData);
if(nRet != SUCCESS)
return nRet;
//******************************
//*** L_DecompressBuffer
//******************************
nMaxIndex = ReadTag(szFileName, TAG_STRIPOFFSETS, StripOffsets);
ReadTag(szFileName, TAG_STRIPBYTECOUNTS, StripSizes);
ReadTag(szFileName, TAG_ROWSPERSTRIP, &nRowsPerStrip);
fd = CreateFile(szFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
DecompressData.nRow = 0;//Note--this field is ignored for strips
for (nIndex = 0; nIndex < nMaxIndex; nIndex++)
{
//seek to the first strip
SetFilePointer(fd,StripOffsets[nIndex] , 0, FILE_BEGIN);
pBuf = (L_UCHAR *)malloc(StripSizes[nIndex]);
ReadFile (fd, pBuf, StripSizes[nIndex], &wReadBytes, NULL);
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
nRet = L_DecompressBuffer ( hDecompress, &DecompressData);
if(nRet != SUCCESS)
return nRet;
free(pBuf);
}
CloseHandle(fd);
//******************************
//*** L_StopDecompressBuffer
//******************************
L_StopDecompressBuffer (hDecompress);
// Bitmap contains the uncompressed bitmap
nRet = L_SaveBitmap (TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\Uncompressed.bmp"), &Bitmap, FILE_BMP, 24, 0, NULL);
L_FreeBitmap(&Bitmap);
return nRet;
}
Thank you!
Loretta :o)
#2
Posted
:
Monday, August 6, 2007 6:43:52 AM(UTC)
Groups: Manager, Tech Support
Posts: 367
Was thanked: 1 time(s) in 1 post(s)
Loretta,
The default behavior for LEADTOOLS when loading any type of image, including compressed TIFF, is to decompress it automatically.
This means an easy way to obtain a non-compressed buffer containing pixel data, is to simply load it, then get the data using L_GetBitmapRow().
The following code does this using LEADTOOLS 15:
BITMAPHANDLE Bitmap = {0};
int nBytes = 0;
L_UCHAR *pBuf = NULL; //pointer to buffer
L_LoadBitmap(TEXT("test.tif"), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
if(!Bitmap.Flags.Allocated) //loading failed
return;
nBytes = Bitmap.BytesPerLine * BITMAPHEIGHT(&Bitmap);
pBuf = (L_UCHAR *)malloc(nBytes);
if(pBuf)
{
L_AccessBitmap(&Bitmap);
L_GetBitmapRow(&Bitmap, pBuf, 0, nBytes);
//... DoSomthingWithBuffer(pBuf);
free(pBuf);
L_ReleaseBitmap(&Bitmap);
}
L_FreeBitmap(&Bitmap);
Amin Dodin
Senior Support Engineer
LEAD Technologies, Inc.
#3
Posted
:
Tuesday, July 28, 2009 9:20:21 AM(UTC)
Groups: Registered
Posts: 3
Does LEADTOOLS Load Method decompress all compression types? I have a program that fails to load files with LZW Compression.
Lucio Gayosso
Lead Developer, PCSS
lucio@pcssinc.com
l_gayosso@hotmail.com
#4
Posted
:
Wednesday, July 29, 2009 4:56:09 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
Lucio,
You are already discussing this issue in the forum post below:
http://support.leadtools.com/SupportPortal/CS/forums/29706/ShowPost.aspx
Please continue discussing this issue in that forum post.
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.