potracelib.h 4.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
/* Copyright (C) 2001-2007 Peter Selinger.
 *  This file is part of Potrace. It is free software and it is covered
 *  by the GNU General Public License. See the file COPYING for details. */

#ifndef POTRACELIB_H
#define POTRACELIB_H

/* this file defines the API for the core Potrace library. For a more
 *  detailed description of the API, see doc/potracelib.txt */

/* ---------------------------------------------------------------------- */
/* tracing parameters */

/* turn policies */
#define POTRACE_TURNPOLICY_BLACK    0
#define POTRACE_TURNPOLICY_WHITE    1
#define POTRACE_TURNPOLICY_LEFT     2
#define POTRACE_TURNPOLICY_RIGHT    3
#define POTRACE_TURNPOLICY_MINORITY 4
#define POTRACE_TURNPOLICY_MAJORITY 5
#define POTRACE_TURNPOLICY_RANDOM   6

/* structure to hold progress bar callback data */
struct potrace_progress_s
{
    void   (* callback)( double progress, void* privdata ); /* callback fn */
    void*  data;                                            /* callback function's private data */
    double min, max;                                        /* desired range of progress, e.g. 0.0 to 1.0 */
    double epsilon;                                         /* granularity: can skip smaller increments */
};
typedef struct potrace_progress_s potrace_progress_t;

/* structure to hold tracing parameters */
struct potrace_param_s
{
    int                turdsize;        /* area of largest path to be ignored */
    int                turnpolicy;      /* resolves ambiguous turns in path decomposition */
    double             alphamax;        /* corner threshold */
    int                opticurve;       /* use curve optimization? */
    double             opttolerance;    /* curve optimization tolerance */
    potrace_progress_t progress;        /* progress callback function */
};
typedef struct potrace_param_s potrace_param_t;

/* ---------------------------------------------------------------------- */
/* bitmaps */

/* native word size */
typedef unsigned long potrace_word;

/* Internal bitmap format. The n-th scanline starts at scanline(n) =
 *  (map + n*dy). Raster data is stored as a sequence of potrace_words
 *  (NOT bytes). The leftmost bit of scanline n is the most significant
 *  bit of scanline(n)[0]. */
struct potrace_bitmap_s
{
    int           w, h;     /* width and height, in pixels */
    int           dy;       /* words per scanline (not bytes) */
    potrace_word* map;      /* raw data, dy*h words */
};
typedef struct potrace_bitmap_s potrace_bitmap_t;

/* ---------------------------------------------------------------------- */
/* curves */

/* point */
struct potrace_dpoint_s
{
    double x, y;
};
typedef struct potrace_dpoint_s potrace_dpoint_t;

/* segment tags */
#define POTRACE_CURVETO 1
#define POTRACE_CORNER  2

/* closed curve segment */
struct potrace_curve_s
{
80 81 82 83 84
    int  n;                 // number of segments
    int* tag;               // tag[n]: POTRACE_CURVETO or POTRACE_CORNER
    potrace_dpoint_t( * c )[3]; /* c[n][3]: control points.
                                 *  c[n][0] is unused for tag[n]=POTRACE_CORNER
                                 */
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
};
typedef struct potrace_curve_s potrace_curve_t;

/* Linked list of signed curve segments. Also carries a tree structure. */
struct potrace_path_s
{
    int             area;               /* area of the bitmap path */
    int             sign;               /* '+' or '-', depending on orientation */
    potrace_curve_t curve;              /* this path's vector data */

    struct potrace_path_s* next;        /* linked list structure */

    struct potrace_path_s* childlist;   /* tree structure */
    struct potrace_path_s* sibling;     /* tree structure */

    struct potrace_privpath_s* priv;    /* private state */
};
typedef struct potrace_path_s potrace_path_t;

/* ---------------------------------------------------------------------- */
/* Potrace state */

#define POTRACE_STATUS_OK         0
#define POTRACE_STATUS_INCOMPLETE 1

struct potrace_state_s
{
    int             status;
    potrace_path_t* plist;              /* vector data */

    struct potrace_privstate_s* priv;   /* private state */
};
typedef struct potrace_state_s potrace_state_t;

/* ---------------------------------------------------------------------- */
/* API functions */

/* get default parameters */
potrace_param_t* potrace_param_default( void );

/* free parameter set */
void             potrace_param_free( potrace_param_t* p );

/* trace a bitmap*/
potrace_state_t* potrace_trace( const potrace_param_t*  param,
                                const potrace_bitmap_t* bm );

/* free a Potrace state */
void             potrace_state_free( potrace_state_t* st );

/* return a static plain text version string identifying this version
 *  of potracelib */
const char*      potrace_version( void );

#endif /* POTRACELIB_H */