Public Member Functions | Public Attributes | Private Member Functions | Private Attributes

chomp::homology::bmpfile Class Reference

The class 'bmpfile' is an elementary interface that can be used to read or create and write images in the uncompressed Windows BMP format. More...

#include <bitmaps.h>

List of all members.

Public Member Functions

 bmpfile (int _rows=20)
 The only allowed constructor.
 ~bmpfile ()
 The destructor.
int open (const char *filename, int mode=0, int quiet=0)
 Opens a bmp file for reading (mode = ReadOnly) or editing (mode = ReadWrite).
int create (const char *filename, int _width, int _height, int _bitsperpixel=24, int _pallength=0, int32 *_pallette=NULL, int quiet=0)
 Create a bmp file (only 1- and 24-bit supported - sorry!).
void invertedpicture (int _inverted=1)
 Sets processing of the invertec picture, as stored in the file.
int writeheader (void)
 Writes the header to the file.
int32 getpixel (int x, int y, bool index=false)
 Reads the true color of a pixel or its index if 'index = true'.
int32 putpixel (int x, int y, long color=0, bool index=false)
 Writes a pixel and returns its true color.
void drawpixel (int x, int y, int thickness=1, long color=0, bool index=false)
 Writes a thick pixel and returns its true color.
void drawsegment (int x1, int y1, int x2, int y2, int thickness=1, long color=0, bool index=false)
 Draws a segment built of pixels, with the desired thickness.
int picture_width (void)
 Returns the width of the picture.
int picture_height (void)
 Returns the height of the picture.
void flush (void)
 Flushes the buffers to update the contents BMP file.
int getbitsperpixel (void)
 Returns the current number of bits per pixel in the picture.
unsigned char * getrow (int row)
 Returns the pointer to the given row stored in the memory.
unsigned getrowlength () const
 Returns the length of a row stored in the memory.
int32getpalette (void)
 Returns a pointer to the current color palette (if any).
int getpallength (void)
 Returns the length of the current color palette (if any).

Public Attributes

int32 x_resolution
 The X resolution of the picture (in dpi).
int32 y_resolution
 The Y resolution of the picture (in dpi).
long rows_read
 The counter of rows read from a BMP file.
long rows_written
 The counter of rows written to a BMP file.

Private Member Functions

int readrow (int row)
 Reads the current row from the file to the memory.
int writerow (int row)
 Writes the current row from the memory to the file.

Private Attributes

char * header
 The header of the bitmap file.
int pallength
 Palette length (in 32-bit words).
int32palette
 The palette buffer.
bool palette_allocated
 Has the palette memory been allocated?
int * rownumber
 The numbers of rows stored in the memory.
unsigned char ** rowbuf
 The rows of the picture stored in the memory.
char * changed
 Flags that indicate which rows have been changed.
unsigned char * defined
 Flags that indicate which rows have been defined.
int current
 The current row.
int bmpstart
 The offset of the bitmap beginning in the file.
unsigned rowlength
 The length of a row in the bitmap (in bytes).
int bitsperpixel
 The number of bits per pixel in the bitmap file.
int width
 The actual width of the picture stored in the file.
int height
 The actual height of the picture stored in the file.
FILE * fbmp
 The binary stream containing the picture file.
int fileinuse
 The type of the bitmap file: 0 = none, 1 = read, 2 = write, 3 = r/w.
int firstundefinedrow
 The number of the first row undefined in the picture.
int firstundefinedbyte
 The number of the first undefined byte in the BMP file that has not yet been written after creating the file.
int rows
 The number of rows allocated in the memory.
unsigned char fillbyte
 The value of the byte to fill empty lines (background).
int inverted
 A flag that remembers whether the inverted picture should be processed.

Detailed Description

The class 'bmpfile' is an elementary interface that can be used to read or create and write images in the uncompressed Windows BMP format.

It supports black-and-white as well as color bitmap images.

Definition at line 67 of file bitmaps.h.


Constructor & Destructor Documentation

chomp::homology::bmpfile::bmpfile ( int  _rows = 20  ) 

The only allowed constructor.

Defines the number of rows that are stored in the memory. For optimal performance, this should be set to the height of the picture (if known).

chomp::homology::bmpfile::~bmpfile (  ) 

The destructor.


Member Function Documentation

int chomp::homology::bmpfile::create ( const char *  filename,
int  _width,
int  _height,
int  _bitsperpixel = 24,
int  _pallength = 0,
int32 _pallette = NULL,
int  quiet = 0 
)

Create a bmp file (only 1- and 24-bit supported - sorry!).

Set "x_resolution" and "y_resolution" before or 0 will be assumed. If you change these parameters later, you must rewrite the header;. Returns: 0 = Ok, -1 = Can't create, -2 = Can't write header, -3 = Can't write palette, -4 = Bad params, -5 = Not supported, -6 = Memory allocation error occurred. Displays a message in case of error.

void chomp::homology::bmpfile::drawpixel ( int  x,
int  y,
int  thickness = 1,
long  color = 0,
bool  index = false 
)

Writes a thick pixel and returns its true color.

void chomp::homology::bmpfile::drawsegment ( int  x1,
int  y1,
int  x2,
int  y2,
int  thickness = 1,
long  color = 0,
bool  index = false 
)

Draws a segment built of pixels, with the desired thickness.

void chomp::homology::bmpfile::flush ( void   ) 

Flushes the buffers to update the contents BMP file.

int chomp::homology::bmpfile::getbitsperpixel ( void   ) 

Returns the current number of bits per pixel in the picture.

int32* chomp::homology::bmpfile::getpalette ( void   )  [inline]

Returns a pointer to the current color palette (if any).

Definition at line 166 of file bitmaps.h.

References palette.

{ return palette; };

int chomp::homology::bmpfile::getpallength ( void   )  [inline]

Returns the length of the current color palette (if any).

Definition at line 169 of file bitmaps.h.

{ return pallength; };

int32 chomp::homology::bmpfile::getpixel ( int  x,
int  y,
bool  index = false 
)

Reads the true color of a pixel or its index if 'index = true'.

Note: The coordinates start with (0,0).

unsigned char* chomp::homology::bmpfile::getrow ( int  row  ) 

Returns the pointer to the given row stored in the memory.

Please, use this function with caution!

unsigned chomp::homology::bmpfile::getrowlength (  )  const

Returns the length of a row stored in the memory.

void chomp::homology::bmpfile::invertedpicture ( int  _inverted = 1  )  [inline]

Sets processing of the invertec picture, as stored in the file.

This results in the Y axis running from bottom to top, like in mathematics, unlike in computers.

Definition at line 110 of file bitmaps.h.

References inverted.

                {inverted = _inverted;};

int chomp::homology::bmpfile::open ( const char *  filename,
int  mode = 0,
int  quiet = 0 
)

Opens a bmp file for reading (mode = ReadOnly) or editing (mode = ReadWrite).

Returns: 0 = Ok, -1 = Not found, -2 = Can't read header, -3 = Can't read palette, -4 = Not BMP, -5 = Not supported, -6 = Memory allocation error occurred. Displays a message in case of error.

int chomp::homology::bmpfile::picture_height ( void   )  [inline]

Returns the height of the picture.

Definition at line 138 of file bitmaps.h.

{ return height; };

int chomp::homology::bmpfile::picture_width ( void   )  [inline]

Returns the width of the picture.

Definition at line 135 of file bitmaps.h.

References width.

{ return width; };

int32 chomp::homology::bmpfile::putpixel ( int  x,
int  y,
long  color = 0,
bool  index = false 
)

Writes a pixel and returns its true color.

int chomp::homology::bmpfile::readrow ( int  row  )  [private]

Reads the current row from the file to the memory.

int chomp::homology::bmpfile::writeheader ( void   ) 

Writes the header to the file.

Returns: 0 = Ok, -1 = Error (no messages displayed).

int chomp::homology::bmpfile::writerow ( int  row  )  [private]

Writes the current row from the memory to the file.


Member Data Documentation

The number of bits per pixel in the bitmap file.

Definition at line 212 of file bitmaps.h.

The offset of the bitmap beginning in the file.

Definition at line 206 of file bitmaps.h.

Flags that indicate which rows have been changed.

Definition at line 191 of file bitmaps.h.

The current row.

Definition at line 197 of file bitmaps.h.

unsigned char* chomp::homology::bmpfile::defined [private]

Flags that indicate which rows have been defined.

Definition at line 194 of file bitmaps.h.

The binary stream containing the picture file.

Definition at line 221 of file bitmaps.h.

The type of the bitmap file: 0 = none, 1 = read, 2 = write, 3 = r/w.

Definition at line 225 of file bitmaps.h.

unsigned char chomp::homology::bmpfile::fillbyte [private]

The value of the byte to fill empty lines (background).

Definition at line 242 of file bitmaps.h.

The number of the first undefined byte in the BMP file that has not yet been written after creating the file.

Definition at line 236 of file bitmaps.h.

The number of the first row undefined in the picture.

Normally it will be the height of the picture, since rows are numbered starting with 0. It is important while creating a BMP picture so that the program knows where to begin writing the empty rows if any.

Definition at line 232 of file bitmaps.h.

The header of the bitmap file.

Definition at line 169 of file bitmaps.h.

The actual height of the picture stored in the file.

Definition at line 218 of file bitmaps.h.

A flag that remembers whether the inverted picture should be processed.

This is the order of rows as stored in the file, with the vertical axis Y running from the bottom to the top of the screen.

Definition at line 248 of file bitmaps.h.

Referenced by invertedpicture().

The palette buffer.

Definition at line 179 of file bitmaps.h.

Referenced by getpalette().

Has the palette memory been allocated?

Definition at line 182 of file bitmaps.h.

Palette length (in 32-bit words).

Definition at line 176 of file bitmaps.h.

unsigned char** chomp::homology::bmpfile::rowbuf [private]

The rows of the picture stored in the memory.

Definition at line 188 of file bitmaps.h.

The length of a row in the bitmap (in bytes).

Definition at line 209 of file bitmaps.h.

The numbers of rows stored in the memory.

Definition at line 185 of file bitmaps.h.

The number of rows allocated in the memory.

Definition at line 239 of file bitmaps.h.

The counter of rows read from a BMP file.

Definition at line 147 of file bitmaps.h.

The counter of rows written to a BMP file.

Definition at line 150 of file bitmaps.h.

The actual width of the picture stored in the file.

Definition at line 215 of file bitmaps.h.

Referenced by picture_width().

The X resolution of the picture (in dpi).

Definition at line 138 of file bitmaps.h.

The Y resolution of the picture (in dpi).

Definition at line 144 of file bitmaps.h.


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