KiCad PCB EDA Suite
decompose.h File Reference
#include "potracelib.h"
#include "progress.h"
#include "curve.h"

Go to the source code of this file.

Functions

int bm_to_pathlist (const potrace_bitmap_t *bm, path_t **plistp, const potrace_param_t *param, progress_t *progress)
 

Function Documentation

int bm_to_pathlist ( const potrace_bitmap_t bm,
path_t **  plistp,
const potrace_param_t param,
progress_t progress 
)

Definition at line 555 of file decompose.cpp.

References potrace_path_s::area, bm_clearexcess(), bm_dup(), bm_free(), BM_GET, findnext(), findpath(), potrace_bitmap_s::h, list_forall_unlink, list_insert_beforehook, path_free(), pathlist_to_tree(), progress_update(), sign(), potrace_param_s::turdsize, potrace_param_s::turnpolicy, and xor_path().

Referenced by potrace_trace().

559 {
560  int x;
561  int y;
562  path_t* p;
563  path_t* plist = NULL; /* linked list of path objects */
564  path_t** plist_hook = &plist; /* used to speed up appending to linked list */
565  potrace_bitmap_t* bm1 = NULL;
566  int sign;
567 
568  bm1 = bm_dup( bm );
569 
570  if( !bm1 )
571  {
572  goto error;
573  }
574 
575  /* be sure the byte padding on the right is set to 0, as the fast
576  * pixel search below relies on it */
577  bm_clearexcess( bm1 );
578 
579  /* iterate through components */
580  x = 0;
581  y = bm1->h - 1;
582 
583  while( findnext( bm1, &x, &y ) == 0 )
584  {
585  /* calculate the sign by looking at the original */
586  sign = BM_GET( bm, x, y ) ? '+' : '-';
587 
588  /* calculate the path */
589  p = findpath( bm1, x, y + 1, sign, param->turnpolicy );
590 
591  if( p==NULL )
592  {
593  goto error;
594  }
595 
596  /* update buffered image */
597  xor_path( bm1, p );
598 
599  /* if it's a turd, eliminate it, else append it to the list */
600  if( p->area <= param->turdsize )
601  {
602  path_free( p );
603  }
604  else
605  {
606  list_insert_beforehook( p, plist_hook );
607  }
608 
609  if( bm1->h > 0 ) /* to be sure */
610  {
611  progress_update( 1 - y / (double) bm1->h, progress );
612  }
613  }
614 
615  pathlist_to_tree( plist, bm1 );
616  bm_free( bm1 );
617  *plistp = plist;
618 
619  progress_update( 1.0, progress );
620 
621  return 0;
622 
623 error:
624  bm_free( bm1 );
625  list_forall_unlink( p, plist ) {
626  path_free( p );
627  }
628  return -1;
629 }
static void bm_free(potrace_bitmap_t *bm)
Definition: bitmap.h:49
#define list_forall_unlink(elt, list)
Definition: lists.h:166
static potrace_bitmap_t * bm_dup(const potrace_bitmap_t *bm)
Definition: bitmap.h:109
static path_t * findpath(potrace_bitmap_t *bm, int x0, int y0, int sign, int turnpolicy)
Definition: decompose.cpp:249
static void pathlist_to_tree(path_t *plist, potrace_bitmap_t *bm)
Definition: decompose.cpp:372
#define BM_GET(bm, x, y)
Definition: bitmap.h:42
static int findnext(potrace_bitmap_t *bm, int *xp, int *yp)
Definition: decompose.cpp:516
void path_free(path_t *p)
Definition: curve.cpp:58
static void bm_clearexcess(potrace_bitmap_t *bm)
Definition: decompose.cpp:56
static void xor_path(potrace_bitmap_t *bm, path_t *p)
Definition: decompose.cpp:175
static void progress_update(double d, progress_t *prog)
Definition: progress.h:29
#define list_insert_beforehook(elt, hook)
Definition: lists.h:76
int sign(T val)
Definition: math_util.h:44