Update potrace library from 1.12 to 1.13, due to a bug fix in 1.13
This commit is contained in:
parent
8994bd1041
commit
a0fd827986
|
@ -8,12 +8,12 @@
|
|||
#ifndef AUXILIARY_H
|
||||
#define AUXILIARY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* point arithmetic */
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* The bitmap type is defined in potracelib.h */
|
||||
#include "potracelib.h"
|
||||
|
@ -28,7 +29,7 @@
|
|||
/* macros for accessing pixel at index (x,y). U* macros omit the
|
||||
* bounds check. */
|
||||
|
||||
#define bm_scanline( bm, y ) ( (bm)->map + (ssize_t) (y) * (ssize_t) (bm)->dy )
|
||||
#define bm_scanline( bm, y ) ( (bm)->map + (ptrdiff_t) (y) * (ptrdiff_t) (bm)->dy )
|
||||
#define bm_index( bm, x, y ) (&bm_scanline( bm, y )[(x) / BM_WORDBITS])
|
||||
#define bm_mask( x ) ( BM_HIBIT >> ( (x) & (BM_WORDBITS - 1) ) )
|
||||
#define bm_range( x, a ) ( (int) (x) >= 0 && (int) (x) < (a) )
|
||||
|
@ -62,10 +63,10 @@ static inline potrace_bitmap_t* bm_new( int w, int h )
|
|||
{
|
||||
potrace_bitmap_t* bm;
|
||||
int dy = w == 0 ? 0 : (w - 1) / BM_WORDBITS + 1;
|
||||
ssize_t size = (ssize_t) dy * (ssize_t) h * (ssize_t) BM_WORDSIZE;
|
||||
ptrdiff_t size = (ptrdiff_t) dy * (ptrdiff_t) h * (ptrdiff_t) BM_WORDSIZE;
|
||||
|
||||
/* check for overflow error */
|
||||
if( size < 0 || size / h / dy != BM_WORDSIZE )
|
||||
if( size < 0 || (h != 0 && dy != 0 && size / h / dy != BM_WORDSIZE) )
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
|
@ -97,8 +98,8 @@ static inline potrace_bitmap_t* bm_new( int w, int h )
|
|||
static inline void bm_clear( potrace_bitmap_t* bm, int c )
|
||||
{
|
||||
/* Note: if the bitmap was created with bm_new, then it is
|
||||
* guaranteed that size will fit into the ssize_t type. */
|
||||
ssize_t size = (ssize_t) bm->dy * (ssize_t) bm->h * (ssize_t) BM_WORDSIZE;
|
||||
* guaranteed that size will fit into the ptrdiff_t type. */
|
||||
ptrdiff_t size = (ptrdiff_t) bm->dy * (ptrdiff_t) bm->h * (ptrdiff_t) BM_WORDSIZE;
|
||||
|
||||
memset( bm->map, c ? -1 : 0, size );
|
||||
}
|
||||
|
@ -108,7 +109,7 @@ static inline void bm_clear( potrace_bitmap_t* bm, int c )
|
|||
static inline potrace_bitmap_t* bm_dup( const potrace_bitmap_t* bm )
|
||||
{
|
||||
potrace_bitmap_t* bm1 = bm_new( bm->w, bm->h );
|
||||
ssize_t size = (ssize_t) bm->dy * (ssize_t) bm->h * (ssize_t) BM_WORDSIZE;
|
||||
ptrdiff_t size = (ptrdiff_t) bm->dy * (ptrdiff_t) bm->h * (ptrdiff_t) BM_WORDSIZE;
|
||||
|
||||
if( !bm1 )
|
||||
{
|
||||
|
@ -123,8 +124,8 @@ static inline potrace_bitmap_t* bm_dup( const potrace_bitmap_t* bm )
|
|||
/* invert the given bitmap. */
|
||||
static inline void bm_invert( potrace_bitmap_t* bm )
|
||||
{
|
||||
ssize_t i;
|
||||
ssize_t size = (ssize_t) bm->dy * (ssize_t) bm->h;
|
||||
ptrdiff_t i;
|
||||
ptrdiff_t size = (ptrdiff_t) bm->dy * (ptrdiff_t) bm->h;
|
||||
|
||||
for( i = 0; i < size; i++ )
|
||||
{
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
|
||||
/* Routines for manipulating bitmaps, including reading pbm files. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bitmap.h"
|
||||
|
@ -181,7 +185,7 @@ static int bm_readbody_pnm( FILE* f, double threshold, potrace_bitmap_t** bmp, i
|
|||
{
|
||||
potrace_bitmap_t* bm;
|
||||
int x, y, i, b, b1, sum;
|
||||
int bpr; /* bytes per row (as opposed to 4*bm->c) */
|
||||
int bpr; /* bytes per row (as opposed to 4*bm->c) */
|
||||
int w, h, max;
|
||||
|
||||
bm = NULL;
|
||||
|
@ -301,7 +305,7 @@ static int bm_readbody_pnm( FILE* f, double threshold, potrace_bitmap_t** bmp, i
|
|||
case '4':
|
||||
/* read P4 format: PBM raw */
|
||||
|
||||
b = fgetc( f ); /* read single white-space character after height */
|
||||
b = fgetc( f ); /* read single white-space character after height */
|
||||
|
||||
if( b==EOF )
|
||||
{
|
||||
|
@ -339,7 +343,7 @@ static int bm_readbody_pnm( FILE* f, double threshold, potrace_bitmap_t** bmp, i
|
|||
goto format_error;
|
||||
}
|
||||
|
||||
b = fgetc( f ); /* read single white-space character after max */
|
||||
b = fgetc( f ); /* read single white-space character after max */
|
||||
|
||||
if( b==EOF )
|
||||
{
|
||||
|
@ -382,7 +386,7 @@ static int bm_readbody_pnm( FILE* f, double threshold, potrace_bitmap_t** bmp, i
|
|||
goto format_error;
|
||||
}
|
||||
|
||||
b = fgetc( f ); /* read single white-space character after max */
|
||||
b = fgetc( f ); /* read single white-space character after max */
|
||||
|
||||
if( b==EOF )
|
||||
{
|
||||
|
@ -573,6 +577,9 @@ static int bmp_forward( FILE* f, int pos )
|
|||
/* correct y-coordinate for top-down format */
|
||||
#define ycorr( y ) (bmpinfo.topdown ? bmpinfo.h - 1 - y : y)
|
||||
|
||||
/* safe colortable access */
|
||||
#define COLTABLE( c ) ( (c) < bmpinfo.ncolors ? coltable[(c)] : 0 )
|
||||
|
||||
/* read BMP stream after magic number. Return values as for bm_read.
|
||||
* We choose to be as permissive as possible, since there are many
|
||||
* programs out there which produce BMP. For instance, ppmtobmp can
|
||||
|
@ -599,7 +606,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
bm = NULL;
|
||||
coltable = NULL;
|
||||
|
||||
bmp_pos = 2; /* set file position */
|
||||
bmp_pos = 2; /* set file position */
|
||||
|
||||
/* file header (minus magic number) */
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.FileSize ) );
|
||||
|
@ -613,7 +620,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
|| bmpinfo.InfoSize == 108 || bmpinfo.InfoSize == 124 )
|
||||
{
|
||||
/* Windows or new OS/2 format */
|
||||
bmpinfo.ctbits = 32; /* sample size in color table */
|
||||
bmpinfo.ctbits = 32; /* sample size in color table */
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.w ) );
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.h ) );
|
||||
TRY( bmp_readint( f, 2, &bmpinfo.Planes ) );
|
||||
|
@ -625,7 +632,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
TRY( bmp_readint( f, 4, &bmpinfo.ncolors ) );
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.ColorsImportant ) );
|
||||
|
||||
if( bmpinfo.InfoSize >= 108 ) /* V4 and V5 bitmaps */
|
||||
if( bmpinfo.InfoSize >= 108 ) /* V4 and V5 bitmaps */
|
||||
{
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.RedMask ) );
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.GreenMask ) );
|
||||
|
@ -656,7 +663,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
else if( bmpinfo.InfoSize == 12 )
|
||||
{
|
||||
/* old OS/2 format */
|
||||
bmpinfo.ctbits = 24; /* sample size in color table */
|
||||
bmpinfo.ctbits = 24; /* sample size in color table */
|
||||
TRY( bmp_readint( f, 2, &bmpinfo.w ) );
|
||||
TRY( bmp_readint( f, 2, &bmpinfo.h ) );
|
||||
TRY( bmp_readint( f, 2, &bmpinfo.Planes ) );
|
||||
|
@ -676,13 +683,18 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
goto format_error;
|
||||
}
|
||||
|
||||
if( bmpinfo.comp > 3 || bmpinfo.bits > 32 )
|
||||
{
|
||||
goto format_error;
|
||||
}
|
||||
|
||||
/* forward to color table (e.g., if bmpinfo.InfoSize == 64) */
|
||||
TRY( bmp_forward( f, 14 + bmpinfo.InfoSize ) );
|
||||
|
||||
if( bmpinfo.Planes != 1 )
|
||||
{
|
||||
bm_read_error = "cannot handle bmp planes";
|
||||
goto format_error; /* can't handle planes */
|
||||
goto format_error; /* can't handle planes */
|
||||
}
|
||||
|
||||
if( bmpinfo.ncolors == 0 )
|
||||
|
@ -716,7 +728,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
}
|
||||
|
||||
/* forward to data */
|
||||
if( bmpinfo.InfoSize != 12 ) /* not old OS/2 format */
|
||||
if( bmpinfo.InfoSize != 12 ) /* not old OS/2 format */
|
||||
{
|
||||
TRY( bmp_forward( f, bmpinfo.DataOffset ) );
|
||||
}
|
||||
|
@ -768,7 +780,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x002: /* 2-bit to 8-bit palettes */
|
||||
case 0x002: /* 2-bit to 8-bit palettes */
|
||||
case 0x003:
|
||||
case 0x004:
|
||||
case 0x005:
|
||||
|
@ -794,7 +806,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
b = bitbuf >> (INTBITS - bmpinfo.bits);
|
||||
bitbuf <<= bmpinfo.bits;
|
||||
n -= bmpinfo.bits;
|
||||
BM_UPUT( bm, x, ycorr( y ), coltable[b] );
|
||||
BM_UPUT( bm, x, ycorr( y ), COLTABLE( b ) );
|
||||
}
|
||||
|
||||
TRY( bmp_pad( f ) );
|
||||
|
@ -802,15 +814,15 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x010: /* 16-bit encoding */
|
||||
case 0x010: /* 16-bit encoding */
|
||||
/* can't do this format because it is not well-documented and I
|
||||
* don't have any samples */
|
||||
bm_read_error = "cannot handle bmp 16-bit coding";
|
||||
goto format_error;
|
||||
break;
|
||||
|
||||
case 0x018: /* 24-bit encoding */
|
||||
case 0x020: /* 32-bit encoding */
|
||||
case 0x018: /* 24-bit encoding */
|
||||
case 0x020: /* 32-bit encoding */
|
||||
|
||||
for( y = 0; y<bmpinfo.h; y++ )
|
||||
{
|
||||
|
@ -828,7 +840,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x320: /* 32-bit encoding with bitfields */
|
||||
case 0x320: /* 32-bit encoding with bitfields */
|
||||
redshift = lobit( bmpinfo.RedMask );
|
||||
greenshift = lobit( bmpinfo.GreenMask );
|
||||
blueshift = lobit( bmpinfo.BlueMask );
|
||||
|
@ -851,20 +863,20 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x204: /* 4-bit runlength compressed encoding (RLE4) */
|
||||
case 0x204: /* 4-bit runlength compressed encoding (RLE4) */
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* opcode */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* argument */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* opcode */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* argument */
|
||||
|
||||
if( b>0 )
|
||||
{
|
||||
/* repeat count */
|
||||
col[0] = coltable[(c >> 4) & 0xf];
|
||||
col[1] = coltable[c & 0xf];
|
||||
col[0] = COLTABLE( (c >> 4) & 0xf );
|
||||
col[1] = COLTABLE( c & 0xf );
|
||||
|
||||
for( i = 0; i<b && x<bmpinfo.w; i++ )
|
||||
{
|
||||
|
@ -897,8 +909,8 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
else if( c == 2 )
|
||||
{
|
||||
/* "delta": skip pixels in x and y directions */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* x offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* y offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* x offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* y offset */
|
||||
x += b;
|
||||
y += c;
|
||||
}
|
||||
|
@ -923,7 +935,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
break;
|
||||
}
|
||||
|
||||
BM_PUT( bm, x, ycorr( y ), coltable[( b >> ( 4 - 4 * (i & 1) ) ) & 0xf] );
|
||||
BM_PUT( bm, x, ycorr( y ), COLTABLE( ( b >> ( 4 - 4 * (i & 1) ) ) & 0xf ) );
|
||||
x++;
|
||||
}
|
||||
|
||||
|
@ -937,14 +949,14 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x108: /* 8-bit runlength compressed encoding (RLE8) */
|
||||
case 0x108: /* 8-bit runlength compressed encoding (RLE8) */
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* opcode */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* argument */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* opcode */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* argument */
|
||||
|
||||
if( b>0 )
|
||||
{
|
||||
|
@ -962,7 +974,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
break;
|
||||
}
|
||||
|
||||
BM_UPUT( bm, x, ycorr( y ), coltable[c] );
|
||||
BM_UPUT( bm, x, ycorr( y ), COLTABLE( c ) );
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
@ -980,8 +992,8 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
else if( c == 2 )
|
||||
{
|
||||
/* "delta": skip pixels in x and y directions */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* x offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* y offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* x offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* y offset */
|
||||
x += b;
|
||||
y += c;
|
||||
}
|
||||
|
@ -1003,7 +1015,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
break;
|
||||
}
|
||||
|
||||
BM_PUT( bm, x, ycorr( y ), coltable[b] );
|
||||
BM_PUT( bm, x, ycorr( y ), COLTABLE( b ) );
|
||||
x++;
|
||||
}
|
||||
|
||||
|
@ -1016,7 +1028,7 @@ static int bm_readbody_bmp( FILE* f, double threshold, potrace_bitmap_t** bmp )
|
|||
}
|
||||
|
||||
break;
|
||||
} /* switch */
|
||||
} /* switch */
|
||||
|
||||
/* skip any potential junk after the data section, but don't
|
||||
* complain in case EOF is encountered */
|
||||
|
@ -1034,7 +1046,7 @@ eof:
|
|||
format_error:
|
||||
try_error:
|
||||
free( coltable );
|
||||
free( bm );
|
||||
bm_free( bm );
|
||||
|
||||
if( !bm_read_error )
|
||||
{
|
||||
|
@ -1045,7 +1057,7 @@ try_error:
|
|||
|
||||
std_error:
|
||||
free( coltable );
|
||||
free( bm );
|
||||
bm_free( bm );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define BITOPS_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
/* private part of the path and curve data structures */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
* 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. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -40,8 +43,8 @@ static inline int detrand( int x, int y )
|
|||
|
||||
/* 0x04b3e375 and 0x05a8ef93 are chosen to contain every possible
|
||||
* 5-bit sequence */
|
||||
z = ( (0x04b3e375 * x) ^ y ) * 0x05a8ef93;
|
||||
z = t[z & 0xff] ^ t[(z >> 8) & 0xff] ^ t[(z >> 16) & 0xff] ^ t[(z >> 24) & 0xff];
|
||||
z = ( (0x04b3e375 * x) ^ y ) * 0x05a8ef93;
|
||||
z = t[z & 0xff] ^ t[(z >> 8) & 0xff] ^ t[(z >> 16) & 0xff] ^ t[(z >> 24) & 0xff];
|
||||
return z;
|
||||
}
|
||||
|
||||
|
@ -69,7 +72,7 @@ static void bm_clearexcess( potrace_bitmap_t* bm )
|
|||
|
||||
struct bbox_s
|
||||
{
|
||||
int x0, x1, y0, y1; /* bounding box */
|
||||
int x0, x1, y0, y1; /* bounding box */
|
||||
};
|
||||
typedef struct bbox_s bbox_t;
|
||||
|
||||
|
@ -77,8 +80,8 @@ typedef struct bbox_s bbox_t;
|
|||
* than clearing the whole bitmap) */
|
||||
static void clear_bm_with_bbox( potrace_bitmap_t* bm, bbox_t* bbox )
|
||||
{
|
||||
int imin = (bbox->x0 / BM_WORDBITS);
|
||||
int imax = ( (bbox->x1 + BM_WORDBITS - 1) / BM_WORDBITS );
|
||||
int imin = (bbox->x0 / BM_WORDBITS);
|
||||
int imax = ( (bbox->x1 + BM_WORDBITS - 1) / BM_WORDBITS );
|
||||
int i, y;
|
||||
|
||||
for( y = bbox->y0; y<bbox->y1; y++ )
|
||||
|
@ -100,7 +103,7 @@ static int majority( potrace_bitmap_t* bm, int x, int y )
|
|||
{
|
||||
int i, a, ct;
|
||||
|
||||
for( i = 2; i<5; i++ ) /* check at "radius" i */
|
||||
for( i = 2; i<5; i++ ) /* check at "radius" i */
|
||||
{
|
||||
ct = 0;
|
||||
|
||||
|
@ -134,7 +137,7 @@ static int majority( potrace_bitmap_t* bm, int x, int y )
|
|||
static void xor_to_ref( potrace_bitmap_t* bm, int x, int y, int xa )
|
||||
{
|
||||
int xhi = x & - BM_WORDBITS;
|
||||
int xlo = x & (BM_WORDBITS - 1); /* = x % BM_WORDBITS */
|
||||
int xlo = x & (BM_WORDBITS - 1); /* = x % BM_WORDBITS */
|
||||
int i;
|
||||
|
||||
if( xhi<xa )
|
||||
|
@ -173,7 +176,7 @@ static void xor_path( potrace_bitmap_t* bm, path_t* p )
|
|||
{
|
||||
int xa, x, y, k, y1;
|
||||
|
||||
if( p->priv->len <= 0 ) /* a path of length 0 is silly, but legal */
|
||||
if( p->priv->len <= 0 ) /* a path of length 0 is silly, but legal */
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -184,8 +187,8 @@ static void xor_path( potrace_bitmap_t* bm, path_t* p )
|
|||
|
||||
for( k = 0; k<p->priv->len; k++ )
|
||||
{
|
||||
x = p->priv->pt[k].x;
|
||||
y = p->priv->pt[k].y;
|
||||
x = p->priv->pt[k].x;
|
||||
y = p->priv->pt[k].y;
|
||||
|
||||
if( y != y1 )
|
||||
{
|
||||
|
@ -204,15 +207,15 @@ static void setbbox_path( bbox_t* bbox, path_t* p )
|
|||
int x, y;
|
||||
int k;
|
||||
|
||||
bbox->y0 = INT_MAX;
|
||||
bbox->y1 = 0;
|
||||
bbox->x0 = INT_MAX;
|
||||
bbox->x1 = 0;
|
||||
bbox->y0 = INT_MAX;
|
||||
bbox->y1 = 0;
|
||||
bbox->x0 = INT_MAX;
|
||||
bbox->x1 = 0;
|
||||
|
||||
for( k = 0; k<p->priv->len; k++ )
|
||||
{
|
||||
x = p->priv->pt[k].x;
|
||||
y = p->priv->pt[k].y;
|
||||
x = p->priv->pt[k].x;
|
||||
y = p->priv->pt[k].y;
|
||||
|
||||
if( x < bbox->x0 )
|
||||
{
|
||||
|
@ -247,26 +250,26 @@ static path_t* findpath( potrace_bitmap_t* bm, int x0, int y0, int sign, int tur
|
|||
{
|
||||
int x, y, dirx, diry, len, size, area;
|
||||
int c, d, tmp;
|
||||
point_t* pt, * pt1;
|
||||
path_t* p = NULL;
|
||||
point_t* pt, * pt1;
|
||||
path_t* p = NULL;
|
||||
|
||||
x = x0;
|
||||
y = y0;
|
||||
dirx = 0;
|
||||
diry = -1;
|
||||
x = x0;
|
||||
y = y0;
|
||||
dirx = 0;
|
||||
diry = -1;
|
||||
|
||||
len = size = 0;
|
||||
pt = NULL;
|
||||
area = 0;
|
||||
len = size = 0;
|
||||
pt = NULL;
|
||||
area = 0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
/* add point to path */
|
||||
if( len>=size )
|
||||
{
|
||||
size += 100;
|
||||
size = (int) (1.3 * size);
|
||||
pt1 = (point_t*) realloc( pt, size * sizeof(point_t) );
|
||||
size += 100;
|
||||
size = (int) (1.3 * size);
|
||||
pt1 = (point_t*) realloc( pt, size * sizeof(point_t) );
|
||||
|
||||
if( !pt1 )
|
||||
{
|
||||
|
@ -276,13 +279,13 @@ static path_t* findpath( potrace_bitmap_t* bm, int x0, int y0, int sign, int tur
|
|||
pt = pt1;
|
||||
}
|
||||
|
||||
pt[len].x = x;
|
||||
pt[len].y = y;
|
||||
pt[len].x = x;
|
||||
pt[len].y = y;
|
||||
len++;
|
||||
|
||||
/* move to next point */
|
||||
x += dirx;
|
||||
y += diry;
|
||||
x += dirx;
|
||||
y += diry;
|
||||
area += x * diry;
|
||||
|
||||
/* path complete? */
|
||||
|
@ -292,8 +295,8 @@ static path_t* findpath( potrace_bitmap_t* bm, int x0, int y0, int sign, int tur
|
|||
}
|
||||
|
||||
/* determine next direction */
|
||||
c = BM_GET( bm, x + (dirx + diry - 1) / 2, y + (diry - dirx - 1) / 2 );
|
||||
d = BM_GET( bm, x + (dirx - diry - 1) / 2, y + (diry + dirx - 1) / 2 );
|
||||
c = BM_GET( bm, x + (dirx + diry - 1) / 2, y + (diry - dirx - 1) / 2 );
|
||||
d = BM_GET( bm, x + (dirx - diry - 1) / 2, y + (diry + dirx - 1) / 2 );
|
||||
|
||||
if( c && !d ) /* ambiguous turn */
|
||||
{
|
||||
|
@ -304,30 +307,30 @@ static path_t* findpath( potrace_bitmap_t* bm, int x0, int y0, int sign, int tur
|
|||
|| ( turnpolicy == POTRACE_TURNPOLICY_MAJORITY && majority( bm, x, y ) )
|
||||
|| ( turnpolicy == POTRACE_TURNPOLICY_MINORITY && !majority( bm, x, y ) ) )
|
||||
{
|
||||
tmp = dirx; /* right turn */
|
||||
dirx = diry;
|
||||
diry = -tmp;
|
||||
tmp = dirx; /* right turn */
|
||||
dirx = diry;
|
||||
diry = -tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = dirx; /* left turn */
|
||||
dirx = -diry;
|
||||
diry = tmp;
|
||||
tmp = dirx; /* left turn */
|
||||
dirx = -diry;
|
||||
diry = tmp;
|
||||
}
|
||||
}
|
||||
else if( c ) /* right turn */
|
||||
{
|
||||
tmp = dirx;
|
||||
dirx = diry;
|
||||
diry = -tmp;
|
||||
tmp = dirx;
|
||||
dirx = diry;
|
||||
diry = -tmp;
|
||||
}
|
||||
else if( !d ) /* left turn */
|
||||
{
|
||||
tmp = dirx;
|
||||
dirx = -diry;
|
||||
diry = tmp;
|
||||
tmp = dirx;
|
||||
dirx = -diry;
|
||||
diry = tmp;
|
||||
}
|
||||
} /* while this path */
|
||||
} /* while this path */
|
||||
|
||||
/* allocate new path object */
|
||||
p = path_new();
|
||||
|
@ -337,8 +340,8 @@ static path_t* findpath( potrace_bitmap_t* bm, int x0, int y0, int sign, int tur
|
|||
goto error;
|
||||
}
|
||||
|
||||
p->priv->pt = pt;
|
||||
p->priv->len = len;
|
||||
p->priv->pt = pt;
|
||||
p->priv->len = len;
|
||||
p->area = area;
|
||||
p->sign = sign;
|
||||
|
||||
|
@ -372,9 +375,9 @@ static void pathlist_to_tree( path_t* plist, potrace_bitmap_t* bm )
|
|||
path_t* heap, * heap1;
|
||||
path_t* cur;
|
||||
path_t* head;
|
||||
path_t** plist_hook; /* for fast appending to linked list */
|
||||
path_t** hook_in, ** hook_out; /* for fast appending to linked list */
|
||||
bbox_t bbox;
|
||||
path_t** plist_hook; /* for fast appending to linked list */
|
||||
path_t** hook_in, ** hook_out; /* for fast appending to linked list */
|
||||
bbox_t bbox;
|
||||
|
||||
bm_clear( bm, 0 );
|
||||
|
||||
|
@ -396,13 +399,13 @@ static void pathlist_to_tree( path_t* plist, potrace_bitmap_t* bm )
|
|||
while( heap )
|
||||
{
|
||||
/* unlink first sublist */
|
||||
cur = heap;
|
||||
heap = heap->childlist;
|
||||
cur = heap;
|
||||
heap = heap->childlist;
|
||||
cur->childlist = NULL;
|
||||
|
||||
/* unlink first path */
|
||||
head = cur;
|
||||
cur = cur->next;
|
||||
head = cur;
|
||||
cur = cur->next;
|
||||
head->next = NULL;
|
||||
|
||||
/* render path */
|
||||
|
@ -412,8 +415,8 @@ static void pathlist_to_tree( path_t* plist, potrace_bitmap_t* bm )
|
|||
/* now do insideness test for each element of cur; append it to
|
||||
* head->childlist if it's inside head, else append it to
|
||||
* head->next. */
|
||||
hook_in = &head->childlist;
|
||||
hook_out = &head->next;
|
||||
hook_in = &head->childlist;
|
||||
hook_out = &head->next;
|
||||
list_forall_unlink( p, cur ) {
|
||||
if( p->priv->pt[0].y <= bbox.y0 )
|
||||
{
|
||||
|
@ -470,7 +473,7 @@ static void pathlist_to_tree( path_t* plist, potrace_bitmap_t* bm )
|
|||
|
||||
if( heap )
|
||||
{
|
||||
heap->next = NULL; /* heap is a linked list of childlists */
|
||||
heap->next = NULL; /* heap is a linked list of childlists */
|
||||
}
|
||||
|
||||
plist = NULL;
|
||||
|
@ -574,8 +577,8 @@ int bm_to_pathlist( const potrace_bitmap_t* bm,
|
|||
bm_clearexcess( bm1 );
|
||||
|
||||
/* iterate through components */
|
||||
x = 0;
|
||||
y = bm1->h - 1;
|
||||
x = 0;
|
||||
y = bm1->h - 1;
|
||||
|
||||
while( findnext( bm1, &x, &y ) == 0 )
|
||||
{
|
||||
|
@ -603,7 +606,7 @@ int bm_to_pathlist( const potrace_bitmap_t* bm,
|
|||
list_insert_beforehook( p, plist_hook );
|
||||
}
|
||||
|
||||
if( bm1->h > 0 ) /* to be sure */
|
||||
if( bm1->h > 0 ) /* to be sure */
|
||||
{
|
||||
progress_update( 1 - y / (double) bm1->h, progress );
|
||||
}
|
||||
|
|
|
@ -6,10 +6,15 @@
|
|||
/* Routines for manipulating greymaps, including reading pgm files. We
|
||||
* only deal with greymaps of depth 8 bits. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "greymap.h"
|
||||
#include "bitops.h"
|
||||
|
@ -28,8 +33,8 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp );
|
|||
* Assumes w, h >= 0. */
|
||||
greymap_t* gm_new( int w, int h )
|
||||
{
|
||||
greymap_t* gm;
|
||||
ssize_t size = (ssize_t) w * (ssize_t) h * (ssize_t) sizeof(signed short int);
|
||||
greymap_t* gm;
|
||||
ptrdiff_t size = (ptrdiff_t) w * (ptrdiff_t) h * (ptrdiff_t) sizeof(signed short int);
|
||||
|
||||
/* check for overflow error */
|
||||
if( size < 0 || size / w / h != sizeof(signed short int) )
|
||||
|
@ -272,7 +277,7 @@ static int gm_readbody_pnm( FILE* f, greymap_t** gmp, int magic )
|
|||
{
|
||||
greymap_t* gm;
|
||||
int x, y, i, j, b, b1, sum;
|
||||
int bpr; /* bytes per row (as opposed to 4*gm->c) */
|
||||
int bpr; /* bytes per row (as opposed to 4*gm->c) */
|
||||
int w, h, max;
|
||||
|
||||
gm = NULL;
|
||||
|
@ -392,7 +397,7 @@ static int gm_readbody_pnm( FILE* f, greymap_t** gmp, int magic )
|
|||
case '4':
|
||||
/* read P4 format: PBM raw */
|
||||
|
||||
b = fgetc( f ); /* read single white-space character after height */
|
||||
b = fgetc( f ); /* read single white-space character after height */
|
||||
|
||||
if( b==EOF )
|
||||
{
|
||||
|
@ -414,7 +419,7 @@ static int gm_readbody_pnm( FILE* f, greymap_t** gmp, int magic )
|
|||
|
||||
for( j = 0; j<8; j++ )
|
||||
{
|
||||
GM_PUT( gm, i * 8 + j, y, (b & (0x80 >> j)) ? 0 : 255 );
|
||||
GM_PUT( gm, i * 8 + j, y, b & (0x80 >> j) ? 0 : 255 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -431,7 +436,7 @@ static int gm_readbody_pnm( FILE* f, greymap_t** gmp, int magic )
|
|||
goto format_error;
|
||||
}
|
||||
|
||||
b = fgetc( f ); /* read single white-space character after max */
|
||||
b = fgetc( f ); /* read single white-space character after max */
|
||||
|
||||
if( b==EOF )
|
||||
{
|
||||
|
@ -474,7 +479,7 @@ static int gm_readbody_pnm( FILE* f, greymap_t** gmp, int magic )
|
|||
goto format_error;
|
||||
}
|
||||
|
||||
b = fgetc( f ); /* read single white-space character after max */
|
||||
b = fgetc( f ); /* read single white-space character after max */
|
||||
|
||||
if( b==EOF )
|
||||
{
|
||||
|
@ -689,7 +694,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
gm = NULL;
|
||||
coltable = NULL;
|
||||
|
||||
bmp_pos = 2; /* set file position */
|
||||
bmp_pos = 2; /* set file position */
|
||||
|
||||
/* file header (minus magic number) */
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.FileSize ) );
|
||||
|
@ -703,7 +708,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
|| bmpinfo.InfoSize == 108 || bmpinfo.InfoSize == 124 )
|
||||
{
|
||||
/* Windows or new OS/2 format */
|
||||
bmpinfo.ctbits = 32; /* sample size in color table */
|
||||
bmpinfo.ctbits = 32; /* sample size in color table */
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.w ) );
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.h ) );
|
||||
TRY( bmp_readint( f, 2, &bmpinfo.Planes ) );
|
||||
|
@ -715,7 +720,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
TRY( bmp_readint( f, 4, &bmpinfo.ncolors ) );
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.ColorsImportant ) );
|
||||
|
||||
if( bmpinfo.InfoSize >= 108 ) /* V4 and V5 bitmaps */
|
||||
if( bmpinfo.InfoSize >= 108 ) /* V4 and V5 bitmaps */
|
||||
{
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.RedMask ) );
|
||||
TRY( bmp_readint( f, 4, &bmpinfo.GreenMask ) );
|
||||
|
@ -746,7 +751,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
else if( bmpinfo.InfoSize == 12 )
|
||||
{
|
||||
/* old OS/2 format */
|
||||
bmpinfo.ctbits = 24; /* sample size in color table */
|
||||
bmpinfo.ctbits = 24; /* sample size in color table */
|
||||
TRY( bmp_readint( f, 2, &bmpinfo.w ) );
|
||||
TRY( bmp_readint( f, 2, &bmpinfo.h ) );
|
||||
TRY( bmp_readint( f, 2, &bmpinfo.Planes ) );
|
||||
|
@ -772,7 +777,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
if( bmpinfo.Planes != 1 )
|
||||
{
|
||||
gm_read_error = "cannot handle bmp planes";
|
||||
goto format_error; /* can't handle planes */
|
||||
goto format_error; /* can't handle planes */
|
||||
}
|
||||
|
||||
if( bmpinfo.ncolors == 0 )
|
||||
|
@ -801,7 +806,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
}
|
||||
|
||||
/* forward to data */
|
||||
if( bmpinfo.InfoSize != 12 ) /* not old OS/2 format */
|
||||
if( bmpinfo.InfoSize != 12 ) /* not old OS/2 format */
|
||||
{
|
||||
TRY( bmp_forward( f, bmpinfo.DataOffset ) );
|
||||
}
|
||||
|
@ -823,7 +828,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
goto format_error;
|
||||
break;
|
||||
|
||||
case 0x001: /* monochrome palette */
|
||||
case 0x001: /* monochrome palette */
|
||||
|
||||
/* raster data */
|
||||
for( y = 0; y<bmpinfo.h; y++ )
|
||||
|
@ -837,7 +842,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
for( j = 0; j<8; j++ )
|
||||
{
|
||||
GM_PUT( gm, i * 8 + j, ycorr( y ),
|
||||
(b & (0x80 >> j)) ? coltable[1] : coltable[0] );
|
||||
b & (0x80 >> j) ? coltable[1] : coltable[0] );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -846,7 +851,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x002: /* 2-bit to 8-bit palettes */
|
||||
case 0x002: /* 2-bit to 8-bit palettes */
|
||||
case 0x003:
|
||||
case 0x004:
|
||||
case 0x005:
|
||||
|
@ -880,15 +885,15 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x010: /* 16-bit encoding */
|
||||
case 0x010: /* 16-bit encoding */
|
||||
/* can't do this format because it is not well-documented and I
|
||||
* don't have any samples */
|
||||
gm_read_error = "cannot handle bmp 16-bit coding";
|
||||
goto format_error;
|
||||
break;
|
||||
|
||||
case 0x018: /* 24-bit encoding */
|
||||
case 0x020: /* 32-bit encoding */
|
||||
case 0x018: /* 24-bit encoding */
|
||||
case 0x020: /* 32-bit encoding */
|
||||
|
||||
for( y = 0; y<bmpinfo.h; y++ )
|
||||
{
|
||||
|
@ -906,7 +911,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x320: /* 32-bit encoding with bitfields */
|
||||
case 0x320: /* 32-bit encoding with bitfields */
|
||||
redshift = lobit( bmpinfo.RedMask );
|
||||
greenshift = lobit( bmpinfo.GreenMask );
|
||||
blueshift = lobit( bmpinfo.BlueMask );
|
||||
|
@ -929,14 +934,14 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x204: /* 4-bit runlength compressed encoding (RLE4) */
|
||||
case 0x204: /* 4-bit runlength compressed encoding (RLE4) */
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* opcode */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* argument */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* opcode */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* argument */
|
||||
|
||||
if( b>0 )
|
||||
{
|
||||
|
@ -975,8 +980,8 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
else if( c == 2 )
|
||||
{
|
||||
/* "delta": skip pixels in x and y directions */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* x offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* y offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* x offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* y offset */
|
||||
x += b;
|
||||
y += c;
|
||||
}
|
||||
|
@ -1015,14 +1020,14 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
|
||||
break;
|
||||
|
||||
case 0x108: /* 8-bit runlength compressed encoding (RLE8) */
|
||||
case 0x108: /* 8-bit runlength compressed encoding (RLE8) */
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* opcode */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* argument */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* opcode */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* argument */
|
||||
|
||||
if( b>0 )
|
||||
{
|
||||
|
@ -1058,8 +1063,8 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
else if( c == 2 )
|
||||
{
|
||||
/* "delta": skip pixels in x and y directions */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* x offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* y offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &b ) ); /* x offset */
|
||||
TRY_EOF( bmp_readint( f, 1, &c ) ); /* y offset */
|
||||
x += b;
|
||||
y += c;
|
||||
}
|
||||
|
@ -1094,7 +1099,7 @@ static int gm_readbody_bmp( FILE* f, greymap_t** gmp )
|
|||
}
|
||||
|
||||
break;
|
||||
} /* switch */
|
||||
} /* switch */
|
||||
|
||||
/* skip any potential junk after the data section, but don't
|
||||
* complain in case EOF is encountered */
|
||||
|
@ -1267,7 +1272,7 @@ int gm_print( FILE* f, greymap_t* gm )
|
|||
}
|
||||
}
|
||||
|
||||
fputc( "*#=- "[5 * d / t], f ); /* what a cute trick :) */
|
||||
fputc( "*#=- "[5 * d / t], f ); /* what a cute trick :) */
|
||||
}
|
||||
|
||||
fputc( '\n', f );
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* internal format for greymaps. Note: in this format, rows are
|
||||
* ordered from bottom to top. The pixels in each row are given from
|
||||
|
@ -24,7 +25,7 @@ typedef struct greymap_s greymap_t;
|
|||
/* macros for accessing pixel at index (x,y). Note that the origin is
|
||||
* in the *lower* left corner. U* macros omit the bounds check. */
|
||||
|
||||
#define gm_index( gm, x, y ) (&(gm)->map[(x) + (y) * (ssize_t) (gm)->w])
|
||||
#define gm_index( gm, x, y ) (&(gm)->map[(x) + (y) * (ptrdiff_t) (gm)->w])
|
||||
#define gm_safe( gm, x, \
|
||||
y ) ( (int) (x)>=0 && (int) (x)<(gm)->w && (int) (y)>=0 \
|
||||
&& (int) (y)<(gm)->h )
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
* Return NULL if out of bounds. */
|
||||
#define list_nth( elt, list, n ) \
|
||||
MACRO_BEGIN \
|
||||
int _x; /* only evaluate n once */ \
|
||||
int _x; /* only evaluate n once */ \
|
||||
for( _x = (n), elt = list; _x && elt; _x--, elt = elt->next ) {} \
|
||||
MACRO_END
|
||||
|
||||
|
@ -124,7 +124,7 @@
|
|||
* Return NULL if out of bounds. */
|
||||
#define list_nth_hook( elt, list, n, hook ) \
|
||||
MACRO_BEGIN \
|
||||
int _x; /* only evaluate n once */ \
|
||||
int _x; /* only evaluate n once */ \
|
||||
for( _x = (n), elt = list, hook = &list; _x && elt; \
|
||||
_x--, hook = &elt->next, elt = elt->next ) {} \
|
||||
MACRO_END
|
||||
|
@ -265,8 +265,8 @@
|
|||
|
||||
#define dlist_append( head, end, elt ) \
|
||||
MACRO_BEGIN \
|
||||
elt->prev = end; \
|
||||
elt->next = NULL; \
|
||||
elt->prev = end; \
|
||||
elt->next = NULL; \
|
||||
if( end ) { \
|
||||
end->next = elt; \
|
||||
} \
|
||||
|
@ -294,8 +294,8 @@
|
|||
else { \
|
||||
end = NULL; \
|
||||
} \
|
||||
elt->prev = NULL; \
|
||||
elt->next = NULL; \
|
||||
elt->prev = NULL; \
|
||||
elt->next = NULL; \
|
||||
} \
|
||||
MACRO_END
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
#define POTRACELIB_VERSION "potracelib 1.12"
|
||||
#define POTRACELIB_VERSION "potracelib 1.13"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
* 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. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -12,10 +16,6 @@
|
|||
#include "progress.h"
|
||||
#include <potrace_version.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/* default parameters */
|
||||
static const potrace_param_t param_default =
|
||||
{
|
||||
|
@ -93,7 +93,7 @@ potrace_state_t* potrace_trace( const potrace_param_t* param, const potrace_bitm
|
|||
|
||||
st->status = POTRACE_STATUS_OK;
|
||||
st->plist = plist;
|
||||
st->priv = NULL; /* private state currently unused */
|
||||
st->priv = NULL; /* private state currently unused */
|
||||
|
||||
progress_subrange_end( &prog, &subprog );
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@ struct 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 */
|
||||
double b; /* upper limit of subrange in superrange units */
|
||||
double d_prev; /* previous value of d */
|
||||
double min, max; /* desired range of progress, e.g. 0.0 to 1.0 */
|
||||
double epsilon; /* granularity: can skip smaller increments */
|
||||
double b; /* upper limit of subrange in superrange units */
|
||||
double d_prev; /* previous value of d */
|
||||
};
|
||||
typedef struct progress_s progress_t;
|
||||
|
||||
|
@ -64,14 +64,14 @@ static inline void progress_subrange_start( double a,
|
|||
|
||||
if( max - min < prog->epsilon )
|
||||
{
|
||||
sub->callback = NULL; /* no further progress info in subrange */
|
||||
sub->callback = NULL; /* no further progress info in subrange */
|
||||
sub->b = b;
|
||||
return;
|
||||
}
|
||||
|
||||
sub->callback = prog->callback;
|
||||
sub->data = prog->data;
|
||||
sub->epsilon = prog->epsilon;
|
||||
sub->epsilon = prog->epsilon;
|
||||
sub->min = min;
|
||||
sub->max = max;
|
||||
sub->d_prev = prog->d_prev;
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
* 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. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -132,7 +135,7 @@ static void incrow( render_t* rm, int x, int y, int b )
|
|||
|
||||
if( rm->incrow_buf[y] == 0 )
|
||||
{
|
||||
rm->incrow_buf[y] = x + 1; /* store x+1 so that we can use 0 for "vacant" */
|
||||
rm->incrow_buf[y] = x + 1; /* store x+1 so that we can use 0 for "vacant" */
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -162,8 +165,8 @@ void render_lineto( render_t* rm, double x2, double y2 )
|
|||
int x2i, y2i;
|
||||
double t0 = 2, s0 = 2;
|
||||
int sn, tn;
|
||||
double ss = 2, ts = 2;
|
||||
double r0, r1;
|
||||
double ss = 2, ts = 2;
|
||||
double r0, r1;
|
||||
int i, j;
|
||||
int rxi, ryi;
|
||||
int s;
|
||||
|
@ -188,8 +191,8 @@ void render_lineto( render_t* rm, double x2, double y2 )
|
|||
|
||||
r0 = 0;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
i = 0;
|
||||
j = 0;
|
||||
|
||||
rxi = rm->x1i;
|
||||
ryi = rm->y1i;
|
||||
|
@ -277,7 +280,7 @@ void render_curveto( render_t* rm, double x2, double y2, double x3, double y3, d
|
|||
* between the true curve and its approximation does not exceed the
|
||||
* desired accuracy delta. */
|
||||
|
||||
delta = .1; /* desired accuracy, in pixels */
|
||||
delta = .1; /* desired accuracy, in pixels */
|
||||
|
||||
/* let dd = maximal value of 2nd derivative over curve - this must
|
||||
* occur at an endpoint. */
|
||||
|
@ -285,7 +288,7 @@ void render_curveto( render_t* rm, double x2, double y2, double x3, double y3, d
|
|||
dd1 = sq( x2 - 2 * x3 + x4 ) + sq( y2 - 2 * y3 + y4 );
|
||||
dd = 6 * sqrt( max( dd0, dd1 ) );
|
||||
e2 = 8 * delta <= dd ? 8 * delta / dd : 1;
|
||||
epsilon = sqrt( e2 ); /* necessary interval size */
|
||||
epsilon = sqrt( e2 ); /* necessary interval size */
|
||||
|
||||
for( t = epsilon; t<1; t += epsilon )
|
||||
{
|
||||
|
|
|
@ -13,8 +13,8 @@ struct render_s
|
|||
greymap_t* gm;
|
||||
double x0, y0, x1, y1;
|
||||
int x0i, y0i, x1i, y1i;
|
||||
double a0, a1;
|
||||
int* incrow_buf;
|
||||
double a0, a1;
|
||||
int* incrow_buf;
|
||||
};
|
||||
typedef struct render_s render_t;
|
||||
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
/* transform jaggy paths into smooth curves */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -91,7 +95,7 @@ static void pointslope( privpath_t* pp, int i, int j, dpoint_t* ctr, dpoint_t* d
|
|||
double x, y, x2, xy, y2;
|
||||
double k;
|
||||
double a, b, c, lambda2, l;
|
||||
int r = 0; /* rotations from i to j */
|
||||
int r = 0; /* rotations from i to j */
|
||||
|
||||
while( j>=n )
|
||||
{
|
||||
|
@ -131,7 +135,7 @@ static void pointslope( privpath_t* pp, int i, int j, dpoint_t* ctr, dpoint_t* d
|
|||
b = (xy - (double) x * y / k) / k;
|
||||
c = (y2 - (double) y * y / k) / k;
|
||||
|
||||
lambda2 = ( a + c + sqrt( (a - c) * (a - c) + 4 * b * b ) ) / 2; /* larger e.value */
|
||||
lambda2 = ( a + c + sqrt( (a - c) * (a - c) + 4 * b * b ) ) / 2; /* larger e.value */
|
||||
|
||||
/* now find e.vector for lambda2 */
|
||||
a -= lambda2;
|
||||
|
@ -160,8 +164,8 @@ static void pointslope( privpath_t* pp, int i, int j, dpoint_t* ctr, dpoint_t* d
|
|||
|
||||
if( l==0 )
|
||||
{
|
||||
dir->x = dir->y = 0; /* sometimes this can happen when k=4:
|
||||
* the two eigenvalues coincide */
|
||||
dir->x = dir->y = 0; /* sometimes this can happen when k=4:
|
||||
* the two eigenvalues coincide */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,7 +413,7 @@ static int calc_lon( privpath_t* pp )
|
|||
{
|
||||
if( pt[i].x != pt[k].x && pt[i].y != pt[k].y )
|
||||
{
|
||||
k = i + 1; /* necessarily i<n-1 in this case */
|
||||
k = i + 1; /* necessarily i<n-1 in this case */
|
||||
}
|
||||
|
||||
nc[i] = k;
|
||||
|
@ -523,7 +527,7 @@ constraint_viol:
|
|||
pivk[i] = mod( k1 + j, n );
|
||||
foundk:
|
||||
;
|
||||
} /* for i */
|
||||
} /* for i */
|
||||
|
||||
/* clean up: for each i, let lon[i] be the largest k such that for
|
||||
* all i' with i<=i'<k, i'<k<=pivk[i']. */
|
||||
|
@ -575,7 +579,7 @@ static double penalty3( privpath_t* pp, int i, int j )
|
|||
double a, b, c, s;
|
||||
double px, py, ex, ey;
|
||||
|
||||
int r = 0; /* rotations from i to j */
|
||||
int r = 0; /* rotations from i to j */
|
||||
|
||||
if( j>=n )
|
||||
{
|
||||
|
@ -773,7 +777,7 @@ static int adjust_vertices( privpath_t* pp )
|
|||
|
||||
dpoint_t* ctr = NULL; /* ctr[m] */
|
||||
dpoint_t* dir = NULL; /* dir[m] */
|
||||
quadform_t* q = NULL; /* q[m] */
|
||||
quadform_t* q = NULL; /* q[m] */
|
||||
double v[3];
|
||||
double d;
|
||||
int i, j, k, l;
|
||||
|
@ -839,7 +843,7 @@ static int adjust_vertices( privpath_t* pp )
|
|||
* the two lines. */
|
||||
for( i = 0; i<m; i++ )
|
||||
{
|
||||
quadform_t Q;
|
||||
quadform_t Q;
|
||||
dpoint_t w;
|
||||
double dx, dy;
|
||||
double det;
|
||||
|
@ -934,7 +938,7 @@ static int adjust_vertices( privpath_t* pp )
|
|||
goto fixx;
|
||||
}
|
||||
|
||||
for( z = 0; z<2; z++ ) /* value of the y-coordinate */
|
||||
for( z = 0; z<2; z++ ) /* value of the y-coordinate */
|
||||
{
|
||||
w.y = s.y - 0.5 + z;
|
||||
w.x = -(Q[0][1] * w.y + Q[0][2]) / Q[0][0];
|
||||
|
@ -956,7 +960,7 @@ fixx:
|
|||
goto corners;
|
||||
}
|
||||
|
||||
for( z = 0; z<2; z++ ) /* value of the x-coordinate */
|
||||
for( z = 0; z<2; z++ ) /* value of the x-coordinate */
|
||||
{
|
||||
w.x = s.x - 0.5 + z;
|
||||
w.y = -(Q[1][0] * w.x + Q[1][2]) / Q[1][1];
|
||||
|
@ -1062,7 +1066,7 @@ static void smooth( privcurve_t* curve, double alphamax )
|
|||
|
||||
if( alpha >= alphamax ) /* pointed corner */
|
||||
{
|
||||
curve->tag[j] = POTRACE_CORNER;
|
||||
curve->tag[j] = POTRACE_CORNER;
|
||||
curve->c[j][1] = curve->vertex[j];
|
||||
curve->c[j][2] = p4;
|
||||
}
|
||||
|
@ -1079,13 +1083,13 @@ static void smooth( privcurve_t* curve, double alphamax )
|
|||
|
||||
p2 = interval( .5 + .5 * alpha, curve->vertex[i], curve->vertex[j] );
|
||||
p3 = interval( .5 + .5 * alpha, curve->vertex[k], curve->vertex[j] );
|
||||
curve->tag[j] = POTRACE_CURVETO;
|
||||
curve->tag[j] = POTRACE_CURVETO;
|
||||
curve->c[j][0] = p2;
|
||||
curve->c[j][1] = p3;
|
||||
curve->c[j][2] = p4;
|
||||
}
|
||||
|
||||
curve->alpha[j] = alpha; /* store the "cropped" value of alpha */
|
||||
curve->alpha[j] = alpha; /* store the "cropped" value of alpha */
|
||||
curve->beta[j] = 0.5;
|
||||
}
|
||||
|
||||
|
@ -1101,8 +1105,8 @@ struct opti_s
|
|||
{
|
||||
double pen; /* penalty */
|
||||
dpoint_t c[2]; /* curve parameters */
|
||||
double t, s; /* curve parameters */
|
||||
double alpha; /* curve parameter */
|
||||
double t, s; /* curve parameters */
|
||||
double alpha; /* curve parameter */
|
||||
};
|
||||
typedef struct opti_s opti_t;
|
||||
|
||||
|
@ -1121,17 +1125,17 @@ static int opti_penalty( privpath_t* pp,
|
|||
int k, k1, k2, conv, i1;
|
||||
double area, alpha, d, d1, d2;
|
||||
dpoint_t p0, p1, p2, p3, pt;
|
||||
double A, R, A1, A2, A3, A4;
|
||||
double s, t;
|
||||
double A, R, A1, A2, A3, A4;
|
||||
double s, t;
|
||||
|
||||
/* check convexity, corner-freeness, and maximum bend < 179 degrees */
|
||||
|
||||
if( i==j ) /* sanity - a full loop can never be an opticurve */
|
||||
if( i==j ) /* sanity - a full loop can never be an opticurve */
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
k = i;
|
||||
k = i;
|
||||
i1 = mod( i + 1, m );
|
||||
k1 = mod( k + 1, m );
|
||||
conv = convc[k1];
|
||||
|
@ -1192,7 +1196,7 @@ static int opti_penalty( privpath_t* pp,
|
|||
/* A4 = dpara(p1, p2, p3); */
|
||||
A4 = A1 + A3 - A2;
|
||||
|
||||
if( A2 == A1 ) /* this should never happen */
|
||||
if( A2 == A1 ) /* this should never happen */
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -1201,7 +1205,7 @@ static int opti_penalty( privpath_t* pp,
|
|||
s = A2 / (A2 - A1);
|
||||
A = A2 * t / 2.0;
|
||||
|
||||
if( A == 0.0 ) /* this should never happen */
|
||||
if( A == 0.0 ) /* this should never happen */
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -1235,7 +1239,7 @@ static int opti_penalty( privpath_t* pp,
|
|||
pt = bezier( t, p0, p1, p2, p3 );
|
||||
d = ddist( pp->curve.vertex[k], pp->curve.vertex[k1] );
|
||||
|
||||
if( d == 0.0 ) /* this should never happen */
|
||||
if( d == 0.0 ) /* this should never happen */
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -1270,7 +1274,7 @@ static int opti_penalty( privpath_t* pp,
|
|||
pt = bezier( t, p0, p1, p2, p3 );
|
||||
d = ddist( pp->curve.c[k][2], pp->curve.c[k1][2] );
|
||||
|
||||
if( d == 0.0 ) /* this should never happen */
|
||||
if( d == 0.0 ) /* this should never happen */
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -1360,13 +1364,13 @@ static int opticurve( privpath_t* pp, double opttolerance )
|
|||
area += 0.3 * alpha * (4 - alpha) * dpara( pp->curve.c[i][2],
|
||||
pp->curve.vertex[i1],
|
||||
pp->curve.c[i1][2] ) / 2;
|
||||
area += dpara( p0, pp->curve.c[i][2], pp->curve.c[i1][2] ) / 2;
|
||||
area += dpara( p0, pp->curve.c[i][2], pp->curve.c[i1][2] ) / 2;
|
||||
}
|
||||
|
||||
areac[i + 1] = area;
|
||||
}
|
||||
|
||||
pt[0] = -1;
|
||||
pt[0] = -1;
|
||||
pen[0] = 0;
|
||||
len[0] = 0;
|
||||
|
||||
|
@ -1376,7 +1380,7 @@ static int opticurve( privpath_t* pp, double opttolerance )
|
|||
for( j = 1; j<=m; j++ )
|
||||
{
|
||||
/* calculate best path from 0 to j */
|
||||
pt[j] = j - 1;
|
||||
pt[j] = j - 1;
|
||||
pen[j] = pen[j - 1];
|
||||
len[j] = len[j - 1] + 1;
|
||||
|
||||
|
@ -1391,7 +1395,7 @@ static int opticurve( privpath_t* pp, double opttolerance )
|
|||
|
||||
if( len[j] > len[i] + 1 || (len[j] == len[i] + 1 && pen[j] > pen[i] + o.pen) )
|
||||
{
|
||||
pt[j] = i;
|
||||
pt[j] = i;
|
||||
pen[j] = pen[i] + o.pen;
|
||||
len[j] = len[i] + 1;
|
||||
opt[j] = o;
|
||||
|
@ -1416,7 +1420,7 @@ static int opticurve( privpath_t* pp, double opttolerance )
|
|||
{
|
||||
if( pt[j]==j - 1 )
|
||||
{
|
||||
pp->ocurve.tag[i] = pp->curve.tag[mod( j, m )];
|
||||
pp->ocurve.tag[i] = pp->curve.tag[mod( j, m )];
|
||||
pp->ocurve.c[i][0] = pp->curve.c[mod( j, m )][0];
|
||||
pp->ocurve.c[i][1] = pp->curve.c[mod( j, m )][1];
|
||||
pp->ocurve.c[i][2] = pp->curve.c[mod( j, m )][2];
|
||||
|
@ -1428,12 +1432,12 @@ static int opticurve( privpath_t* pp, double opttolerance )
|
|||
}
|
||||
else
|
||||
{
|
||||
pp->ocurve.tag[i] = POTRACE_CURVETO;
|
||||
pp->ocurve.tag[i] = POTRACE_CURVETO;
|
||||
pp->ocurve.c[i][0] = opt[j].c[0];
|
||||
pp->ocurve.c[i][1] = opt[j].c[1];
|
||||
pp->ocurve.c[i][2] = pp->curve.c[mod( j, m )][2];
|
||||
pp->ocurve.vertex[i] = interval( opt[j].s, pp->curve.c[mod( j,
|
||||
m )][2],
|
||||
pp->ocurve.vertex[i] = interval( opt[j].s, pp->curve.c[mod( j,
|
||||
m )][2],
|
||||
pp->curve.vertex[mod( j, m )] );
|
||||
pp->ocurve.alpha[i] = opt[j].alpha;
|
||||
pp->ocurve.alpha0[i] = opt[j].alpha;
|
||||
|
@ -1504,7 +1508,7 @@ int process_path( path_t* plist, const potrace_param_t* param, progress_t* progr
|
|||
TRY( bestpolygon( p->priv ) );
|
||||
TRY( adjust_vertices( p->priv ) );
|
||||
|
||||
if( p->sign == '-' ) /* reverse orientation of negative paths */
|
||||
if( p->sign == '-' ) /* reverse orientation of negative paths */
|
||||
{
|
||||
reverse( &p->priv->curve );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue