📄 jbig.doc
字号:
Using the JBIG-KIT library--------------------------Markus Kuhn -- 1998-04-10This text explains how to include the functions provided by theJBIG-KIT portable image compression library into your applicationsoftware.1 Introduction to JBIGBelow follows a short introduction into some technical aspects of theJBIG standard. More detailed information is provided in the"Introduction and overview" section of the JBIG standard. Informationabout how to obtain a copy of the standard is available on theInternet from <http://www.itu.ch/> or <http://www.iso.ch/>.Image data encoded with the JBIG algorithm is separated into planes,layers, and stripes. Each plane contains one bit per pixel. The numberof planes stored in a JBIG data stream is the number of bits perpixel. Resolution layers are numbered from 0 to D with 0 being thelayer with the lowest resolution and D the layer with the highest one.Each next higher resolution layer has exactly twice the number of rowsand columns than the previous one. Layer 0 is encoded independently ofany other data, all other resolution layers are encoded as only thedifference between the next lower and the current layer. Forapplications that require very quick access to parts of an image it ispossible to divide an image into several horizontal stripes. Allstripes of one resolution layer have equal size except perhaps thefinal one. The number of stripes of an image is equal in allresolution layers and in all bit planes.The compressed data stream specified by the JBIG standard is called abi-level image entity (BIE). A BIE consists of a 20-byte header,followed by an optional 1728-byte table (usually not present, exceptin special applications) followed by a sequence of stripe dataentities (SDE). SDEs are the data blocks of which each encodes thecontent of one single stripe in one plane and resolution layer.Between the SDEs, other information blocks (called floating markersegments) can also be present, which change certain parameters of thealgorithm in the middle of an image or contain additional applicationspecific information. A BIE looks like this: +------------------------------------------------+ | | | 20-byte header (with image size, #planes, | | #layers, stripe size, first layer, options, | | SDE ordering, ...) | | | +------------------------------------------------+ | | | optional 1728-byte table | | | +------------------------------------------------+ | | | stripe data entity | | | +------------------------------------------------+ | | | optional floating marker segments | | | +------------------------------------------------+ | | | stripe data entity | | | +------------------------------------------------+ ... +------------------------------------------------+ | | | stripe data entity | | | +------------------------------------------------+One BIE can contain all resolution layers of an image, but it is alsopossible to store various resolution layers in several BIEs. The BIEheader contains the number of the first and the last resolution layerstored in this BIE, as well as the size of the highest resolutionlayer stored in this BIE. Progressive coding is deactivated by simplystoring the image in one single resolution layer.Different applications might have different requirements for the orderin which the SDEs for stripes of various planes and layers are storedin the BIE, so all possible sensible orderings are allowed andindicated by four bits in the header.It is possible to use the raw BIE data stream as specified by the JBIGstandard directly as the format of a file used for storing images.This is what the JBIG<->PBM conversion tools that are provided in thispackage as demonstration applications do. However as the BIE formathas been designed for a large number of very different applicationsand also in order to allow efficient direct processing by special JBIGhardware chip implementations, the BIE header contains only theminimum amount of information absolutely required by the decompressionalgorithm. A large number of features expected from a good file formatare missing in the BIE data stream: - no "magic code" in the first few bytes to allow identification of the file on a typeless file system as JBIG encoded and to allow automatic distinction from other compression algorithms - no standardized way to encode additional information like a textual description, information about the meaning of various bit planes, the physical size and resolution of the document, etc. - a checksum that ensures image integrity - encryption and signature mechanisms - many things moreRaw BIE data streams alone are consequently no suitable format fordocument archiving and exchange. A standard format for this purposewould typically combine a BIE representing the image data togetherwith an additional header providing auxiliary information into onefile. Existing established multi-purpose file formats with a rich setof auxiliary information attributes like TIFF could be extended easilyso that they can also contain JBIG compressed data.On the other hand, in database applications for instance, a BIE mightbe directly stored in a variable length field. Auxiliary informationon which efficient search operations are required would then be storedin other fields of the same record.2 Compressing an image2.1 Format of the source imageFor processing by the library, the image has to be present in memoryas separate bitmap planes. Each byte of a bitmap contains eightpixels, the most significant bit represents the leftmost of thesepixels. Each line of a bitmap has to be stored in an integral numberof bytes. If the image width is not an integral multiple of eight,then the final byte has to be padded with zero bits.For example the 23x5 pixels large single plane image: .XXXXX..XXX...X...XXX.. .....X..X..X..X..X..... .....X..XXX...X..X.XXX. .X...X..X..X..X..X...X. ..XXX...XXX...X...XXX..is represented by the 15 bytes 01111100 11100010 00111000 00000100 10010010 01000000 00000100 11100010 01011100 01000100 10010010 01000100 00111000 11100010 00111000or in hexadecimal notation 7c e2 38 04 92 40 04 e2 5c 44 92 44 38 e2 38This is the format used in binary PBM files and it can also be behandled directly by the Xlib library of the X Window System.As JBIG can also handle images with several bit planes, the JBIG-KITlibrary functions accept and return always arrays of pointers tobitmaps with one pointer per plane.For single plane images, the standard recommends that a 0 pixelrepresents the background and a 1 pixel represents the foregroundcolor of an image, i.e. 0 is white and 1 is black for scanned paperdocuments. For images with several bits per pixel, the JBIG standardmakes no recommendations about how various colors should be encoded.For greyscale images, by using a Gray code instead of a simple binaryweighted representation of the pixel intensity, some increase incoding efficiency can be reached.A Gray code is also a binary representation of integer numbers, buthas the property that the representations of the integer numbers i and(i+1) differ always in exactly one single bit. For example, thenumbers 0 to 7 can be represented in normal binary code and Gray codeas in the following table: normal number binary code Gray code --------------------------------------- 0 000 000 1 001 001 2 010 011 3 011 010 4 100 110 5 101 111 6 110 101 7 111 100The form of Gray code shown above has the property that the secondhalf of the code (numbers 4 - 7) is simply the mirrored first half(numbers 3 - 0) with the first bit set to one. This way, arbitrarilylarge Gray codes can be generated quickly by mirroring the aboveexample and prefixing the first half with zeros and the second halfwith ones as often as required. In greyscale images, it is commonpractise to use the all-0 code for black and the all-1 code for white.No matter whether a Gray code or a binary code is used for encoding apixel intensity in several bit planes, it always makes sense to storethe most significant (leftmost) bit in plane 0, which is transmittedfirst. This way, a decoder could increase the precision of thedisplayed pixel intensities while data is still being received and thebasic structure of the image will become visible as early as possibleduring the transmission.2.2 A simple compression applicationIn order to use JBIG-KIT in your application, just link libjbig.a toyour executable (on Unix systems just add -ljbig and -L. to thecommand line options of your compiler, on other systems you will haveto write a new Makefile anyway), copy the file jbig.h into your sourcedirectory and put the line #include "jbig.h"into your source code.The library interface follows the concepts of object-orientedprogramming. You have to declare a variable (object) struct jbg_enc_state se;which contains the current status of an encoder. Then you initializethe encoder by calling the constructor function void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y, int pl, unsigned char **p, void (*data_out)(unsigned char *start, size_t len, void *file), void *file);The parameters have the following meaning: s A pointer to the jbg_enc_state structure which you want
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -