00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef BMP8_H
00021 #define BMP8_H
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include "con_comp.h"
00032 #include "cached_file.h"
00033
00034 namespace tesseract {
00035
00036
00037 static const float kMinDeslantAngle = -30.0f;
00038 static const float kMaxDeslantAngle = 30.0f;
00039 static const float kDeslantAngleDelta = 0.5f;
00040
00041 class Bmp8 {
00042 public:
00043 Bmp8(unsigned short wid, unsigned short hgt);
00044 ~Bmp8();
00045
00046 bool Clear();
00047
00048 inline unsigned short Width() const { return wid_; }
00049 inline unsigned short Stride() const { return stride_; }
00050 inline unsigned short Height() const { return hgt_; }
00051 inline unsigned char *RawData() const {
00052 return (line_buff_ == NULL ? NULL : line_buff_[0]);
00053 }
00054
00055
00056 bool ScaleFrom(Bmp8 *bmp, bool isotropic = true);
00057
00058 bool Deslant();
00059
00060 bool HorizontalDeslant(double *deslant_angle);
00061
00062 static Bmp8 *FromCharDumpFile(CachedFile *fp);
00063 static Bmp8 *FromCharDumpFile(FILE *fp);
00064
00065 bool IsIdentical(Bmp8 *pBmp) const;
00066
00067 ConComp ** FindConComps(int *concomp_cnt, int min_size) const;
00068
00069 float ForegroundRatio() const;
00070
00071 float MeanHorizontalHistogramEntropy() const;
00072
00073 int *HorizontalHistogram() const;
00074
00075 private:
00076
00077 static bool ComputeTanTable();
00078
00079 unsigned char ** CreateBmpBuffer(unsigned char init_val = 0xff);
00080 static unsigned int ** CreateBmpBuffer(int wid, int hgt,
00081 unsigned char init_val = 0xff);
00082
00083 static void FreeBmpBuffer(unsigned char **buff);
00084 static void FreeBmpBuffer(unsigned int **buff);
00085
00086
00087 static float *tan_table_;
00088
00089 unsigned short stride_;
00090
00091 static const unsigned int kMagicNumber = 0xdeadbeef;
00092
00093 protected:
00094
00095 unsigned short wid_;
00096 unsigned short hgt_;
00097
00098 unsigned char **line_buff_;
00099
00100 static const int kConCompAllocChunk = 16;
00101 static const int kDeslantAngleCount;
00102
00103
00104 bool LoadFromCharDumpFile(CachedFile *fp);
00105 bool LoadFromCharDumpFile(FILE *fp);
00106
00107 bool LoadFromCharDumpFile(unsigned char **raw_data);
00108
00109 bool LoadFromRawData(unsigned char *data);
00110
00111 bool SaveBmp2CharDumpFile(FILE *fp) const;
00112
00113 bool IsBlankColumn(int x) const;
00114 bool IsBlankRow(int y) const;
00115
00116 void Crop(int *xst_src, int *yst_src, int *wid, int *hgt);
00117
00118 void Copy(int x, int y, int wid, int hgt, Bmp8 *bmp_dest) const;
00119 };
00120 }
00121
00122 #endif // BMP8_H