The Original CHomP Software
bitmaps.h
Go to the documentation of this file.
1
3
16
17// Copyright (C) 1997-2020 by Pawel Pilarczyk.
18//
19// This file is part of my research software package. This is free software:
20// you can redistribute it and/or modify it under the terms of the GNU
21// General Public License as published by the Free Software Foundation,
22// either version 3 of the License, or (at your option) any later version.
23//
24// This software is distributed in the hope that it will be useful,
25// but WITHOUT ANY WARRANTY; without even the implied warranty of
26// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27// GNU General Public License for more details.
28//
29// You should have received a copy of the GNU General Public License
30// along with this software; see the file "license.txt". If not,
31// please, see <https://www.gnu.org/licenses/>.
32
33// Started in June 1998. Last revision: July 15, 2023.
34
35// WARNING: This version of the module has very limited capabilities,
36// e.g. it can normally write only 1-bit B/W and 24-bit true color bitmaps,
37// and operates improperly if the entire output bitmap is not stored
38// in the memory or is not written row by row.
39
40
41#ifndef _CHOMP_BITMAPS_BITMAPS_H_
42#define _CHOMP_BITMAPS_BITMAPS_H_
43
44#include "chomp/system/config.h"
46
47#include <iostream>
48#include <stdio.h>
49#include <cstdlib>
50
51namespace chomp {
52namespace homology {
53
54
55// classes defined within this header file:
56class bmpfile;
57
58
59// --------------------------------------------------
60// -------------------- bmpfile ---------------------
61// --------------------------------------------------
62
67{
68public:
72 bmpfile (int _rows = 20);
73
76
77#ifndef bmpReadOnly
78#define bmpReadOnly 0
79#endif
80
81#ifndef bmpReadWrite
82#define bmpReadWrite 1
83#endif
90 int open (const char *filename, int mode = bmpReadOnly,
91 int quiet = 0);
92
102 int create (const char *filename, int _width, int _height,
103 int _bitsperpixel = 24, int _pallength = 0,
104 int32 *_pallette = NULL, int quiet = 0);
105
109 inline void invertedpicture (int _inverted = 1)
110 {inverted = _inverted;};
111
114 int writeheader (void);
115
118 int32 getpixel (int x, int y, bool index = false);
119
121 int32 putpixel (int x, int y, long color = 0,
122 bool index = false);
123
125 void drawpixel (int x, int y, int thickness = 1,
126 long color = 0, bool index = false);
127
129 void drawsegment (int x1, int y1, int x2, int y2,
130 int thickness = 1, long color = 0,
131 bool index = false);
132
134 inline int picture_width (void) { return width; };
135
137 inline int picture_height (void) { return height; };
138
141
144
147
150
152 void flush (void);
153
155 int getbitsperpixel (void);
156
159 unsigned char *getrow (int row);
160
162 unsigned getrowlength () const;
163
165 inline int32 *getpalette (void) { return palette; };
166
168 inline int getpallength (void) { return pallength; };
169
170private:
172 char *header;
173
176
179
182
185
187 unsigned char **rowbuf;
188
190 char *changed;
191
193 unsigned char *defined;
194
197
199 int readrow (int row);
200
202 int writerow (int row);
203
206
208 unsigned rowlength;
209
212
214 int width;
215
218
220 FILE *fbmp;
221
225
232
236
238 int rows;
239
241 unsigned char fillbyte;
242
248
249}; /* class bmpfile */
250
251
252} // namespace homology
253} // namespace chomp
254
255#endif // _CHOMP_BITMAPS_BITMAPS_H_
256
258
#define bmpReadOnly
Definition: bitmaps.h:78
The class 'bmpfile' is an elementary interface that can be used to read or create and write images in...
Definition: bitmaps.h:67
char * header
The header of the bitmap file.
Definition: bitmaps.h:172
bool palette_allocated
Has the palette memory been allocated?
Definition: bitmaps.h:181
FILE * fbmp
The binary stream containing the picture file.
Definition: bitmaps.h:220
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 current
The current row.
Definition: bitmaps.h:196
void invertedpicture(int _inverted=1)
Sets processing of the invertec picture, as stored in the file.
Definition: bitmaps.h:109
void drawpixel(int x, int y, int thickness=1, long color=0, bool index=false)
Writes a thick pixel and returns its true color.
int writeheader(void)
Writes the header to the file.
~bmpfile()
The destructor.
unsigned char * defined
Flags that indicate which rows have been defined.
Definition: bitmaps.h:193
int bitsperpixel
The number of bits per pixel in the bitmap file.
Definition: bitmaps.h:211
int getbitsperpixel(void)
Returns the current number of bits per pixel in the picture.
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 flush(void)
Flushes the buffers to update the contents BMP file.
int firstundefinedbyte
The number of the first undefined byte in the BMP file that has not yet been written after creating t...
Definition: bitmaps.h:235
unsigned char ** rowbuf
The rows of the picture stored in the memory.
Definition: bitmaps.h:187
int firstundefinedrow
The number of the first row undefined in the picture.
Definition: bitmaps.h:231
int height
The actual height of the picture stored in the file.
Definition: bitmaps.h:217
int rows
The number of rows allocated in the memory.
Definition: bitmaps.h:238
unsigned rowlength
The length of a row in the bitmap (in bytes)
Definition: bitmaps.h:208
int picture_height(void)
Returns the height of the picture.
Definition: bitmaps.h:137
int bmpstart
The offset of the bitmap beginning in the file.
Definition: bitmaps.h:205
int inverted
A flag that remembers whether the inverted picture should be processed.
Definition: bitmaps.h:247
int width
The actual width of the picture stored in the file.
Definition: bitmaps.h:214
unsigned char fillbyte
The value of the byte to fill empty lines (background).
Definition: bitmaps.h:241
char * changed
Flags that indicate which rows have been changed.
Definition: bitmaps.h:190
int32 getpixel(int x, int y, bool index=false)
Reads the true color of a pixel or its index if 'index = true'.
unsigned getrowlength() const
Returns the length of a row stored in the memory.
int readrow(int row)
Reads the current row from the file to the memory.
int32 * palette
The palette buffer.
Definition: bitmaps.h:178
unsigned char * getrow(int row)
Returns the pointer to the given row stored in the memory.
bmpfile(int _rows=20)
The only allowed constructor.
int picture_width(void)
Returns the width of the picture.
Definition: bitmaps.h:134
int32 putpixel(int x, int y, long color=0, bool index=false)
Writes a pixel and returns its true color.
long rows_written
The counter of rows written to a BMP file.
Definition: bitmaps.h:149
int getpallength(void)
Returns the length of the current color palette (if any).
Definition: bitmaps.h:168
int32 y_resolution
The Y resolution of the picture (in dpi).
Definition: bitmaps.h:143
int pallength
Palette length (in 32-bit words).
Definition: bitmaps.h:175
int32 * getpalette(void)
Returns a pointer to the current color palette (if any).
Definition: bitmaps.h:165
long rows_read
The counter of rows read from a BMP file.
Definition: bitmaps.h:146
int32 x_resolution
The X resolution of the picture (in dpi).
Definition: bitmaps.h:140
int fileinuse
The type of the bitmap file: 0 = none, 1 = read, 2 = write, 3 = r/w.
Definition: bitmaps.h:224
int open(const char *filename, int mode=0, int quiet=0)
Opens a bmp file for reading (mode = bmpReadOnly) or editing (mode = bmpReadWrite).
int writerow(int row)
Writes the current row from the memory to the file.
int * rownumber
The numbers of rows stored in the memory.
Definition: bitmaps.h:184
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
int int32
Defines the type of 32-bit integers.
Definition: config.h:101
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51
This file contains some useful functions related to the text input/output procedures.