dvi2bitmap dvi2bitmap1.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Bitmap.h
Go to the documentation of this file.
1 /* This file is part of dvi2bitmap; see README for copyrights and licence */
2
3
4 #ifndef BITMAP_HEADER_READ
5 #define BITMAP_HEADER_READ 1
6
7 #include "Byte.h"
8 //#include "DviFile.h" /* needed by BitmapMark */
9 #include "DviFilePosition.h"
10 #include "DviError.h"
11 #include "verbosity.h"
12
13 class BitmapError : public DviError {
14 public:
15 BitmapError(string s) : DviError(s) { };
16 };
17
22 class Bitmap {
23 public:
24 Bitmap (const int width, const int height, const int bpp=1,
25 bool expandable=true,
26 const int maxwidth=-1, const int maxheight=-1)
27 throw (BitmapError);
28 ~Bitmap();
29
30 // make sure Left..Bottom are 0..3 (I should use an iterator, I know...)
31 enum Margin { Left=0, Right=1, Top=2, Bottom=3, All};
32
33 void paint (const int x, const int y, const int w, const int h,
34 const Byte* b)
35 throw (BitmapError);
36 void rule (const int x, const int y, const int w, const int h)
37 throw (BitmapError);
38 void strut (const int x, const int y,
39 const int l, const int r,
40 const int t, const int b)
41 throw (BitmapError);
42 void write (const string filename, const string format)
43 throw (BitmapError);
44 void freeze ();
45 void crop ();
46 static void cropDefault (Margin spec, int pixels, bool absolute=false)
47 throw (BitmapError);
48 void crop (Margin spec, int pixels, bool absolute=false)
49 throw (BitmapError);
50 void blur ();
51 void clear();
56 void setTransparent(const bool sw) { transparent_ = sw; }
57 typedef struct BitmapColour_s {
58 Byte red, green, blue;
59 } BitmapColour;
60 void setRGB (const bool fg, const BitmapColour*);
61 static void setDefaultRGB (const bool fg, const BitmapColour*);
62 void scaleDown (const int factor)
63 throw (BitmapError);
71 bool empty () const
72 { return (bbL > W || bbR < 0 || bbT > H || bbB < 0); }
73 bool overlaps() const;
74 int* boundingBox();
80 int getWidth() const { return W; }
86 int getHeight() const { return H; }
92 static verbosities verbosity (const verbosities level) {
93 enum verbosities oldv = verbosity_;
94 verbosity_ = level;
95 return oldv;
96 }
105 static void logBitmapInfo (const char *prefix) {
106 logBitmapPrefix_ = prefix;
107 };
108
109 #if 0
110
118 class BitmapMark {
119 private:
120 double x, y;
121 DviFile* dvif;
122 public:
123 BitmapMark(DviFile*, double x_sp, double y_sp);
124 double getX(const DviFile::DviUnits u);
125 double getY(const DviFile::DviUnits u);
126 void shift(double dx, double dy, DviFile::DviUnits u);
127 void scale(double factor);
128 // make a static copy
129 BitmapMark* copy();
130 };
131 void mark(DviFile*, const double x, const double y);
132 BitmapMark* getMark();
133 #endif
134 void mark(DviFilePosition*);
135 DviFilePosition* getMark();
136
138 class const_iterator
139 {
140 public:
141 Byte* operator*() throw (DviError);
142 const_iterator& operator++() throw (DviError);
143 bool operator==(const const_iterator& it) const;
144 bool operator!=(const const_iterator& it) const;
145 ~const_iterator();
146 private:
147 const_iterator();
148 void init(Byte* b, int startx, int starty, int width, int nrows);
149 Byte* b_;
150 int rowLength_;
151 int rowNumber_;
152 int startColumn_;
153 int lastRow_;
154 friend class Bitmap;
155 };
156 const_iterator runningIterator_;
157 static const_iterator endIterator_;
158 const_iterator begin();
159 const_iterator end() const;
160
161 private:
162 void normalizeBB_(int& l, int& r, int& t, int& b);
163 void usesBitmapArea_(const int ulx, const int uly,
164 const int lrx, const int lry);
166 Byte *B;
168 int W, H;
170 int maxW_, maxH_;
172 bool isExpandable_;
182 int bbL, bbR, bbT, bbB;
184 int BB[4];
186 bool frozen_;
188 int cropL, cropR, cropT, cropB;
190 bool cropped_;
192 bool scaled_;
194 DviFilePosition* mark_;
196 static int cropMarginDefault[4];
197 int cropMargin[4];
198 static bool cropMarginAbsDefault[4];
199 bool cropMarginAbs[4];
201 bool transparent_;
202 BitmapColour fg_, bg_;
204 bool customRGB_;
206 static BitmapColour def_fg_, def_bg_;
207 static bool def_customRGB_;
209 int bpp_;
211 Byte max_colour_;
213 static verbosities verbosity_;
215 static const char* logBitmapPrefix_;
216 };
217
218 #endif //#ifndef BITMAP_HEADER_READ