// ** View2D.h : View2D クラスの宣言 for Win32 MFC VS2005 (View2D.h) // ** クラス:Array, Color, View2D // ** // ** 著作権者:東京工芸大学 工学部 メディア画像学科 降旗 隆 T.Furuhata (2007.9) // ******** Array クラスの宣言 ******************************************************************** // ** i 行、j 列の double 型二次元配列 Array(i, j) を提供するクラス class Array { private: // 外部から参照不可 // ** メンバ変数 int isize; int jsize; double *p; public: // 外部から参照可 // ** メンバ関数のプロトタイプ宣言 Array(int i, int j); double &put(int i, int j); double get(int i, int j); double *ArrayP(); int del(); }; // ******** Color クラスの宣言 ******************************************************************** // ** グラフィックスの描画色を指定するクラス class Color { public: // 外部から参照可 // ** メンバ変数 double R, G, B; // RGB 3原色:0.0 〜 1.0 の値 COLORREF CREF; public: // ** メンバ関数のプロトタイプ宣言 // ** コンストラクタ[描画色:黒を指定] Color(); // ** 引数付きコンストラクタ[描画色 r, g, b の飽和度を 0.0 〜 1.0 で指定] Color(double r, double g, double b); // ** フレンド関数(2項演算子の多重定義) // 彩度・加色変換 friend Color operator*(double a, Color cb); friend Color operator*(Color ca, double b); friend Color operator/(Color ca, double b); friend Color operator+(Color ca, Color cb); }; // R G B 1.0 は色飽和度 100% (255 レベル) に対応 #define WHITE Color(1.0, 1.0, 1.0) // ホワイト (白色) #define YELLOW Color(1.0, 1.0, 0.0) // イエロー (黄色) #define CYAN Color(0.0, 1.0, 1.0) // シアン (水色) #define GREEN Color(0.0, 1.0, 0.0) // グリーン (緑色) #define MAGENTA Color(1.0, 0.0, 1.0) // マゼンタ (紫色) #define RED Color(1.0, 0.0, 0.0) // レッド (赤色) #define BLUE Color(0.0, 0.0, 1.0) // ブルー (青色) #define BLACK Color(0.0, 0.0, 0.0) // ブラック (黒色) #define GRAY Color(0.5, 0.5, 0.5) // グレー (灰色) #define DARKBLUE Color(0.1, 0.2, 0.3) // ダークブルー (暗青色) // ******** View2D クラスの宣言 ******************************************************************* // ** ビットマップ画像処理とウィンドウ 2D グラフィックス描画を行うクラス class View2D { private: // 外部から参照不可 // ** メンバ変数 HWND hWnd; // 描画するウィンドウのハンドル CDC* pdc; // 描画用デバイスコンテキスト(CDC クラス・オブジェクトのポインタ) int Width, Height; // ウィンドウ・クライアント領域のサイズ:Width × Height public: HBITMAP mhBmp; // ビットマップオブジェクト(DIBSECTION)のハンドル public: // 外部から参照可 // ** メンバ変数 double *rr; // R 画素処理用一次元動的配列 double *gg; // G 画素処理用一次元動的配列 double *bb; // B 画素処理用一次元動的配列 public: // ** メンバ関数のプロトタイプ宣言 // ** コンストラクタ View2D(); // ** 引数付きコンストラクタ View2D(CSize&); View2D(CDC* pDC); View2D(CDC* pDC, HWND, Color c = WHITE); View2D(CDC*, HWND, int, int, Color c = WHITE); View2D(CDC*, HWND, int, int, int, int, Color c = WHITE); // ** デストラクタ ~View2D(); // ** ビットマップ画像処理関数 ** // ** BMP ファイルの読み込み void ReadBmp(CString filepath); void ReadBmp(CString filepath, HBITMAP&); // ** double 型一次元配列使用の BMP フルカラー画像のロード void LoadBmp(double* rr, double* gg, double* bb); void LoadBmp(void); void LoadBmp(HBITMAP&, double* rr, double* gg, double* bb); void LoadBmp(HBITMAP&); // ** double 型二次元配列使用の BMP フルカラー画像のロード void LoadBmp2(Array RR, Array GG, Array BB); void LoadBmp2(HBITMAP&, Array RR, Array GG, Array BB); // ** double 型一次元配列使用の BMP フルカラー画像のセーブ void SaveBmp(CString filepath, CSize& imgsize, double* rr, double* gg, double* bb); void SaveBmp(CString filepath, CSize&); // ** double 型二次元配列使用の BMP フルカラー画像のセーブ void SaveBmp2(CString filepath, CSize&, Array RR, Array GG, Array BB); // ** double 型一次元配列使用の BMP フルカラー画像の DIBSECTION セーブ void SaveDib(CSize& imgsize, double* rr, double* gg, double* bb); void SaveDib(CSize& imgsize, double* rr, double* gg, double* bb, HBITMAP&); // ** BMP ファイルの書き込み void WriteBmp(CString filepath); void WriteBmp(CString filepath, HBITMAP&); void WriteBmpx(CString filepath); // ** BMP 画像の描画 void DrawBmp(int x, int y); void DrawBmp(int x, int y, HBITMAP&); // ** BMP イメージサイズの取得 CSize GetImageSize(void); CSize GetImageSize(HBITMAP& hBmp); CSize GetImageSize(CString filepath); CSize GetImageSize(char *fname); // ** BMP フルカラー画像のチェック void CheckBit(HBITMAP& hBmp); // ** HBMP の取得 HBITMAP GetHBMP(void); // ** HBMP への代入 void PutHBMP(HBITMAP& hbmp); // ** BMP ファイルの読み込み&表示 void ReadDrawBmp(CString filepath, int, int); void ReadDrawBmp(CString filepath, int, int, HBITMAP&); // ** BMP ファイルの読み込みロード void ReadLoadBmp(CString filepath); // ** BMP ファイルの読み込み void Reading(CArchive&); void Reading(CArchive& ar, HBITMAP& hbmp); // ** BMP ファイルの書き込み void Writing(CArchive&); void Writing(CArchive& ar, HBITMAP& hbmp); void Writingx(CArchive&); // ** メッセージ表示 void Message(char*, double a0 = 0.0, double a1 = 0.0, double a2 = 0.0, double a3 = 0.0, double a4 = 0.0, double a5 = 0.0, double a6 = 0.0, double a7 = 0.0, double a8 = 0.0, double a9 = 0.0); // ** View2D グラフィックス描画関数 ** // ** ウィンドウ描画イメージを BMP ファイルへ書き込む void WriteWin(CString); void WriteWin(HWND, CString, int, int, int, int); // ** ウィンドウの背景色を設定 COLORREF SetWinColor(Color); // ** 描画する文字列の色を設定 void StrColor(Color); // ** 描画する文字列のフォントとサイズを設定 CFont *StrFont(int, CString); // ** 描画する文字列のフォントとサイズを元に戻す void ReturnFont(CFont*); // ** 文字列を描画 void PutString(int, int, CString, Color c = BLACK); void PutString(int, int, char*, Color c = BLACK); // ** 数値を表示 void Wprintf(int, int, char*, double a0, double a1 = 0.0, double a2 = 0.0, double a3 = 0.0, double a4 = 0.0, double a5 = 0.0, double a6 = 0.0, double a7 = 0.0, double a8 = 0.0, double a9 = 0.0); // 文字色は StrColor で設定 // ** 描画用ペンを生成 void SetPen(CPen&, Color c = BLACK, int dot = 1); // ** 描画用ペンを移動 void Move(int, int); // ** 線分を描画 void Line(int, int, Color c = BLACK, int dot = 1); void Line(int, int, int, int, Color c = BLACK, int dot = 1); // ** 四角形を描画 void Square(int, int, int, int, Color c = BLACK, int dot = 1); // ** 円を描画 void Circle(int, int, int, Color c = BLACK, int dot = 1, int n = 20); // ** 点を描画 void PutDot(int, int, Color, int dot = 1); // ** 画素点を描画 void PutPixel(int, int, Color c = BLACK); // ** 描画(クライアント)領域のサイズを取得 CSize GetClientSize(HWND); }; // ******** ウィンドウ描画関数の宣言 ************************************************************** // ** SetWinColor 関数 // ** ウィンドウの背景色を設定 COLORREF SetWinColor(CDC*, Color c = WHITE); // ** StrColor 関数 // ** 描画する文字列の色を設定 void StrColor(CDC*, Color); // ** StrFont 関数 // ** 描画する文字列のフォントとサイズを設定 CFont *StrFont(CDC*, int, CString); // ** ReturnFont 関数 // ** 描画する文字列のフォントとサイズを元に戻す void ReturnFont(CDC*, CFont*); // ** PutString 関数 // ** 文字列を描画 void PutString(CDC*, int, int, CString, Color c = BLACK); void PutString(CDC*, int, int, char*, Color c = BLACK); // ** Wprintf 関数 // ** 数値を表示 void Wprintf(CDC*, int, int, char*, double a0, double a1 = 0.0, double a2 = 0.0, double a3 = 0.0, double a4 = 0.0, double a5 = 0.0, double a6 = 0.0, double a7 = 0.0, double a8 = 0.0, double a9 = 0.0); // 文字色は StrColor で設定 // ** SetPen 関数 // ** 描画用ペンを生成 void SetPen(CDC*, CPen&, Color c = BLACK, int dot = 1); // ** Move 関数 // ** 描画用ペンを移動 void Move(CDC*, int, int); // ** Line 関数 // ** 線分を描画 void Line(CDC*, int, int, Color c = BLACK, int dot = 1); void Line(CDC*, int, int, int, int, Color c = BLACK, int dot = 1); // ** Square 関数 // ** 四角形を描画 void Square(CDC*, int, int, int, int, Color c = BLACK, int dot = 1); // ** Circle 関数 // ** 円を描画 void Circle(CDC*, int, int, int, Color c = BLACK, int dot = 1, int n = 20); // ** PutDot 関数 // ** 点を描画 void PutDot(CDC*, int, int, Color, int dot = 1); // ** PutPixel 関数 // ** 画素点を描画 void PutPixel(CDC*, int, int, Color c = BLACK); // ** GetImageSize 関数 // ** BMP 画像のイメージサイズ取得 CSize GetImageSize(CString); CSize GetImageSize(char*);