←Select platform

CodecsCompressDataCallback Delegate

Summary
Provides a callback method that gets called when compressed data is available.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public delegate bool CodecsCompressDataCallback( 
   int width, 
   int height, 
   int bitsPerPixel, 
   RasterByteOrder order, 
   RasterViewPerspective viewPerspective, 
   RasterNativeBuffer buffer 
) 
typedef BOOL (^LTCodecsCompressDataCallback)(NSUInteger width, NSUInteger height, NSUInteger bitsPerPixel, LTRasterByteOrder order, LTRasterViewPerspective viewPerspective, unsigned char *data, NSUInteger dataLength)compress 
public boolean OnCodecsCompressDataCallback(int width, int height, int bitsPerPixel, RasterByteOrder order, RasterViewPerspective viewPerspective, RasterNativeBuffer buffer) 
public delegate bool CodecsCompressDataCallback(  
   int width, 
   int height, 
   int bitsPerPixel, 
   RasterByteOrder order, 
   RasterViewPerspective viewPerspective, 
   RasterNativeBuffer buffer 
) 
def CodecsCompressDataCallback(self,width,height,bitsPerPixel,order,viewPerspective,buffer): 
# width : Int32, height : Int32, bitsPerPixel : Int32, order : RasterByteOrder, viewPerspective : RasterViewPerspective, buffer : RasterNativeBuffer 

Parameters

width
The image being compressed width in pixels.

height
The image being compressed height in pixels.

bitsPerPixel
The image being compressed bits/pixel value.

order
The image being compressed byte order.

viewPerspective
The image being compressed view perspective value.

buffer
A pointer to the memory buffer containing compressed data.

Return Value

true to continue compressing the data, false to abort.

Remarks

The CodecsCompressDataCallback delegate is passed to RasterCodecs.StartCompress and will get called when compressed data is available.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
 
public void CompressExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_CompressData.cmp"); 
 
   // Load the image to at 24-bits per pixel 
   RasterImage image = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1); 
   if (image.ViewPerspective != RasterViewPerspective.TopLeft) 
      image.ChangeViewPerspective(RasterViewPerspective.TopLeft); 
 
   // Create the output file 
   _compressStream = File.Create(destFileName); 
 
   // Calculate the bytes per line in the input buffer, without padding  
   int lineBytes = image.Width * 3; 
 
   // Allocate a buffer for the incoming uncompressed data. Note that we 
   //  are compressing 16 lines at a time. You should always use multiples of 16 
   byte[] inBuffer = new byte[16 * lineBytes]; 
 
   // Allocate an output buffer. This is where the compressed data will 
   // go.  Note that this allocates 1024-byte packets.  
   byte[] outBuffer = new byte[1024]; 
 
   // Lock down the image 
   image.Access(); 
 
   // Initialize the compression engine 
   codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.QualityAndSize; 
   codecs.StartCompress( 
      image.Width, 
      image.Height, 
      image.BitsPerPixel, 
      image.Order, 
      image.ViewPerspective, 
      16 * lineBytes, 
      outBuffer, 
      0, 
      outBuffer.Length, 
      CodecsCompression.Cmp, 
      CodecsCompressDataCallback); 
 
   // Compress the data 
   int i = 0; 
   while (i < image.Height) // i is incremented at the end 
   { 
      // Compression of the 16-line chunk starts here 
      int j = 0; 
      int inBufferIndex = 0; 
      while ((i + j) < image.Height && j < 16) 
      { 
         // Get one line at time 
         image.GetRow(i + j, inBuffer, inBufferIndex, lineBytes); 
 
         // Move to next line 
         inBufferIndex += lineBytes; 
 
         j++; 
      } 
 
      // This is the main function that will do the actual Compression 
      codecs.Compress(inBuffer, 0); 
      i += 16; 
   } 
 
   // Reset the compression engine  
   codecs.StopCompress(); 
 
   // Release the image and close the file 
   image.Release(); 
   _compressStream.Close(); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
FileStream _compressStream; 
byte[] _compressBuffer; 
 
bool CodecsCompressDataCallback(int width, int height, int bitsPerPixel, RasterByteOrder order, RasterViewPerspective viewPerspective, RasterNativeBuffer buffer) 
{ 
   // Write data to the file 
   if (_compressBuffer == null || _compressBuffer.Length < buffer.Length) 
      _compressBuffer = new byte[(int)buffer.Length]; 
 
   Marshal.Copy(buffer.Data, _compressBuffer, 0, (int)buffer.Length); 
 
   _compressStream.Write(_compressBuffer, 0, (int)buffer.Length); 
 
   return true; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

See Also

Reference

Leadtools.Codecs Namespace

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.