1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gxshade4.h 8132 2007-07-16 21:24:42Z leonardo $ */
15
/* Internal definitions for triangle shading rendering */
17
#ifndef gxshade4_INCLUDED
18
# define gxshade4_INCLUDED
20
/* Configuration flags for development needs only. Users should not modify them. */
21
#define USE_LINEAR_COLOR_PROCS 1 /* Old code = 0, new code = 1. */
23
#define QUADRANGLES 0 /* 0 = decompose by triangles, 1 = by quadrangles. */
24
/* The code QUADRANGLES 1 appears unuseful.
25
We keep it because it stores a valuable code for constant_color_quadrangle,
26
which decomposes a random quadrangle into 3 or 4 trapezoids.
27
The color approximation looks worse than with triangles, and works some slower.
29
#define INTERPATCH_PADDING (fixed_1 / 2) /* Emulate a trapping for poorly designed documents. */
30
/* When INTERPATCH_PADDING > 0, it generates paddings between patches,
31
i.e. performs a patch expansion, being similar
32
to the path adjustment in the filling algorithm.
33
The expansion is an emulation of Adobe's trapping.
34
The value specifies the width of paddings.
35
We did some testing of Adobe RIP, and it looks as applying
36
same logicks as for clipping - any part of pixel inside.
37
Therefore the expansion should be half pixel size.
39
#define COLOR_CONTIGUITY 1 /* A smothness divisor for triangulation. */
40
/* This is a coefficient used to rich
41
a better color contiguity. The value 1 corresponds to PLRM,
42
bigger values mean more contiguity. The speed decreases as
43
a square of COLOR_CONTIGUITY.
45
#define LAZY_WEDGES 1 /* 0 = fill immediately, 1 = fill lazy. */
46
/* This mode delays creating wedges for a boundary until
47
both neoghbour areas are painted. At that moment we can know
48
all subdivision points for both right and left areas,
49
and skip wedges for common points. Therefore the number of wadges
50
dramatically reduces, causing a significant speedup.
51
The LAZY_WEDGES 0 mode was not systematically tested.
53
#define VD_TRACE_DOWN 1 /* Developer's needs, not important for production. */
54
#define NOFILL_TEST 0 /* Developer's needs, must be off for production. */
55
#define SKIP_TEST 0 /* Developer's needs, must be off for production. */
56
/* End of configuration flags (we don't mean that users should modify the rest). */
58
typedef struct mesh_frame_s { /* recursion frame */
59
mesh_vertex_t va, vb, vc; /* current vertices */
62
/****** NEED GC DESCRIPTOR ******/
65
* Define the fill state structure for triangle shadings. This is used
66
* both for the Gouraud triangle shading types and for the Coons and
69
* The shading pointer is named pshm rather than psh in case subclasses
70
* also want to store a pointer of a more specific type.
72
#define mesh_fill_state_common\
73
shading_fill_state_common;\
74
const gs_shading_mesh_t *pshm;\
76
typedef struct mesh_fill_state_s {
77
mesh_fill_state_common;
79
/****** NEED GC DESCRIPTOR ******/
81
typedef struct wedge_vertex_list_elem_s wedge_vertex_list_elem_t;
82
struct wedge_vertex_list_elem_s {
86
wedge_vertex_list_elem_t *next, *prev;
90
wedge_vertex_list_elem_t *beg, *end;
91
} wedge_vertex_list_t;
93
#define LAZY_WEDGES_MAX_LEVEL 9 /* memory consumption is
94
sizeof(wedge_vertex_list_elem_t) * LAZY_WEDGES_MAX_LEVEL * (1 << LAZY_WEDGES_MAX_LEVEL) */
96
#define SHADING_COLOR_STACK_SIZE 200; /* Should be enough for max 64 decomposition levels. */
98
/* Define a color to be used in curve rendering. */
99
/* This may be a real client color, or a parametric function argument. */
100
struct patch_color_s {
101
float t[2]; /* parametric value */
103
/* NOTE : The structure gs_client_color ends with a big array, but only few elements
104
are used in most cases. Therefore sometimes we allocate a shorter area,
105
so that ending elements are not allocated and must not be accessed/modified.
106
The number of allocated elements are known from the shading color space
107
and from patch_fill_state_s::num_components. */
110
#ifndef patch_color_t_DEFINED
111
# define patch_color_t_DEFINED
112
typedef struct patch_color_s patch_color_t;
115
#ifndef gs_color_index_cache_DEFINED
116
# define gs_color_index_cache_DEFINED
117
typedef struct gs_color_index_cache_s gs_color_index_cache_t;
120
#ifndef patch_fill_state_t_DEFINED
121
# define patch_fill_state_t_DEFINED
122
typedef struct patch_fill_state_s patch_fill_state_t;
125
/* Define the common state for rendering Coons and tensor patches. */
126
struct patch_fill_state_s {
127
mesh_fill_state_common;
128
const gs_function_t *Function;
129
int function_arg_shift;
132
fixed max_small_coord; /* Length restriction for intersection_of_small_bars. */
133
wedge_vertex_list_elem_t *wedge_vertex_list_elem_buffer;
134
wedge_vertex_list_elem_t *free_wedge_vertex;
135
int wedge_vertex_list_elem_count;
136
int wedge_vertex_list_elem_count_max;
137
gs_client_color color_domain;
138
fixed decomposition_limit;
141
bool maybe_self_intersecting;
142
bool monotonic_color;
146
int color_stack_size;
147
int color_stack_step;
148
byte *color_stack_ptr;
149
byte *color_stack; /* A storage for shortened patch_color_t structures. */
150
byte *color_stack_limit;
151
gs_memory_t *memory; /* Where color_buffer is allocated. */
152
gs_color_index_cache_t *pcic;
155
/* Define a structure for mesh or patch vertex. */
156
struct shading_vertex_s {
158
const patch_color_t *c;
161
/* Define one segment (vertex and next control points) of a curve. */
162
typedef struct patch_curve_s {
163
mesh_vertex_t vertex;
164
gs_fixed_point control[2];
169
const shading_vertex_t *p[2][2]; /* [v][u] */
170
wedge_vertex_list_t *l0001, *l0111, *l1110, *l1000;
173
/* Initialize the fill state for triangle shading. */
174
int mesh_init_fill_state(mesh_fill_state_t * pfs,
175
const gs_shading_mesh_t * psh,
176
const gs_fixed_rect * rect_clip,
177
gx_device * dev, gs_imager_state * pis);
179
int init_patch_fill_state(patch_fill_state_t *pfs);
180
bool term_patch_fill_state(patch_fill_state_t *pfs);
181
int gx_init_patch_fill_state_for_clist(gx_device *dev, patch_fill_state_t *pfs, gs_memory_t *memory);
183
int mesh_triangle(patch_fill_state_t *pfs,
184
const shading_vertex_t *p0, const shading_vertex_t *p1, const shading_vertex_t *p2);
186
int mesh_padding(patch_fill_state_t *pfs, const gs_fixed_point *p0, const gs_fixed_point *p1,
187
const patch_color_t *c0, const patch_color_t *c1);
189
int patch_fill(patch_fill_state_t * pfs, const patch_curve_t curve[4],
190
const gs_fixed_point interior[4],
191
void (*transform) (gs_fixed_point *, const patch_curve_t[4],
192
const gs_fixed_point[4], floatp, floatp));
194
int constant_color_quadrangle(patch_fill_state_t *pfs, const quadrangle_patch *p, bool self_intersecting);
196
int wedge_vertex_list_elem_buffer_alloc(patch_fill_state_t *pfs);
197
void wedge_vertex_list_elem_buffer_free(patch_fill_state_t *pfs);
199
void patch_resolve_color(patch_color_t * ppcr, const patch_fill_state_t *pfs);
201
int gx_shade_background(gx_device *pdev, const gs_fixed_rect *rect,
202
const gx_device_color *pdevc, gs_logical_operation_t log_op);
204
int patch_color_to_device_color(const patch_fill_state_t *pfs,
205
const patch_color_t *c, gx_device_color *pdevc);
207
byte *reserve_colors(patch_fill_state_t *pfs, patch_color_t *c0[], int n);
208
void release_colors(patch_fill_state_t *pfs, byte *ptr, int n);
210
dev_proc_fill_linear_color_triangle(gx_fill_triangle_small);
212
#endif /* gxshade4_INCLUDED */