PICTools Programmer's Reference
OP_JLSP

OP_JLSP: Compress DIB or RAW to JPEG-LS

See the JLS_UNION:OP_JLSP, OP_JLSE, the LSSCAN, and the REGION sections for additional information about compressing DIBs using JPEG-LS. 

OP_JLSP is used for compressing images according to the JPEG-LS standard. JPEG-LS is a sophisticated algorithm, designed to give excellent lossless or near-lossless compression performance over a wide range of images. As is the case for any image compression, and is particularly applicable to lossless compression, the effectiveness of the compression is dependent upon tuning the algorithm to the statistics of the image. JPEG-LS has made visible some key parameters that can be used to tune the algorithm for specific images to possibly achieve better compression than the defaults would give. The parameters MAXVAL, T1, T2, T3 and RESET are fundamental to the operation of the algorithm. Either these values are put in the marker segments or it is clearly made known to the decoder that the defaults are to be used. It is essential that the decoder use the same values as the encoder.

The default values for the parameters of the JPEG-LS algorithm have been carefully chosen so that most images will compress well. It is recommended that the default values be used when possible. It is not easy to predict, without doing theoretical analysis or experimentation on specific images, how changes to the parameters will affect the compression performance. Changes to the parameters will affect different types of images in different ways. However, OP_JLSP does make these parameters accessible in the LSSCAN structure so that they can be changed if desired.

The JPEG-LS parameter MAXVAL must be set equal to or greater than the maximum image sample value over all components of a scan but no greater than the maximum sample value allowed by the bit precision of the samples (after applying the point transform if necessary). The maximum possible value allowed by the bit precision (adjusted for point transform if necessary) of the samples is used by default. A MAXVAL close to the true maximum should give best compression performance. JPEG-LS uses the parameters T1, T2, T3 (to determine context) and RESET (to modify the accumulation of statistics) as it processes each input sample; setting these to other than default values will affect compression performance in an image-dependent way.

JPEG-LS defines the parameter NEAR (specified by NEARparam in the LSSCAN structure) that is used by OP_JLSP to provide near-lossless compression of an input image. NEARparam defines the error tolerance for near-lossless compression. If NEARparam is set to zero, compression will be lossless and the reconstructed image after decompression will be identical to the original. If NEARparam is set to a nonzero value, the JPEG-LS algorithm guarantees that each sample value of the reconstructed image will differ from the original by no more than the value of NEARparam (when point transform is zero; if point transform is nonzero, then this tolerance refers to the point‑transformed samples). Generally, NEARparam should be set to zero or a small positive number.

JPEG-LS allows a point transform (Pt) to be specified whose purpose is to define a right shift that is applied to all input samples prior to encoding and then an equal, but opposite, left shift to all output samples after decoding. The point transform thus defines the number of low-order bits that will be zero in each reconstructed sample after decompression. A point transform is another way to use the JPEG‑LS algorithm in a near-lossless mode, but NEARparam is preferred because it provides a much better error distribution. A point transform might be useful when compressing a noisy image. Note that a point transform reduces the effective precision of the samples being encoded and therefore reduces the default/maximum allowed MAXVAL used by OP_JLSP.

JPEG-LS defines the parameter ILV (specified by ILVparam in the LSSCAN structure) to specify the interleave mode for multicomponent images. OP_JLSP is capable of compressing single-component images with sample size ranging from 2 to 16 bits; in this case, ILVparam is set to JLS_NONINTERLEAVED. OP_JLSP can also compress 24-bit three-component images (assumed to be RGB) in one of three modes: ILVparam set to JLS_NONINTERLEAVED (numerically, 0), ILVparam set to JLS_LINEINTERLEAVED (numerically, 1), or ILVparam set to JLS_SAMPLEINTERLEAVED (numerically, 2). When JLS_NONINTERLEAVED is specified, each component is encoded in its own scan. If JLS_LINEINTERLEAVED is specified, all components are encoded together in one scan with the samples interleaved line-by-line as they are encoded. When JLS_SAMPLEINTERLEAVED is specified, all components are encoded in one scan with the samples interleaved sample-by-sample as they are encoded. Typically, JLS_NONINTERLEAVED or JLS_LINEINTERLEAVED would be used to encode an RGB image. Either mode will compress the image well; however, the two modes will produce different compressed files and which mode compresses better is a function of the characteristics of the image. The mode JLS_SAMPLEINTERLEAVED is specialized and intended for synthetic graphics or computer-generated compound documents (i.e., images likely to contain large flat areas that are common to all the components). On other image types, this mode is likely to be slower, and compress worse, than the other modes. When compression is lossless (NEARparam is zero), all three modes will decompress to the same image. When compression is near-lossless (NEARparam is nonzero), all three modes will meet the error tolerance for all reconstructed samples but the errors will not be the same; the decompressed images will differ.

OP_JLSP does not currently support the advanced JPEG-LS features of sub-sampled components and mapping tables for palletized images. In order to support larger images, this opcode supports the optional use of REGION2. If ParmVerMinor is set to 4, then the opcode treats u.JLS.Region as a REGION2 structure instead of a REGION structure. Otherwise, ParmVerMinor should be set to 2. See the REGION2 section for more information.

StripSize will have been set by OP_JLSP after REQ_INIT is complete.  The Get queue must be at least StripSize bytes in length. If an RGB image is to be compressed as one component per scan (i.e., ILVparam is set to JLS_NONINTERLEAVED), then the entire image must be available in the GET queue; OP_JLSP sets StripSize to the proper value. Otherwise, StripSize is set to Region.Stride and OP_JLSP consumes the data in the GET queue line-by-line. For RGB (24-bit) images, OP_JLSP expects data in the GET queue to be interleaved as RGB when RF_SwapRB is set in Region.Flags or as BGR when RF_SwapRB is clear.

If PF_YieldGet is set in u.JLS.PicFlags then OP_JLSP will return a RES_GET_DATA_YIELD response periodically during compression.  This would allow an application to update compression progress reporting for example.

OP_JLSP allows the optional insertion of comments and application data using PIC2List packets. See the PIC2List section of Accessing Comments and Other Auxiliary Data in the PICTools and AIMTools Programmer's Guide for more information about how opcodes use PIC2List packets.

A subrectangle of the input image can be compressed by setting F_Crop in PicParm.Flags and setting PicParm.CropXoff, PicParm.CropYoff, PicParm.CropWidth, and PicParm.CropHeight to describe the subrectangle.

 

 

 


©2022. Accusoft Corporation. All Rights Reserved.

Send Feedback