Leadtools.Codecs Namespace > RasterCodecs Class : StartDecompress Method |
public object StartDecompress( CodecsStartDecompressOptions options )
'Declaration Public Function StartDecompress( _ ByVal options As CodecsStartDecompressOptions _ ) As Object
'Usage Dim instance As RasterCodecs Dim options As CodecsStartDecompressOptions Dim value As Object value = instance.StartDecompress(options)
public object StartDecompress( CodecsStartDecompressOptions options )
function Leadtools.Codecs.RasterCodecs.StartDecompress( options )
public: Object^ StartDecompress( CodecsStartDecompressOptions options )
Initializes the buffered decompression engine. The decompression is then carried out using the Decompress(Object,Byte[],Int32,Int32,Int32,Int32,Int32,Int32,CodecsDecompressDataFlags) method. It is ended by the StopDecompress method.
Currently, raw JPEG must contain all the Huffman tables encoded. That is, it must be a readable JPEG file.
' This sample loads raw data from a PackBits TIF file ' 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 Compress method Private Sub LoadRawPackbitsStrips(ByVal packTifFile As String) Dim codecs As RasterCodecs = New RasterCodecs() Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Decompress.bmp") Dim imageInfo As CodecsImageInfo = codecs.GetInformation(packTifFile, False) ' StartDecompress Dim options As CodecsStartDecompressOptions = CodecsStartDecompressOptions.Empty options.DataType = CodecsStartDecompressDataType.Strips options.Format = RasterImageFormat.RawPackBits options.Width = imageInfo.Width options.Height = imageInfo.Height options.BitsPerPixel = imageInfo.BitsPerPixel options.ViewPerspective = imageInfo.ViewPerspective options.RawOrder = imageInfo.Order options.LoadOrder = CodecsLoadByteOrder.BgrOrGray options.XResolution = imageInfo.XResolution options.YResolution = imageInfo.YResolution options.TiffPhotometricInterpretation = CodecsTiffPhotometricInterpretation.Rgb Dim decompressObject As Object = codecs.StartDecompress(options) ' Decompress Const TAG_STRIPOFFSETS As Integer = &H111 Const TAG_STRIPBYTECOUNTS As Integer = &H117 Const TAG_ROWSPERSTRIP As Integer = &H116 Const MAX_STRIPS As Integer = 1000 Dim stripOffsets As Integer() = New Integer(MAX_STRIPS - 1) {} Dim stripSizes As Integer() = New Integer(MAX_STRIPS - 1) {} Dim rowsPerStripBuffer As Integer() = New Integer(0) {} Dim maxIndex As Integer = ReadTag(codecs, packTifFile, TAG_STRIPOFFSETS, stripOffsets) ReadTag(codecs, packTifFile, TAG_STRIPBYTECOUNTS, stripSizes) ReadTag(codecs, packTifFile, TAG_ROWSPERSTRIP, rowsPerStripBuffer) Dim rowsPerStrip As Integer = rowsPerStripBuffer(0) Dim fs As FileStream = File.OpenRead(packTifFile) Const row As Integer = 0 ' Note: this parameter is ignored for strips Const column As Integer = 0 ' Column offset of tile Dim index As Integer = 0 Do While index < maxIndex ' seek to the first strip fs.Seek(stripOffsets(index), SeekOrigin.Begin) Dim buffer As Byte() = New Byte(stripSizes(index) - 1) {} fs.Read(buffer, 0, buffer.Length) ' Calculate the height of uncompressed strip/tile Dim height As Integer = rowsPerStrip If index = (maxIndex - 1) Then ' fewer rows per strip height = imageInfo.Height - (maxIndex - 1) * rowsPerStrip End If codecs.Decompress(decompressObject, buffer, 0, buffer.Length, imageInfo.Width, height, row, column, CodecsDecompressDataFlags.Complete) index += 1 Loop fs.Close() ' StopDecompress Dim image As RasterImage = codecs.StopDecompress(decompressObject) ' 'image' contains the uncompressed image codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24) image.Dispose() ' Clean up codecs.Dispose() End Sub ' Returns maximum index Private Function ReadTag(ByVal codecs As RasterCodecs, ByVal fileName As String, ByVal tagId As Integer, ByVal stripArray As Integer()) As Integer Dim tag As RasterTagMetadata = codecs.ReadTag(fileName, 1, tagId) Dim data As Integer() = tag.ToInt32() data.CopyTo(stripArray, 0) Return tag.Count End Function Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
// This sample loads raw data from a PackBits TIF file // 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 Compress method void LoadRawPackbitsStrips(string packTifFile) { RasterCodecs codecs = new RasterCodecs(); string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Decompress.bmp"); CodecsImageInfo imageInfo = codecs.GetInformation(packTifFile, false); // StartDecompress CodecsStartDecompressOptions options = CodecsStartDecompressOptions.Empty; options.DataType = CodecsStartDecompressDataType.Strips; options.Format = RasterImageFormat.RawPackBits; options.Width = imageInfo.Width; options.Height = imageInfo.Height; options.BitsPerPixel = imageInfo.BitsPerPixel; options.ViewPerspective = imageInfo.ViewPerspective; options.RawOrder = imageInfo.Order; options.LoadOrder = CodecsLoadByteOrder.BgrOrGray; options.XResolution = imageInfo.XResolution; options.YResolution = imageInfo.YResolution; options.TiffPhotometricInterpretation = CodecsTiffPhotometricInterpretation.Rgb; object decompressObject = codecs.StartDecompress(options); // Decompress const int TAG_STRIPOFFSETS = 0x111; const int TAG_STRIPBYTECOUNTS = 0x117; const int TAG_ROWSPERSTRIP = 0x116; const int MAX_STRIPS = 1000; int[] stripOffsets = new int[MAX_STRIPS]; int[] stripSizes = new int[MAX_STRIPS]; int[] rowsPerStripBuffer = new int[1]; int maxIndex = ReadTag(codecs, packTifFile, TAG_STRIPOFFSETS, stripOffsets); ReadTag(codecs, packTifFile, TAG_STRIPBYTECOUNTS, stripSizes); ReadTag(codecs, packTifFile, TAG_ROWSPERSTRIP, rowsPerStripBuffer); int rowsPerStrip = rowsPerStripBuffer[0]; FileStream fs = File.OpenRead(packTifFile); const int row = 0; // Note: this parameter is ignored for strips const int column = 0; // Column offset of tile for (int index = 0; index < maxIndex; index++) { // seek to the first strip fs.Seek(stripOffsets[index], SeekOrigin.Begin); byte[] buffer = new byte[stripSizes[index]]; fs.Read(buffer, 0, buffer.Length); // Calculate the height of uncompressed strip/tile int height = rowsPerStrip; if (index == (maxIndex - 1)) { // fewer rows per strip height = imageInfo.Height - (maxIndex - 1) * rowsPerStrip; } codecs.Decompress( decompressObject, buffer, 0, buffer.Length, imageInfo.Width, height, row, column, CodecsDecompressDataFlags.Complete); } fs.Close(); // StopDecompress RasterImage image = codecs.StopDecompress(decompressObject); // 'image' contains the uncompressed image codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24); image.Dispose(); // Clean up codecs.Dispose(); } // Returns maximum index int ReadTag(RasterCodecs codecs, string fileName, int tagId, int[] stripArray) { RasterTagMetadata tag = codecs.ReadTag(fileName, 1, tagId); int[] data = tag.ToInt32(); data.CopyTo(stripArray, 0); return tag.Count; } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
// // This sample loads raw data from a PackBits TIF file // // 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 Compress method // async Task LoadRawPackbitsStrips(string packTifFile) // { // RasterCodecs codecs = new RasterCodecs(); // string destFileName = "Decompress.bmp"; // IStorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(packTifFile); // CodecsImageInfo imageInfo = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), false, 1); // // StartDecompress // CodecsStartDecompressOptions options = new CodecsStartDecompressOptions(); // options.DataType = CodecsStartDecompressDataType.Strips; // options.Format = RasterImageFormat.RawPackBits; // options.Width = imageInfo.Width; // options.Height = imageInfo.Height; // options.BitsPerPixel = imageInfo.BitsPerPixel; // options.ViewPerspective = imageInfo.ViewPerspective; // options.RawOrder = imageInfo.Order; // options.LoadOrder = CodecsLoadByteOrder.BgrOrGray; // options.XResolution = imageInfo.XResolution; // options.YResolution = imageInfo.YResolution; // options.TiffPhotometricInterpretation = CodecsTiffPhotometricInterpretation.Rgb; // object decompressObject = codecs.StartDecompress(options); // // Decompress // const int TAG_STRIPOFFSETS = 0x111; // const int TAG_STRIPBYTECOUNTS = 0x117; // const int TAG_ROWSPERSTRIP = 0x116; // const int MAX_STRIPS = 1000; // int[] stripOffsets = new int[MAX_STRIPS]; // int[] stripSizes = new int[MAX_STRIPS]; // int[] rowsPerStripBuffer = new int[1]; // int maxIndex = await ReadTag(codecs, packTifFile, TAG_STRIPOFFSETS, stripOffsets); // await ReadTag(codecs, packTifFile, TAG_STRIPBYTECOUNTS, stripSizes); // await ReadTag(codecs, packTifFile, TAG_ROWSPERSTRIP, rowsPerStripBuffer); // int rowsPerStrip = rowsPerStripBuffer[0]; // Stream fs = await loadFile.OpenStreamForReadAsync(); // const int row = 0; // Note: this parameter is ignored for strips // const int column = 0; // Column offset of tile // for (int index = 0; index < maxIndex; index++) // { // // seek to the first strip // fs.Seek(stripOffsets[index], SeekOrigin.Begin); // byte[] buffer = new byte[stripSizes[index]]; // fs.Read(buffer, 0, buffer.Length); // // Calculate the height of uncompressed strip/tile // int height = rowsPerStrip; // if (index == (maxIndex - 1)) // { // // fewer rows per strip // height = imageInfo.Height - (maxIndex - 1) * rowsPerStrip; // } // codecs.Decompress( // decompressObject, // buffer, // 0, // buffer.Length, // imageInfo.Width, // height, // row, // column, // CodecsDecompressDataFlags.Complete); // } // fs.Dispose(); // // StopDecompress // RasterImage image = codecs.StopDecompress(decompressObject); // // 'image' contains the uncompressed image // IStorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName); // await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 24); // image.Dispose(); // // Clean up // codecs.Dispose(); // } // // Returns maximum index //async Task<int> ReadTag(RasterCodecs codecs, string fileName, int tagId, int[] stripArray) // { // StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(fileName); // RasterTagMetadata tag = await codecs.ReadTagAsync(LeadStreamFactory.Create(loadFile), 1, tagId); // int[] data = tag.ToInt32(); // data.CopyTo(stripArray, 0); // return tag.Count; // } //
// This sample loads raw data from a PackBits TIF file // 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 Compress method async Task LoadRawPackbitsStrips(string packTifFile) { RasterCodecs codecs = new RasterCodecs(); string destFileName = "Decompress.bmp"; IStorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(packTifFile); CodecsImageInfo imageInfo = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), false, 1); // StartDecompress CodecsStartDecompressOptions options = new CodecsStartDecompressOptions(); options.DataType = CodecsStartDecompressDataType.Strips; options.Format = RasterImageFormat.RawPackBits; options.Width = imageInfo.Width; options.Height = imageInfo.Height; options.BitsPerPixel = imageInfo.BitsPerPixel; options.ViewPerspective = imageInfo.ViewPerspective; options.RawOrder = imageInfo.Order; options.LoadOrder = CodecsLoadByteOrder.BgrOrGray; options.XResolution = imageInfo.XResolution; options.YResolution = imageInfo.YResolution; options.TiffPhotometricInterpretation = CodecsTiffPhotometricInterpretation.Rgb; object decompressObject = codecs.StartDecompress(options); // Decompress const int TAG_STRIPOFFSETS = 0x111; const int TAG_STRIPBYTECOUNTS = 0x117; const int TAG_ROWSPERSTRIP = 0x116; const int MAX_STRIPS = 1000; int[] stripOffsets = new int[MAX_STRIPS]; int[] stripSizes = new int[MAX_STRIPS]; int[] rowsPerStripBuffer = new int[1]; int maxIndex = await ReadTag(codecs, packTifFile, TAG_STRIPOFFSETS, stripOffsets); await ReadTag(codecs, packTifFile, TAG_STRIPBYTECOUNTS, stripSizes); await ReadTag(codecs, packTifFile, TAG_ROWSPERSTRIP, rowsPerStripBuffer); int rowsPerStrip = rowsPerStripBuffer[0]; Stream fs = await loadFile.OpenStreamForReadAsync(); const int row = 0; // Note: this parameter is ignored for strips const int column = 0; // Column offset of tile for (int index = 0; index < maxIndex; index++) { // seek to the first strip fs.Seek(stripOffsets[index], SeekOrigin.Begin); byte[] buffer = new byte[stripSizes[index]]; fs.Read(buffer, 0, buffer.Length); // Calculate the height of uncompressed strip/tile int height = rowsPerStrip; if (index == (maxIndex - 1)) { // fewer rows per strip height = imageInfo.Height - (maxIndex - 1) * rowsPerStrip; } codecs.Decompress( decompressObject, buffer, 0, buffer.Length, imageInfo.Width, height, row, column, CodecsDecompressDataFlags.Complete); } fs.Dispose(); // StopDecompress RasterImage image = codecs.StopDecompress(decompressObject); // 'image' contains the uncompressed image IStorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 24); image.Dispose(); // Clean up codecs.Dispose(); } // Returns maximum index async Task<int> ReadTag(RasterCodecs codecs, string fileName, int tagId, int[] stripArray) { StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(fileName); RasterTagMetadata tag = await codecs.ReadTagAsync(LeadStreamFactory.Create(loadFile), 1, tagId); int[] data = tag.ToInt32(); data.CopyTo(stripArray, 0); return tag.Count; }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2