File indexing completed on 2024-12-22 04:04:10
0001 /* Copyright (C) 2001-2019 Peter Selinger. 0002 This file is part of Potrace. It is free software and it is covered 0003 by the GNU General Public License. See the file COPYING for details. */ 0004 0005 #ifndef CURVE_H 0006 #define CURVE_H 0007 0008 #include "auxiliary.h" 0009 0010 /* vertex is c[1] for tag=POTRACE_CORNER, and the intersection of 0011 .c[-1][2]..c[0] and c[1]..c[2] for tag=POTRACE_CURVETO. alpha is only 0012 defined for tag=POTRACE_CURVETO and is the alpha parameter of the curve: 0013 .c[-1][2]..c[0] = alpha*(.c[-1][2]..vertex), and 0014 c[2]..c[1] = alpha*(c[2]..vertex). 0015 Beta is so that (.beta[i])[.vertex[i],.vertex[i+1]] = .c[i][2]. 0016 */ 0017 0018 struct privcurve_s { 0019 int n; /* number of segments */ 0020 int *tag; /* tag[n]: POTRACE_CORNER or POTRACE_CURVETO */ 0021 dpoint_t (*c)[3]; /* c[n][i]: control points. 0022 c[n][0] is unused for tag[n]=POTRACE_CORNER */ 0023 /* the remainder of this structure is special to privcurve, and is 0024 used in EPS debug output and special EPS "short coding". These 0025 fields are valid only if "alphacurve" is set. */ 0026 int alphacurve; /* have the following fields been initialized? */ 0027 dpoint_t *vertex; /* for POTRACE_CORNER, this equals c[1] */ 0028 double *alpha; /* only for POTRACE_CURVETO */ 0029 double *alpha0; /* "uncropped" alpha parameter - for debug output only */ 0030 double *beta; 0031 }; 0032 typedef struct privcurve_s privcurve_t; 0033 0034 struct sums_s { 0035 double x; 0036 double y; 0037 double x2; 0038 double xy; 0039 double y2; 0040 }; 0041 typedef struct sums_s sums_t; 0042 0043 /* the path structure is filled in with information about a given path 0044 as it is accumulated and passed through the different stages of the 0045 Potrace algorithm. Backends only need to read the fcurve and fm 0046 fields of this data structure, but debugging backends may read 0047 other fields. */ 0048 struct potrace_privpath_s { 0049 int len; 0050 point_t *pt; /* pt[len]: path as extracted from bitmap */ 0051 int *lon; /* lon[len]: (i,lon[i]) = longest straight line from i */ 0052 0053 int x0, y0; /* origin for sums */ 0054 sums_t *sums; /* sums[len+1]: cache for fast summing */ 0055 0056 int m; /* length of optimal polygon */ 0057 int *po; /* po[m]: optimal polygon */ 0058 0059 privcurve_t curve; /* curve[m]: array of curve elements */ 0060 privcurve_t ocurve; /* ocurve[om]: array of curve elements */ 0061 privcurve_t *fcurve; /* final curve: this points to either curve or 0062 ocurve. Do not free this separately. */ 0063 }; 0064 typedef struct potrace_privpath_s potrace_privpath_t; 0065 0066 /* shorter names */ 0067 typedef potrace_privpath_t privpath_t; 0068 typedef potrace_path_t path_t; 0069 0070 path_t *path_new(void); 0071 void path_free(path_t *p); 0072 void pathlist_free(path_t *plist); 0073 int privcurve_init(privcurve_t *curve, int n); 0074 void privcurve_to_curve(privcurve_t *pc, potrace_curve_t *c); 0075 0076 #endif /* CURVE_H */ 0077