static int DrawMarkers(Engine *engine, long n, const GpReal *px, const GpReal *py) { PSEngine *psEngine= (PSEngine *)engine; GpXYMap *map= &engine->map; long maxPoints= 4050, nPoints; int type, markEnd= 0; GpPoint *points; int size; char typeString[8]; if (n<1 || gistA.m.type<=0) return 0; if (CheckClip(psEngine)) return 1; if (SetupColor(psEngine, gistA.m.color) || SetupFont(psEngine, gistA.m.size*DEFAULT_MARKER_SIZE)) return 1; if (psEngine->curClip) size= 0; else size= (int)(psEngine->curHeight*NDC_TO_PS); if (gistA.m.type>32 && gistA.m.type<127) { char *now= typeString; *now++= '('; if (gistA.m.type=='(' || gistA.m.type==')' || gistA.m.type=='\\') *now++= '\\'; *now++= type= gistA.m.type; *now++= ')'; *now++= '\0'; } else { if (gistA.m.type<0 || gistA.m.type>M_CROSS) type= M_ASTERISK; else type= gistA.m.type; sprintf(typeString, "%d", type-1); } if (n>90) { long nLines= (n-1)/9 + 1; /* 9 points is 72 characters */ if (psEngine->nchars && PutLine(psEngine)) return 1; sprintf(line, "%%%%BeginData: %ld ASCII Lines", nLines+1); if (Append(psEngine, line) || PutLine(psEngine)) return 1; markEnd= 1; } if (Append(psEngine, typeString)) return 1; /* "(A)" or "1", e.g. */ sprintf(line, type<32? "%ld MS" : "%ld M", n); if (Append(psEngine, line) || PutLine(psEngine)) return 1; while ((nPoints= GpIntPoints(map, maxPoints, n, px, py, &points))) { if (PutPoints(psEngine, points, nPoints, size)) return 1; if (n==nPoints) break; n-= nPoints; px+= nPoints; py+= nPoints; } if (markEnd) { if (Append(psEngine, "%%EndData") || PutLine(psEngine)) return 1; } return 0; }
static int DrawLines(Engine *engine, long n, const GpReal *px, const GpReal *py, int closed, int smooth) { PSEngine *psEngine= (PSEngine *)engine; GpXYMap *map= &engine->map; long maxPoints= 4050, nPoints; long np= n + (closed?1:0); int firstPass= 1, markEnd= 0; GpPoint firstPoint, *points; int size; if (CheckClip(psEngine)) return 1; if (n<1) return 0; if (SetupLine(psEngine, &gistA.l)) return 1; if (psEngine->curClip) size= 0; else size= (int)(psEngine->curWidth*0.5*DEFAULT_PS_WIDTH); if (np>90) { long nLines= (np-1)/9 + 1; /* 9 points is 72 characters */ if (psEngine->nchars && PutLine(psEngine)) return 1; sprintf(line, "%%%%BeginData: %ld ASCII Lines", nLines+1); if (Append(psEngine, line) || PutLine(psEngine)) return 1; markEnd= 1; } sprintf(line, smooth? "%ld LS" : "%ld L", np); if (Append(psEngine, line) || PutLine(psEngine)) return 1; while ((nPoints= GpIntPoints(map, maxPoints, n, px, py, &points))) { if (closed) { if (firstPass) { firstPoint= points[0]; firstPass= 0; } if (n==nPoints) { n++; points[nPoints++]= firstPoint; } } if (PutPoints(psEngine, points, nPoints, size)) return 1; if (n==nPoints) break; n-= nPoints; px+= nPoints; py+= nPoints; } if (markEnd) { if (Append(psEngine, "%%EndData") || PutLine(psEngine)) return 1; } return 0; }
static int DrawFill(Engine *engine, long n, const GpReal *px, const GpReal *py) { PSEngine *psEngine= (PSEngine *)engine; GpXYMap *map= &engine->map; long maxPoints= 4050, nPoints; int markEnd= 0; GpPoint *points; int value= 0; /* For now, only FillSolid style supported */ if (n<1) return 0; if (CheckClip(psEngine) || SetupColor(psEngine, gistA.f.color)) return 1; if (n>90) { long nLines= (n-1)/9 + 1; /* 9 points is 72 characters */ if (psEngine->nchars && PutLine(psEngine)) return 1; sprintf(line, "%%%%BeginData: %ld ASCII Lines", nLines+1); if (Append(psEngine, line) || PutLine(psEngine)) return 1; markEnd= 1; } if (gistA.e.type==L_NONE) sprintf(line, "%ld F", n); else sprintf(line, "%ld E", n); if (Append(psEngine, line) || PutLine(psEngine)) return 1; while ((nPoints= GpIntPoints(map, maxPoints, n, px, py, &points))) { if (PutPoints(psEngine, points, nPoints, 0)) return 1; if (n==nPoints) break; n-= nPoints; px+= nPoints; py+= nPoints; value= 1; /* Polygons with >4050 sides won't be filled correctly */ } if (gistA.e.type!=L_NONE) { /* setup for edge (usually different color than fill), then draw it */ if (SetupLine(psEngine, &gistA.e)) return 1; if (Append(psEngine, "0 E") || PutLine(psEngine)) return 1; } if (markEnd) { if (Append(psEngine, "%%EndData") || PutLine(psEngine)) return 1; } return value; }
/**************************************************** WALhDIB() 参数: hDIB为输入的DIB句柄 返回值: 成功为TRUE;失败为FALSE 说明: 本函数实现DIB位图的快速沃尔什-哈达玛变换 ****************************************************/ BOOL WALhDIB(HDIB hDIB) { if (hDIB == NULL) return FALSE; // start wait cursor WaitCursorBegin(); HDIB hDib = NULL; HDIB hNewDib = NULL; // we only convolute 24bpp DIB, so first convert DIB to 24bpp WORD wBitCount = DIBBitCount(hDIB); if (wBitCount != 24) { hNewDib = ConvertDIBFormat(hDIB, 24, NULL); hDib = CopyHandle(hNewDib); } else { hNewDib = CopyHandle(hDIB); hDib = CopyHandle(hDIB); } if (hNewDib == NULL && hDib == NULL) { WaitCursorEnd(); return FALSE; } // process! LPBYTE lpSrcDIB = (LPBYTE)GlobalLock(hDib); LPBYTE lpDIB = (LPBYTE)GlobalLock(hNewDib); LPBYTE lpInput = FindDIBBits(lpSrcDIB); LPBYTE lpOutput = FindDIBBits(lpDIB); int nWidth = DIBWidth(lpSrcDIB); int nHeight = DIBHeight(lpSrcDIB); int w=1,h=1,wp=0,hp=0; while(w*2<=nWidth) { w*=2; wp++; } while(h*2<=nHeight) { h*=2; hp++; } int x,y; BYTE *lpPoints=new BYTE[nWidth*nHeight]; GetPoints(nWidth,nHeight,lpInput,lpPoints); double *f=new double[w*h]; double *W=new double[w*h]; for(y=0;y<h;y++) { for(x=0;x<w;x++) { f[x+y*w]=Point(x,y); } } for(y=0;y<h;y++) { WALh(f+w*y,W+w*y,wp); } for(y=0;y<h;y++) { for(x=0;x<w;x++) { f[x*h+y]=W[x+w*y]; } } for(x=0;x<w;x++) { WALh(f+x*h,W+x*h,hp); } double a; memset(lpPoints,0,nWidth*nHeight); for(y=0;y<h;y++) { for(x=0;x<w;x++) { a=fabs(W[x*h+y]*1000); if (a>255) a=255; Point(x,nHeight-y-1)=(BYTE)a; } } delete f; delete W; PutPoints(nWidth,nHeight,lpOutput,lpPoints); delete lpPoints; // recover DWORD dwSize = GlobalSize(hDib); memcpy(lpSrcDIB, lpDIB, dwSize); GlobalUnlock(hDib); GlobalUnlock(hNewDib); if (wBitCount != 24) { hNewDib = ConvertDIBFormat(hDib, wBitCount, NULL); lpSrcDIB = (LPBYTE)GlobalLock(hDIB); lpDIB = (LPBYTE)GlobalLock(hNewDib); dwSize = GlobalSize(hNewDib); memcpy(lpSrcDIB, lpDIB, dwSize); GlobalUnlock(hDIB); GlobalUnlock(hNewDib); } else { lpSrcDIB = (LPBYTE)GlobalLock(hDIB); lpDIB = (LPBYTE)GlobalLock(hDib); dwSize = GlobalSize(hDib); memcpy(lpSrcDIB, lpDIB, dwSize); GlobalUnlock(hDIB); GlobalUnlock(hDib); } // cleanup GlobalFree(hDib); GlobalFree(hNewDib); // return WaitCursorEnd(); return TRUE; }
/**************************************************** FFTDIB() 参数: hDIB为输入的DIB句柄 返回值: 成功为TRUE;失败为FALSE 说明: 本函数实现DIB位图的快速傅立叶变换 ****************************************************/ BOOL FFTDIB(HDIB hDIB) { if (hDIB == NULL) return FALSE; // start wait cursor WaitCursorBegin(); HDIB hDib = NULL; HDIB hNewDib = NULL; // we only convolute 24bpp DIB, so first convert DIB to 24bpp WORD wBitCount = DIBBitCount(hDIB); if (wBitCount != 24) { hNewDib = ConvertDIBFormat(hDIB, 24, NULL); hDib = CopyHandle(hNewDib); } else { hNewDib = CopyHandle(hDIB); hDib = CopyHandle(hDIB); } if (hNewDib == NULL && hDib == NULL) { WaitCursorEnd(); return FALSE; } // process! LPBYTE lpSrcDIB = (LPBYTE)GlobalLock(hDib); LPBYTE lpDIB = (LPBYTE)GlobalLock(hNewDib); LPBYTE lpInput = FindDIBBits(lpSrcDIB); LPBYTE lpOutput = FindDIBBits(lpDIB); int nWidth = DIBWidth(lpSrcDIB); int nHeight = DIBHeight(lpSrcDIB); int w=1,h=1,wp=0,hp=0; while(w*2<=nWidth) { w*=2; wp++; } while(h*2<=nHeight) { h*=2; hp++; } int x,y; BYTE *lpPoints=new BYTE[nWidth*nHeight]; GetPoints(nWidth,nHeight,lpInput,lpPoints); COMPLEX *TD=new COMPLEX[w*h]; COMPLEX *FD=new COMPLEX[w*h]; for(y=0;y<h;y++) { for(x=0;x<w;x++) { TD[x+w*y].re=Point(x,y); TD[x+w*y].im=0; } } for(y=0;y<h;y++) { FFT(&TD[w*y],&FD[w*y],wp); } for(y=0;y<h;y++) { for(x=0;x<w;x++) { TD[y+h*x]=FD[x+w*y]; // TD[x+w*y]=FD[x*h+y]; } } for(x=0;x<w;x++) { FFT(&TD[x*h],&FD[x*h],hp); } memset(lpPoints,0,nWidth*nHeight); double m; for(y=0;y<h;y++) { for(x=0;x<w;x++) { m=sqrt(FD[x*h+y].re*FD[x*h+y].re+FD[x*h+y].im*FD[x*h+y].im)/100; if (m>255) m=255; Point((x<w/2?x+w/2:x-w/2),nHeight-1-(y<h/2?y+h/2:y-h/2))=(BYTE)(m); } } delete TD; delete FD; PutPoints(nWidth,nHeight,lpOutput,lpPoints); delete lpPoints; // recover DWORD dwSize = GlobalSize(hDib); memcpy(lpSrcDIB, lpDIB, dwSize); GlobalUnlock(hDib); GlobalUnlock(hNewDib); if (wBitCount != 24) { hNewDib = ConvertDIBFormat(hDib, wBitCount, NULL); lpSrcDIB = (LPBYTE)GlobalLock(hDIB); lpDIB = (LPBYTE)GlobalLock(hNewDib); dwSize = GlobalSize(hNewDib); memcpy(lpSrcDIB, lpDIB, dwSize); GlobalUnlock(hDIB); GlobalUnlock(hNewDib); } else { lpSrcDIB = (LPBYTE)GlobalLock(hDIB); lpDIB = (LPBYTE)GlobalLock(hDib); dwSize = GlobalSize(hDib); memcpy(lpSrcDIB, lpDIB, dwSize); GlobalUnlock(hDIB); GlobalUnlock(hDib); } // cleanup GlobalFree(hDib); GlobalFree(hNewDib); // return WaitCursorEnd(); return TRUE; }