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>
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. | |
int32 * | getpalette (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). | |
int32 * | palette |
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. |
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.
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.
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] |
int chomp::homology::bmpfile::getpallength | ( | void | ) | [inline] |
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] |
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] |
int chomp::homology::bmpfile::picture_width | ( | void | ) | [inline] |
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.
int chomp::homology::bmpfile::bitsperpixel [private] |
int chomp::homology::bmpfile::bmpstart [private] |
char* chomp::homology::bmpfile::changed [private] |
int chomp::homology::bmpfile::current [private] |
unsigned char* chomp::homology::bmpfile::defined [private] |
FILE* chomp::homology::bmpfile::fbmp [private] |
int chomp::homology::bmpfile::fileinuse [private] |
unsigned char chomp::homology::bmpfile::fillbyte [private] |
int chomp::homology::bmpfile::firstundefinedbyte [private] |
int chomp::homology::bmpfile::firstundefinedrow [private] |
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.
char* chomp::homology::bmpfile::header [private] |
int chomp::homology::bmpfile::height [private] |
int chomp::homology::bmpfile::inverted [private] |
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().
int32* chomp::homology::bmpfile::palette [private] |
bool chomp::homology::bmpfile::palette_allocated [private] |
int chomp::homology::bmpfile::pallength [private] |
unsigned char** chomp::homology::bmpfile::rowbuf [private] |
unsigned chomp::homology::bmpfile::rowlength [private] |
int* chomp::homology::bmpfile::rownumber [private] |
int chomp::homology::bmpfile::rows [private] |
int chomp::homology::bmpfile::width [private] |
The actual width of the picture stored in the file.
Definition at line 215 of file bitmaps.h.
Referenced by picture_width().