/* * edge2 -- Sobel operator edge filter */ #include "filter.cc" int ihypot(int, int); void filter(unsigned char *l0, unsigned char *l1, unsigned char *l2, int nchan, int npix){ unsigned char *op=outline; int v; npix*=nchan; if(npix==0) return; do{ v=ihypot((l0[-nchan]+2*l0[0]+l0[nchan]) -(l2[-nchan]+2*l2[0]+l2[nchan]), (l0[-nchan]+2*l1[-nchan]+l2[-nchan]) -(l0[ nchan]+2*l1[ nchan]+l2[ nchan])); *op++=v<0?0:v<256?v:255; l0++; l1++; l2++; }while(--npix!=0); } #define NTABLE 10 #define NSHIFT 21 /* NSHIFT+NTABLE==# bits in a positive int */ static int table[1<>=2,x<<=1); */ x=table[a>>NSHIFT]; while((y=(a/x+x)>>1)