📄 jbig.doc
字号:
the first line of the next stripe. This option is by default deactivated and is only required for passing a special compatibility test suite.In addition, parameter l0 in jbg_enc_options() allows you to specifythe number of lines per stripe in resolution layer 0. The parametersmx and my change the maximal offset allowed for the adaptive templatepixel. JBIG-KIT now supports the full range of possible mx values upto 127 in the encoder and decoder, but my is at the moment ignored andalways set to 0. As the standard requires of all decoderimplementations only to support maximum values mx = 16 and my = 0,higher values should normally be avoided in order to guaranteeinteroperability. The ITU-T T.85 profile for JBIG in fax machinesrequires support for mx = 127 and my = 0. Default is mx = 8 and my =0. If any of the parameters order, options, mx or my is negative, orl0 is zero, then the corresponding current value remains unmodified.The resolution reduction and deterministic prediction tables can alsobe replaced. However as these options are anyway only for experts,please have a look at the source code of jbg_enc_out() and the structmembers dppriv and res_tab of struct jbg_enc_state for the details ofhow to do this, in case you really need it. The functionsjbg_int2dppriv and jbg_dppriv2int are provided in order to convert theDPTABLE data from the format used in the standard into the moreefficient format used internally by JBIG-KIT.If you want to encode a greyscale image, you can use the libraryfunction void jbg_split_planes(unsigned long x, unsigned long y, int has_planes, int encode_planes, const unsigned char *src, unsigned char **dest, int use_graycode);It separates an image in which each pixel is represented by one ormore bytes into separate bit planes. The dest array of pointers tothese bit planes can then be handed over to jbg_enc_init(). Thevariables x and y specify the width and height of the image in pixels,and has_planes specifies how many bits per pixel are used. As eachpixel is represented by an integral number of consecutive bytes, ofwhich each contains up to eight bits, the total length of the inputimage array src[] will therefore be x * y * ((has_planes + 7) / 8)bytes. The pixels are stored as usually in English reading order, andfor each pixel the integer value is stored with the most significantbyte coming first (Bigendian). This is exactly the format used in rawPGM files. In encode_planes, the number of bit planes that shall beextracted can be specified. This allows for instance to extract onlythe most significant 8 bits of a 12-bit image, where each pixel isrepresented by two bytes, by specifying has_planes = 12 andencode_planes = 8. If use_graycode is zero, then the binary code ofthe pixel integer values will be used instead of the Gray code. Plane0 contains always the most significant bit.3 Decompressing an imageLike with the compression functions, if you want to use the JBIG-KITlibrary, you have to put the line #include "jbig.h"into your source code and link your executable with libjbig.a.The state of a JBIG decoder is stored completely in a struct and youwill have to define a variable like struct jbg_dec_state sd;which is initialized by a call to void jbg_dec_init(struct jbg_dec_state *s);After this, you can directly start to pass data from the BIE to the decoderby calling the function int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len, size_t *cnt);The pointer data points to the first byte of a data block with lengthlen, which contains bytes from a BIE. It is not necessary to pass awhole BIE at once to jbg_dec_in(), it can arrive fragmented in any wayby calling jbg_dec_in() several times. It is also possible to sendseveral BIEs concatenated to jbg_dec_in(), however these then have tofit together. If you send several BIEs to the decoder, the lowestresolution layer in each following BIE has to be the highestresolution layer in the previous BIE plus one and the image sizes andnumber of planes also have to fit together, otherwise jbg_dec_in()will return the error JBG_ENOCONT after the header of the new BIE hasbeen received completely.If pointer cnt is not NULL, then the number of bytes actually readfrom the data block is stored there. In case the data block did notcontain the end of the BIE, then the value JBG_EAGAIN will be returnedand *cnt equals len.Once the end of a BIE has been reached, the return value ofjbg_dec_in() will be JBG_EOK. After this has happened, the functionsand macros long jbg_dec_getwidth(struct jbg_dec_state *s); long jbg_dec_getheight(struct jbg_dec_state *s); int jbg_dec_getplanes(struct jbg_dec_state *s); unsigned char *jbg_dec_getimage(struct jbg_dec_state *s, int plane); long jbg_dec_getsize(struct jbg_dec_state *s);can be used to query the dimensions of the now completely decodedimage and to get a pointer to all bitmap planes. The bitmaps arestored as described in section 2.1. The function jbg_dec_getsize()calculates the number of bytes which one bitmap requires.The function void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode, void (*data_out)(unsigned char *start, size_t len, void *file), void *file);allows you to merge the bit planes that can be accessed individuallywith jbg_dec_getimage() into an array with one or more bytes per pixel(i.e., the format provided to jbg_split_planes()). If use_graycode iszero, then a binary encoding will be used. The output array will bedelivered via the callback function data_out, exactly in the same wayin which the encoder provides the BIE. The function long jbg_dec_getsize_merged(const struct jbg_dec_state *s);determines how long the data array delivered by jbg_dec_merge_planes()is going to be.Before calling jbg_dec_in() the first time, it is possible to specify witha call to void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax, unsigned long ymax);an abort criterion for progressively encoded images. For instance if anapplication will display a whole document on a screen which is 1024 x768 pixels large, then this application should call jbg_dec_maxsize(&sd, 1024, 768);before the decoding process starts. If the image has been encoded inprogressive mode (i.e. with several resolution layers), then thedecoder will stop with a return value JBG_EOK_INTR after the largestresolution layer that is still smaller than 1024 x 768. However thisis no guarantee that the image which can then be read out usingjbg_dec_getimage(), etc. is really not larger than the specifiedmaximal size. The application will have to check the size of theimage, because the decoder does not automatically apply a resolutionreduction if no suitable resolution layer is available in the BIE.If jbg_dec_in() returned JBG_EOK_INTR or JBG_EOK, then it is possibleto continue calling jbg_dec_in() with the remaining data in order toeither decode the remaining resolution layers of the current BIE or inorder to add another BIE with additional resolution layers. In bothcases, after jbg_dec_in() returned JBG_EOK_INTR or JBG_EOK, *cnt isprobably not equal to len and the remainder of the data block whichhas not yet been processed by the decoder has to be delivered tojbg_dec_in() again.If any other return value than JBG_EOK, JBG_EOK_INTR or JBG_EAGAINhas been returned by jbg_dec_in(), then an error has occurred and void jbg_dec_free(struct jbg_dec_state *s);should be called in order to release any allocated memory. Thedestructor jbg_dec_free() should of course also be called, once thedecoded bitmap returned by jbg_dec_getimage() is no longer requiredand the memory can be released.The function const char *jbg_strerror(int errnum, int language);returns a pointer to a short single line test message which explainsthe return value of jbg_dec_in(). This message can be used in order toprovide the user a brief informative message about what when wrongwhile decompressing the JBIG image. The error messages are availablein several languages and in several character sets. Currentlysupported are the following values for the language parameter: JBG_EN English messages in ASCII JBG_DE_8859_1 German messages in ISO 8859-1 Latin 1 character set JBG_DE_UTF_8 German messages in ISO 10646/Unicode UTF-8 encodingThe current implementation of the JBIG-KIT decoder has the followinglimitations: - The maximal vertical offset MY of the adaptive template pixel must be zero. - HITOLO and SEQ bits must not be set in the order value. - Not more than JBG_ATMOVES_MAX (currently set to 64) ATMOVE marker segments can be handled per stripe. - the number D of differential layers must be less than 32None of the above limitations can be exceeded by a JBIG data streamthat conforms to the ITU-T T.85 application profile for the use ofJBIG1 in fax machines.There are two more limitations of the current implementation of theJBIG-KIT decoder that might cause problems with processing JBIG datastream that conform to ITU-T T.85: - The JBIG-KIT decoder was designed to operate incrementally. Each received byte is processed immediately as soon as it arrives. As a result, it does not look beyond the SDRST/SDNORM at the end of all stripes for any immediately following NEWLEN marker that might reduce the number of lines encoded by the current stripe. However section 6.2.6.2 of ITU-T T.82 says that a NEWLEN marker segment "could refer to a line in the immediately preceding stripe due to an unexpected termination of the image or the use of only such stripe", and ITU-T.85 explicitly suggests the use of this for fax machines that start transmission before having encountered the end of the page. - The image size initially indicated in the BIE header is used to allocate memory for a bitmap of this size. This means that BIEs that set initially Y_D = 0xffffffff (as suggested in ITU-T T.85 for fax machines that do not know the height of the page at the start of the transmission) cannot be decoded directly by this version.For both issues, there is a very simple workaround:If you encounter a BIE that has in the header the VLENGTH=1 option bitset, then first wait until you have received the entire BIE and storedit in memory. Then call the function int jbg_newlen(unsigned char *bie, size_t len);where bie is a pointer to the first byte of the BIE and len its lengthin bytes. This function will scan the entire BIE for the first NEWLENmarker segment. It will then take the updated image-height value YDfrom it and use it to overwrite the YD value in the BIE header. Thejbg_newlen() can return some of the same error codes as jbg_dec_in(),namely JBG_EOK if everything went fine, JBG_EAGAIN is the dataprovided is too short to be a valid BIE, JBG_EINVAL if a format errorwas encountered, and JBG_EABORT if an ABORT marker segment was found.After having patched the image-height value in the BIE usingjbg_newlen(), simply hand over the BIE as usual to jbg_dec_in().A more detailed description of the JBIG-KIT implementation is Markus Kuhn: Effiziente Kompression von bi-level Bilddaten durch kontextsensitive arithmetische Codierung. Studienarbeit, Lehrstuhl f黵 Betriebssysteme, IMMD IV, Universit鋞 Erlangen-N黵nberg, Erlangen, July 1995. (German, 62 pages) <http://www.cl.cam.ac.uk/~mgk25/kuhn-sta.pdf>Please quote the above if you use JBIG-KIT in your research project.*** Happy compressing ***[end]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -