/src/xpdf-4.06/splash/SplashState.cc
Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // SplashState.cc |
4 | | // |
5 | | // Copyright 2003-2013 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #include <aconf.h> |
10 | | |
11 | | #include <string.h> |
12 | | #include "gmem.h" |
13 | | #include "gmempp.h" |
14 | | #include "SplashPattern.h" |
15 | | #include "SplashScreen.h" |
16 | | #include "SplashClip.h" |
17 | | #include "SplashBitmap.h" |
18 | | #include "SplashState.h" |
19 | | |
20 | | //------------------------------------------------------------------------ |
21 | | // SplashState |
22 | | //------------------------------------------------------------------------ |
23 | | |
24 | | // number of components in each color mode |
25 | | int splashColorModeNComps[] = { |
26 | | 1, 1, 3, 3 |
27 | | #if SPLASH_CMYK |
28 | | , 4 |
29 | | #endif |
30 | | }; |
31 | | |
32 | | SplashState::SplashState(int width, int height, GBool vectorAntialias, |
33 | 208k | SplashScreenParams *screenParams) { |
34 | 208k | SplashColor color; |
35 | 208k | int i; |
36 | | |
37 | 208k | matrix[0] = 1; matrix[1] = 0; |
38 | 208k | matrix[2] = 0; matrix[3] = 1; |
39 | 208k | matrix[4] = 0; matrix[5] = 0; |
40 | 208k | memset(&color, 0, sizeof(SplashColor)); |
41 | 208k | strokePattern = new SplashSolidColor(color); |
42 | 208k | fillPattern = new SplashSolidColor(color); |
43 | 208k | screen = new SplashScreen(screenParams); |
44 | 208k | blendFunc = NULL; |
45 | 208k | strokeAlpha = 1; |
46 | 208k | fillAlpha = 1; |
47 | 208k | lineWidth = 1; |
48 | 208k | lineCap = splashLineCapButt; |
49 | 208k | lineJoin = splashLineJoinMiter; |
50 | 208k | miterLimit = 10; |
51 | 208k | flatness = 1; |
52 | 208k | lineDash = NULL; |
53 | 208k | lineDashLength = 0; |
54 | 208k | lineDashPhase = 0; |
55 | 208k | strokeAdjust = splashStrokeAdjustOff; |
56 | 208k | alphaIsShape = gFalse; |
57 | 208k | clip = new SplashClip(0, 0, width, height); |
58 | 208k | clipIsShared = gFalse; |
59 | 208k | softMask = NULL; |
60 | 208k | deleteSoftMask = gFalse; |
61 | 208k | inNonIsolatedGroup = gFalse; |
62 | 208k | inKnockoutGroup = gFalse; |
63 | 208k | #if SPLASH_CMYK |
64 | 208k | rgbTransferR = (Guchar *)gmalloc(8 * 256); |
65 | 208k | rgbTransferG = rgbTransferR + 256; |
66 | 208k | rgbTransferB = rgbTransferG + 256; |
67 | 208k | grayTransfer = rgbTransferB + 256; |
68 | 208k | cmykTransferC = grayTransfer + 256; |
69 | 208k | cmykTransferM = cmykTransferC + 256; |
70 | 208k | cmykTransferY = cmykTransferM + 256; |
71 | 208k | cmykTransferK = cmykTransferY + 256; |
72 | | #else |
73 | | rgbTransferR = (Guchar *)gmalloc(4 * 256); |
74 | | rgbTransferG = rgbTransferR + 256; |
75 | | rgbTransferB = rgbTransferG + 256; |
76 | | grayTransfer = rgbTransferB + 256; |
77 | | #endif |
78 | 53.6M | for (i = 0; i < 256; ++i) { |
79 | 53.4M | rgbTransferR[i] = (Guchar)i; |
80 | 53.4M | rgbTransferG[i] = (Guchar)i; |
81 | 53.4M | rgbTransferB[i] = (Guchar)i; |
82 | 53.4M | grayTransfer[i] = (Guchar)i; |
83 | 53.4M | #if SPLASH_CMYK |
84 | 53.4M | cmykTransferC[i] = (Guchar)i; |
85 | 53.4M | cmykTransferM[i] = (Guchar)i; |
86 | 53.4M | cmykTransferY[i] = (Guchar)i; |
87 | 53.4M | cmykTransferK[i] = (Guchar)i; |
88 | 53.4M | #endif |
89 | 53.4M | } |
90 | 208k | transferIsShared = gFalse; |
91 | 208k | overprintMask = 0xffffffff; |
92 | 208k | enablePathSimplification = gFalse; |
93 | 208k | next = NULL; |
94 | 208k | } |
95 | | |
96 | | SplashState::SplashState(int width, int height, GBool vectorAntialias, |
97 | 8.03k | SplashScreen *screenA) { |
98 | 8.03k | SplashColor color; |
99 | 8.03k | int i; |
100 | | |
101 | 8.03k | matrix[0] = 1; matrix[1] = 0; |
102 | 8.03k | matrix[2] = 0; matrix[3] = 1; |
103 | 8.03k | matrix[4] = 0; matrix[5] = 0; |
104 | 8.03k | memset(&color, 0, sizeof(SplashColor)); |
105 | 8.03k | strokePattern = new SplashSolidColor(color); |
106 | 8.03k | fillPattern = new SplashSolidColor(color); |
107 | 8.03k | screen = screenA->copy(); |
108 | 8.03k | blendFunc = NULL; |
109 | 8.03k | strokeAlpha = 1; |
110 | 8.03k | fillAlpha = 1; |
111 | 8.03k | lineWidth = 1; |
112 | 8.03k | lineCap = splashLineCapButt; |
113 | 8.03k | lineJoin = splashLineJoinMiter; |
114 | 8.03k | miterLimit = 10; |
115 | 8.03k | flatness = 1; |
116 | 8.03k | lineDash = NULL; |
117 | 8.03k | lineDashLength = 0; |
118 | 8.03k | lineDashPhase = 0; |
119 | 8.03k | strokeAdjust = splashStrokeAdjustOff; |
120 | 8.03k | alphaIsShape = gFalse; |
121 | 8.03k | clip = new SplashClip(0, 0, width, height); |
122 | 8.03k | clipIsShared = gFalse; |
123 | 8.03k | softMask = NULL; |
124 | 8.03k | deleteSoftMask = gFalse; |
125 | 8.03k | inNonIsolatedGroup = gFalse; |
126 | 8.03k | inKnockoutGroup = gFalse; |
127 | 8.03k | #if SPLASH_CMYK |
128 | 8.03k | rgbTransferR = (Guchar *)gmalloc(8 * 256); |
129 | 8.03k | rgbTransferG = rgbTransferR + 256; |
130 | 8.03k | rgbTransferB = rgbTransferG + 256; |
131 | 8.03k | grayTransfer = rgbTransferB + 256; |
132 | 8.03k | cmykTransferC = grayTransfer + 256; |
133 | 8.03k | cmykTransferM = cmykTransferC + 256; |
134 | 8.03k | cmykTransferY = cmykTransferM + 256; |
135 | 8.03k | cmykTransferK = cmykTransferY + 256; |
136 | | #else |
137 | | rgbTransferR = (Guchar *)gmalloc(4 * 256); |
138 | | rgbTransferG = rgbTransferR + 256; |
139 | | rgbTransferB = rgbTransferG + 256; |
140 | | grayTransfer = rgbTransferB + 256; |
141 | | #endif |
142 | 2.06M | for (i = 0; i < 256; ++i) { |
143 | 2.05M | rgbTransferR[i] = (Guchar)i; |
144 | 2.05M | rgbTransferG[i] = (Guchar)i; |
145 | 2.05M | rgbTransferB[i] = (Guchar)i; |
146 | 2.05M | grayTransfer[i] = (Guchar)i; |
147 | 2.05M | #if SPLASH_CMYK |
148 | 2.05M | cmykTransferC[i] = (Guchar)i; |
149 | 2.05M | cmykTransferM[i] = (Guchar)i; |
150 | 2.05M | cmykTransferY[i] = (Guchar)i; |
151 | 2.05M | cmykTransferK[i] = (Guchar)i; |
152 | 2.05M | #endif |
153 | 2.05M | } |
154 | 8.03k | transferIsShared = gFalse; |
155 | 8.03k | overprintMask = 0xffffffff; |
156 | 8.03k | enablePathSimplification = gFalse; |
157 | 8.03k | next = NULL; |
158 | 8.03k | } |
159 | | |
160 | 2.81M | SplashState::SplashState(SplashState *state) { |
161 | 2.81M | memcpy(matrix, state->matrix, 6 * sizeof(SplashCoord)); |
162 | 2.81M | strokePattern = state->strokePattern->copy(); |
163 | 2.81M | fillPattern = state->fillPattern->copy(); |
164 | 2.81M | screen = state->screen->copy(); |
165 | 2.81M | blendFunc = state->blendFunc; |
166 | 2.81M | strokeAlpha = state->strokeAlpha; |
167 | 2.81M | fillAlpha = state->fillAlpha; |
168 | 2.81M | lineWidth = state->lineWidth; |
169 | 2.81M | lineCap = state->lineCap; |
170 | 2.81M | lineJoin = state->lineJoin; |
171 | 2.81M | miterLimit = state->miterLimit; |
172 | 2.81M | flatness = state->flatness; |
173 | 2.81M | if (state->lineDash) { |
174 | 2.17k | lineDashLength = state->lineDashLength; |
175 | 2.17k | lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord)); |
176 | 2.17k | memcpy(lineDash, state->lineDash, lineDashLength * sizeof(SplashCoord)); |
177 | 2.81M | } else { |
178 | 2.81M | lineDash = NULL; |
179 | 2.81M | lineDashLength = 0; |
180 | 2.81M | } |
181 | 2.81M | lineDashPhase = state->lineDashPhase; |
182 | 2.81M | strokeAdjust = state->strokeAdjust; |
183 | 2.81M | alphaIsShape = state->alphaIsShape; |
184 | 2.81M | clip = state->clip; |
185 | 2.81M | clipIsShared = gTrue; |
186 | 2.81M | softMask = state->softMask; |
187 | 2.81M | deleteSoftMask = gFalse; |
188 | 2.81M | inNonIsolatedGroup = state->inNonIsolatedGroup; |
189 | 2.81M | inKnockoutGroup = state->inKnockoutGroup; |
190 | 2.81M | rgbTransferR = state->rgbTransferR; |
191 | 2.81M | rgbTransferG = state->rgbTransferG; |
192 | 2.81M | rgbTransferB = state->rgbTransferB; |
193 | 2.81M | grayTransfer = state->grayTransfer; |
194 | 2.81M | #if SPLASH_CMYK |
195 | 2.81M | cmykTransferC = state->cmykTransferC; |
196 | 2.81M | cmykTransferM = state->cmykTransferM; |
197 | 2.81M | cmykTransferY = state->cmykTransferY; |
198 | 2.81M | cmykTransferK = state->cmykTransferK; |
199 | 2.81M | #endif |
200 | 2.81M | transferIsShared = gTrue; |
201 | 2.81M | overprintMask = state->overprintMask; |
202 | 2.81M | enablePathSimplification = state->enablePathSimplification; |
203 | 2.81M | next = NULL; |
204 | 2.81M | } |
205 | | |
206 | 3.03M | SplashState::~SplashState() { |
207 | 3.03M | delete strokePattern; |
208 | 3.03M | delete fillPattern; |
209 | 3.03M | delete screen; |
210 | 3.03M | gfree(lineDash); |
211 | 3.03M | if (!clipIsShared) { |
212 | 345k | delete clip; |
213 | 345k | } |
214 | 3.03M | if (!transferIsShared) { |
215 | 217k | gfree(rgbTransferR); |
216 | 217k | } |
217 | 3.03M | if (deleteSoftMask && softMask) { |
218 | 1.41k | delete softMask; |
219 | 1.41k | } |
220 | 3.03M | } |
221 | | |
222 | 491k | void SplashState::setStrokePattern(SplashPattern *strokePatternA) { |
223 | 491k | delete strokePattern; |
224 | 491k | strokePattern = strokePatternA; |
225 | 491k | } |
226 | | |
227 | 1.95M | void SplashState::setFillPattern(SplashPattern *fillPatternA) { |
228 | 1.95M | delete fillPattern; |
229 | 1.95M | fillPattern = fillPatternA; |
230 | 1.95M | } |
231 | | |
232 | 0 | void SplashState::setScreen(SplashScreen *screenA) { |
233 | 0 | delete screen; |
234 | 0 | screen = screenA; |
235 | 0 | } |
236 | | |
237 | | void SplashState::setLineDash(SplashCoord *lineDashA, int lineDashLengthA, |
238 | 403k | SplashCoord lineDashPhaseA) { |
239 | 403k | gfree(lineDash); |
240 | 403k | lineDashLength = lineDashLengthA; |
241 | 403k | if (lineDashLength > 0) { |
242 | 910 | lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord)); |
243 | 910 | memcpy(lineDash, lineDashA, lineDashLength * sizeof(SplashCoord)); |
244 | 402k | } else { |
245 | 402k | lineDash = NULL; |
246 | 402k | } |
247 | 403k | lineDashPhase = lineDashPhaseA; |
248 | 403k | } |
249 | | |
250 | 0 | GBool SplashState::lineDashContainsZeroLengthDashes() { |
251 | 0 | int i; |
252 | |
|
253 | 0 | if (lineDashLength == 0) { |
254 | 0 | return gFalse; |
255 | 0 | } |
256 | | |
257 | | // if the line dash array has an odd number of elements, we need to |
258 | | // check all of the elements; if the length is even, we only need to |
259 | | // check even-number elements |
260 | 0 | if (lineDashLength & 1) { |
261 | 0 | for (i = 0; i < lineDashLength; ++i) { |
262 | 0 | if (lineDash[i] == 0) { |
263 | 0 | return gTrue; |
264 | 0 | } |
265 | 0 | } |
266 | 0 | } else { |
267 | 0 | for (i = 0; i < lineDashLength; i += 2) { |
268 | 0 | if (lineDash[i] == 0) { |
269 | 0 | return gTrue; |
270 | 0 | } |
271 | 0 | } |
272 | 0 | } |
273 | 0 | return gFalse; |
274 | 0 | } |
275 | | |
276 | | void SplashState::clipResetToRect(SplashCoord x0, SplashCoord y0, |
277 | 0 | SplashCoord x1, SplashCoord y1) { |
278 | 0 | if (clipIsShared) { |
279 | 0 | clip = clip->copy(); |
280 | 0 | clipIsShared = gFalse; |
281 | 0 | } |
282 | 0 | clip->resetToRect(x0, y0, x1, y1); |
283 | 0 | } |
284 | | |
285 | | SplashError SplashState::clipToRect(SplashCoord x0, SplashCoord y0, |
286 | 0 | SplashCoord x1, SplashCoord y1) { |
287 | 0 | if (clipIsShared) { |
288 | 0 | clip = clip->copy(); |
289 | 0 | clipIsShared = gFalse; |
290 | 0 | } |
291 | 0 | return clip->clipToRect(x0, y0, x1, y1); |
292 | 0 | } |
293 | | |
294 | 176k | SplashError SplashState::clipToPath(SplashPath *path, GBool eo) { |
295 | 176k | if (clipIsShared) { |
296 | 128k | clip = clip->copy(); |
297 | 128k | clipIsShared = gFalse; |
298 | 128k | } |
299 | 176k | return clip->clipToPath(path, matrix, flatness, eo, |
300 | 176k | enablePathSimplification, strokeAdjust); |
301 | 176k | } |
302 | | |
303 | 12.4k | void SplashState::setSoftMask(SplashBitmap *softMaskA, GBool deleteBitmap) { |
304 | 12.4k | if (deleteSoftMask) { |
305 | 3.01k | delete softMask; |
306 | 3.01k | } |
307 | 12.4k | softMask = softMaskA; |
308 | 12.4k | deleteSoftMask = deleteBitmap; |
309 | 12.4k | } |
310 | | |
311 | | void SplashState::setTransfer(Guchar *red, Guchar *green, Guchar *blue, |
312 | 598 | Guchar *gray) { |
313 | 598 | #if SPLASH_CMYK |
314 | 598 | int i; |
315 | 598 | #endif |
316 | | |
317 | 598 | if (transferIsShared) { |
318 | 536 | #if SPLASH_CMYK |
319 | 536 | rgbTransferR = (Guchar *)gmalloc(8 * 256); |
320 | 536 | rgbTransferG = rgbTransferR + 256; |
321 | 536 | rgbTransferB = rgbTransferG + 256; |
322 | 536 | grayTransfer = rgbTransferB + 256; |
323 | 536 | cmykTransferC = grayTransfer + 256; |
324 | 536 | cmykTransferM = cmykTransferC + 256; |
325 | 536 | cmykTransferY = cmykTransferM + 256; |
326 | 536 | cmykTransferK = cmykTransferY + 256; |
327 | | #else |
328 | | rgbTransferR = (Guchar *)gmalloc(4 * 256); |
329 | | rgbTransferG = rgbTransferR + 256; |
330 | | rgbTransferB = rgbTransferG + 256; |
331 | | grayTransfer = rgbTransferB + 256; |
332 | | #endif |
333 | 536 | transferIsShared = gFalse; |
334 | 536 | } |
335 | 598 | memcpy(rgbTransferR, red, 256); |
336 | 598 | memcpy(rgbTransferG, green, 256); |
337 | 598 | memcpy(rgbTransferB, blue, 256); |
338 | 598 | memcpy(grayTransfer, gray, 256); |
339 | 598 | #if SPLASH_CMYK |
340 | 153k | for (i = 0; i < 256; ++i) { |
341 | 153k | cmykTransferC[i] = (Guchar)(255 - rgbTransferR[255 - i]); |
342 | 153k | cmykTransferM[i] = (Guchar)(255 - rgbTransferG[255 - i]); |
343 | 153k | cmykTransferY[i] = (Guchar)(255 - rgbTransferB[255 - i]); |
344 | 153k | cmykTransferK[i] = (Guchar)(255 - grayTransfer[255 - i]); |
345 | 153k | } |
346 | 598 | #endif |
347 | 598 | } |
348 | | |