/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 | 395k | SplashScreenParams *screenParams) { |
34 | 395k | SplashColor color; |
35 | 395k | int i; |
36 | | |
37 | 395k | matrix[0] = 1; matrix[1] = 0; |
38 | 395k | matrix[2] = 0; matrix[3] = 1; |
39 | 395k | matrix[4] = 0; matrix[5] = 0; |
40 | 395k | memset(&color, 0, sizeof(SplashColor)); |
41 | 395k | strokePattern = new SplashSolidColor(color); |
42 | 395k | fillPattern = new SplashSolidColor(color); |
43 | 395k | screen = new SplashScreen(screenParams); |
44 | 395k | blendFunc = NULL; |
45 | 395k | strokeAlpha = 1; |
46 | 395k | fillAlpha = 1; |
47 | 395k | lineWidth = 1; |
48 | 395k | lineCap = splashLineCapButt; |
49 | 395k | lineJoin = splashLineJoinMiter; |
50 | 395k | miterLimit = 10; |
51 | 395k | flatness = 1; |
52 | 395k | lineDash = NULL; |
53 | 395k | lineDashLength = 0; |
54 | 395k | lineDashPhase = 0; |
55 | 395k | strokeAdjust = splashStrokeAdjustOff; |
56 | 395k | alphaIsShape = gFalse; |
57 | 395k | clip = new SplashClip(0, 0, width, height); |
58 | 395k | clipIsShared = gFalse; |
59 | 395k | softMask = NULL; |
60 | 395k | deleteSoftMask = gFalse; |
61 | 395k | inNonIsolatedGroup = gFalse; |
62 | 395k | inKnockoutGroup = gFalse; |
63 | 395k | #if SPLASH_CMYK |
64 | 395k | rgbTransferR = (Guchar *)gmalloc(8 * 256); |
65 | 395k | rgbTransferG = rgbTransferR + 256; |
66 | 395k | rgbTransferB = rgbTransferG + 256; |
67 | 395k | grayTransfer = rgbTransferB + 256; |
68 | 395k | cmykTransferC = grayTransfer + 256; |
69 | 395k | cmykTransferM = cmykTransferC + 256; |
70 | 395k | cmykTransferY = cmykTransferM + 256; |
71 | 395k | 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 | 101M | for (i = 0; i < 256; ++i) { |
79 | 101M | rgbTransferR[i] = (Guchar)i; |
80 | 101M | rgbTransferG[i] = (Guchar)i; |
81 | 101M | rgbTransferB[i] = (Guchar)i; |
82 | 101M | grayTransfer[i] = (Guchar)i; |
83 | 101M | #if SPLASH_CMYK |
84 | 101M | cmykTransferC[i] = (Guchar)i; |
85 | 101M | cmykTransferM[i] = (Guchar)i; |
86 | 101M | cmykTransferY[i] = (Guchar)i; |
87 | 101M | cmykTransferK[i] = (Guchar)i; |
88 | 101M | #endif |
89 | 101M | } |
90 | 395k | transferIsShared = gFalse; |
91 | 395k | overprintMask = 0xffffffff; |
92 | 395k | enablePathSimplification = gFalse; |
93 | 395k | next = NULL; |
94 | 395k | } |
95 | | |
96 | | SplashState::SplashState(int width, int height, GBool vectorAntialias, |
97 | 7.39k | SplashScreen *screenA) { |
98 | 7.39k | SplashColor color; |
99 | 7.39k | int i; |
100 | | |
101 | 7.39k | matrix[0] = 1; matrix[1] = 0; |
102 | 7.39k | matrix[2] = 0; matrix[3] = 1; |
103 | 7.39k | matrix[4] = 0; matrix[5] = 0; |
104 | 7.39k | memset(&color, 0, sizeof(SplashColor)); |
105 | 7.39k | strokePattern = new SplashSolidColor(color); |
106 | 7.39k | fillPattern = new SplashSolidColor(color); |
107 | 7.39k | screen = screenA->copy(); |
108 | 7.39k | blendFunc = NULL; |
109 | 7.39k | strokeAlpha = 1; |
110 | 7.39k | fillAlpha = 1; |
111 | 7.39k | lineWidth = 1; |
112 | 7.39k | lineCap = splashLineCapButt; |
113 | 7.39k | lineJoin = splashLineJoinMiter; |
114 | 7.39k | miterLimit = 10; |
115 | 7.39k | flatness = 1; |
116 | 7.39k | lineDash = NULL; |
117 | 7.39k | lineDashLength = 0; |
118 | 7.39k | lineDashPhase = 0; |
119 | 7.39k | strokeAdjust = splashStrokeAdjustOff; |
120 | 7.39k | alphaIsShape = gFalse; |
121 | 7.39k | clip = new SplashClip(0, 0, width, height); |
122 | 7.39k | clipIsShared = gFalse; |
123 | 7.39k | softMask = NULL; |
124 | 7.39k | deleteSoftMask = gFalse; |
125 | 7.39k | inNonIsolatedGroup = gFalse; |
126 | 7.39k | inKnockoutGroup = gFalse; |
127 | 7.39k | #if SPLASH_CMYK |
128 | 7.39k | rgbTransferR = (Guchar *)gmalloc(8 * 256); |
129 | 7.39k | rgbTransferG = rgbTransferR + 256; |
130 | 7.39k | rgbTransferB = rgbTransferG + 256; |
131 | 7.39k | grayTransfer = rgbTransferB + 256; |
132 | 7.39k | cmykTransferC = grayTransfer + 256; |
133 | 7.39k | cmykTransferM = cmykTransferC + 256; |
134 | 7.39k | cmykTransferY = cmykTransferM + 256; |
135 | 7.39k | 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 | 1.90M | for (i = 0; i < 256; ++i) { |
143 | 1.89M | rgbTransferR[i] = (Guchar)i; |
144 | 1.89M | rgbTransferG[i] = (Guchar)i; |
145 | 1.89M | rgbTransferB[i] = (Guchar)i; |
146 | 1.89M | grayTransfer[i] = (Guchar)i; |
147 | 1.89M | #if SPLASH_CMYK |
148 | 1.89M | cmykTransferC[i] = (Guchar)i; |
149 | 1.89M | cmykTransferM[i] = (Guchar)i; |
150 | 1.89M | cmykTransferY[i] = (Guchar)i; |
151 | 1.89M | cmykTransferK[i] = (Guchar)i; |
152 | 1.89M | #endif |
153 | 1.89M | } |
154 | 7.39k | transferIsShared = gFalse; |
155 | 7.39k | overprintMask = 0xffffffff; |
156 | 7.39k | enablePathSimplification = gFalse; |
157 | 7.39k | next = NULL; |
158 | 7.39k | } |
159 | | |
160 | 2.44M | SplashState::SplashState(SplashState *state) { |
161 | 2.44M | memcpy(matrix, state->matrix, 6 * sizeof(SplashCoord)); |
162 | 2.44M | strokePattern = state->strokePattern->copy(); |
163 | 2.44M | fillPattern = state->fillPattern->copy(); |
164 | 2.44M | screen = state->screen->copy(); |
165 | 2.44M | blendFunc = state->blendFunc; |
166 | 2.44M | strokeAlpha = state->strokeAlpha; |
167 | 2.44M | fillAlpha = state->fillAlpha; |
168 | 2.44M | lineWidth = state->lineWidth; |
169 | 2.44M | lineCap = state->lineCap; |
170 | 2.44M | lineJoin = state->lineJoin; |
171 | 2.44M | miterLimit = state->miterLimit; |
172 | 2.44M | flatness = state->flatness; |
173 | 2.44M | if (state->lineDash) { |
174 | 2.85k | lineDashLength = state->lineDashLength; |
175 | 2.85k | lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord)); |
176 | 2.85k | memcpy(lineDash, state->lineDash, lineDashLength * sizeof(SplashCoord)); |
177 | 2.44M | } else { |
178 | 2.44M | lineDash = NULL; |
179 | 2.44M | lineDashLength = 0; |
180 | 2.44M | } |
181 | 2.44M | lineDashPhase = state->lineDashPhase; |
182 | 2.44M | strokeAdjust = state->strokeAdjust; |
183 | 2.44M | alphaIsShape = state->alphaIsShape; |
184 | 2.44M | clip = state->clip; |
185 | 2.44M | clipIsShared = gTrue; |
186 | 2.44M | softMask = state->softMask; |
187 | 2.44M | deleteSoftMask = gFalse; |
188 | 2.44M | inNonIsolatedGroup = state->inNonIsolatedGroup; |
189 | 2.44M | inKnockoutGroup = state->inKnockoutGroup; |
190 | 2.44M | rgbTransferR = state->rgbTransferR; |
191 | 2.44M | rgbTransferG = state->rgbTransferG; |
192 | 2.44M | rgbTransferB = state->rgbTransferB; |
193 | 2.44M | grayTransfer = state->grayTransfer; |
194 | 2.44M | #if SPLASH_CMYK |
195 | 2.44M | cmykTransferC = state->cmykTransferC; |
196 | 2.44M | cmykTransferM = state->cmykTransferM; |
197 | 2.44M | cmykTransferY = state->cmykTransferY; |
198 | 2.44M | cmykTransferK = state->cmykTransferK; |
199 | 2.44M | #endif |
200 | 2.44M | transferIsShared = gTrue; |
201 | 2.44M | overprintMask = state->overprintMask; |
202 | 2.44M | enablePathSimplification = state->enablePathSimplification; |
203 | 2.44M | next = NULL; |
204 | 2.44M | } |
205 | | |
206 | 2.84M | SplashState::~SplashState() { |
207 | 2.84M | delete strokePattern; |
208 | 2.84M | delete fillPattern; |
209 | 2.84M | delete screen; |
210 | 2.84M | gfree(lineDash); |
211 | 2.84M | if (!clipIsShared) { |
212 | 590k | delete clip; |
213 | 590k | } |
214 | 2.84M | if (!transferIsShared) { |
215 | 403k | gfree(rgbTransferR); |
216 | 403k | } |
217 | 2.84M | if (deleteSoftMask && softMask) { |
218 | 984 | delete softMask; |
219 | 984 | } |
220 | 2.84M | } |
221 | | |
222 | 911k | void SplashState::setStrokePattern(SplashPattern *strokePatternA) { |
223 | 911k | delete strokePattern; |
224 | 911k | strokePattern = strokePatternA; |
225 | 911k | } |
226 | | |
227 | 3.50M | void SplashState::setFillPattern(SplashPattern *fillPatternA) { |
228 | 3.50M | delete fillPattern; |
229 | 3.50M | fillPattern = fillPatternA; |
230 | 3.50M | } |
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 | 795k | SplashCoord lineDashPhaseA) { |
239 | 795k | gfree(lineDash); |
240 | 795k | lineDashLength = lineDashLengthA; |
241 | 795k | if (lineDashLength > 0) { |
242 | 1.40k | lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord)); |
243 | 1.40k | memcpy(lineDash, lineDashA, lineDashLength * sizeof(SplashCoord)); |
244 | 794k | } else { |
245 | 794k | lineDash = NULL; |
246 | 794k | } |
247 | 795k | lineDashPhase = lineDashPhaseA; |
248 | 795k | } |
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 | 233k | SplashError SplashState::clipToPath(SplashPath *path, GBool eo) { |
295 | 233k | if (clipIsShared) { |
296 | 187k | clip = clip->copy(); |
297 | 187k | clipIsShared = gFalse; |
298 | 187k | } |
299 | 233k | return clip->clipToPath(path, matrix, flatness, eo, |
300 | 233k | enablePathSimplification, strokeAdjust); |
301 | 233k | } |
302 | | |
303 | 11.8k | void SplashState::setSoftMask(SplashBitmap *softMaskA, GBool deleteBitmap) { |
304 | 11.8k | if (deleteSoftMask) { |
305 | 4.39k | delete softMask; |
306 | 4.39k | } |
307 | 11.8k | softMask = softMaskA; |
308 | 11.8k | deleteSoftMask = deleteBitmap; |
309 | 11.8k | } |
310 | | |
311 | | void SplashState::setTransfer(Guchar *red, Guchar *green, Guchar *blue, |
312 | 897 | Guchar *gray) { |
313 | 897 | #if SPLASH_CMYK |
314 | 897 | int i; |
315 | 897 | #endif |
316 | | |
317 | 897 | if (transferIsShared) { |
318 | 659 | #if SPLASH_CMYK |
319 | 659 | rgbTransferR = (Guchar *)gmalloc(8 * 256); |
320 | 659 | rgbTransferG = rgbTransferR + 256; |
321 | 659 | rgbTransferB = rgbTransferG + 256; |
322 | 659 | grayTransfer = rgbTransferB + 256; |
323 | 659 | cmykTransferC = grayTransfer + 256; |
324 | 659 | cmykTransferM = cmykTransferC + 256; |
325 | 659 | cmykTransferY = cmykTransferM + 256; |
326 | 659 | 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 | 659 | transferIsShared = gFalse; |
334 | 659 | } |
335 | 897 | memcpy(rgbTransferR, red, 256); |
336 | 897 | memcpy(rgbTransferG, green, 256); |
337 | 897 | memcpy(rgbTransferB, blue, 256); |
338 | 897 | memcpy(grayTransfer, gray, 256); |
339 | 897 | #if SPLASH_CMYK |
340 | 230k | for (i = 0; i < 256; ++i) { |
341 | 229k | cmykTransferC[i] = (Guchar)(255 - rgbTransferR[255 - i]); |
342 | 229k | cmykTransferM[i] = (Guchar)(255 - rgbTransferG[255 - i]); |
343 | 229k | cmykTransferY[i] = (Guchar)(255 - rgbTransferB[255 - i]); |
344 | 229k | cmykTransferK[i] = (Guchar)(255 - grayTransfer[255 - i]); |
345 | 229k | } |
346 | 897 | #endif |
347 | 897 | } |
348 | | |