@ -83,47 +83,47 @@
be implemented in the future .
{ \ bf JB2 Images } - - - Class \ Ref { JB2Image } is the central data structure
implemented here . A # JB2Image # is composed of an array of tq shapes
and an array of blits . Each tq shape contains a small bitmap representing an
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 tq shape at a
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 tq shape. A tq shape can also
contain a pointer to a parent tq shape. Additional compression is achieved
when both tq shapes are similar because each tq shape is encoded using the
parent tq shape as a model . A # " O " # tq shape for instance could be a parent for
both a # " C " # tq shape and a # " Q " # tq shape.
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.
{ \ bf JB2 Dictionary } - - - Class \ Ref { JB2Dict } is a peculiar kind of
JB2Image which only contains an array of tq shapes. These tq shapes can be
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
\ Ref { JB2Dict : : set_inherited_dict } . Several JB2Images can use tq shapes from a
\ Ref { 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 .
{ \ bf Decoding JB2 data } - - - The first step for decoding JB2 data consists of
creating an empty # JB2Image # object . Function \ Ref { JB2Image : : decode } then
reads the data and populates the # JB2Image # with the tq shapes and the blits .
reads the data and populates the # JB2Image # with the shapes and the blits .
Function \ Ref { JB2Image : : get_bitmap } finally produces an anti - aliased image .
{ \ bf Encoding JB2 data } - - - The first step for decoding JB2 data also
consists of creating an empty # JB2Image # object . You must then use
functions \ Ref { JB2Image : : add_ tq shape} and \ Ref { JB2Image : : add_blit } to
functions \ Ref { JB2Image : : add_ shape} and \ Ref { JB2Image : : add_blit } to
populate the # JB2Image # object . Function \ Ref { JB2Image : : encode } finally
produces the JB2 data . Function # encode # sequentially encodes the blits
and the necessary tq shapes. The compression ratio depends on several
and the necessary shapes. The compression ratio depends on several
factors :
\ begin { itemize }
\ item Blits should reuse tq shapes as often as possible .
\ item Blits should reuse shapes as often as possible .
\ item Blits should be sorted in reading order because this facilitates
the prediction of the blit coordinates .
\ item Shapes should be sorted according to the order of first appearance
in the sequence of blits because this facilitates the prediction of the
tq shape indices .
\ item Shapes should be compared to all previous tq shapes in the tq shape array .
The tq shape parent pointer should be set to a suitable parent tq shape if
such a parent tq shape exists . The parent tq shape should have almost the
shape indices .
\ item 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 .
\ end { itemize }
All this is quite easy to achieve in the case of an electronically
@ -131,16 +131,16 @@
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 tq shapes is then an essentially
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 tq shapes never
effects the file size , misordering blits or mismatching shapes never
effects the quality of the image . The last refinement consists in
smoothing the tq shapes in order to reduce the noise and maximize the
similarities between tq shapes.
smoothing the shapes in order to reduce the noise and maximize the
similarities between shapes.
{ \ bf JB2 extensions } - - - Two extensions of the JB2
encoding format have been introduced with DjVu files version 21. The first
extension addresses the shared tq shape dictionaries . The second extension
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
@ -190,10 +190,10 @@ class ByteStream;
/** Blit data structure. A #JB2Image# contains an array of #JB2Blit# data
structures . Each array entry instructs the decoder to render a particular
tq shape at a particular location . Members # left # and # bottom # specify the
coordinates of the bottom left corner of the tq shape bitmap . All
shape at a particular location . Members # left # and # bottom # specify the
coordinates of the bottom left corner of the shape bitmap . All
coordinates are relative to the bottom left corner of the image . Member
# tq shapeno# is the subscript of the tq shape to be rendered. */
# shapeno# is the subscript of the shape to be rendered. */
class JB2Blit {
public :
@ -201,31 +201,31 @@ public:
unsigned short left ;
/**Qt::Vertical coordinate of the blit. */
unsigned short bottom ;
/** Index of the tq shape to blit. */
unsigned int tq shapeno;
/** Index of the shape to blit. */
unsigned int shapeno;
} ;
/** Shape data structure. A #JB2Image# contains an array of #JB2Shape# data
structures . Each array entry represents an elementary blob of ink such as
a character or a segment of line art . Member # bits # points to a bilevel
image representing the tq shape pixels . Member # parent # is the subscript of
the parent tq shape. */
image representing the shape pixels . Member # parent # is the subscript of
the parent shape. */
class JB2Shape
{
public :
/** Subscript of the parent tq shape. The parent tq shape must always be located
before the current tq shape in the tq shape array . A negative value indicates
/** Subscript of the parent shape. The parent shape must always be located
before the current shape in the shape array . A negative value indicates
that this shape . has no parent . Any negative values smaller than # - 1 #
further indicates that this tq shape does not look like a character . This
further indicates that this shape does not look like a character . This
is used to enable a few internal optimizations . This information is
saved into the JB2 file , but the actual value of the # parent # variable
is not . */
int parent ;
/** Bilevel image of the tq shape pixels. This must be a pointer to a bilevel
/** Bilevel image of the shape pixels. This must be a pointer to a bilevel
# GBitmap# image. This pointer can also be null. The encoder will just
silently discard all blits referring to a tq shape containing a null
silently discard all blits referring to a shape containing a null
bitmap . */
GP < GBitmap > bits ;
/** Private user data. This long word is provided as a convenience for users
@ -238,14 +238,14 @@ public:
/** JB2 Dictionary callback.
The decoding function call this callback function when they discover that
the current JB2Image or JB2Dict needs a pre - existing tq shape dictionary .
the current JB2Image or JB2Dict needs a pre - existing shape dictionary .
The callback function must return a pointer to the dictionary or NULL
if none is found . */
typedef GP < JB2Dict > JB2DecoderCallback ( void * ) ;
/** Dictionary of JB2 tq shapes. */
/** Dictionary of JB2 shapes. */
class JB2Dict : public GPEnabled
{
@ -257,43 +257,43 @@ public:
// CONSTRUCTION
/** Default creator. Constructs an empty #JB2Dict# object. You can then
call the decoding function # decode # . You can also manually set the
image size using # add_ tq shape# . */
image size using # add_ shape# . */
static GP < JB2Dict > create ( void ) ;
// INITIALIZATION
/** Resets the #JB2Image# object. This function reinitializes both the tq shape
/** Resets the #JB2Image# object. This function reinitializes both the shape
and the blit arrays . All allocated memory is freed . */
void init ( void ) ;
// INHERITED
/** Returns the inherited dictionary. */
GP < JB2Dict > get_inherited_dict ( void ) const ;
/** Returns the number of inherited tq shapes. */
int get_inherited_ tq shape_count( void ) const ;
/** Returns the number of inherited shapes. */
int get_inherited_ shape_count( void ) const ;
/** Sets the inherited dictionary. */
void set_inherited_dict ( const GP < JB2Dict > & dict ) ;
// ACCESSING THE SHAPE LIBRARY
/** Returns the total number of tq shapes.
Shape indices range from # 0 # to # get_ tq shape_count( ) - 1 # . */
int get_ tq shape_count( void ) const ;
/** Returns a pointer to tq shape #tq shapeno#.
The returned pointer directly points into the tq shape array .
This pointer can be used for reading or writing the tq shape data . */
JB2Shape & get_ tq shape( const int tq shapeno) ;
/** Returns a constant pointer to tq shape #tq shapeno#.
The returned pointer directly points into the tq shape array .
This pointer can only be used for reading the tq shape data . */
const JB2Shape & get_ tq shape( const int tq shapeno) const ;
/** Appends a tq shape to the tq shape array. This function appends a copy of
tq shape # tq shape# to the tq shape array and returns the subscript of the new
tq shape. The subscript of the parent tq shape # tq shape. parent # must
actually designate an already existing tq shape. */
int add_ tq shape( const JB2Shape & tq shape) ;
/** Returns the total number of shapes.
Shape indices range from # 0 # to # get_ shape_count( ) - 1 # . */
int get_ shape_count( void ) const ;
/** 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 . */
JB2Shape & get_ shape( const int shapeno) ;
/** 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 . */
const JB2Shape & get_ shape( const int shapeno) const ;
/** 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. */
int add_ shape( const JB2Shape & shape) ;
// MEMORY OPTIMIZATION
/** Compresses all tq shape bitmaps. This function reduces the memory required
by the # JB2Image # by calling \ Ref { GBitmap : : compress } on all tq shapes
/** Compresses all shape bitmaps. This function reduces the memory required
by the # JB2Image # by calling \ Ref { GBitmap : : compress } on all shapes
bitmaps . This function is best called after decoding a # JB2Image # ,
because function \ Ref { get_bitmap } can directly use the compressed
bitmaps . */
@ -307,9 +307,9 @@ public:
This function generates the JB2 data stream without any header . */
void encode ( const GP < ByteStream > & gbs ) const ;
/** Decodes JB2 data from ByteStream #bs#. This function decodes the image
size and populates the tq shape and blit arrays . The callback function
size and populates the shape and blit arrays . The callback function
# cb# is called when the decoder determines that the ByteStream data
requires a tq shape dictionary which has not been set with
requires a shape dictionary which has not been set with
\ Ref { 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
@ -322,15 +322,15 @@ public:
GUTF8String comment ;
private :
int inherited_ tq shapes;
int inherited_ shapes;
GP < JB2Dict > inherited_dict ;
GArray < JB2Shape > tq shapes;
GArray < JB2Shape > shapes;
} ;
/** Main JB2 data structure. Each #JB2Image# consists of an array of tq shapes
/** 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 \ Ref { add_ tq shape} and \ Ref { add_blit } , or by decoding JB2 data
functions \ Ref { add_ shape} and \ Ref { add_blit } , or by decoding JB2 data
using function \ Ref { decode } . You can then use function \ Ref { get_bitmap }
to render anti - aliased images , or use function \ Ref { encode } to generate
JB2 data . */
@ -343,12 +343,12 @@ public:
/** 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 tq shape and blit arrays
using # add_ tq shape# and # add_blit # . */
image size using # set_dimension # and populate the shape and blit arrays
using # add_ shape# and # add_blit # . */
static GP < JB2Image > create ( void ) { return new JB2Image ( ) ; }
// INITIALIZATION
/** Resets the #JB2Image# object. This function reinitializes both the tq shape
/** Resets the #JB2Image# object. This function reinitializes both the shape
and the blit arrays . All allocated memory is freed . */
void init ( void ) ;
@ -370,7 +370,7 @@ public:
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 tq alignment of the
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 . */
@ -380,7 +380,7 @@ public:
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 tq alignment of the rows of the returned
Argument # align # specified the alignment of the rows of the returned
images , as explained above . Argument # dispy # should remain null . */
GP < GBitmap > get_bitmap ( const GRect & rect , int subsample = 1 , int align = 1 , int dispy = 0 ) const ;
@ -393,13 +393,13 @@ public:
This pointer can be used for reading or writing the blit data . */
JB2Blit * get_blit ( int blitno ) ;
/** Returns a constant pointer to blit #blitno#.
The returned pointer directly points into the tq shape array .
This pointer can only be used for reading the tq shape data . */
The returned pointer directly points into the shape array .
This pointer can only be used for reading the shape data . */
const JB2Blit * get_blit ( int blitno ) const ;
/** 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
tq shape subscript # blit . tq shapeno# must actually designate an already
existing tq shape. */
shape subscript # blit . shapeno# must actually designate an already
existing shape. */
int add_blit ( const JB2Blit & blit ) ;
// MEMORY OPTIMIZATION
@ -412,9 +412,9 @@ public:
This function generates the JB2 data stream without any header . */
void encode ( const GP < ByteStream > & gbs ) const ;
/** Decodes JB2 data from ByteStream #bs#. This function decodes the image
size and populates the tq shape and blit arrays . The callback function
size and populates the shape and blit arrays . The callback function
# cb# is called when the decoder determines that the ByteStream data
requires a tq shape dictionary which has not been set with
requires a shape dictionary which has not been set with
\ Ref { 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
@ -438,15 +438,15 @@ public:
// JB2DICT INLINE FUNCTIONS
inline int
JB2Dict : : get_ tq shape_count( void ) const
JB2Dict : : get_ shape_count( void ) const
{
return inherited_ tq shapes + tq shapes. size ( ) ;
return inherited_ shapes + shapes. size ( ) ;
}
inline int
JB2Dict : : get_inherited_ tq shape_count( void ) const
JB2Dict : : get_inherited_ shape_count( void ) const
{
return inherited_ tq shapes;
return inherited_ shapes;
}
inline GP < JB2Dict >
@ -612,7 +612,7 @@ protected:
void reset_numcoder ( void ) ;
inline void code_eventual_lossless_refinement ( void ) ;
void init_library ( JB2Dict & jim ) ;
int add_library ( const int tq shapeno, JB2Shape & jshp ) ;
int add_library ( const int shapeno, JB2Shape & jshp ) ;
void code_relative_location ( JB2Blit * jblt , int rows , int columns ) ;
void code_bitmap_directly ( GBitmap & bm ) ;
void code_bitmap_by_cross_coding ( GBitmap & bm , GP < GBitmap > & cbm , const int libno ) ;
@ -640,7 +640,7 @@ protected:
virtual void code_comment ( GUTF8String & comment ) = 0 ;
virtual void code_record_type ( int & rectype ) = 0 ;
virtual int code_match_index ( int & index , JB2Dict & jim ) = 0 ;
virtual void code_inherited_ tq shape_count( JB2Dict & jim ) = 0 ;
virtual void code_inherited_ shape_count( JB2Dict & jim ) = 0 ;
virtual void code_image_size ( JB2Dict & jim ) ;
virtual void code_image_size ( JB2Image & jim ) ;
virtual void code_absolute_location ( JB2Blit * jblt , int rows , int columns ) = 0 ;
@ -678,8 +678,8 @@ protected:
NumContext dist_match_index ;
BitContext dist_refinement_flag ;
// Library
GTArray < int > tq shape2lib;
GTArray < int > lib2 tq shape;
GTArray < int > shape2lib;
GTArray < int > lib2 shape;
GTArray < LibRect > libinfo ;
// Code pairs
NumContext abs_loc_x ;
@ -687,7 +687,7 @@ protected:
NumContext abs_size_x ;
NumContext abs_size_y ;
NumContext image_size_dist ;
NumContext inherited_ tq shape_count_dist;
NumContext inherited_ shape_count_dist;
BitContext offset_type_dist ;
NumContext rel_loc_x_current ;
NumContext rel_loc_x_last ;