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