←Select platform

Decompress(object,IntPtr,int,int,int,int,int,int,CodecsDecompressDataFlags) Method

Summary
Called for each unmanaged memory buffer, strip or tile of decompressed data.
Syntax
C#
C++/CLI
Python
public void Decompress( 
   object decompressContext, 
   IntPtr data, 
   int dataOffset, 
   int dataLength, 
   int width, 
   int height, 
   int row, 
   int column, 
   CodecsDecompressDataFlags flags 
) 
public: 
void Decompress(  
   Object^ decompressContext, 
   IntPtr data, 
   int dataOffset, 
   int dataLength, 
   int width, 
   int height, 
   int row, 
   int column, 
   CodecsDecompressDataFlags flags 
)  
def Decompress(self,flags): 

Parameters

decompressContext
The decompressing context object obtained through StartDecompress.

data
A pointer to an unmanaged memory buffer that contains the raw compressed data.

dataOffset
Offset of the strip referenced by  data, This is usually zero.

dataLength
Number of bytes in  data.

width
Width of the uncompressed strip or tile, in bytes

height
Height of the uncompressed strip or tile, in bytes. If the image consists of a single compressed strip, as with TWAIN, this is the height of the image.

row
Row offset of the tile or strip.

column
Column offset of the tile or strip.

flags
Flags that indicate whether which part of a strip or tile is being processed. Possible values are:

Value Meaning
CodecsDecompressDataFlags.Start Processing the beginning of a tile or strip
CodecsDecompressDataFlags.End Processing the end of a tile or strip
CodecsDecompressDataFlags.Complete Process a complete tile or strip. This is the same as CodecsDecompressDataFlags.Start | CodecsDecompressDataFlags.End
Remarks

Note that you must call the StartDecompress method before using this method, and you must call the StopDecompress method to end the decompression process.

If  data does not point to a full tile or strip, set  flags to CodecsDecompressDataFlags.Start when the tile/strip begins and set it to CodecsDecompressDataFlags.End when the tile/strip ends.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
// 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.LeastSignificantBitFirst = false; 
   options.Pad4 = false; 
   options.PlanarConfiguration = CodecsPlanarConfiguration.PlanarFormat; 
   options.ViewPerspective = imageInfo.ViewPerspective; 
   options.RawOrder = imageInfo.Order; 
   options.LoadOrder = CodecsLoadByteOrder.BgrOrGray; 
   options.XResolution = imageInfo.XResolution; 
   options.YResolution = imageInfo.YResolution; 
   options.TiffPhotometricInterpretation = CodecsTiffPhotometricInterpretation.Rgb; 
   options.SetColorMask(options.GetColorMask()); 
   options.SetPalette(options.GetPalette()); 
   options.UsePalette = false; 
 
   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:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
// 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 
public void loadRawPackbitsStripsExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String packTifFile = combine(LEAD_VARS_IMAGES_DIR, "packbits.tif"); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "Decompress.bmp"); 
 
   CodecsImageInfo imageInfo = codecs.getInformation(packTifFile, false); 
 
   // StartDecompress 
   CodecsStartDecompressOptions options = CodecsStartDecompressOptions.getEmpty(); 
   options.setDataType(CodecsStartDecompressDataType.STRIPS); 
   options.setFormat(RasterImageFormat.RAW_PACKBITS); 
   options.setWidth(imageInfo.getWidth()); 
   options.setHeight(imageInfo.getHeight()); 
   options.setBitsPerPixel(imageInfo.getBitsPerPixel()); 
   options.setLeastSignificantBitFirst(false); 
   options.setPad4(false); 
   options.setPlanarConfiguration(CodecsPlanarConfiguration.PLANAR_FORMAT); 
   options.setViewPerspective(imageInfo.getViewPerspective()); 
   options.setRawOrder(imageInfo.getOrder()); 
   options.setLoadOrder(CodecsLoadByteOrder.BGR_OR_GRAY); 
   options.setXResolution(imageInfo.getXResolution()); 
   options.setYResolution(imageInfo.getYResolution()); 
   options.setTiffPhotometricInterpretation(CodecsTiffPhotometricInterpretation.RGB); 
   options.setColorMask(options.getColorMask()); 
   options.setPalette(options.getPalette()); 
   options.setUsePalette(false); 
 
   Object decompressObject = codecs.startDecompress(options); 
 
   // Decompress 
   final int TAG_STRIPOFFSETS = 0x111; 
   final int TAG_STRIPBYTECOUNTS = 0x117; 
   final int TAG_ROWSPERSTRIP = 0x116; 
   final 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]; 
 
   ILeadStream packTifStream = LeadStreamFactory.create(packTifFile); 
 
   final int row = 0; // Note: this parameter is ignored for strips 
   final int column = 0; // Column offset of tile 
   for (int index = 0; index < maxIndex; index++) { 
      // seek to the first strip 
      packTifStream.seek(LeadSeekOrigin.BEGIN, stripOffsets[index]); 
 
      byte[] buffer = new byte[stripSizes[index]]; 
      packTifStream.read(buffer, buffer.length); 
 
      // Calculate the height of uncompressed strip/tile 
      int height = rowsPerStrip; 
      if (index == (maxIndex - 1)) { 
         // fewer rows per strip 
         height = imageInfo.getHeight() - (maxIndex - 1) * rowsPerStrip; 
      } 
 
      codecs.decompress( 
            decompressObject, 
            buffer, 
            0, 
            buffer.length, 
            imageInfo.getWidth(), 
            height, 
            row, 
            column, 
            CodecsDecompressDataFlags.COMPLETE); 
   } 
 
   packTifStream.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) throws IOException { 
   ILeadStream fileStream = LeadStreamFactory.create(fileName); 
   RasterTagMetadata tag = codecs.readTag(fileStream, 1, tagId); 
   int[] data = tag.toInt32(); 
   for (int i = 0; i < data.length; i++) { 
      stripArray[i] = data[i]; 
   } 
   fileStream.close(); 
   return tag.getCount(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.