diff options
author | cathook <b01902109@csie.ntu.edu.tw> | 2014-06-19 07:25:48 +0800 |
---|---|---|
committer | cathook <b01902109@csie.ntu.edu.tw> | 2014-06-19 07:25:48 +0800 |
commit | fe926756145c5e5cf5f315af0acdbfd85ba27543 (patch) | |
tree | 4d75f94b87fd6d60262f2377d92f5896faf1be7d /meowpp/gra/Bitmap.h | |
parent | b2b55d8c642524274d8115d5b1863e1a40715887 (diff) | |
download | meow-fe926756145c5e5cf5f315af0acdbfd85ba27543.tar meow-fe926756145c5e5cf5f315af0acdbfd85ba27543.tar.gz meow-fe926756145c5e5cf5f315af0acdbfd85ba27543.tar.bz2 meow-fe926756145c5e5cf5f315af0acdbfd85ba27543.tar.lz meow-fe926756145c5e5cf5f315af0acdbfd85ba27543.tar.xz meow-fe926756145c5e5cf5f315af0acdbfd85ba27543.tar.zst meow-fe926756145c5e5cf5f315af0acdbfd85ba27543.zip |
x
Diffstat (limited to 'meowpp/gra/Bitmap.h')
-rw-r--r-- | meowpp/gra/Bitmap.h | 87 |
1 files changed, 52 insertions, 35 deletions
diff --git a/meowpp/gra/Bitmap.h b/meowpp/gra/Bitmap.h index c4ed4e0..59136c2 100644 --- a/meowpp/gra/Bitmap.h +++ b/meowpp/gra/Bitmap.h @@ -1,9 +1,6 @@ #ifndef gra_Bitmap_H__ #define gra_Bitmap_H__ - -#include "../Self.h" - #include "../math/utility.h" #include "../math/Matrix.h" @@ -15,7 +12,7 @@ #include <typeinfo> #include <cstdlib> -namespace meow{ +namespace meow { /*! * @brief 二維點陣資料 @@ -26,7 +23,8 @@ template<class Pixel> class Bitmap: public ObjBase { private: Matrix<Pixel> matrix_; - // + + //! 回傳高斯模糊的權重 static std::vector<double> gaussianFactor1(double sigma) { double sigma2 = squ(sigma); size_t width = std::max(ceil((double)(sigma * 2)), 0.0); @@ -38,6 +36,8 @@ private: factor[width] = 1.0; return factor; } + + //! 回傳gradiance的權重 static std::vector<double> gradianceFactor1(double sigma) { double sigma2 = squ(sigma), ss = sigma * 2; size_t width = std::max(ceil(ss), 1.0); @@ -49,6 +49,8 @@ private: factor[width] = 0.0; return factor; } + + //! 針對某一方向用某種權重模糊 Bitmap xyBlur(std::vector<double> const& factor, ssize_t dx, ssize_t dy) const { Bitmap ret(*this); @@ -128,7 +130,7 @@ public: void reset(size_t h, size_t w, Pixel const& p) { matrix_.reset(h, w, p); } - + /*! * @brief 清除資料, 寬高階規零 */ @@ -233,6 +235,28 @@ public: } /*! + * @brief 回傳矩陣形式 + */ + Matrix<Pixel> const& matrix() const { + return matrix_; + } + + /*! + * @brief 回傳矩陣形式 (non-constant form) + */ + Matrix<Pixel>& matrixGet() { + return matrix_; + } + + /*! + * @brief 直接設定 + */ + Matrix<Pixel> const& matrix(Matrix<Pixel> const& p) { + matrix_.copyFrom(p); + return matrix(); + } + + /*! * @brief 回傳高斯模糊 * * @param [in] radiusY 高斯模糊的Y軸方向的sigma @@ -278,7 +302,7 @@ public: Bitmap<Pixel>& gradiancedX(double radiusY, double radiusX) { return copyFrom(gradianceX(radiusY, radiusX)); } - + /*! * @brief 回傳對y偏微分 * @@ -322,48 +346,42 @@ public: Pixel const& operator()(size_t y, size_t x, Pixel const& p) const { return pixel(y, x, p); } - + /*! @brief 將資料寫入檔案 * * @note 未完成, 輸入參數 fg 無用 */ bool write(FILE* f, bool bin, unsigned int fg) const { - size_t w = width(), h = height(); + if (fg & 1) + return false; if (bin) { - if (fwrite(&h, sizeof(size_t), 1, f) < 1) return false; - if (fwrite(&w, sizeof(size_t), 1, f) < 1) return false; + long tmp; + if (fwrite(&(tmp = matrix_.cols()), sizeof(tmp), 1, f) < 1) return false; + if (fwrite(&(tmp = matrix_.rows()), sizeof(tmp), 1, f) < 1) return false; } else { - if (fprintf(f, "%lu %lu\n", h, w) < 2) return false; - } - if (fg) { - // TODO - return false; + if (fprintf(f, "%ld %ld\n", (long)matrix_.cols(), (long)matrix_.rows()) + < 2) return false; } return true; - //return propertyWrite(__f, __bin, __fg); } - + /*! @brief 將資料讀入 * * @note 未完成, 輸入參數 fg 無用 */ bool read(FILE* f, bool bin, unsigned int fg) { - size_t w, h; - if (bin) { - if (fread(&h, sizeof(size_t), 1, f) < 1) return false; - if (fread(&w, sizeof(size_t), 1, f) < 1) return false; - } - else { - if (fscanf(f, "%lu %lu\n", &h, &w) < 2) return false; - } - if (fg) { - // TODO + if (fg & 1) return false; + long tmp1, tmp2; + if (bin) { + if (fread(&tmp1, sizeof(tmp1), 1, f) < 1) return false; + if (fread(&tmp2, sizeof(tmp2), 1, f) < 1) return false; } else { - reset(h, w, Pixel(0)); + if (fscanf(f, "%ld %ld", &tmp1, &tmp2) < 2) return false; } + matrix_.size(tmp1, tmp2, Pixel(0)); return true; } @@ -374,7 +392,7 @@ public: ObjBase* create() const { return new Bitmap(); } - + /*! @brief 複製資料 * * 輸入型別是 \c ObjBase \c const* @@ -387,16 +405,15 @@ public: ObjBase* copyFrom(ObjBase const* b) { return &(copyFrom(*(Bitmap*)b)); } - + /*! @brief 回傳class的type * * @return \c char \c const\c * 形式的typename */ char const* ctype() const{ - static char const* ptr = typeid(*this).name(); - return ptr; + return typeid(*this).name(); } - + /*! @brief 回傳class的type * * @return \c std::string 形式的typename @@ -406,6 +423,6 @@ public: } }; -} +} // meow #endif // gra_Bitmap_H__ |