00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <math.h>
00020 #include "proto2D.h"
00021
00046 short breshenham(imau1 *image,short x1, short y1, short x2,short y2,short intensity)
00047
00048 {
00049 short switch1;
00050 short inx1, inxy;
00051 short stopX;
00052 short diffX, diffY, helpdiff;
00053 short x,y,flag=0;
00054
00055
00056 diffX=x2-x1;
00057 diffY=y2-y1;
00058 if (fabs(diffY)>fabs(diffX)){
00059 flag=1;
00060 x=y1;
00061 y=x1;
00062 stopX=y2;
00063 helpdiff=diffX;
00064 diffX=diffY;
00065 diffY=helpdiff;
00066 }
00067 else{
00068 flag=0;
00069 x=x1;
00070 y=y1;
00071 stopX=x2;
00072 }
00073 switch1=2*fabs(diffY)-fabs(diffX);
00074 inx1=2*fabs(diffY);
00075 inxy=2*(fabs(diffY)-fabs(diffX));
00076
00077
00078 while (x!=stopX) {
00079 if (flag==0) {
00080 image->p[y][x]=intensity;
00081 }
00082 else{
00083 image->p[x][y]=intensity;
00084 }
00085 if (diffX<0)
00086 x--;
00087 else
00088 x++;
00089 if (switch1>0){
00090 if (diffY<0)
00091 y--;
00092 else
00093 y++;
00094 switch1+=inxy;
00095 }
00096 else
00097 switch1+=inx1;
00098 }
00099 image->p[y2][x2]=intensity;
00100 return 0;
00101 }