Commit f0a492e8 authored by Raph Levien's avatar Raph Levien

Initial revision

parents
*.lo
*.la
.deps
.libs
INSTALL
Makefile
Makefile.in
aclocal.m4
confdefs.h
config.cache
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
libtool
ltconfig
ltmain.sh
missing
mkinstalldirs
stamp-h
stamp-h.in
testart
testuta
Raph Levien <raph@acm.org>
This diff is collapsed.
Tue Nov 10 12:43:30 1998 Raph Levien <raph@acm.org>
* Getting the library in shape for initial checkin to CVS.
noinst_PROGRAMS = testart testuta
lib_LTLIBRARIES = libart_lgpl.la
libart_lgpl_la_SOURCES = \
art_bpath.c \
art_bpath.h \
art_misc.c \
art_misc.h \
art_pathcode.h \
art_point.h \
art_rect.c \
art_rect.h \
art_rect_uta.c \
art_rect_uta.h \
art_uta.c \
art_uta.h \
art_uta_rect.c \
art_uta_rect.h \
art_uta_vpath.c \
art_uta_vpath.h \
art_vpath.c \
art_vpath.h
libart_lgplincdir = $(includedir)/libart
libart_lgplinc = \
art_bpath.h \
art_misc.h \
art_pathcode.h \
art_point.h \
art_rect.h \
art_rect_uta.h \
art_uta.h \
art_uta_rect.h \
art_uta_vpath.h \
art_vpath.h
DEPS = $(top_builddir)/libart_lgpl.la
LDADDS = $(top_builddir)/libart_lgpl.la
testart_SOURCES=testart.c
testart_LDFLAGS =
testart_DEPENDENCIES = $(DEPS)
testart_LDADD = $(LDADDS) -lm
testuta_SOURCES=testuta.c
testuta_LDFLAGS =
testuta_DEPENDENCIES = $(DEPS)
testuta_LDADD = $(LDADDS) -lm
tests: testart testuta
Please see http://www.levien.com/libart/ for the latest news.
This is the LGPL'd component of libart. All functions needed for
running the Gnome canvas, and for printing support, will be going in
here. The GPL'd component will be getting various enhanced functions
for specific applications.
Libart is free software. It is also for sale. For information about
licensing libart, please contact Raph Levien
<raph@acm.org>. Contributions to the codebase are also very welcome,
but the copyright must be assigned in writing to preserve the
licensing flexibility.
For more information about libart, see the web page:
http://www.levien.com/libart/
Welcome to the libart source tree!
This code is being developed in a "free software for sale"
model. Thus, it's available under a free software license (LGPL for
this module), but I'm also requesting that for all changes to the code
the copyright gets assigned back to me.
So if you want to contribute, please do, but contact me about getting
the copyright assigned. Otherwise, I will have to back your changes
out.
Thanks!
Raph Levien <raph@acm.org>
#undef PACKAGE
#undef VERSION
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* Basic constructors and operations for bezier paths */
#include <math.h>
#include "art_misc.h"
#include "art_bpath.h"
/* Result (x', y') = (matrix[0] * x + matrix[2] * y + matrix[4],
matrix[1] * x + matrix[3] * y + matrix[5])
Returns newly allocated transformed path. */
ArtBpath *
bpath_affine_transform (const ArtBpath *src, const double matrix[6])
{
int i;
int size;
ArtBpath *new;
double x, y;
for (i = 0; src[i].code != ART_END; i++);
size = i;
new = art_new (ArtBpath, size + 1);
for (i = 0; i < size; i++)
{
new[i].code = src[i].code;
x = src[i].x1;
y = src[i].y1;
new[i].x1 = matrix[0] * x + matrix[2] * y + matrix[4];
new[i].y1 = matrix[1] * x + matrix[3] * y + matrix[5];
x = src[i].x2;
y = src[i].y2;
new[i].x2 = matrix[0] * x + matrix[2] * y + matrix[4];
new[i].y2 = matrix[1] * x + matrix[3] * y + matrix[5];
x = src[i].x3;
y = src[i].y3;
new[i].x3 = matrix[0] * x + matrix[2] * y + matrix[4];
new[i].y3 = matrix[1] * x + matrix[3] * y + matrix[5];
}
new[i].code = ART_END;
return new;
}
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __ART_BPATH_H__
#define __ART_BPATH_H__
#include <art_point.h>
#include <art_pathcode.h>
/* Basic data structures and constructors for bezier paths */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _ArtBpath ArtBpath;
struct _ArtBpath {
ArtPathcode code;
double x1;
double y1;
double x2;
double y2;
double x3;
double y3;
};
ArtBpath *
art_bpath_affine_transform (const ArtBpath *src, const double matrix[6]);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __ART_BPATH_H__ */
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* Various utility functions RLL finds useful. */
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include "art_misc.h"
/* Print the error message to stdout and exit with a return code of 1 */
void
art_die (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
exit (1);
}
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* Simple macros to set up storage allocation and basic types for libart
functions. */
#ifndef __ART_MISC_H__
#define __ART_MISC_H__
#include <stdlib.h> /* for malloc, etc. */
#define art_alloc malloc
#define art_free free
#define art_realloc realloc
/* These aren't, strictly speaking, configuration macros, but they're
damn handy to have around, and may be worth playing with for
debugging. */
#define art_new(type, n) ((type *)art_alloc ((n) * sizeof(type)))
#define art_renew(p, type, n) ((type *)art_realloc (p, (n) * sizeof(type)))
/* This one must be used carefully - in particular, p and max should
be variables. They can also be pstruct->el lvalues. */
#define art_expand(p, type, max) p = art_renew (p, type, max <<= 1)
typedef int art_boolean;
#define ART_FALSE 0
#define ART_TRUE 1
/* define pi */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
/* These will be true on all platforms I care about. Nonetheless, it
should be autoconf'ed. */
typedef unsigned char art_u8;
typedef unsigned int art_u32;
void
art_die (const char *fmt, ...);
#endif /* __ART_MISC_H__ */
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __ART_PATHCODE_H__
#define __ART_PATHCODE_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* I probably want to add an ART_MOVETO_OPEN */
typedef enum {
ART_MOVETO,
ART_CURVETO,
ART_LINETO,
ART_END
} ArtPathcode;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __ART_PATHCODE_H__ */
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __ART_POINT_H__
#define __ART_POINT_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _ArtPoint ArtPoint;
struct _ArtPoint {
double x, y;
};
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __ART_POINT_H__ */
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include "art_misc.h"
#include "art_rect.h"
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif /* MAX */
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif /* MIN */
/* rectangle primitives stolen from gzilla */
/* Make a copy of the rectangle. */
void
art_irect_copy (ArtIRect *dest, const ArtIRect *src) {
dest->x0 = src->x0;
dest->y0 = src->y0;
dest->x1 = src->x1;
dest->y1 = src->y1;
}
/* Find the smallest rectangle that includes both source rectangles. */
void
art_irect_union (ArtIRect *dest, const ArtIRect *src1, const ArtIRect *src2) {
if (art_irect_empty (src1)) {
art_irect_copy (dest, src2);
} else if (art_irect_empty (src2)) {
art_irect_copy (dest, src1);
} else {
dest->x0 = MIN (src1->x0, src2->x0);
dest->y0 = MIN (src1->y0, src2->y0);
dest->x1 = MAX (src1->x1, src2->x1);
dest->y1 = MAX (src1->y1, src2->y1);
}
}
/* Return the intersection of the two rectangles */
void
art_irect_intersect (ArtIRect *dest, const ArtIRect *src1, const ArtIRect *src2) {
dest->x0 = MAX (src1->x0, src2->x0);
dest->y0 = MAX (src1->y0, src2->y0);
dest->x1 = MIN (src1->x1, src2->x1);
dest->y1 = MIN (src1->y1, src2->y1);
}
/* Return true if the rectangle is empty. */
int
art_irect_empty (const ArtIRect *src) {
return (src->x1 <= src->x0 || src->y1 <= src->y0);
}
#if 0
gboolean irect_point_inside (ArtIRect *rect, GzwPoint *point) {
return (point->x >= rect->x0 && point->y >= rect->y0 &&
point->x < rect->x1 && point->y < rect->y1);
}
#endif
void
art_bbox_affine_transform (ArtDRect *dst, const ArtDRect *src, const double matrix[6])
{
double x0, y0, x1, y1;
/* note: this only works for 90 degree rotations */
x0 = src->x0 * matrix[0] + src->y0 * matrix[2] + matrix[4];
y0 = src->x0 * matrix[1] + src->y0 * matrix[3] + matrix[5];
x1 = src->x1 * matrix[0] + src->y1 * matrix[2] + matrix[4];
y1 = src->x1 * matrix[1] + src->y1 * matrix[3] + matrix[5];
dst->x0 = MIN (x0, x1);
dst->x1 = MAX (x0, x1);
dst->y0 = MIN (y0, y1);
dst->y1 = MAX (y0, y1);
}
void
art_drect_to_irect (ArtIRect *dst, ArtDRect *src)
{
dst->x0 = floor (src->x0);
dst->y0 = floor (src->y0);
dst->x1 = ceil (src->x1);
dst->y1 = ceil (src->y1);
}
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __ART_RECT_H__
#define __ART_RECT_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _ArtDRect ArtDRect;
typedef struct _ArtIRect ArtIRect;
struct _ArtDRect {
double x0, y0, x1, y1;
};
struct _ArtIRect {
int x0, y0, x1, y1;
};
/* Make a copy of the rectangle. */
void art_irect_copy (ArtIRect *dest, const ArtIRect *src);
/* Find the smallest rectangle that includes both source rectangles. */
void art_irect_union (ArtIRect *dest,
const ArtIRect *src1, const ArtIRect *src2);
/* Return the intersection of the two rectangles */
void art_irect_intersect (ArtIRect *dest,
const ArtIRect *src1, const ArtIRect *src2);
/* Return true if the rectangle is empty. */
int art_irect_empty (const ArtIRect *src);
void
art_drect_affine_transform (ArtDRect *dst, const ArtDRect *src,
const double matrix[6]);
void art_drect_to_irect (ArtIRect *dst, ArtDRect *src);
#ifdef __cplusplus
}
#endif
#endif
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "art_misc.h"
#include "art_uta.h"
#include "art_rect.h"
#include "art_rect_uta.h"
/* Functions to decompose a microtile array into a list of rectangles. */
/* Allocate a new list of rectangles, set *p_nrects to the number in
the list.
Each rectangle bounded in size by (max_width, max_height). However,
these bounds must be at least the size of one tile.
This routine provides a precise implementation, i.e. the rectangles
cover exactly the same area as the uta. It is thus appropriate in
cases where the overhead per rectangle is small compared with the
cost of filling in extra pixels. */
ArtIRect *
art_rect_list_from_uta (ArtUta *uta, int max_width, int max_height,
int *p_nrects)
{
ArtIRect *rects;
int n_rects, n_rects_max;
int x, y;
int width, height;
int ix;
int left_ix;
ArtUtaBbox *utiles;
ArtUtaBbox bb;
int x0, y0, x1, y1;
int *glom;
int glom_rect;
n_rects = 0;
n_rects_max = 1;
rects = art_new (ArtIRect, n_rects_max);
width = uta->width;
height = uta->height;
utiles = uta->utiles;
glom = art_new (int, width * height);
for (ix = 0; ix < width * height; ix++)
glom[ix] = -1;
ix = 0;
for (y = 0; y < height; y++)
for (x = 0; x < width; x++)
{
bb = utiles[ix];
if (bb)
{
x0 = ((uta->x0 + x) << ART_UTILE_SHIFT) + ART_UTA_BBOX_X0(bb);
y0 = ((uta->y0 + y) << ART_UTILE_SHIFT) + ART_UTA_BBOX_Y0(bb);
y1 = ((uta->y0 + y) << ART_UTILE_SHIFT) + ART_UTA_BBOX_Y1(bb);
left_ix = ix;
/* now try to extend to the right */
while (x != width - 1 &&
ART_UTA_BBOX_X1(bb) == ART_UTILE_SIZE &&
(((bb & 0xffffff) ^ utiles[ix + 1]) & 0xffff00ff) == 0 &&
(((uta->x0 + x + 1) << ART_UTILE_SHIFT) +
ART_UTA_BBOX_X1(utiles[ix + 1]) -
x0) <= max_width)
{
bb = utiles[ix + 1];
ix++;
x++;
}
x1 = ((uta->x0 + x) << ART_UTILE_SHIFT) + ART_UTA_BBOX_X1(bb);
/* if rectangle nonempty */
if ((x1 ^ x0) | (y1 ^ y0))
{
/* try to glom onto an existing rectangle */
glom_rect = glom[left_ix];
if (glom_rect != -1 &&
x0 == rects[glom_rect].x0 &&
x1 == rects[glom_rect].x1 &&
y0 == rects[glom_rect].y1 &&
y1 - rects[glom_rect].y0 <= max_height)
{
rects[glom_rect].y1 = y1;
}
else
{
if (n_rects == n_rects_max)
art_expand (rects, ArtIRect, n_rects_max);
rects[n_rects].x0 = x0;
rects[n_rects].y0 = y0;
rects[n_rects].x1 = x1;
rects[n_rects].y1 = y1;
glom_rect = n_rects;
n_rects++;
}
if (y != height - 1)
glom[left_ix + width] = glom_rect;
}
}
ix++;
}
art_free (glom);
*p_nrects = n_rects;
return rects;
}
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __ART_RECT_UTA_H__
#define __ART_RECT_UTA_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
ArtIRect *
art_rect_list_from_uta (ArtUta *uta, int max_width, int max_height,
int *p_nrects);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __ART_UTA_RECT_H__ */
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*