src/lib/sketchy/SketchyImage.c
//
// helper method called by :
// 1) SketchyImage_avgDarknessForLine returns the average darkness for pixels under a line
// 2) SketchyImage_clearDarknessForLine clears the darkness for pixels under the line, returns 0
//
helper method called by :
1) SketchyImage_avgDarknessForLine returns the average darkness for pixels under a line
2) SketchyImage_clearDarknessForLine clears the darkness for pixels under the line, returns 0
helper method called by : 1 ) SketchyImage_avgDarknessForLine returns the average darkness for pixels under a line 2 ) SketchyImage_clearDarknessForLine clears the darkness for pixels under the line returns 0
float SketchyImage_darknessHelperForLine(SketchyImage *obj, float x1, float y1, float x2, float y2,LineDarknessMode mode){
    int kernelSize = obj->nibsize;
    if(kernelSize%2 == 0){
        kernelSize = kernelSize - 1;
    }
    int xpol = (x1-x2) < 0;
    int ypol = (y1-y2) < 0;
    if(xpol == 0){
        xpol = -1;
    }
    if(ypol == 0){
        ypol = -1;
    }
    float xd = fabs(x1-x2);
    float yd = fabs(y1-y2);
    float slope = (x1-x2)/(y1-y2);
    float totaldarkness = 0;
    float avg;
    if(xd > yd){
        int i;
        int cx = (int)x1;
        int cy = (int)y1;
        for(i=0;i<xd;i++){
            if(mode == lineDarknessModeAvg){
                int darkness = SketchyImage_kernelValueByXY(obj,(int)floor(cx),(int)floor(cy),false,kernelSize);
                totaldarkness = totaldarkness + darkness;
            }else{
                SketchyImage_kernelValueByXY(obj,cx,cy,true,kernelSize);
            }
            cx += xpol;
            cy = y1 + i/slope * xpol;
        }
        avg = totaldarkness/xd; 
    }else{
        int i;
        int cx = (int)x1;
        int cy = (int)y1;
        for(i=0;i<yd;i++){
            if(mode == lineDarknessModeAvg){
                int darkness = SketchyImage_kernelValueByXY(obj,cx,cy,false,kernelSize);
                totaldarkness = totaldarkness + darkness;
            }else{
                SketchyImage_kernelValueByXY(obj,cx,cy,true,kernelSize);
            }
            cy += ypol;
            cx = x1 + i*slope * ypol;
        }
        avg = totaldarkness/yd; 
    }
    return avg;
}
float SketchyImage_darknessHelperForLine ( SketchyImage * obj , float x1 , float y1 , float x2 , float y2 , LineDarknessMode mode ) { int kernelSize = obj -> nibsize ; if ( kernelSize % 2 == 0 ) { kernelSize = kernelSize - 1 ; } int xpol = ( x1 - x2 ) < 0 ; int ypol = ( y1 - y2 ) < 0 ; if ( xpol == 0 ) { xpol = -1 ; } if ( ypol == 0 ) { ypol = -1 ; } float xd = fabs ( x1 - x2 ) ; float yd = fabs ( y1 - y2 ) ; float slope = ( x1 - x2 ) / ( y1 - y2 ) ; float totaldarkness = 0 ; float avg ; if ( xd > yd ) { int i ; int cx = ( int ) x1 ; int cy = ( int ) y1 ; for ( i = 0 ; i < xd ; i ++ ) { if ( mode == lineDarknessModeAvg ) { int darkness = SketchyImage_kernelValueByXY ( obj , ( int ) floor ( cx ) , ( int ) floor ( cy ) , false , kernelSize ) ; totaldarkness = totaldarkness + darkness ; } else { SketchyImage_kernelValueByXY ( obj , cx , cy , true , kernelSize ) ; } cx += xpol ; cy = y1 + i / slope * xpol ; } avg = totaldarkness / xd ; } else { int i ; int cx = ( int ) x1 ; int cy = ( int ) y1 ; for ( i = 0 ; i < yd ; i ++ ) { if ( mode == lineDarknessModeAvg ) { int darkness = SketchyImage_kernelValueByXY ( obj , cx , cy , false , kernelSize ) ; totaldarkness = totaldarkness + darkness ; } else { SketchyImage_kernelValueByXY ( obj , cx , cy , true , kernelSize ) ; } cy += ypol ; cx = x1 + i * slope * ypol ; } avg = totaldarkness / yd ; } return avg ; }
helper method called by :
1) SketchyImage_avgDarknessForLine returns the average darkness for pixels under a line
2) SketchyImage_clearDarknessForLine clears the darkness for pixels under the line, returns 0
helper method called by : 1 ) SketchyImage_avgDarknessForLine returns the average darkness for pixels under a line 2 ) SketchyImage_clearDarknessForLine clears the darkness for pixels under the line returns 0