00001 # ifndef OptIm_h
00002 # define OptIm_h OptIm_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 # include <vector>
00021 # include "Root.h"
00022 # include "PixelLine.h"
00023
00024 # include "GlyphFeatures.h"
00025
00026
00027 namespace Conjecture {
00028 class Image;
00029 class ImageArgs;
00030
00031
00113
00114 class OptIm : public Root {
00115 friend class PixFilt;
00116
00117 public:
00118
00119 typedef std::vector<PixelLine> PixelMatrix;
00120
00121
00122 OptIm(const std::vector<unsigned int>& rows, u1 width = PixelLine::MaxPixels);
00123 OptIm(const Image* image, const ImageArgs& config);
00124
00125
00126
00127
00128
00129
00130 inline const u1 & width() const { return this->_width; }
00131 inline const PixelMatrix & cols() const { return this->_cols; }
00132 inline const PixelMatrix & rows() const { return this->_rows; }
00133
00134
00135
00136
00137
00138
00139 void updateMeta();
00140
00141
00142
00143
00144
00145
00147 int rblack(u1 i) const { return (this->updated() ? this->rows()[i].black() : 0); }
00149 int rholes(u1 i) const { return (this->updated() ? this->rows()[i].holes() : 0); }
00151 int cblack(u1 i) const { return (this->updated() ? this->cols()[i].black() : 0); }
00153 int choles(u1 i) const { return (this->updated() ? this->cols()[i].holes() : 0); }
00154
00155 u1 height() const { return this->rows().size(); }
00156
00159 inline bool get(u2 x, u2 y) const { int w = this->width(); return this->rows()[y].get(w-1-x); }
00160
00164 inline std::string str(char on = '#', char off = '.') const { return this->str("",0,on,off); }
00165
00170 std::string str(const std::string& title, int valign = 0, char on = '#', char off = '.') const;
00171
00185 bool crop(int level = 0);
00186 bool crop(int topthick, int bottomthick, int leftthick, int rightthick);
00187 bool crop(int topthick, int bottomthick, int leftthick, int rightthick, int& topref, int& bottomref, int& leftref, int& rightref);
00188
00196 void identifyFeatures(GlyphFeatures& features);
00197
00201 inline const PixelLine& row(int i) const {
00202 if ( i < 0 ) { i += this->height(); }
00203 return this->rows()[i];
00204 }
00205
00211 bool removeBottomSerifs();
00212
00218 bool removeTopSerifs();
00219
00220 static void test(int argc = 0, const char* argv[] = NULL);
00221
00222 inline void print(ostream& os = cout) const { os << this->str() << endl; }
00223
00224 protected:
00225
00226
00227 inline bool updated() const { return this->_updated; }
00228 inline void updatedIs(const bool & updated) { this->_updated = updated; }
00229 inline void widthIs(const u1 & width) { this->_width = width; }
00230 inline void colsIs(const PixelMatrix & cols) { this->_cols = cols; }
00231 inline void rowsIs(const PixelMatrix & rows) { this->_rows = rows; }
00232
00233
00234
00235 std::string rawstr(const PixelMatrix& vec, char on = '1', char off = '0', unsigned char size = PixelLine::MaxPixels) const;
00236
00240 inline PixelLine& row(int i) {
00241 if ( i < 0 ) { i += this->height(); }
00242 return this->rowsRef()[i];
00243 }
00244
00245 GlyphFeatures::Variant analyzeLines(u1 min, u2 max, const PixelMatrix& matrix, u1 dom, u1 rec, u1 halfn);
00246
00247 private:
00248
00249
00250 inline bool& updatedRef() { return this->_updated; }
00251 inline u1& widthRef() { return this->_width; }
00252 inline PixelMatrix& colsRef() { return this->_cols; }
00253 inline PixelMatrix& rowsRef() { return this->_rows; }
00254
00255
00256
00257
00258
00259
00260
00263 bool _updated;
00264
00275 u1 _width;
00276
00278 PixelMatrix _rows;
00279
00281 PixelMatrix _cols;
00282 };
00283 }
00284
00285 # endif // OptIm_h
00286