原型:extern void *memcpy(void *dest, void *src, unsigned int count); 用法:#include <string.h> 功能:由src所指内存区域复制count个字节到dest所指内存区域。 说明:src和dest所指内存区域不能重叠,函数返回指向dest的指针。 举例: // memcpy.c #include <syslib.h> #include <string.h> main() { char *s="Golden Global View"; char d[20]; clrscr(); memcpy(d,s,strlen(s)); d[strlen(s)]=0; printf("%s",d); getchar()(); return 0; } 相关函数:memccpy,memmove,strcpys
内部实现
void* mymemcpy(void* dest, void* source, size_t count)
{
char *ret = (char *)dest;
char *dest_t = ret;
char *source_t = (char *)source;
while (count--){
*dest_t++ = *source_t++;
}
return ret;
}
易错点:
void* memcpy(void* dest, void* source, size_t count)
{
void* ret = dest;
//copy from lower address to higher address
while (count--)
*dest++ = *source++; //不知道两个指针的类型,不可以这样自加。
return ret;
}
函数准备好了,下面开始实现高斯
PIXTYPE * Gauss(PIXTYPE * s,int halfsize)
{
}Raw2D Raw2D::guassConv(Raw2D *raw2d,int halfsize) { int i=0,N=5,j=0,sum,m,n,width,length,weight,total; int delta; int g[25] ={}; PIXTYPE * s=raw2d->gety(); width=getXsize(); length=getYsize(); for (i=1;i<=width;i++) { for (j=1;j<=length;j++) { int index=0; for(int m=i-halfsize; m<i+halfsize; m++) { for(int n=j-halfsize; j<j+halfsize; j++) { weight=g[index++]=exp((float)-(m^2+n^2)/(2*delta^2)); total+=weight; sum += weight*s[m*width+n]; } } sum /=total; if(sum>255) sum=255; s[i*width+j]=sum; // PIXTYPE *p=raw2d->gety(); } } raw2d=new Raw2D(width,length,s); return *raw2d; }