Debian Codegraph @

libs/xpdf/xpdf-src/splash/SplashState.cc

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