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