bitmaps.h

Go to the documentation of this file.
00001 
00002 
00003 
00016 
00017 // Copyright (C) 1997-2010 by Pawel Pilarczyk.
00018 //
00019 // This file is part of the Homology Library.  This library is free software;
00020 // you can redistribute it and/or modify it under the terms of the GNU
00021 // General Public License as published by the Free Software Foundation;
00022 // either version 2 of the License, or (at your option) any later version.
00023 //
00024 // This library is distributed in the hope that it will be useful,
00025 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027 // GNU General Public License for more details.
00028 //
00029 // You should have received a copy of the GNU General Public License along
00030 // with this software; see the file "license.txt".  If not, write to the
00031 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00032 // MA 02111-1307, USA.
00033 
00034 // Started in June 1998. Last revision: September 3, 2003 (Nov 13, 2003).
00035 
00036 // WARNING: This version of the module has very limited capabilities,
00037 // e.g. it can normally write only 1-bit B/W and 24-bit true color bitmaps,
00038 // and operates improperly if the entire output bitmap is not stored
00039 // in the memory or is not written row by row.
00040 
00041 
00042 #ifndef _CHOMP_BITMAPS_BITMAPS_H_
00043 #define _CHOMP_BITMAPS_BITMAPS_H_
00044 
00045 #include "chomp/system/config.h"
00046 #include "chomp/system/textfile.h"
00047 
00048 #include <iostream>
00049 #include <stdio.h>
00050 #include <cstdlib>
00051 
00052 namespace chomp {
00053 namespace homology {
00054 
00055 
00056 // classes defined within this header file:
00057 class bmpfile;
00058 
00059 
00060 // --------------------------------------------------
00061 // -------------------- bmpfile ---------------------
00062 // --------------------------------------------------
00063 
00067 class bmpfile
00068 {
00069 public:
00073         bmpfile (int _rows = 20);
00074 
00076         ~bmpfile ();
00077 
00078 #ifndef ReadOnly
00079 #define ReadOnly 0
00080 #endif
00081 
00082 #ifndef ReadWrite
00083 #define ReadWrite 1
00084 #endif
00085 
00086 
00087 
00088 
00089 
00090 
00091         int open (const char *filename, int mode = ReadOnly,
00092                 int quiet = 0);
00093 
00103         int create (const char *filename, int _width, int _height,
00104                 int _bitsperpixel = 24, int _pallength = 0,
00105                 int32 *_pallette = NULL, int quiet = 0);
00106 
00110         inline void invertedpicture (int _inverted = 1)
00111                 {inverted = _inverted;};
00112 
00115         int writeheader (void);
00116 
00119         int32 getpixel (int x, int y, bool index = false);
00120 
00122         int32 putpixel (int x, int y, long color = 0,
00123                 bool index = false);
00124 
00126         void drawpixel (int x, int y, int thickness = 1,
00127                 long color = 0, bool index = false);
00128 
00130         void drawsegment (int x1, int y1, int x2, int y2,
00131                 int thickness = 1, long color = 0,
00132                 bool index = false);
00133 
00135         inline int picture_width (void) { return width; };
00136 
00138         inline int picture_height (void) { return height; };
00139 
00141         int32 x_resolution;
00142 
00144         int32 y_resolution;
00145 
00147         long rows_read;
00148 
00150         long rows_written;
00151 
00153         void flush (void);
00154 
00156         int getbitsperpixel (void);
00157 
00160         unsigned char *getrow (int row);
00161         
00163         unsigned getrowlength () const;
00164 
00166         inline int32 *getpalette (void) { return palette; };
00167 
00169         inline int getpallength (void) { return pallength; };
00170 
00171 private:
00173         char *header;
00174 
00176         int pallength;
00177 
00179         int32 *palette;
00180 
00182         bool palette_allocated;
00183 
00185         int *rownumber;
00186 
00188         unsigned char **rowbuf;
00189 
00191         char *changed;
00192 
00194         unsigned char *defined;
00195 
00197         int current;
00198 
00200         int readrow (int row);
00201 
00203         int writerow (int row);
00204 
00206         int bmpstart;
00207 
00209         unsigned rowlength;
00210 
00212         int bitsperpixel;
00213 
00215         int width;
00216 
00218         int height;
00219 
00221         FILE *fbmp;
00222 
00225         int fileinuse;
00226 
00232         int firstundefinedrow;
00233 
00236         int firstundefinedbyte;
00237 
00239         int rows;
00240 
00242         unsigned char fillbyte;
00243 
00248         int inverted;
00249 
00250 }; /* class bmpfile */
00251 
00252 
00253 } // namespace homology
00254 } // namespace chomp
00255 
00256 #endif // _CHOMP_BITMAPS_BITMAPS_H_
00257 
00259