Bilevel and gray-level images.
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.
GBitmap(int nrows, int ncolumns, int border=0)
GBitmap(const GBitmap &ref)
GBitmap(const GBitmap &ref, int border)
GBitmap(const GBitmap &ref, const GRect &rect, int border=0)
GBitmap(ByteStream &ref, int border=0)
void init(const GBitmap &ref, int border=0)
void init(const GBitmap &ref, const GRect &rect, int border=0)
void init(ByteStream &ref, int border=0)
GBitmap& operator=(const GBitmap &ref)
void fill(unsigned char value)
unsigned int columns() const
const unsigned char* operator[] (int row) const
unsigned char* operator[] (int row)
unsigned int rowsize() const
void minborder(int minimum)
void set_grays(int grays)
void change_grays(int grays)
void binarize_grays(int threshold=0)
void uncompress()
unsigned int get_memory_usage() const
GMonitor* monitor() const
void share()
static void rle_get_bitmap(const int ncolumns, const unsigned char *&runs, unsigned char *bitmap, const bool invert )
int rle_get_runs(int rowno, int *rlens) const
int rle_get_rect(GRect &rect) const
Example: Assume for instance that the current GBitmap is initially white (all pixels have value zero). This operation copies the pixel values of GBitmap bm at position (x,y) into the current GBitmap. Note that function blit does not change the number of gray levels in the current GBitmap. You may have to call set_grays to specify how the pixel values should be interpreted.
Example: Assume for instance that the current GBitmap is initially
white (all pixels have value zero). Each pixel of the current GBitmap
then contains the sum of the gray levels of the corresponding pixels in
GBitmap bm. There are up to subsample*subsample such pixels. If
for instance GBitmap bm is a bilevel image (pixels can be 0 or 1),
the pixels of the current GBitmap can take values in range 0 to
subsample*subsample. Note that function blit does not change the
number of gray levels in the current GBitmap. You must call
set_grays to indicate that there are subsample^2+1 gray
levels. Since there is at most 256 gray levels, this also means that
subsample should never be greater than 15. Remark: Arguments x and y do not represent a position in the
coordinate system of the current GBitmap. According to the above
discussion, the position is (x/subsample,y/subsample). In other
words, you can position the blit with a sub-pixel resolution. The
resulting anti-aliasing changes are paramount to the image quality.
void blit(const GBitmap *shape, int x, int y, int subsample)
void save_pgm(ByteStream &bs, int raw=1)
void save_rle(ByteStream &bs)
inline void borrow_data(unsigned char &data, int w, int h)
void donate_data(unsigned char *data, int w, int h)
const unsigned char* get_rle(unsigned int &rle_length)
void donate_rle(unsigned char *rledata, unsigned int rledatalen, int w, int h)
static inline int read_run(const unsigned char *&data)
static inline void append_run(unsigned char *&data, int count)
Alphabetic index HTML hierarchy of classes or Java