SplashState.cc 7.87 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6
//========================================================================
//
// SplashState.cc
//
//========================================================================

7 8 9 10 11 12 13
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
14
// Copyright (C) 2009, 2011, 2012, 2015 Thomas Freitag <Thomas.Freitag@alfa.de>
15 16 17 18 19 20
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================

Kristian Høgsberg's avatar
Kristian Høgsberg committed
21 22 23 24 25 26 27 28 29 30 31
#include <config.h>

#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif

#include <string.h>
#include "goo/gmem.h"
#include "SplashPattern.h"
#include "SplashScreen.h"
#include "SplashClip.h"
32
#include "SplashBitmap.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
33 34 35 36 37 38
#include "SplashState.h"

//------------------------------------------------------------------------
// SplashState
//------------------------------------------------------------------------

39 40
// number of components in each color mode
int splashColorModeNComps[] = {
41
  1, 1, 3, 3, 4
42
#ifdef SPLASH_CMYK
43
  , 4, 4 + SPOT_NCOMPS
44
#endif
45 46
};

47 48
SplashState::SplashState(int width, int height, GBool vectorAntialias,
			 SplashScreenParams *screenParams) {
Kristian Høgsberg's avatar
Kristian Høgsberg committed
49
  SplashColor color;
50
  int i;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
51

52 53 54
  matrix[0] = 1;  matrix[1] = 0;
  matrix[2] = 0;  matrix[3] = 1;
  matrix[4] = 0;  matrix[5] = 0;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
55 56 57
  memset(&color, 0, sizeof(SplashColor));
  strokePattern = new SplashSolidColor(color);
  fillPattern = new SplashSolidColor(color);
58
  screen = new SplashScreen(screenParams);
59 60 61
  blendFunc = NULL;
  strokeAlpha = 1;
  fillAlpha = 1;
62 63 64
  multiplyPatternAlpha = gFalse;
  patternStrokeAlpha = 1;
  patternFillAlpha = 1;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
65 66 67 68 69 70 71 72
  lineWidth = 0;
  lineCap = splashLineCapButt;
  lineJoin = splashLineJoinMiter;
  miterLimit = 10;
  flatness = 1;
  lineDash = NULL;
  lineDashLength = 0;
  lineDashPhase = 0;
73 74 75 76 77
  strokeAdjust = gFalse;
  clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias);
  softMask = NULL;
  deleteSoftMask = gFalse;
  inNonIsolatedGroup = gFalse;
78 79 80
  fillOverprint = gFalse;
  strokeOverprint = gFalse;
  overprintMode = 0;	  
81 82 83 84 85
  for (i = 0; i < 256; ++i) {
    rgbTransferR[i] = (Guchar)i;
    rgbTransferG[i] = (Guchar)i;
    rgbTransferB[i] = (Guchar)i;
    grayTransfer[i] = (Guchar)i;
86
#ifdef SPLASH_CMYK
87 88 89 90
    cmykTransferC[i] = (Guchar)i;
    cmykTransferM[i] = (Guchar)i;
    cmykTransferY[i] = (Guchar)i;
    cmykTransferK[i] = (Guchar)i;
91 92 93
    for (int cp = 0; cp < SPOT_NCOMPS+4; cp++)
      deviceNTransfer[cp][i] = (Guchar)i;
#endif
94 95
  }
  overprintMask = 0xffffffff;
96
  overprintAdditive = gFalse;
97 98 99 100 101 102
  next = NULL;
}

SplashState::SplashState(int width, int height, GBool vectorAntialias,
			 SplashScreen *screenA) {
  SplashColor color;
103
  int i;
104 105 106 107 108 109 110 111 112 113 114

  matrix[0] = 1;  matrix[1] = 0;
  matrix[2] = 0;  matrix[3] = 1;
  matrix[4] = 0;  matrix[5] = 0;
  memset(&color, 0, sizeof(SplashColor));
  strokePattern = new SplashSolidColor(color);
  fillPattern = new SplashSolidColor(color);
  screen = screenA->copy();
  blendFunc = NULL;
  strokeAlpha = 1;
  fillAlpha = 1;
115 116 117
  multiplyPatternAlpha = gFalse;
  patternStrokeAlpha = 1;
  patternFillAlpha = 1;
118 119 120 121 122 123 124 125 126 127 128 129 130
  lineWidth = 0;
  lineCap = splashLineCapButt;
  lineJoin = splashLineJoinMiter;
  miterLimit = 10;
  flatness = 1;
  lineDash = NULL;
  lineDashLength = 0;
  lineDashPhase = 0;
  strokeAdjust = gFalse;
  clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias);
  softMask = NULL;
  deleteSoftMask = gFalse;
  inNonIsolatedGroup = gFalse;
131 132 133
  fillOverprint = gFalse;
  strokeOverprint = gFalse;
  overprintMode = 0;	  
134 135 136 137 138
  for (i = 0; i < 256; ++i) {
    rgbTransferR[i] = (Guchar)i;
    rgbTransferG[i] = (Guchar)i;
    rgbTransferB[i] = (Guchar)i;
    grayTransfer[i] = (Guchar)i;
139
#ifdef SPLASH_CMYK
140 141 142 143
    cmykTransferC[i] = (Guchar)i;
    cmykTransferM[i] = (Guchar)i;
    cmykTransferY[i] = (Guchar)i;
    cmykTransferK[i] = (Guchar)i;
144 145 146
    for (int cp = 0; cp < SPOT_NCOMPS+4; cp++)
      deviceNTransfer[cp][i] = (Guchar)i;
#endif
147 148
  }
  overprintMask = 0xffffffff;
149
  overprintAdditive = gFalse;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
150 151 152 153
  next = NULL;
}

SplashState::SplashState(SplashState *state) {
154
  memcpy(matrix, state->matrix, 6 * sizeof(SplashCoord));
Kristian Høgsberg's avatar
Kristian Høgsberg committed
155 156 157
  strokePattern = state->strokePattern->copy();
  fillPattern = state->fillPattern->copy();
  screen = state->screen->copy();
158 159 160
  blendFunc = state->blendFunc;
  strokeAlpha = state->strokeAlpha;
  fillAlpha = state->fillAlpha;
161 162 163
  multiplyPatternAlpha = state->multiplyPatternAlpha;
  patternStrokeAlpha = state->patternStrokeAlpha;
  patternFillAlpha = state->patternFillAlpha;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
164 165 166 167 168 169 170
  lineWidth = state->lineWidth;
  lineCap = state->lineCap;
  lineJoin = state->lineJoin;
  miterLimit = state->miterLimit;
  flatness = state->flatness;
  if (state->lineDash) {
    lineDashLength = state->lineDashLength;
171
    lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord));
Kristian Høgsberg's avatar
Kristian Høgsberg committed
172 173 174 175 176 177
    memcpy(lineDash, state->lineDash, lineDashLength * sizeof(SplashCoord));
  } else {
    lineDash = NULL;
    lineDashLength = 0;
  }
  lineDashPhase = state->lineDashPhase;
178
  strokeAdjust = state->strokeAdjust;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
179
  clip = state->clip->copy();
180 181 182
  softMask = state->softMask;
  deleteSoftMask = gFalse;
  inNonIsolatedGroup = state->inNonIsolatedGroup;
183 184 185
  fillOverprint = state->fillOverprint;
  strokeOverprint = state->strokeOverprint;
  overprintMode = state->overprintMode;	  
186 187 188 189
  memcpy(rgbTransferR, state->rgbTransferR, 256);
  memcpy(rgbTransferG, state->rgbTransferG, 256);
  memcpy(rgbTransferB, state->rgbTransferB, 256);
  memcpy(grayTransfer, state->grayTransfer, 256);
190
#ifdef SPLASH_CMYK
191 192 193 194
  memcpy(cmykTransferC, state->cmykTransferC, 256);
  memcpy(cmykTransferM, state->cmykTransferM, 256);
  memcpy(cmykTransferY, state->cmykTransferY, 256);
  memcpy(cmykTransferK, state->cmykTransferK, 256);
195 196 197
  for (int cp = 0; cp < SPOT_NCOMPS+4; cp++)
    memcpy(deviceNTransfer[cp], state->deviceNTransfer[cp], 256);
#endif
198
  overprintMask = state->overprintMask;
199
  overprintAdditive = state->overprintAdditive;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
200 201 202 203 204 205 206 207 208
  next = NULL;
}

SplashState::~SplashState() {
  delete strokePattern;
  delete fillPattern;
  delete screen;
  gfree(lineDash);
  delete clip;
209 210 211
  if (deleteSoftMask && softMask) {
    delete softMask;
  }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
}

void SplashState::setStrokePattern(SplashPattern *strokePatternA) {
  delete strokePattern;
  strokePattern = strokePatternA;
}

void SplashState::setFillPattern(SplashPattern *fillPatternA) {
  delete fillPattern;
  fillPattern = fillPatternA;
}

void SplashState::setScreen(SplashScreen *screenA) {
  delete screen;
  screen = screenA;
}

void SplashState::setLineDash(SplashCoord *lineDashA, int lineDashLengthA,
			      SplashCoord lineDashPhaseA) {
  gfree(lineDash);
  lineDashLength = lineDashLengthA;
  if (lineDashLength > 0) {
234
    lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord));
Kristian Høgsberg's avatar
Kristian Høgsberg committed
235 236 237 238 239 240
    memcpy(lineDash, lineDashA, lineDashLength * sizeof(SplashCoord));
  } else {
    lineDash = NULL;
  }
  lineDashPhase = lineDashPhaseA;
}
241 242 243 244 245 246 247 248

void SplashState::setSoftMask(SplashBitmap *softMaskA) {
  if (deleteSoftMask) {
    delete softMask;
  }
  softMask = softMaskA;
  deleteSoftMask = gTrue;
}
249 250 251

void SplashState::setTransfer(Guchar *red, Guchar *green, Guchar *blue,
			      Guchar *gray) {
252
#ifdef SPLASH_CMYK
253 254 255 256 257 258 259 260
  int i;

  for (i = 0; i < 256; ++i) {
    cmykTransferC[i] = 255 - rgbTransferR[255 - i];
    cmykTransferM[i] = 255 - rgbTransferG[255 - i];
    cmykTransferY[i] = 255 - rgbTransferB[255 - i];
    cmykTransferK[i] = 255 - grayTransfer[255 - i];
  }
261 262 263 264 265 266 267 268 269 270 271
  for (i = 0; i < 256; ++i) {
    deviceNTransfer[0][i] = 255 - rgbTransferR[255 - i];
    deviceNTransfer[1][i] = 255 - rgbTransferG[255 - i];
    deviceNTransfer[2][i] = 255 - rgbTransferB[255 - i];
    deviceNTransfer[3][i] = 255 - grayTransfer[255 - i];
  }
#endif
  memcpy(rgbTransferR, red, 256);
  memcpy(rgbTransferG, green, 256);
  memcpy(rgbTransferB, blue, 256);
  memcpy(grayTransfer, gray, 256);
272
}