kviewshell
JB2Image Class Reference
Main JB2 data structure. More...
#include <JB2Image.h>
Public Member Functions | |
int | add_blit (const JB2Blit &blit) |
void | decode (const GP< ByteStream > &gbs, JB2DecoderCallback *cb=0, void *arg=0) |
void | encode (const GP< ByteStream > &gbs) const |
GP< GBitmap > | get_bitmap (const GRect &rect, int subsample=1, int align=1, int dispy=0) const |
GP< GBitmap > | get_bitmap (int subsample=1, int align=1) const |
unsigned int | get_memory_usage (void) const |
void | init (void) |
void | set_dimension (int width, int height) |
JB2Image.h | |
Files #"JB2Image.h"# and #"JB2Image.cpp"# address the compression of bilevel images using the JB2 soft pattern matching scheme. These files provide the complete decoder and the decoder back-end. The JB2 scheme is optimized for images containing a large number of self-similar small components such as characters. Typical text images can be compressed into files 3 to 5 times smaller than with G4/MMR and 2 to 4 times smaller than with JBIG1. { JB2 and JBIG2} --- JB2 has strong similarities with the forthcoming JBIG2 standard developed by the "ISO/IEC JTC1 SC29 Working Group 1" which is responsible for both the JPEG and JBIG standards. This is hardly surprising since JB2 was our own proposal for the JBIG2 standard and remained the only proposal for years. The full JBIG2 standard however is significantly more complex and slighlty less efficient than JB2 because it addresses a broader range of applications. Full JBIG2 compliance may be implemented in the future. { JB2 Images} --- Class {JB2Image} is the central data structure implemented here. A JB2Image# is composed of an array of shapes and an array of blits. Each shape contains a small bitmap representing an elementary blob of ink, such as a character or a segment of line art. Each blit instructs the decoder to render a particular shape at a specified position in the image. Some compression is already achieved because several blits can refer to the same shape. A shape can also contain a pointer to a parent shape. Additional compression is achieved when both shapes are similar because each shape is encoded using the parent shape as a model. A #"O"# shape for instance could be a parent for both a #"C"# shape and a #"Q"# shape. { JB2 Dictionary} --- Class {JB2Dict} is a peculiar kind of JB2Image which only contains an array of shapes. These shapes can be referenced from another JB2Dict/JB2Image. This is arranged by setting the ``inherited dictionary'' of a JB2Dict/JB2Image using function {JB2Dict::set_inherited_dict}. Several JB2Images can use shapes from a same JB2Dict encoded separately. This is how several pages of a same document can share information. { Decoding JB2 data} --- The first step for decoding JB2 data consists of creating an empty JB2Image# object. Function {JB2Image::decode} then reads the data and populates the JB2Image# with the shapes and the blits. Function {JB2Image::get_bitmap} finally produces an anti-aliased image. { Encoding JB2 data} --- The first step for decoding JB2 data also consists of creating an empty JB2Image# object. You must then use functions {JB2Image::add_shape} and {JB2Image::add_blit} to populate the JB2Image# object. Function {JB2Image::encode} finally produces the JB2 data. Function encode# sequentially encodes the blits and the necessary shapes. The compression ratio depends on several factors: {itemize} Blits should reuse shapes as often as possible. Blits should be sorted in reading order because this facilitates the prediction of the blit coordinates. Shapes should be sorted according to the order of first appearance in the sequence of blits because this facilitates the prediction of the shape indices. Shapes should be compared to all previous shapes in the shape array. The shape parent pointer should be set to a suitable parent shape if such a parent shape exists. The parent shape should have almost the same size and the same pixels. {itemize} All this is quite easy to achieve in the case of an electronically produced document such as a DVI file or a PS file: we know what the characters are and where they are located. If you only have a scanned image however you must first locate the characters (connected component analysis) and cut the remaining pieces of ink into smaller blobs. Ordering the blits and matching the shapes is then an essentially heuristic process. Although the quality of the heuristics substantially effects the file size, misordering blits or mismatching shapes never effects the quality of the image. The last refinement consists in smoothing the shapes in order to reduce the noise and maximize the similarities between shapes. { JB2 extensions} --- Two extensions of the JB2 encoding format have been introduced with DjVu files version 21. The first extension addresses the shared shape dictionaries. The second extension bounds the number of probability contexts used for coding numbers. Both extensions maintain backward compatibility with JB2 as described in the ICFDD proposal. A more complete discussion can be found in section {JB2 extensions for version 21.}. { References} {itemize} Paul G. Howard : {Text image compression using soft pattern matching}, Computer Journal, volume 40:2/3, 1997. JBIG1 : {http://www.jpeg.org/public/jbighomepage.htm}. JBIG2 draft : {http://www.jpeg.org/public/jbigpt2.htm}. ICFDD Draft Proposed American National Standard, 1999-08-26. {itemize}
| |
const JB2Blit * | get_blit (int blitno) const |
JB2Blit * | get_blit (int blitno) |
int | get_blit_count (void) const |
int | get_height (void) const |
int | get_width (void) const |
Static Public Member Functions | |
static GP< JB2Image > | create (void) |
Public Attributes | |
bool | reproduce_old_bug |
Protected Member Functions | |
JB2Image (void) |
Detailed Description
Main JB2 data structure.Each JB2Image# consists of an array of shapes and an array of blits. These arrays can be populated by hand using functions {add_shape} and {add_blit}, or by decoding JB2 data using function {decode}. You can then use function {get_bitmap} to render anti-aliased images, or use function {encode} to generate JB2 data.
Definition at line 338 of file JB2Image.h.
Constructor & Destructor Documentation
JB2Image::JB2Image | ( | void | ) | [protected] |
Definition at line 248 of file JB2Image.cpp.
Member Function Documentation
int JB2Image::add_blit | ( | const JB2Blit & | blit | ) |
Appends a blit to the blit array.
This function appends a copy of blit blit# to the blit array and returns the subscript of the new blit. The shape subscript blit.shapeno# must actually designate an already existing shape.
Definition at line 278 of file JB2Image.cpp.
Creates an empty JB2Image# object.
You can then call the decoding function decode#. You can also manually set the image size using set_dimension# and populate the shape and blit arrays using add_shape# and add_blit#.
Reimplemented from JB2Dict.
Definition at line 348 of file JB2Image.h.
void JB2Image::decode | ( | const GP< ByteStream > & | gbs, | |
JB2DecoderCallback * | cb = 0 , |
|||
void * | arg = 0 | |||
) |
Decodes JB2 data from ByteStream bs#.
This function decodes the image size and populates the shape and blit arrays. The callback function cb# is called when the decoder determines that the ByteStream data requires a shape dictionary which has not been set with {JB2Dict::set_inherited_dict}. The callback receives argument arg# and must return a suitable dictionary which will be installed as the inherited dictionary. The callback should return null if no such dictionary is found.
Reimplemented from JB2Dict.
Definition at line 331 of file JB2Image.cpp.
void JB2Image::encode | ( | const GP< ByteStream > & | gbs | ) | const |
Encodes the JB2Image into ByteStream bs#.
This function generates the JB2 data stream without any header.
Reimplemented from JB2Dict.
Definition at line 149 of file JB2EncodeCodec.cpp.
GP< GBitmap > JB2Image::get_bitmap | ( | const GRect & | rect, | |
int | subsample = 1 , |
|||
int | align = 1 , |
|||
int | dispy = 0 | |||
) | const |
Renders an anti-aliased gray level sub-image.
This function renders a segment of the JB2Image as a bilevel or gray level image. Conceptually, this function first renders the full JB2Image with subsampling ratio subsample# and then extracts rectangle rect# in the subsampled image. Both operations of course are efficiently performed simultaneously. Argument align# specified the alignment of the rows of the returned images, as explained above. Argument dispy# should remain null.
Definition at line 309 of file JB2Image.cpp.
Renders an anti-aliased gray level image.
This function renders the JB2Image as a bilevel or gray level image. Argument subsample# specifies the desired subsampling ratio in range #1# to #15#. The returned image uses #1+subsample^2# gray levels for representing anti-aliased edges. Argument align# specified the alignment of the rows of the returned images. Setting align# to #4#, for instance, will adjust the bitmap border in order to make sure that each row of the returned image starts on a word (four byte) boundary.
Definition at line 289 of file JB2Image.cpp.
const JB2Blit * JB2Image::get_blit | ( | int | blitno | ) | const [inline] |
Returns a constant pointer to blit blitno#.
The returned pointer directly points into the shape array. This pointer can only be used for reading the shape data.
Definition at line 487 of file JB2Image.h.
JB2Blit * JB2Image::get_blit | ( | int | blitno | ) | [inline] |
Returns a pointer to blit blitno#.
The returned pointer directly points into the blit array. This pointer can be used for reading or writing the blit data.
Definition at line 481 of file JB2Image.h.
int JB2Image::get_blit_count | ( | void | ) | const [inline] |
Returns the total number of blits.
Blit indices range from #0# to get_blit_count(void)-1#.
Definition at line 474 of file JB2Image.h.
int JB2Image::get_height | ( | void | ) | const [inline] |
Returns the height of the image.
This is the height value previously set with set_dimension#.
Definition at line 467 of file JB2Image.h.
unsigned int JB2Image::get_memory_usage | ( | void | ) | const |
Returns the total memory used by the JB2Image.
The returned value is expressed in bytes.
Reimplemented from JB2Dict.
Definition at line 262 of file JB2Image.cpp.
int JB2Image::get_width | ( | void | ) | const [inline] |
Returns the width of the image.
This is the width value previously set with set_dimension#.
Definition at line 461 of file JB2Image.h.
void JB2Image::init | ( | void | ) |
Resets the JB2Image# object.
This function reinitializes both the shape and the blit arrays. All allocated memory is freed.
Reimplemented from JB2Dict.
Definition at line 254 of file JB2Image.cpp.
void JB2Image::set_dimension | ( | int | width, | |
int | height | |||
) |
Sets the size of the JB2Image.
This function can be called at any time. The corresponding width# and the height# are stored in the JB2 file.
Definition at line 271 of file JB2Image.cpp.
Member Data Documentation
Reproduces a old bug.
Setting this flag may be necessary for accurately decoding DjVu files with version smaller than #18#. The default value is of couse false#.
Definition at line 433 of file JB2Image.h.
The documentation for this class was generated from the following files: