/src/poppler/splash/SplashState.cc
Line | Count | Source |
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, 2025, 2026 Albert Astals Cid <aacid@kde.org> |
17 | | // Copyright (C) 2020 Peter Wang <novalazy@gmail.com> |
18 | | // Copyright (C) 2026 Taufeeque Sifat <entity069@protonmail.com> |
19 | | // Copyright (C) 2026 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> |
20 | | // |
21 | | // To see a description of the changes please see the Changelog file that |
22 | | // came with your tarball or type make ChangeLog if you are building from git |
23 | | // |
24 | | //======================================================================== |
25 | | |
26 | | #include <config.h> |
27 | | |
28 | | #include <cstring> |
29 | | #include "SplashPattern.h" |
30 | | #include "SplashScreen.h" |
31 | | #include "SplashClip.h" |
32 | | #include "SplashBitmap.h" |
33 | | #include "SplashState.h" |
34 | | |
35 | | //------------------------------------------------------------------------ |
36 | | // SplashState |
37 | | //------------------------------------------------------------------------ |
38 | | |
39 | | // number of components in each color mode |
40 | | int splashColorModeNComps[] = { 1, 1, 3, 3, 4, 4, 4 + SPOT_NCOMPS }; |
41 | | |
42 | | SplashState::SplashState(int width, int height, bool vectorAntialias, const SplashScreen &screenA) |
43 | 0 | { |
44 | 0 | SplashColor color; |
45 | 0 | int i; |
46 | |
|
47 | 0 | matrix[0] = 1; |
48 | 0 | matrix[1] = 0; |
49 | 0 | matrix[2] = 0; |
50 | 0 | matrix[3] = 1; |
51 | 0 | matrix[4] = 0; |
52 | 0 | matrix[5] = 0; |
53 | 0 | memset(&color, 0, sizeof(SplashColor)); |
54 | 0 | strokePattern = new SplashSolidColor(color); |
55 | 0 | fillPattern = new SplashSolidColor(color); |
56 | 0 | screen = screenA.copy(); |
57 | 0 | blendFunc = nullptr; |
58 | 0 | strokeAlpha = 1; |
59 | 0 | fillAlpha = 1; |
60 | 0 | multiplyPatternAlpha = false; |
61 | 0 | patternStrokeAlpha = 1; |
62 | 0 | patternFillAlpha = 1; |
63 | 0 | lineWidth = 1; |
64 | 0 | lineCap = SplashLineCap::Butt; |
65 | 0 | lineJoin = SplashLineJoin::Miter; |
66 | 0 | miterLimit = 10; |
67 | 0 | flatness = 1; |
68 | 0 | lineDashPhase = 0; |
69 | 0 | strokeAdjust = false; |
70 | 0 | clip = std::make_unique<SplashClip>(0, 0, width - 0.001, height - 0.001, vectorAntialias); |
71 | 0 | softMask = nullptr; |
72 | 0 | deleteSoftMask = false; |
73 | 0 | inNonIsolatedGroup = false; |
74 | 0 | inKnockoutGroup = false; |
75 | 0 | fillOverprint = false; |
76 | 0 | strokeOverprint = false; |
77 | 0 | overprintMode = 0; |
78 | 0 | for (i = 0; i < 256; ++i) { |
79 | 0 | rgbTransferR[i] = static_cast<unsigned char>(i); |
80 | 0 | rgbTransferG[i] = static_cast<unsigned char>(i); |
81 | 0 | rgbTransferB[i] = static_cast<unsigned char>(i); |
82 | 0 | grayTransfer[i] = static_cast<unsigned char>(i); |
83 | 0 | cmykTransferC[i] = static_cast<unsigned char>(i); |
84 | 0 | cmykTransferM[i] = static_cast<unsigned char>(i); |
85 | 0 | cmykTransferY[i] = static_cast<unsigned char>(i); |
86 | 0 | cmykTransferK[i] = static_cast<unsigned char>(i); |
87 | 0 | for (auto &cp : deviceNTransfer) { |
88 | 0 | cp[i] = static_cast<unsigned char>(i); |
89 | 0 | } |
90 | 0 | } |
91 | 0 | overprintMask = 0xffffffff; |
92 | 0 | overprintAdditive = false; |
93 | 0 | next = nullptr; |
94 | 0 | } |
95 | | |
96 | | SplashState::SplashState(const SplashState *state) |
97 | 0 | { |
98 | 0 | matrix = state->matrix; |
99 | 0 | strokePattern = state->strokePattern->copy(); |
100 | 0 | fillPattern = state->fillPattern->copy(); |
101 | 0 | screen = state->screen->copy(); |
102 | 0 | blendFunc = state->blendFunc; |
103 | 0 | strokeAlpha = state->strokeAlpha; |
104 | 0 | fillAlpha = state->fillAlpha; |
105 | 0 | multiplyPatternAlpha = state->multiplyPatternAlpha; |
106 | 0 | patternStrokeAlpha = state->patternStrokeAlpha; |
107 | 0 | patternFillAlpha = state->patternFillAlpha; |
108 | 0 | lineWidth = state->lineWidth; |
109 | 0 | lineCap = state->lineCap; |
110 | 0 | lineJoin = state->lineJoin; |
111 | 0 | miterLimit = state->miterLimit; |
112 | 0 | flatness = state->flatness; |
113 | 0 | lineDash = state->lineDash; |
114 | 0 | lineDashPhase = state->lineDashPhase; |
115 | 0 | strokeAdjust = state->strokeAdjust; |
116 | 0 | clip = state->clip->copy(); |
117 | 0 | softMask = state->softMask; |
118 | 0 | deleteSoftMask = false; |
119 | 0 | inNonIsolatedGroup = state->inNonIsolatedGroup; |
120 | 0 | inKnockoutGroup = state->inKnockoutGroup; |
121 | 0 | fillOverprint = state->fillOverprint; |
122 | 0 | strokeOverprint = state->strokeOverprint; |
123 | 0 | overprintMode = state->overprintMode; |
124 | 0 | memcpy(rgbTransferR, state->rgbTransferR, 256); |
125 | 0 | memcpy(rgbTransferG, state->rgbTransferG, 256); |
126 | 0 | memcpy(rgbTransferB, state->rgbTransferB, 256); |
127 | 0 | memcpy(grayTransfer, state->grayTransfer, 256); |
128 | 0 | memcpy(cmykTransferC, state->cmykTransferC, 256); |
129 | 0 | memcpy(cmykTransferM, state->cmykTransferM, 256); |
130 | 0 | memcpy(cmykTransferY, state->cmykTransferY, 256); |
131 | 0 | memcpy(cmykTransferK, state->cmykTransferK, 256); |
132 | 0 | for (int cp = 0; cp < SPOT_NCOMPS + 4; cp++) { |
133 | 0 | memcpy(deviceNTransfer[cp], state->deviceNTransfer[cp], 256); |
134 | 0 | } |
135 | 0 | overprintMask = state->overprintMask; |
136 | 0 | overprintAdditive = state->overprintAdditive; |
137 | 0 | next = nullptr; |
138 | 0 | } |
139 | | |
140 | | SplashState::~SplashState() |
141 | 0 | { |
142 | 0 | delete strokePattern; |
143 | 0 | delete fillPattern; |
144 | 0 | delete screen; |
145 | 0 | if (deleteSoftMask && softMask) { |
146 | 0 | delete softMask; |
147 | 0 | } |
148 | 0 | } |
149 | | |
150 | | void SplashState::setStrokePattern(SplashPattern *strokePatternA) |
151 | 0 | { |
152 | 0 | delete strokePattern; |
153 | 0 | strokePattern = strokePatternA; |
154 | 0 | } |
155 | | |
156 | | void SplashState::setFillPattern(SplashPattern *fillPatternA) |
157 | 0 | { |
158 | 0 | delete fillPattern; |
159 | 0 | fillPattern = fillPatternA; |
160 | 0 | } |
161 | | |
162 | | void SplashState::setLineDash(std::vector<double> &&lineDashA, double lineDashPhaseA) |
163 | 0 | { |
164 | 0 | lineDash = lineDashA; |
165 | 0 | lineDashPhase = lineDashPhaseA; |
166 | 0 | } |
167 | | |
168 | | void SplashState::setSoftMask(SplashBitmap *softMaskA) |
169 | 0 | { |
170 | 0 | if (deleteSoftMask) { |
171 | 0 | delete softMask; |
172 | 0 | } |
173 | 0 | softMask = softMaskA; |
174 | 0 | deleteSoftMask = true; |
175 | 0 | } |
176 | | |
177 | | void SplashState::setTransfer(unsigned char *red, unsigned char *green, unsigned char *blue, unsigned char *gray) |
178 | 0 | { |
179 | 0 | for (int i = 0; i < 256; ++i) { |
180 | 0 | cmykTransferC[i] = 255 - rgbTransferR[255 - i]; |
181 | 0 | cmykTransferM[i] = 255 - rgbTransferG[255 - i]; |
182 | 0 | cmykTransferY[i] = 255 - rgbTransferB[255 - i]; |
183 | 0 | cmykTransferK[i] = 255 - grayTransfer[255 - i]; |
184 | 0 | } |
185 | 0 | for (int i = 0; i < 256; ++i) { |
186 | 0 | deviceNTransfer[0][i] = 255 - rgbTransferR[255 - i]; |
187 | 0 | deviceNTransfer[1][i] = 255 - rgbTransferG[255 - i]; |
188 | 0 | deviceNTransfer[2][i] = 255 - rgbTransferB[255 - i]; |
189 | 0 | deviceNTransfer[3][i] = 255 - grayTransfer[255 - i]; |
190 | 0 | } |
191 | 0 | memcpy(rgbTransferR, red, 256); |
192 | 0 | memcpy(rgbTransferG, green, 256); |
193 | 0 | memcpy(rgbTransferB, blue, 256); |
194 | 0 | memcpy(grayTransfer, gray, 256); |
195 | 0 | } |