#include "c64cfg.h"
#include "mean5x5.h"
void roberts(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows)
{
int i;
Int32 temp,temp0,temp1,temp3,temp5; //模板元素定义
for( i=cols; i<cols*rows-cols; i++ ) //区域模板运算
{
temp1 = (*(inputbuffer16+i-cols-1))&0xff00;
temp3 = (*(inputbuffer16+i-cols+1))&0xff00;
temp5 = (*(inputbuffer16+i))&0xff00;
temp = -temp3 + temp5;
temp0 = -temp1 +temp5;
temp=abs(temp); //列梯度
temp0=abs(temp0); //行梯度
temp=temp+temp0;
if(temp > 0xff00)
*(Uint16 *)(outputbuffer16+i) = 0xff80;
else
*(Uint16 *)(outputbuffer16+i) = (((Uint16)temp)&0xff00) + 0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16-cols+i);
}
//add code here
void prewitt(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows)
{
int i;
Int32 temp,temp0,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9; //模板元素定义
for(i=cols;i<cols*rows-cols;i++) //区域模板运算
{
temp1=(*(inputbuffer16+i-cols-1))&0xff00;
temp2=(*(inputbuffer16+i-cols))&0xff00;
temp3=(*(inputbuffer16+i-cols+1))&0xff00;
temp4=(*(inputbuffer16+i-1))&0xff00;
temp6=(*(inputbuffer16+i+1))&0xff00;
temp7=(*(inputbuffer16+i+cols-1))&0xff00;
temp8=(*(inputbuffer16+i+cols))&0xff00;
temp9=(*(inputbuffer16+i+cols+1))&0xff00;
temp=temp1+temp2+temp3-temp7-temp8-temp9; //列梯度
temp0=-temp1-temp4-temp7+temp3+temp6+temp9; //行梯度
temp=abs(temp);
temp0=abs(temp0);
temp=temp+temp0;
if(temp>0xff00)
*(Uint16 *)(outputbuffer16+i)=0xff80;
else
*(Uint16 *)(outputbuffer16+i)=(((Uint16)temp)&0xff00)+0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16+i)=*((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16+i)=*((Uint16 *)outputbuffer16-cols+i);
}
//prewitt梯度方向罗盘梯度
//东H1
void h1prewitt(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows) //模板元素定义
{
int i;
Int32 temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9;
for( i=cols; i<cols*rows-cols; i++ ) //区域模板运算
{
temp1 = (*(inputbuffer16+i-cols-1))&0xff00;
temp2 = (*(inputbuffer16+i-cols))&0xff00;
temp3 = (*(inputbuffer16+i-cols+1))&0xff00;
temp4 = (*(inputbuffer16+i-1 ))&0xff00;
temp6 = (*(inputbuffer16+i+1 ))&0xff00;
temp5 = (*(inputbuffer16+i))&0xff00;
temp7 = (*(inputbuffer16+i+cols-1))&0xff00;
temp8 = (*(inputbuffer16+i+cols))&0xff00;
temp9 = (*(inputbuffer16+i+cols+1))&0xff00;
temp = temp1 + temp2 - temp3 +temp4-(temp5<<1) - temp6+temp7+temp8 - temp9;
temp=abs(temp);
if(temp > 0xff00)
*(Uint16 *)(outputbuffer16+i) = 0xff80;
else
*(Uint16 *)(outputbuffer16+i) = (((Uint16)temp)&0xff00) + 0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16-cols+i);
}
//东北H2
void h2prewitt(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows) //模板元素定义
{
int i;
Int32 temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9;
for( i=cols; i<cols*rows-cols; i++ ) //区域模板运算
{
temp1 = (*(inputbuffer16+i-cols-1))&0xff00;
temp2 = (*(inputbuffer16+i-cols))&0xff00;
temp3 = (*(inputbuffer16+i-cols+1))&0xff00;
temp4 = (*(inputbuffer16+i-1 ))&0xff00;
temp6 = (*(inputbuffer16+i+1 ))&0xff00;
temp5 = (*(inputbuffer16+i))&0xff00;
temp7 = (*(inputbuffer16+i+cols-1))&0xff00;
temp8 = (*(inputbuffer16+i+cols))&0xff00;
temp9 = (*(inputbuffer16+i+cols+1))&0xff00;
temp = temp1 - temp2 - temp3 +temp4-(temp5<<1) - temp6+temp7+temp8 + temp9;
temp=abs(temp);
if(temp > 0xff00)
*(Uint16 *)(outputbuffer16+i) = 0xff80;
else
*(Uint16 *)(outputbuffer16+i) = (((Uint16)temp)&0xff00) + 0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16-cols+i);
}
//北H3
void h3prewitt(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows) //模板元素定义
{
int i;
Int32 temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9;
for( i=cols; i<cols*rows-cols; i++ ) //区域模板运算
{
temp1 = (*(inputbuffer16+i-cols-1))&0xff00;
temp2 = (*(inputbuffer16+i-cols))&0xff00;
temp3 = (*(inputbuffer16+i-cols+1))&0xff00;
temp4 = (*(inputbuffer16+i-1 ))&0xff00;
temp6 = (*(inputbuffer16+i+1 ))&0xff00;
temp5 = (*(inputbuffer16+i))&0xff00;
temp7 = (*(inputbuffer16+i+cols-1))&0xff00;
temp8 = (*(inputbuffer16+i+cols))&0xff00;
temp9 = (*(inputbuffer16+i+cols+1))&0xff00;
temp = - temp1 - temp2 - temp3 + temp4 -(temp5<<1) + temp6 + temp7 + temp8 + temp9;
temp=abs(temp);
if(temp > 0xff00)
*(Uint16 *)(outputbuffer16+i) = 0xff80;
else
*(Uint16 *)(outputbuffer16+i) = (((Uint16)temp)&0xff00) + 0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16-cols+i);
}
//西北H4
void h4prewitt(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows) //模板元素定义
{
int i;
Int32 temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9;
for( i=cols; i<cols*rows-cols; i++ ) //区域模板运算
{
temp1 = (*(inputbuffer16+i-cols-1))&0xff00;
temp2 = (*(inputbuffer16+i-cols))&0xff00;
temp3 = (*(inputbuffer16+i-cols+1))&0xff00;
temp4 = (*(inputbuffer16+i-1 ))&0xff00;
temp6 = (*(inputbuffer16+i+1 ))&0xff00;
temp5 = (*(inputbuffer16+i))&0xff00;
temp7 = (*(inputbuffer16+i+cols-1))&0xff00;
temp8 = (*(inputbuffer16+i+cols))&0xff00;
temp9 = (*(inputbuffer16+i+cols+1))&0xff00;
temp = - temp1 - temp2 + temp3 - temp4 - (temp5<<1) + temp6 + temp7 + temp8 + temp9;
temp=abs(temp);
if(temp > 0xff00)
*(Uint16 *)(outputbuffer16+i) = 0xff80;
else
*(Uint16 *)(outputbuffer16+i) = (((Uint16)temp)&0xff00) + 0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16-cols+i);
}
//西H5
void h5prewitt(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows) //模板元素定义
{
int i;
Int32 temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9;
for( i=cols; i<cols*rows-cols; i++ ) //区域模板运算
{
temp1 = (*(inputbuffer16+i-cols-1))&0xff00;
temp2 = (*(inputbuffer16+i-cols))&0xff00;
temp3 = (*(inputbuffer16+i-cols+1))&0xff00;
temp4 = (*(inputbuffer16+i-1 ))&0xff00;
temp6 = (*(inputbuffer16+i+1 ))&0xff00;
temp5 = (*(inputbuffer16+i))&0xff00;
temp7 = (*(inputbuffer16+i+cols-1))&0xff00;
temp8 = (*(inputbuffer16+i+cols))&0xff00;
temp9 = (*(inputbuffer16+i+cols+1))&0xff00;
temp = - temp1 + temp2 + temp3 - temp4 - (temp5<<1) + temp6 - temp7 + temp8 + temp9;
temp=abs(temp);
if(temp > 0xff00)
*(Uint16 *)(outputbuffer16+i) = 0xff80;
else
*(Uint16 *)(outputbuffer16+i) = (((Uint16)temp)&0xff00) + 0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)o