LEADTOOLS Image File Support (Leadtools.Codecs assembly)

CodecsJpeg2000Options Class

Show in webframe
Example 







Members 
Provides extra options for loading and saving JPEG 2000 and LEAD CMW images.
Object Model
Syntax
public class CodecsJpeg2000Options 
'Declaration
 
Public Class CodecsJpeg2000Options 
'Usage
 
Dim instance As CodecsJpeg2000Options
public sealed class CodecsJpeg2000Options 
@interface LTCodecsJpeg2000Options : NSObject
public class CodecsJpeg2000Options
function Leadtools.Codecs.CodecsJpeg2000Options()
public ref class CodecsJpeg2000Options 
Remarks

The JPEG2000 image format offers both superior compression performance and robust file handling. Some J2K options can have a direct impact on compression performance, while others primarily affect resulting file size. Notes on Advanced options continue below.

Main options (listed above) include:

Using this structure with LEAD CMW (Cmw) or TIFF with LEAD Wavelet CMW compression (TifCmw) files

When using this structure with Cmw or TifCmw files, only the following data properties are required:

CodecsJpeg2000SaveOptions.CompressionControl

CodecsJpeg2000SaveOptions.CompressionRatio

CodecsJpeg2000SaveOptions.TargetFileSize

CodecsJpeg2000SaveOptions.ProgressingOrder

The resulting file size/ compression ratio can be determined in several ways. Depending on the value set in the CompressionControl property, the user can set the size of the target file, the actual compression ratio to use during compression or the quality factor to use during compression. If the CodecsJpeg2000SaveOptions.CompressionControl property is set to Ratio, then the compression used is based on the compression ratio in the CodecsJpeg2000SaveOptions.CompressionRatio property. If the CodecsJpeg2000SaveOptions.CompressionControl property is set to TargetSize, the compression used is based on the desired target file size in the CodecsJpeg2000SaveOptions.TargetFileSize property. If the CodecsJpeg2000SaveOptions.CompressionControl property is set to QualityFactor, then the compression used is based on the QualityFactor passed to the Save functions.

Lossless Compression

For lossless compression, set the CodecsJpeg2000SaveOptions.CompressionControl property to Lossless.

Lossy Compression Quantization

There are two types of quantization for Lossy compression: Scalar Derived Quantization and Scalar Expounded Quantization.

The exponent/mantissa pairs are either signaled in the codestream for every sub-band (expounded quantization) or else signaled only for the Low Pass sub-band and derived for all other sub-bands (derived quantization). In the case of derived quantization, all exponent/mantissa pairs are derived from the single exponent/mantissa pair corresponding to the Low pass sub-band.

The quantization step size for a sub-band is calculated from the dynamic range of the sub-band using the following equation, where R = bpp for the sub-band:

Quantization Step = (2 (R - Exponent) ) * [1 + (Mantissa / 2048)]

If the value of the CodecsJpeg2000SaveOptions.CompressionControl property is Ratio, QualityFactor or TargetSize, and the value of the CodecsJpeg2000SaveOptions.AlphaChannelLossless property is true, the compressed J2K/JP2 file will have three lossy components (red, green and blue), in addition to the lossless alpha component.

If the value of the CodecsJpeg2000SaveOptions.CompressionControl property is Lossless, the value of CodecsJpeg2000SaveOptions.AlphaChannelLossless will be ignored and all the components will be lossless.

The alpha channel can be dithered using Leadtools.ImageProcessing.ColorResolutionCommand and Leadtools.ImageProcessing.Color.DynamicBinaryCommand externally, and before saving a J2K/JP2 file, in case a better alpha channel quality is desired.

Tile and Canvas Settings

The values of the CodecsJpeg2000SaveOptions.ImageAreaHorizontalOffset, CodecsJpeg2000SaveOptions.ImageAreaVerticalOffset, CodecsJpeg2000SaveOptions.ReferenceTileHeight, CodecsJpeg2000SaveOptions.ReferenceTileWidth, CodecsJpeg2000SaveOptions.TileHorizontalOffset and CodecsJpeg2000SaveOptions.TileVerticalOffset properties are used to create tiles within the image. Arbitrary tile sizes are allowed. All tiles are the same size, except for the border tiles. Each tile can be compressed individually. This can decrease memory usage while the program is running, but can also generate artifacts at the edges of the tiles. Artifacts generally increase as the size of the tile decreases. By default, there is one tile that contains the entire image.

The reference grid is a rectangular grid of points with the indices from (0, 0) to (Xsiz-1, Ysiz-1). An "image area" is defined on the reference grid by the dimensional parameters, (Xsiz, Ysiz) and (XOsiz, YOsiz). The various parameters defining the reference grid appear in the figures below.

Specifically, the image area on the reference grid is defined by its upper left hand reference grid point at location (XOsiz, YOsiz), and its lower right hand reference grid point at location (Xsiz-1, Ysiz-1).

Property Name Label In Diagram
ImageAreaHorizontalOffset XOsiz
ImageAreaVerticalOffset YOsiz
ReferenceTileHeight XTsiz
ReferenceTileWidth YTsiz
TileHorizontalOffset XTOsiz
TileVerticalOffset YTOsiz

Progression Order

For a given tile-part, the packets contain all compressed image data from a specific layer, a specific component, a specific resolution level, and a specific precinct. The order in which these packets are found in the codestream is called the progression order. Use the CodecsJpeg2000SaveOptions.ProgressingOrder property to set the progression order. The ProgressingOrder property uses the CodecsJpeg2000ProgressionsOrder enumeration to specify the progression The ordering of the packets can progress along four axes: layer, component, resolution and position. The following progressions can be specified:

  1. LayerResolutionComponentPosition. A progression of this type might be useful when low sample accuracy is most desirable, but information is needed for all components.

  2. ResolutionLayerComponentPosition. A progression of this type might be useful in providing low-resolution level versions of all image components.

  3. ResolutionPositionComponentLayer. A progression of this type might be useful in providing low-resolution level versions of all image components at a particular spatial location.

  4. PositionComponentResolutionLayer. A progression of this type might be useful in providing high sample accuracy for a particular spatial location in all components.

  5. ComponentPositionResolutionLayer. A progression of this type might be useful in providing high accuracy for a particular spatial location in a particular image component.

For more information, refer to:

ISO/IEC JTC1/SC29/WG1 N1861: Coding of Still Pictures

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs

Public Sub CodecsJpeg2000OptionsExample()
   Dim codecs As RasterCodecs = New RasterCodecs()

   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.j2k")

   'Setting the Jpeg2000 load options.
   codecs.Options.Jpeg2000.Load.J2kResolution = New LeadSize(800, 800)
   codecs.Options.Jpeg2000.Load.Jp2Resolution = New LeadSize(800, 800)

   'loading a Jpeg2000 image.
   Dim srcImage As RasterImage = codecs.Load(srcFileName)

   'Setting the Jpeg2000 save options 
   codecs.Options.Jpeg2000.Save.CodeBlockHeight = 32
   codecs.Options.Jpeg2000.Save.CodeBlockWidth = 32
   codecs.Options.Jpeg2000.Save.CompressionControl = CodecsJpeg2000CompressionControl.Ratio
   codecs.Options.Jpeg2000.Save.CompressionRatio = 15.0F
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 5
   codecs.Options.Jpeg2000.Save.DerivedBaseExponent = 8
   codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2
   codecs.Options.Jpeg2000.Save.DerivedQuantization = True
   codecs.Options.Jpeg2000.Save.ErrorResilienceSymbol = False
   codecs.Options.Jpeg2000.Save.GuardBits = 4
   codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = 0
   codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = 0
   codecs.Options.Jpeg2000.Save.PredictableTermination = False
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.PositionComponentResolutionLayer
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 240
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 480
   codecs.Options.Jpeg2000.Save.RegionOfInterest = CodecsJpeg2000RegionOfInterest.UseLeadRegion
   codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = New LeadRect(0, 0, 0, 0)
   codecs.Options.Jpeg2000.Save.ResetContextOnBoundaries = False
   codecs.Options.Jpeg2000.Save.SelectiveAcBypass = False
   codecs.Options.Jpeg2000.Save.TargetFileSize = 10240
   codecs.Options.Jpeg2000.Save.TerminationOnEachPass = False
   codecs.Options.Jpeg2000.Save.TileHorizontalOffset = 0
   codecs.Options.Jpeg2000.Save.TileVerticalOffset = 0
   codecs.Options.Jpeg2000.Save.UseColorTransform = True
   codecs.Options.Jpeg2000.Save.UseEphMarker = False
   codecs.Options.Jpeg2000.Save.UseRegionOfInterest = False
   codecs.Options.Jpeg2000.Save.UseSopMarker = False
   codecs.Options.Jpeg2000.Save.VerticallyCausalContext = False

   'Save the first sample.
   codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_test.j2k"), RasterImageFormat.J2k, srcImage.BitsPerPixel)

   'changing some of the Jpeg2000 save options
   codecs.Options.Jpeg2000.Save.CodeBlockHeight = 4
   codecs.Options.Jpeg2000.Save.CodeBlockWidth = 8
   codecs.Options.Jpeg2000.Save.CompressionRatio = 23.0F
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 6
   codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 320
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 320
   codecs.Options.Jpeg2000.Save.UseEphMarker = True
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.ResolutionPositionComponentLayer
   codecs.Options.Jpeg2000.Save.UseSopMarker = True
   codecs.Options.Jpeg2000.Save.TargetFileSize = 102400

   'Save the first sample.
   codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_test.jp2"), RasterImageFormat.J2k, srcImage.BitsPerPixel)

   ' Clean up
   srcImage.Dispose()
   codecs.Dispose()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;

public void CodecsJpeg2000OptionsExample()
{
    RasterCodecs codecs = new RasterCodecs();

    string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.j2k");

    //Setting the Jpeg2000 load options.
    codecs.Options.Jpeg2000.Load.J2kResolution = new LeadSize(800, 800);
    codecs.Options.Jpeg2000.Load.Jp2Resolution = new LeadSize(800, 800);

    //loading a Jpeg2000 image.
    RasterImage srcImage = codecs.Load(srcFileName);

    //Setting the Jpeg2000 save options 
    codecs.Options.Jpeg2000.Save.CodeBlockHeight = 32;
    codecs.Options.Jpeg2000.Save.CodeBlockWidth = 32;
    codecs.Options.Jpeg2000.Save.CompressionControl = CodecsJpeg2000CompressionControl.Ratio;
    codecs.Options.Jpeg2000.Save.CompressionRatio = 15.0f;
    codecs.Options.Jpeg2000.Save.DecompositionLevels = 5;
    codecs.Options.Jpeg2000.Save.DerivedBaseExponent = 8;
    codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2;
    codecs.Options.Jpeg2000.Save.DerivedQuantization = true;
    codecs.Options.Jpeg2000.Save.ErrorResilienceSymbol = false;
    codecs.Options.Jpeg2000.Save.GuardBits = 4;
    codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = 0;
    codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = 0;
    codecs.Options.Jpeg2000.Save.PredictableTermination = false;
    codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.PositionComponentResolutionLayer;
    codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 240;
    codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 480;
    codecs.Options.Jpeg2000.Save.RegionOfInterest = CodecsJpeg2000RegionOfInterest.UseLeadRegion;
    codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = new LeadRect(0, 0, 0, 0);
    codecs.Options.Jpeg2000.Save.ResetContextOnBoundaries = false;
    codecs.Options.Jpeg2000.Save.SelectiveAcBypass = false;
    codecs.Options.Jpeg2000.Save.TargetFileSize = 10240;
    codecs.Options.Jpeg2000.Save.TerminationOnEachPass = false;
    codecs.Options.Jpeg2000.Save.TileHorizontalOffset = 0;
    codecs.Options.Jpeg2000.Save.TileVerticalOffset = 0;
    codecs.Options.Jpeg2000.Save.UseColorTransform = true;
    codecs.Options.Jpeg2000.Save.UseEphMarker = false;
    codecs.Options.Jpeg2000.Save.UseRegionOfInterest = false;
    codecs.Options.Jpeg2000.Save.UseSopMarker = false;
    codecs.Options.Jpeg2000.Save.VerticallyCausalContext = false;

    //Save the first sample.
    codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_test.j2k"), RasterImageFormat.J2k, srcImage.BitsPerPixel);

    //changing some of the Jpeg2000 save options
    codecs.Options.Jpeg2000.Save.CodeBlockHeight = 4;
    codecs.Options.Jpeg2000.Save.CodeBlockWidth = 8;
    codecs.Options.Jpeg2000.Save.CompressionRatio = 23.0f;
    codecs.Options.Jpeg2000.Save.DecompositionLevels = 6;
    codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2;
    codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 320;
    codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 320;
    codecs.Options.Jpeg2000.Save.UseEphMarker = true;
    codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.ResolutionPositionComponentLayer;
    codecs.Options.Jpeg2000.Save.UseSopMarker = true;
    codecs.Options.Jpeg2000.Save.TargetFileSize = 102400;

    //Save the first sample.
    codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_test.jp2"), RasterImageFormat.J2k, srcImage.BitsPerPixel);

    // Clean up
    srcImage.Dispose();
    codecs.Dispose();
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
CodecsOptionsExamples.prototype.CodecsJpeg2000OptionsExample = function ( ) 
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {

         var codecs = new RasterCodecs();
         var image;
         //Setting the Jpeg2000 load options.
         codecs.options.jpeg2000.load.j2kResolution = LeadSizeHelper.create(800, 800);
         codecs.options.jpeg2000.load.jp2Resolution = LeadSizeHelper.create(800, 800);

         //loading a Jpeg2000 image.
         var srcFileName = "Assets\\Image1.j2k";
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (img) {
            image = img;

            //Setting the Jpeg2000 save options 
            codecs.options.jpeg2000.save.codeBlockHeight = 32;
            codecs.options.jpeg2000.save.codeBlockWidth = 32;
            codecs.options.jpeg2000.save.compressionControl = CodecsJpeg2000CompressionControl.ratio;
            codecs.options.jpeg2000.save.compressionRatio = 15.0;
            codecs.options.jpeg2000.save.decompositionLevels = 5;
            codecs.options.jpeg2000.save.derivedBaseExponent = 8;
            codecs.options.jpeg2000.save.derivedBaseMantissa = 2;
            codecs.options.jpeg2000.save.derivedQuantization = true;
            codecs.options.jpeg2000.save.errorResilienceSymbol = false;
            codecs.options.jpeg2000.save.guardBits = 4;
            codecs.options.jpeg2000.save.imageAreaHorizontalOffset = 0;
            codecs.options.jpeg2000.save.imageAreaVerticalOffset = 0;
            codecs.options.jpeg2000.save.predictableTermination = false;
            codecs.options.jpeg2000.save.progressingOrder = CodecsJpeg2000ProgressionsOrder.positionComponentResolutionLayer;
            codecs.options.jpeg2000.save.referenceTileHeight = 240;
            codecs.options.jpeg2000.save.referenceTileWidth = 480;
            codecs.options.jpeg2000.save.regionOfInterest = CodecsJpeg2000RegionOfInterest.useLeadRegion;
            codecs.options.jpeg2000.save.regionOfInterestRectangle = LeadRectHelper.create(0, 0, 0, 0);
            codecs.options.jpeg2000.save.resetContextOnBoundaries = false;
            codecs.options.jpeg2000.save.selectiveAcBypass = false;
            codecs.options.jpeg2000.save.targetFileSize = 10240;
            codecs.options.jpeg2000.save.terminationOnEachPass = false;
            codecs.options.jpeg2000.save.tileHorizontalOffset = 0;
            codecs.options.jpeg2000.save.tileVerticalOffset = 0;
            codecs.options.jpeg2000.save.useColorTransform = true;
            codecs.options.jpeg2000.save.useEphMarker = false;
            codecs.options.jpeg2000.save.useRegionOfInterest = false;
            codecs.options.jpeg2000.save.useSopMarker = false;
            codecs.options.jpeg2000.save.verticallyCausalContext = false;

            //Save the first sample.
            var destFileName = "Image1_test.j2k";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         }).then(function (saveFile) {
            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.j2k, image.bitsPerPixel)
         })
         .then(function () {

            //changing some of the Jpeg2000 save options
            codecs.options.jpeg2000.save.codeBlockHeight = 4;
            codecs.options.jpeg2000.save.codeBlockWidth = 8;
            codecs.options.jpeg2000.save.compressionRatio = 23.0;
            codecs.options.jpeg2000.save.decompositionLevels = 6;
            codecs.options.jpeg2000.save.derivedBaseMantissa = 2;
            codecs.options.jpeg2000.save.referenceTileHeight = 320;
            codecs.options.jpeg2000.save.referenceTileWidth = 320;
            codecs.options.jpeg2000.save.useEphMarker = true;
            codecs.options.jpeg2000.save.progressingOrder = CodecsJpeg2000ProgressionsOrder.resolutionPositionComponentLayer;
            codecs.options.jpeg2000.save.useSopMarker = true;
            codecs.options.jpeg2000.save.targetFileSize = 102400;

            //Save the first sample.
            var destFileName = "Image1_test.jp2";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.j2k, image.bitsPerPixel)
         })
         .then(function () {

            // Clean up
            image.close();
            codecs.close();
         });
      }
   }
}
using Leadtools;
using Leadtools.Codecs;

      
public async Task CodecsJpeg2000OptionsExample()
{
   RasterCodecs codecs = new RasterCodecs();
   //Setting the Jpeg2000 load options.
   codecs.Options.Jpeg2000.Load.J2kResolution = LeadSizeHelper.Create(800, 800);
   codecs.Options.Jpeg2000.Load.Jp2Resolution = LeadSizeHelper.Create(800, 800);

   //loading a Jpeg2000 image.
   string srcFileName = @"Assets\Image1.j2k";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   //Setting the Jpeg2000 save options 
   codecs.Options.Jpeg2000.Save.CodeBlockHeight = 32;
   codecs.Options.Jpeg2000.Save.CodeBlockWidth = 32;
   codecs.Options.Jpeg2000.Save.CompressionControl = CodecsJpeg2000CompressionControl.Ratio;
   codecs.Options.Jpeg2000.Save.CompressionRatio = 15.0f;
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 5;
   codecs.Options.Jpeg2000.Save.DerivedBaseExponent = 8;
   codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2;
   codecs.Options.Jpeg2000.Save.DerivedQuantization = true;
   codecs.Options.Jpeg2000.Save.ErrorResilienceSymbol = false;
   codecs.Options.Jpeg2000.Save.GuardBits = 4;
   codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = 0;
   codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = 0;
   codecs.Options.Jpeg2000.Save.PredictableTermination = false;
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.PositionComponentResolutionLayer;
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 240;
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 480;
   codecs.Options.Jpeg2000.Save.RegionOfInterest = CodecsJpeg2000RegionOfInterest.UseLeadRegion;
   codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = LeadRectHelper.Create(0, 0, 0, 0);
   codecs.Options.Jpeg2000.Save.ResetContextOnBoundaries = false;
   codecs.Options.Jpeg2000.Save.SelectiveAcBypass = false;
   codecs.Options.Jpeg2000.Save.TargetFileSize = 10240;
   codecs.Options.Jpeg2000.Save.TerminationOnEachPass = false;
   codecs.Options.Jpeg2000.Save.TileHorizontalOffset = 0;
   codecs.Options.Jpeg2000.Save.TileVerticalOffset = 0;
   codecs.Options.Jpeg2000.Save.UseColorTransform = true;
   codecs.Options.Jpeg2000.Save.UseEphMarker = false;
   codecs.Options.Jpeg2000.Save.UseRegionOfInterest = false;
   codecs.Options.Jpeg2000.Save.UseSopMarker = false;
   codecs.Options.Jpeg2000.Save.VerticallyCausalContext = false;

   //Save the first sample.
   string destFileName = @"Image1_test.j2k";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.J2k, image.BitsPerPixel);

   //changing some of the Jpeg2000 save options
   codecs.Options.Jpeg2000.Save.CodeBlockHeight = 4;
   codecs.Options.Jpeg2000.Save.CodeBlockWidth = 8;
   codecs.Options.Jpeg2000.Save.CompressionRatio = 23.0f;
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 6;
   codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2;
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 320;
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 320;
   codecs.Options.Jpeg2000.Save.UseEphMarker = true;
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.ResolutionPositionComponentLayer;
   codecs.Options.Jpeg2000.Save.UseSopMarker = true;
   codecs.Options.Jpeg2000.Save.TargetFileSize = 102400;

   //Save the first sample.
   destFileName = @"Image1_test.jp2";
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.J2k, image.BitsPerPixel);

   // Clean up
   image.Dispose();
   codecs.Dispose();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;
using Leadtools.ImageProcessing;

public void CodecsJpeg2000OptionsExample(Stream inStream, Stream outStreamJ2k, Stream outStreamJp2)
{
   RasterCodecs codecs = new RasterCodecs();
   //Setting the Jpeg2000 load options.
   codecs.Options.Jpeg2000.Load.J2kResolution = new LeadSize(800, 800);
   codecs.Options.Jpeg2000.Load.Jp2Resolution = new LeadSize(800, 800);

   //loading a Jpeg2000 image.
   RasterImage srcImage = codecs.Load(inStream);

   //Setting the Jpeg2000 save options 
   codecs.Options.Jpeg2000.Save.CodeBlockHeight = 32;
   codecs.Options.Jpeg2000.Save.CodeBlockWidth = 32;
   codecs.Options.Jpeg2000.Save.CompressionControl = CodecsJpeg2000CompressionControl.Ratio;
   codecs.Options.Jpeg2000.Save.CompressionRatio = 15.0f;
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 5;
   codecs.Options.Jpeg2000.Save.DerivedBaseExponent = 8;
   codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2;
   codecs.Options.Jpeg2000.Save.DerivedQuantization = true;
   codecs.Options.Jpeg2000.Save.ErrorResilienceSymbol = false;
   codecs.Options.Jpeg2000.Save.GuardBits = 4;
   codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = 0;
   codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = 0;
   codecs.Options.Jpeg2000.Save.PredictableTermination = false;
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.PositionComponentResolutionLayer;
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 240;
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 480;
   codecs.Options.Jpeg2000.Save.RegionOfInterest = CodecsJpeg2000RegionOfInterest.UseLeadRegion;
   codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = new LeadRect(0, 0, 0, 0);
   codecs.Options.Jpeg2000.Save.ResetContextOnBoundaries = false;
   codecs.Options.Jpeg2000.Save.SelectiveAcBypass = false;
   codecs.Options.Jpeg2000.Save.TargetFileSize = 10240;
   codecs.Options.Jpeg2000.Save.TerminationOnEachPass = false;
   codecs.Options.Jpeg2000.Save.TileHorizontalOffset = 0;
   codecs.Options.Jpeg2000.Save.TileVerticalOffset = 0;
   codecs.Options.Jpeg2000.Save.UseColorTransform = true;
   codecs.Options.Jpeg2000.Save.UseEphMarker = false;
   codecs.Options.Jpeg2000.Save.UseRegionOfInterest = false;
   codecs.Options.Jpeg2000.Save.UseSopMarker = false;
   codecs.Options.Jpeg2000.Save.VerticallyCausalContext = false;

   //Save the first sample.
   codecs.Save(srcImage, outStreamJ2k, RasterImageFormat.J2k, srcImage.BitsPerPixel);

   //changing some of the Jpeg2000 save options
   codecs.Options.Jpeg2000.Save.CodeBlockHeight = 4;
   codecs.Options.Jpeg2000.Save.CodeBlockWidth = 8;
   codecs.Options.Jpeg2000.Save.CompressionRatio = 23.0f;
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 6;
   codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2;
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 320;
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 320;
   codecs.Options.Jpeg2000.Save.UseEphMarker = true;
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.ResolutionPositionComponentLayer;
   codecs.Options.Jpeg2000.Save.UseSopMarker = true;
   codecs.Options.Jpeg2000.Save.TargetFileSize = 102400;

   //Save the second sample.
   codecs.Save(srcImage, outStreamJp2, RasterImageFormat.J2k, srcImage.BitsPerPixel);

   // Clean up
   srcImage.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing

Public Sub CodecsJpeg2000OptionsExample(ByVal inStream As Stream, ByVal outStreamJ2k As Stream, ByVal outStreamJp2 As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   'Setting the Jpeg2000 load options.
   codecs.Options.Jpeg2000.Load.J2kResolution = New LeadSize(800, 800)
   codecs.Options.Jpeg2000.Load.Jp2Resolution = New LeadSize(800, 800)

   'loading a Jpeg2000 image.
   Dim srcImage As RasterImage = codecs.Load(inStream)

   'Setting the Jpeg2000 save options 
   codecs.Options.Jpeg2000.Save.CodeBlockHeight = 32
   codecs.Options.Jpeg2000.Save.CodeBlockWidth = 32
   codecs.Options.Jpeg2000.Save.CompressionControl = CodecsJpeg2000CompressionControl.Ratio
   codecs.Options.Jpeg2000.Save.CompressionRatio = 15.0f
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 5
   codecs.Options.Jpeg2000.Save.DerivedBaseExponent = 8
   codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2
   codecs.Options.Jpeg2000.Save.DerivedQuantization = True
   codecs.Options.Jpeg2000.Save.ErrorResilienceSymbol = False
   codecs.Options.Jpeg2000.Save.GuardBits = 4
   codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = 0
   codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = 0
   codecs.Options.Jpeg2000.Save.PredictableTermination = False
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.PositionComponentResolutionLayer
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 240
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 480
   codecs.Options.Jpeg2000.Save.RegionOfInterest = CodecsJpeg2000RegionOfInterest.UseLeadRegion
   codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = New LeadRect(0, 0, 0, 0)
   codecs.Options.Jpeg2000.Save.ResetContextOnBoundaries = False
   codecs.Options.Jpeg2000.Save.SelectiveAcBypass = False
   codecs.Options.Jpeg2000.Save.TargetFileSize = 10240
   codecs.Options.Jpeg2000.Save.TerminationOnEachPass = False
   codecs.Options.Jpeg2000.Save.TileHorizontalOffset = 0
   codecs.Options.Jpeg2000.Save.TileVerticalOffset = 0
   codecs.Options.Jpeg2000.Save.UseColorTransform = True
   codecs.Options.Jpeg2000.Save.UseEphMarker = False
   codecs.Options.Jpeg2000.Save.UseRegionOfInterest = False
   codecs.Options.Jpeg2000.Save.UseSopMarker = False
   codecs.Options.Jpeg2000.Save.VerticallyCausalContext = False

   'Save the first sample.
   codecs.Save(srcImage, outStreamJ2k, RasterImageFormat.J2k, srcImage.BitsPerPixel)

   'changing some of the Jpeg2000 save options
   codecs.Options.Jpeg2000.Save.CodeBlockHeight = 4
   codecs.Options.Jpeg2000.Save.CodeBlockWidth = 8
   codecs.Options.Jpeg2000.Save.CompressionRatio = 23.0f
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 6
   codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = 2
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 320
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 320
   codecs.Options.Jpeg2000.Save.UseEphMarker = True
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.ResolutionPositionComponentLayer
   codecs.Options.Jpeg2000.Save.UseSopMarker = True
   codecs.Options.Jpeg2000.Save.TargetFileSize = 102400

   'Save the second sample.
   codecs.Save(srcImage, outStreamJp2, RasterImageFormat.J2k, srcImage.BitsPerPixel)

   ' Clean up
   srcImage.Dispose()
End Sub
Requirements

Target Platforms

See Also

Reference

CodecsJpeg2000Options Members
Leadtools.Codecs Namespace
Programming With JPEG 2000 Features

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.