sinc with TL rev. 38618.
[luatex.git] / source / libs / poppler / poppler-0.37.0 / splash / SplashState.cc
blobfd2789d02f948e118e3b0965b8e1f08e34cbc61f
1 //========================================================================
2 //
3 // SplashState.cc
4 //
5 //========================================================================
7 //========================================================================
8 //
9 // Modified under the Poppler project - http://poppler.freedesktop.org
11 // All changes made under the Poppler project to this file are licensed
12 // under GPL version 2 or later
14 // Copyright (C) 2009, 2011, 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
16 // To see a description of the changes please see the Changelog file that
17 // came with your tarball or type make ChangeLog if you are building from git
19 //========================================================================
21 #include <config.h>
23 #ifdef USE_GCC_PRAGMAS
24 #pragma implementation
25 #endif
27 #include <string.h>
28 #include "goo/gmem.h"
29 #include "SplashPattern.h"
30 #include "SplashScreen.h"
31 #include "SplashClip.h"
32 #include "SplashBitmap.h"
33 #include "SplashState.h"
35 //------------------------------------------------------------------------
36 // SplashState
37 //------------------------------------------------------------------------
39 // number of components in each color mode
40 int splashColorModeNComps[] = {
41 1, 1, 3, 3, 4
42 #if SPLASH_CMYK
43 , 4, 4 + SPOT_NCOMPS
44 #endif
47 SplashState::SplashState(int width, int height, GBool vectorAntialias,
48 SplashScreenParams *screenParams) {
49 SplashColor color;
50 int i;
52 matrix[0] = 1; matrix[1] = 0;
53 matrix[2] = 0; matrix[3] = 1;
54 matrix[4] = 0; matrix[5] = 0;
55 memset(&color, 0, sizeof(SplashColor));
56 strokePattern = new SplashSolidColor(color);
57 fillPattern = new SplashSolidColor(color);
58 screen = new SplashScreen(screenParams);
59 blendFunc = NULL;
60 strokeAlpha = 1;
61 fillAlpha = 1;
62 lineWidth = 0;
63 lineCap = splashLineCapButt;
64 lineJoin = splashLineJoinMiter;
65 miterLimit = 10;
66 flatness = 1;
67 lineDash = NULL;
68 lineDashLength = 0;
69 lineDashPhase = 0;
70 strokeAdjust = gFalse;
71 clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias);
72 softMask = NULL;
73 deleteSoftMask = gFalse;
74 inNonIsolatedGroup = gFalse;
75 fillOverprint = gFalse;
76 strokeOverprint = gFalse;
77 overprintMode = 0;
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 for (int cp = 0; cp < SPOT_NCOMPS+4; cp++)
89 deviceNTransfer[cp][i] = (Guchar)i;
90 #endif
92 overprintMask = 0xffffffff;
93 overprintAdditive = gFalse;
94 next = NULL;
97 SplashState::SplashState(int width, int height, GBool vectorAntialias,
98 SplashScreen *screenA) {
99 SplashColor color;
100 int i;
102 matrix[0] = 1; matrix[1] = 0;
103 matrix[2] = 0; matrix[3] = 1;
104 matrix[4] = 0; matrix[5] = 0;
105 memset(&color, 0, sizeof(SplashColor));
106 strokePattern = new SplashSolidColor(color);
107 fillPattern = new SplashSolidColor(color);
108 screen = screenA->copy();
109 blendFunc = NULL;
110 strokeAlpha = 1;
111 fillAlpha = 1;
112 lineWidth = 0;
113 lineCap = splashLineCapButt;
114 lineJoin = splashLineJoinMiter;
115 miterLimit = 10;
116 flatness = 1;
117 lineDash = NULL;
118 lineDashLength = 0;
119 lineDashPhase = 0;
120 strokeAdjust = gFalse;
121 clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias);
122 softMask = NULL;
123 deleteSoftMask = gFalse;
124 inNonIsolatedGroup = gFalse;
125 fillOverprint = gFalse;
126 strokeOverprint = gFalse;
127 overprintMode = 0;
128 for (i = 0; i < 256; ++i) {
129 rgbTransferR[i] = (Guchar)i;
130 rgbTransferG[i] = (Guchar)i;
131 rgbTransferB[i] = (Guchar)i;
132 grayTransfer[i] = (Guchar)i;
133 #if SPLASH_CMYK
134 cmykTransferC[i] = (Guchar)i;
135 cmykTransferM[i] = (Guchar)i;
136 cmykTransferY[i] = (Guchar)i;
137 cmykTransferK[i] = (Guchar)i;
138 for (int cp = 0; cp < SPOT_NCOMPS+4; cp++)
139 deviceNTransfer[cp][i] = (Guchar)i;
140 #endif
142 overprintMask = 0xffffffff;
143 overprintAdditive = gFalse;
144 next = NULL;
147 SplashState::SplashState(SplashState *state) {
148 memcpy(matrix, state->matrix, 6 * sizeof(SplashCoord));
149 strokePattern = state->strokePattern->copy();
150 fillPattern = state->fillPattern->copy();
151 screen = state->screen->copy();
152 blendFunc = state->blendFunc;
153 strokeAlpha = state->strokeAlpha;
154 fillAlpha = state->fillAlpha;
155 lineWidth = state->lineWidth;
156 lineCap = state->lineCap;
157 lineJoin = state->lineJoin;
158 miterLimit = state->miterLimit;
159 flatness = state->flatness;
160 if (state->lineDash) {
161 lineDashLength = state->lineDashLength;
162 lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord));
163 memcpy(lineDash, state->lineDash, lineDashLength * sizeof(SplashCoord));
164 } else {
165 lineDash = NULL;
166 lineDashLength = 0;
168 lineDashPhase = state->lineDashPhase;
169 strokeAdjust = state->strokeAdjust;
170 clip = state->clip->copy();
171 softMask = state->softMask;
172 deleteSoftMask = gFalse;
173 inNonIsolatedGroup = state->inNonIsolatedGroup;
174 fillOverprint = state->fillOverprint;
175 strokeOverprint = state->strokeOverprint;
176 overprintMode = state->overprintMode;
177 memcpy(rgbTransferR, state->rgbTransferR, 256);
178 memcpy(rgbTransferG, state->rgbTransferG, 256);
179 memcpy(rgbTransferB, state->rgbTransferB, 256);
180 memcpy(grayTransfer, state->grayTransfer, 256);
181 #if SPLASH_CMYK
182 memcpy(cmykTransferC, state->cmykTransferC, 256);
183 memcpy(cmykTransferM, state->cmykTransferM, 256);
184 memcpy(cmykTransferY, state->cmykTransferY, 256);
185 memcpy(cmykTransferK, state->cmykTransferK, 256);
186 for (int cp = 0; cp < SPOT_NCOMPS+4; cp++)
187 memcpy(deviceNTransfer[cp], state->deviceNTransfer[cp], 256);
188 #endif
189 overprintMask = state->overprintMask;
190 overprintAdditive = state->overprintAdditive;
191 next = NULL;
194 SplashState::~SplashState() {
195 delete strokePattern;
196 delete fillPattern;
197 delete screen;
198 gfree(lineDash);
199 delete clip;
200 if (deleteSoftMask && softMask) {
201 delete softMask;
205 void SplashState::setStrokePattern(SplashPattern *strokePatternA) {
206 delete strokePattern;
207 strokePattern = strokePatternA;
210 void SplashState::setFillPattern(SplashPattern *fillPatternA) {
211 delete fillPattern;
212 fillPattern = fillPatternA;
215 void SplashState::setScreen(SplashScreen *screenA) {
216 delete screen;
217 screen = screenA;
220 void SplashState::setLineDash(SplashCoord *lineDashA, int lineDashLengthA,
221 SplashCoord lineDashPhaseA) {
222 gfree(lineDash);
223 lineDashLength = lineDashLengthA;
224 if (lineDashLength > 0) {
225 lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord));
226 memcpy(lineDash, lineDashA, lineDashLength * sizeof(SplashCoord));
227 } else {
228 lineDash = NULL;
230 lineDashPhase = lineDashPhaseA;
233 void SplashState::setSoftMask(SplashBitmap *softMaskA) {
234 if (deleteSoftMask) {
235 delete softMask;
237 softMask = softMaskA;
238 deleteSoftMask = gTrue;
241 void SplashState::setTransfer(Guchar *red, Guchar *green, Guchar *blue,
242 Guchar *gray) {
243 #if SPLASH_CMYK
244 int i;
246 for (i = 0; i < 256; ++i) {
247 cmykTransferC[i] = 255 - rgbTransferR[255 - i];
248 cmykTransferM[i] = 255 - rgbTransferG[255 - i];
249 cmykTransferY[i] = 255 - rgbTransferB[255 - i];
250 cmykTransferK[i] = 255 - grayTransfer[255 - i];
252 for (i = 0; i < 256; ++i) {
253 deviceNTransfer[0][i] = 255 - rgbTransferR[255 - i];
254 deviceNTransfer[1][i] = 255 - rgbTransferG[255 - i];
255 deviceNTransfer[2][i] = 255 - rgbTransferB[255 - i];
256 deviceNTransfer[3][i] = 255 - grayTransfer[255 - i];
258 #endif
259 memcpy(rgbTransferR, red, 256);
260 memcpy(rgbTransferG, green, 256);
261 memcpy(rgbTransferB, blue, 256);
262 memcpy(grayTransfer, gray, 256);