001: #ifndef __INCLUDE_IPCOMMON_H__
002: #define __INCLUDE_IPCOMMON_H__
003:
004:
005:
006: extern UINT iHeight,iWidth,iLength;
007: extern UINT iSize,biSize;
008: extern LPBYTE lpOrgBMP,lpBMP;
009: extern UINT iGHist[512];
010:
011: #ifndef M_PI
012: #define M_PI 3.14159265358979323846
013: #endif
014:
015:
016:
017: #define iWHITE 0xff
018: #define iBLACK 0
019: #define iGRAY 100
020: #define iMAX_GRAY 256
021: #define iRED 2
022: #define iGREEN 1
023: #define iBLUE 0
024:
025:
026:
027:
028: #define XY2PI(x,y,w) ((x)+(y)*w)
029:
030: #define ip_safe(x,y,w,h) (x>=0 && x<w && y>=0 && y<h)
031:
032: #define rint(x) ((x>=0)?((int)(x+0.5)):((int)(x-0.5)))
033:
034: #define deg2rad(x) ((double)x*M_PI/180.)
035:
036: #define rad2deg(x) ((double)x*180./M_PI)
037:
038: enum COLOR_DEF {
039: COLOR_R = 0, COLOR_G = 1, COLOR_B = 2,
040: COLOR_Y = 3, COLOR_U = 4, COLOR_V = 5,
041: COLOR_RHO = 6, COLOR_THETA = 7,
042: COLOR_RGB = 8
043: };
044:
045: enum INTERPOLATION {
046: INTP_NN = 0, INTP_LN = 1, INTP_BCC = 2,
047: };
048:
049: typedef struct COLOR_PIXEL {
050: BYTE r,g,b;
051: } CPIXEL;
052:
053: static POINT offset8[8] = {
054: {-1,-1},{ 0,-1},{ 1,-1},
055: {-1, 0},{ 1, 0},
056: {-1, 1},{ 0, 1},{ 1, 1}
057: };
058:
059: static POINT offset9[9] = {
060: {-1,-1},{ 0,-1},{ 1,-1},
061: {-1, 0},{ 0, 0},{ 1, 0},
062: {-1, 1},{ 0, 1},{ 1, 1}
063: };
064:
065:
066:
067: int lcm(int a,int b);
068: void init_random();
069: int random_int(int n);
070: void swapv(int c1,int c2);
071: void swap_point(POINT p1,POINT p2);
072: int colcmp(LPBYTE inb,CPIXEL c2);
073: void setcol(LPBYTE inb,CPIXEL c);
074: double calc_distance(POINT p1,POINT p2);
075: double calc_distance(int x1,int y1,int x2,int y2);
076: double calc_mean(int n,double* a);
077: double calc_sd(int n,double* a);
078: void standalize_data(int n,double* a);
079: void normalize_data(int n,double* a);
080:
081:
082:
083: BYTE rgb2gray(BYTE r,BYTE g,BYTE b);
084: void rgb2yuv(BYTE r,BYTE g,BYTE b,BYTE &y,BYTE &u,BYTE &v);
085: BYTE rgb2y(BYTE r,BYTE g,BYTE b);
086: BYTE rgb2u(BYTE r,BYTE g,BYTE b);
087: BYTE rgb2v(BYTE r,BYTE g,BYTE b);
088: void rgb2rth(BYTE r,BYTE g,BYTE b,BYTE &rho,BYTE &th);
089: BYTE rgb2rho(BYTE r,BYTE g,BYTE b);
090: BYTE rgb2theta(BYTE r,BYTE g,BYTE b);
091:
092:
093:
094: void draw_circle(LPBYTE oBuf,POINT cp,int radius);
095: void draw_line(LPBYTE oBuf,POINT p1,POINT p2,int col=iWHITE);
096: void draw_line(LPBYTE oBuf,int x1,int y1,int x2,int y2,int col=iWHITE);
097: int croslnxc(int x1,int y1,int x2,int y2,int xc,int *yc);
098: int croslnyc(int x1,int y1,int x2,int y2,int yc,int *xc);
099: int scrossln(int* x1,int* y1,int* x2,int* y2);
100: void mark_template_area(LPBYTE inBuf,POINT tp,int txsize,int tysize);
101:
102:
103:
104: void make_histogram(LPBYTE inBuf);
105: void GrayToColor(LPBYTE iGray,LPBYTE iColor);
106: void toGray(LPBYTE inBuf);
107: void toCGray(LPBYTE inBuf,int csel);
108: void toGray();
109: LPBYTE GetGray();
110: LPBYTE GetColor(int csel);
111: void affine_transform(LPBYTE inBuf,int intp_opt,
112: double zx,double zy,
113: double deg,double px,double py);
114: void c_affine_transform(LPBYTE inBuf,int intp_opt,
115: double zx,double zy,
116: double deg,double px,double py);
117: BYTE image_interpolation(LPBYTE ib,int intp_opt,
118: double x,double y,int xc,int yc);
119: CPIXEL c_image_interpolation(LPBYTE icb,int intp_opt,
120: double x,double y,int xc,int yc);
121: void nn_scale(LPBYTE image_in,double zx,double zy);
122: void linear_scale(LPBYTE inBuf,double zx,double zy);
123: void bcc_scale(LPBYTE inBuf,double zx,double zy);
124: void sqm_scale(LPBYTE inBuf,double zx,double zy);
125: void c_sqm_scale(LPBYTE inBuf,double zx,double zy);
126: void IPfunc_OR(LPBYTE iDst,LPBYTE iAdd);
127: void IPfunc_median(LPBYTE inBuf);
128: BYTE median(BYTE c[9]);
129: void toDither(LPBYTE inBuf);
130: void linear_transform(LPBYTE inBuf);
131: void change_graylevel(LPBYTE inBuf,int iLevel);
132: void spacial_filtering(LPBYTE inBuf,int iFlt[9],double iMag);
133: void make_error_difusion_image(LPBYTE inBuf);
134: void make_histogram_image(LPBYTE inBuf);
135: void draw_3D_graph(LPBYTE inBuf,int plot_step=5,double plot_ratio=1.0);
136:
137:
138: #endif