1//========================================================================
2//
3// SplashState.cc
4//
5//========================================================================
6
7//========================================================================
8//
9// Modified under the Poppler project - http://poppler.freedesktop.org
10//
11// All changes made under the Poppler project to this file are licensed
12// under GPL version 2 or later
13//
14// Copyright (C) 2009, 2011, 2012, 2015 Thomas Freitag <Thomas.Freitag@alfa.de>
15// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
16// Copyright (C) 2019, 2021, 2022 Albert Astals Cid <aacid@kde.org>
17// Copyright (C) 2020 Peter Wang <novalazy@gmail.com>
18//
19// To see a description of the changes please see the Changelog file that
20// came with your tarball or type make ChangeLog if you are building from git
21//
22//========================================================================
23
24#include <config.h>
25
26#include <cstring>
27#include "goo/gmem.h"
28#include "SplashPattern.h"
29#include "SplashScreen.h"
30#include "SplashClip.h"
31#include "SplashBitmap.h"
32#include "SplashState.h"
33
34//------------------------------------------------------------------------
35// SplashState
36//------------------------------------------------------------------------
37
38// number of components in each color mode
39int splashColorModeNComps[] = { 1, 1, 3, 3, 4, 4, 4 + SPOT_NCOMPS };
40
41SplashState::SplashState(int width, int height, bool vectorAntialias, SplashScreenParams *screenParams)
42{
43 SplashColor color;
44 int i;
45
46 matrix[0] = 1;
47 matrix[1] = 0;
48 matrix[2] = 0;
49 matrix[3] = 1;
50 matrix[4] = 0;
51 matrix[5] = 0;
52 memset(s: &color, c: 0, n: sizeof(SplashColor));
53 strokePattern = new SplashSolidColor(color);
54 fillPattern = new SplashSolidColor(color);
55 screen = new SplashScreen(screenParams);
56 blendFunc = nullptr;
57 strokeAlpha = 1;
58 fillAlpha = 1;
59 multiplyPatternAlpha = false;
60 patternStrokeAlpha = 1;
61 patternFillAlpha = 1;
62 lineWidth = 1;
63 lineCap = splashLineCapButt;
64 lineJoin = splashLineJoinMiter;
65 miterLimit = 10;
66 flatness = 1;
67 lineDashPhase = 0;
68 strokeAdjust = false;
69 clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias);
70 softMask = nullptr;
71 deleteSoftMask = false;
72 inNonIsolatedGroup = false;
73 fillOverprint = false;
74 strokeOverprint = false;
75 overprintMode = 0;
76 for (i = 0; i < 256; ++i) {
77 rgbTransferR[i] = (unsigned char)i;
78 rgbTransferG[i] = (unsigned char)i;
79 rgbTransferB[i] = (unsigned char)i;
80 grayTransfer[i] = (unsigned char)i;
81 cmykTransferC[i] = (unsigned char)i;
82 cmykTransferM[i] = (unsigned char)i;
83 cmykTransferY[i] = (unsigned char)i;
84 cmykTransferK[i] = (unsigned char)i;
85 for (auto &cp : deviceNTransfer) {
86 cp[i] = (unsigned char)i;
87 }
88 }
89 overprintMask = 0xffffffff;
90 overprintAdditive = false;
91 next = nullptr;
92}
93
94SplashState::SplashState(int width, int height, bool vectorAntialias, SplashScreen *screenA)
95{
96 SplashColor color;
97 int i;
98
99 matrix[0] = 1;
100 matrix[1] = 0;
101 matrix[2] = 0;
102 matrix[3] = 1;
103 matrix[4] = 0;
104 matrix[5] = 0;
105 memset(s: &color, c: 0, n: sizeof(SplashColor));
106 strokePattern = new SplashSolidColor(color);
107 fillPattern = new SplashSolidColor(color);
108 screen = screenA->copy();
109 blendFunc = nullptr;
110 strokeAlpha = 1;
111 fillAlpha = 1;
112 multiplyPatternAlpha = false;
113 patternStrokeAlpha = 1;
114 patternFillAlpha = 1;
115 lineWidth = 1;
116 lineCap = splashLineCapButt;
117 lineJoin = splashLineJoinMiter;
118 miterLimit = 10;
119 flatness = 1;
120 lineDashPhase = 0;
121 strokeAdjust = false;
122 clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias);
123 softMask = nullptr;
124 deleteSoftMask = false;
125 inNonIsolatedGroup = false;
126 fillOverprint = false;
127 strokeOverprint = false;
128 overprintMode = 0;
129 for (i = 0; i < 256; ++i) {
130 rgbTransferR[i] = (unsigned char)i;
131 rgbTransferG[i] = (unsigned char)i;
132 rgbTransferB[i] = (unsigned char)i;
133 grayTransfer[i] = (unsigned char)i;
134 cmykTransferC[i] = (unsigned char)i;
135 cmykTransferM[i] = (unsigned char)i;
136 cmykTransferY[i] = (unsigned char)i;
137 cmykTransferK[i] = (unsigned char)i;
138 for (auto &cp : deviceNTransfer) {
139 cp[i] = (unsigned char)i;
140 }
141 }
142 overprintMask = 0xffffffff;
143 overprintAdditive = false;
144 next = nullptr;
145}
146
147SplashState::SplashState(const SplashState *state)
148{
149 memcpy(dest: matrix, src: state->matrix, n: 6 * sizeof(SplashCoord));
150 strokePattern = state->strokePattern->copy();
151 fillPattern = state->fillPattern->copy();
152 screen = state->screen->copy();
153 blendFunc = state->blendFunc;
154 strokeAlpha = state->strokeAlpha;
155 fillAlpha = state->fillAlpha;
156 multiplyPatternAlpha = state->multiplyPatternAlpha;
157 patternStrokeAlpha = state->patternStrokeAlpha;
158 patternFillAlpha = state->patternFillAlpha;
159 lineWidth = state->lineWidth;
160 lineCap = state->lineCap;
161 lineJoin = state->lineJoin;
162 miterLimit = state->miterLimit;
163 flatness = state->flatness;
164 lineDash = state->lineDash;
165 lineDashPhase = state->lineDashPhase;
166 strokeAdjust = state->strokeAdjust;
167 clip = state->clip->copy();
168 softMask = state->softMask;
169 deleteSoftMask = false;
170 inNonIsolatedGroup = state->inNonIsolatedGroup;
171 fillOverprint = state->fillOverprint;
172 strokeOverprint = state->strokeOverprint;
173 overprintMode = state->overprintMode;
174 memcpy(dest: rgbTransferR, src: state->rgbTransferR, n: 256);
175 memcpy(dest: rgbTransferG, src: state->rgbTransferG, n: 256);
176 memcpy(dest: rgbTransferB, src: state->rgbTransferB, n: 256);
177 memcpy(dest: grayTransfer, src: state->grayTransfer, n: 256);
178 memcpy(dest: cmykTransferC, src: state->cmykTransferC, n: 256);
179 memcpy(dest: cmykTransferM, src: state->cmykTransferM, n: 256);
180 memcpy(dest: cmykTransferY, src: state->cmykTransferY, n: 256);
181 memcpy(dest: cmykTransferK, src: state->cmykTransferK, n: 256);
182 for (int cp = 0; cp < SPOT_NCOMPS + 4; cp++) {
183 memcpy(dest: deviceNTransfer[cp], src: state->deviceNTransfer[cp], n: 256);
184 }
185 overprintMask = state->overprintMask;
186 overprintAdditive = state->overprintAdditive;
187 next = nullptr;
188}
189
190SplashState::~SplashState()
191{
192 delete strokePattern;
193 delete fillPattern;
194 delete screen;
195 delete clip;
196 if (deleteSoftMask && softMask) {
197 delete softMask;
198 }
199}
200
201void SplashState::setStrokePattern(SplashPattern *strokePatternA)
202{
203 delete strokePattern;
204 strokePattern = strokePatternA;
205}
206
207void SplashState::setFillPattern(SplashPattern *fillPatternA)
208{
209 delete fillPattern;
210 fillPattern = fillPatternA;
211}
212
213void SplashState::setScreen(SplashScreen *screenA)
214{
215 delete screen;
216 screen = screenA;
217}
218
219void SplashState::setLineDash(std::vector<SplashCoord> &&lineDashA, SplashCoord lineDashPhaseA)
220{
221 lineDash = lineDashA;
222 lineDashPhase = lineDashPhaseA;
223}
224
225void SplashState::setSoftMask(SplashBitmap *softMaskA)
226{
227 if (deleteSoftMask) {
228 delete softMask;
229 }
230 softMask = softMaskA;
231 deleteSoftMask = true;
232}
233
234void SplashState::setTransfer(unsigned char *red, unsigned char *green, unsigned char *blue, unsigned char *gray)
235{
236 for (int i = 0; i < 256; ++i) {
237 cmykTransferC[i] = 255 - rgbTransferR[255 - i];
238 cmykTransferM[i] = 255 - rgbTransferG[255 - i];
239 cmykTransferY[i] = 255 - rgbTransferB[255 - i];
240 cmykTransferK[i] = 255 - grayTransfer[255 - i];
241 }
242 for (int i = 0; i < 256; ++i) {
243 deviceNTransfer[0][i] = 255 - rgbTransferR[255 - i];
244 deviceNTransfer[1][i] = 255 - rgbTransferG[255 - i];
245 deviceNTransfer[2][i] = 255 - rgbTransferB[255 - i];
246 deviceNTransfer[3][i] = 255 - grayTransfer[255 - i];
247 }
248 memcpy(dest: rgbTransferR, src: red, n: 256);
249 memcpy(dest: rgbTransferG, src: green, n: 256);
250 memcpy(dest: rgbTransferB, src: blue, n: 256);
251 memcpy(dest: grayTransfer, src: gray, n: 256);
252}
253

source code of poppler/splash/SplashState.cc