C# Class CsPotrace.Potrace

Datei anzeigen Open project: antimatter15/js-potrace Class Usage Examples

Public Properties

Property Type Description
alphamax double
curveoptimizing bool
opttolerance double
turdsize int

Public Methods

Method Description
BinaryToBitmap ( bool Matrix, bool IgnoreBorder ) : Bitmap

Makes a Black and White Bitmap from the Data of a Binarymatrix. Value with 'true' returns a white Pixel such with 'false' a Black pixel.

BitMapToBinary ( Bitmap b, int _treshold ) : ].bool[

Produces a binary Matrix with Dimensions b.Width+2 and b.Height +2, where the Border ( of width) in the Matrix is filled with 'true' -values. On this way we avoid a lot of boundsinequalities. For the threshold, we take the Maximum of (R,G,B ) of a Pixel at x,y. If this is less then the threshold the resultMatrix at x+1, y+1 is filled with false else with true.

potrace_trace ( bool bm, ArrayList ListOfCurveArrays ) : void

It is the main function, which yields the curveinformations related to a given binary bitmap. It fills the ArrayList ListOfCurveArrays with curvepathes. Each of this pathes is an list of connecting curves. Example:

 Call first: ArrayList ListOfCurveArrays = new ArrayList(); potrace_trace(bm, ListOfCurveArrays); Paint the result: GraphicsPath gp = new GraphicsPath(); for (int i = 0; i < ListOfCurveArrays.Count; i++) { ArrayList CurveArray = (ArrayList)ListOfCurveArrays[i]; GraphicsPath Contour=null; GraphicsPath Hole = null; GraphicsPath Current=null; for (int j = 0; j < CurveArray.Count; j++) { if (j == 0) { Contour = new GraphicsPath(); Current = Contour; } else { Hole = new GraphicsPath(); Current = Hole; } Potrace.Curve[] Curves = (Curve[])CurveArray[j]; for (int k = 0; k < Curves.Length; k++) { if (Curves[k].Kind == Potrace.CurveKind.Bezier) Current.AddBezier((float)Curves[k].A.x, (float)Curves[k].A.y, (float)Curves[k].ControlPointA.x, (float)Curves[k].ControlPoint.y, (float)Curves[k].ControlPointB.x, (float)Curves[k].ControlPointB.y, (float)Curves[k].B.x, (float)Curves[k].B.y); else Current.AddLine((float)Curves[k].A.x, (float)Curves[k].A.y, (float)Curves[k].B.x, (float)Curves[k].B.y); } if (j > 0) Contour.AddPath(Hole, false); } gp.AddPath(Contour, false); } // any Graphic g Graphics g = CreateGraphics(); // Paint the fill g.FillPath(Brushes.Black, gp); // Paint the border g.DrawPath(Pens.Red,gp); 

Private Methods

Method Description
AddCurve ( ArrayList Curves, dPoint A, dPoint ControlPointA, dPoint ControlPointB, dPoint B ) : void
FindNext ( bool Matrix, int &x, int &y ) : bool

Searches a x and a y such that source[x,y] = true and source[x+1,y] false. If this not exists, false will be returned else the result is true.

FindNext ( bool Matrix, int &x, int &y, Path P ) : bool

Searches a x and a y inside the Path P such that source[x,y] = true and source[x+1,y] false. If this not exists, false will be returned else the result is true.

GetMonotonIntervals ( iPoint Pts ) : ArrayList
PathList_to_ListOfCurveArrays ( ArrayList plistp, ArrayList ListOfCurveArrays ) : void
Xor_Path ( bool Matrix, Path P ) : void
abs ( int a ) : int
adjust_vertices ( Path pp ) : void
bestpolygon ( Path pp ) : void
bezier ( double t, dPoint p0, dPoint p1, dPoint p2, dPoint p3 ) : dPoint
bm_to_pathlist ( bool bm, ArrayList plistp ) : void

Decompose the given bitmap into paths. Returns a linked list of Path objects with the fields len, pt, area filled

calc_lon ( Path pp ) : void
calc_sums ( Path pp ) : void

Preparation: fill in the sum* fields of a path (used for later rapid summing).

cprod ( dPoint p0, dPoint p1, dPoint p2, dPoint p3 ) : double
cu ( int a ) : int
cyclic ( int a, int b, int c ) : bool
ddenom ( dPoint p0, dPoint p2 ) : double
ddist ( dPoint p, dPoint q ) : double
dorth_infty ( dPoint p0, dPoint p2 ) : iPoint
dpara ( dPoint p0, dPoint p1, dPoint p2 ) : double
findNextTrace ( bool Matrix, int &x, int &y, direction &Dir ) : void
findpath ( bool Matrix, iPoint Start ) : Path

Compute a path in the binary matrix. Start path at the point (x0,x1), which must be an upper left corner of the path. Also compute the area enclosed by the path. Return a new path_t object, or NULL on error (note that a legitimate path cannot have length 0). We omit turnpolicies and sign

floordiv ( int a, int n ) : int
getContur ( bool bm, int x, int y, ArrayList plistp ) : void
i ( ) : void
interval ( double lambda, dPoint a, dPoint b ) : dPoint
iprod ( dPoint p0, dPoint p1, dPoint p2 ) : double
iprod1 ( dPoint p0, dPoint p1, dPoint p2, dPoint p3 ) : double
max ( int a, int b ) : int
min ( int a, int b ) : int
mod ( int a, int n ) : int
opti_penalty ( Path pp, int i, int j, opti &res, double opttolerance, int convc, double areac ) : bool
opticurve ( Path pp, double opttolerance ) : void
penalty3 ( Path pp, int i, int j ) : double
pointslope ( Path pp, int i, int j, dPoint &ctr, dPoint &dir ) : void
process_path ( ArrayList plistp ) : void
quadform ( double Q, dPoint w ) : double
sign ( double x ) : int
sign ( int x ) : int
smooth ( privcurve curve, int sign, double alphamax ) : void
sq ( int a ) : int
tangent ( dPoint p0, dPoint p1, dPoint p2, dPoint p3, dPoint q0, dPoint q1 ) : double
xprod ( dPoint p1, dPoint p2 ) : double
xprod ( iPoint p1, iPoint p2 ) : int

Method Details

BinaryToBitmap() public static method

Makes a Black and White Bitmap from the Data of a Binarymatrix. Value with 'true' returns a white Pixel such with 'false' a Black pixel.
public static BinaryToBitmap ( bool Matrix, bool IgnoreBorder ) : Bitmap
Matrix bool A Binary Matrix, which have boolean values
IgnoreBorder bool If this value is set then a Border with 1 Pixel is ignored
return System.Drawing.Bitmap

BitMapToBinary() public static method

Produces a binary Matrix with Dimensions b.Width+2 and b.Height +2, where the Border ( of width) in the Matrix is filled with 'true' -values. On this way we avoid a lot of boundsinequalities. For the threshold, we take the Maximum of (R,G,B ) of a Pixel at x,y. If this is less then the threshold the resultMatrix at x+1, y+1 is filled with false else with true.
public static BitMapToBinary ( Bitmap b, int _treshold ) : ].bool[
b System.Drawing.Bitmap A Bitmap, which will be transformed to a binary Matrix
_treshold int Gives a threshold ( between 1 and 254 ) for Converting
return ].bool[

potrace_trace() public static method

It is the main function, which yields the curveinformations related to a given binary bitmap. It fills the ArrayList ListOfCurveArrays with curvepathes. Each of this pathes is an list of connecting curves. Example:
 Call first: ArrayList ListOfCurveArrays = new ArrayList(); potrace_trace(bm, ListOfCurveArrays); Paint the result: GraphicsPath gp = new GraphicsPath(); for (int i = 0; i < ListOfCurveArrays.Count; i++) { ArrayList CurveArray = (ArrayList)ListOfCurveArrays[i]; GraphicsPath Contour=null; GraphicsPath Hole = null; GraphicsPath Current=null; for (int j = 0; j < CurveArray.Count; j++) { if (j == 0) { Contour = new GraphicsPath(); Current = Contour; } else { Hole = new GraphicsPath(); Current = Hole; } Potrace.Curve[] Curves = (Curve[])CurveArray[j]; for (int k = 0; k < Curves.Length; k++) { if (Curves[k].Kind == Potrace.CurveKind.Bezier) Current.AddBezier((float)Curves[k].A.x, (float)Curves[k].A.y, (float)Curves[k].ControlPointA.x, (float)Curves[k].ControlPoint.y, (float)Curves[k].ControlPointB.x, (float)Curves[k].ControlPointB.y, (float)Curves[k].B.x, (float)Curves[k].B.y); else Current.AddLine((float)Curves[k].A.x, (float)Curves[k].A.y, (float)Curves[k].B.x, (float)Curves[k].B.y); } if (j > 0) Contour.AddPath(Hole, false); } gp.AddPath(Contour, false); } // any Graphic g Graphics g = CreateGraphics(); // Paint the fill g.FillPath(Brushes.Black, gp); // Paint the border g.DrawPath(Pens.Red,gp); 
public static potrace_trace ( bool bm, ArrayList ListOfCurveArrays ) : void
bm bool A binary bitmap, which holds the pixelinformation about the image.
ListOfCurveArrays System.Collections.ArrayList A list in which the curveinformations will be stored.
return void

Property Details

alphamax public_oe static_oe property

corner threshold
public static double alphamax
return double

curveoptimizing public_oe static_oe property

use curve optimization optimize the path p, replacing sequences of Bezier segments by a single segment when possible.
public static bool curveoptimizing
return bool

opttolerance public_oe static_oe property

curve optimization tolerance
public static double opttolerance
return double

turdsize public_oe static_oe property

area of largest path to be ignored
public static int turdsize
return int