comparison mupdf-source/include/mupdf/fitz/shade.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // Copyright (C) 2004-2025 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #ifndef MUPDF_FITZ_SHADE_H
24 #define MUPDF_FITZ_SHADE_H
25
26 #include "mupdf/fitz/system.h"
27 #include "mupdf/fitz/context.h"
28 #include "mupdf/fitz/geometry.h"
29 #include "mupdf/fitz/store.h"
30 #include "mupdf/fitz/pixmap.h"
31 #include "mupdf/fitz/compressed-buffer.h"
32
33 /**
34 * The shading code uses gouraud shaded triangle meshes.
35 */
36
37 enum
38 {
39 FZ_FUNCTION_BASED = 1,
40 FZ_LINEAR = 2,
41 FZ_RADIAL = 3,
42 FZ_MESH_TYPE4 = 4,
43 FZ_MESH_TYPE5 = 5,
44 FZ_MESH_TYPE6 = 6,
45 FZ_MESH_TYPE7 = 7
46 };
47
48 /**
49 Structure is public to allow derived classes. Do not
50 access the members directly.
51 */
52 typedef struct
53 {
54 fz_storable storable;
55
56 fz_rect bbox; /* can be fz_infinite_rect */
57 fz_colorspace *colorspace;
58
59 fz_matrix matrix; /* matrix from pattern dict */
60 int use_background; /* background color for fills but not 'sh' */
61 float background[FZ_MAX_COLORS];
62
63 /* Just to be confusing, PDF Shadings of Type 1 (Function Based
64 * Shadings), do NOT use function, but all the others do. This
65 * is because Type 1 shadings take 2 inputs, whereas all the
66 * others (when used with a function take 1 input. The type 1
67 * data is in the 'f' field of the union below. */
68 /* If function_stride = 0, then function is not used. Otherwise
69 * function points to 256*function_stride entries. */
70 int function_stride;
71 float *function;
72
73 int type; /* function, linear, radial, mesh */
74 union
75 {
76 struct
77 {
78 int extend[2];
79 float coords[2][3]; /* (x,y,r) twice */
80 } l_or_r;
81 struct
82 {
83 int vprow;
84 int bpflag;
85 int bpcoord;
86 int bpcomp;
87 float x0, x1;
88 float y0, y1;
89 float c0[FZ_MAX_COLORS];
90 float c1[FZ_MAX_COLORS];
91 } m;
92 struct
93 {
94 fz_matrix matrix;
95 int xdivs;
96 int ydivs;
97 float domain[2][2];
98 float *fn_vals;
99 } f;
100 } u;
101
102 fz_compressed_buffer *buffer;
103 } fz_shade;
104
105 /**
106 Increment the reference count for the shade structure. The
107 same pointer is returned.
108
109 Never throws exceptions.
110 */
111 fz_shade *fz_keep_shade(fz_context *ctx, fz_shade *shade);
112
113 /**
114 Decrement the reference count for the shade structure. When
115 the reference count hits zero, the structure is freed.
116
117 Never throws exceptions.
118 */
119 void fz_drop_shade(fz_context *ctx, fz_shade *shade);
120
121 /**
122 Bound a given shading.
123
124 shade: The shade to bound.
125
126 ctm: The transform to apply to the shade before bounding.
127
128 r: Pointer to storage to put the bounds in.
129
130 Returns r, updated to contain the bounds for the shading.
131 */
132 fz_rect fz_bound_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm);
133
134 typedef struct fz_shade_color_cache fz_shade_color_cache;
135
136 void fz_drop_shade_color_cache(fz_context *ctx, fz_shade_color_cache *cache);
137
138 /**
139 Render a shade to a given pixmap.
140
141 shade: The shade to paint.
142
143 override_cs: NULL, or colorspace to override the shades
144 inbuilt colorspace.
145
146 ctm: The transform to apply.
147
148 dest: The pixmap to render into.
149
150 color_params: The color rendering settings
151
152 bbox: Pointer to a bounding box to limit the rendering
153 of the shade.
154
155 eop: NULL, or pointer to overprint bitmap.
156
157 cache: *cache is used to cache color information. If *cache is NULL it
158 is set to point to a new fz_shade_color_cache. If cache is NULL it is
159 ignored.
160 */
161 void fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_colorspace *override_cs, fz_matrix ctm, fz_pixmap *dest, fz_color_params color_params, fz_irect bbox, const fz_overprint *eop, fz_shade_color_cache **cache);
162
163 /**
164 * Handy routine for processing mesh based shades
165 */
166 typedef struct
167 {
168 fz_point p;
169 float c[FZ_MAX_COLORS];
170 } fz_vertex;
171
172 /**
173 Callback function type for use with
174 fz_process_shade.
175
176 arg: Opaque pointer from fz_process_shade caller.
177
178 v: Pointer to a fz_vertex structure to populate.
179
180 c: Pointer to an array of floats used to populate v.
181 */
182 typedef void (fz_shade_prepare_fn)(fz_context *ctx, void *arg, fz_vertex *v, const float *c);
183
184 /**
185 Callback function type for use with
186 fz_process_shade.
187
188 arg: Opaque pointer from fz_process_shade caller.
189
190 av, bv, cv: Pointers to a fz_vertex structure describing
191 the corner locations and colors of a triangle to be
192 filled.
193 */
194 typedef void (fz_shade_process_fn)(fz_context *ctx, void *arg, fz_vertex *av, fz_vertex *bv, fz_vertex *cv);
195
196 /**
197 Process a shade, using supplied callback functions. This
198 decomposes the shading to a mesh (even ones that are not
199 natively meshes, such as linear or radial shadings), and
200 processes triangles from those meshes.
201
202 shade: The shade to process.
203
204 ctm: The transform to use
205
206 prepare: Callback function to 'prepare' each vertex.
207 This function is passed an array of floats, and populates
208 a fz_vertex structure.
209
210 process: This function is passed 3 pointers to vertex
211 structures, and actually performs the processing (typically
212 filling the area between the vertices).
213
214 process_arg: An opaque argument passed through from caller
215 to callback functions.
216 */
217 void fz_process_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_rect scissor,
218 fz_shade_prepare_fn *prepare,
219 fz_shade_process_fn *process,
220 void *process_arg);
221
222
223 /* Implementation details: subject to change. */
224
225 /**
226 Internal function to destroy a
227 shade. Only exposed for use with the fz_store.
228
229 shade: The reference to destroy.
230 */
231 void fz_drop_shade_imp(fz_context *ctx, fz_storable *shade);
232
233 #endif