Logo Search packages:      
Sourcecode: djvulibre version File versions

GBitmap Class Reference

#include <GBitmap.h>

Inheritance diagram for GBitmap:


List of all members.

Detailed Description

Bilevel and gray-level images. Instances of class GBitmap# represent bilevel or gray-level images. Images are usually represented using one byte per pixel. Value zero represents a white pixel. A value equal to the number of gray levels minus one represents a black pixel. The number of gray levels is returned by the function {get_grays} and can be manipulated by the functions {set_grays} and {change_grays}.

The bracket operator returns a pointer to the bytes composing one line of the image. This pointer can be used to read or write the image pixels. Line zero represents the bottom line of the image.

The memory organization is setup in such a way that you can safely read a few pixels located in a small border surrounding all four sides of the image. The width of this border can be modified using the function {minborder}. The border pixels are initialized to zero and therefore represent white pixels. You should never write anything into border pixels because they are shared between images and between lines.

Definition at line 128 of file GBitmap.h.

Stealing or borrowing the memory buffer (advanced).

void borrow_data (unsigned char &data, int w, int h)
void donate_data (unsigned char *data, int w, int h)
void donate_rle (unsigned char *rledata, unsigned int rledatalen, int w, int h)
const unsigned char * get_rle (unsigned int &rle_length)
GP< GBitmaprotate (int count=0)
unsigned char * take_data (size_t &offset)
static void append_run (unsigned char *&data, int count)
static int read_run (unsigned char *&data)
static int read_run (const unsigned char *&data)

Accessing RLE data.

The next functions are useful for processing bilevel images encoded using the run length encoding scheme. These functions always return zero if the bitmap is not RLE encoded. Function {compress} must be used to ensure that the bitmap is RLE encoded.

int rle_get_bits (int rowno, unsigned char *bits) const
int rle_get_rect (GRect &rect) const
int rle_get_runs (int rowno, int *rlens) const
static void rle_get_bitmap (const int ncolumns, const unsigned char *&runs, unsigned char *bitmap, const bool invert)

Public Types

enum  { MAXRUNSIZE = 0x3fff }
enum  { RUNOVERFLOWVALUE = 0xc0 }
enum  { RUNMSBMASK = 0x3f }
enum  { RUNLSBMASK = 0xff }

Public Member Functions

void check_border () const
void destroy (void)
int get_count (void) const
Managing gray levels.

void binarize_grays (int threshold=0)
void change_grays (int grays)
int get_grays () const
void set_grays (int grays)
Additive Blit.
The blit functions are designed to efficiently construct an anti-aliased image by copying smaller images at predefined locations. The image of a page, for instance, is composed by copying the images of characters at predefined locations. These functions are fairly optimized. They can directly use compressed GBitmaps (see {compress}). We consider in this section that each GBitmap comes with a coordinate system defined as follows. Position (#0#,#0#) corresponds to the bottom left corner of the bottom left pixel. Position (#1#,#1#) corresponds to the top right corner of the bottom left pixel, which is also the bottom left corner of the second pixel of the second row. Position (w#,h#), where w# and h# denote the size of the GBitmap, corresponds to the top right corner of the top right pixel.

void blit (const GBitmap *shape, int x, int y, int subsample)
void blit (const GBitmap *bm, int x, int y)
Accessing the pixels.

unsigned int columns () const
void minborder (int minimum)
unsigned char * operator[] (int row)
const unsigned char * operator[] (int row) const
unsigned int rows () const
unsigned int rowsize () const
Optimizing the memory usage.
The amount of memory used by bilevel images can be reduced using function {compress}, which encodes the image using a run-length encoding scheme. The bracket operator decompresses the image on demand. A few highly optimized functions (e.g. {blit}) can use a run-length encoded bitmap without decompressing it. There are unfortunate locking issues associated with this capability (c.f. {share} and {monitor}).

void compress ()
unsigned int get_memory_usage () const
GMonitormonitor () const
void share ()
void uncompress ()

void fill (unsigned char value)
void init (ByteStream &ref, int border=0)
void init (const GBitmap &ref, const GRect &rect, int border=0)
void init (const GBitmap &ref, int border=0)
void init (int nrows, int ncolumns, int border=0)
GBitmapoperator= (const GBitmap &ref)
Saving images.
The following functions write PBM, PGM and RLE files. PBM and PGM are well known formats for bilevel and gray-level images. The RLE is a simple run-length encoding scheme for bilevel images. These files can be read using the ByteStream based constructor or initialization function. See {PNM and RLE file formats} for more information.

void save_pbm (ByteStream &bs, int raw=1)
void save_pgm (ByteStream &bs, int raw=1)
void save_rle (ByteStream &bs)

Static Public Member Functions


static GP< GBitmapcreate (ByteStream &ref, const int border=0)
static GP< GBitmapcreate (const GBitmap &ref, const GRect &rect, const int border=0)
static GP< GBitmapcreate (const GBitmap &ref, const int border)
static GP< GBitmapcreate (const GBitmap &ref)
static GP< GBitmapcreate (const int nrows, const int ncolumns, const int border=0)
static GP< GBitmapcreate (void)

Public Attributes

GP< ZeroBuffer > gzerobuffer

Protected Member Functions

 GBitmap (ByteStream &ref, int border=0)
 GBitmap (const GBitmap &ref, const GRect &rect, int border=0)
 GBitmap (const GBitmap &ref, int border)
 GBitmap (const GBitmap &ref)
 GBitmap (int nrows, int ncolumns, int border=0)

Protected Attributes

unsigned short border
unsigned char * bytes
unsigned char * bytes_data
unsigned short bytes_per_row
volatile int count
 The reference counter.
GPBuffer< unsigned char > gbytes_data
unsigned short grays
GPBuffer< unsigned char > grle
GPBuffer< unsigned char * > grlerows
unsigned short ncolumns
unsigned short nrows
unsigned char * rle
unsigned int rlelength
unsigned char ** rlerows

Private Member Functions

void decode (unsigned char *runs)
int encode (unsigned char *&pruns, GPBuffer< unsigned char > &gpruns) const
void read_pbm_raw (ByteStream &ref)
void read_pbm_text (ByteStream &ref)
void read_pgm_raw (ByteStream &ref)
void read_pgm_text (ByteStream &ref)
void read_rle_raw (ByteStream &ref)

Static Private Member Functions

static void append_line (unsigned char *&data, const unsigned char *row, const int rowlen, bool invert=false)
static void append_long_run (unsigned char *&data, int count)
static void euclidian_ratio (int a, int b, int &q, int &r)
static void makerows (int, const int, unsigned char *, unsigned char *[])
static unsigned int read_integer (char &lookahead, ByteStream &ref)
static GP< ZeroBuffer > zeroes (int ncolumns)

Private Attributes


Static Private Attributes

static unsigned char * zerobuffer = const_cast<unsigned char *>(static_zerobuffer)
static int zerosize = sizeof(static_zerobuffer)


class DjVu_PixImage
class DjVu_Stream
class ZeroBuffer


class  ZeroBuffer

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index