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