PICTools Programmer's Reference
OP_JBIG2P

OP_JBIG2P: Compress DIB or RAW to JBIG2

See the JBIG2_UNION:OP_JBIG2P, OP_JBIG2E, the JBIG2_REGION, and the REGION sections for additional information about compressing DIBs using JBIG2.  Note that OP_JBIG2P requires that ParmVerMinor be 2.

OP_JBIG2P is used for compressing images according to the JBIG2 standard. JBIG2 is a sophisticated algorithm, designed to give excellent lossless or lossy compression performance for bi-level images. The JBIG2 standard does not explicitly define how to encode an image; rather, it defines the specifics of the bitstream of an encoded image and precisely how a decoder would interpret that bitstream to reconstruct the image. A compliant decoder must produce the same image that the encoder encodes, which may be lossless or lossy compared to the original image. Even if JBIG2 encoding is lossy, all compliant decoders will reconstruct the identical image.

A JBIG2 encoder is free to encode an image in any of a number of ways, with the specifics being chosen to satisfy some criterion such as degree of compression, speed of execution, memory requirements, amount of tolerable loss, etc. The standard has defined many parameters that control how the bitstream is to be decoded; this allows the encoder to be extremely flexible in deciding how to encode a particular image. Such flexibility, however, also implies that a sound understanding of the JBIG2 standard and encoding principles for bi-level images is necessary for choosing the best values for the parameters. Therefore, OP_JBIG2P provides several pre-defined encoding modes, each of which tailors the parameters to best meet a specific need. (Contact Accusoft Corporation to discuss any needs not met by these pre-defined encoding modes).

OP_JBIG2P supports lossless and lossy compression. The input image is encoded as one page comprising one or more JBIG2 regions, with each of those regions being a generic region, a text region, or a halftone region. Each region is identified by its x and y offsets and its width and height in pixels; setting them all to zero selects the entire image to be encoded as one region. Specify an encoding mode for the region and the compression parameters will be implicitly set according to the mode selected. The pre-defined encoding modes for generic regions provide lossless encoding of the specified region. Text regions can be encoded as lossless or as lossy according to the encoding mode specified. The lossy modes use the value in Looseness to control how loose to be when matching symbols and thereby increase compression and reduce filesize. Compression means loss, however, and a consequence of higher compression is an increased risk of errors in the reconstructed image. Specify a larger value of Looseness to reduce the compressed filesize; use a smaller value to reduce the errors, if any. Halftone regions can be encoded lossy by specifying one of the lossy halftone encoding modes. Alternatively, they can be encoded lossless by using the lossless generic encoding mode.

A JBIG2 bitstream contains a bit in the page header that is used to indicate if the encoded page is a lossless representation of the original (pre-coding) page. OP_JBIG2P sets this bit only if the JBIG2_PageFlags_IsLossless flag is set in u.JBIG2.PageFlags. The default behavior (flag clear) is not to set the bit.

The number of regions used for encoding a page is equal to u.JBIG2.NumOtherJBIG2Regions + 1. If a page is to be encoded as only one region, OP_JBIG2P uses the coordinates and encoding parameters found in u.JBIG2.BaseJBIG2Region. If a page is to be encoded as more than one region, OP_JBIG2P uses the coordinates and encoding parameters found in u.JBIG2.BaseJBIG2Region and sequentially in the array of structures pointed to by u.JBIG2.OtherJBIG2Regions. Think of a page as a base region with overlaid regions and these regions may or may not overlap. Pixels will be encoded according to the parameters of the last-specified region (top-most layer) in which the pixels reside. i.e., coordinates and encoding parameters in u.JBIG2.OtherJBIG2Regions[m] are used to encode only those pixels not encoded in any u.JBIG2.OtherJBIG2Regions[n], n > m, and coordinates and parameters in u.JBIG2.BaseJBIG2Region are used for encoding those pixels not encoded by any other u.JBIG2.OtherJBIG2Regions. Specify the base region as a full-page region to ensure that all pixels have been encoded; any pixels not encoded in any other region will be encoded in that base region.

A JBIG2 file may be organized in two ways, for sequential access or for random access. Sequential organization is intended for streaming applications, where the decoder reads and decodes the file in order as the data is received. Random access organization permits the decoder to know the entire file structure without having to read the entire file and then use that information to access the required data in a random-access fashion; this would be useful for applications such as decoding only odd-number pages, for example. The default file organization used by OP_JBIG2P is sequential, chosen by setting u.JBIG2.FileOrg to JBIG2_FileOrg_Default or JBIG2_FileOrg_Sequential. Set u.JBIG2.FileOrg to JBIG2_FileOrg_RandomAccess for random access organization.

The input image to be compressed can be formatted as a Windows DIB, if F_Bmp is set or if F_Raw is clear in PicParm.Flags, or as raw image data otherwise. In both cases, the image is 1 bit per pixel packed 8 pixels per byte with the most significant bit corresponding to the leftmost pixel. A Windows DIB has each row padded to a 32-bit boundary. By default OP_JBIG2P assumes that the image to encode follows the interpretation of a zero bit as white and a one bit as black. If F_Bmp is set, then the colormap is used to properly set the bits as one or zero before encoding. For the F_Raw case, set the flag RF_WhiteIsZero in u.JBIG2.Region.Flags to prevent OP_JBIG2P from inverting the bits prior to encoding.

u.JBIG2.StripSize will have been set by OP_JBIG2P after REQ_INIT is complete.  The Get queue must be at least StripSize bytes in length.

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

OP_JBIG2P allows the optional insertion of comments (as comment extension segments) using PIC2List packets. Comments are entered as name-value pairs; a null character separates the name from the value. One pair is input in each packet of type P2P_JBIG2Comment with the SegNum field set to the same number for related packets that are to be inserted together into the same segment. Comments can be 8-bit ANSI or 16-bit Unicode; the CharSet field indicates which. Note that the SegNum field is only used to communicate proper grouping to OP_JBIG2P and will not necessarily be the actual number of the comment extension segment in the JBIG2 bitstream.  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.  See the pic2file.h in the PICTools include directory for more information about the JBIG2Comment packet.

 

 

 


©2022. Accusoft Corporation. All Rights Reserved.

Send Feedback