kviewshell
JB2Dict Class Reference
Dictionary of JB2 shapes. More...
#include <JB2Image.h>
Classes | |
class | JB2Codec |
Public Member Functions | |
int | add_shape (const JB2Shape &shape) |
void | compress (void) |
void | decode (const GP< ByteStream > &gbs, JB2DecoderCallback *cb=0, void *arg=0) |
void | encode (const GP< ByteStream > &gbs) const |
unsigned int | get_memory_usage (void) const |
const JB2Shape & | get_shape (const int shapeno) const |
JB2Shape & | get_shape (const int shapeno) |
void | init (void) |
void | set_inherited_dict (const GP< JB2Dict > &dict) |
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}
| |
GP< JB2Dict > | get_inherited_dict (void) const |
int | get_inherited_shape_count (void) const |
int | get_shape_count (void) const |
Static Public Member Functions | |
static GP< JB2Dict > | create (void) |
Public Attributes | |
GUTF8String | comment |
Protected Member Functions | |
JB2Dict (void) |
Detailed Description
Dictionary of JB2 shapes.
Definition at line 250 of file JB2Image.h.
Constructor & Destructor Documentation
JB2Dict::JB2Dict | ( | void | ) | [protected] |
Definition at line 138 of file JB2Image.cpp.
Member Function Documentation
int JB2Dict::add_shape | ( | const JB2Shape & | shape | ) |
Appends a shape to the shape array.
This function appends a copy of shape shape# to the shape array and returns the subscript of the new shape. The subscript of the parent shape shape.parent# must actually designate an already existing shape.
Definition at line 221 of file JB2Image.cpp.
void JB2Dict::compress | ( | void | ) |
Compresses all shape bitmaps.
This function reduces the memory required by the JB2Image# by calling {GBitmap::compress} on all shapes bitmaps. This function is best called after decoding a JB2Image#, because function {get_bitmap} can directly use the compressed bitmaps.
Definition at line 203 of file JB2Image.cpp.
void JB2Dict::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 in JB2Image.
Definition at line 232 of file JB2Image.cpp.
void JB2Dict::encode | ( | const GP< ByteStream > & | gbs | ) | const |
Encodes the JB2Dict into ByteStream bs#.
This function generates the JB2 data stream without any header.
Reimplemented in JB2Image.
Definition at line 137 of file JB2EncodeCodec.cpp.
int JB2Dict::get_inherited_shape_count | ( | void | ) | const [inline] |
unsigned int JB2Dict::get_memory_usage | ( | void | ) | const |
Returns the total memory used by the JB2Image.
The returned value is expressed in bytes.
Reimplemented in JB2Image.
Definition at line 210 of file JB2Image.cpp.
const JB2Shape & JB2Dict::get_shape | ( | const int | shapeno | ) | const |
Returns a constant pointer to shape shapeno#.
The returned pointer directly points into the shape array. This pointer can only be used for reading the shape data.
Definition at line 169 of file JB2Image.cpp.
JB2Shape & JB2Dict::get_shape | ( | const int | shapeno | ) |
Returns a pointer to shape shapeno#.
The returned pointer directly points into the shape array. This pointer can be used for reading or writing the shape data.
Definition at line 152 of file JB2Image.cpp.
int JB2Dict::get_shape_count | ( | void | ) | const [inline] |
Returns the total number of shapes.
Shape indices range from #0# to get_shape_count()-1#.
Definition at line 441 of file JB2Image.h.
void JB2Dict::init | ( | void | ) |
Resets the JB2Image# object.
This function reinitializes both the shape and the blit arrays. All allocated memory is freed.
Reimplemented in JB2Image.
Definition at line 144 of file JB2Image.cpp.
Member Data Documentation
The documentation for this class was generated from the following files: