#ifndef __INCLUDE_IPCOMMON_H__ #define __INCLUDE_IPCOMMON_H__ //----------------------------------------------------------------- #include #include #include #include #include "wingui.h" //----------------------------------------------------------------- // 定数定義 //----------------------------------------------------------------- extern int iHeight,iWidth,iLength; // 高さ,幅,1行幅 extern int iSize,biSize; // サイズ extern int iGHist[512],iCHist[3][512]; // ヒストグラム extern LPBYTE lpOrgBMP,lpBMP; // オリジナル画像, 表示画像 //----------------------------------------------------------------- #ifndef M_PI #define M_PI 3.14159265358979323846 #endif // 色定義 #define iWHITE 0xff #define iBLACK 0 #define iGRAY 100 #define iMAX_GRAY 256 #define iRED 2 #define iGREEN 1 #define iBLUE 0 #define CBIT 8 //----------------------------------------------------------------- // マクロ宣言 //----------------------------------------------------------------- // calc image pointer index #define XY1D(x,y,w) ((x)+(y)*w) // check point #define ip_safe(x,y,w,h) ((x)>=0 && (x)<(w) && (y)>=0 && (y)<(h)) // double to int #define rint(x) ((x>=0)?((int)(x+0.5)):((int)(x-0.5))) // degree to radian #define deg2rad(x) ((double)(x)*M_PI/180.) // radian to degree #define rad2deg(x) ((double)(x)*180./M_PI) // calc power #define calc_pw(x,y) (sqrt((x)*(x)+(y)*(y))) #define calc_sq(x,y) ((x)*(x)+(y)*(y)) //----------------------------------------------------------------- enum COLOR_DEF { COLOR_R = 0, COLOR_G = 1, COLOR_B = 2, COLOR_GRAY = 3, COLOR_Y = 4, COLOR_U = 5, COLOR_V = 6, COLOR_RHO = 7, COLOR_THETA = 8, COLOR_RGB = 9, }; // 補間形式 enum INTERPOLATION { INTP_NN = 0, INTP_LN = 1, INTP_BCC = 2, }; // RGB色 typedef struct COLOR_PIXEL { BYTE r,g,b; } CPIXEL; // 近接画素へのオフセット static POINT offset8[8] = { {-1,-1},{ 0,-1},{ 1,-1}, {-1, 0},{ 1, 0}, {-1, 1},{ 0, 1},{ 1, 1} }; // 近接画素へのオフセット static POINT offset9[9] = { {-1,-1},{ 0,-1},{ 1,-1}, {-1, 0},{ 0, 0},{ 1, 0}, {-1, 1},{ 0, 1},{ 1, 1} }; //----------------------------------------------------------------- // 諸関数 //----------------------------------------------------------------- int lcm(int a,int b); void init_random(); int random_int(int n); void swapv(int c1,int c2); void swap_point(POINT p1,POINT p2); int colcmp(LPBYTE inb,CPIXEL c2); void setcol(LPBYTE inb,CPIXEL c); double calc_distance(POINT p1,POINT p2); double calc_distance(int x1,int y1,int x2,int y2); double calc_mean(int n,double* a); double calc_sd(int n,double* a); void standalize_data(int n,double* a); void normalize_data(int n,double* a); //----------------------------------------------------------------- // 表色系の変換 //----------------------------------------------------------------- BYTE rgb2gray(BYTE r,BYTE g,BYTE b); void rgb2yuv(BYTE r,BYTE g,BYTE b,BYTE &y,BYTE &u,BYTE &v); BYTE rgb2y(BYTE r,BYTE g,BYTE b); BYTE rgb2u(BYTE r,BYTE g,BYTE b); BYTE rgb2v(BYTE r,BYTE g,BYTE b); void rgb2rth(BYTE r,BYTE g,BYTE b,BYTE &rho,BYTE &th); BYTE rgb2rho(BYTE r,BYTE g,BYTE b); BYTE rgb2theta(BYTE r,BYTE g,BYTE b); //----------------------------------------------------------------- // 描画関数 //----------------------------------------------------------------- void draw_circle(LPBYTE oBuf,POINT cp,int radius); void draw_line(LPBYTE oBuf,POINT p1,POINT p2,int col=iWHITE); void draw_line(LPBYTE oBuf,int x1,int y1,int x2,int y2,int col=iWHITE); void c_draw_line(LPBYTE oBuf,int x1,int y1,int x2,int y2); void c_draw_line(LPBYTE oBuf,int x1,int y1,int x2,int y2,CPIXEL col); int croslnxc(int x1,int y1,int x2,int y2,int xc,int *yc); int croslnyc(int x1,int y1,int x2,int y2,int yc,int *xc); int scrossln(int* x1,int* y1,int* x2,int* y2); void mark_template_area(LPBYTE inBuf,POINT tp,int txsize,int tysize); //----------------------------------------------------------------- // 画像処理関数 //----------------------------------------------------------------- void make_histogram(LPBYTE inBuf); void c_make_histogram(LPBYTE inBuf); void GrayToColor(LPBYTE iGray,LPBYTE iColor); void RGBToColor(LPBYTE icol,LPBYTE iR,LPBYTE iG,LPBYTE iB); void toGray(LPBYTE inBuf,int csel=COLOR_GRAY); void toGray(); LPBYTE GetGray(int csel=COLOR_GRAY); LPBYTE GetColor(); //----------------------------------------------------------------- // 画像の拡大・縮小 //----------------------------------------------------------------- void affine_transform(LPBYTE inBuf,int intp_opt, double zx,double zy, double deg,double px,double py); void c_affine_transform(LPBYTE inBuf,int intp_opt, double zx,double zy, double deg,double px,double py); BYTE image_interpolation(LPBYTE ib,int intp_opt, double x,double y,int xc,int yc); CPIXEL c_image_interpolation(LPBYTE icb,int intp_opt, double x,double y,int xc,int yc); void nn_scale(LPBYTE image_in,double zx,double zy); void linear_scale(LPBYTE inBuf,double zx,double zy); void bcc_scale(LPBYTE inBuf,double zx,double zy); void sqm_scale(LPBYTE inBuf,double zx,double zy); void c_sqm_scale(LPBYTE inBuf,double zx,double zy); LPBYTE scale_large(LPBYTE inb,double zx,double zy); //----------------------------------------------------------------- // 一般 //----------------------------------------------------------------- void IPfunc_OR(LPBYTE iDst,LPBYTE iAdd); void IPfunc_median(LPBYTE inBuf); BYTE median(BYTE c[9]); void toDither(LPBYTE inBuf); void linear_transform(LPBYTE inBuf); void reduce_color(LPBYTE inBuf,int iLevel); void c_reduce_color(LPBYTE inBuf,int iLevel); void quantize(LPBYTE inBuf,int bit); void c_quantize(LPBYTE inBuf,int bit); void spacial_filtering(LPBYTE inBuf,int iFlt[9],double iMag); void make_error_difusion_image(LPBYTE inBuf); void make_histogram_image(LPBYTE inBuf); void draw_3D_graph(LPBYTE inBuf,int plot_step=5,double plot_ratio=1.0); //----------------------------------------------------------------- #endif // __INCLUDE_IPCOMMON_H__