PICTools Programmer's Reference
OP_LIP3, OP_LIP3PLUS

OP_LIP3, OP_LIP3PLUS: Compress DIB or RAW to Lossless JPEG and IMSTAR

See the LOSSLESS3:OP_LIP3 section for additional information about compressing DIBs using IMStar lossless compression. 

OP_LIP3 produces lossless JPEG files from 1bpp to 8bpp grayscale and 24bpp RGB images. IMStar and LOCO compression can be used with 1bpp, 4bpp, or 8bpp color-mapped and grayscale images.

OP_LIP3PLUS adds the ability to compress up to 16bpp grayscale and 48bpp RGB data using standard lossless JPEG compression.

The compression process follows the familiar REQ_INIT, REQ_EXEC, REQ_TERM sequence of calls to Pegasus. Before REQ_INIT, some image data is placed in a Get buffer and a PIC_PARM structure, pic_parm, is allocated and its basic structure members initialized:

 
Copy Code
PIC_PARM pic_parm;
pic_parm.u.ParmSize = sizeof(PIC_PARM);
pic_parm.u.ParmVer = CURRENT_PARMVER;
pic_parm.u.ParmVerMinor = 2;
pic_parm.u.Op = OP_LIP3;

It is recommended that a defer function callback is defined, assigned to DeferFn and F_UseDeferFn set in Flags. REQ_INIT returns the minimum size for the Get buffer in u.LL3.StripSize. The Get queue must be at least u.LL3.StripSize bytes in length.

The compression algorithm used is indicated with the u.LL3.CompMethod field: 

Compression can be further tuned by setting u.LL3.CompOrder. For lossless JPEG, u.LL3.CompOrder is the predictor for lossless JPEG. Its value may be between 1 and 7, inclusive.  For IMStar, u.LL3.CompOrder is the order, or length, of the context that is to be used to predict the image pixels. Its value may be between 1 and 4, inclusive.

The compressed image is stored in a PIC2 file format by default. To create standard lossless JPEG-compliant files for lossless JPEG compression, set PF_JPEGFileOnly in u.LL3.PicFlags.

To support larger images, where stride exceeds 32767, set ParmVerMinor to 4 so that u.LL3.Region is considered a REGION2 structure. Otherwise, ParmVerMinor should be set to 2 so that u.LL3.Region is considered a REGION structure. See the LOSSLESS3:OP_LIP3 section and the REGION2 section for more information.

If PF_YieldGet is set in u.LL3.PicFlags then OP_LIP3 will return a RES_GET_DATA_YIELD response periodically during compression. This behavior allows an application to update compression progress reporting.

This opcode allows image data to be encrypted using an application-provided key. See details in the section describing the PIC_PARM KeyField field.

If PF_HaveWatermark is set in u.LL3.PicFlags, then a P2P_Watermark packet in PIC2List will be combined with the image in such a way that the watermark can be recovered when the image is expanded. In this case the compression is lossy because the original source image pixel values cannot be exactly recovered. However, the loss will ordinarily not be visible. A watermark cannot be combined with non-grayscale, 1bpp images.

Packets of type P2P_Comment and P2P_RawData in PIC2List will also be put into the compressed image file. If the output file is a lossless JPEG file, then P2P_Comment packets will be placed into comment sections, and P2P_RawData packets will be placed into "APPn" sections, where n is the hexadecimal APP marker number, depending upon the RawDescription. See include\pic2file.h and the PIC2List section of Accessing Comments and Other Auxiliary Data in the PICTools and AIMTools Programmer’s Guide for more information about PIC2List packets.

PIC2 Files

The compressed image is stored in a PIC2 file format when PF_JPEGFIleOnly is clear in u.LL3.PicFlags.

The PIC2 file format supports an optional CRC-32 check of file integrity. If the Put queue is large enough to hold the entire compressed image, the CRC will be added to the output image and PF_DidPolish will be set in u.LL3.PicFlags. The output is a valid PIC2 format image file even if no CRC is present.

Applications can specify useful, non-essential image characteristics in images compressed with OP_LIP3 into a PIC2 file. The following LOSSLESS3 fields may be stored into compressed images to assist applications with presentation of the decompressed image: NumOfPages, PageNum, DispMethod, UserDelay, XOff, YOff, and Transparent. For more information about these fields, see the LOSSLESS3:OP_LIP3 section.

The PIC2 file format specifies fields that must be written to the output before their values can be known during sequential processing of the input. If the Put queue is not large enough for the entire compressed image, then the output locations for these values may not be present in the Put queue buffer when the values become known. In that case, after all other image data are output a RES_POKE response will be returned for each field to be updated. At that point, SeekInfo will have the offset from the start of the output data Put.FrontEnd will point to the field value, and Put.RearEnd minus Put.FrontEnd will be the length of the value. For example:

 
Copy Code
case RES_POKE:
  fseek( file, pic_parm.SeekInfo, SEEK_SET );
  fwrite( pic_parm.Put.FrontEnd, 1, pic_parm.Put.RearEnd - pic_parm.Put.FrontEnd,  file );
  break;

RGB Images

For 24bpp and 48bpp RGB images, either set F_Bmp in Flags and populate the Head fields, or set F_Raw in Flags and populate the u.LL3.Region fields. 

For 48bpp RGB RAW data, set u.LL3.Region.PixType to PT_RGBM for bytes ordered in big-endian (Motorola) format, or PT_RGB for bytes ordered in little-endian (Intel) format.

The interleaved pixel component sample ordering must be BGR (Blue, Green, and then Red). Set RF_SwapRB in u.LL3.Region.Flags for RAW input whose component sample ordering is not BGR.

To convert 24bpp RGB to grayscale, set F_Raw in Flags and populate the u.LL3.Region fields, and set RF_MakeGray in u.LL3.Region.Flags.

By default, 24bpp RGB samples remain in the RGB colorspace. However, if PF_LIPUseYCbCrForColors is set in u.LL3.PicFlags, the pixels are converted to a pseudo-YCbCr colorspace prior to compression. This proprietary format requires PICTools for decoding, but compresses better than RGB and remains lossless.

Color-Mapped Images

For 1bpp to 8bpp color-mapped images, either set F_Bmp in Flags and populate the Head fields, or set F_Raw in Flags and fill in the u.LL3.Region fields. Packed pixels, i.e., more than one pixel per byte, are not supported. 

Grayscale Images

For 1bpp to 8bpp DIB images, set F_Bmp in Flags and fill in the Head fields. Packed pixels, i.e., more than one pixel per byte, are not supported. 

For 1bpp to 16bpp RAW data, set F_Raw in Flags and fill in the u.LL3.Region fields.

For 9bpp to 16bpp high-gray RAW data, set u.LL3.Region.PixType to either PT_GRAYM, for bytes ordered in Motorola/big-endian format or PT_GRAY, for bytes ordered in Intel/little-endian format.

Set the u.LL3.CompMethod to choose the desired compression method. For the advantages of each, see the information above.

Specify a non-zero u.LL3.AllowedBitErr value to filter noise or other low-intensity image variations from grayscale images. The u.LL3.AllowedBitErr field specifies the number of least significant bits masked out of each image pixel’s gray level prior to compression. This may improve the compression and, in some cases, the appearance of the image. However, the image compression will become lossy, and the original source image will no longer be exactly recovered from the compressed image. 

Set PF_JPEGFileOnly in u.LL3.PicFlags to create a standard lossless JPEG-compliant file instead of a PIC2 file.

 

 


©2022. Accusoft Corporation. All Rights Reserved.

Send Feedback