Coverage Report

Created: 2023-09-25 06:41

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