| 1 |
//======================================================================== |
| 2 |
// |
| 3 |
// Splash.cc |
| 4 |
// |
| 5 |
// Copyright 2003-2020 Glyph & Cog, LLC |
| 6 |
// |
| 7 |
//======================================================================== |
| 8 |
|
| 9 |
#include <aconf.h> |
| 10 |
|
| 11 |
#include <stdlib.h> |
| 12 |
#include <string.h> |
| 13 |
#include <limits.h> |
| 14 |
#include <math.h> |
| 15 |
#include "gmem.h" |
| 16 |
#include "gmempp.h" |
| 17 |
#include "GString.h" |
| 18 |
#include "SplashErrorCodes.h" |
| 19 |
#include "SplashMath.h" |
| 20 |
#include "SplashBitmap.h" |
| 21 |
#include "SplashState.h" |
| 22 |
#include "SplashPath.h" |
| 23 |
#include "SplashXPath.h" |
| 24 |
#include "SplashXPathScanner.h" |
| 25 |
#include "SplashPattern.h" |
| 26 |
#include "SplashScreen.h" |
| 27 |
#include "SplashFont.h" |
| 28 |
#include "SplashGlyphBitmap.h" |
| 29 |
#include "Splash.h" |
| 30 |
|
| 31 |
// the MSVC math.h doesn't define this |
| 32 |
#ifndef M_PI |
| 33 |
#define M_PI 3.14159265358979323846 |
| 34 |
#endif |
| 35 |
|
| 36 |
//------------------------------------------------------------------------ |
| 37 |
|
| 38 |
// distance of Bezier control point from center for circle approximation |
| 39 |
// = (4 * (sqrt(2) - 1) / 3) * r |
| 40 |
#define bezierCircle ((SplashCoord)0.55228475) |
| 41 |
#define bezierCircle2 ((SplashCoord)(0.5 * 0.55228475)) |
| 42 |
|
| 43 |
// Divide a 16-bit value (in [0, 255*255]) by 255, returning an 8-bit result. |
| 44 |
static inline Guchar div255(int x) { |
| 45 |
return (Guchar)((x + (x >> 8) + 0x80) >> 8); |
| 46 |
} |
| 47 |
|
| 48 |
// Clip x to lie in [0, 255]. |
| 49 |
static inline Guchar clip255(int x) { |
| 50 |
return x < 0 ? 0 : x > 255 ? 255 : (Guchar)x; |
| 51 |
} |
| 52 |
|
| 53 |
// Used by drawImage and fillImageMask to divide the target |
| 54 |
// quadrilateral into sections. |
| 55 |
struct ImageSection { |
| 56 |
int y0, y1; // actual y range |
| 57 |
int ia0, ia1; // vertex indices for edge A |
| 58 |
int ib0, ib1; // vertex indices for edge B |
| 59 |
SplashCoord xa0, ya0, xa1, ya1; // edge A |
| 60 |
SplashCoord dxdya; // slope of edge A |
| 61 |
SplashCoord xb0, yb0, xb1, yb1; // edge B |
| 62 |
SplashCoord dxdyb; // slope of edge B |
| 63 |
}; |
| 64 |
|
| 65 |
//------------------------------------------------------------------------ |
| 66 |
// SplashPipe |
| 67 |
//------------------------------------------------------------------------ |
| 68 |
|
| 69 |
#define splashPipeMaxStages 9 |
| 70 |
|
| 71 |
struct SplashPipe { |
| 72 |
// source pattern |
| 73 |
SplashPattern *pattern; |
| 74 |
|
| 75 |
// source alpha and color |
| 76 |
Guchar aInput; |
| 77 |
SplashColor cSrcVal; |
| 78 |
|
| 79 |
// source overprint mask |
| 80 |
//~ this is a kludge - this pointer should be passed as an arg to the |
| 81 |
//~ pipeRun function, but that would require passing in a lot of |
| 82 |
//~ null pointers, since it's rarely used |
| 83 |
Guint *srcOverprintMaskPtr; |
| 84 |
|
| 85 |
// alpha is shape |
| 86 |
GBool alphaIsShape; |
| 87 |
|
| 88 |
// special cases and result color |
| 89 |
GBool noTransparency; |
| 90 |
GBool alphaOnly; |
| 91 |
SplashPipeResultColorCtrl resultColorCtrl; |
| 92 |
|
| 93 |
// non-isolated group correction |
| 94 |
// (this is only used when Splash::composite() is called to composite |
| 95 |
// a non-isolated group onto the backdrop) |
| 96 |
GBool nonIsolatedGroup; |
| 97 |
|
| 98 |
// the "run" function |
| 99 |
void (Splash::*run)(SplashPipe *pipe, int x0, int x1, int y, |
| 100 |
Guchar *shapPetr, Guchar *alphaPtr, |
| 101 |
SplashColorPtr cSrcPtr); |
| 102 |
}; |
| 103 |
|
| 104 |
SplashPipeResultColorCtrl Splash::pipeResultColorNoAlphaBlend[] = { |
| 105 |
splashPipeResultColorNoAlphaBlendMono, |
| 106 |
splashPipeResultColorNoAlphaBlendMono, |
| 107 |
splashPipeResultColorNoAlphaBlendRGB, |
| 108 |
splashPipeResultColorNoAlphaBlendRGB |
| 109 |
#if SPLASH_CMYK |
| 110 |
, |
| 111 |
splashPipeResultColorNoAlphaBlendCMYK |
| 112 |
#endif |
| 113 |
}; |
| 114 |
|
| 115 |
SplashPipeResultColorCtrl Splash::pipeResultColorAlphaNoBlend[] = { |
| 116 |
splashPipeResultColorAlphaNoBlendMono, |
| 117 |
splashPipeResultColorAlphaNoBlendMono, |
| 118 |
splashPipeResultColorAlphaNoBlendRGB, |
| 119 |
splashPipeResultColorAlphaNoBlendRGB |
| 120 |
#if SPLASH_CMYK |
| 121 |
, |
| 122 |
splashPipeResultColorAlphaNoBlendCMYK |
| 123 |
#endif |
| 124 |
}; |
| 125 |
|
| 126 |
SplashPipeResultColorCtrl Splash::pipeResultColorAlphaBlend[] = { |
| 127 |
splashPipeResultColorAlphaBlendMono, |
| 128 |
splashPipeResultColorAlphaBlendMono, |
| 129 |
splashPipeResultColorAlphaBlendRGB, |
| 130 |
splashPipeResultColorAlphaBlendRGB |
| 131 |
#if SPLASH_CMYK |
| 132 |
, |
| 133 |
splashPipeResultColorAlphaBlendCMYK |
| 134 |
#endif |
| 135 |
}; |
| 136 |
|
| 137 |
//------------------------------------------------------------------------ |
| 138 |
// modified region |
| 139 |
//------------------------------------------------------------------------ |
| 140 |
|
| 141 |
void Splash::clearModRegion() { |
| 142 |
modXMin = bitmap->width; |
| 143 |
modYMin = bitmap->height; |
| 144 |
modXMax = -1; |
| 145 |
modYMax = -1; |
| 146 |
} |
| 147 |
|
| 148 |
inline void Splash::updateModX(int x) { |
| 149 |
if (x < modXMin) { |
| 150 |
modXMin = x; |
| 151 |
} |
| 152 |
if (x > modXMax) { |
| 153 |
modXMax = x; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
inline void Splash::updateModY(int y) { |
| 158 |
if (y < modYMin) { |
| 159 |
modYMin = y; |
| 160 |
} |
| 161 |
if (y > modYMax) { |
| 162 |
modYMax = y; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
//------------------------------------------------------------------------ |
| 167 |
// pipeline |
| 168 |
//------------------------------------------------------------------------ |
| 169 |
|
| 170 |
inline void Splash::pipeInit(SplashPipe *pipe, SplashPattern *pattern, |
| 171 |
Guchar aInput, GBool usesShape, GBool usesAlpha, |
| 172 |
GBool nonIsolatedGroup, GBool usesSrcOverprint, |
| 173 |
GBool alphaIsShape) { |
| 174 |
SplashColorMode mode; |
| 175 |
|
| 176 |
mode = bitmap->mode; |
| 177 |
|
| 178 |
pipe->pattern = NULL; |
| 179 |
|
| 180 |
// source color |
| 181 |
if (pattern && pattern->isStatic()) { |
| 182 |
pattern->getColor(0, 0, pipe->cSrcVal); |
| 183 |
pipe->pattern = NULL; |
| 184 |
} else { |
| 185 |
pipe->pattern = pattern; |
| 186 |
} |
| 187 |
|
| 188 |
// source alpha |
| 189 |
pipe->aInput = aInput; |
| 190 |
|
| 191 |
// source overprint mask |
| 192 |
pipe->srcOverprintMaskPtr = NULL; |
| 193 |
|
| 194 |
// alpha is shape |
| 195 |
pipe->alphaIsShape = alphaIsShape; |
| 196 |
|
| 197 |
// special cases |
| 198 |
pipe->noTransparency = aInput == 255 && |
| 199 |
!state->softMask && |
| 200 |
!usesShape && |
| 201 |
!usesAlpha && |
| 202 |
!state->inNonIsolatedGroup && |
| 203 |
!state->inKnockoutGroup && |
| 204 |
!nonIsolatedGroup && |
| 205 |
state->overprintMask == 0xffffffff; |
| 206 |
pipe->alphaOnly = aInput == 255 && |
| 207 |
!state->softMask && |
| 208 |
!usesShape && |
| 209 |
usesAlpha && |
| 210 |
!state->inNonIsolatedGroup && |
| 211 |
!state->inKnockoutGroup && |
| 212 |
!nonIsolatedGroup && |
| 213 |
state->overprintMask == 0xffffffff; |
| 214 |
|
| 215 |
// result color |
| 216 |
if (pipe->noTransparency) { |
| 217 |
// the !state->blendFunc case is handled separately in pipeRun |
| 218 |
pipe->resultColorCtrl = pipeResultColorNoAlphaBlend[mode]; |
| 219 |
} else if (!state->blendFunc) { |
| 220 |
pipe->resultColorCtrl = pipeResultColorAlphaNoBlend[mode]; |
| 221 |
} else { |
| 222 |
pipe->resultColorCtrl = pipeResultColorAlphaBlend[mode]; |
| 223 |
} |
| 224 |
|
| 225 |
// non-isolated group correction |
| 226 |
pipe->nonIsolatedGroup = nonIsolatedGroup; |
| 227 |
|
| 228 |
// select the 'run' function |
| 229 |
pipe->run = &Splash::pipeRun; |
| 230 |
if (shapeBitmap || overprintMaskBitmap || usesSrcOverprint) { |
| 231 |
// use Splash::pipeRun |
| 232 |
} else if (!pipe->pattern && pipe->noTransparency && !state->blendFunc) { |
| 233 |
if (mode == splashModeMono1 && !bitmap->alpha) { |
| 234 |
pipe->run = &Splash::pipeRunSimpleMono1; |
| 235 |
} else if (mode == splashModeMono8 && bitmap->alpha) { |
| 236 |
pipe->run = &Splash::pipeRunSimpleMono8; |
| 237 |
} else if (mode == splashModeRGB8 && bitmap->alpha) { |
| 238 |
pipe->run = &Splash::pipeRunSimpleRGB8; |
| 239 |
} else if (mode == splashModeBGR8 && bitmap->alpha) { |
| 240 |
pipe->run = &Splash::pipeRunSimpleBGR8; |
| 241 |
#if SPLASH_CMYK |
| 242 |
} else if (mode == splashModeCMYK8 && bitmap->alpha) { |
| 243 |
pipe->run = &Splash::pipeRunSimpleCMYK8; |
| 244 |
#endif |
| 245 |
} |
| 246 |
} else if (!pipe->pattern && pipe->alphaOnly && !state->blendFunc) { |
| 247 |
if (mode == splashModeMono1 && !bitmap->alpha) { |
| 248 |
pipe->run = &Splash::pipeRunShapeMono1; |
| 249 |
} else if (mode == splashModeMono8 && bitmap->alpha) { |
| 250 |
pipe->run = &Splash::pipeRunShapeMono8; |
| 251 |
} else if (mode == splashModeRGB8 && bitmap->alpha) { |
| 252 |
pipe->run = &Splash::pipeRunShapeRGB8; |
| 253 |
} else if (mode == splashModeBGR8 && bitmap->alpha) { |
| 254 |
pipe->run = &Splash::pipeRunShapeBGR8; |
| 255 |
#if SPLASH_CMYK |
| 256 |
} else if (mode == splashModeCMYK8 && bitmap->alpha) { |
| 257 |
pipe->run = &Splash::pipeRunShapeCMYK8; |
| 258 |
#endif |
| 259 |
} else if (mode == splashModeMono8 && !bitmap->alpha) { |
| 260 |
// this is used when drawing soft-masked images |
| 261 |
pipe->run = &Splash::pipeRunShapeNoAlphaMono8; |
| 262 |
} |
| 263 |
} else if (!pipe->pattern && !pipe->noTransparency && !state->softMask && |
| 264 |
usesAlpha && |
| 265 |
!(state->inNonIsolatedGroup && (alpha0Bitmap || |
| 266 |
parent->bitmap->alpha)) && |
| 267 |
!state->inKnockoutGroup && |
| 268 |
!state->blendFunc && !pipe->nonIsolatedGroup) { |
| 269 |
if (mode == splashModeMono1 && !bitmap->alpha) { |
| 270 |
pipe->run = &Splash::pipeRunAAMono1; |
| 271 |
} else if (mode == splashModeMono8 && bitmap->alpha) { |
| 272 |
pipe->run = &Splash::pipeRunAAMono8; |
| 273 |
} else if (mode == splashModeRGB8 && bitmap->alpha) { |
| 274 |
pipe->run = &Splash::pipeRunAARGB8; |
| 275 |
} else if (mode == splashModeBGR8 && bitmap->alpha) { |
| 276 |
pipe->run = &Splash::pipeRunAABGR8; |
| 277 |
#if SPLASH_CMYK |
| 278 |
} else if (mode == splashModeCMYK8 && bitmap->alpha) { |
| 279 |
pipe->run = &Splash::pipeRunAACMYK8; |
| 280 |
#endif |
| 281 |
} |
| 282 |
} else if (!pipe->pattern && |
| 283 |
aInput == 255 && |
| 284 |
state->softMask && |
| 285 |
usesAlpha && |
| 286 |
!state->inNonIsolatedGroup && |
| 287 |
!state->inKnockoutGroup && |
| 288 |
!nonIsolatedGroup && |
| 289 |
state->overprintMask == 0xffffffff && |
| 290 |
!state->blendFunc) { |
| 291 |
if (mode == splashModeMono8 && bitmap->alpha) { |
| 292 |
pipe->run = &Splash::pipeRunSoftMaskMono8; |
| 293 |
} else if (mode == splashModeRGB8 && bitmap->alpha) { |
| 294 |
pipe->run = &Splash::pipeRunSoftMaskRGB8; |
| 295 |
} else if (mode == splashModeBGR8 && bitmap->alpha) { |
| 296 |
pipe->run = &Splash::pipeRunSoftMaskBGR8; |
| 297 |
#if SPLASH_CMYK |
| 298 |
} else if (mode == splashModeCMYK8 && bitmap->alpha) { |
| 299 |
pipe->run = &Splash::pipeRunSoftMaskCMYK8; |
| 300 |
#endif |
| 301 |
} |
| 302 |
} else if (!pipe->pattern && !pipe->noTransparency && !state->softMask && |
| 303 |
usesAlpha && |
| 304 |
state->inNonIsolatedGroup && (alpha0Bitmap || |
| 305 |
parent->bitmap->alpha) && |
| 306 |
!state->inKnockoutGroup && |
| 307 |
!state->blendFunc && !pipe->nonIsolatedGroup) { |
| 308 |
if (mode == splashModeMono8 && bitmap->alpha) { |
| 309 |
pipe->run = &Splash::pipeRunNonIsoMono8; |
| 310 |
} else if (mode == splashModeRGB8 && bitmap->alpha) { |
| 311 |
pipe->run = &Splash::pipeRunNonIsoRGB8; |
| 312 |
} else if (mode == splashModeBGR8 && bitmap->alpha) { |
| 313 |
pipe->run = &Splash::pipeRunNonIsoBGR8; |
| 314 |
#if SPLASH_CMYK |
| 315 |
} else if (mode == splashModeCMYK8 && bitmap->alpha) { |
| 316 |
pipe->run = &Splash::pipeRunNonIsoCMYK8; |
| 317 |
#endif |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
// general case |
| 323 |
void Splash::pipeRun(SplashPipe *pipe, int x0, int x1, int y, |
| 324 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 325 |
SplashColorPtr cSrcPtr) { |
| 326 |
Guchar *shapePtr2, *alphaPtr2; |
| 327 |
Guchar shape, alpha, fSrc, aSrc, fDest, aDest; |
| 328 |
Guchar alphaI, alphaIm1, alpha0, fResult, aResult; |
| 329 |
Guchar m1, m2, m3, m4; |
| 330 |
SplashColor cSrc, cDest, c0, cBlend; |
| 331 |
Guchar shapeVal, alphaVal, cResult0, cResult1, cResult2, cResult3; |
| 332 |
int cSrcStride, shapeStride, alphaStride, x, lastX, t; |
| 333 |
SplashColorPtr cBlendIn, destColorPtr; |
| 334 |
Guchar destColorMask; |
| 335 |
Guchar *destShapePtr, *destAlphaPtr; |
| 336 |
SplashColorPtr color0Ptr; |
| 337 |
Guchar color0Mask; |
| 338 |
Guchar *alpha0Ptr; |
| 339 |
SplashColorPtr softMaskPtr; |
| 340 |
Guint overprintMask; |
| 341 |
Guint *overprintMaskPtr; |
| 342 |
#if SPLASH_CMYK |
| 343 |
Guchar aPrev; |
| 344 |
SplashColor cSrc2, cBlendIn2; |
| 345 |
#endif |
| 346 |
int i; |
| 347 |
|
| 348 |
if (cSrcPtr && !pipe->pattern) { |
| 349 |
cSrcStride = bitmapComps; |
| 350 |
} else { |
| 351 |
cSrcPtr = pipe->cSrcVal; |
| 352 |
cSrcStride = 0; |
| 353 |
} |
| 354 |
if (shapePtr) { |
| 355 |
shapePtr2 = shapePtr; |
| 356 |
shapeStride = 1; |
| 357 |
} else { |
| 358 |
shapeVal = 0xff; |
| 359 |
shapePtr2 = &shapeVal; |
| 360 |
shapeStride = 0; |
| 361 |
} |
| 362 |
if (alphaPtr) { |
| 363 |
alphaPtr2 = alphaPtr; |
| 364 |
alphaStride = 1; |
| 365 |
} else { |
| 366 |
alphaVal = 0xff; |
| 367 |
alphaPtr2 = &alphaVal; |
| 368 |
alphaStride = 0; |
| 369 |
} |
| 370 |
|
| 371 |
if (shapePtr) { |
| 372 |
for (; x0 <= x1; ++x0) { |
| 373 |
if (*shapePtr2) { |
| 374 |
break; |
| 375 |
} |
| 376 |
cSrcPtr += cSrcStride; |
| 377 |
++shapePtr2; |
| 378 |
++alphaPtr2; |
| 379 |
if (pipe->srcOverprintMaskPtr) { |
| 380 |
++pipe->srcOverprintMaskPtr; |
| 381 |
} |
| 382 |
} |
| 383 |
} else if (alphaPtr) { |
| 384 |
for (; x0 <= x1; ++x0) { |
| 385 |
if (*alphaPtr2) { |
| 386 |
break; |
| 387 |
} |
| 388 |
cSrcPtr += cSrcStride; |
| 389 |
++alphaPtr2; |
| 390 |
if (pipe->srcOverprintMaskPtr) { |
| 391 |
++pipe->srcOverprintMaskPtr; |
| 392 |
} |
| 393 |
} |
| 394 |
} |
| 395 |
if (x0 > x1) { |
| 396 |
return; |
| 397 |
} |
| 398 |
updateModX(x0); |
| 399 |
updateModY(y); |
| 400 |
lastX = x0; |
| 401 |
|
| 402 |
useBitmapRow(y); |
| 403 |
|
| 404 |
if (bitmap->mode == splashModeMono1) { |
| 405 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + (x0 >> 3)]; |
| 406 |
destColorMask = (Guchar)(0x80 >> (x0 & 7)); |
| 407 |
} else { |
| 408 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0 * bitmapComps]; |
| 409 |
destColorMask = 0; // make gcc happy |
| 410 |
} |
| 411 |
if (shapeBitmap) { |
| 412 |
destShapePtr = &shapeBitmap->alpha[y * shapeBitmap->alphaRowSize + x0]; |
| 413 |
} else { |
| 414 |
destShapePtr = NULL; |
| 415 |
} |
| 416 |
if (bitmap->alpha) { |
| 417 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 418 |
} else { |
| 419 |
destAlphaPtr = NULL; |
| 420 |
} |
| 421 |
if (state->softMask) { |
| 422 |
softMaskPtr = &state->softMask->data[y * state->softMask->rowSize + x0]; |
| 423 |
} else { |
| 424 |
softMaskPtr = NULL; |
| 425 |
} |
| 426 |
if (state->inKnockoutGroup) { |
| 427 |
if (bitmap->mode == splashModeMono1) { |
| 428 |
color0Ptr = |
| 429 |
&parent->bitmap->data[(parentOffsetY + y) * parent->bitmap->rowSize + |
| 430 |
((parentOffsetX + x0) >> 3)]; |
| 431 |
color0Mask = (Guchar)(0x80 >> ((parentOffsetX + x0) & 7)); |
| 432 |
} else { |
| 433 |
color0Ptr = |
| 434 |
&parent->bitmap->data[(parentOffsetY + y) * parent->bitmap->rowSize + |
| 435 |
(parentOffsetX + x0) * bitmapComps]; |
| 436 |
color0Mask = 0; // make gcc happy |
| 437 |
} |
| 438 |
} else { |
| 439 |
color0Ptr = NULL; |
| 440 |
color0Mask = 0; // make gcc happy |
| 441 |
} |
| 442 |
if (alpha0Bitmap) { |
| 443 |
alpha0Ptr = &alpha0Bitmap->alpha[y * alpha0Bitmap->alphaRowSize + x0]; |
| 444 |
} else if (state->inNonIsolatedGroup && parent->bitmap->alpha) { |
| 445 |
alpha0Ptr = &parent->bitmap->alpha[ |
| 446 |
(parentOffsetY + y) * parent->bitmap->alphaRowSize |
| 447 |
+ (parentOffsetX + x0)]; |
| 448 |
} else { |
| 449 |
alpha0Ptr = NULL; |
| 450 |
} |
| 451 |
if (overprintMaskBitmap) { |
| 452 |
overprintMaskPtr = overprintMaskBitmap + y * bitmap->width + x0; |
| 453 |
} else { |
| 454 |
overprintMaskPtr = NULL; |
| 455 |
} |
| 456 |
|
| 457 |
// c0 is only used for non-iso knockout groups, but in some other |
| 458 |
// cases we use m2 * c0[i], with m2=0 -- so initialize c0[i]=0 here |
| 459 |
// to avoid valgrind warnings |
| 460 |
for (i = 0; i < bitmapComps; ++i) { |
| 461 |
c0[i] = 0; |
| 462 |
} |
| 463 |
|
| 464 |
for (x = x0; x <= x1; ++x) { |
| 465 |
|
| 466 |
//----- shape and alpha |
| 467 |
|
| 468 |
shape = *shapePtr2; |
| 469 |
alpha = *alphaPtr2; |
| 470 |
if (!(shapePtr ? shape : alpha)) { |
| 471 |
if (bitmap->mode == splashModeMono1) { |
| 472 |
destColorPtr += destColorMask & 1; |
| 473 |
destColorMask = (Guchar)((destColorMask << 7) | (destColorMask >> 1)); |
| 474 |
} else { |
| 475 |
destColorPtr += bitmapComps; |
| 476 |
} |
| 477 |
if (destShapePtr) { |
| 478 |
++destShapePtr; |
| 479 |
} |
| 480 |
if (destAlphaPtr) { |
| 481 |
++destAlphaPtr; |
| 482 |
} |
| 483 |
if (softMaskPtr) { |
| 484 |
++softMaskPtr; |
| 485 |
} |
| 486 |
if (color0Ptr) { |
| 487 |
if (bitmap->mode == splashModeMono1) { |
| 488 |
color0Ptr += color0Mask & 1; |
| 489 |
color0Mask = (Guchar)((color0Mask << 7) | (color0Mask >> 1)); |
| 490 |
} else { |
| 491 |
color0Ptr += bitmapComps; |
| 492 |
} |
| 493 |
} |
| 494 |
if (alpha0Ptr) { |
| 495 |
++alpha0Ptr; |
| 496 |
} |
| 497 |
cSrcPtr += cSrcStride; |
| 498 |
shapePtr2 += shapeStride; |
| 499 |
alphaPtr2 += alphaStride; |
| 500 |
if (pipe->srcOverprintMaskPtr) { |
| 501 |
++pipe->srcOverprintMaskPtr; |
| 502 |
} |
| 503 |
if (overprintMaskPtr) { |
| 504 |
++overprintMaskPtr; |
| 505 |
} |
| 506 |
continue; |
| 507 |
} |
| 508 |
lastX = x; |
| 509 |
|
| 510 |
//----- source color |
| 511 |
|
| 512 |
// static pattern: handled in pipeInit |
| 513 |
// fixed color: handled in pipeInit |
| 514 |
|
| 515 |
// dynamic pattern |
| 516 |
if (pipe->pattern) { |
| 517 |
pipe->pattern->getColor(x, y, pipe->cSrcVal); |
| 518 |
} |
| 519 |
|
| 520 |
cResult0 = cResult1 = cResult2 = cResult3 = 0; // make gcc happy |
| 521 |
|
| 522 |
if (pipe->noTransparency && !state->blendFunc) { |
| 523 |
|
| 524 |
//----- handle overprint |
| 525 |
|
| 526 |
if (overprintMaskPtr) { |
| 527 |
*overprintMaskPtr++ = 0xffffffff; |
| 528 |
} |
| 529 |
|
| 530 |
//----- result color |
| 531 |
|
| 532 |
switch (bitmap->mode) { |
| 533 |
case splashModeMono1: |
| 534 |
case splashModeMono8: |
| 535 |
cResult0 = state->grayTransfer[cSrcPtr[0]]; |
| 536 |
break; |
| 537 |
case splashModeRGB8: |
| 538 |
case splashModeBGR8: |
| 539 |
cResult0 = state->rgbTransferR[cSrcPtr[0]]; |
| 540 |
cResult1 = state->rgbTransferG[cSrcPtr[1]]; |
| 541 |
cResult2 = state->rgbTransferB[cSrcPtr[2]]; |
| 542 |
break; |
| 543 |
#if SPLASH_CMYK |
| 544 |
case splashModeCMYK8: |
| 545 |
cResult0 = state->cmykTransferC[cSrcPtr[0]]; |
| 546 |
cResult1 = state->cmykTransferM[cSrcPtr[1]]; |
| 547 |
cResult2 = state->cmykTransferY[cSrcPtr[2]]; |
| 548 |
cResult3 = state->cmykTransferK[cSrcPtr[3]]; |
| 549 |
break; |
| 550 |
#endif |
| 551 |
} |
| 552 |
fResult = 255; |
| 553 |
aResult = 255; |
| 554 |
|
| 555 |
} else { // if (noTransparency && !blendFunc) |
| 556 |
|
| 557 |
//----- read destination color |
| 558 |
|
| 559 |
switch (bitmap->mode) { |
| 560 |
case splashModeMono1: |
| 561 |
cDest[0] = (*destColorPtr & destColorMask) ? 0xff : 0x00; |
| 562 |
break; |
| 563 |
case splashModeMono8: |
| 564 |
cDest[0] = *destColorPtr; |
| 565 |
break; |
| 566 |
case splashModeRGB8: |
| 567 |
cDest[0] = destColorPtr[0]; |
| 568 |
cDest[1] = destColorPtr[1]; |
| 569 |
cDest[2] = destColorPtr[2]; |
| 570 |
break; |
| 571 |
case splashModeBGR8: |
| 572 |
cDest[0] = destColorPtr[2]; |
| 573 |
cDest[1] = destColorPtr[1]; |
| 574 |
cDest[2] = destColorPtr[0]; |
| 575 |
break; |
| 576 |
#if SPLASH_CMYK |
| 577 |
case splashModeCMYK8: |
| 578 |
cDest[0] = destColorPtr[0]; |
| 579 |
cDest[1] = destColorPtr[1]; |
| 580 |
cDest[2] = destColorPtr[2]; |
| 581 |
cDest[3] = destColorPtr[3]; |
| 582 |
break; |
| 583 |
#endif |
| 584 |
} |
| 585 |
|
| 586 |
//----- read backdrop color |
| 587 |
// (only used for non-iso knockout groups) |
| 588 |
|
| 589 |
if (color0Ptr && alpha0Ptr) { |
| 590 |
switch (bitmap->mode) { |
| 591 |
case splashModeMono1: |
| 592 |
c0[0] = (*color0Ptr & color0Mask) ? 0xff : 0x00; |
| 593 |
color0Ptr += color0Mask & 1; |
| 594 |
color0Mask = (Guchar)((color0Mask << 7) | (color0Mask >> 1)); |
| 595 |
break; |
| 596 |
case splashModeMono8: |
| 597 |
c0[0] = *color0Ptr++; |
| 598 |
break; |
| 599 |
case splashModeRGB8: |
| 600 |
c0[0] = color0Ptr[0]; |
| 601 |
c0[1] = color0Ptr[1]; |
| 602 |
c0[2] = color0Ptr[2]; |
| 603 |
color0Ptr += 3; |
| 604 |
break; |
| 605 |
case splashModeBGR8: |
| 606 |
c0[2] = color0Ptr[0]; |
| 607 |
c0[1] = color0Ptr[1]; |
| 608 |
c0[0] = color0Ptr[2]; |
| 609 |
color0Ptr += 3; |
| 610 |
break; |
| 611 |
#if SPLASH_CMYK |
| 612 |
case splashModeCMYK8: |
| 613 |
c0[0] = color0Ptr[0]; |
| 614 |
c0[1] = color0Ptr[1]; |
| 615 |
c0[2] = color0Ptr[2]; |
| 616 |
c0[3] = color0Ptr[3]; |
| 617 |
color0Ptr += 4; |
| 618 |
break; |
| 619 |
#endif |
| 620 |
} |
| 621 |
cBlendIn = c0; |
| 622 |
} else { |
| 623 |
cBlendIn = cDest; |
| 624 |
} |
| 625 |
|
| 626 |
//----- read destination shape and alpha |
| 627 |
|
| 628 |
if (destShapePtr) { |
| 629 |
fDest = *destShapePtr; |
| 630 |
} else { |
| 631 |
fDest = 0xff; |
| 632 |
} |
| 633 |
|
| 634 |
if (destAlphaPtr) { |
| 635 |
aDest = *destAlphaPtr; |
| 636 |
} else { |
| 637 |
aDest = 0xff; |
| 638 |
} |
| 639 |
|
| 640 |
//----- read source color; handle overprint |
| 641 |
|
| 642 |
if (pipe->srcOverprintMaskPtr) { |
| 643 |
overprintMask = *pipe->srcOverprintMaskPtr++; |
| 644 |
} else { |
| 645 |
overprintMask = state->overprintMask; |
| 646 |
} |
| 647 |
if (overprintMaskPtr) { |
| 648 |
*overprintMaskPtr++ |= overprintMask; |
| 649 |
} |
| 650 |
|
| 651 |
switch (bitmap->mode) { |
| 652 |
case splashModeMono1: |
| 653 |
case splashModeMono8: |
| 654 |
cSrc[0] = state->grayTransfer[cSrcPtr[0]]; |
| 655 |
break; |
| 656 |
case splashModeRGB8: |
| 657 |
case splashModeBGR8: |
| 658 |
cSrc[0] = state->rgbTransferR[cSrcPtr[0]]; |
| 659 |
cSrc[1] = state->rgbTransferG[cSrcPtr[1]]; |
| 660 |
cSrc[2] = state->rgbTransferB[cSrcPtr[2]]; |
| 661 |
break; |
| 662 |
#if SPLASH_CMYK |
| 663 |
case splashModeCMYK8: |
| 664 |
if (alpha0Ptr) { // non-isolated group |
| 665 |
if (color0Ptr) { // non-isolated, knockout group |
| 666 |
aPrev = *alpha0Ptr; |
| 667 |
} else { // non-isolated, non-knockout group |
| 668 |
aPrev = (Guchar)(*alpha0Ptr + aDest - div255(*alpha0Ptr * aDest)); |
| 669 |
} |
| 670 |
} else { // isolated group |
| 671 |
if (color0Ptr) { // isolated, knockout group |
| 672 |
aPrev = 0; |
| 673 |
} else { // isolated, non-knockout group |
| 674 |
aPrev = aDest; |
| 675 |
} |
| 676 |
} |
| 677 |
if (overprintMask & 0x01) { |
| 678 |
cSrc[0] = state->cmykTransferC[cSrcPtr[0]]; |
| 679 |
} else { |
| 680 |
cSrc[0] = div255(aPrev * cDest[0]); |
| 681 |
} |
| 682 |
if (overprintMask & 0x02) { |
| 683 |
cSrc[1] = state->cmykTransferM[cSrcPtr[1]]; |
| 684 |
} else { |
| 685 |
cSrc[1] = div255(aPrev * cDest[1]); |
| 686 |
} |
| 687 |
if (overprintMask & 0x04) { |
| 688 |
cSrc[2] = state->cmykTransferY[cSrcPtr[2]]; |
| 689 |
} else { |
| 690 |
cSrc[2] = div255(aPrev * cDest[2]); |
| 691 |
} |
| 692 |
if (overprintMask & 0x08) { |
| 693 |
cSrc[3] = state->cmykTransferK[cSrcPtr[3]]; |
| 694 |
} else { |
| 695 |
cSrc[3] = div255(aPrev * cDest[3]); |
| 696 |
} |
| 697 |
break; |
| 698 |
#endif |
| 699 |
} |
| 700 |
|
| 701 |
//----- source shape and alpha |
| 702 |
|
| 703 |
fSrc = shape; |
| 704 |
aSrc = div255(pipe->aInput * alpha); |
| 705 |
if (softMaskPtr) { |
| 706 |
if (pipe->alphaIsShape) { |
| 707 |
fSrc = div255(fSrc * *softMaskPtr); |
| 708 |
} |
| 709 |
aSrc = div255(aSrc * *softMaskPtr); |
| 710 |
++softMaskPtr; |
| 711 |
} |
| 712 |
|
| 713 |
//----- non-isolated group correction |
| 714 |
|
| 715 |
if (pipe->nonIsolatedGroup && alpha != 0) { |
| 716 |
// This path is only used when Splash::composite() is called to |
| 717 |
// composite a non-isolated group onto the backdrop. In this |
| 718 |
// case, alpha is the source (group) alpha. |
| 719 |
// |
| 720 |
// In a nested non-isolated group, i.e., if the destination is |
| 721 |
// also a non-isolated group (state->inNonIsolatedGroup), we |
| 722 |
// need to compute the corrected alpha, because the |
| 723 |
// destination is is storing group alpha (same computation as |
| 724 |
// blitCorrectedAlpha). |
| 725 |
if (alpha0Ptr) { |
| 726 |
t = *alpha0Ptr; |
| 727 |
t = (Guchar)(aDest + t - div255(aDest * t)); |
| 728 |
} else { |
| 729 |
t = aDest; |
| 730 |
} |
| 731 |
t = (t * 255) / alpha - t; |
| 732 |
switch (bitmap->mode) { |
| 733 |
#if SPLASH_CMYK |
| 734 |
case splashModeCMYK8: |
| 735 |
cSrc[3] = clip255(cSrc[3] + ((cSrc[3] - cDest[3]) * t) / 255); |
| 736 |
#endif |
| 737 |
case splashModeRGB8: |
| 738 |
case splashModeBGR8: |
| 739 |
cSrc[2] = clip255(cSrc[2] + ((cSrc[2] - cDest[2]) * t) / 255); |
| 740 |
cSrc[1] = clip255(cSrc[1] + ((cSrc[1] - cDest[1]) * t) / 255); |
| 741 |
case splashModeMono1: |
| 742 |
case splashModeMono8: |
| 743 |
cSrc[0] = clip255(cSrc[0] + ((cSrc[0] - cDest[0]) * t) / 255); |
| 744 |
break; |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
//----- blend function |
| 749 |
|
| 750 |
if (state->blendFunc) { |
| 751 |
#if SPLASH_CMYK |
| 752 |
if (bitmap->mode == splashModeCMYK8) { |
| 753 |
// convert colors to additive |
| 754 |
cSrc2[0] = (Guchar)(0xff - cSrc[0]); |
| 755 |
cSrc2[1] = (Guchar)(0xff - cSrc[1]); |
| 756 |
cSrc2[2] = (Guchar)(0xff - cSrc[2]); |
| 757 |
cSrc2[3] = (Guchar)(0xff - cSrc[3]); |
| 758 |
cBlendIn2[0] = (Guchar)(0xff - cBlendIn[0]); |
| 759 |
cBlendIn2[1] = (Guchar)(0xff - cBlendIn[1]); |
| 760 |
cBlendIn2[2] = (Guchar)(0xff - cBlendIn[2]); |
| 761 |
cBlendIn2[3] = (Guchar)(0xff - cBlendIn[3]); |
| 762 |
(*state->blendFunc)(cSrc2, cBlendIn2, cBlend, bitmap->mode); |
| 763 |
// convert result back to subtractive |
| 764 |
cBlend[0] = (Guchar)(0xff - cBlend[0]); |
| 765 |
cBlend[1] = (Guchar)(0xff - cBlend[1]); |
| 766 |
cBlend[2] = (Guchar)(0xff - cBlend[2]); |
| 767 |
cBlend[3] = (Guchar)(0xff - cBlend[3]); |
| 768 |
} else |
| 769 |
#endif |
| 770 |
(*state->blendFunc)(cSrc, cBlendIn, cBlend, bitmap->mode); |
| 771 |
} |
| 772 |
|
| 773 |
//----- result shape |
| 774 |
|
| 775 |
fResult = (Guchar)(fSrc + fDest - div255(fSrc * fDest)); |
| 776 |
|
| 777 |
//----- result alpha |
| 778 |
// and setup for result color |
| 779 |
|
| 780 |
// alphaI = alpha_i |
| 781 |
// alphaIm1 = alpha_(i-1) |
| 782 |
|
| 783 |
if (pipe->noTransparency) { |
| 784 |
alphaI = aResult = 255; |
| 785 |
m1 = m2 = m3 = m4 = 0; // make gcc happy |
| 786 |
} else if (alpha0Ptr) { // non-isolated |
| 787 |
alpha0 = *alpha0Ptr++; |
| 788 |
if (color0Ptr) { // non-isolated, knockout |
| 789 |
aResult = (Guchar)(div255((255 - fSrc) * aDest) + aSrc); |
| 790 |
alphaI = (Guchar)(alpha0 + aResult - div255(alpha0 * aResult)); |
| 791 |
alphaIm1 = (Guchar)(alpha0 + aDest - div255(alpha0 * aDest)); |
| 792 |
m1 = div255((255 - fSrc) * alphaIm1); |
| 793 |
m2 = div255((fSrc - aSrc) * alpha0); |
| 794 |
m3 = div255(aSrc * (255 - alpha0)); |
| 795 |
m4 = div255(aSrc * alpha0); |
| 796 |
} else { // non-isolated, non-knockout |
| 797 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 798 |
alphaI = (Guchar)(alpha0 + aResult - div255(alpha0 * aResult)); |
| 799 |
alphaIm1 = (Guchar)(alpha0 + aDest - div255(alpha0 * aDest)); |
| 800 |
m1 = alphaI - aSrc; |
| 801 |
m2 = 0; |
| 802 |
m3 = div255(aSrc * (255 - alphaIm1)); |
| 803 |
m4 = div255(aSrc * alphaIm1); |
| 804 |
} |
| 805 |
} else { |
| 806 |
if (color0Ptr) { // isolated, knockout |
| 807 |
aResult = (Guchar)(div255((255 - fSrc) * aDest) + aSrc); |
| 808 |
alphaI = aResult; |
| 809 |
alphaIm1 = aDest; |
| 810 |
m1 = div255((255 - fSrc) * alphaIm1); |
| 811 |
m2 = 0; |
| 812 |
m3 = aSrc; |
| 813 |
m4 = 0; |
| 814 |
} else { // isolated, non-knockout |
| 815 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 816 |
alphaI = aResult; |
| 817 |
alphaIm1 = aDest; |
| 818 |
m1 = alphaI - aSrc; |
| 819 |
m2 = 0; |
| 820 |
m3 = div255(aSrc * (255 - alphaIm1)); |
| 821 |
m4 = div255(aSrc * alphaIm1); |
| 822 |
} |
| 823 |
} |
| 824 |
|
| 825 |
//----- result color |
| 826 |
|
| 827 |
switch (pipe->resultColorCtrl) { |
| 828 |
|
| 829 |
case splashPipeResultColorNoAlphaBlendMono: |
| 830 |
cResult0 = div255((255 - aDest) * cSrc[0] + aDest * cBlend[0]); |
| 831 |
break; |
| 832 |
case splashPipeResultColorNoAlphaBlendRGB: |
| 833 |
cResult0 = div255((255 - aDest) * cSrc[0] + aDest * cBlend[0]); |
| 834 |
cResult1 = div255((255 - aDest) * cSrc[1] + aDest * cBlend[1]); |
| 835 |
cResult2 = div255((255 - aDest) * cSrc[2] + aDest * cBlend[2]); |
| 836 |
break; |
| 837 |
#if SPLASH_CMYK |
| 838 |
case splashPipeResultColorNoAlphaBlendCMYK: |
| 839 |
cResult0 = div255((255 - aDest) * cSrc[0] + aDest * cBlend[0]); |
| 840 |
cResult1 = div255((255 - aDest) * cSrc[1] + aDest * cBlend[1]); |
| 841 |
cResult2 = div255((255 - aDest) * cSrc[2] + aDest * cBlend[2]); |
| 842 |
cResult3 = div255((255 - aDest) * cSrc[3] + aDest * cBlend[3]); |
| 843 |
break; |
| 844 |
#endif |
| 845 |
|
| 846 |
case splashPipeResultColorAlphaNoBlendMono: |
| 847 |
if (alphaI == 0) { |
| 848 |
cResult0 = 0; |
| 849 |
} else { |
| 850 |
cResult0 = (Guchar)((m1 * cDest[0] + m2 * c0[0] + aSrc * cSrc[0]) |
| 851 |
/ alphaI); |
| 852 |
} |
| 853 |
break; |
| 854 |
case splashPipeResultColorAlphaNoBlendRGB: |
| 855 |
if (alphaI == 0) { |
| 856 |
cResult0 = 0; |
| 857 |
cResult1 = 0; |
| 858 |
cResult2 = 0; |
| 859 |
} else { |
| 860 |
cResult0 = (Guchar)((m1 * cDest[0] + m2 * c0[0] + aSrc * cSrc[0]) |
| 861 |
/ alphaI); |
| 862 |
cResult1 = (Guchar)((m1 * cDest[1] + m2 * c0[1] + aSrc * cSrc[1]) |
| 863 |
/ alphaI); |
| 864 |
cResult2 = (Guchar)((m1 * cDest[2] + m2 * c0[2] + aSrc * cSrc[2]) |
| 865 |
/ alphaI); |
| 866 |
} |
| 867 |
break; |
| 868 |
#if SPLASH_CMYK |
| 869 |
case splashPipeResultColorAlphaNoBlendCMYK: |
| 870 |
if (alphaI == 0) { |
| 871 |
cResult0 = 0; |
| 872 |
cResult1 = 0; |
| 873 |
cResult2 = 0; |
| 874 |
cResult3 = 0; |
| 875 |
} else { |
| 876 |
cResult0 = (Guchar)((m1 * cDest[0] + m2 * c0[0] + aSrc * cSrc[0]) |
| 877 |
/ alphaI); |
| 878 |
cResult1 = (Guchar)((m1 * cDest[1] + m2 * c0[1] + aSrc * cSrc[1]) |
| 879 |
/ alphaI); |
| 880 |
cResult2 = (Guchar)((m1 * cDest[2] + m2 * c0[2] + aSrc * cSrc[2]) |
| 881 |
/ alphaI); |
| 882 |
cResult3 = (Guchar)((m1 * cDest[3] + m2 * c0[2] + aSrc * cSrc[3]) |
| 883 |
/ alphaI); |
| 884 |
} |
| 885 |
break; |
| 886 |
#endif |
| 887 |
|
| 888 |
case splashPipeResultColorAlphaBlendMono: |
| 889 |
if (alphaI == 0) { |
| 890 |
cResult0 = 0; |
| 891 |
} else { |
| 892 |
cResult0 = (Guchar)((m1 * cDest[0] + m2 * c0[0] + |
| 893 |
m3 * cSrc[0] + m4 * cBlend[0]) |
| 894 |
/ alphaI); |
| 895 |
} |
| 896 |
break; |
| 897 |
case splashPipeResultColorAlphaBlendRGB: |
| 898 |
if (alphaI == 0) { |
| 899 |
cResult0 = 0; |
| 900 |
cResult1 = 0; |
| 901 |
cResult2 = 0; |
| 902 |
} else { |
| 903 |
cResult0 = (Guchar)((m1 * cDest[0] + m2 * c0[0] + |
| 904 |
m3 * cSrc[0] + m4 * cBlend[0]) |
| 905 |
/ alphaI); |
| 906 |
cResult1 = (Guchar)((m1 * cDest[1] + m2 * c0[1] + |
| 907 |
m3 * cSrc[1] + m4 * cBlend[1]) |
| 908 |
/ alphaI); |
| 909 |
cResult2 = (Guchar)((m1 * cDest[2] + m2 * c0[2] + |
| 910 |
m3 * cSrc[2] + m4 * cBlend[2]) |
| 911 |
/ alphaI); |
| 912 |
} |
| 913 |
break; |
| 914 |
#if SPLASH_CMYK |
| 915 |
case splashPipeResultColorAlphaBlendCMYK: |
| 916 |
if (alphaI == 0) { |
| 917 |
cResult0 = 0; |
| 918 |
cResult1 = 0; |
| 919 |
cResult2 = 0; |
| 920 |
cResult3 = 0; |
| 921 |
} else { |
| 922 |
cResult0 = (Guchar)((m1 * cDest[0] + m2 * c0[0] + |
| 923 |
m3 * cSrc[0] + m4 * cBlend[0]) |
| 924 |
/ alphaI); |
| 925 |
cResult1 = (Guchar)((m1 * cDest[1] + m2 * c0[1] + |
| 926 |
m3 * cSrc[1] + m4 * cBlend[1]) |
| 927 |
/ alphaI); |
| 928 |
cResult2 = (Guchar)((m1 * cDest[2] + m2 * c0[2] + |
| 929 |
m3 * cSrc[2] + m4 * cBlend[2]) |
| 930 |
/ alphaI); |
| 931 |
cResult3 = (Guchar)((m1 * cDest[3] + m2 * c0[3] + |
| 932 |
m3 * cSrc[3] + m4 * cBlend[3]) |
| 933 |
/ alphaI); |
| 934 |
} |
| 935 |
break; |
| 936 |
#endif |
| 937 |
} |
| 938 |
|
| 939 |
} // if (noTransparency && !blendFunc) |
| 940 |
|
| 941 |
//----- write destination pixel |
| 942 |
|
| 943 |
switch (bitmap->mode) { |
| 944 |
case splashModeMono1: |
| 945 |
if (state->screen->test(x, y, cResult0)) { |
| 946 |
*destColorPtr |= destColorMask; |
| 947 |
} else { |
| 948 |
*destColorPtr &= (Guchar)~destColorMask; |
| 949 |
} |
| 950 |
destColorPtr += destColorMask & 1; |
| 951 |
destColorMask = (Guchar)((destColorMask << 7) | (destColorMask >> 1)); |
| 952 |
break; |
| 953 |
case splashModeMono8: |
| 954 |
*destColorPtr++ = cResult0; |
| 955 |
break; |
| 956 |
case splashModeRGB8: |
| 957 |
destColorPtr[0] = cResult0; |
| 958 |
destColorPtr[1] = cResult1; |
| 959 |
destColorPtr[2] = cResult2; |
| 960 |
destColorPtr += 3; |
| 961 |
break; |
| 962 |
case splashModeBGR8: |
| 963 |
destColorPtr[0] = cResult2; |
| 964 |
destColorPtr[1] = cResult1; |
| 965 |
destColorPtr[2] = cResult0; |
| 966 |
destColorPtr += 3; |
| 967 |
break; |
| 968 |
#if SPLASH_CMYK |
| 969 |
case splashModeCMYK8: |
| 970 |
destColorPtr[0] = cResult0; |
| 971 |
destColorPtr[1] = cResult1; |
| 972 |
destColorPtr[2] = cResult2; |
| 973 |
destColorPtr[3] = cResult3; |
| 974 |
destColorPtr += 4; |
| 975 |
break; |
| 976 |
#endif |
| 977 |
} |
| 978 |
if (destShapePtr) { |
| 979 |
*destShapePtr++ = fResult; |
| 980 |
} |
| 981 |
if (destAlphaPtr) { |
| 982 |
*destAlphaPtr++ = aResult; |
| 983 |
} |
| 984 |
|
| 985 |
cSrcPtr += cSrcStride; |
| 986 |
shapePtr2 += shapeStride; |
| 987 |
alphaPtr2 += alphaStride; |
| 988 |
} // for (x ...) |
| 989 |
|
| 990 |
updateModX(lastX); |
| 991 |
} |
| 992 |
|
| 993 |
// special case: |
| 994 |
// !pipe->pattern && pipe->noTransparency && !state->blendFunc && |
| 995 |
// bitmap->mode == splashModeMono1 && !bitmap->alpha) { |
| 996 |
void Splash::pipeRunSimpleMono1(SplashPipe *pipe, int x0, int x1, int y, |
| 997 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 998 |
SplashColorPtr cSrcPtr) { |
| 999 |
Guchar cResult0; |
| 1000 |
SplashColorPtr destColorPtr; |
| 1001 |
Guchar destColorMask; |
| 1002 |
SplashScreenCursor screenCursor; |
| 1003 |
int cSrcStride, x; |
| 1004 |
|
| 1005 |
if (cSrcPtr) { |
| 1006 |
cSrcStride = 1; |
| 1007 |
} else { |
| 1008 |
cSrcPtr = pipe->cSrcVal; |
| 1009 |
cSrcStride = 0; |
| 1010 |
} |
| 1011 |
if (x0 > x1) { |
| 1012 |
return; |
| 1013 |
} |
| 1014 |
updateModX(x0); |
| 1015 |
updateModX(x1); |
| 1016 |
updateModY(y); |
| 1017 |
|
| 1018 |
useBitmapRow(y); |
| 1019 |
|
| 1020 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + (x0 >> 3)]; |
| 1021 |
destColorMask = (Guchar)(0x80 >> (x0 & 7)); |
| 1022 |
|
| 1023 |
screenCursor = state->screen->getTestCursor(y); |
| 1024 |
|
| 1025 |
for (x = x0; x <= x1; ++x) { |
| 1026 |
|
| 1027 |
//----- write destination pixel |
| 1028 |
cResult0 = state->grayTransfer[cSrcPtr[0]]; |
| 1029 |
if (state->screen->testWithCursor(screenCursor, x, cResult0)) { |
| 1030 |
*destColorPtr |= destColorMask; |
| 1031 |
} else { |
| 1032 |
*destColorPtr &= (Guchar)~destColorMask; |
| 1033 |
} |
| 1034 |
destColorPtr += destColorMask & 1; |
| 1035 |
destColorMask = (Guchar)((destColorMask << 7) | (destColorMask >> 1)); |
| 1036 |
|
| 1037 |
cSrcPtr += cSrcStride; |
| 1038 |
} |
| 1039 |
} |
| 1040 |
|
| 1041 |
// special case: |
| 1042 |
// !pipe->pattern && pipe->noTransparency && !state->blendFunc && |
| 1043 |
// bitmap->mode == splashModeMono8 && bitmap->alpha) { |
| 1044 |
void Splash::pipeRunSimpleMono8(SplashPipe *pipe, int x0, int x1, int y, |
| 1045 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1046 |
SplashColorPtr cSrcPtr) { |
| 1047 |
SplashColorPtr destColorPtr; |
| 1048 |
Guchar *destAlphaPtr; |
| 1049 |
int cSrcStride, x; |
| 1050 |
|
| 1051 |
if (cSrcPtr) { |
| 1052 |
cSrcStride = 1; |
| 1053 |
} else { |
| 1054 |
cSrcPtr = pipe->cSrcVal; |
| 1055 |
cSrcStride = 0; |
| 1056 |
} |
| 1057 |
if (x0 > x1) { |
| 1058 |
return; |
| 1059 |
} |
| 1060 |
updateModX(x0); |
| 1061 |
updateModX(x1); |
| 1062 |
updateModY(y); |
| 1063 |
|
| 1064 |
useBitmapRow(y); |
| 1065 |
|
| 1066 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; |
| 1067 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1068 |
|
| 1069 |
for (x = x0; x <= x1; ++x) { |
| 1070 |
|
| 1071 |
//----- write destination pixel |
| 1072 |
*destColorPtr++ = state->grayTransfer[cSrcPtr[0]]; |
| 1073 |
*destAlphaPtr++ = 255; |
| 1074 |
|
| 1075 |
cSrcPtr += cSrcStride; |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
// special case: |
| 1080 |
// !pipe->pattern && pipe->noTransparency && !state->blendFunc && |
| 1081 |
// bitmap->mode == splashModeRGB8 && bitmap->alpha) { |
| 1082 |
void Splash::pipeRunSimpleRGB8(SplashPipe *pipe, int x0, int x1, int y, |
| 1083 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1084 |
SplashColorPtr cSrcPtr) { |
| 1085 |
SplashColorPtr destColorPtr; |
| 1086 |
Guchar *destAlphaPtr; |
| 1087 |
int cSrcStride, x; |
| 1088 |
|
| 1089 |
if (cSrcPtr) { |
| 1090 |
cSrcStride = 3; |
| 1091 |
} else { |
| 1092 |
cSrcPtr = pipe->cSrcVal; |
| 1093 |
cSrcStride = 0; |
| 1094 |
} |
| 1095 |
if (x0 > x1) { |
| 1096 |
return; |
| 1097 |
} |
| 1098 |
updateModX(x0); |
| 1099 |
updateModX(x1); |
| 1100 |
updateModY(y); |
| 1101 |
|
| 1102 |
useBitmapRow(y); |
| 1103 |
|
| 1104 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; |
| 1105 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1106 |
|
| 1107 |
for (x = x0; x <= x1; ++x) { |
| 1108 |
|
| 1109 |
//----- write destination pixel |
| 1110 |
destColorPtr[0] = state->rgbTransferR[cSrcPtr[0]]; |
| 1111 |
destColorPtr[1] = state->rgbTransferG[cSrcPtr[1]]; |
| 1112 |
destColorPtr[2] = state->rgbTransferB[cSrcPtr[2]]; |
| 1113 |
destColorPtr += 3; |
| 1114 |
*destAlphaPtr++ = 255; |
| 1115 |
|
| 1116 |
cSrcPtr += cSrcStride; |
| 1117 |
} |
| 1118 |
} |
| 1119 |
|
| 1120 |
// special case: |
| 1121 |
// !pipe->pattern && pipe->noTransparency && !state->blendFunc && |
| 1122 |
// bitmap->mode == splashModeBGR8 && bitmap->alpha) { |
| 1123 |
void Splash::pipeRunSimpleBGR8(SplashPipe *pipe, int x0, int x1, int y, |
| 1124 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1125 |
SplashColorPtr cSrcPtr) { |
| 1126 |
SplashColorPtr destColorPtr; |
| 1127 |
Guchar *destAlphaPtr; |
| 1128 |
int cSrcStride, x; |
| 1129 |
|
| 1130 |
if (cSrcPtr) { |
| 1131 |
cSrcStride = 3; |
| 1132 |
} else { |
| 1133 |
cSrcPtr = pipe->cSrcVal; |
| 1134 |
cSrcStride = 0; |
| 1135 |
} |
| 1136 |
if (x0 > x1) { |
| 1137 |
return; |
| 1138 |
} |
| 1139 |
updateModX(x0); |
| 1140 |
updateModX(x1); |
| 1141 |
updateModY(y); |
| 1142 |
|
| 1143 |
useBitmapRow(y); |
| 1144 |
|
| 1145 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; |
| 1146 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1147 |
|
| 1148 |
for (x = x0; x <= x1; ++x) { |
| 1149 |
|
| 1150 |
//----- write destination pixel |
| 1151 |
destColorPtr[0] = state->rgbTransferB[cSrcPtr[2]]; |
| 1152 |
destColorPtr[1] = state->rgbTransferG[cSrcPtr[1]]; |
| 1153 |
destColorPtr[2] = state->rgbTransferR[cSrcPtr[0]]; |
| 1154 |
destColorPtr += 3; |
| 1155 |
*destAlphaPtr++ = 255; |
| 1156 |
|
| 1157 |
cSrcPtr += cSrcStride; |
| 1158 |
} |
| 1159 |
} |
| 1160 |
|
| 1161 |
#if SPLASH_CMYK |
| 1162 |
// special case: |
| 1163 |
// !pipe->pattern && pipe->noTransparency && !state->blendFunc && |
| 1164 |
// bitmap->mode == splashModeCMYK8 && bitmap->alpha) { |
| 1165 |
void Splash::pipeRunSimpleCMYK8(SplashPipe *pipe, int x0, int x1, int y, |
| 1166 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1167 |
SplashColorPtr cSrcPtr) { |
| 1168 |
SplashColorPtr destColorPtr; |
| 1169 |
Guchar *destAlphaPtr; |
| 1170 |
int cSrcStride, x; |
| 1171 |
|
| 1172 |
if (cSrcPtr) { |
| 1173 |
cSrcStride = 4; |
| 1174 |
} else { |
| 1175 |
cSrcPtr = pipe->cSrcVal; |
| 1176 |
cSrcStride = 0; |
| 1177 |
} |
| 1178 |
if (x0 > x1) { |
| 1179 |
return; |
| 1180 |
} |
| 1181 |
updateModX(x0); |
| 1182 |
updateModX(x1); |
| 1183 |
updateModY(y); |
| 1184 |
|
| 1185 |
useBitmapRow(y); |
| 1186 |
|
| 1187 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 4 * x0]; |
| 1188 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1189 |
|
| 1190 |
for (x = x0; x <= x1; ++x) { |
| 1191 |
|
| 1192 |
//----- write destination pixel |
| 1193 |
destColorPtr[0] = state->cmykTransferC[cSrcPtr[0]]; |
| 1194 |
destColorPtr[1] = state->cmykTransferM[cSrcPtr[1]]; |
| 1195 |
destColorPtr[2] = state->cmykTransferY[cSrcPtr[2]]; |
| 1196 |
destColorPtr[3] = state->cmykTransferK[cSrcPtr[3]]; |
| 1197 |
destColorPtr += 4; |
| 1198 |
*destAlphaPtr++ = 255; |
| 1199 |
|
| 1200 |
cSrcPtr += cSrcStride; |
| 1201 |
} |
| 1202 |
} |
| 1203 |
#endif |
| 1204 |
|
| 1205 |
|
| 1206 |
// special case: |
| 1207 |
// !pipe->pattern && pipe->alphaOnly && !state->blendFunc && |
| 1208 |
// bitmap->mode == splashModeMono1 && !bitmap->alpha |
| 1209 |
void Splash::pipeRunShapeMono1(SplashPipe *pipe, int x0, int x1, int y, |
| 1210 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1211 |
SplashColorPtr cSrcPtr) { |
| 1212 |
Guchar alpha, aSrc, cSrc0, cDest0, cResult0; |
| 1213 |
SplashColorPtr destColorPtr; |
| 1214 |
Guchar destColorMask; |
| 1215 |
SplashScreenCursor screenCursor; |
| 1216 |
int cSrcStride, x, lastX; |
| 1217 |
|
| 1218 |
if (cSrcPtr) { |
| 1219 |
cSrcStride = 1; |
| 1220 |
} else { |
| 1221 |
cSrcPtr = pipe->cSrcVal; |
| 1222 |
cSrcStride = 0; |
| 1223 |
} |
| 1224 |
for (; x0 <= x1; ++x0) { |
| 1225 |
if (*alphaPtr) { |
| 1226 |
break; |
| 1227 |
} |
| 1228 |
cSrcPtr += cSrcStride; |
| 1229 |
++alphaPtr; |
| 1230 |
} |
| 1231 |
if (x0 > x1) { |
| 1232 |
return; |
| 1233 |
} |
| 1234 |
updateModX(x0); |
| 1235 |
updateModY(y); |
| 1236 |
lastX = x0; |
| 1237 |
|
| 1238 |
useBitmapRow(y); |
| 1239 |
|
| 1240 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + (x0 >> 3)]; |
| 1241 |
destColorMask = (Guchar)(0x80 >> (x0 & 7)); |
| 1242 |
|
| 1243 |
screenCursor = state->screen->getTestCursor(y); |
| 1244 |
|
| 1245 |
for (x = x0; x <= x1; ++x) { |
| 1246 |
|
| 1247 |
//----- alpha |
| 1248 |
alpha = *alphaPtr; |
| 1249 |
if (!alpha) { |
| 1250 |
destColorPtr += destColorMask & 1; |
| 1251 |
destColorMask = (Guchar)((destColorMask << 7) | (destColorMask >> 1)); |
| 1252 |
cSrcPtr += cSrcStride; |
| 1253 |
++alphaPtr; |
| 1254 |
continue; |
| 1255 |
} |
| 1256 |
lastX = x; |
| 1257 |
|
| 1258 |
//----- source color |
| 1259 |
cSrc0 = state->grayTransfer[cSrcPtr[0]]; |
| 1260 |
|
| 1261 |
//----- source alpha |
| 1262 |
aSrc = alpha; |
| 1263 |
|
| 1264 |
//----- special case for aSrc = 255 |
| 1265 |
if (aSrc == 255) { |
| 1266 |
cResult0 = cSrc0; |
| 1267 |
} else { |
| 1268 |
|
| 1269 |
//----- read destination pixel |
| 1270 |
cDest0 = (*destColorPtr & destColorMask) ? 0xff : 0x00; |
| 1271 |
|
| 1272 |
//----- result color |
| 1273 |
// note: aDest = alphaI = aResult = 0xff |
| 1274 |
cResult0 = (Guchar)div255((0xff - aSrc) * cDest0 + aSrc * cSrc0); |
| 1275 |
} |
| 1276 |
|
| 1277 |
//----- write destination pixel |
| 1278 |
if (state->screen->testWithCursor(screenCursor, x, cResult0)) { |
| 1279 |
*destColorPtr |= destColorMask; |
| 1280 |
} else { |
| 1281 |
*destColorPtr &= (Guchar)~destColorMask; |
| 1282 |
} |
| 1283 |
destColorPtr += destColorMask & 1; |
| 1284 |
destColorMask = (Guchar)((destColorMask << 7) | (destColorMask >> 1)); |
| 1285 |
|
| 1286 |
cSrcPtr += cSrcStride; |
| 1287 |
++alphaPtr; |
| 1288 |
} |
| 1289 |
|
| 1290 |
updateModX(lastX); |
| 1291 |
} |
| 1292 |
|
| 1293 |
// special case: |
| 1294 |
// !pipe->pattern && pipe->alphaOnly && !state->blendFunc && |
| 1295 |
// bitmap->mode == splashModeMono8 && bitmap->alpha |
| 1296 |
void Splash::pipeRunShapeMono8(SplashPipe *pipe, int x0, int x1, int y, |
| 1297 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1298 |
SplashColorPtr cSrcPtr) { |
| 1299 |
Guchar alpha, aSrc, aDest, alphaI, aResult, cSrc0, cDest0, cResult0; |
| 1300 |
SplashColorPtr destColorPtr; |
| 1301 |
Guchar *destAlphaPtr; |
| 1302 |
int cSrcStride, x, lastX; |
| 1303 |
|
| 1304 |
if (cSrcPtr) { |
| 1305 |
cSrcStride = 1; |
| 1306 |
} else { |
| 1307 |
cSrcPtr = pipe->cSrcVal; |
| 1308 |
cSrcStride = 0; |
| 1309 |
} |
| 1310 |
for (; x0 <= x1; ++x0) { |
| 1311 |
if (*alphaPtr) { |
| 1312 |
break; |
| 1313 |
} |
| 1314 |
cSrcPtr += cSrcStride; |
| 1315 |
++alphaPtr; |
| 1316 |
} |
| 1317 |
if (x0 > x1) { |
| 1318 |
return; |
| 1319 |
} |
| 1320 |
updateModX(x0); |
| 1321 |
updateModY(y); |
| 1322 |
lastX = x0; |
| 1323 |
|
| 1324 |
useBitmapRow(y); |
| 1325 |
|
| 1326 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; |
| 1327 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1328 |
|
| 1329 |
for (x = x0; x <= x1; ++x) { |
| 1330 |
|
| 1331 |
//----- alpha |
| 1332 |
alpha = *alphaPtr; |
| 1333 |
if (!alpha) { |
| 1334 |
++destColorPtr; |
| 1335 |
++destAlphaPtr; |
| 1336 |
cSrcPtr += cSrcStride; |
| 1337 |
++alphaPtr; |
| 1338 |
continue; |
| 1339 |
} |
| 1340 |
lastX = x; |
| 1341 |
|
| 1342 |
//----- source color |
| 1343 |
cSrc0 = state->grayTransfer[cSrcPtr[0]]; |
| 1344 |
|
| 1345 |
//----- source alpha |
| 1346 |
aSrc = alpha; |
| 1347 |
|
| 1348 |
//----- special case for aSrc = 255 |
| 1349 |
if (aSrc == 255) { |
| 1350 |
aResult = 255; |
| 1351 |
cResult0 = cSrc0; |
| 1352 |
} else { |
| 1353 |
|
| 1354 |
//----- read destination alpha |
| 1355 |
aDest = *destAlphaPtr; |
| 1356 |
|
| 1357 |
//----- special case for aDest = 0 |
| 1358 |
if (aDest == 0) { |
| 1359 |
aResult = aSrc; |
| 1360 |
cResult0 = cSrc0; |
| 1361 |
} else { |
| 1362 |
|
| 1363 |
//----- read destination pixel |
| 1364 |
cDest0 = *destColorPtr; |
| 1365 |
|
| 1366 |
//----- result alpha and non-isolated group element correction |
| 1367 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 1368 |
alphaI = aResult; |
| 1369 |
|
| 1370 |
//----- result color |
| 1371 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 1372 |
} |
| 1373 |
} |
| 1374 |
|
| 1375 |
//----- write destination pixel |
| 1376 |
*destColorPtr++ = cResult0; |
| 1377 |
*destAlphaPtr++ = aResult; |
| 1378 |
|
| 1379 |
cSrcPtr += cSrcStride; |
| 1380 |
++alphaPtr; |
| 1381 |
} |
| 1382 |
|
| 1383 |
updateModX(lastX); |
| 1384 |
} |
| 1385 |
|
| 1386 |
// special case: |
| 1387 |
// !pipe->pattern && pipe->alphaOnly && !state->blendFunc && |
| 1388 |
// bitmap->mode == splashModeRGB8 && bitmap->alpha |
| 1389 |
void Splash::pipeRunShapeRGB8(SplashPipe *pipe, int x0, int x1, int y, |
| 1390 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1391 |
SplashColorPtr cSrcPtr) { |
| 1392 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 1393 |
Guchar cSrc0, cSrc1, cSrc2; |
| 1394 |
Guchar cDest0, cDest1, cDest2; |
| 1395 |
Guchar cResult0, cResult1, cResult2; |
| 1396 |
SplashColorPtr destColorPtr; |
| 1397 |
Guchar *destAlphaPtr; |
| 1398 |
int cSrcStride, x, lastX; |
| 1399 |
|
| 1400 |
if (cSrcPtr) { |
| 1401 |
cSrcStride = 3; |
| 1402 |
} else { |
| 1403 |
cSrcPtr = pipe->cSrcVal; |
| 1404 |
cSrcStride = 0; |
| 1405 |
} |
| 1406 |
for (; x0 <= x1; ++x0) { |
| 1407 |
if (*alphaPtr) { |
| 1408 |
break; |
| 1409 |
} |
| 1410 |
cSrcPtr += cSrcStride; |
| 1411 |
++alphaPtr; |
| 1412 |
} |
| 1413 |
if (x0 > x1) { |
| 1414 |
return; |
| 1415 |
} |
| 1416 |
updateModX(x0); |
| 1417 |
updateModY(y); |
| 1418 |
lastX = x0; |
| 1419 |
|
| 1420 |
useBitmapRow(y); |
| 1421 |
|
| 1422 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; |
| 1423 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1424 |
|
| 1425 |
for (x = x0; x <= x1; ++x) { |
| 1426 |
|
| 1427 |
//----- alpha |
| 1428 |
alpha = *alphaPtr; |
| 1429 |
if (!alpha) { |
| 1430 |
destColorPtr += 3; |
| 1431 |
++destAlphaPtr; |
| 1432 |
cSrcPtr += cSrcStride; |
| 1433 |
++alphaPtr; |
| 1434 |
continue; |
| 1435 |
} |
| 1436 |
lastX = x; |
| 1437 |
|
| 1438 |
//----- source color |
| 1439 |
cSrc0 = state->rgbTransferR[cSrcPtr[0]]; |
| 1440 |
cSrc1 = state->rgbTransferG[cSrcPtr[1]]; |
| 1441 |
cSrc2 = state->rgbTransferB[cSrcPtr[2]]; |
| 1442 |
|
| 1443 |
//----- source alpha |
| 1444 |
aSrc = alpha; |
| 1445 |
|
| 1446 |
//----- special case for aSrc = 255 |
| 1447 |
if (aSrc == 255) { |
| 1448 |
aResult = 255; |
| 1449 |
cResult0 = cSrc0; |
| 1450 |
cResult1 = cSrc1; |
| 1451 |
cResult2 = cSrc2; |
| 1452 |
} else { |
| 1453 |
|
| 1454 |
//----- read destination alpha |
| 1455 |
aDest = *destAlphaPtr; |
| 1456 |
|
| 1457 |
//----- special case for aDest = 0 |
| 1458 |
if (aDest == 0) { |
| 1459 |
aResult = aSrc; |
| 1460 |
cResult0 = cSrc0; |
| 1461 |
cResult1 = cSrc1; |
| 1462 |
cResult2 = cSrc2; |
| 1463 |
} else { |
| 1464 |
|
| 1465 |
//----- read destination pixel |
| 1466 |
cDest0 = destColorPtr[0]; |
| 1467 |
cDest1 = destColorPtr[1]; |
| 1468 |
cDest2 = destColorPtr[2]; |
| 1469 |
|
| 1470 |
//----- result alpha and non-isolated group element correction |
| 1471 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 1472 |
alphaI = aResult; |
| 1473 |
|
| 1474 |
//----- result color |
| 1475 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 1476 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 1477 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 1478 |
} |
| 1479 |
} |
| 1480 |
|
| 1481 |
//----- write destination pixel |
| 1482 |
destColorPtr[0] = cResult0; |
| 1483 |
destColorPtr[1] = cResult1; |
| 1484 |
destColorPtr[2] = cResult2; |
| 1485 |
destColorPtr += 3; |
| 1486 |
*destAlphaPtr++ = aResult; |
| 1487 |
|
| 1488 |
cSrcPtr += cSrcStride; |
| 1489 |
++alphaPtr; |
| 1490 |
} |
| 1491 |
|
| 1492 |
updateModX(lastX); |
| 1493 |
} |
| 1494 |
|
| 1495 |
// special case: |
| 1496 |
// !pipe->pattern && pipe->alphaOnly && !state->blendFunc && |
| 1497 |
// bitmap->mode == splashModeBGR8 && bitmap->alpha |
| 1498 |
void Splash::pipeRunShapeBGR8(SplashPipe *pipe, int x0, int x1, int y, |
| 1499 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1500 |
SplashColorPtr cSrcPtr) { |
| 1501 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 1502 |
Guchar cSrc0, cSrc1, cSrc2; |
| 1503 |
Guchar cDest0, cDest1, cDest2; |
| 1504 |
Guchar cResult0, cResult1, cResult2; |
| 1505 |
SplashColorPtr destColorPtr; |
| 1506 |
Guchar *destAlphaPtr; |
| 1507 |
int cSrcStride, x, lastX; |
| 1508 |
|
| 1509 |
if (cSrcPtr) { |
| 1510 |
cSrcStride = 3; |
| 1511 |
} else { |
| 1512 |
cSrcPtr = pipe->cSrcVal; |
| 1513 |
cSrcStride = 0; |
| 1514 |
} |
| 1515 |
for (; x0 <= x1; ++x0) { |
| 1516 |
if (*alphaPtr) { |
| 1517 |
break; |
| 1518 |
} |
| 1519 |
cSrcPtr += cSrcStride; |
| 1520 |
++alphaPtr; |
| 1521 |
} |
| 1522 |
if (x0 > x1) { |
| 1523 |
return; |
| 1524 |
} |
| 1525 |
updateModX(x0); |
| 1526 |
updateModY(y); |
| 1527 |
lastX = x0; |
| 1528 |
|
| 1529 |
useBitmapRow(y); |
| 1530 |
|
| 1531 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; |
| 1532 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1533 |
|
| 1534 |
for (x = x0; x <= x1; ++x) { |
| 1535 |
|
| 1536 |
//----- alpha |
| 1537 |
alpha = *alphaPtr; |
| 1538 |
if (!alpha) { |
| 1539 |
destColorPtr += 3; |
| 1540 |
++destAlphaPtr; |
| 1541 |
cSrcPtr += cSrcStride; |
| 1542 |
++alphaPtr; |
| 1543 |
continue; |
| 1544 |
} |
| 1545 |
lastX = x; |
| 1546 |
|
| 1547 |
//----- source color |
| 1548 |
cSrc0 = state->rgbTransferR[cSrcPtr[0]]; |
| 1549 |
cSrc1 = state->rgbTransferG[cSrcPtr[1]]; |
| 1550 |
cSrc2 = state->rgbTransferB[cSrcPtr[2]]; |
| 1551 |
|
| 1552 |
//----- source alpha |
| 1553 |
aSrc = alpha; |
| 1554 |
|
| 1555 |
//----- special case for aSrc = 255 |
| 1556 |
if (aSrc == 255) { |
| 1557 |
aResult = 255; |
| 1558 |
cResult0 = cSrc0; |
| 1559 |
cResult1 = cSrc1; |
| 1560 |
cResult2 = cSrc2; |
| 1561 |
} else { |
| 1562 |
|
| 1563 |
//----- read destination alpha |
| 1564 |
aDest = *destAlphaPtr; |
| 1565 |
|
| 1566 |
//----- special case for aDest = 0 |
| 1567 |
if (aDest == 0) { |
| 1568 |
aResult = aSrc; |
| 1569 |
cResult0 = cSrc0; |
| 1570 |
cResult1 = cSrc1; |
| 1571 |
cResult2 = cSrc2; |
| 1572 |
} else { |
| 1573 |
|
| 1574 |
//----- read destination pixel |
| 1575 |
cDest0 = destColorPtr[2]; |
| 1576 |
cDest1 = destColorPtr[1]; |
| 1577 |
cDest2 = destColorPtr[0]; |
| 1578 |
|
| 1579 |
//----- result alpha and non-isolated group element correction |
| 1580 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 1581 |
alphaI = aResult; |
| 1582 |
|
| 1583 |
//----- result color |
| 1584 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 1585 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 1586 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 1587 |
} |
| 1588 |
} |
| 1589 |
|
| 1590 |
//----- write destination pixel |
| 1591 |
destColorPtr[0] = cResult2; |
| 1592 |
destColorPtr[1] = cResult1; |
| 1593 |
destColorPtr[2] = cResult0; |
| 1594 |
destColorPtr += 3; |
| 1595 |
*destAlphaPtr++ = aResult; |
| 1596 |
|
| 1597 |
cSrcPtr += cSrcStride; |
| 1598 |
++alphaPtr; |
| 1599 |
} |
| 1600 |
|
| 1601 |
updateModX(lastX); |
| 1602 |
} |
| 1603 |
|
| 1604 |
#if SPLASH_CMYK |
| 1605 |
// special case: |
| 1606 |
// !pipe->pattern && pipe->alphaOnly && !state->blendFunc && |
| 1607 |
// bitmap->mode == splashModeCMYK8 && bitmap->alpha |
| 1608 |
void Splash::pipeRunShapeCMYK8(SplashPipe *pipe, int x0, int x1, int y, |
| 1609 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1610 |
SplashColorPtr cSrcPtr) { |
| 1611 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 1612 |
Guchar cSrc0, cSrc1, cSrc2, cSrc3; |
| 1613 |
Guchar cDest0, cDest1, cDest2, cDest3; |
| 1614 |
Guchar cResult0, cResult1, cResult2, cResult3; |
| 1615 |
SplashColorPtr destColorPtr; |
| 1616 |
Guchar *destAlphaPtr; |
| 1617 |
int cSrcStride, x, lastX; |
| 1618 |
|
| 1619 |
if (cSrcPtr) { |
| 1620 |
cSrcStride = 4; |
| 1621 |
} else { |
| 1622 |
cSrcPtr = pipe->cSrcVal; |
| 1623 |
cSrcStride = 0; |
| 1624 |
} |
| 1625 |
for (; x0 <= x1; ++x0) { |
| 1626 |
if (*alphaPtr) { |
| 1627 |
break; |
| 1628 |
} |
| 1629 |
cSrcPtr += cSrcStride; |
| 1630 |
++alphaPtr; |
| 1631 |
} |
| 1632 |
if (x0 > x1) { |
| 1633 |
return; |
| 1634 |
} |
| 1635 |
updateModX(x0); |
| 1636 |
updateModY(y); |
| 1637 |
lastX = x0; |
| 1638 |
|
| 1639 |
useBitmapRow(y); |
| 1640 |
|
| 1641 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 4 * x0]; |
| 1642 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1643 |
|
| 1644 |
for (x = x0; x <= x1; ++x) { |
| 1645 |
|
| 1646 |
//----- alpha |
| 1647 |
alpha = *alphaPtr; |
| 1648 |
if (!alpha) { |
| 1649 |
destColorPtr += 4; |
| 1650 |
++destAlphaPtr; |
| 1651 |
cSrcPtr += cSrcStride; |
| 1652 |
++alphaPtr; |
| 1653 |
continue; |
| 1654 |
} |
| 1655 |
lastX = x; |
| 1656 |
|
| 1657 |
//----- read destination pixel |
| 1658 |
cDest0 = destColorPtr[0]; |
| 1659 |
cDest1 = destColorPtr[1]; |
| 1660 |
cDest2 = destColorPtr[2]; |
| 1661 |
cDest3 = destColorPtr[3]; |
| 1662 |
aDest = *destAlphaPtr; |
| 1663 |
|
| 1664 |
//----- overprint |
| 1665 |
cSrc0 = state->cmykTransferC[cSrcPtr[0]]; |
| 1666 |
cSrc1 = state->cmykTransferM[cSrcPtr[1]]; |
| 1667 |
cSrc2 = state->cmykTransferY[cSrcPtr[2]]; |
| 1668 |
cSrc3 = state->cmykTransferK[cSrcPtr[3]]; |
| 1669 |
|
| 1670 |
//----- source alpha |
| 1671 |
aSrc = alpha; |
| 1672 |
|
| 1673 |
//----- special case for aSrc = 255 |
| 1674 |
if (aSrc == 255) { |
| 1675 |
aResult = 255; |
| 1676 |
cResult0 = cSrc0; |
| 1677 |
cResult1 = cSrc1; |
| 1678 |
cResult2 = cSrc2; |
| 1679 |
cResult3 = cSrc3; |
| 1680 |
} else { |
| 1681 |
|
| 1682 |
//----- special case for aDest = 0 |
| 1683 |
if (aDest == 0) { |
| 1684 |
aResult = aSrc; |
| 1685 |
cResult0 = cSrc0; |
| 1686 |
cResult1 = cSrc1; |
| 1687 |
cResult2 = cSrc2; |
| 1688 |
cResult3 = cSrc3; |
| 1689 |
} else { |
| 1690 |
|
| 1691 |
//----- result alpha and non-isolated group element correction |
| 1692 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 1693 |
alphaI = aResult; |
| 1694 |
|
| 1695 |
//----- result color |
| 1696 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 1697 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 1698 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 1699 |
cResult3 = (Guchar)(((alphaI - aSrc) * cDest3 + aSrc * cSrc3) / alphaI); |
| 1700 |
} |
| 1701 |
} |
| 1702 |
|
| 1703 |
//----- write destination pixel |
| 1704 |
destColorPtr[0] = cResult0; |
| 1705 |
destColorPtr[1] = cResult1; |
| 1706 |
destColorPtr[2] = cResult2; |
| 1707 |
destColorPtr[3] = cResult3; |
| 1708 |
destColorPtr += 4; |
| 1709 |
*destAlphaPtr++ = aResult; |
| 1710 |
|
| 1711 |
cSrcPtr += cSrcStride; |
| 1712 |
++alphaPtr; |
| 1713 |
} |
| 1714 |
|
| 1715 |
updateModX(lastX); |
| 1716 |
} |
| 1717 |
#endif |
| 1718 |
|
| 1719 |
|
| 1720 |
// special case: |
| 1721 |
// !pipe->pattern && pipe->alphaOnly && !state->blendFunc && |
| 1722 |
// bitmap->mode == splashModeMono8 && !bitmap->alpha |
| 1723 |
void Splash::pipeRunShapeNoAlphaMono8(SplashPipe *pipe, int x0, int x1, int y, |
| 1724 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1725 |
SplashColorPtr cSrcPtr) { |
| 1726 |
Guchar alpha, aSrc, cSrc0, cDest0, cResult0; |
| 1727 |
SplashColorPtr destColorPtr; |
| 1728 |
int cSrcStride, x, lastX; |
| 1729 |
|
| 1730 |
if (cSrcPtr) { |
| 1731 |
cSrcStride = 1; |
| 1732 |
} else { |
| 1733 |
cSrcPtr = pipe->cSrcVal; |
| 1734 |
cSrcStride = 0; |
| 1735 |
} |
| 1736 |
for (; x0 <= x1; ++x0) { |
| 1737 |
if (*alphaPtr) { |
| 1738 |
break; |
| 1739 |
} |
| 1740 |
cSrcPtr += cSrcStride; |
| 1741 |
++alphaPtr; |
| 1742 |
} |
| 1743 |
if (x0 > x1) { |
| 1744 |
return; |
| 1745 |
} |
| 1746 |
updateModX(x0); |
| 1747 |
updateModY(y); |
| 1748 |
lastX = x0; |
| 1749 |
|
| 1750 |
useBitmapRow(y); |
| 1751 |
|
| 1752 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; |
| 1753 |
|
| 1754 |
for (x = x0; x <= x1; ++x) { |
| 1755 |
|
| 1756 |
//----- alpha |
| 1757 |
alpha = *alphaPtr; |
| 1758 |
if (!alpha) { |
| 1759 |
++destColorPtr; |
| 1760 |
cSrcPtr += cSrcStride; |
| 1761 |
++alphaPtr; |
| 1762 |
continue; |
| 1763 |
} |
| 1764 |
lastX = x; |
| 1765 |
|
| 1766 |
//----- source color |
| 1767 |
cSrc0 = state->grayTransfer[cSrcPtr[0]]; |
| 1768 |
|
| 1769 |
//----- source alpha |
| 1770 |
aSrc = alpha; |
| 1771 |
|
| 1772 |
//----- special case for aSrc = 255 |
| 1773 |
if (aSrc == 255) { |
| 1774 |
cResult0 = cSrc0; |
| 1775 |
} else { |
| 1776 |
|
| 1777 |
//----- read destination pixel |
| 1778 |
cDest0 = *destColorPtr; |
| 1779 |
|
| 1780 |
//----- result color |
| 1781 |
cResult0 = div255((255 - aSrc) * cDest0 + aSrc * cSrc0); |
| 1782 |
} |
| 1783 |
|
| 1784 |
//----- write destination pixel |
| 1785 |
*destColorPtr++ = cResult0; |
| 1786 |
|
| 1787 |
cSrcPtr += cSrcStride; |
| 1788 |
++alphaPtr; |
| 1789 |
} |
| 1790 |
|
| 1791 |
updateModX(lastX); |
| 1792 |
} |
| 1793 |
|
| 1794 |
// special case: |
| 1795 |
// !pipe->pattern && !pipe->noTransparency && !state->softMask && |
| 1796 |
// usesAlpha && !pipe->alpha0Ptr && !state->blendFunc && |
| 1797 |
// !pipe->nonIsolatedGroup && |
| 1798 |
// bitmap->mode == splashModeMono1 && !bitmap->alpha |
| 1799 |
void Splash::pipeRunAAMono1(SplashPipe *pipe, int x0, int x1, int y, |
| 1800 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1801 |
SplashColorPtr cSrcPtr) { |
| 1802 |
Guchar alpha, aSrc, cSrc0, cDest0, cResult0; |
| 1803 |
SplashColorPtr destColorPtr; |
| 1804 |
Guchar destColorMask; |
| 1805 |
SplashScreenCursor screenCursor; |
| 1806 |
int cSrcStride, x, lastX; |
| 1807 |
|
| 1808 |
if (cSrcPtr) { |
| 1809 |
cSrcStride = 1; |
| 1810 |
} else { |
| 1811 |
cSrcPtr = pipe->cSrcVal; |
| 1812 |
cSrcStride = 0; |
| 1813 |
} |
| 1814 |
for (; x0 <= x1; ++x0) { |
| 1815 |
if (*alphaPtr) { |
| 1816 |
break; |
| 1817 |
} |
| 1818 |
cSrcPtr += cSrcStride; |
| 1819 |
++alphaPtr; |
| 1820 |
} |
| 1821 |
if (x0 > x1) { |
| 1822 |
return; |
| 1823 |
} |
| 1824 |
updateModX(x0); |
| 1825 |
updateModY(y); |
| 1826 |
lastX = x0; |
| 1827 |
|
| 1828 |
useBitmapRow(y); |
| 1829 |
|
| 1830 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + (x0 >> 3)]; |
| 1831 |
destColorMask = (Guchar)(0x80 >> (x0 & 7)); |
| 1832 |
|
| 1833 |
screenCursor = state->screen->getTestCursor(y); |
| 1834 |
|
| 1835 |
for (x = x0; x <= x1; ++x) { |
| 1836 |
|
| 1837 |
//----- alpha |
| 1838 |
alpha = *alphaPtr; |
| 1839 |
if (!alpha) { |
| 1840 |
destColorPtr += destColorMask & 1; |
| 1841 |
destColorMask = (Guchar)((destColorMask << 7) | (destColorMask >> 1)); |
| 1842 |
cSrcPtr += cSrcStride; |
| 1843 |
++alphaPtr; |
| 1844 |
continue; |
| 1845 |
} |
| 1846 |
lastX = x; |
| 1847 |
|
| 1848 |
//----- read destination pixel |
| 1849 |
cDest0 = (*destColorPtr & destColorMask) ? 0xff : 0x00; |
| 1850 |
|
| 1851 |
//----- source color |
| 1852 |
cSrc0 = state->grayTransfer[cSrcPtr[0]]; |
| 1853 |
|
| 1854 |
//----- source alpha |
| 1855 |
aSrc = div255(pipe->aInput * alpha); |
| 1856 |
|
| 1857 |
//----- result color |
| 1858 |
// note: aDest = alphaI = aResult = 0xff |
| 1859 |
cResult0 = (Guchar)div255((0xff - aSrc) * cDest0 + aSrc * cSrc0); |
| 1860 |
|
| 1861 |
//----- write destination pixel |
| 1862 |
if (state->screen->testWithCursor(screenCursor, x, cResult0)) { |
| 1863 |
*destColorPtr |= destColorMask; |
| 1864 |
} else { |
| 1865 |
*destColorPtr &= (Guchar)~destColorMask; |
| 1866 |
} |
| 1867 |
destColorPtr += destColorMask & 1; |
| 1868 |
destColorMask = (Guchar)((destColorMask << 7) | (destColorMask >> 1)); |
| 1869 |
|
| 1870 |
cSrcPtr += cSrcStride; |
| 1871 |
++alphaPtr; |
| 1872 |
} |
| 1873 |
|
| 1874 |
updateModX(lastX); |
| 1875 |
} |
| 1876 |
|
| 1877 |
// special case: |
| 1878 |
// !pipe->pattern && !pipe->noTransparency && !state->softMask && |
| 1879 |
// usesAlpha && !pipe->alpha0Ptr && !state->blendFunc && |
| 1880 |
// !pipe->nonIsolatedGroup && |
| 1881 |
// bitmap->mode == splashModeMono8 && bitmap->alpha |
| 1882 |
void Splash::pipeRunAAMono8(SplashPipe *pipe, int x0, int x1, int y, |
| 1883 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1884 |
SplashColorPtr cSrcPtr) { |
| 1885 |
Guchar alpha, aSrc, aDest, alphaI, aResult, cSrc0, cDest0, cResult0; |
| 1886 |
SplashColorPtr destColorPtr; |
| 1887 |
Guchar *destAlphaPtr; |
| 1888 |
int cSrcStride, x, lastX; |
| 1889 |
|
| 1890 |
if (cSrcPtr) { |
| 1891 |
cSrcStride = 1; |
| 1892 |
} else { |
| 1893 |
cSrcPtr = pipe->cSrcVal; |
| 1894 |
cSrcStride = 0; |
| 1895 |
} |
| 1896 |
for (; x0 <= x1; ++x0) { |
| 1897 |
if (*alphaPtr) { |
| 1898 |
break; |
| 1899 |
} |
| 1900 |
cSrcPtr += cSrcStride; |
| 1901 |
++alphaPtr; |
| 1902 |
} |
| 1903 |
if (x0 > x1) { |
| 1904 |
return; |
| 1905 |
} |
| 1906 |
updateModX(x0); |
| 1907 |
updateModY(y); |
| 1908 |
lastX = x0; |
| 1909 |
|
| 1910 |
useBitmapRow(y); |
| 1911 |
|
| 1912 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; |
| 1913 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 1914 |
|
| 1915 |
for (x = x0; x <= x1; ++x) { |
| 1916 |
|
| 1917 |
//----- alpha |
| 1918 |
alpha = *alphaPtr; |
| 1919 |
if (!alpha) { |
| 1920 |
++destColorPtr; |
| 1921 |
++destAlphaPtr; |
| 1922 |
cSrcPtr += cSrcStride; |
| 1923 |
++alphaPtr; |
| 1924 |
continue; |
| 1925 |
} |
| 1926 |
lastX = x; |
| 1927 |
|
| 1928 |
//----- read destination pixel |
| 1929 |
cDest0 = *destColorPtr; |
| 1930 |
aDest = *destAlphaPtr; |
| 1931 |
|
| 1932 |
//----- source color |
| 1933 |
cSrc0 = state->grayTransfer[cSrcPtr[0]]; |
| 1934 |
|
| 1935 |
//----- source alpha |
| 1936 |
aSrc = div255(pipe->aInput * alpha); |
| 1937 |
|
| 1938 |
//----- result alpha and non-isolated group element correction |
| 1939 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 1940 |
alphaI = aResult; |
| 1941 |
|
| 1942 |
//----- result color |
| 1943 |
if (alphaI == 0) { |
| 1944 |
cResult0 = 0; |
| 1945 |
} else { |
| 1946 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 1947 |
} |
| 1948 |
|
| 1949 |
//----- write destination pixel |
| 1950 |
*destColorPtr++ = cResult0; |
| 1951 |
*destAlphaPtr++ = aResult; |
| 1952 |
|
| 1953 |
cSrcPtr += cSrcStride; |
| 1954 |
++alphaPtr; |
| 1955 |
} |
| 1956 |
|
| 1957 |
updateModX(lastX); |
| 1958 |
} |
| 1959 |
|
| 1960 |
// special case: |
| 1961 |
// !pipe->pattern && !pipe->noTransparency && !state->softMask && |
| 1962 |
// usesAlpha && !pipe->alpha0Ptr && !state->blendFunc && |
| 1963 |
// !pipe->nonIsolatedGroup && |
| 1964 |
// bitmap->mode == splashModeRGB8 && bitmap->alpha |
| 1965 |
void Splash::pipeRunAARGB8(SplashPipe *pipe, int x0, int x1, int y, |
| 1966 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 1967 |
SplashColorPtr cSrcPtr) { |
| 1968 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 1969 |
Guchar cSrc0, cSrc1, cSrc2; |
| 1970 |
Guchar cDest0, cDest1, cDest2; |
| 1971 |
Guchar cResult0, cResult1, cResult2; |
| 1972 |
SplashColorPtr destColorPtr; |
| 1973 |
Guchar *destAlphaPtr; |
| 1974 |
int cSrcStride, x, lastX; |
| 1975 |
|
| 1976 |
if (cSrcPtr) { |
| 1977 |
cSrcStride = 3; |
| 1978 |
} else { |
| 1979 |
cSrcPtr = pipe->cSrcVal; |
| 1980 |
cSrcStride = 0; |
| 1981 |
} |
| 1982 |
for (; x0 <= x1; ++x0) { |
| 1983 |
if (*alphaPtr) { |
| 1984 |
break; |
| 1985 |
} |
| 1986 |
cSrcPtr += cSrcStride; |
| 1987 |
++alphaPtr; |
| 1988 |
} |
| 1989 |
if (x0 > x1) { |
| 1990 |
return; |
| 1991 |
} |
| 1992 |
updateModX(x0); |
| 1993 |
updateModY(y); |
| 1994 |
lastX = x0; |
| 1995 |
|
| 1996 |
useBitmapRow(y); |
| 1997 |
|
| 1998 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; |
| 1999 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2000 |
|
| 2001 |
for (x = x0; x <= x1; ++x) { |
| 2002 |
|
| 2003 |
//----- alpha |
| 2004 |
alpha = *alphaPtr; |
| 2005 |
if (!alpha) { |
| 2006 |
destColorPtr += 3; |
| 2007 |
++destAlphaPtr; |
| 2008 |
cSrcPtr += cSrcStride; |
| 2009 |
++alphaPtr; |
| 2010 |
continue; |
| 2011 |
} |
| 2012 |
lastX = x; |
| 2013 |
|
| 2014 |
//----- read destination pixel |
| 2015 |
cDest0 = destColorPtr[0]; |
| 2016 |
cDest1 = destColorPtr[1]; |
| 2017 |
cDest2 = destColorPtr[2]; |
| 2018 |
aDest = *destAlphaPtr; |
| 2019 |
|
| 2020 |
//----- source color |
| 2021 |
cSrc0 = state->rgbTransferR[cSrcPtr[0]]; |
| 2022 |
cSrc1 = state->rgbTransferG[cSrcPtr[1]]; |
| 2023 |
cSrc2 = state->rgbTransferB[cSrcPtr[2]]; |
| 2024 |
|
| 2025 |
//----- source alpha |
| 2026 |
aSrc = div255(pipe->aInput * alpha); |
| 2027 |
|
| 2028 |
//----- result alpha and non-isolated group element correction |
| 2029 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2030 |
alphaI = aResult; |
| 2031 |
|
| 2032 |
//----- result color |
| 2033 |
if (alphaI == 0) { |
| 2034 |
cResult0 = 0; |
| 2035 |
cResult1 = 0; |
| 2036 |
cResult2 = 0; |
| 2037 |
} else { |
| 2038 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2039 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 2040 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 2041 |
} |
| 2042 |
|
| 2043 |
//----- write destination pixel |
| 2044 |
destColorPtr[0] = cResult0; |
| 2045 |
destColorPtr[1] = cResult1; |
| 2046 |
destColorPtr[2] = cResult2; |
| 2047 |
destColorPtr += 3; |
| 2048 |
*destAlphaPtr++ = aResult; |
| 2049 |
|
| 2050 |
cSrcPtr += cSrcStride; |
| 2051 |
++alphaPtr; |
| 2052 |
} |
| 2053 |
|
| 2054 |
updateModX(lastX); |
| 2055 |
} |
| 2056 |
|
| 2057 |
// special case: |
| 2058 |
// !pipe->pattern && !pipe->noTransparency && !state->softMask && |
| 2059 |
// usesAlpha && !pipe->alpha0Ptr && !state->blendFunc && |
| 2060 |
// !pipe->nonIsolatedGroup && |
| 2061 |
// bitmap->mode == splashModeBGR8 && bitmap->alpha |
| 2062 |
void Splash::pipeRunAABGR8(SplashPipe *pipe, int x0, int x1, int y, |
| 2063 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2064 |
SplashColorPtr cSrcPtr) { |
| 2065 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 2066 |
Guchar cSrc0, cSrc1, cSrc2; |
| 2067 |
Guchar cDest0, cDest1, cDest2; |
| 2068 |
Guchar cResult0, cResult1, cResult2; |
| 2069 |
SplashColorPtr destColorPtr; |
| 2070 |
Guchar *destAlphaPtr; |
| 2071 |
int cSrcStride, x, lastX; |
| 2072 |
|
| 2073 |
if (cSrcPtr) { |
| 2074 |
cSrcStride = 3; |
| 2075 |
} else { |
| 2076 |
cSrcPtr = pipe->cSrcVal; |
| 2077 |
cSrcStride = 0; |
| 2078 |
} |
| 2079 |
for (; x0 <= x1; ++x0) { |
| 2080 |
if (*alphaPtr) { |
| 2081 |
break; |
| 2082 |
} |
| 2083 |
cSrcPtr += cSrcStride; |
| 2084 |
++alphaPtr; |
| 2085 |
} |
| 2086 |
if (x0 > x1) { |
| 2087 |
return; |
| 2088 |
} |
| 2089 |
updateModX(x0); |
| 2090 |
updateModY(y); |
| 2091 |
lastX = x0; |
| 2092 |
|
| 2093 |
useBitmapRow(y); |
| 2094 |
|
| 2095 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; |
| 2096 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2097 |
|
| 2098 |
for (x = x0; x <= x1; ++x) { |
| 2099 |
|
| 2100 |
//----- alpha |
| 2101 |
alpha = *alphaPtr; |
| 2102 |
if (!alpha) { |
| 2103 |
destColorPtr += 3; |
| 2104 |
++destAlphaPtr; |
| 2105 |
cSrcPtr += cSrcStride; |
| 2106 |
++alphaPtr; |
| 2107 |
continue; |
| 2108 |
} |
| 2109 |
lastX = x; |
| 2110 |
|
| 2111 |
//----- read destination pixel |
| 2112 |
cDest0 = destColorPtr[2]; |
| 2113 |
cDest1 = destColorPtr[1]; |
| 2114 |
cDest2 = destColorPtr[0]; |
| 2115 |
aDest = *destAlphaPtr; |
| 2116 |
|
| 2117 |
//----- source color |
| 2118 |
cSrc0 = state->rgbTransferR[cSrcPtr[0]]; |
| 2119 |
cSrc1 = state->rgbTransferG[cSrcPtr[1]]; |
| 2120 |
cSrc2 = state->rgbTransferB[cSrcPtr[2]]; |
| 2121 |
|
| 2122 |
//----- source alpha |
| 2123 |
aSrc = div255(pipe->aInput * alpha); |
| 2124 |
|
| 2125 |
//----- result alpha and non-isolated group element correction |
| 2126 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2127 |
alphaI = aResult; |
| 2128 |
|
| 2129 |
//----- result color |
| 2130 |
if (alphaI == 0) { |
| 2131 |
cResult0 = 0; |
| 2132 |
cResult1 = 0; |
| 2133 |
cResult2 = 0; |
| 2134 |
} else { |
| 2135 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2136 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 2137 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 2138 |
} |
| 2139 |
|
| 2140 |
//----- write destination pixel |
| 2141 |
destColorPtr[0] = cResult2; |
| 2142 |
destColorPtr[1] = cResult1; |
| 2143 |
destColorPtr[2] = cResult0; |
| 2144 |
destColorPtr += 3; |
| 2145 |
*destAlphaPtr++ = aResult; |
| 2146 |
|
| 2147 |
cSrcPtr += cSrcStride; |
| 2148 |
++alphaPtr; |
| 2149 |
} |
| 2150 |
|
| 2151 |
updateModX(lastX); |
| 2152 |
} |
| 2153 |
|
| 2154 |
#if SPLASH_CMYK |
| 2155 |
// special case: |
| 2156 |
// !pipe->pattern && !pipe->noTransparency && !state->softMask && |
| 2157 |
// usesAlpha && !pipe->alpha0Ptr && !state->blendFunc && |
| 2158 |
// !pipe->nonIsolatedGroup && |
| 2159 |
// bitmap->mode == splashModeCMYK8 && bitmap->alpha |
| 2160 |
void Splash::pipeRunAACMYK8(SplashPipe *pipe, int x0, int x1, int y, |
| 2161 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2162 |
SplashColorPtr cSrcPtr) { |
| 2163 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 2164 |
Guchar cSrc0, cSrc1, cSrc2, cSrc3; |
| 2165 |
Guchar cDest0, cDest1, cDest2, cDest3; |
| 2166 |
Guchar cResult0, cResult1, cResult2, cResult3; |
| 2167 |
SplashColorPtr destColorPtr; |
| 2168 |
Guchar *destAlphaPtr; |
| 2169 |
int cSrcStride, x, lastX; |
| 2170 |
|
| 2171 |
if (cSrcPtr) { |
| 2172 |
cSrcStride = 4; |
| 2173 |
} else { |
| 2174 |
cSrcPtr = pipe->cSrcVal; |
| 2175 |
cSrcStride = 0; |
| 2176 |
} |
| 2177 |
for (; x0 <= x1; ++x0) { |
| 2178 |
if (*alphaPtr) { |
| 2179 |
break; |
| 2180 |
} |
| 2181 |
cSrcPtr += cSrcStride; |
| 2182 |
++alphaPtr; |
| 2183 |
} |
| 2184 |
if (x0 > x1) { |
| 2185 |
return; |
| 2186 |
} |
| 2187 |
updateModX(x0); |
| 2188 |
updateModY(y); |
| 2189 |
lastX = x0; |
| 2190 |
|
| 2191 |
useBitmapRow(y); |
| 2192 |
|
| 2193 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + 4 * x0]; |
| 2194 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2195 |
|
| 2196 |
for (x = x0; x <= x1; ++x) { |
| 2197 |
|
| 2198 |
//----- alpha |
| 2199 |
alpha = *alphaPtr; |
| 2200 |
if (!alpha) { |
| 2201 |
destColorPtr += 4; |
| 2202 |
++destAlphaPtr; |
| 2203 |
cSrcPtr += cSrcStride; |
| 2204 |
++alphaPtr; |
| 2205 |
continue; |
| 2206 |
} |
| 2207 |
lastX = x; |
| 2208 |
|
| 2209 |
//----- read destination pixel |
| 2210 |
cDest0 = destColorPtr[0]; |
| 2211 |
cDest1 = destColorPtr[1]; |
| 2212 |
cDest2 = destColorPtr[2]; |
| 2213 |
cDest3 = destColorPtr[3]; |
| 2214 |
aDest = *destAlphaPtr; |
| 2215 |
|
| 2216 |
//----- overprint |
| 2217 |
if (state->overprintMask & 1) { |
| 2218 |
cSrc0 = state->cmykTransferC[cSrcPtr[0]]; |
| 2219 |
} else { |
| 2220 |
cSrc0 = div255(aDest * cDest0); |
| 2221 |
} |
| 2222 |
if (state->overprintMask & 2) { |
| 2223 |
cSrc1 = state->cmykTransferM[cSrcPtr[1]]; |
| 2224 |
} else { |
| 2225 |
cSrc1 = div255(aDest * cDest1); |
| 2226 |
} |
| 2227 |
if (state->overprintMask & 4) { |
| 2228 |
cSrc2 = state->cmykTransferY[cSrcPtr[2]]; |
| 2229 |
} else { |
| 2230 |
cSrc2 = div255(aDest * cDest2); |
| 2231 |
} |
| 2232 |
if (state->overprintMask & 8) { |
| 2233 |
cSrc3 = state->cmykTransferK[cSrcPtr[3]]; |
| 2234 |
} else { |
| 2235 |
cSrc3 = div255(aDest * cDest3); |
| 2236 |
} |
| 2237 |
|
| 2238 |
//----- source alpha |
| 2239 |
aSrc = div255(pipe->aInput * alpha); |
| 2240 |
|
| 2241 |
//----- result alpha and non-isolated group element correction |
| 2242 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2243 |
alphaI = aResult; |
| 2244 |
|
| 2245 |
//----- result color |
| 2246 |
if (alphaI == 0) { |
| 2247 |
cResult0 = 0; |
| 2248 |
cResult1 = 0; |
| 2249 |
cResult2 = 0; |
| 2250 |
cResult3 = 0; |
| 2251 |
} else { |
| 2252 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2253 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 2254 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 2255 |
cResult3 = (Guchar)(((alphaI - aSrc) * cDest3 + aSrc * cSrc3) / alphaI); |
| 2256 |
} |
| 2257 |
|
| 2258 |
//----- write destination pixel |
| 2259 |
destColorPtr[0] = cResult0; |
| 2260 |
destColorPtr[1] = cResult1; |
| 2261 |
destColorPtr[2] = cResult2; |
| 2262 |
destColorPtr[3] = cResult3; |
| 2263 |
destColorPtr += 4; |
| 2264 |
*destAlphaPtr++ = aResult; |
| 2265 |
|
| 2266 |
cSrcPtr += cSrcStride; |
| 2267 |
++alphaPtr; |
| 2268 |
} |
| 2269 |
|
| 2270 |
updateModX(lastX); |
| 2271 |
} |
| 2272 |
#endif |
| 2273 |
|
| 2274 |
|
| 2275 |
// special case: |
| 2276 |
// !pipe->pattern && aInput == 255 && state->softMask && usesAlpha && |
| 2277 |
// !state->inNonIsolatedGroup && !state->inKnockoutGroup && |
| 2278 |
// !nonIsolatedGroup && state->overprintMask == 0xffffffff && |
| 2279 |
// !state->blendFunc && |
| 2280 |
// bitmap->mode == splashModeMono8 && bitmap->alpha |
| 2281 |
void Splash::pipeRunSoftMaskMono8(SplashPipe *pipe, int x0, int x1, int y, |
| 2282 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2283 |
SplashColorPtr cSrcPtr) { |
| 2284 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 2285 |
Guchar cSrc0, cDest0, cResult0; |
| 2286 |
SplashColorPtr destColorPtr; |
| 2287 |
Guchar *destAlphaPtr; |
| 2288 |
SplashColorPtr softMaskPtr; |
| 2289 |
int cSrcStride, x, lastX; |
| 2290 |
|
| 2291 |
if (cSrcPtr) { |
| 2292 |
cSrcStride = 1; |
| 2293 |
} else { |
| 2294 |
cSrcPtr = pipe->cSrcVal; |
| 2295 |
cSrcStride = 0; |
| 2296 |
} |
| 2297 |
for (; x0 <= x1; ++x0) { |
| 2298 |
if (*alphaPtr) { |
| 2299 |
break; |
| 2300 |
} |
| 2301 |
cSrcPtr += cSrcStride; |
| 2302 |
++alphaPtr; |
| 2303 |
} |
| 2304 |
if (x0 > x1) { |
| 2305 |
return; |
| 2306 |
} |
| 2307 |
updateModX(x0); |
| 2308 |
updateModY(y); |
| 2309 |
lastX = x0; |
| 2310 |
|
| 2311 |
useBitmapRow(y); |
| 2312 |
|
| 2313 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; |
| 2314 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2315 |
softMaskPtr = &state->softMask->data[y * state->softMask->rowSize + x0]; |
| 2316 |
|
| 2317 |
for (x = x0; x <= x1; ++x) { |
| 2318 |
|
| 2319 |
//----- alpha |
| 2320 |
alpha = *alphaPtr; |
| 2321 |
if (!alpha) { |
| 2322 |
++destColorPtr; |
| 2323 |
++destAlphaPtr; |
| 2324 |
++softMaskPtr; |
| 2325 |
cSrcPtr += cSrcStride; |
| 2326 |
++alphaPtr; |
| 2327 |
continue; |
| 2328 |
} |
| 2329 |
lastX = x; |
| 2330 |
|
| 2331 |
//----- read source color |
| 2332 |
cSrc0 = state->grayTransfer[cSrcPtr[0]]; |
| 2333 |
|
| 2334 |
//----- source alpha |
| 2335 |
aSrc = div255(*softMaskPtr++ * alpha); |
| 2336 |
|
| 2337 |
//----- special case for aSrc = 255 |
| 2338 |
if (aSrc == 255) { |
| 2339 |
aResult = 255; |
| 2340 |
cResult0 = cSrc0; |
| 2341 |
} else { |
| 2342 |
|
| 2343 |
//----- read destination alpha |
| 2344 |
aDest = *destAlphaPtr; |
| 2345 |
|
| 2346 |
//----- special case for aDest = 0 |
| 2347 |
if (aDest == 0) { |
| 2348 |
aResult = aSrc; |
| 2349 |
cResult0 = cSrc0; |
| 2350 |
} else { |
| 2351 |
|
| 2352 |
//----- read destination pixel |
| 2353 |
cDest0 = destColorPtr[0]; |
| 2354 |
|
| 2355 |
//----- result alpha and non-isolated group element correction |
| 2356 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2357 |
alphaI = aResult; |
| 2358 |
|
| 2359 |
//----- result color |
| 2360 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2361 |
} |
| 2362 |
} |
| 2363 |
|
| 2364 |
//----- write destination pixel |
| 2365 |
destColorPtr[0] = cResult0; |
| 2366 |
++destColorPtr; |
| 2367 |
*destAlphaPtr++ = aResult; |
| 2368 |
|
| 2369 |
cSrcPtr += cSrcStride; |
| 2370 |
++alphaPtr; |
| 2371 |
} |
| 2372 |
|
| 2373 |
updateModX(lastX); |
| 2374 |
} |
| 2375 |
|
| 2376 |
// special case: |
| 2377 |
// !pipe->pattern && aInput == 255 && state->softMask && usesAlpha && |
| 2378 |
// !state->inNonIsolatedGroup && !state->inKnockoutGroup && |
| 2379 |
// !nonIsolatedGroup && state->overprintMask == 0xffffffff && |
| 2380 |
// !state->blendFunc && |
| 2381 |
// bitmap->mode == splashModeRGB8 && bitmap->alpha |
| 2382 |
void Splash::pipeRunSoftMaskRGB8(SplashPipe *pipe, int x0, int x1, int y, |
| 2383 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2384 |
SplashColorPtr cSrcPtr) { |
| 2385 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 2386 |
Guchar cSrc0, cSrc1, cSrc2; |
| 2387 |
Guchar cDest0, cDest1, cDest2; |
| 2388 |
Guchar cResult0, cResult1, cResult2; |
| 2389 |
SplashColorPtr destColorPtr; |
| 2390 |
Guchar *destAlphaPtr; |
| 2391 |
SplashColorPtr softMaskPtr; |
| 2392 |
int cSrcStride, x, lastX; |
| 2393 |
|
| 2394 |
if (cSrcPtr) { |
| 2395 |
cSrcStride = 3; |
| 2396 |
} else { |
| 2397 |
cSrcPtr = pipe->cSrcVal; |
| 2398 |
cSrcStride = 0; |
| 2399 |
} |
| 2400 |
for (; x0 <= x1; ++x0) { |
| 2401 |
if (*alphaPtr) { |
| 2402 |
break; |
| 2403 |
} |
| 2404 |
cSrcPtr += cSrcStride; |
| 2405 |
++alphaPtr; |
| 2406 |
} |
| 2407 |
if (x0 > x1) { |
| 2408 |
return; |
| 2409 |
} |
| 2410 |
updateModX(x0); |
| 2411 |
updateModY(y); |
| 2412 |
lastX = x0; |
| 2413 |
|
| 2414 |
useBitmapRow(y); |
| 2415 |
|
| 2416 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0 * 3]; |
| 2417 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2418 |
softMaskPtr = &state->softMask->data[y * state->softMask->rowSize + x0]; |
| 2419 |
|
| 2420 |
for (x = x0; x <= x1; ++x) { |
| 2421 |
|
| 2422 |
//----- alpha |
| 2423 |
alpha = *alphaPtr; |
| 2424 |
if (!alpha) { |
| 2425 |
destColorPtr += 3; |
| 2426 |
++destAlphaPtr; |
| 2427 |
++softMaskPtr; |
| 2428 |
cSrcPtr += cSrcStride; |
| 2429 |
++alphaPtr; |
| 2430 |
continue; |
| 2431 |
} |
| 2432 |
lastX = x; |
| 2433 |
|
| 2434 |
//----- read source color |
| 2435 |
cSrc0 = state->rgbTransferR[cSrcPtr[0]]; |
| 2436 |
cSrc1 = state->rgbTransferG[cSrcPtr[1]]; |
| 2437 |
cSrc2 = state->rgbTransferB[cSrcPtr[2]]; |
| 2438 |
|
| 2439 |
//----- source alpha |
| 2440 |
aSrc = div255(*softMaskPtr++ * alpha); |
| 2441 |
|
| 2442 |
//----- special case for aSrc = 255 |
| 2443 |
if (aSrc == 255) { |
| 2444 |
aResult = 255; |
| 2445 |
cResult0 = cSrc0; |
| 2446 |
cResult1 = cSrc1; |
| 2447 |
cResult2 = cSrc2; |
| 2448 |
} else { |
| 2449 |
|
| 2450 |
//----- read destination alpha |
| 2451 |
aDest = *destAlphaPtr; |
| 2452 |
|
| 2453 |
//----- special case for aDest = 0 |
| 2454 |
if (aDest == 0) { |
| 2455 |
aResult = aSrc; |
| 2456 |
cResult0 = cSrc0; |
| 2457 |
cResult1 = cSrc1; |
| 2458 |
cResult2 = cSrc2; |
| 2459 |
} else { |
| 2460 |
|
| 2461 |
//----- read destination pixel |
| 2462 |
cDest0 = destColorPtr[0]; |
| 2463 |
cDest1 = destColorPtr[1]; |
| 2464 |
cDest2 = destColorPtr[2]; |
| 2465 |
|
| 2466 |
//----- result alpha and non-isolated group element correction |
| 2467 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2468 |
alphaI = aResult; |
| 2469 |
|
| 2470 |
//----- result color |
| 2471 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2472 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 2473 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 2474 |
} |
| 2475 |
} |
| 2476 |
|
| 2477 |
//----- write destination pixel |
| 2478 |
destColorPtr[0] = cResult0; |
| 2479 |
destColorPtr[1] = cResult1; |
| 2480 |
destColorPtr[2] = cResult2; |
| 2481 |
destColorPtr += 3; |
| 2482 |
*destAlphaPtr++ = aResult; |
| 2483 |
|
| 2484 |
cSrcPtr += cSrcStride; |
| 2485 |
++alphaPtr; |
| 2486 |
} |
| 2487 |
|
| 2488 |
updateModX(lastX); |
| 2489 |
} |
| 2490 |
|
| 2491 |
// special case: |
| 2492 |
// !pipe->pattern && aInput == 255 && state->softMask && usesAlpha && |
| 2493 |
// !state->inNonIsolatedGroup && !state->inKnockoutGroup && |
| 2494 |
// !nonIsolatedGroup && state->overprintMask == 0xffffffff && |
| 2495 |
// !state->blendFunc && |
| 2496 |
// bitmap->mode == splashModeBGR8 && bitmap->alpha |
| 2497 |
void Splash::pipeRunSoftMaskBGR8(SplashPipe *pipe, int x0, int x1, int y, |
| 2498 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2499 |
SplashColorPtr cSrcPtr) { |
| 2500 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 2501 |
Guchar cSrc0, cSrc1, cSrc2; |
| 2502 |
Guchar cDest0, cDest1, cDest2; |
| 2503 |
Guchar cResult0, cResult1, cResult2; |
| 2504 |
SplashColorPtr destColorPtr; |
| 2505 |
Guchar *destAlphaPtr; |
| 2506 |
SplashColorPtr softMaskPtr; |
| 2507 |
int cSrcStride, x, lastX; |
| 2508 |
|
| 2509 |
if (cSrcPtr) { |
| 2510 |
cSrcStride = 3; |
| 2511 |
} else { |
| 2512 |
cSrcPtr = pipe->cSrcVal; |
| 2513 |
cSrcStride = 0; |
| 2514 |
} |
| 2515 |
for (; x0 <= x1; ++x0) { |
| 2516 |
if (*alphaPtr) { |
| 2517 |
break; |
| 2518 |
} |
| 2519 |
cSrcPtr += cSrcStride; |
| 2520 |
++alphaPtr; |
| 2521 |
} |
| 2522 |
if (x0 > x1) { |
| 2523 |
return; |
| 2524 |
} |
| 2525 |
updateModX(x0); |
| 2526 |
updateModY(y); |
| 2527 |
lastX = x0; |
| 2528 |
|
| 2529 |
useBitmapRow(y); |
| 2530 |
|
| 2531 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0 * 3]; |
| 2532 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2533 |
softMaskPtr = &state->softMask->data[y * state->softMask->rowSize + x0]; |
| 2534 |
|
| 2535 |
for (x = x0; x <= x1; ++x) { |
| 2536 |
|
| 2537 |
//----- alpha |
| 2538 |
alpha = *alphaPtr; |
| 2539 |
if (!alpha) { |
| 2540 |
destColorPtr += 3; |
| 2541 |
++destAlphaPtr; |
| 2542 |
++softMaskPtr; |
| 2543 |
cSrcPtr += cSrcStride; |
| 2544 |
++alphaPtr; |
| 2545 |
continue; |
| 2546 |
} |
| 2547 |
lastX = x; |
| 2548 |
|
| 2549 |
//----- read source color |
| 2550 |
cSrc0 = state->rgbTransferR[cSrcPtr[0]]; |
| 2551 |
cSrc1 = state->rgbTransferG[cSrcPtr[1]]; |
| 2552 |
cSrc2 = state->rgbTransferB[cSrcPtr[2]]; |
| 2553 |
|
| 2554 |
//----- source alpha |
| 2555 |
aSrc = div255(*softMaskPtr++ * alpha); |
| 2556 |
|
| 2557 |
//----- special case for aSrc = 255 |
| 2558 |
if (aSrc == 255) { |
| 2559 |
aResult = 255; |
| 2560 |
cResult0 = cSrc0; |
| 2561 |
cResult1 = cSrc1; |
| 2562 |
cResult2 = cSrc2; |
| 2563 |
} else { |
| 2564 |
|
| 2565 |
//----- read destination alpha |
| 2566 |
aDest = *destAlphaPtr; |
| 2567 |
|
| 2568 |
//----- special case for aDest = 0 |
| 2569 |
if (aDest == 0) { |
| 2570 |
aResult = aSrc; |
| 2571 |
cResult0 = cSrc0; |
| 2572 |
cResult1 = cSrc1; |
| 2573 |
cResult2 = cSrc2; |
| 2574 |
} else { |
| 2575 |
|
| 2576 |
//----- read destination pixel |
| 2577 |
cDest0 = destColorPtr[2]; |
| 2578 |
cDest1 = destColorPtr[1]; |
| 2579 |
cDest2 = destColorPtr[0]; |
| 2580 |
|
| 2581 |
//----- result alpha and non-isolated group element correction |
| 2582 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2583 |
alphaI = aResult; |
| 2584 |
|
| 2585 |
//----- result color |
| 2586 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2587 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 2588 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 2589 |
} |
| 2590 |
} |
| 2591 |
|
| 2592 |
//----- write destination pixel |
| 2593 |
destColorPtr[2] = cResult0; |
| 2594 |
destColorPtr[1] = cResult1; |
| 2595 |
destColorPtr[0] = cResult2; |
| 2596 |
destColorPtr += 3; |
| 2597 |
*destAlphaPtr++ = aResult; |
| 2598 |
|
| 2599 |
cSrcPtr += cSrcStride; |
| 2600 |
++alphaPtr; |
| 2601 |
} |
| 2602 |
|
| 2603 |
updateModX(lastX); |
| 2604 |
} |
| 2605 |
|
| 2606 |
#if SPLASH_CMYK |
| 2607 |
// special case: |
| 2608 |
// !pipe->pattern && aInput == 255 && state->softMask && usesAlpha && |
| 2609 |
// !state->inNonIsolatedGroup && !state->inKnockoutGroup && |
| 2610 |
// !nonIsolatedGroup && state->overprintMask == 0xffffffff && |
| 2611 |
// !state->blendFunc && |
| 2612 |
// bitmap->mode == splashModeCMYK8 && bitmap->alpha |
| 2613 |
void Splash::pipeRunSoftMaskCMYK8(SplashPipe *pipe, int x0, int x1, int y, |
| 2614 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2615 |
SplashColorPtr cSrcPtr) { |
| 2616 |
Guchar alpha, aSrc, aDest, alphaI, aResult; |
| 2617 |
Guchar cSrc0, cSrc1, cSrc2, cSrc3; |
| 2618 |
Guchar cDest0, cDest1, cDest2, cDest3; |
| 2619 |
Guchar cResult0, cResult1, cResult2, cResult3; |
| 2620 |
SplashColorPtr destColorPtr; |
| 2621 |
Guchar *destAlphaPtr; |
| 2622 |
SplashColorPtr softMaskPtr; |
| 2623 |
int cSrcStride, x, lastX; |
| 2624 |
|
| 2625 |
if (cSrcPtr) { |
| 2626 |
cSrcStride = 4; |
| 2627 |
} else { |
| 2628 |
cSrcPtr = pipe->cSrcVal; |
| 2629 |
cSrcStride = 0; |
| 2630 |
} |
| 2631 |
for (; x0 <= x1; ++x0) { |
| 2632 |
if (*alphaPtr) { |
| 2633 |
break; |
| 2634 |
} |
| 2635 |
cSrcPtr += cSrcStride; |
| 2636 |
++alphaPtr; |
| 2637 |
} |
| 2638 |
if (x0 > x1) { |
| 2639 |
return; |
| 2640 |
} |
| 2641 |
updateModX(x0); |
| 2642 |
updateModY(y); |
| 2643 |
lastX = x0; |
| 2644 |
|
| 2645 |
useBitmapRow(y); |
| 2646 |
|
| 2647 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0 * 4]; |
| 2648 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2649 |
softMaskPtr = &state->softMask->data[y * state->softMask->rowSize + x0]; |
| 2650 |
|
| 2651 |
for (x = x0; x <= x1; ++x) { |
| 2652 |
|
| 2653 |
//----- alpha |
| 2654 |
alpha = *alphaPtr; |
| 2655 |
if (!alpha) { |
| 2656 |
destColorPtr += 4; |
| 2657 |
++destAlphaPtr; |
| 2658 |
++softMaskPtr; |
| 2659 |
cSrcPtr += cSrcStride; |
| 2660 |
++alphaPtr; |
| 2661 |
continue; |
| 2662 |
} |
| 2663 |
lastX = x; |
| 2664 |
|
| 2665 |
//----- read destination pixel |
| 2666 |
cDest0 = destColorPtr[0]; |
| 2667 |
cDest1 = destColorPtr[1]; |
| 2668 |
cDest2 = destColorPtr[2]; |
| 2669 |
cDest3 = destColorPtr[3]; |
| 2670 |
|
| 2671 |
//----- read destination alpha |
| 2672 |
aDest = *destAlphaPtr; |
| 2673 |
|
| 2674 |
//----- overprint |
| 2675 |
cSrc0 = state->cmykTransferC[cSrcPtr[0]]; |
| 2676 |
cSrc1 = state->cmykTransferM[cSrcPtr[1]]; |
| 2677 |
cSrc2 = state->cmykTransferY[cSrcPtr[2]]; |
| 2678 |
cSrc3 = state->cmykTransferK[cSrcPtr[3]]; |
| 2679 |
|
| 2680 |
//----- source alpha |
| 2681 |
aSrc = div255(*softMaskPtr++ * alpha); |
| 2682 |
|
| 2683 |
//----- special case for aSrc = 255 |
| 2684 |
if (aSrc == 255) { |
| 2685 |
aResult = 255; |
| 2686 |
cResult0 = cSrc0; |
| 2687 |
cResult1 = cSrc1; |
| 2688 |
cResult2 = cSrc2; |
| 2689 |
cResult3 = cSrc3; |
| 2690 |
} else { |
| 2691 |
|
| 2692 |
//----- special case for aDest = 0 |
| 2693 |
if (aDest == 0) { |
| 2694 |
aResult = aSrc; |
| 2695 |
cResult0 = cSrc0; |
| 2696 |
cResult1 = cSrc1; |
| 2697 |
cResult2 = cSrc2; |
| 2698 |
cResult3 = cSrc3; |
| 2699 |
} else { |
| 2700 |
|
| 2701 |
//----- result alpha and non-isolated group element correction |
| 2702 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2703 |
alphaI = aResult; |
| 2704 |
|
| 2705 |
//----- result color |
| 2706 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2707 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 2708 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 2709 |
cResult3 = (Guchar)(((alphaI - aSrc) * cDest3 + aSrc * cSrc3) / alphaI); |
| 2710 |
} |
| 2711 |
} |
| 2712 |
|
| 2713 |
//----- write destination pixel |
| 2714 |
destColorPtr[0] = cResult0; |
| 2715 |
destColorPtr[1] = cResult1; |
| 2716 |
destColorPtr[2] = cResult2; |
| 2717 |
destColorPtr[3] = cResult3; |
| 2718 |
destColorPtr += 4; |
| 2719 |
*destAlphaPtr++ = aResult; |
| 2720 |
|
| 2721 |
cSrcPtr += cSrcStride; |
| 2722 |
++alphaPtr; |
| 2723 |
} |
| 2724 |
|
| 2725 |
updateModX(lastX); |
| 2726 |
} |
| 2727 |
#endif |
| 2728 |
|
| 2729 |
|
| 2730 |
void Splash::pipeRunNonIsoMono8(SplashPipe *pipe, int x0, int x1, int y, |
| 2731 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2732 |
SplashColorPtr cSrcPtr) { |
| 2733 |
Guchar alpha, aSrc, aDest, alphaI, alpha0, aResult; |
| 2734 |
Guchar cSrc0, cDest0, cResult0; |
| 2735 |
SplashColorPtr destColorPtr; |
| 2736 |
Guchar *destAlphaPtr; |
| 2737 |
Guchar *alpha0Ptr; |
| 2738 |
int cSrcStride, x, lastX; |
| 2739 |
|
| 2740 |
if (cSrcPtr) { |
| 2741 |
cSrcStride = 1; |
| 2742 |
} else { |
| 2743 |
cSrcPtr = pipe->cSrcVal; |
| 2744 |
cSrcStride = 0; |
| 2745 |
} |
| 2746 |
for (; x0 <= x1; ++x0) { |
| 2747 |
if (*alphaPtr) { |
| 2748 |
break; |
| 2749 |
} |
| 2750 |
cSrcPtr += cSrcStride; |
| 2751 |
++alphaPtr; |
| 2752 |
} |
| 2753 |
if (x0 > x1) { |
| 2754 |
return; |
| 2755 |
} |
| 2756 |
updateModX(x0); |
| 2757 |
updateModY(y); |
| 2758 |
lastX = x0; |
| 2759 |
|
| 2760 |
useBitmapRow(y); |
| 2761 |
|
| 2762 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; |
| 2763 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2764 |
if (alpha0Bitmap) { |
| 2765 |
alpha0Ptr = &alpha0Bitmap->alpha[y * alpha0Bitmap->alphaRowSize + x0]; |
| 2766 |
} else { |
| 2767 |
alpha0Ptr = &parent->bitmap->alpha[ |
| 2768 |
(parentOffsetY + y) * parent->bitmap->alphaRowSize |
| 2769 |
+ (parentOffsetX + x0)]; |
| 2770 |
} |
| 2771 |
|
| 2772 |
for (x = x0; x <= x1; ++x) { |
| 2773 |
|
| 2774 |
//----- alpha |
| 2775 |
alpha = *alphaPtr; |
| 2776 |
if (!alpha) { |
| 2777 |
destColorPtr += 1; |
| 2778 |
++destAlphaPtr; |
| 2779 |
++alpha0Ptr; |
| 2780 |
cSrcPtr += cSrcStride; |
| 2781 |
++alphaPtr; |
| 2782 |
continue; |
| 2783 |
} |
| 2784 |
lastX = x; |
| 2785 |
|
| 2786 |
//----- read destination pixel |
| 2787 |
cDest0 = destColorPtr[0]; |
| 2788 |
aDest = *destAlphaPtr; |
| 2789 |
|
| 2790 |
//----- source color |
| 2791 |
cSrc0 = state->grayTransfer[cSrcPtr[0]]; |
| 2792 |
|
| 2793 |
//----- source alpha |
| 2794 |
aSrc = div255(pipe->aInput * alpha); |
| 2795 |
|
| 2796 |
//----- result alpha and non-isolated group element correction |
| 2797 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2798 |
alpha0 = *alpha0Ptr++; |
| 2799 |
alphaI = (Guchar)(aResult + alpha0 - div255(aResult * alpha0)); |
| 2800 |
|
| 2801 |
//----- result color |
| 2802 |
if (alphaI == 0) { |
| 2803 |
cResult0 = 0; |
| 2804 |
} else { |
| 2805 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2806 |
} |
| 2807 |
|
| 2808 |
//----- write destination pixel |
| 2809 |
*destColorPtr++ = cResult0; |
| 2810 |
*destAlphaPtr++ = aResult; |
| 2811 |
|
| 2812 |
cSrcPtr += cSrcStride; |
| 2813 |
++alphaPtr; |
| 2814 |
} // for (x ...) |
| 2815 |
|
| 2816 |
updateModX(lastX); |
| 2817 |
} |
| 2818 |
|
| 2819 |
void Splash::pipeRunNonIsoRGB8(SplashPipe *pipe, int x0, int x1, int y, |
| 2820 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2821 |
SplashColorPtr cSrcPtr) { |
| 2822 |
Guchar alpha, aSrc, aDest, alphaI, alpha0, aResult; |
| 2823 |
Guchar cSrc0, cSrc1, cSrc2; |
| 2824 |
Guchar cDest0, cDest1, cDest2; |
| 2825 |
Guchar cResult0, cResult1, cResult2; |
| 2826 |
SplashColorPtr destColorPtr; |
| 2827 |
Guchar *destAlphaPtr; |
| 2828 |
Guchar *alpha0Ptr; |
| 2829 |
int cSrcStride, x, lastX; |
| 2830 |
|
| 2831 |
if (cSrcPtr) { |
| 2832 |
cSrcStride = 3; |
| 2833 |
} else { |
| 2834 |
cSrcPtr = pipe->cSrcVal; |
| 2835 |
cSrcStride = 0; |
| 2836 |
} |
| 2837 |
for (; x0 <= x1; ++x0) { |
| 2838 |
if (*alphaPtr) { |
| 2839 |
break; |
| 2840 |
} |
| 2841 |
cSrcPtr += cSrcStride; |
| 2842 |
++alphaPtr; |
| 2843 |
} |
| 2844 |
if (x0 > x1) { |
| 2845 |
return; |
| 2846 |
} |
| 2847 |
updateModX(x0); |
| 2848 |
updateModY(y); |
| 2849 |
lastX = x0; |
| 2850 |
|
| 2851 |
useBitmapRow(y); |
| 2852 |
|
| 2853 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0 * 3]; |
| 2854 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2855 |
if (alpha0Bitmap) { |
| 2856 |
alpha0Ptr = &alpha0Bitmap->alpha[y * alpha0Bitmap->alphaRowSize + x0]; |
| 2857 |
} else { |
| 2858 |
alpha0Ptr = &parent->bitmap->alpha[ |
| 2859 |
(parentOffsetY + y) * parent->bitmap->alphaRowSize |
| 2860 |
+ (parentOffsetX + x0)]; |
| 2861 |
} |
| 2862 |
|
| 2863 |
for (x = x0; x <= x1; ++x) { |
| 2864 |
|
| 2865 |
//----- alpha |
| 2866 |
alpha = *alphaPtr; |
| 2867 |
if (!alpha) { |
| 2868 |
destColorPtr += 3; |
| 2869 |
++destAlphaPtr; |
| 2870 |
++alpha0Ptr; |
| 2871 |
cSrcPtr += cSrcStride; |
| 2872 |
++alphaPtr; |
| 2873 |
continue; |
| 2874 |
} |
| 2875 |
lastX = x; |
| 2876 |
|
| 2877 |
//----- read destination pixel |
| 2878 |
cDest0 = destColorPtr[0]; |
| 2879 |
cDest1 = destColorPtr[1]; |
| 2880 |
cDest2 = destColorPtr[2]; |
| 2881 |
aDest = *destAlphaPtr; |
| 2882 |
|
| 2883 |
//----- source color |
| 2884 |
cSrc0 = state->rgbTransferR[cSrcPtr[0]]; |
| 2885 |
cSrc1 = state->rgbTransferG[cSrcPtr[1]]; |
| 2886 |
cSrc2 = state->rgbTransferB[cSrcPtr[2]]; |
| 2887 |
|
| 2888 |
//----- source alpha |
| 2889 |
aSrc = div255(pipe->aInput * alpha); |
| 2890 |
|
| 2891 |
//----- result alpha and non-isolated group element correction |
| 2892 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2893 |
alpha0 = *alpha0Ptr++; |
| 2894 |
alphaI = (Guchar)(aResult + alpha0 - div255(aResult * alpha0)); |
| 2895 |
|
| 2896 |
//----- result color |
| 2897 |
if (alphaI == 0) { |
| 2898 |
cResult0 = 0; |
| 2899 |
cResult1 = 0; |
| 2900 |
cResult2 = 0; |
| 2901 |
} else { |
| 2902 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 2903 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 2904 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 2905 |
} |
| 2906 |
|
| 2907 |
//----- write destination pixel |
| 2908 |
destColorPtr[0] = cResult0; |
| 2909 |
destColorPtr[1] = cResult1; |
| 2910 |
destColorPtr[2] = cResult2; |
| 2911 |
destColorPtr += 3; |
| 2912 |
*destAlphaPtr++ = aResult; |
| 2913 |
|
| 2914 |
cSrcPtr += cSrcStride; |
| 2915 |
++alphaPtr; |
| 2916 |
} // for (x ...) |
| 2917 |
|
| 2918 |
updateModX(lastX); |
| 2919 |
} |
| 2920 |
|
| 2921 |
void Splash::pipeRunNonIsoBGR8(SplashPipe *pipe, int x0, int x1, int y, |
| 2922 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 2923 |
SplashColorPtr cSrcPtr) { |
| 2924 |
Guchar alpha, aSrc, aDest, alphaI, alpha0, aResult; |
| 2925 |
Guchar cSrc0, cSrc1, cSrc2; |
| 2926 |
Guchar cDest0, cDest1, cDest2; |
| 2927 |
Guchar cResult0, cResult1, cResult2; |
| 2928 |
SplashColorPtr destColorPtr; |
| 2929 |
Guchar *destAlphaPtr; |
| 2930 |
Guchar *alpha0Ptr; |
| 2931 |
int cSrcStride, x, lastX; |
| 2932 |
|
| 2933 |
if (cSrcPtr) { |
| 2934 |
cSrcStride = 3; |
| 2935 |
} else { |
| 2936 |
cSrcPtr = pipe->cSrcVal; |
| 2937 |
cSrcStride = 0; |
| 2938 |
} |
| 2939 |
for (; x0 <= x1; ++x0) { |
| 2940 |
if (*alphaPtr) { |
| 2941 |
break; |
| 2942 |
} |
| 2943 |
cSrcPtr += cSrcStride; |
| 2944 |
++alphaPtr; |
| 2945 |
} |
| 2946 |
if (x0 > x1) { |
| 2947 |
return; |
| 2948 |
} |
| 2949 |
updateModX(x0); |
| 2950 |
updateModY(y); |
| 2951 |
lastX = x0; |
| 2952 |
|
| 2953 |
useBitmapRow(y); |
| 2954 |
|
| 2955 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0 * 3]; |
| 2956 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 2957 |
if (alpha0Bitmap) { |
| 2958 |
alpha0Ptr = &alpha0Bitmap->alpha[y * alpha0Bitmap->alphaRowSize + x0]; |
| 2959 |
} else { |
| 2960 |
alpha0Ptr = &parent->bitmap->alpha[ |
| 2961 |
(parentOffsetY + y) * parent->bitmap->alphaRowSize |
| 2962 |
+ (parentOffsetX + x0)]; |
| 2963 |
} |
| 2964 |
|
| 2965 |
for (x = x0; x <= x1; ++x) { |
| 2966 |
|
| 2967 |
//----- alpha |
| 2968 |
alpha = *alphaPtr; |
| 2969 |
if (!alpha) { |
| 2970 |
destColorPtr += 3; |
| 2971 |
++destAlphaPtr; |
| 2972 |
++alpha0Ptr; |
| 2973 |
cSrcPtr += cSrcStride; |
| 2974 |
++alphaPtr; |
| 2975 |
continue; |
| 2976 |
} |
| 2977 |
lastX = x; |
| 2978 |
|
| 2979 |
//----- read destination pixel |
| 2980 |
cDest0 = destColorPtr[2]; |
| 2981 |
cDest1 = destColorPtr[1]; |
| 2982 |
cDest2 = destColorPtr[0]; |
| 2983 |
aDest = *destAlphaPtr; |
| 2984 |
|
| 2985 |
//----- source color |
| 2986 |
cSrc0 = state->rgbTransferR[cSrcPtr[0]]; |
| 2987 |
cSrc1 = state->rgbTransferG[cSrcPtr[1]]; |
| 2988 |
cSrc2 = state->rgbTransferB[cSrcPtr[2]]; |
| 2989 |
|
| 2990 |
//----- source alpha |
| 2991 |
aSrc = div255(pipe->aInput * alpha); |
| 2992 |
|
| 2993 |
//----- result alpha and non-isolated group element correction |
| 2994 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 2995 |
alpha0 = *alpha0Ptr++; |
| 2996 |
alphaI = (Guchar)(aResult + alpha0 - div255(aResult * alpha0)); |
| 2997 |
|
| 2998 |
//----- result color |
| 2999 |
if (alphaI == 0) { |
| 3000 |
cResult0 = 0; |
| 3001 |
cResult1 = 0; |
| 3002 |
cResult2 = 0; |
| 3003 |
} else { |
| 3004 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 3005 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 3006 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 3007 |
} |
| 3008 |
|
| 3009 |
//----- write destination pixel |
| 3010 |
destColorPtr[0] = cResult2; |
| 3011 |
destColorPtr[1] = cResult1; |
| 3012 |
destColorPtr[2] = cResult0; |
| 3013 |
destColorPtr += 3; |
| 3014 |
*destAlphaPtr++ = aResult; |
| 3015 |
|
| 3016 |
cSrcPtr += cSrcStride; |
| 3017 |
++alphaPtr; |
| 3018 |
} // for (x ...) |
| 3019 |
|
| 3020 |
updateModX(lastX); |
| 3021 |
} |
| 3022 |
|
| 3023 |
#if SPLASH_CMYK |
| 3024 |
void Splash::pipeRunNonIsoCMYK8(SplashPipe *pipe, int x0, int x1, int y, |
| 3025 |
Guchar *shapePtr, Guchar *alphaPtr, |
| 3026 |
SplashColorPtr cSrcPtr) { |
| 3027 |
Guchar alpha, aSrc, aDest, alphaI, alpha0, aResult, aPrev; |
| 3028 |
Guchar cSrc0, cSrc1, cSrc2, cSrc3; |
| 3029 |
Guchar cDest0, cDest1, cDest2, cDest3; |
| 3030 |
Guchar cResult0, cResult1, cResult2, cResult3; |
| 3031 |
SplashColorPtr destColorPtr; |
| 3032 |
Guchar *destAlphaPtr; |
| 3033 |
Guchar *alpha0Ptr; |
| 3034 |
int cSrcStride, x, lastX; |
| 3035 |
|
| 3036 |
if (cSrcPtr) { |
| 3037 |
cSrcStride = 4; |
| 3038 |
} else { |
| 3039 |
cSrcPtr = pipe->cSrcVal; |
| 3040 |
cSrcStride = 0; |
| 3041 |
} |
| 3042 |
for (; x0 <= x1; ++x0) { |
| 3043 |
if (*alphaPtr) { |
| 3044 |
break; |
| 3045 |
} |
| 3046 |
cSrcPtr += cSrcStride; |
| 3047 |
++alphaPtr; |
| 3048 |
} |
| 3049 |
if (x0 > x1) { |
| 3050 |
return; |
| 3051 |
} |
| 3052 |
updateModX(x0); |
| 3053 |
updateModY(y); |
| 3054 |
lastX = x0; |
| 3055 |
|
| 3056 |
useBitmapRow(y); |
| 3057 |
|
| 3058 |
destColorPtr = &bitmap->data[y * bitmap->rowSize + x0 * 4]; |
| 3059 |
destAlphaPtr = &bitmap->alpha[y * bitmap->alphaRowSize + x0]; |
| 3060 |
if (alpha0Bitmap) { |
| 3061 |
alpha0Ptr = &alpha0Bitmap->alpha[y * alpha0Bitmap->alphaRowSize + x0]; |
| 3062 |
} else { |
| 3063 |
alpha0Ptr = &parent->bitmap->alpha[ |
| 3064 |
(parentOffsetY + y) * parent->bitmap->alphaRowSize |
| 3065 |
+ (parentOffsetX + x0)]; |
| 3066 |
} |
| 3067 |
|
| 3068 |
for (x = x0; x <= x1; ++x) { |
| 3069 |
|
| 3070 |
//----- alpha |
| 3071 |
alpha = *alphaPtr; |
| 3072 |
if (!alpha) { |
| 3073 |
destColorPtr += 4; |
| 3074 |
++destAlphaPtr; |
| 3075 |
++alpha0Ptr; |
| 3076 |
cSrcPtr += cSrcStride; |
| 3077 |
++alphaPtr; |
| 3078 |
continue; |
| 3079 |
} |
| 3080 |
lastX = x; |
| 3081 |
|
| 3082 |
//----- read destination pixel |
| 3083 |
cDest0 = destColorPtr[0]; |
| 3084 |
cDest1 = destColorPtr[1]; |
| 3085 |
cDest2 = destColorPtr[2]; |
| 3086 |
cDest3 = destColorPtr[3]; |
| 3087 |
aDest = *destAlphaPtr; |
| 3088 |
|
| 3089 |
//----- overprint |
| 3090 |
aPrev = (Guchar)(*alpha0Ptr + aDest - div255(*alpha0Ptr * aDest)); |
| 3091 |
if (state->overprintMask & 0x01) { |
| 3092 |
cSrc0 = state->cmykTransferC[cSrcPtr[0]]; |
| 3093 |
} else { |
| 3094 |
cSrc0 = div255(aPrev * cDest0); |
| 3095 |
} |
| 3096 |
if (state->overprintMask & 0x02) { |
| 3097 |
cSrc1 = state->cmykTransferM[cSrcPtr[1]]; |
| 3098 |
} else { |
| 3099 |
cSrc1 = div255(aPrev * cDest1); |
| 3100 |
} |
| 3101 |
if (state->overprintMask & 0x04) { |
| 3102 |
cSrc2 = state->cmykTransferY[cSrcPtr[2]]; |
| 3103 |
} else { |
| 3104 |
cSrc2 = div255(aPrev * cDest2); |
| 3105 |
} |
| 3106 |
if (state->overprintMask & 0x08) { |
| 3107 |
cSrc3 = state->cmykTransferK[cSrcPtr[3]]; |
| 3108 |
} else { |
| 3109 |
cSrc3 = div255(aPrev * cDest3); |
| 3110 |
} |
| 3111 |
|
| 3112 |
//----- source alpha |
| 3113 |
aSrc = div255(pipe->aInput * alpha); |
| 3114 |
|
| 3115 |
//----- result alpha and non-isolated group element correction |
| 3116 |
aResult = (Guchar)(aSrc + aDest - div255(aSrc * aDest)); |
| 3117 |
alpha0 = *alpha0Ptr++; |
| 3118 |
alphaI = (Guchar)(aResult + alpha0 - div255(aResult * alpha0)); |
| 3119 |
|
| 3120 |
//----- result color |
| 3121 |
if (alphaI == 0) { |
| 3122 |
cResult0 = 0; |
| 3123 |
cResult1 = 0; |
| 3124 |
cResult2 = 0; |
| 3125 |
cResult3 = 0; |
| 3126 |
} else { |
| 3127 |
cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); |
| 3128 |
cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); |
| 3129 |
cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); |
| 3130 |
cResult3 = (Guchar)(((alphaI - aSrc) * cDest3 + aSrc * cSrc3) / alphaI); |
| 3131 |
} |
| 3132 |
|
| 3133 |
//----- write destination pixel |
| 3134 |
destColorPtr[0] = cResult0; |
| 3135 |
destColorPtr[1] = cResult1; |
| 3136 |
destColorPtr[2] = cResult2; |
| 3137 |
destColorPtr[3] = cResult3; |
| 3138 |
destColorPtr += 4; |
| 3139 |
*destAlphaPtr++ = aResult; |
| 3140 |
|
| 3141 |
cSrcPtr += cSrcStride; |
| 3142 |
++alphaPtr; |
| 3143 |
} // for (x ...) |
| 3144 |
|
| 3145 |
updateModX(lastX); |
| 3146 |
} |
| 3147 |
#endif |
| 3148 |
|
| 3149 |
|
| 3150 |
void Splash::useBitmapRow(int y) { |
| 3151 |
if (!deferredInit) { |
| 3152 |
return; |
| 3153 |
} |
| 3154 |
|
| 3155 |
int y0, y1; |
| 3156 |
if (deferredInitYMin > deferredInitYMax) { |
| 3157 |
y0 = y1 = y; |
| 3158 |
deferredInitYMin = deferredInitYMax = y; |
| 3159 |
} else if (y < deferredInitYMin) { |
| 3160 |
y0 = y; |
| 3161 |
y1 = deferredInitYMin - 1; |
| 3162 |
deferredInitYMin = y; |
| 3163 |
} else if (y > deferredInitYMax) { |
| 3164 |
y0 = deferredInitYMax + 1; |
| 3165 |
y1 = y; |
| 3166 |
deferredInitYMax = y; |
| 3167 |
} else { |
| 3168 |
return; |
| 3169 |
} |
| 3170 |
|
| 3171 |
parent->useBitmapRow(parentOffsetY + y); |
| 3172 |
if (state->inNonIsolatedGroup) { |
| 3173 |
for (int yy = y0; yy <= y1; ++yy) { |
| 3174 |
copyParentRowColor(yy); |
| 3175 |
} |
| 3176 |
} else { |
| 3177 |
for (int yy = y0; yy <= y1; ++yy) { |
| 3178 |
zeroRowColor(yy); |
| 3179 |
} |
| 3180 |
} |
| 3181 |
if (bitmap->alpha) { |
| 3182 |
for (int yy = y0; yy <= y1; ++yy) { |
| 3183 |
zeroRowAlpha(yy); |
| 3184 |
} |
| 3185 |
} |
| 3186 |
if (alpha0Bitmap) { |
| 3187 |
for (int yy = y0; yy <= y1; ++yy) { |
| 3188 |
computeAlpha0Row(yy); |
| 3189 |
} |
| 3190 |
} |
| 3191 |
} |
| 3192 |
|
| 3193 |
void Splash::copyParentRowColor(int y) { |
| 3194 |
if (parent->bitmap->mode != bitmap->mode) { |
| 3195 |
return; |
| 3196 |
} |
| 3197 |
if (bitmap->mode == splashModeMono1) { |
| 3198 |
SplashColorPtr p = &bitmap->data[y * bitmap->rowSize]; |
| 3199 |
Guchar mask = (Guchar)0x80; |
| 3200 |
SplashColorPtr q = |
| 3201 |
&parent->bitmap->data[(parentOffsetY + y) * parent->bitmap->rowSize |
| 3202 |
+ (parentOffsetX >> 3)]; |
| 3203 |
Guchar srcMask = (Guchar)(0x80 >> (parentOffsetX & 7)); |
| 3204 |
for (int x = 0; x < bitmap->width; ++x) { |
| 3205 |
if (*q & srcMask) { |
| 3206 |
*p |= mask; |
| 3207 |
} else { |
| 3208 |
*p &= (Guchar)~mask; |
| 3209 |
} |
| 3210 |
if (!(mask = (Guchar)(mask >> 1))) { |
| 3211 |
mask = 0x80; |
| 3212 |
++p; |
| 3213 |
} |
| 3214 |
if (!(srcMask = (Guchar)(srcMask >> 1))) { |
| 3215 |
srcMask = 0x80; |
| 3216 |
++q; |
| 3217 |
} |
| 3218 |
} |
| 3219 |
} else { |
| 3220 |
SplashColorPtr p = &bitmap->data[y * bitmap->rowSize]; |
| 3221 |
SplashColorPtr q = |
| 3222 |
&parent->bitmap->data[(parentOffsetY + y) * parent->bitmap->rowSize |
| 3223 |
+ bitmapComps * parentOffsetX]; |
| 3224 |
memcpy(p, q, bitmapComps * bitmap->width); |
| 3225 |
} |
| 3226 |
} |
| 3227 |
|
| 3228 |
void Splash::zeroRowColor(int y) { |
| 3229 |
memset(&bitmap->data[y * bitmap->rowSize], 0, |
| 3230 |
bitmap->rowSize < 0 ? -bitmap->rowSize : bitmap->rowSize); |
| 3231 |
} |
| 3232 |
|
| 3233 |
void Splash::zeroRowAlpha(int y) { |
| 3234 |
memset(&bitmap->alpha[y * bitmap->alphaRowSize], 0, bitmap->width); |
| 3235 |
} |
| 3236 |
|
| 3237 |
void Splash::computeAlpha0Row(int y) { |
| 3238 |
Guchar *p = &alpha0Bitmap->alpha[y * alpha0Bitmap->alphaRowSize]; |
| 3239 |
Guchar *q0; |
| 3240 |
if (parent->alpha0Bitmap) { |
| 3241 |
q0 = &parent->alpha0Bitmap->alpha[ |
| 3242 |
(parentOffsetY + y) * parent->alpha0Bitmap->alphaRowSize |
| 3243 |
+ parentOffsetX]; |
| 3244 |
} else { |
| 3245 |
q0 = &parent->parent->bitmap->alpha[ |
| 3246 |
(parentOffsetY + parent->parentOffsetY + y) |
| 3247 |
* parent->parent->bitmap->alphaRowSize |
| 3248 |
+ parentOffsetX + parent->parentOffsetX]; |
| 3249 |
} |
| 3250 |
Guchar *q1 = &parent->bitmap->alpha[ |
| 3251 |
(parentOffsetY + y) * parent->bitmap->alphaRowSize |
| 3252 |
+ parentOffsetX]; |
| 3253 |
int w = alpha0Bitmap->width; |
| 3254 |
for (int x = 0; x < w; ++x) { |
| 3255 |
Guchar a0 = *q0++; |
| 3256 |
Guchar a1 = *q1++; |
| 3257 |
*p++ = (Guchar)(a0 + a1 - div255(a0 * a1)); |
| 3258 |
} |
| 3259 |
} |
| 3260 |
|
| 3261 |
//------------------------------------------------------------------------ |
| 3262 |
|
| 3263 |
// Transform a point from user space to device space. |
| 3264 |
inline void Splash::transform(SplashCoord *matrix, |
| 3265 |
SplashCoord xi, SplashCoord yi, |
| 3266 |
SplashCoord *xo, SplashCoord *yo) { |
| 3267 |
// [ m[0] m[1] 0 ] |
| 3268 |
// [xo yo 1] = [xi yi 1] * [ m[2] m[3] 0 ] |
| 3269 |
// [ m[4] m[5] 1 ] |
| 3270 |
*xo = xi * matrix[0] + yi * matrix[2] + matrix[4]; |
| 3271 |
*yo = xi * matrix[1] + yi * matrix[3] + matrix[5]; |
| 3272 |
} |
| 3273 |
|
| 3274 |
//------------------------------------------------------------------------ |
| 3275 |
// SplashImageCache |
| 3276 |
//------------------------------------------------------------------------ |
| 3277 |
|
| 3278 |
SplashImageCache::SplashImageCache() { |
| 3279 |
tag = NULL; |
| 3280 |
width = 0; |
| 3281 |
height = 0; |
| 3282 |
mode = splashModeRGB8; |
| 3283 |
alpha = gFalse; |
| 3284 |
interpolate = gFalse; |
| 3285 |
colorData = NULL; |
| 3286 |
alphaData = NULL; |
| 3287 |
refCount = 1; |
| 3288 |
} |
| 3289 |
|
| 3290 |
SplashImageCache::~SplashImageCache() { |
| 3291 |
if (tag) { |
| 3292 |
delete tag; |
| 3293 |
} |
| 3294 |
gfree(colorData); |
| 3295 |
gfree(alphaData); |
| 3296 |
} |
| 3297 |
|
| 3298 |
GBool SplashImageCache::match(GString *aTag, int aWidth, int aHeight, |
| 3299 |
SplashColorMode aMode, GBool aAlpha, |
| 3300 |
GBool aInterpolate) { |
| 3301 |
return aTag && tag && !aTag->cmp(tag) && |
| 3302 |
aWidth == width && aHeight == height && |
| 3303 |
aMode == mode && aAlpha == alpha && |
| 3304 |
aInterpolate == interpolate; |
| 3305 |
} |
| 3306 |
|
| 3307 |
void SplashImageCache::reset(GString *aTag, int aWidth, int aHeight, |
| 3308 |
SplashColorMode aMode, GBool aAlpha, |
| 3309 |
GBool aInterpolate) { |
| 3310 |
if (tag) { |
| 3311 |
delete tag; |
| 3312 |
} |
| 3313 |
if (aTag) { |
| 3314 |
tag = aTag->copy(); |
| 3315 |
} else { |
| 3316 |
tag = NULL; |
| 3317 |
} |
| 3318 |
width = aWidth; |
| 3319 |
height = aHeight; |
| 3320 |
mode = aMode; |
| 3321 |
alpha = aAlpha; |
| 3322 |
interpolate = aInterpolate; |
| 3323 |
gfree(colorData); |
| 3324 |
colorData = NULL; |
| 3325 |
gfree(alphaData); |
| 3326 |
alphaData = NULL; |
| 3327 |
} |
| 3328 |
|
| 3329 |
void SplashImageCache::incRefCount() { |
| 3330 |
++refCount; |
| 3331 |
} |
| 3332 |
|
| 3333 |
void SplashImageCache::decRefCount() { |
| 3334 |
--refCount; |
| 3335 |
if (refCount == 0) { |
| 3336 |
delete this; |
| 3337 |
} |
| 3338 |
} |
| 3339 |
|
| 3340 |
//------------------------------------------------------------------------ |
| 3341 |
// ImageScaler |
| 3342 |
//------------------------------------------------------------------------ |
| 3343 |
|
| 3344 |
// Abstract base class. |
| 3345 |
class ImageScaler { |
| 3346 |
public: |
| 3347 |
|
| 3348 |
ImageScaler() {} |
| 3349 |
virtual ~ImageScaler() {} |
| 3350 |
|
| 3351 |
// Compute the next line of the scaled image. This can be called up |
| 3352 |
// to [scaledHeight] times. |
| 3353 |
virtual void nextLine() = 0; |
| 3354 |
|
| 3355 |
// Retrieve the color and alpha data generated by the most recent |
| 3356 |
// call to nextLine(). |
| 3357 |
virtual Guchar *colorData() = 0; |
| 3358 |
virtual Guchar *alphaData() = 0; |
| 3359 |
}; |
| 3360 |
|
| 3361 |
//------------------------------------------------------------------------ |
| 3362 |
// BasicImageScaler |
| 3363 |
//------------------------------------------------------------------------ |
| 3364 |
|
| 3365 |
// The actual image scaler. |
| 3366 |
class BasicImageScaler: public ImageScaler { |
| 3367 |
public: |
| 3368 |
|
| 3369 |
BasicImageScaler(SplashImageSource aSrc, void *aSrcData, |
| 3370 |
int aSrcWidth, int aSrcHeight, int aNComps, GBool aHasAlpha, |
| 3371 |
int aScaledWidth, int aScaledHeight, GBool aInterpolate); |
| 3372 |
virtual ~BasicImageScaler(); |
| 3373 |
virtual void nextLine(); |
| 3374 |
virtual Guchar *colorData() { return colorLine; } |
| 3375 |
virtual Guchar *alphaData() { return alphaLine; } |
| 3376 |
|
| 3377 |
protected: |
| 3378 |
|
| 3379 |
void vertDownscaleHorizDownscale(); |
| 3380 |
void vertDownscaleHorizUpscaleNoInterp(); |
| 3381 |
void vertDownscaleHorizUpscaleInterp(); |
| 3382 |
void vertUpscaleHorizDownscaleNoInterp(); |
| 3383 |
void vertUpscaleHorizDownscaleInterp(); |
| 3384 |
void vertUpscaleHorizUpscaleNoInterp(); |
| 3385 |
void vertUpscaleHorizUpscaleInterp(); |
| 3386 |
|
| 3387 |
// source image data function |
| 3388 |
SplashImageSource src; |
| 3389 |
void *srcData; |
| 3390 |
|
| 3391 |
// source image size |
| 3392 |
int srcWidth; |
| 3393 |
int srcHeight; |
| 3394 |
|
| 3395 |
// scaled image size |
| 3396 |
int scaledWidth; |
| 3397 |
int scaledHeight; |
| 3398 |
|
| 3399 |
// number of color and alpha components |
| 3400 |
int nComps; |
| 3401 |
GBool hasAlpha; |
| 3402 |
|
| 3403 |
// params/state for vertical scaling |
| 3404 |
int yp, yq; |
| 3405 |
int yt, yn; |
| 3406 |
int ySrcCur, yScaledCur; |
| 3407 |
SplashCoord yInvScale; |
| 3408 |
|
| 3409 |
// params for horizontal scaling |
| 3410 |
int xp, xq; |
| 3411 |
SplashCoord xInvScale; |
| 3412 |
|
| 3413 |
// scaling function |
| 3414 |
void (BasicImageScaler::*scalingFunc)(); |
| 3415 |
|
| 3416 |
// temporary buffers for vertical scaling |
| 3417 |
Guchar *colorTmpBuf0; |
| 3418 |
Guchar *colorTmpBuf1; |
| 3419 |
Guchar *colorTmpBuf2; |
| 3420 |
Guchar *alphaTmpBuf0; |
| 3421 |
Guchar *alphaTmpBuf1; |
| 3422 |
Guchar *alphaTmpBuf2; |
| 3423 |
Guint *colorAccBuf; |
| 3424 |
Guint *alphaAccBuf; |
| 3425 |
|
| 3426 |
// output of horizontal scaling |
| 3427 |
Guchar *colorLine; |
| 3428 |
Guchar *alphaLine; |
| 3429 |
}; |
| 3430 |
|
| 3431 |
BasicImageScaler::BasicImageScaler(SplashImageSource aSrc, void *aSrcData, |
| 3432 |
int aSrcWidth, int aSrcHeight, |
| 3433 |
int aNComps, GBool aHasAlpha, |
| 3434 |
int aScaledWidth, int aScaledHeight, |
| 3435 |
GBool aInterpolate) { |
| 3436 |
colorTmpBuf0 = NULL; |
| 3437 |
colorTmpBuf1 = NULL; |
| 3438 |
colorTmpBuf2 = NULL; |
| 3439 |
alphaTmpBuf0 = NULL; |
| 3440 |
alphaTmpBuf1 = NULL; |
| 3441 |
alphaTmpBuf2 = NULL; |
| 3442 |
colorAccBuf = NULL; |
| 3443 |
alphaAccBuf = NULL; |
| 3444 |
colorLine = NULL; |
| 3445 |
alphaLine = NULL; |
| 3446 |
|
| 3447 |
src = aSrc; |
| 3448 |
srcData = aSrcData; |
| 3449 |
srcWidth = aSrcWidth; |
| 3450 |
srcHeight = aSrcHeight; |
| 3451 |
scaledWidth = aScaledWidth; |
| 3452 |
scaledHeight = aScaledHeight; |
| 3453 |
nComps = aNComps; |
| 3454 |
hasAlpha = aHasAlpha; |
| 3455 |
|
| 3456 |
// select scaling function; allocate buffers |
| 3457 |
if (scaledHeight <= srcHeight) { |
| 3458 |
// vertical downscaling |
| 3459 |
yp = srcHeight / scaledHeight; |
| 3460 |
yq = srcHeight % scaledHeight; |
| 3461 |
yt = 0; |
| 3462 |
colorTmpBuf0 = (Guchar *)gmallocn(srcWidth, nComps); |
| 3463 |
colorAccBuf = (Guint *)gmallocn(srcWidth, nComps * (int)sizeof(Guint)); |
| 3464 |
if (hasAlpha) { |
| 3465 |
alphaTmpBuf0 = (Guchar *)gmalloc(srcWidth); |
| 3466 |
alphaAccBuf = (Guint *)gmallocn(srcWidth, sizeof(Guint)); |
| 3467 |
} |
| 3468 |
if (scaledWidth <= srcWidth) { |
| 3469 |
scalingFunc = &BasicImageScaler::vertDownscaleHorizDownscale; |
| 3470 |
} else { |
| 3471 |
if (aInterpolate) { |
| 3472 |
scalingFunc = &BasicImageScaler::vertDownscaleHorizUpscaleInterp; |
| 3473 |
} else { |
| 3474 |
scalingFunc = &BasicImageScaler::vertDownscaleHorizUpscaleNoInterp; |
| 3475 |
} |
| 3476 |
} |
| 3477 |
} else { |
| 3478 |
// vertical upscaling |
| 3479 |
yp = scaledHeight / srcHeight; |
| 3480 |
yq = scaledHeight % srcHeight; |
| 3481 |
yt = 0; |
| 3482 |
yn = 0; |
| 3483 |
if (aInterpolate) { |
| 3484 |
yInvScale = (SplashCoord)srcHeight / (SplashCoord)scaledHeight; |
| 3485 |
colorTmpBuf0 = (Guchar *)gmallocn(srcWidth, nComps); |
| 3486 |
colorTmpBuf1 = (Guchar *)gmallocn(srcWidth, nComps); |
| 3487 |
if (hasAlpha) { |
| 3488 |
alphaTmpBuf0 = (Guchar *)gmalloc(srcWidth); |
| 3489 |
alphaTmpBuf1 = (Guchar *)gmalloc(srcWidth); |
| 3490 |
} |
| 3491 |
ySrcCur = 0; |
| 3492 |
yScaledCur = 0; |
| 3493 |
if (scaledWidth <= srcWidth) { |
| 3494 |
scalingFunc = &BasicImageScaler::vertUpscaleHorizDownscaleInterp; |
| 3495 |
} else { |
| 3496 |
colorTmpBuf2 = (Guchar *)gmallocn(srcWidth, nComps); |
| 3497 |
if (hasAlpha) { |
| 3498 |
alphaTmpBuf2 = (Guchar *)gmalloc(srcWidth); |
| 3499 |
} |
| 3500 |
scalingFunc = &BasicImageScaler::vertUpscaleHorizUpscaleInterp; |
| 3501 |
} |
| 3502 |
} else { |
| 3503 |
colorTmpBuf0 = (Guchar *)gmallocn(srcWidth, nComps); |
| 3504 |
if (hasAlpha) { |
| 3505 |
alphaTmpBuf0 = (Guchar *)gmalloc(srcWidth); |
| 3506 |
} |
| 3507 |
if (scaledWidth <= srcWidth) { |
| 3508 |
scalingFunc = &BasicImageScaler::vertUpscaleHorizDownscaleNoInterp; |
| 3509 |
} else { |
| 3510 |
scalingFunc = &BasicImageScaler::vertUpscaleHorizUpscaleNoInterp; |
| 3511 |
} |
| 3512 |
} |
| 3513 |
} |
| 3514 |
if (scaledWidth <= srcWidth) { |
| 3515 |
xp = srcWidth / scaledWidth; |
| 3516 |
xq = srcWidth % scaledWidth; |
| 3517 |
} else { |
| 3518 |
xp = scaledWidth / srcWidth; |
| 3519 |
xq = scaledWidth % srcWidth; |
| 3520 |
if (aInterpolate) { |
| 3521 |
xInvScale = (SplashCoord)srcWidth / (SplashCoord)scaledWidth; |
| 3522 |
} |
| 3523 |
} |
| 3524 |
colorLine = (Guchar *)gmallocn(scaledWidth, nComps); |
| 3525 |
if (hasAlpha) { |
| 3526 |
alphaLine = (Guchar *)gmalloc(scaledWidth); |
| 3527 |
} |
| 3528 |
} |
| 3529 |
|
| 3530 |
BasicImageScaler::~BasicImageScaler() { |
| 3531 |
gfree(colorTmpBuf0); |
| 3532 |
gfree(colorTmpBuf1); |
| 3533 |
gfree(colorTmpBuf2); |
| 3534 |
gfree(alphaTmpBuf0); |
| 3535 |
gfree(alphaTmpBuf1); |
| 3536 |
gfree(alphaTmpBuf2); |
| 3537 |
gfree(colorAccBuf); |
| 3538 |
gfree(alphaAccBuf); |
| 3539 |
gfree(colorLine); |
| 3540 |
gfree(alphaLine); |
| 3541 |
} |
| 3542 |
|
| 3543 |
void BasicImageScaler::nextLine() { |
| 3544 |
(this->*scalingFunc)(); |
| 3545 |
} |
| 3546 |
|
| 3547 |
void BasicImageScaler::vertDownscaleHorizDownscale() { |
| 3548 |
//--- vert downscale |
| 3549 |
int yStep = yp; |
| 3550 |
yt += yq; |
| 3551 |
if (yt >= scaledHeight) { |
| 3552 |
yt -= scaledHeight; |
| 3553 |
++yStep; |
| 3554 |
} |
| 3555 |
memset(colorAccBuf, 0, (srcWidth * nComps) * sizeof(Guint)); |
| 3556 |
if (hasAlpha) { |
| 3557 |
memset(alphaAccBuf, 0, srcWidth * sizeof(Guint)); |
| 3558 |
} |
| 3559 |
int nRowComps = srcWidth * nComps; |
| 3560 |
for (int i = 0; i < yStep; ++i) { |
| 3561 |
(*src)(srcData, colorTmpBuf0, alphaTmpBuf0); |
| 3562 |
for (int j = 0; j < nRowComps; ++j) { |
| 3563 |
colorAccBuf[j] += colorTmpBuf0[j]; |
| 3564 |
} |
| 3565 |
if (hasAlpha) { |
| 3566 |
for (int j = 0; j < srcWidth; ++j) { |
| 3567 |
alphaAccBuf[j] += alphaTmpBuf0[j]; |
| 3568 |
} |
| 3569 |
} |
| 3570 |
} |
| 3571 |
|
| 3572 |
//--- horiz downscale |
| 3573 |
int colorAcc[splashMaxColorComps]; |
| 3574 |
int xt = 0; |
| 3575 |
int unscaledColorIdx = 0; |
| 3576 |
int unscaledAlphaIdx = 0; |
| 3577 |
int scaledColorIdx = 0; |
| 3578 |
|
| 3579 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 3580 |
int xStep = xp; |
| 3581 |
xt += xq; |
| 3582 |
if (xt >= scaledWidth) { |
| 3583 |
xt -= scaledWidth; |
| 3584 |
++xStep; |
| 3585 |
} |
| 3586 |
|
| 3587 |
for (int j = 0; j < nComps; ++j) { |
| 3588 |
colorAcc[j] = 0; |
| 3589 |
} |
| 3590 |
for (int i = 0; i < xStep; ++i) { |
| 3591 |
for (int j = 0; j < nComps; ++j) { |
| 3592 |
colorAcc[j] += colorAccBuf[unscaledColorIdx + j]; |
| 3593 |
} |
| 3594 |
unscaledColorIdx += nComps; |
| 3595 |
} |
| 3596 |
int nPixels = yStep * xStep; |
| 3597 |
for (int j = 0; j < nComps; ++j) { |
| 3598 |
colorLine[scaledColorIdx + j] = (Guchar)(colorAcc[j] / nPixels); |
| 3599 |
} |
| 3600 |
scaledColorIdx += nComps; |
| 3601 |
|
| 3602 |
if (hasAlpha) { |
| 3603 |
int alphaAcc = 0; |
| 3604 |
for (int i = 0; i < xStep; ++i) { |
| 3605 |
alphaAcc += alphaAccBuf[unscaledAlphaIdx]; |
| 3606 |
++unscaledAlphaIdx; |
| 3607 |
} |
| 3608 |
alphaLine[scaledIdx] = (Guchar)(alphaAcc / nPixels); |
| 3609 |
} |
| 3610 |
} |
| 3611 |
} |
| 3612 |
|
| 3613 |
void BasicImageScaler::vertDownscaleHorizUpscaleNoInterp() { |
| 3614 |
//--- vert downscale |
| 3615 |
int yStep = yp; |
| 3616 |
yt += yq; |
| 3617 |
if (yt >= scaledHeight) { |
| 3618 |
yt -= scaledHeight; |
| 3619 |
++yStep; |
| 3620 |
} |
| 3621 |
memset(colorAccBuf, 0, (srcWidth * nComps) * sizeof(Guint)); |
| 3622 |
if (hasAlpha) { |
| 3623 |
memset(alphaAccBuf, 0, srcWidth * sizeof(Guint)); |
| 3624 |
} |
| 3625 |
int nRowComps = srcWidth * nComps; |
| 3626 |
for (int i = 0; i < yStep; ++i) { |
| 3627 |
(*src)(srcData, colorTmpBuf0, alphaTmpBuf0); |
| 3628 |
for (int j = 0; j < nRowComps; ++j) { |
| 3629 |
colorAccBuf[j] += colorTmpBuf0[j]; |
| 3630 |
} |
| 3631 |
if (hasAlpha) { |
| 3632 |
for (int j = 0; j < srcWidth; ++j) { |
| 3633 |
alphaAccBuf[j] += alphaTmpBuf0[j]; |
| 3634 |
} |
| 3635 |
} |
| 3636 |
} |
| 3637 |
|
| 3638 |
//--- horiz upscale |
| 3639 |
Guchar colorBuf[splashMaxColorComps]; |
| 3640 |
int xt = 0; |
| 3641 |
int scaledColorIdx = 0; |
| 3642 |
int srcColorIdx = 0; |
| 3643 |
int scaledAlphaIdx = 0; |
| 3644 |
for (int srcIdx = 0; srcIdx < srcWidth; ++srcIdx) { |
| 3645 |
int xStep = xp; |
| 3646 |
xt += xq; |
| 3647 |
if (xt >= srcWidth) { |
| 3648 |
xt -= srcWidth; |
| 3649 |
++xStep; |
| 3650 |
} |
| 3651 |
for (int j = 0; j < nComps; ++j) { |
| 3652 |
colorBuf[j] = (Guchar)(colorAccBuf[srcColorIdx + j] / yStep); |
| 3653 |
} |
| 3654 |
srcColorIdx += nComps; |
| 3655 |
for (int i = 0; i < xStep; ++i) { |
| 3656 |
for (int j = 0; j < nComps; ++j) { |
| 3657 |
colorLine[scaledColorIdx + j] = colorBuf[j]; |
| 3658 |
} |
| 3659 |
scaledColorIdx += nComps; |
| 3660 |
} |
| 3661 |
if (hasAlpha) { |
| 3662 |
Guchar alphaBuf = (Guchar)(alphaAccBuf[srcIdx] / yStep); |
| 3663 |
for (int i = 0; i < xStep; ++i) { |
| 3664 |
alphaLine[scaledAlphaIdx] = alphaBuf; |
| 3665 |
++scaledAlphaIdx; |
| 3666 |
} |
| 3667 |
} |
| 3668 |
} |
| 3669 |
} |
| 3670 |
|
| 3671 |
void BasicImageScaler::vertDownscaleHorizUpscaleInterp() { |
| 3672 |
//--- vert downscale |
| 3673 |
int yStep = yp; |
| 3674 |
yt += yq; |
| 3675 |
if (yt >= scaledHeight) { |
| 3676 |
yt -= scaledHeight; |
| 3677 |
++yStep; |
| 3678 |
} |
| 3679 |
memset(colorAccBuf, 0, (srcWidth * nComps) * sizeof(Guint)); |
| 3680 |
if (hasAlpha) { |
| 3681 |
memset(alphaAccBuf, 0, srcWidth * sizeof(Guint)); |
| 3682 |
} |
| 3683 |
int nRowComps = srcWidth * nComps; |
| 3684 |
for (int i = 0; i < yStep; ++i) { |
| 3685 |
(*src)(srcData, colorTmpBuf0, alphaTmpBuf0); |
| 3686 |
for (int j = 0; j < nRowComps; ++j) { |
| 3687 |
colorAccBuf[j] += colorTmpBuf0[j]; |
| 3688 |
} |
| 3689 |
if (hasAlpha) { |
| 3690 |
for (int j = 0; j < srcWidth; ++j) { |
| 3691 |
alphaAccBuf[j] += alphaTmpBuf0[j]; |
| 3692 |
} |
| 3693 |
} |
| 3694 |
} |
| 3695 |
for (int j = 0; j < srcWidth * nComps; ++j) { |
| 3696 |
colorAccBuf[j] /= yStep; |
| 3697 |
} |
| 3698 |
if (hasAlpha) { |
| 3699 |
for (int j = 0; j < srcWidth; ++j) { |
| 3700 |
alphaAccBuf[j] /= yStep; |
| 3701 |
} |
| 3702 |
} |
| 3703 |
|
| 3704 |
//--- horiz upscale |
| 3705 |
int scaledColorIdx = 0; |
| 3706 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 3707 |
SplashCoord xs = ((SplashCoord)scaledIdx + 0.5) * xInvScale; |
| 3708 |
int x0 = splashFloor(xs - 0.5); |
| 3709 |
int x1 = x0 + 1; |
| 3710 |
SplashCoord s0 = (SplashCoord)x1 + 0.5 - xs; |
| 3711 |
SplashCoord s1 = (SplashCoord)1 - s0; |
| 3712 |
if (x0 < 0) { |
| 3713 |
x0 = 0; |
| 3714 |
} |
| 3715 |
if (x1 >= srcWidth) { |
| 3716 |
x1 = srcWidth - 1; |
| 3717 |
} |
| 3718 |
for (int j = 0; j < nComps; ++j) { |
| 3719 |
colorLine[scaledColorIdx + j] = |
| 3720 |
(Guchar)(int)(s0 * colorAccBuf[x0 * nComps + j] + |
| 3721 |
s1 * colorAccBuf[x1 * nComps + j]); |
| 3722 |
} |
| 3723 |
scaledColorIdx += nComps; |
| 3724 |
if (hasAlpha) { |
| 3725 |
alphaLine[scaledIdx] = (Guchar)(int)(s0 * alphaAccBuf[x0] + |
| 3726 |
s1 * alphaAccBuf[x1]); |
| 3727 |
} |
| 3728 |
} |
| 3729 |
} |
| 3730 |
|
| 3731 |
void BasicImageScaler::vertUpscaleHorizDownscaleNoInterp() { |
| 3732 |
//--- vert upscale |
| 3733 |
if (yn == 0) { |
| 3734 |
yn = yp; |
| 3735 |
yt += yq; |
| 3736 |
if (yt >= srcHeight) { |
| 3737 |
yt -= srcHeight; |
| 3738 |
++yn; |
| 3739 |
} |
| 3740 |
(*src)(srcData, colorTmpBuf0, alphaTmpBuf0); |
| 3741 |
} |
| 3742 |
--yn; |
| 3743 |
|
| 3744 |
//--- horiz downscale |
| 3745 |
int colorAcc[splashMaxColorComps]; |
| 3746 |
int xt = 0; |
| 3747 |
int unscaledColorIdx = 0; |
| 3748 |
int unscaledAlphaIdx = 0; |
| 3749 |
int scaledColorIdx = 0; |
| 3750 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 3751 |
int xStep = xp; |
| 3752 |
xt += xq; |
| 3753 |
if (xt >= scaledWidth) { |
| 3754 |
xt -= scaledWidth; |
| 3755 |
++xStep; |
| 3756 |
} |
| 3757 |
|
| 3758 |
for (int j = 0; j < nComps; ++j) { |
| 3759 |
colorAcc[j] = 0; |
| 3760 |
} |
| 3761 |
for (int i = 0; i < xStep; ++i) { |
| 3762 |
for (int j = 0; j < nComps; ++j) { |
| 3763 |
colorAcc[j] += colorTmpBuf0[unscaledColorIdx + j]; |
| 3764 |
} |
| 3765 |
unscaledColorIdx += nComps; |
| 3766 |
} |
| 3767 |
for (int j = 0; j < nComps; ++j) { |
| 3768 |
colorLine[scaledColorIdx + j] = (Guchar)(colorAcc[j] / xStep); |
| 3769 |
} |
| 3770 |
scaledColorIdx += nComps; |
| 3771 |
|
| 3772 |
if (hasAlpha) { |
| 3773 |
int alphaAcc = 0; |
| 3774 |
for (int i = 0; i < xStep; ++i) { |
| 3775 |
alphaAcc += alphaTmpBuf0[unscaledAlphaIdx]; |
| 3776 |
++unscaledAlphaIdx; |
| 3777 |
} |
| 3778 |
alphaLine[scaledIdx] = (Guchar)(alphaAcc / xStep); |
| 3779 |
} |
| 3780 |
} |
| 3781 |
} |
| 3782 |
|
| 3783 |
void BasicImageScaler::vertUpscaleHorizDownscaleInterp() { |
| 3784 |
//--- vert upscale |
| 3785 |
if (ySrcCur == 0) { |
| 3786 |
(*src)(srcData, colorTmpBuf0, alphaTmpBuf0); |
| 3787 |
(*src)(srcData, colorTmpBuf1, alphaTmpBuf1); |
| 3788 |
ySrcCur = 1; |
| 3789 |
} |
| 3790 |
SplashCoord ys = ((SplashCoord)yScaledCur + 0.5) * yInvScale; |
| 3791 |
int y0 = splashFloor(ys - 0.5); |
| 3792 |
int y1 = y0 + 1; |
| 3793 |
SplashCoord vs0 = (SplashCoord)y1 + 0.5 - ys; |
| 3794 |
SplashCoord vs1 = (SplashCoord)1 - vs0; |
| 3795 |
if (y1 > ySrcCur && ySrcCur < srcHeight - 1) { |
| 3796 |
Guchar *t = colorTmpBuf0; |
| 3797 |
colorTmpBuf0 = colorTmpBuf1; |
| 3798 |
colorTmpBuf1 = t; |
| 3799 |
if (hasAlpha) { |
| 3800 |
t = alphaTmpBuf0; |
| 3801 |
alphaTmpBuf0 = alphaTmpBuf1; |
| 3802 |
alphaTmpBuf1 = t; |
| 3803 |
} |
| 3804 |
(*src)(srcData, colorTmpBuf1, alphaTmpBuf1); |
| 3805 |
++ySrcCur; |
| 3806 |
} |
| 3807 |
Guchar *color0 = colorTmpBuf0; |
| 3808 |
Guchar *color1 = colorTmpBuf1; |
| 3809 |
Guchar *alpha0 = alphaTmpBuf0; |
| 3810 |
Guchar *alpha1 = alphaTmpBuf1; |
| 3811 |
if (y0 < 0) { |
| 3812 |
y0 = 0; |
| 3813 |
color1 = color0; |
| 3814 |
alpha1 = alpha0; |
| 3815 |
} |
| 3816 |
if (y1 >= srcHeight) { |
| 3817 |
y1 = srcHeight - 1; |
| 3818 |
color0 = color1; |
| 3819 |
alpha0 = alpha1; |
| 3820 |
} |
| 3821 |
++yScaledCur; |
| 3822 |
|
| 3823 |
//--- horiz downscale |
| 3824 |
int colorAcc[splashMaxColorComps]; |
| 3825 |
int xt = 0; |
| 3826 |
int unscaledColorIdx = 0; |
| 3827 |
int unscaledAlphaIdx = 0; |
| 3828 |
int scaledColorIdx = 0; |
| 3829 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 3830 |
int xStep = xp; |
| 3831 |
xt += xq; |
| 3832 |
if (xt >= scaledWidth) { |
| 3833 |
xt -= scaledWidth; |
| 3834 |
++xStep; |
| 3835 |
} |
| 3836 |
|
| 3837 |
for (int j = 0; j < nComps; ++j) { |
| 3838 |
colorAcc[j] = 0; |
| 3839 |
} |
| 3840 |
for (int i = 0; i < xStep; ++i) { |
| 3841 |
for (int j = 0; j < nComps; ++j) { |
| 3842 |
colorAcc[j] += (int)(vs0 * (int)color0[unscaledColorIdx + j] + |
| 3843 |
vs1 * (int)color1[unscaledColorIdx + j]); |
| 3844 |
} |
| 3845 |
unscaledColorIdx += nComps; |
| 3846 |
} |
| 3847 |
for (int j = 0; j < nComps; ++j) { |
| 3848 |
colorLine[scaledColorIdx + j] = (Guchar)(colorAcc[j] / xStep); |
| 3849 |
} |
| 3850 |
scaledColorIdx += nComps; |
| 3851 |
|
| 3852 |
if (hasAlpha) { |
| 3853 |
int alphaAcc = 0; |
| 3854 |
for (int i = 0; i < xStep; ++i) { |
| 3855 |
alphaAcc += (int)(vs0 * (int)alpha0[unscaledAlphaIdx] + |
| 3856 |
vs1 * (int)alpha1[unscaledAlphaIdx]); |
| 3857 |
++unscaledAlphaIdx; |
| 3858 |
} |
| 3859 |
alphaLine[scaledIdx] = (Guchar)(alphaAcc / xStep); |
| 3860 |
} |
| 3861 |
} |
| 3862 |
} |
| 3863 |
|
| 3864 |
void BasicImageScaler::vertUpscaleHorizUpscaleNoInterp() { |
| 3865 |
//--- vert upscale |
| 3866 |
if (yn == 0) { |
| 3867 |
yn = yp; |
| 3868 |
yt += yq; |
| 3869 |
if (yt >= srcHeight) { |
| 3870 |
yt -= srcHeight; |
| 3871 |
++yn; |
| 3872 |
} |
| 3873 |
(*src)(srcData, colorTmpBuf0, alphaTmpBuf0); |
| 3874 |
} |
| 3875 |
--yn; |
| 3876 |
|
| 3877 |
//--- horiz upscale |
| 3878 |
int xt = 0; |
| 3879 |
int scaledColorIdx = 0; |
| 3880 |
int srcColorIdx = 0; |
| 3881 |
int scaledAlphaIdx = 0; |
| 3882 |
for (int srcIdx = 0; srcIdx < srcWidth; ++srcIdx) { |
| 3883 |
int xStep = xp; |
| 3884 |
xt += xq; |
| 3885 |
if (xt >= srcWidth) { |
| 3886 |
xt -= srcWidth; |
| 3887 |
++xStep; |
| 3888 |
} |
| 3889 |
for (int i = 0; i < xStep; ++i) { |
| 3890 |
for (int j = 0; j < nComps; ++j) { |
| 3891 |
colorLine[scaledColorIdx + j] = colorTmpBuf0[srcColorIdx + j]; |
| 3892 |
} |
| 3893 |
scaledColorIdx += nComps; |
| 3894 |
} |
| 3895 |
srcColorIdx += nComps; |
| 3896 |
if (hasAlpha) { |
| 3897 |
Guchar alphaBuf = alphaTmpBuf0[srcIdx]; |
| 3898 |
for (int i = 0; i < xStep; ++i) { |
| 3899 |
alphaLine[scaledAlphaIdx] = alphaBuf; |
| 3900 |
++scaledAlphaIdx; |
| 3901 |
} |
| 3902 |
} |
| 3903 |
} |
| 3904 |
} |
| 3905 |
|
| 3906 |
void BasicImageScaler::vertUpscaleHorizUpscaleInterp() { |
| 3907 |
//--- vert upscale |
| 3908 |
if (ySrcCur == 0) { |
| 3909 |
(*src)(srcData, colorTmpBuf0, alphaTmpBuf0); |
| 3910 |
(*src)(srcData, colorTmpBuf1, alphaTmpBuf1); |
| 3911 |
ySrcCur = 1; |
| 3912 |
} |
| 3913 |
SplashCoord ys = ((SplashCoord)yScaledCur + 0.5) * yInvScale; |
| 3914 |
int y0 = splashFloor(ys - 0.5); |
| 3915 |
int y1 = y0 + 1; |
| 3916 |
SplashCoord vs0 = (SplashCoord)y1 + 0.5 - ys; |
| 3917 |
SplashCoord vs1 = (SplashCoord)1 - vs0; |
| 3918 |
if (y1 > ySrcCur && ySrcCur < srcHeight - 1) { |
| 3919 |
Guchar *t = colorTmpBuf0; |
| 3920 |
colorTmpBuf0 = colorTmpBuf1; |
| 3921 |
colorTmpBuf1 = t; |
| 3922 |
if (hasAlpha) { |
| 3923 |
t = alphaTmpBuf0; |
| 3924 |
alphaTmpBuf0 = alphaTmpBuf1; |
| 3925 |
alphaTmpBuf1 = t; |
| 3926 |
} |
| 3927 |
(*src)(srcData, colorTmpBuf1, alphaTmpBuf1); |
| 3928 |
++ySrcCur; |
| 3929 |
} |
| 3930 |
Guchar *color0 = colorTmpBuf0; |
| 3931 |
Guchar *color1 = colorTmpBuf1; |
| 3932 |
Guchar *alpha0 = alphaTmpBuf0; |
| 3933 |
Guchar *alpha1 = alphaTmpBuf1; |
| 3934 |
if (y0 < 0) { |
| 3935 |
y0 = 0; |
| 3936 |
color1 = color0; |
| 3937 |
alpha1 = alpha0; |
| 3938 |
} |
| 3939 |
if (y1 >= srcHeight) { |
| 3940 |
y1 = srcHeight - 1; |
| 3941 |
color0 = color1; |
| 3942 |
alpha0 = alpha1; |
| 3943 |
} |
| 3944 |
++yScaledCur; |
| 3945 |
for (int srcIdx = 0; srcIdx < srcWidth * nComps; ++srcIdx) { |
| 3946 |
colorTmpBuf2[srcIdx] = (Guchar)(int)(vs0 * (int)color0[srcIdx] + |
| 3947 |
vs1 * (int)color1[srcIdx]); |
| 3948 |
} |
| 3949 |
if (hasAlpha) { |
| 3950 |
for (int srcIdx = 0; srcIdx < srcWidth; ++srcIdx) { |
| 3951 |
alphaTmpBuf2[srcIdx] = (Guchar)(int)(vs0 * (int)alpha0[srcIdx] + |
| 3952 |
vs1 * (int)alpha1[srcIdx]); |
| 3953 |
} |
| 3954 |
} |
| 3955 |
|
| 3956 |
//--- horiz upscale |
| 3957 |
int scaledColorIdx = 0; |
| 3958 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 3959 |
SplashCoord xs = ((SplashCoord)scaledIdx + 0.5) * xInvScale; |
| 3960 |
int x0 = splashFloor(xs - 0.5); |
| 3961 |
int x1 = x0 + 1; |
| 3962 |
SplashCoord hs0 = (SplashCoord)x1 + 0.5 - xs; |
| 3963 |
SplashCoord hs1 = (SplashCoord)1 - hs0; |
| 3964 |
if (x0 < 0) { |
| 3965 |
x0 = 0; |
| 3966 |
} |
| 3967 |
if (x1 >= srcWidth) { |
| 3968 |
x1 = srcWidth - 1; |
| 3969 |
} |
| 3970 |
for (int j = 0; j < nComps; ++j) { |
| 3971 |
colorLine[scaledColorIdx + j] = |
| 3972 |
(Guchar)(int)(hs0 * (int)colorTmpBuf2[x0 * nComps + j] + |
| 3973 |
hs1 * (int)colorTmpBuf2[x1 * nComps + j]); |
| 3974 |
} |
| 3975 |
scaledColorIdx += nComps; |
| 3976 |
if (hasAlpha) { |
| 3977 |
alphaLine[scaledIdx] = (Guchar)(int)(hs0 * (int)alphaTmpBuf2[x0] + |
| 3978 |
hs1 * (int)alphaTmpBuf2[x1]); |
| 3979 |
} |
| 3980 |
} |
| 3981 |
} |
| 3982 |
|
| 3983 |
//------------------------------------------------------------------------ |
| 3984 |
// SavingImageScaler |
| 3985 |
//------------------------------------------------------------------------ |
| 3986 |
|
| 3987 |
// Wrapper around BasicImageScaler that saves the scaled image for use |
| 3988 |
// by ReplayImageScaler. |
| 3989 |
class SavingImageScaler: public BasicImageScaler { |
| 3990 |
public: |
| 3991 |
|
| 3992 |
SavingImageScaler(SplashImageSource aSrc, void *aSrcData, |
| 3993 |
int aSrcWidth, int aSrcHeight, int aNComps, GBool aHasAlpha, |
| 3994 |
int aScaledWidth, int aScaledHeight, GBool aInterpolate, |
| 3995 |
Guchar *aColorCache, Guchar *aAlphaCache); |
| 3996 |
virtual void nextLine(); |
| 3997 |
|
| 3998 |
private: |
| 3999 |
|
| 4000 |
Guchar *colorPtr; |
| 4001 |
Guchar *alphaPtr; |
| 4002 |
}; |
| 4003 |
|
| 4004 |
SavingImageScaler::SavingImageScaler(SplashImageSource aSrc, void *aSrcData, |
| 4005 |
int aSrcWidth, int aSrcHeight, |
| 4006 |
int aNComps, GBool aHasAlpha, |
| 4007 |
int aScaledWidth, int aScaledHeight, |
| 4008 |
GBool aInterpolate, |
| 4009 |
Guchar *aColorCache, Guchar *aAlphaCache): |
| 4010 |
BasicImageScaler(aSrc, aSrcData, aSrcWidth, aSrcHeight, aNComps, aHasAlpha, |
| 4011 |
aScaledWidth, aScaledHeight, aInterpolate) |
| 4012 |
{ |
| 4013 |
colorPtr = aColorCache; |
| 4014 |
alphaPtr = aAlphaCache; |
| 4015 |
} |
| 4016 |
|
| 4017 |
void SavingImageScaler::nextLine() { |
| 4018 |
BasicImageScaler::nextLine(); |
| 4019 |
memcpy(colorPtr, colorData(), scaledWidth * nComps); |
| 4020 |
colorPtr += scaledWidth * nComps; |
| 4021 |
if (hasAlpha) { |
| 4022 |
memcpy(alphaPtr, alphaData(), scaledWidth); |
| 4023 |
alphaPtr += scaledWidth; |
| 4024 |
} |
| 4025 |
} |
| 4026 |
|
| 4027 |
//------------------------------------------------------------------------ |
| 4028 |
// ReplayImageScaler |
| 4029 |
//------------------------------------------------------------------------ |
| 4030 |
|
| 4031 |
// "Replay" a scaled image saved by SavingImageScaler. |
| 4032 |
class ReplayImageScaler: public ImageScaler { |
| 4033 |
public: |
| 4034 |
|
| 4035 |
ReplayImageScaler(int aNComps, GBool aHasAlpha, |
| 4036 |
int aScaledWidth, |
| 4037 |
Guchar *aColorCache, Guchar *aAlphaCache); |
| 4038 |
virtual void nextLine(); |
| 4039 |
virtual Guchar *colorData() { return colorLine; } |
| 4040 |
virtual Guchar *alphaData() { return alphaLine; } |
| 4041 |
|
| 4042 |
private: |
| 4043 |
|
| 4044 |
int nComps; |
| 4045 |
GBool hasAlpha; |
| 4046 |
int scaledWidth; |
| 4047 |
Guchar *colorPtr; |
| 4048 |
Guchar *alphaPtr; |
| 4049 |
Guchar *colorLine; |
| 4050 |
Guchar *alphaLine; |
| 4051 |
}; |
| 4052 |
|
| 4053 |
ReplayImageScaler::ReplayImageScaler(int aNComps, GBool aHasAlpha, |
| 4054 |
int aScaledWidth, |
| 4055 |
Guchar *aColorCache, Guchar *aAlphaCache) { |
| 4056 |
nComps = aNComps; |
| 4057 |
hasAlpha = aHasAlpha; |
| 4058 |
scaledWidth = aScaledWidth; |
| 4059 |
colorPtr = aColorCache; |
| 4060 |
alphaPtr = aAlphaCache; |
| 4061 |
colorLine = NULL; |
| 4062 |
alphaLine = NULL; |
| 4063 |
} |
| 4064 |
|
| 4065 |
void ReplayImageScaler::nextLine() { |
| 4066 |
colorLine = colorPtr; |
| 4067 |
alphaLine = alphaPtr; |
| 4068 |
colorPtr += scaledWidth * nComps; |
| 4069 |
if (hasAlpha) { |
| 4070 |
alphaPtr += scaledWidth; |
| 4071 |
} |
| 4072 |
} |
| 4073 |
|
| 4074 |
//------------------------------------------------------------------------ |
| 4075 |
// ImageMaskScaler |
| 4076 |
//------------------------------------------------------------------------ |
| 4077 |
|
| 4078 |
class ImageMaskScaler { |
| 4079 |
public: |
| 4080 |
|
| 4081 |
// Set up a MaskScaler to scale from [srcWidth]x[srcHeight] to |
| 4082 |
// [scaledWidth]x[scaledHeight]. The [interpolate] flag controls |
| 4083 |
// filtering on upsampling, and the [antialias] flag controls |
| 4084 |
// filtering on downsampling. |
| 4085 |
ImageMaskScaler(SplashImageMaskSource aSrc, void *aSrcData, |
| 4086 |
int aSrcWidth, int aSrcHeight, |
| 4087 |
int aScaledWidth, int aScaledHeight, |
| 4088 |
GBool aInterpolate, GBool aAntialias); |
| 4089 |
|
| 4090 |
~ImageMaskScaler(); |
| 4091 |
|
| 4092 |
// Compute the next line of the scaled image mask. This can be |
| 4093 |
// called up to [scaledHeight] times. |
| 4094 |
void nextLine(); |
| 4095 |
|
| 4096 |
// Retrieve the data generated by the most recent call to |
| 4097 |
// nextLine(). |
| 4098 |
Guchar *data() { return line; } |
| 4099 |
|
| 4100 |
private: |
| 4101 |
|
| 4102 |
void vertDownscaleHorizDownscale(); |
| 4103 |
void vertDownscaleHorizDownscaleThresh(); |
| 4104 |
void vertDownscaleHorizUpscaleNoInterp(); |
| 4105 |
void vertDownscaleHorizUpscaleInterp(); |
| 4106 |
void vertDownscaleHorizUpscaleThresh(); |
| 4107 |
void vertUpscaleHorizDownscaleNoInterp(); |
| 4108 |
void vertUpscaleHorizDownscaleInterp(); |
| 4109 |
void vertUpscaleHorizDownscaleThresh(); |
| 4110 |
void vertUpscaleHorizUpscaleNoInterp(); |
| 4111 |
void vertUpscaleHorizUpscaleInterp(); |
| 4112 |
|
| 4113 |
// source image data function |
| 4114 |
SplashImageMaskSource src; |
| 4115 |
void *srcData; |
| 4116 |
|
| 4117 |
// source image size |
| 4118 |
int srcWidth; |
| 4119 |
int srcHeight; |
| 4120 |
|
| 4121 |
// scaled image size |
| 4122 |
int scaledWidth; |
| 4123 |
int scaledHeight; |
| 4124 |
|
| 4125 |
// params/state for vertical scaling |
| 4126 |
int yp, yq; |
| 4127 |
int yt, yn; |
| 4128 |
int ySrcCur, yScaledCur; |
| 4129 |
SplashCoord yInvScale; |
| 4130 |
|
| 4131 |
// params for horizontal scaling |
| 4132 |
int xp, xq; |
| 4133 |
SplashCoord xInvScale; |
| 4134 |
|
| 4135 |
// vertical and horizontal scaling functions |
| 4136 |
void (ImageMaskScaler::*scalingFunc)(); |
| 4137 |
|
| 4138 |
// temporary buffers for vertical scaling |
| 4139 |
Guchar *tmpBuf0; |
| 4140 |
Guchar *tmpBuf1; |
| 4141 |
Guchar *tmpBuf2; |
| 4142 |
Guint *accBuf; |
| 4143 |
|
| 4144 |
// output of horizontal scaling |
| 4145 |
Guchar *line; |
| 4146 |
}; |
| 4147 |
|
| 4148 |
ImageMaskScaler::ImageMaskScaler(SplashImageMaskSource aSrc, void *aSrcData, |
| 4149 |
int aSrcWidth, int aSrcHeight, |
| 4150 |
int aScaledWidth, int aScaledHeight, |
| 4151 |
GBool aInterpolate, GBool aAntialias) { |
| 4152 |
tmpBuf0 = NULL; |
| 4153 |
tmpBuf1 = NULL; |
| 4154 |
tmpBuf2 = NULL; |
| 4155 |
accBuf = NULL; |
| 4156 |
line = NULL; |
| 4157 |
|
| 4158 |
src = aSrc; |
| 4159 |
srcData = aSrcData; |
| 4160 |
srcWidth = aSrcWidth; |
| 4161 |
srcHeight = aSrcHeight; |
| 4162 |
scaledWidth = aScaledWidth; |
| 4163 |
scaledHeight = aScaledHeight; |
| 4164 |
|
| 4165 |
// select scaling function; allocate buffers |
| 4166 |
if (scaledHeight <= srcHeight) { |
| 4167 |
// vertical downscaling |
| 4168 |
yp = srcHeight / scaledHeight; |
| 4169 |
yq = srcHeight % scaledHeight; |
| 4170 |
yt = 0; |
| 4171 |
tmpBuf0 = (Guchar *)gmalloc(srcWidth); |
| 4172 |
accBuf = (Guint *)gmallocn(srcWidth, sizeof(Guint)); |
| 4173 |
if (scaledWidth <= srcWidth) { |
| 4174 |
if (!aAntialias) { |
| 4175 |
scalingFunc = &ImageMaskScaler::vertDownscaleHorizDownscaleThresh; |
| 4176 |
} else { |
| 4177 |
scalingFunc = &ImageMaskScaler::vertDownscaleHorizDownscale; |
| 4178 |
} |
| 4179 |
} else { |
| 4180 |
if (!aAntialias) { |
| 4181 |
scalingFunc = &ImageMaskScaler::vertDownscaleHorizUpscaleThresh; |
| 4182 |
} else if (aInterpolate) { |
| 4183 |
scalingFunc = &ImageMaskScaler::vertDownscaleHorizUpscaleInterp; |
| 4184 |
} else { |
| 4185 |
scalingFunc = &ImageMaskScaler::vertDownscaleHorizUpscaleNoInterp; |
| 4186 |
} |
| 4187 |
} |
| 4188 |
} else { |
| 4189 |
// vertical upscaling |
| 4190 |
yp = scaledHeight / srcHeight; |
| 4191 |
yq = scaledHeight % srcHeight; |
| 4192 |
yt = 0; |
| 4193 |
yn = 0; |
| 4194 |
if (!aAntialias) { |
| 4195 |
tmpBuf0 = (Guchar *)gmalloc(srcWidth); |
| 4196 |
if (scaledWidth <= srcWidth) { |
| 4197 |
scalingFunc = &ImageMaskScaler::vertUpscaleHorizDownscaleThresh; |
| 4198 |
} else { |
| 4199 |
scalingFunc = &ImageMaskScaler::vertUpscaleHorizUpscaleNoInterp; |
| 4200 |
} |
| 4201 |
} else if (aInterpolate) { |
| 4202 |
yInvScale = (SplashCoord)srcHeight / (SplashCoord)scaledHeight; |
| 4203 |
tmpBuf0 = (Guchar *)gmalloc(srcWidth); |
| 4204 |
tmpBuf1 = (Guchar *)gmalloc(srcWidth); |
| 4205 |
ySrcCur = 0; |
| 4206 |
yScaledCur = 0; |
| 4207 |
if (scaledWidth <= srcWidth) { |
| 4208 |
scalingFunc = &ImageMaskScaler::vertUpscaleHorizDownscaleInterp; |
| 4209 |
} else { |
| 4210 |
tmpBuf2 = (Guchar *)gmalloc(srcWidth); |
| 4211 |
scalingFunc = &ImageMaskScaler::vertUpscaleHorizUpscaleInterp; |
| 4212 |
} |
| 4213 |
} else { |
| 4214 |
tmpBuf0 = (Guchar *)gmalloc(srcWidth); |
| 4215 |
if (scaledWidth <= srcWidth) { |
| 4216 |
scalingFunc = &ImageMaskScaler::vertUpscaleHorizDownscaleNoInterp; |
| 4217 |
} else { |
| 4218 |
scalingFunc = &ImageMaskScaler::vertUpscaleHorizUpscaleNoInterp; |
| 4219 |
} |
| 4220 |
} |
| 4221 |
} |
| 4222 |
if (scaledWidth <= srcWidth) { |
| 4223 |
xp = srcWidth / scaledWidth; |
| 4224 |
xq = srcWidth % scaledWidth; |
| 4225 |
} else { |
| 4226 |
xp = scaledWidth / srcWidth; |
| 4227 |
xq = scaledWidth % srcWidth; |
| 4228 |
if (aInterpolate) { |
| 4229 |
xInvScale = (SplashCoord)srcWidth / (SplashCoord)scaledWidth; |
| 4230 |
} |
| 4231 |
} |
| 4232 |
line = (Guchar *)gmalloc(scaledWidth); |
| 4233 |
} |
| 4234 |
|
| 4235 |
ImageMaskScaler::~ImageMaskScaler() { |
| 4236 |
gfree(tmpBuf0); |
| 4237 |
gfree(tmpBuf1); |
| 4238 |
gfree(tmpBuf2); |
| 4239 |
gfree(accBuf); |
| 4240 |
gfree(line); |
| 4241 |
} |
| 4242 |
|
| 4243 |
void ImageMaskScaler::nextLine() { |
| 4244 |
(this->*scalingFunc)(); |
| 4245 |
} |
| 4246 |
|
| 4247 |
void ImageMaskScaler::vertDownscaleHorizDownscale() { |
| 4248 |
//--- vert downscale |
| 4249 |
int yStep = yp; |
| 4250 |
yt += yq; |
| 4251 |
if (yt >= scaledHeight) { |
| 4252 |
yt -= scaledHeight; |
| 4253 |
++yStep; |
| 4254 |
} |
| 4255 |
memset(accBuf, 0, srcWidth * sizeof(Guint)); |
| 4256 |
for (int i = 0; i < yStep; ++i) { |
| 4257 |
(*src)(srcData, tmpBuf0); |
| 4258 |
for (int j = 0; j < srcWidth; ++j) { |
| 4259 |
accBuf[j] += tmpBuf0[j]; |
| 4260 |
} |
| 4261 |
} |
| 4262 |
|
| 4263 |
//--- horiz downscale |
| 4264 |
int acc; |
| 4265 |
int xt = 0; |
| 4266 |
int unscaledIdx = 0; |
| 4267 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 4268 |
int xStep = xp; |
| 4269 |
xt += xq; |
| 4270 |
if (xt >= scaledWidth) { |
| 4271 |
xt -= scaledWidth; |
| 4272 |
++xStep; |
| 4273 |
} |
| 4274 |
|
| 4275 |
acc = 0; |
| 4276 |
for (int i = 0; i < xStep; ++i) { |
| 4277 |
acc += accBuf[unscaledIdx]; |
| 4278 |
++unscaledIdx; |
| 4279 |
} |
| 4280 |
line[scaledIdx] = (Guchar)((255 * acc) / (xStep * yStep)); |
| 4281 |
} |
| 4282 |
} |
| 4283 |
|
| 4284 |
void ImageMaskScaler::vertDownscaleHorizDownscaleThresh() { |
| 4285 |
//--- vert downscale |
| 4286 |
int yStep = yp; |
| 4287 |
yt += yq; |
| 4288 |
if (yt >= scaledHeight) { |
| 4289 |
yt -= scaledHeight; |
| 4290 |
++yStep; |
| 4291 |
} |
| 4292 |
memset(accBuf, 0, srcWidth * sizeof(Guint)); |
| 4293 |
for (int i = 0; i < yStep; ++i) { |
| 4294 |
(*src)(srcData, tmpBuf0); |
| 4295 |
for (int j = 0; j < srcWidth; ++j) { |
| 4296 |
accBuf[j] += tmpBuf0[j]; |
| 4297 |
} |
| 4298 |
} |
| 4299 |
|
| 4300 |
//--- horiz downscale |
| 4301 |
int acc; |
| 4302 |
int xt = 0; |
| 4303 |
int unscaledIdx = 0; |
| 4304 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 4305 |
int xStep = xp; |
| 4306 |
xt += xq; |
| 4307 |
if (xt >= scaledWidth) { |
| 4308 |
xt -= scaledWidth; |
| 4309 |
++xStep; |
| 4310 |
} |
| 4311 |
|
| 4312 |
acc = 0; |
| 4313 |
for (int i = 0; i < xStep; ++i) { |
| 4314 |
acc += accBuf[unscaledIdx]; |
| 4315 |
++unscaledIdx; |
| 4316 |
} |
| 4317 |
line[scaledIdx] = acc > ((xStep * yStep) >> 1) ? (Guchar)255 : (Guchar)0; |
| 4318 |
} |
| 4319 |
} |
| 4320 |
|
| 4321 |
void ImageMaskScaler::vertDownscaleHorizUpscaleNoInterp() { |
| 4322 |
//--- vert downscale |
| 4323 |
int yStep = yp; |
| 4324 |
yt += yq; |
| 4325 |
if (yt >= scaledHeight) { |
| 4326 |
yt -= scaledHeight; |
| 4327 |
++yStep; |
| 4328 |
} |
| 4329 |
memset(accBuf, 0, srcWidth * sizeof(Guint)); |
| 4330 |
for (int i = 0; i < yStep; ++i) { |
| 4331 |
(*src)(srcData, tmpBuf0); |
| 4332 |
for (int j = 0; j < srcWidth; ++j) { |
| 4333 |
accBuf[j] += tmpBuf0[j]; |
| 4334 |
} |
| 4335 |
} |
| 4336 |
|
| 4337 |
//--- horiz upscale |
| 4338 |
int xt = 0; |
| 4339 |
int scaledIdx = 0; |
| 4340 |
for (int srcIdx = 0; srcIdx < srcWidth; ++srcIdx) { |
| 4341 |
int xStep = xp; |
| 4342 |
xt += xq; |
| 4343 |
if (xt >= srcWidth) { |
| 4344 |
xt -= srcWidth; |
| 4345 |
++xStep; |
| 4346 |
} |
| 4347 |
Guchar buf = (Guchar)((255 * accBuf[srcIdx]) / yStep); |
| 4348 |
for (int i = 0; i < xStep; ++i) { |
| 4349 |
line[scaledIdx] = buf; |
| 4350 |
++scaledIdx; |
| 4351 |
} |
| 4352 |
} |
| 4353 |
} |
| 4354 |
|
| 4355 |
void ImageMaskScaler::vertDownscaleHorizUpscaleInterp() { |
| 4356 |
//--- vert downscale |
| 4357 |
int yStep = yp; |
| 4358 |
yt += yq; |
| 4359 |
if (yt >= scaledHeight) { |
| 4360 |
yt -= scaledHeight; |
| 4361 |
++yStep; |
| 4362 |
} |
| 4363 |
memset(accBuf, 0, srcWidth * sizeof(Guint)); |
| 4364 |
for (int i = 0; i < yStep; ++i) { |
| 4365 |
(*src)(srcData, tmpBuf0); |
| 4366 |
for (int j = 0; j < srcWidth; ++j) { |
| 4367 |
accBuf[j] += tmpBuf0[j]; |
| 4368 |
} |
| 4369 |
} |
| 4370 |
for (int j = 0; j < srcWidth; ++j) { |
| 4371 |
accBuf[j] = (255 * accBuf[j]) / yStep; |
| 4372 |
} |
| 4373 |
|
| 4374 |
//--- horiz upscale |
| 4375 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 4376 |
SplashCoord xs = ((SplashCoord)scaledIdx + 0.5) * xInvScale; |
| 4377 |
int x0 = splashFloor(xs - 0.5); |
| 4378 |
int x1 = x0 + 1; |
| 4379 |
SplashCoord s0 = (SplashCoord)x1 + 0.5 - xs; |
| 4380 |
SplashCoord s1 = (SplashCoord)1 - s0; |
| 4381 |
if (x0 < 0) { |
| 4382 |
x0 = 0; |
| 4383 |
} |
| 4384 |
if (x1 >= srcWidth) { |
| 4385 |
x1 = srcWidth - 1; |
| 4386 |
} |
| 4387 |
line[scaledIdx] = (Guchar)(int)(s0 * accBuf[x0] + s1 * accBuf[x1]); |
| 4388 |
} |
| 4389 |
} |
| 4390 |
|
| 4391 |
void ImageMaskScaler::vertDownscaleHorizUpscaleThresh() { |
| 4392 |
//--- vert downscale |
| 4393 |
int yStep = yp; |
| 4394 |
yt += yq; |
| 4395 |
if (yt >= scaledHeight) { |
| 4396 |
yt -= scaledHeight; |
| 4397 |
++yStep; |
| 4398 |
} |
| 4399 |
memset(accBuf, 0, srcWidth * sizeof(Guint)); |
| 4400 |
for (int i = 0; i < yStep; ++i) { |
| 4401 |
(*src)(srcData, tmpBuf0); |
| 4402 |
for (int j = 0; j < srcWidth; ++j) { |
| 4403 |
accBuf[j] += tmpBuf0[j]; |
| 4404 |
} |
| 4405 |
} |
| 4406 |
|
| 4407 |
//--- horiz upscale |
| 4408 |
int xt = 0; |
| 4409 |
int scaledIdx = 0; |
| 4410 |
for (int srcIdx = 0; srcIdx < srcWidth; ++srcIdx) { |
| 4411 |
int xStep = xp; |
| 4412 |
xt += xq; |
| 4413 |
if (xt >= srcWidth) { |
| 4414 |
xt -= srcWidth; |
| 4415 |
++xStep; |
| 4416 |
} |
| 4417 |
Guchar buf = accBuf[srcIdx] > (Guint)(yStep >> 1) ? (Guchar)255 : (Guchar)0; |
| 4418 |
for (int i = 0; i < xStep; ++i) { |
| 4419 |
line[scaledIdx] = buf; |
| 4420 |
++scaledIdx; |
| 4421 |
} |
| 4422 |
} |
| 4423 |
} |
| 4424 |
|
| 4425 |
void ImageMaskScaler::vertUpscaleHorizDownscaleNoInterp() { |
| 4426 |
//--- vert upscale |
| 4427 |
if (yn == 0) { |
| 4428 |
yn = yp; |
| 4429 |
yt += yq; |
| 4430 |
if (yt >= srcHeight) { |
| 4431 |
yt -= srcHeight; |
| 4432 |
++yn; |
| 4433 |
} |
| 4434 |
(*src)(srcData, tmpBuf0); |
| 4435 |
} |
| 4436 |
--yn; |
| 4437 |
|
| 4438 |
//--- horiz downscale |
| 4439 |
int acc; |
| 4440 |
int xt = 0; |
| 4441 |
int unscaledIdx = 0; |
| 4442 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 4443 |
int xStep = xp; |
| 4444 |
xt += xq; |
| 4445 |
if (xt >= scaledWidth) { |
| 4446 |
xt -= scaledWidth; |
| 4447 |
++xStep; |
| 4448 |
} |
| 4449 |
|
| 4450 |
acc = 0; |
| 4451 |
for (int i = 0; i < xStep; ++i) { |
| 4452 |
acc += tmpBuf0[unscaledIdx]; |
| 4453 |
++unscaledIdx; |
| 4454 |
} |
| 4455 |
line[scaledIdx] = (Guchar)((255 * acc) / xStep); |
| 4456 |
} |
| 4457 |
} |
| 4458 |
|
| 4459 |
void ImageMaskScaler::vertUpscaleHorizDownscaleInterp() { |
| 4460 |
//--- vert upscale |
| 4461 |
if (ySrcCur == 0) { |
| 4462 |
(*src)(srcData, tmpBuf0); |
| 4463 |
(*src)(srcData, tmpBuf1); |
| 4464 |
ySrcCur = 1; |
| 4465 |
} |
| 4466 |
SplashCoord ys = ((SplashCoord)yScaledCur + 0.5) * yInvScale; |
| 4467 |
int y0 = splashFloor(ys - 0.5); |
| 4468 |
int y1 = y0 + 1; |
| 4469 |
SplashCoord vs0 = (SplashCoord)y1 + 0.5 - ys; |
| 4470 |
SplashCoord vs1 = (SplashCoord)1 - vs0; |
| 4471 |
if (y1 > ySrcCur && ySrcCur < srcHeight - 1) { |
| 4472 |
Guchar *t = tmpBuf0; |
| 4473 |
tmpBuf0 = tmpBuf1; |
| 4474 |
tmpBuf1 = t; |
| 4475 |
(*src)(srcData, tmpBuf1); |
| 4476 |
++ySrcCur; |
| 4477 |
} |
| 4478 |
Guchar *mask0 = tmpBuf0; |
| 4479 |
Guchar *mask1 = tmpBuf1; |
| 4480 |
if (y0 < 0) { |
| 4481 |
y0 = 0; |
| 4482 |
mask1 = mask0; |
| 4483 |
} |
| 4484 |
if (y1 >= srcHeight) { |
| 4485 |
y1 = srcHeight - 1; |
| 4486 |
mask0 = mask1; |
| 4487 |
} |
| 4488 |
++yScaledCur; |
| 4489 |
|
| 4490 |
//--- horiz downscale |
| 4491 |
int acc; |
| 4492 |
int xt = 0; |
| 4493 |
int unscaledIdx = 0; |
| 4494 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 4495 |
int xStep = xp; |
| 4496 |
xt += xq; |
| 4497 |
if (xt >= scaledWidth) { |
| 4498 |
xt -= scaledWidth; |
| 4499 |
++xStep; |
| 4500 |
} |
| 4501 |
|
| 4502 |
acc = 0; |
| 4503 |
for (int i = 0; i < xStep; ++i) { |
| 4504 |
acc += (int)(vs0 * (int)mask0[unscaledIdx] + |
| 4505 |
vs1 * (int)mask1[unscaledIdx]); |
| 4506 |
++unscaledIdx; |
| 4507 |
} |
| 4508 |
line[scaledIdx] = (Guchar)((255 * acc) / xStep); |
| 4509 |
} |
| 4510 |
} |
| 4511 |
|
| 4512 |
void ImageMaskScaler::vertUpscaleHorizDownscaleThresh() { |
| 4513 |
//--- vert upscale |
| 4514 |
if (yn == 0) { |
| 4515 |
yn = yp; |
| 4516 |
yt += yq; |
| 4517 |
if (yt >= srcHeight) { |
| 4518 |
yt -= srcHeight; |
| 4519 |
++yn; |
| 4520 |
} |
| 4521 |
(*src)(srcData, tmpBuf0); |
| 4522 |
} |
| 4523 |
--yn; |
| 4524 |
|
| 4525 |
//--- horiz downscale |
| 4526 |
int acc; |
| 4527 |
int xt = 0; |
| 4528 |
int unscaledIdx = 0; |
| 4529 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 4530 |
int xStep = xp; |
| 4531 |
xt += xq; |
| 4532 |
if (xt >= scaledWidth) { |
| 4533 |
xt -= scaledWidth; |
| 4534 |
++xStep; |
| 4535 |
} |
| 4536 |
|
| 4537 |
acc = 0; |
| 4538 |
for (int i = 0; i < xStep; ++i) { |
| 4539 |
acc += tmpBuf0[unscaledIdx]; |
| 4540 |
++unscaledIdx; |
| 4541 |
} |
| 4542 |
line[scaledIdx] = acc > (xStep >> 1) ? (Guchar)255 : (Guchar)0; |
| 4543 |
} |
| 4544 |
} |
| 4545 |
|
| 4546 |
void ImageMaskScaler::vertUpscaleHorizUpscaleNoInterp() { |
| 4547 |
//--- vert upscale |
| 4548 |
if (yn == 0) { |
| 4549 |
yn = yp; |
| 4550 |
yt += yq; |
| 4551 |
if (yt >= srcHeight) { |
| 4552 |
yt -= srcHeight; |
| 4553 |
++yn; |
| 4554 |
} |
| 4555 |
(*src)(srcData, tmpBuf0); |
| 4556 |
} |
| 4557 |
--yn; |
| 4558 |
|
| 4559 |
//--- horiz upscale |
| 4560 |
int xt = 0; |
| 4561 |
int scaledIdx = 0; |
| 4562 |
for (int srcIdx = 0; srcIdx < srcWidth; ++srcIdx) { |
| 4563 |
int xStep = xp; |
| 4564 |
xt += xq; |
| 4565 |
if (xt >= srcWidth) { |
| 4566 |
xt -= srcWidth; |
| 4567 |
++xStep; |
| 4568 |
} |
| 4569 |
Guchar buf = (Guchar)(255 * tmpBuf0[srcIdx]); |
| 4570 |
for (int i = 0; i < xStep; ++i) { |
| 4571 |
line[scaledIdx] = buf; |
| 4572 |
++scaledIdx; |
| 4573 |
} |
| 4574 |
} |
| 4575 |
} |
| 4576 |
|
| 4577 |
void ImageMaskScaler::vertUpscaleHorizUpscaleInterp() { |
| 4578 |
//--- vert upscale |
| 4579 |
if (ySrcCur == 0) { |
| 4580 |
(*src)(srcData, tmpBuf0); |
| 4581 |
(*src)(srcData, tmpBuf1); |
| 4582 |
ySrcCur = 1; |
| 4583 |
} |
| 4584 |
SplashCoord ys = ((SplashCoord)yScaledCur + 0.5) * yInvScale; |
| 4585 |
int y0 = splashFloor(ys - 0.5); |
| 4586 |
int y1 = y0 + 1; |
| 4587 |
SplashCoord vs0 = (SplashCoord)255 * ((SplashCoord)y1 + 0.5 - ys); |
| 4588 |
SplashCoord vs1 = (SplashCoord)255 - vs0; |
| 4589 |
if (y1 > ySrcCur && ySrcCur < srcHeight - 1) { |
| 4590 |
Guchar *t = tmpBuf0; |
| 4591 |
tmpBuf0 = tmpBuf1; |
| 4592 |
tmpBuf1 = t; |
| 4593 |
(*src)(srcData, tmpBuf1); |
| 4594 |
++ySrcCur; |
| 4595 |
} |
| 4596 |
Guchar *mask0 = tmpBuf0; |
| 4597 |
Guchar *mask1 = tmpBuf1; |
| 4598 |
if (y0 < 0) { |
| 4599 |
y0 = 0; |
| 4600 |
mask1 = mask0; |
| 4601 |
} |
| 4602 |
if (y1 >= srcHeight) { |
| 4603 |
y1 = srcHeight - 1; |
| 4604 |
mask0 = mask1; |
| 4605 |
} |
| 4606 |
++yScaledCur; |
| 4607 |
for (int srcIdx = 0; srcIdx < srcWidth; ++srcIdx) { |
| 4608 |
tmpBuf2[srcIdx] = (Guchar)(int)(vs0 * (int)mask0[srcIdx] + |
| 4609 |
vs1 * (int)mask1[srcIdx]); |
| 4610 |
} |
| 4611 |
|
| 4612 |
//--- horiz upscale |
| 4613 |
for (int scaledIdx = 0; scaledIdx < scaledWidth; ++scaledIdx) { |
| 4614 |
SplashCoord xs = ((SplashCoord)scaledIdx + 0.5) * xInvScale; |
| 4615 |
int x0 = splashFloor(xs - 0.5); |
| 4616 |
int x1 = x0 + 1; |
| 4617 |
SplashCoord hs0 = (SplashCoord)x1 + 0.5 - xs; |
| 4618 |
SplashCoord hs1 = (SplashCoord)1 - hs0; |
| 4619 |
if (x0 < 0) { |
| 4620 |
x0 = 0; |
| 4621 |
} |
| 4622 |
if (x1 >= srcWidth) { |
| 4623 |
x1 = srcWidth - 1; |
| 4624 |
} |
| 4625 |
line[scaledIdx] = (Guchar)(int)(hs0 * (int)tmpBuf2[x0] + |
| 4626 |
hs1 * (int)tmpBuf2[x1]); |
| 4627 |
} |
| 4628 |
} |
| 4629 |
|
| 4630 |
//------------------------------------------------------------------------ |
| 4631 |
// Splash |
| 4632 |
//------------------------------------------------------------------------ |
| 4633 |
|
| 4634 |
Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA, |
| 4635 |
SplashImageCache *imageCacheA, |
| 4636 |
SplashScreenParams *screenParams) { |
| 4637 |
bitmap = bitmapA; |
| 4638 |
bitmapComps = splashColorModeNComps[bitmap->mode]; |
| 4639 |
vectorAntialias = vectorAntialiasA; |
| 4640 |
state = new SplashState(bitmap->width, bitmap->height, vectorAntialias, |
| 4641 |
screenParams); |
| 4642 |
scanBuf = (Guchar *)gmalloc(bitmap->width); |
| 4643 |
if (bitmap->mode == splashModeMono1) { |
| 4644 |
scanBuf2 = (Guchar *)gmalloc(bitmap->width); |
| 4645 |
} else { |
| 4646 |
scanBuf2 = NULL; |
| 4647 |
} |
| 4648 |
parent = NULL; |
| 4649 |
deferredInit = gFalse; |
| 4650 |
alpha0Bitmap = NULL; |
| 4651 |
shapeBitmap = NULL; |
| 4652 |
overprintMaskBitmap = NULL; |
| 4653 |
minLineWidth = 0; |
| 4654 |
clearModRegion(); |
| 4655 |
debugMode = gFalse; |
| 4656 |
|
| 4657 |
if (imageCacheA) { |
| 4658 |
imageCache = imageCacheA; |
| 4659 |
imageCache->incRefCount(); |
| 4660 |
} else { |
| 4661 |
imageCache = new SplashImageCache(); |
| 4662 |
} |
| 4663 |
} |
| 4664 |
|
| 4665 |
Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA, |
| 4666 |
SplashImageCache *imageCacheA, SplashScreen *screenA) { |
| 4667 |
bitmap = bitmapA; |
| 4668 |
bitmapComps = splashColorModeNComps[bitmap->mode]; |
| 4669 |
vectorAntialias = vectorAntialiasA; |
| 4670 |
state = new SplashState(bitmap->width, bitmap->height, vectorAntialias, |
| 4671 |
screenA); |
| 4672 |
scanBuf = (Guchar *)gmalloc(bitmap->width); |
| 4673 |
if (bitmap->mode == splashModeMono1) { |
| 4674 |
scanBuf2 = (Guchar *)gmalloc(bitmap->width); |
| 4675 |
} else { |
| 4676 |
scanBuf2 = NULL; |
| 4677 |
} |
| 4678 |
parent = NULL; |
| 4679 |
deferredInit = gFalse; |
| 4680 |
alpha0Bitmap = NULL; |
| 4681 |
shapeBitmap = NULL; |
| 4682 |
overprintMaskBitmap = NULL; |
| 4683 |
minLineWidth = 0; |
| 4684 |
clearModRegion(); |
| 4685 |
debugMode = gFalse; |
| 4686 |
|
| 4687 |
if (imageCacheA) { |
| 4688 |
imageCache = imageCacheA; |
| 4689 |
imageCache->incRefCount(); |
| 4690 |
} else { |
| 4691 |
imageCache = new SplashImageCache(); |
| 4692 |
} |
| 4693 |
} |
| 4694 |
|
| 4695 |
Splash::~Splash() { |
| 4696 |
imageCache->decRefCount(); |
| 4697 |
|
| 4698 |
while (state->next) { |
| 4699 |
restoreState(); |
| 4700 |
} |
| 4701 |
delete state; |
| 4702 |
gfree(scanBuf); |
| 4703 |
gfree(scanBuf2); |
| 4704 |
} |
| 4705 |
|
| 4706 |
//------------------------------------------------------------------------ |
| 4707 |
// state read |
| 4708 |
//------------------------------------------------------------------------ |
| 4709 |
|
| 4710 |
SplashCoord *Splash::getMatrix() { |
| 4711 |
return state->matrix; |
| 4712 |
} |
| 4713 |
|
| 4714 |
SplashPattern *Splash::getStrokePattern() { |
| 4715 |
return state->strokePattern; |
| 4716 |
} |
| 4717 |
|
| 4718 |
SplashPattern *Splash::getFillPattern() { |
| 4719 |
return state->fillPattern; |
| 4720 |
} |
| 4721 |
|
| 4722 |
SplashScreen *Splash::getScreen() { |
| 4723 |
return state->screen; |
| 4724 |
} |
| 4725 |
|
| 4726 |
SplashBlendFunc Splash::getBlendFunc() { |
| 4727 |
return state->blendFunc; |
| 4728 |
} |
| 4729 |
|
| 4730 |
SplashCoord Splash::getStrokeAlpha() { |
| 4731 |
return state->strokeAlpha; |
| 4732 |
} |
| 4733 |
|
| 4734 |
SplashCoord Splash::getFillAlpha() { |
| 4735 |
return state->fillAlpha; |
| 4736 |
} |
| 4737 |
|
| 4738 |
SplashCoord Splash::getLineWidth() { |
| 4739 |
return state->lineWidth; |
| 4740 |
} |
| 4741 |
|
| 4742 |
int Splash::getLineCap() { |
| 4743 |
return state->lineCap; |
| 4744 |
} |
| 4745 |
|
| 4746 |
int Splash::getLineJoin() { |
| 4747 |
return state->lineJoin; |
| 4748 |
} |
| 4749 |
|
| 4750 |
SplashCoord Splash::getMiterLimit() { |
| 4751 |
return state->miterLimit; |
| 4752 |
} |
| 4753 |
|
| 4754 |
SplashCoord Splash::getFlatness() { |
| 4755 |
return state->flatness; |
| 4756 |
} |
| 4757 |
|
| 4758 |
SplashCoord *Splash::getLineDash() { |
| 4759 |
return state->lineDash; |
| 4760 |
} |
| 4761 |
|
| 4762 |
int Splash::getLineDashLength() { |
| 4763 |
return state->lineDashLength; |
| 4764 |
} |
| 4765 |
|
| 4766 |
SplashCoord Splash::getLineDashPhase() { |
| 4767 |
return state->lineDashPhase; |
| 4768 |
} |
| 4769 |
|
| 4770 |
SplashStrokeAdjustMode Splash::getStrokeAdjust() { |
| 4771 |
return state->strokeAdjust; |
| 4772 |
} |
| 4773 |
|
| 4774 |
SplashClip *Splash::getClip() { |
| 4775 |
return state->clip; |
| 4776 |
} |
| 4777 |
|
| 4778 |
SplashBitmap *Splash::getSoftMask() { |
| 4779 |
return state->softMask; |
| 4780 |
} |
| 4781 |
|
| 4782 |
GBool Splash::getInNonIsolatedGroup() { |
| 4783 |
return state->inNonIsolatedGroup; |
| 4784 |
} |
| 4785 |
|
| 4786 |
GBool Splash::getInKnockoutGroup() { |
| 4787 |
return state->inKnockoutGroup; |
| 4788 |
} |
| 4789 |
|
| 4790 |
//------------------------------------------------------------------------ |
| 4791 |
// state write |
| 4792 |
//------------------------------------------------------------------------ |
| 4793 |
|
| 4794 |
void Splash::setMatrix(SplashCoord *matrix) { |
| 4795 |
memcpy(state->matrix, matrix, 6 * sizeof(SplashCoord)); |
| 4796 |
} |
| 4797 |
|
| 4798 |
void Splash::setStrokePattern(SplashPattern *strokePattern) { |
| 4799 |
state->setStrokePattern(strokePattern); |
| 4800 |
} |
| 4801 |
|
| 4802 |
void Splash::setFillPattern(SplashPattern *fillPattern) { |
| 4803 |
state->setFillPattern(fillPattern); |
| 4804 |
} |
| 4805 |
|
| 4806 |
void Splash::setScreen(SplashScreen *screen) { |
| 4807 |
state->setScreen(screen); |
| 4808 |
} |
| 4809 |
|
| 4810 |
void Splash::setBlendFunc(SplashBlendFunc func) { |
| 4811 |
state->blendFunc = func; |
| 4812 |
} |
| 4813 |
|
| 4814 |
void Splash::setStrokeAlpha(SplashCoord alpha) { |
| 4815 |
state->strokeAlpha = alpha; |
| 4816 |
} |
| 4817 |
|
| 4818 |
void Splash::setFillAlpha(SplashCoord alpha) { |
| 4819 |
state->fillAlpha = alpha; |
| 4820 |
} |
| 4821 |
|
| 4822 |
void Splash::setLineWidth(SplashCoord lineWidth) { |
| 4823 |
state->lineWidth = lineWidth; |
| 4824 |
} |
| 4825 |
|
| 4826 |
void Splash::setLineCap(int lineCap) { |
| 4827 |
if (lineCap >= 0 && lineCap <= 2) { |
| 4828 |
state->lineCap = lineCap; |
| 4829 |
} else { |
| 4830 |
state->lineCap = 0; |
| 4831 |
} |
| 4832 |
} |
| 4833 |
|
| 4834 |
void Splash::setLineJoin(int lineJoin) { |
| 4835 |
if (lineJoin >= 0 && lineJoin <= 2) { |
| 4836 |
state->lineJoin = lineJoin; |
| 4837 |
} else { |
| 4838 |
state->lineJoin = 0; |
| 4839 |
} |
| 4840 |
} |
| 4841 |
|
| 4842 |
void Splash::setMiterLimit(SplashCoord miterLimit) { |
| 4843 |
state->miterLimit = miterLimit; |
| 4844 |
} |
| 4845 |
|
| 4846 |
void Splash::setFlatness(SplashCoord flatness) { |
| 4847 |
if (flatness < 1) { |
| 4848 |
state->flatness = 1; |
| 4849 |
} else { |
| 4850 |
state->flatness = flatness; |
| 4851 |
} |
| 4852 |
} |
| 4853 |
|
| 4854 |
void Splash::setLineDash(SplashCoord *lineDash, int lineDashLength, |
| 4855 |
SplashCoord lineDashPhase) { |
| 4856 |
state->setLineDash(lineDash, lineDashLength, lineDashPhase); |
| 4857 |
} |
| 4858 |
|
| 4859 |
void Splash::setStrokeAdjust(SplashStrokeAdjustMode strokeAdjust) { |
| 4860 |
state->strokeAdjust = strokeAdjust; |
| 4861 |
} |
| 4862 |
|
| 4863 |
void Splash::setAlphaIsShape(GBool alphaIsShape) { |
| 4864 |
state->alphaIsShape = alphaIsShape; |
| 4865 |
} |
| 4866 |
|
| 4867 |
void Splash::clipResetToRect(SplashCoord x0, SplashCoord y0, |
| 4868 |
SplashCoord x1, SplashCoord y1) { |
| 4869 |
state->clipResetToRect(x0, y0, x1, y1); |
| 4870 |
} |
| 4871 |
|
| 4872 |
SplashError Splash::clipToRect(SplashCoord x0, SplashCoord y0, |
| 4873 |
SplashCoord x1, SplashCoord y1) { |
| 4874 |
return state->clipToRect(x0, y0, x1, y1); |
| 4875 |
} |
| 4876 |
|
| 4877 |
SplashError Splash::clipToPath(SplashPath *path, GBool eo) { |
| 4878 |
return state->clipToPath(path, eo); |
| 4879 |
} |
| 4880 |
|
| 4881 |
void Splash::setSoftMask(SplashBitmap *softMask, GBool deleteBitmap) { |
| 4882 |
state->setSoftMask(softMask, deleteBitmap); |
| 4883 |
} |
| 4884 |
|
| 4885 |
void Splash::setInTransparencyGroup(Splash *parentA, |
| 4886 |
int parentOffsetXA, int parentOffsetYA, |
| 4887 |
SplashAlphaBitmap *alpha0BitmapA, |
| 4888 |
SplashAlphaBitmap *shapeBitmapA, |
| 4889 |
GBool nonIsolated, GBool knockout) { |
| 4890 |
parent = parentA; |
| 4891 |
parentOffsetX = parentOffsetXA; |
| 4892 |
parentOffsetY = parentOffsetYA; |
| 4893 |
deferredInit = gTrue; |
| 4894 |
deferredInitYMin = 1; |
| 4895 |
deferredInitYMax = 0; |
| 4896 |
alpha0Bitmap = alpha0BitmapA; |
| 4897 |
shapeBitmap = shapeBitmapA; |
| 4898 |
state->inNonIsolatedGroup = nonIsolated; |
| 4899 |
state->inKnockoutGroup = knockout; |
| 4900 |
} |
| 4901 |
|
| 4902 |
void Splash::forceDeferredInit(int y, int h) { |
| 4903 |
useBitmapRow(y); |
| 4904 |
useBitmapRow(y + h - 1); |
| 4905 |
} |
| 4906 |
|
| 4907 |
// Check that alpha is 0 in the specified rectangle. |
| 4908 |
// NB: This doesn't work correctly in a non-isolated group, because |
| 4909 |
// the rasterizer temporarily stores alpha_g instead of alpha. |
| 4910 |
GBool Splash::checkTransparentRect(int x, int y, int w, int h) { |
| 4911 |
if (state->inNonIsolatedGroup) { |
| 4912 |
return gFalse; |
| 4913 |
} |
| 4914 |
|
| 4915 |
|
| 4916 |
if (!bitmap->alpha) { |
| 4917 |
return gFalse; |
| 4918 |
} |
| 4919 |
int yy0, yy1; |
| 4920 |
if (deferredInit) { |
| 4921 |
// all transparency groups initialize alpha to zero, so anything |
| 4922 |
// outside of groupDestInit[YMin,YMax] will have alpha=0 |
| 4923 |
yy0 = (y > deferredInitYMin) ? y : deferredInitYMin; |
| 4924 |
yy1 = (y + h - 1 < deferredInitYMax) ? y + h - 1 : deferredInitYMax; |
| 4925 |
} else { |
| 4926 |
yy0 = y; |
| 4927 |
yy1 = y + h - 1; |
| 4928 |
} |
| 4929 |
Guchar *alphaP = &bitmap->alpha[yy0 * bitmap->alphaRowSize + x]; |
| 4930 |
for (int yy = yy0; yy <= yy1; ++yy) { |
| 4931 |
for (int xx = 0; xx < w; ++xx) { |
| 4932 |
if (alphaP[xx] != 0) { |
| 4933 |
return gFalse; |
| 4934 |
} |
| 4935 |
} |
| 4936 |
alphaP += bitmap->getAlphaRowSize(); |
| 4937 |
} |
| 4938 |
return gTrue; |
| 4939 |
} |
| 4940 |
|
| 4941 |
void Splash::setTransfer(Guchar *red, Guchar *green, Guchar *blue, |
| 4942 |
Guchar *gray) { |
| 4943 |
state->setTransfer(red, green, blue, gray); |
| 4944 |
} |
| 4945 |
|
| 4946 |
void Splash::setOverprintMask(Guint overprintMask) { |
| 4947 |
state->overprintMask = overprintMask; |
| 4948 |
} |
| 4949 |
|
| 4950 |
|
| 4951 |
void Splash::setEnablePathSimplification(GBool en) { |
| 4952 |
state->enablePathSimplification = en; |
| 4953 |
} |
| 4954 |
|
| 4955 |
//------------------------------------------------------------------------ |
| 4956 |
// state save/restore |
| 4957 |
//------------------------------------------------------------------------ |
| 4958 |
|
| 4959 |
void Splash::saveState() { |
| 4960 |
SplashState *newState; |
| 4961 |
|
| 4962 |
newState = state->copy(); |
| 4963 |
newState->next = state; |
| 4964 |
state = newState; |
| 4965 |
} |
| 4966 |
|
| 4967 |
SplashError Splash::restoreState() { |
| 4968 |
SplashState *oldState; |
| 4969 |
|
| 4970 |
if (!state->next) { |
| 4971 |
return splashErrNoSave; |
| 4972 |
} |
| 4973 |
oldState = state; |
| 4974 |
state = state->next; |
| 4975 |
delete oldState; |
| 4976 |
return splashOk; |
| 4977 |
} |
| 4978 |
|
| 4979 |
//------------------------------------------------------------------------ |
| 4980 |
// drawing operations |
| 4981 |
//------------------------------------------------------------------------ |
| 4982 |
|
| 4983 |
void Splash::clear(SplashColorPtr color, Guchar alpha) { |
| 4984 |
SplashColorPtr row, p; |
| 4985 |
Guchar mono; |
| 4986 |
int x, y; |
| 4987 |
|
| 4988 |
switch (bitmap->mode) { |
| 4989 |
case splashModeMono1: |
| 4990 |
mono = (color[0] & 0x80) ? 0xff : 0x00; |
| 4991 |
if (bitmap->rowSize < 0) { |
| 4992 |
memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), |
| 4993 |
mono, -bitmap->rowSize * bitmap->height); |
| 4994 |
} else { |
| 4995 |
memset(bitmap->data, mono, bitmap->rowSize * bitmap->height); |
| 4996 |
} |
| 4997 |
break; |
| 4998 |
case splashModeMono8: |
| 4999 |
if (bitmap->rowSize < 0) { |
| 5000 |
memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), |
| 5001 |
color[0], -bitmap->rowSize * bitmap->height); |
| 5002 |
} else { |
| 5003 |
memset(bitmap->data, color[0], bitmap->rowSize * bitmap->height); |
| 5004 |
} |
| 5005 |
break; |
| 5006 |
case splashModeRGB8: |
| 5007 |
if (color[0] == color[1] && color[1] == color[2]) { |
| 5008 |
if (bitmap->rowSize < 0) { |
| 5009 |
memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), |
| 5010 |
color[0], -bitmap->rowSize * bitmap->height); |
| 5011 |
} else { |
| 5012 |
memset(bitmap->data, color[0], bitmap->rowSize * bitmap->height); |
| 5013 |
} |
| 5014 |
} else { |
| 5015 |
row = bitmap->data; |
| 5016 |
for (y = 0; y < bitmap->height; ++y) { |
| 5017 |
p = row; |
| 5018 |
for (x = 0; x < bitmap->width; ++x) { |
| 5019 |
*p++ = color[0]; |
| 5020 |
*p++ = color[1]; |
| 5021 |
*p++ = color[2]; |
| 5022 |
} |
| 5023 |
row += bitmap->rowSize; |
| 5024 |
} |
| 5025 |
} |
| 5026 |
break; |
| 5027 |
case splashModeBGR8: |
| 5028 |
if (color[0] == color[1] && color[1] == color[2]) { |
| 5029 |
if (bitmap->rowSize < 0) { |
| 5030 |
memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), |
| 5031 |
color[0], -bitmap->rowSize * bitmap->height); |
| 5032 |
} else { |
| 5033 |
memset(bitmap->data, color[0], bitmap->rowSize * bitmap->height); |
| 5034 |
} |
| 5035 |
} else { |
| 5036 |
row = bitmap->data; |
| 5037 |
for (y = 0; y < bitmap->height; ++y) { |
| 5038 |
p = row; |
| 5039 |
for (x = 0; x < bitmap->width; ++x) { |
| 5040 |
*p++ = color[2]; |
| 5041 |
*p++ = color[1]; |
| 5042 |
*p++ = color[0]; |
| 5043 |
} |
| 5044 |
row += bitmap->rowSize; |
| 5045 |
} |
| 5046 |
} |
| 5047 |
break; |
| 5048 |
#if SPLASH_CMYK |
| 5049 |
case splashModeCMYK8: |
| 5050 |
if (color[0] == color[1] && color[1] == color[2] && color[2] == color[3]) { |
| 5051 |
if (bitmap->rowSize < 0) { |
| 5052 |
memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), |
| 5053 |
color[0], -bitmap->rowSize * bitmap->height); |
| 5054 |
} else { |
| 5055 |
memset(bitmap->data, color[0], bitmap->rowSize * bitmap->height); |
| 5056 |
} |
| 5057 |
} else { |
| 5058 |
row = bitmap->data; |
| 5059 |
for (y = 0; y < bitmap->height; ++y) { |
| 5060 |
p = row; |
| 5061 |
for (x = 0; x < bitmap->width; ++x) { |
| 5062 |
*p++ = color[0]; |
| 5063 |
*p++ = color[1]; |
| 5064 |
*p++ = color[2]; |
| 5065 |
*p++ = color[3]; |
| 5066 |
} |
| 5067 |
row += bitmap->rowSize; |
| 5068 |
} |
| 5069 |
} |
| 5070 |
break; |
| 5071 |
#endif |
| 5072 |
} |
| 5073 |
|
| 5074 |
if (bitmap->alpha) { |
| 5075 |
memset(bitmap->alpha, alpha, bitmap->alphaRowSize * bitmap->height); |
| 5076 |
} |
| 5077 |
|
| 5078 |
updateModX(0); |
| 5079 |
updateModY(0); |
| 5080 |
updateModX(bitmap->width - 1); |
| 5081 |
updateModY(bitmap->height - 1); |
| 5082 |
} |
| 5083 |
|
| 5084 |
SplashError Splash::stroke(SplashPath *path) { |
| 5085 |
SplashPath *path2, *dPath; |
| 5086 |
SplashCoord w, w2, lineDashMax, lineDashTotal; |
| 5087 |
int lineCap, lineJoin, i; |
| 5088 |
|
| 5089 |
if (debugMode) { |
| 5090 |
printf("stroke [dash:%d] [width:%.2f]:\n", |
| 5091 |
state->lineDashLength, (double)state->lineWidth); |
| 5092 |
dumpPath(path); |
| 5093 |
} |
| 5094 |
opClipRes = splashClipAllOutside; |
| 5095 |
if (path->length == 0) { |
| 5096 |
return splashErrEmptyPath; |
| 5097 |
} |
| 5098 |
if (pathAllOutside(path, gTrue)) { |
| 5099 |
return splashOk; |
| 5100 |
} |
| 5101 |
path2 = flattenPath(path, state->matrix, state->flatness); |
| 5102 |
|
| 5103 |
// Compute an approximation of the transformed line width. |
| 5104 |
// Given a CTM of [m0 m1], |
| 5105 |
// [m2 m3] |
| 5106 |
// if |m0|*|m3| >= |m1|*|m2| then use min{|m0|,|m3|}, else |
| 5107 |
// use min{|m1|,|m2|}. |
| 5108 |
// This handles the common cases -- [s 0 ] and [0 s] -- |
| 5109 |
// [0 +/-s] [+/-s 0] |
| 5110 |
// well, and still does something reasonable for the uncommon |
| 5111 |
// case transforms. |
| 5112 |
double t0 = splashAbs(state->matrix[0]); |
| 5113 |
double t1 = splashAbs(state->matrix[1]); |
| 5114 |
double t2 = splashAbs(state->matrix[2]); |
| 5115 |
double t3 = splashAbs(state->matrix[3]); |
| 5116 |
double t01 = t0 * t0 + t1 * t1; |
| 5117 |
double t23 = t2 * t2 + t3 * t3; |
| 5118 |
w = sqrt((t01 > t23) ? t01 : t23); |
| 5119 |
w2 = w * state->lineWidth; |
| 5120 |
|
| 5121 |
// construct the dashed path |
| 5122 |
if (state->lineDashLength > 0) { |
| 5123 |
|
| 5124 |
// check the maximum transformed dash element length (using the |
| 5125 |
// same approximation as for line width) -- if it's less than 0.1 |
| 5126 |
// pixel, don't apply the dash pattern; this avoids a huge |
| 5127 |
// performance/memory hit with PDF files that use absurd dash |
| 5128 |
// patterns like [0.0007 0.0003] |
| 5129 |
// |
| 5130 |
// we also skip the dash pattern for very long paths with short |
| 5131 |
// (but not necessarily sub-pixel) dash patterns -- Adobe appears |
| 5132 |
// to do something similar |
| 5133 |
lineDashTotal = 0; |
| 5134 |
lineDashMax = 0; |
| 5135 |
for (i = 0; i < state->lineDashLength; ++i) { |
| 5136 |
lineDashTotal += state->lineDash[i]; |
| 5137 |
if (state->lineDash[i] > lineDashMax) { |
| 5138 |
lineDashMax = state->lineDash[i]; |
| 5139 |
} |
| 5140 |
} |
| 5141 |
// Acrobat simply draws nothing if the dash array is [0] |
| 5142 |
if (lineDashTotal == 0) { |
| 5143 |
delete path2; |
| 5144 |
return splashOk; |
| 5145 |
} |
| 5146 |
if (w * lineDashMax > 0.1 && |
| 5147 |
w * lineDashMax > 0.0001 * path->length) { |
| 5148 |
dPath = makeDashedPath(path2); |
| 5149 |
delete path2; |
| 5150 |
path2 = dPath; |
| 5151 |
if (path2->length == 0) { |
| 5152 |
delete path2; |
| 5153 |
return splashErrEmptyPath; |
| 5154 |
} |
| 5155 |
} |
| 5156 |
} |
| 5157 |
|
| 5158 |
// round caps on narrow lines look bad, and can't be |
| 5159 |
// stroke-adjusted, so use projecting caps instead (but we can't do |
| 5160 |
// this if there are zero-length dashes or segments, because those |
| 5161 |
// turn into round dots) |
| 5162 |
lineCap = state->lineCap; |
| 5163 |
lineJoin = state->lineJoin; |
| 5164 |
if (state->strokeAdjust == splashStrokeAdjustCAD && |
| 5165 |
w2 < 3.5) { |
| 5166 |
if (lineCap == splashLineCapRound && |
| 5167 |
!state->lineDashContainsZeroLengthDashes() && |
| 5168 |
!path->containsZeroLengthSubpaths()) { |
| 5169 |
lineCap = splashLineCapProjecting; |
| 5170 |
} |
| 5171 |
if (lineJoin == splashLineJoinRound) { |
| 5172 |
lineJoin = splashLineJoinBevel; |
| 5173 |
} |
| 5174 |
} |
| 5175 |
|
| 5176 |
// if there is a min line width set, and the transformed line width |
| 5177 |
// is smaller, use the min line width |
| 5178 |
if (w > 0 && w2 < minLineWidth) { |
| 5179 |
strokeWide(path2, minLineWidth / w, splashLineCapButt, splashLineJoinBevel); |
| 5180 |
} else if (bitmap->mode == splashModeMono1 || !vectorAntialias) { |
| 5181 |
// in monochrome mode or if antialiasing is disabled, use 0-width |
| 5182 |
// lines for any transformed line width <= 1 -- lines less than 1 |
| 5183 |
// pixel wide look too fat without antialiasing |
| 5184 |
if (w2 < 1.001) { |
| 5185 |
strokeNarrow(path2); |
| 5186 |
} else { |
| 5187 |
strokeWide(path2, state->lineWidth, lineCap, lineJoin); |
| 5188 |
} |
| 5189 |
} else { |
| 5190 |
// in gray and color modes, only use 0-width lines if the line |
| 5191 |
// width is explicitly set to 0 |
| 5192 |
if (state->lineWidth == 0) { |
| 5193 |
strokeNarrow(path2); |
| 5194 |
} else { |
| 5195 |
strokeWide(path2, state->lineWidth, lineCap, lineJoin); |
| 5196 |
} |
| 5197 |
} |
| 5198 |
|
| 5199 |
delete path2; |
| 5200 |
return splashOk; |
| 5201 |
} |
| 5202 |
|
| 5203 |
void Splash::strokeNarrow(SplashPath *path) { |
| 5204 |
SplashPipe pipe; |
| 5205 |
SplashXPath *xPath; |
| 5206 |
SplashXPathSeg *seg; |
| 5207 |
int x0, x1, y0, y1, xa, xb, y; |
| 5208 |
SplashCoord dxdy; |
| 5209 |
SplashClipResult clipRes; |
| 5210 |
int nClipRes[3]; |
| 5211 |
int i; |
| 5212 |
|
| 5213 |
nClipRes[0] = nClipRes[1] = nClipRes[2] = 0; |
| 5214 |
|
| 5215 |
xPath = new SplashXPath(path, state->matrix, state->flatness, gFalse, |
| 5216 |
state->enablePathSimplification, |
| 5217 |
state->strokeAdjust, state->clip); |
| 5218 |
|
| 5219 |
pipeInit(&pipe, state->strokePattern, |
| 5220 |
(Guchar)splashRound(state->strokeAlpha * 255), |
| 5221 |
gFalse, gTrue, gFalse); |
| 5222 |
|
| 5223 |
for (i = 0, seg = xPath->segs; i < xPath->length; ++i, ++seg) { |
| 5224 |
if (seg->y0 <= seg->y1) { |
| 5225 |
y0 = splashFloor(seg->y0); |
| 5226 |
y1 = splashFloor(seg->y1); |
| 5227 |
x0 = splashFloor(seg->x0); |
| 5228 |
x1 = splashFloor(seg->x1); |
| 5229 |
} else { |
| 5230 |
y0 = splashFloor(seg->y1); |
| 5231 |
y1 = splashFloor(seg->y0); |
| 5232 |
x0 = splashFloor(seg->x1); |
| 5233 |
x1 = splashFloor(seg->x0); |
| 5234 |
} |
| 5235 |
|
| 5236 |
// With CAD-mode stroke adjustment, and a simple rectangular clip |
| 5237 |
// region, horizontal and vertical stroke-adjusted edges that fall |
| 5238 |
// slightly outside the clip region are adjusted back inside the |
| 5239 |
// clip region. This avoids problems with narrow lines in |
| 5240 |
// slightly mismatched clip rectangles, which appear to be |
| 5241 |
// generated somewhat commonly by buggy CAD software. This is |
| 5242 |
// similar to the code in SplashXPath::strokeAdjust() -- narrow |
| 5243 |
// strokes aren't stroke-adjusted, so this tweak has to be done |
| 5244 |
// here. |
| 5245 |
if (y0 == y1 && |
| 5246 |
seg->y0 == seg->y1 && |
| 5247 |
state->clip->getIsSimple() && |
| 5248 |
state->strokeAdjust == splashStrokeAdjustCAD) { |
| 5249 |
SplashCoord cy0 = state->clip->getYMin(); |
| 5250 |
SplashCoord cy1 = state->clip->getYMax(); |
| 5251 |
int cyi0 = state->clip->getYMinI(state->strokeAdjust); |
| 5252 |
int cyi1 = state->clip->getYMaxI(state->strokeAdjust); |
| 5253 |
if (y0 == cyi0 - 1 && cy0 - seg->y0 < 0.5) { |
| 5254 |
y0 = y1 = y0 + 1; |
| 5255 |
} else if (y0 == cyi1 + 1 && seg->y0 - cy1 < 0.5) { |
| 5256 |
y0 = y1 = y0 - 1; |
| 5257 |
} |
| 5258 |
} else if (x0 == x1 && |
| 5259 |
seg->x0 == seg->x1 && |
| 5260 |
state->clip->getIsSimple() && |
| 5261 |
state->strokeAdjust == splashStrokeAdjustCAD) { |
| 5262 |
SplashCoord cx0 = state->clip->getXMin(); |
| 5263 |
SplashCoord cx1 = state->clip->getXMax(); |
| 5264 |
int cxi0 = state->clip->getXMinI(state->strokeAdjust); |
| 5265 |
int cxi1 = state->clip->getXMaxI(state->strokeAdjust); |
| 5266 |
if (x0 == cxi0 - 1 && cx0 - seg->x0 < 0.5) { |
| 5267 |
x0 = x1 = x0 + 1; |
| 5268 |
} else if (x0 == cxi1 + 1 && seg->x0 - cx1 < 0.5) { |
| 5269 |
x0 = x1 = x0 - 1; |
| 5270 |
} |
| 5271 |
} |
| 5272 |
|
| 5273 |
if ((clipRes = state->clip->testRect(x0 <= x1 ? x0 : x1, y0, |
| 5274 |
x0 <= x1 ? x1 : x0, y1, |
| 5275 |
state->strokeAdjust)) |
| 5276 |
!= splashClipAllOutside) { |
| 5277 |
if (y0 == y1) { |
| 5278 |
if (x0 <= x1) { |
| 5279 |
drawStrokeSpan(&pipe, x0, x1, y0, clipRes == splashClipAllInside); |
| 5280 |
} else { |
| 5281 |
drawStrokeSpan(&pipe, x1, x0, y0, clipRes == splashClipAllInside); |
| 5282 |
} |
| 5283 |
} else if (x0 == x1) { |
| 5284 |
y = state->clip->getYMinI(state->strokeAdjust); |
| 5285 |
if (y0 < y) { |
| 5286 |
y0 = y; |
| 5287 |
} |
| 5288 |
y = state->clip->getYMaxI(state->strokeAdjust); |
| 5289 |
if (y1 > y) { |
| 5290 |
y1 = y; |
| 5291 |
} |
| 5292 |
for (y = y0; y <= y1; ++y) { |
| 5293 |
drawStrokeSpan(&pipe, x0, x0, y, clipRes == splashClipAllInside); |
| 5294 |
} |
| 5295 |
} else { |
| 5296 |
dxdy = seg->dxdy; |
| 5297 |
y = state->clip->getYMinI(state->strokeAdjust); |
| 5298 |
if (y0 < y) { |
| 5299 |
y0 = y; |
| 5300 |
x0 = splashFloor(seg->x0 + ((SplashCoord)y0 - seg->y0) * dxdy); |
| 5301 |
} |
| 5302 |
y = state->clip->getYMaxI(state->strokeAdjust); |
| 5303 |
if (y1 > y) { |
| 5304 |
y1 = y; |
| 5305 |
x1 = splashFloor(seg->x0 + ((SplashCoord)y1 + 1 - seg->y0) * dxdy); |
| 5306 |
} |
| 5307 |
if (x0 <= x1) { |
| 5308 |
xa = x0; |
| 5309 |
for (y = y0; y <= y1; ++y) { |
| 5310 |
if (y < y1) { |
| 5311 |
xb = splashFloor(seg->x0 + |
| 5312 |
((SplashCoord)y + 1 - seg->y0) * dxdy); |
| 5313 |
} else { |
| 5314 |
xb = x1 + 1; |
| 5315 |
} |
| 5316 |
if (xa == xb) { |
| 5317 |
drawStrokeSpan(&pipe, xa, xa, y, clipRes == splashClipAllInside); |
| 5318 |
} else { |
| 5319 |
drawStrokeSpan(&pipe, xa, xb - 1, y, |
| 5320 |
clipRes == splashClipAllInside); |
| 5321 |
} |
| 5322 |
xa = xb; |
| 5323 |
} |
| 5324 |
} else { |
| 5325 |
xa = x0; |
| 5326 |
for (y = y0; y <= y1; ++y) { |
| 5327 |
if (y < y1) { |
| 5328 |
xb = splashFloor(seg->x0 + |
| 5329 |
((SplashCoord)y + 1 - seg->y0) * dxdy); |
| 5330 |
} else { |
| 5331 |
xb = x1 - 1; |
| 5332 |
} |
| 5333 |
if (xa == xb) { |
| 5334 |
drawStrokeSpan(&pipe, xa, xa, y, clipRes == splashClipAllInside); |
| 5335 |
} else { |
| 5336 |
drawStrokeSpan(&pipe, xb + 1, xa, y, |
| 5337 |
clipRes == splashClipAllInside); |
| 5338 |
} |
| 5339 |
xa = xb; |
| 5340 |
} |
| 5341 |
} |
| 5342 |
} |
| 5343 |
} |
| 5344 |
++nClipRes[clipRes]; |
| 5345 |
} |
| 5346 |
|
| 5347 |
if (nClipRes[splashClipPartial] || |
| 5348 |
(nClipRes[splashClipAllInside] && nClipRes[splashClipAllOutside])) { |
| 5349 |
opClipRes = splashClipPartial; |
| 5350 |
} else if (nClipRes[splashClipAllInside]) { |
| 5351 |
opClipRes = splashClipAllInside; |
| 5352 |
} else { |
| 5353 |
opClipRes = splashClipAllOutside; |
| 5354 |
} |
| 5355 |
|
| 5356 |
delete xPath; |
| 5357 |
} |
| 5358 |
|
| 5359 |
void Splash::drawStrokeSpan(SplashPipe *pipe, int x0, int x1, int y, |
| 5360 |
GBool noClip) { |
| 5361 |
int x; |
| 5362 |
|
| 5363 |
x = state->clip->getXMinI(state->strokeAdjust); |
| 5364 |
if (x > x0) { |
| 5365 |
x0 = x; |
| 5366 |
} |
| 5367 |
x = state->clip->getXMaxI(state->strokeAdjust); |
| 5368 |
if (x < x1) { |
| 5369 |
x1 = x; |
| 5370 |
} |
| 5371 |
if (x0 > x1) { |
| 5372 |
return; |
| 5373 |
} |
| 5374 |
for (x = x0; x <= x1; ++x) { |
| 5375 |
scanBuf[x] = 0xff; |
| 5376 |
} |
| 5377 |
if (!noClip) { |
| 5378 |
if (!state->clip->clipSpanBinary(scanBuf, y, x0, x1, state->strokeAdjust)) { |
| 5379 |
return; |
| 5380 |
} |
| 5381 |
} |
| 5382 |
(this->*pipe->run)(pipe, x0, x1, y, scanBuf + x0, scanBuf + x0, NULL); |
| 5383 |
} |
| 5384 |
|
| 5385 |
void Splash::strokeWide(SplashPath *path, SplashCoord w, |
| 5386 |
int lineCap, int lineJoin) { |
| 5387 |
SplashPath *path2; |
| 5388 |
|
| 5389 |
path2 = makeStrokePath(path, w, lineCap, lineJoin, gFalse); |
| 5390 |
fillWithPattern(path2, gFalse, state->strokePattern, state->strokeAlpha); |
| 5391 |
delete path2; |
| 5392 |
} |
| 5393 |
|
| 5394 |
SplashPath *Splash::flattenPath(SplashPath *path, SplashCoord *matrix, |
| 5395 |
SplashCoord flatness) { |
| 5396 |
SplashPath *fPath; |
| 5397 |
SplashCoord flatness2; |
| 5398 |
Guchar flag; |
| 5399 |
int i; |
| 5400 |
|
| 5401 |
fPath = new SplashPath(); |
| 5402 |
#if USE_FIXEDPOINT |
| 5403 |
flatness2 = flatness; |
| 5404 |
#else |
| 5405 |
flatness2 = flatness * flatness; |
| 5406 |
#endif |
| 5407 |
i = 0; |
| 5408 |
while (i < path->length) { |
| 5409 |
flag = path->flags[i]; |
| 5410 |
if (flag & splashPathFirst) { |
| 5411 |
fPath->moveTo(path->pts[i].x, path->pts[i].y); |
| 5412 |
++i; |
| 5413 |
} else { |
| 5414 |
if (flag & splashPathCurve) { |
| 5415 |
flattenCurve(path->pts[i-1].x, path->pts[i-1].y, |
| 5416 |
path->pts[i ].x, path->pts[i ].y, |
| 5417 |
path->pts[i+1].x, path->pts[i+1].y, |
| 5418 |
path->pts[i+2].x, path->pts[i+2].y, |
| 5419 |
matrix, flatness2, fPath); |
| 5420 |
i += 3; |
| 5421 |
} else { |
| 5422 |
fPath->lineTo(path->pts[i].x, path->pts[i].y); |
| 5423 |
++i; |
| 5424 |
} |
| 5425 |
if (path->flags[i-1] & splashPathClosed) { |
| 5426 |
fPath->close(); |
| 5427 |
} |
| 5428 |
} |
| 5429 |
} |
| 5430 |
return fPath; |
| 5431 |
} |
| 5432 |
|
| 5433 |
void Splash::flattenCurve(SplashCoord x0, SplashCoord y0, |
| 5434 |
SplashCoord x1, SplashCoord y1, |
| 5435 |
SplashCoord x2, SplashCoord y2, |
| 5436 |
SplashCoord x3, SplashCoord y3, |
| 5437 |
SplashCoord *matrix, SplashCoord flatness2, |
| 5438 |
SplashPath *fPath) { |
| 5439 |
SplashCoord cx[splashMaxCurveSplits + 1][3]; |
| 5440 |
SplashCoord cy[splashMaxCurveSplits + 1][3]; |
| 5441 |
int cNext[splashMaxCurveSplits + 1]; |
| 5442 |
SplashCoord xl0, xl1, xl2, xr0, xr1, xr2, xr3, xx1, xx2, xh; |
| 5443 |
SplashCoord yl0, yl1, yl2, yr0, yr1, yr2, yr3, yy1, yy2, yh; |
| 5444 |
SplashCoord dx, dy, mx, my, tx, ty, d1, d2; |
| 5445 |
int p1, p2, p3; |
| 5446 |
|
| 5447 |
// initial segment |
| 5448 |
p1 = 0; |
| 5449 |
p2 = splashMaxCurveSplits; |
| 5450 |
cx[p1][0] = x0; cy[p1][0] = y0; |
| 5451 |
cx[p1][1] = x1; cy[p1][1] = y1; |
| 5452 |
cx[p1][2] = x2; cy[p1][2] = y2; |
| 5453 |
cx[p2][0] = x3; cy[p2][0] = y3; |
| 5454 |
cNext[p1] = p2; |
| 5455 |
|
| 5456 |
while (p1 < splashMaxCurveSplits) { |
| 5457 |
|
| 5458 |
// get the next segment |
| 5459 |
xl0 = cx[p1][0]; yl0 = cy[p1][0]; |
| 5460 |
xx1 = cx[p1][1]; yy1 = cy[p1][1]; |
| 5461 |
xx2 = cx[p1][2]; yy2 = cy[p1][2]; |
| 5462 |
p2 = cNext[p1]; |
| 5463 |
xr3 = cx[p2][0]; yr3 = cy[p2][0]; |
| 5464 |
|
| 5465 |
// compute the distances (in device space) from the control points |
| 5466 |
// to the midpoint of the straight line (this is a bit of a hack, |
| 5467 |
// but it's much faster than computing the actual distances to the |
| 5468 |
// line) |
| 5469 |
transform(matrix, (xl0 + xr3) * 0.5, (yl0 + yr3) * 0.5, &mx, &my); |
| 5470 |
transform(matrix, xx1, yy1, &tx, &ty); |
| 5471 |
#if USE_FIXEDPOINT |
| 5472 |
d1 = splashDist(tx, ty, mx, my); |
| 5473 |
#else |
| 5474 |
dx = tx - mx; |
| 5475 |
dy = ty - my; |
| 5476 |
d1 = dx*dx + dy*dy; |
| 5477 |
#endif |
| 5478 |
transform(matrix, xx2, yy2, &tx, &ty); |
| 5479 |
#if USE_FIXEDPOINT |
| 5480 |
d2 = splashDist(tx, ty, mx, my); |
| 5481 |
#else |
| 5482 |
dx = tx - mx; |
| 5483 |
dy = ty - my; |
| 5484 |
d2 = dx*dx + dy*dy; |
| 5485 |
#endif |
| 5486 |
|
| 5487 |
// if the curve is flat enough, or no more subdivisions are |
| 5488 |
// allowed, add the straight line segment |
| 5489 |
if (p2 - p1 == 1 || (d1 <= flatness2 && d2 <= flatness2)) { |
| 5490 |
fPath->lineTo(xr3, yr3); |
| 5491 |
p1 = p2; |
| 5492 |
|
| 5493 |
// otherwise, subdivide the curve |
| 5494 |
} else { |
| 5495 |
xl1 = splashAvg(xl0, xx1); |
| 5496 |
yl1 = splashAvg(yl0, yy1); |
| 5497 |
xh = splashAvg(xx1, xx2); |
| 5498 |
yh = splashAvg(yy1, yy2); |
| 5499 |
xl2 = splashAvg(xl1, xh); |
| 5500 |
yl2 = splashAvg(yl1, yh); |
| 5501 |
xr2 = splashAvg(xx2, xr3); |
| 5502 |
yr2 = splashAvg(yy2, yr3); |
| 5503 |
xr1 = splashAvg(xh, xr2); |
| 5504 |
yr1 = splashAvg(yh, yr2); |
| 5505 |
xr0 = splashAvg(xl2, xr1); |
| 5506 |
yr0 = splashAvg(yl2, yr1); |
| 5507 |
// add the new subdivision points |
| 5508 |
p3 = (p1 + p2) / 2; |
| 5509 |
cx[p1][1] = xl1; cy[p1][1] = yl1; |
| 5510 |
cx[p1][2] = xl2; cy[p1][2] = yl2; |
| 5511 |
cNext[p1] = p3; |
| 5512 |
cx[p3][0] = xr0; cy[p3][0] = yr0; |
| 5513 |
cx[p3][1] = xr1; cy[p3][1] = yr1; |
| 5514 |
cx[p3][2] = xr2; cy[p3][2] = yr2; |
| 5515 |
cNext[p3] = p2; |
| 5516 |
} |
| 5517 |
} |
| 5518 |
} |
| 5519 |
|
| 5520 |
SplashPath *Splash::makeDashedPath(SplashPath *path) { |
| 5521 |
SplashPath *dPath; |
| 5522 |
SplashCoord lineDashTotal; |
| 5523 |
SplashCoord lineDashStartPhase, lineDashDist, segLen; |
| 5524 |
SplashCoord x0, y0, x1, y1, xa, ya; |
| 5525 |
GBool lineDashStartOn, lineDashEndOn, lineDashOn, newPath; |
| 5526 |
int lineDashStartIdx, lineDashIdx, subpathStart, nDashes; |
| 5527 |
int i, j, k; |
| 5528 |
|
| 5529 |
lineDashTotal = 0; |
| 5530 |
for (i = 0; i < state->lineDashLength; ++i) { |
| 5531 |
lineDashTotal += state->lineDash[i]; |
| 5532 |
} |
| 5533 |
// Acrobat simply draws nothing if the dash array is [0] |
| 5534 |
if (lineDashTotal == 0) { |
| 5535 |
return new SplashPath(); |
| 5536 |
} |
| 5537 |
lineDashStartPhase = state->lineDashPhase; |
| 5538 |
if (lineDashStartPhase > 0) { |
| 5539 |
i = splashFloor(lineDashStartPhase / lineDashTotal); |
| 5540 |
lineDashStartPhase -= lineDashTotal * i; |
| 5541 |
} else { |
| 5542 |
i = splashCeil(-lineDashStartPhase / lineDashTotal); |
| 5543 |
lineDashStartPhase += lineDashTotal * i; |
| 5544 |
} |
| 5545 |
lineDashStartOn = !((state->lineDashLength & 1) && (i & 1)); |
| 5546 |
lineDashStartIdx = 0; |
| 5547 |
if (lineDashStartPhase > 0) { |
| 5548 |
while (lineDashStartPhase >= state->lineDash[lineDashStartIdx]) { |
| 5549 |
lineDashStartOn = !lineDashStartOn; |
| 5550 |
lineDashStartPhase -= state->lineDash[lineDashStartIdx]; |
| 5551 |
if (++lineDashStartIdx == state->lineDashLength) { |
| 5552 |
lineDashStartIdx = 0; |
| 5553 |
} |
| 5554 |
} |
| 5555 |
} |
| 5556 |
|
| 5557 |
dPath = new SplashPath(); |
| 5558 |
|
| 5559 |
// process each subpath |
| 5560 |
i = 0; |
| 5561 |
while (i < path->length) { |
| 5562 |
|
| 5563 |
// find the end of the subpath |
| 5564 |
for (j = i; |
| 5565 |
j < path->length - 1 && !(path->flags[j] & splashPathLast); |
| 5566 |
++j) ; |
| 5567 |
|
| 5568 |
// initialize the dash parameters |
| 5569 |
lineDashOn = lineDashStartOn; |
| 5570 |
lineDashEndOn = lineDashStartOn; |
| 5571 |
lineDashIdx = lineDashStartIdx; |
| 5572 |
lineDashDist = state->lineDash[lineDashIdx] - lineDashStartPhase; |
| 5573 |
subpathStart = dPath->length; |
| 5574 |
nDashes = 0; |
| 5575 |
|
| 5576 |
// process each segment of the subpath |
| 5577 |
newPath = gTrue; |
| 5578 |
for (k = i; k < j; ++k) { |
| 5579 |
|
| 5580 |
// grab the segment |
| 5581 |
x0 = path->pts[k].x; |
| 5582 |
y0 = path->pts[k].y; |
| 5583 |
x1 = path->pts[k+1].x; |
| 5584 |
y1 = path->pts[k+1].y; |
| 5585 |
segLen = splashDist(x0, y0, x1, y1); |
| 5586 |
|
| 5587 |
// Special case for zero-length subpath: copy the zero-length |
| 5588 |
// segment into the dashed path so that the round line cap |
| 5589 |
// special case is handled. |
| 5590 |
if (j == i+1 && segLen == 0) { |
| 5591 |
dPath->moveTo(x0, y0); |
| 5592 |
dPath->lineTo(x0, y0); |
| 5593 |
} |
| 5594 |
|
| 5595 |
// process the segment |
| 5596 |
while (segLen > 0) { |
| 5597 |
|
| 5598 |
// Special case for zero-length dash segments: draw a very |
| 5599 |
// short -- but not zero-length -- segment. This ensures that |
| 5600 |
// we get the correct behavior with butt and projecting line |
| 5601 |
// caps. The PS/PDF specs imply that zero-length segments are |
| 5602 |
// not drawn unless the line cap is round, but Acrobat and |
| 5603 |
// Ghostscript both draw very short segments (for butt caps) |
| 5604 |
// and squares (for projecting caps). |
| 5605 |
if (lineDashDist == 0) { |
| 5606 |
if (lineDashOn) { |
| 5607 |
if (newPath) { |
| 5608 |
dPath->moveTo(x0, y0); |
| 5609 |
newPath = gFalse; |
| 5610 |
++nDashes; |
| 5611 |
} |
| 5612 |
xa = x0 + ((SplashCoord)0.001 / segLen) * (x1 - x0); |
| 5613 |
ya = y0 + ((SplashCoord)0.001 / segLen) * (y1 - y0); |
| 5614 |
dPath->lineTo(xa, ya); |
| 5615 |
} |
| 5616 |
|
| 5617 |
} else if (lineDashDist >= segLen) { |
| 5618 |
if (lineDashOn) { |
| 5619 |
if (newPath) { |
| 5620 |
dPath->moveTo(x0, y0); |
| 5621 |
newPath = gFalse; |
| 5622 |
++nDashes; |
| 5623 |
} |
| 5624 |
dPath->lineTo(x1, y1); |
| 5625 |
} |
| 5626 |
lineDashDist -= segLen; |
| 5627 |
segLen = 0; |
| 5628 |
|
| 5629 |
} else { |
| 5630 |
xa = x0 + (lineDashDist / segLen) * (x1 - x0); |
| 5631 |
ya = y0 + (lineDashDist / segLen) * (y1 - y0); |
| 5632 |
if (lineDashOn) { |
| 5633 |
if (newPath) { |
| 5634 |
dPath->moveTo(x0, y0); |
| 5635 |
newPath = gFalse; |
| 5636 |
++nDashes; |
| 5637 |
} |
| 5638 |
dPath->lineTo(xa, ya); |
| 5639 |
} |
| 5640 |
x0 = xa; |
| 5641 |
y0 = ya; |
| 5642 |
segLen -= lineDashDist; |
| 5643 |
lineDashDist = 0; |
| 5644 |
} |
| 5645 |
|
| 5646 |
lineDashEndOn = lineDashOn; |
| 5647 |
|
| 5648 |
// get the next entry in the dash array |
| 5649 |
if (lineDashDist <= 0) { |
| 5650 |
lineDashOn = !lineDashOn; |
| 5651 |
if (++lineDashIdx == state->lineDashLength) { |
| 5652 |
lineDashIdx = 0; |
| 5653 |
} |
| 5654 |
lineDashDist = state->lineDash[lineDashIdx]; |
| 5655 |
newPath = gTrue; |
| 5656 |
} |
| 5657 |
} |
| 5658 |
} |
| 5659 |
|
| 5660 |
// in a closed subpath, where the dash pattern is "on" at both the |
| 5661 |
// start and end of the subpath, we need to merge the start and |
| 5662 |
// end to get a proper line join |
| 5663 |
if ((path->flags[j] & splashPathClosed) && |
| 5664 |
lineDashStartOn && |
| 5665 |
lineDashEndOn) { |
| 5666 |
if (nDashes == 1) { |
| 5667 |
dPath->close(); |
| 5668 |
} else if (nDashes > 1) { |
| 5669 |
k = subpathStart; |
| 5670 |
do { |
| 5671 |
++k; |
| 5672 |
dPath->lineTo(dPath->pts[k].x, dPath->pts[k].y); |
| 5673 |
} while (!(dPath->flags[k] & splashPathLast)); |
| 5674 |
++k; |
| 5675 |
memmove(&dPath->pts[subpathStart], &dPath->pts[k], |
| 5676 |
(dPath->length - k) * sizeof(SplashPathPoint)); |
| 5677 |
memmove(&dPath->flags[subpathStart], &dPath->flags[k], |
| 5678 |
(dPath->length - k) * sizeof(Guchar)); |
| 5679 |
dPath->length -= k - subpathStart; |
| 5680 |
dPath->curSubpath -= k - subpathStart; |
| 5681 |
} |
| 5682 |
} |
| 5683 |
|
| 5684 |
i = j + 1; |
| 5685 |
} |
| 5686 |
|
| 5687 |
return dPath; |
| 5688 |
} |
| 5689 |
|
| 5690 |
SplashError Splash::fill(SplashPath *path, GBool eo) { |
| 5691 |
if (debugMode) { |
| 5692 |
printf("fill [eo:%d]:\n", eo); |
| 5693 |
dumpPath(path); |
| 5694 |
} |
| 5695 |
if (path->length == 0) { |
| 5696 |
return splashErrEmptyPath; |
| 5697 |
} |
| 5698 |
if (pathAllOutside(path, gFalse)) { |
| 5699 |
opClipRes = splashClipAllOutside; |
| 5700 |
return splashOk; |
| 5701 |
} |
| 5702 |
return fillWithPattern(path, eo, state->fillPattern, state->fillAlpha); |
| 5703 |
} |
| 5704 |
|
| 5705 |
SplashError Splash::fillWithPattern(SplashPath *path, GBool eo, |
| 5706 |
SplashPattern *pattern, |
| 5707 |
SplashCoord alpha) { |
| 5708 |
SplashPipe pipe; |
| 5709 |
SplashPath *path2; |
| 5710 |
SplashXPath *xPath; |
| 5711 |
SplashXPathScanner *scanner; |
| 5712 |
int xMin, yMin, xMax, xMin2, xMax2, yMax, y, t; |
| 5713 |
SplashClipResult clipRes; |
| 5714 |
|
| 5715 |
path2 = tweakFillPath(path); |
| 5716 |
|
| 5717 |
xPath = new SplashXPath(path2, state->matrix, state->flatness, gTrue, |
| 5718 |
state->enablePathSimplification, |
| 5719 |
state->strokeAdjust, state->clip); |
| 5720 |
if (path2 != path) { |
| 5721 |
delete path2; |
| 5722 |
} |
| 5723 |
xMin = xPath->getXMin(); |
| 5724 |
yMin = xPath->getYMin(); |
| 5725 |
xMax = xPath->getXMax(); |
| 5726 |
yMax = xPath->getYMax(); |
| 5727 |
if (xMin > xMax || yMin > yMax) { |
| 5728 |
delete xPath; |
| 5729 |
return splashOk; |
| 5730 |
} |
| 5731 |
scanner = new SplashXPathScanner(xPath, eo, yMin, yMax); |
| 5732 |
|
| 5733 |
// check clipping |
| 5734 |
if ((clipRes = state->clip->testRect(xMin, yMin, xMax, yMax, |
| 5735 |
state->strokeAdjust)) |
| 5736 |
!= splashClipAllOutside) { |
| 5737 |
|
| 5738 |
if ((t = state->clip->getXMinI(state->strokeAdjust)) > xMin) { |
| 5739 |
xMin = t; |
| 5740 |
} |
| 5741 |
if ((t = state->clip->getXMaxI(state->strokeAdjust)) < xMax) { |
| 5742 |
xMax = t; |
| 5743 |
} |
| 5744 |
if ((t = state->clip->getYMinI(state->strokeAdjust)) > yMin) { |
| 5745 |
yMin = t; |
| 5746 |
} |
| 5747 |
if ((t = state->clip->getYMaxI(state->strokeAdjust)) < yMax) { |
| 5748 |
yMax = t; |
| 5749 |
} |
| 5750 |
if (xMin > xMax || yMin > yMax) { |
| 5751 |
delete scanner; |
| 5752 |
delete xPath; |
| 5753 |
return splashOk; |
| 5754 |
} |
| 5755 |
|
| 5756 |
pipeInit(&pipe, pattern, (Guchar)splashRound(alpha * 255), |
| 5757 |
gFalse, gTrue, gFalse); |
| 5758 |
|
| 5759 |
// draw the spans |
| 5760 |
if (vectorAntialias) { |
| 5761 |
for (y = yMin; y <= yMax; ++y) { |
| 5762 |
scanner->getSpan(scanBuf, y, xMin, xMax, &xMin2, &xMax2); |
| 5763 |
if (xMin2 <= xMax2) { |
| 5764 |
if (clipRes != splashClipAllInside) { |
| 5765 |
state->clip->clipSpan(scanBuf, y, xMin2, xMax2, |
| 5766 |
state->strokeAdjust); |
| 5767 |
} |
| 5768 |
(this->*pipe.run)(&pipe, xMin2, xMax2, y, |
| 5769 |
NULL, scanBuf + xMin2, NULL); |
| 5770 |
} |
| 5771 |
} |
| 5772 |
} else { |
| 5773 |
for (y = yMin; y <= yMax; ++y) { |
| 5774 |
scanner->getSpanBinary(scanBuf, y, xMin, xMax, &xMin2, &xMax2); |
| 5775 |
if (xMin2 <= xMax2) { |
| 5776 |
if (clipRes != splashClipAllInside) { |
| 5777 |
state->clip->clipSpanBinary(scanBuf, y, xMin2, xMax2, |
| 5778 |
state->strokeAdjust); |
| 5779 |
} |
| 5780 |
(this->*pipe.run)(&pipe, xMin2, xMax2, y, |
| 5781 |
NULL, scanBuf + xMin2, NULL); |
| 5782 |
} |
| 5783 |
} |
| 5784 |
} |
| 5785 |
} |
| 5786 |
opClipRes = clipRes; |
| 5787 |
|
| 5788 |
delete scanner; |
| 5789 |
delete xPath; |
| 5790 |
return splashOk; |
| 5791 |
} |
| 5792 |
|
| 5793 |
// Applies various tweaks to a fill path: |
| 5794 |
// (1) add stroke adjust hints to a filled rectangle |
| 5795 |
// (2) applies a minimum width to a zero-width filled rectangle (so |
| 5796 |
// stroke adjustment works correctly |
| 5797 |
// (3) convert a degenerate fill ('moveto lineto fill' and 'moveto |
| 5798 |
// lineto closepath fill') to a minimum-width filled rectangle |
| 5799 |
// |
| 5800 |
// These tweaks only apply to paths with a single subpath. |
| 5801 |
// |
| 5802 |
// Returns either the unchanged input path or a new path (in which |
| 5803 |
// case the returned path must be deleted by the caller). |
| 5804 |
SplashPath *Splash::tweakFillPath(SplashPath *path) { |
| 5805 |
SplashPath *path2; |
| 5806 |
SplashCoord xx0, yy0, xx1, yy1, dx, dy, d, wx, wy, w; |
| 5807 |
int n; |
| 5808 |
|
| 5809 |
if (state->strokeAdjust == splashStrokeAdjustOff || path->hints) { |
| 5810 |
return path; |
| 5811 |
} |
| 5812 |
|
| 5813 |
n = path->getLength(); |
| 5814 |
if (!((n == 2) || |
| 5815 |
(n == 3 && |
| 5816 |
path->flags[1] == 0) || |
| 5817 |
(n == 4 && |
| 5818 |
path->flags[1] == 0 && |
| 5819 |
path->flags[2] == 0) || |
| 5820 |
(n == 5 && |
| 5821 |
path->flags[1] == 0 && |
| 5822 |
path->flags[2] == 0 && |
| 5823 |
path->flags[3] == 0))) { |
| 5824 |
return path; |
| 5825 |
} |
| 5826 |
|
| 5827 |
path2 = path; |
| 5828 |
|
| 5829 |
// degenerate fill (2 or 3 points) or rectangle of (nearly) zero |
| 5830 |
// width --> replace with a min-width rectangle and hint |
| 5831 |
if (n == 2 || |
| 5832 |
(n == 3 && (path->flags[0] & splashPathClosed)) || |
| 5833 |
(n == 3 && (splashAbs(path->pts[0].x - path->pts[2].x) < 0.001 && |
| 5834 |
splashAbs(path->pts[0].y - path->pts[2].y) < 0.001)) || |
| 5835 |
((n == 4 || |
| 5836 |
(n == 5 && (path->flags[0] & splashPathClosed))) && |
| 5837 |
((splashAbs(path->pts[0].x - path->pts[1].x) < 0.001 && |
| 5838 |
splashAbs(path->pts[0].y - path->pts[1].y) < 0.001 && |
| 5839 |
splashAbs(path->pts[2].x - path->pts[3].x) < 0.001 && |
| 5840 |
splashAbs(path->pts[2].y - path->pts[3].y) < 0.001) || |
| 5841 |
(splashAbs(path->pts[0].x - path->pts[3].x) < 0.001 && |
| 5842 |
splashAbs(path->pts[0].y - path->pts[3].y) < 0.001 && |
| 5843 |
splashAbs(path->pts[1].x - path->pts[2].x) < 0.001 && |
| 5844 |
splashAbs(path->pts[1].y - path->pts[2].y) < 0.001)))) { |
| 5845 |
wx = state->matrix[0] + state->matrix[2]; |
| 5846 |
wy = state->matrix[1] + state->matrix[3]; |
| 5847 |
w = splashSqrt(wx*wx + wy*wy); |
| 5848 |
if (w < 0.001) { |
| 5849 |
w = 0; |
| 5850 |
} else { |
| 5851 |
// min width is 0.1 -- this constant is minWidth * sqrt(2) |
| 5852 |
w = (SplashCoord)0.1414 / w; |
| 5853 |
} |
| 5854 |
xx0 = path->pts[0].x; |
| 5855 |
yy0 = path->pts[0].y; |
| 5856 |
if (n <= 3) { |
| 5857 |
xx1 = path->pts[1].x; |
| 5858 |
yy1 = path->pts[1].y; |
| 5859 |
} else { |
| 5860 |
xx1 = path->pts[2].x; |
| 5861 |
yy1 = path->pts[2].y; |
| 5862 |
} |
| 5863 |
dx = xx1 - xx0; |
| 5864 |
dy = yy1 - yy0; |
| 5865 |
d = splashSqrt(dx * dx + dy * dy); |
| 5866 |
if (d < 0.001) { |
| 5867 |
d = 0; |
| 5868 |
} else { |
| 5869 |
d = w / d; |
| 5870 |
} |
| 5871 |
dx *= d; |
| 5872 |
dy *= d; |
| 5873 |
path2 = new SplashPath(); |
| 5874 |
path2->moveTo(xx0 + dy, yy0 - dx); |
| 5875 |
path2->lineTo(xx1 + dy, yy1 - dx); |
| 5876 |
path2->lineTo(xx1 - dy, yy1 + dx); |
| 5877 |
path2->lineTo(xx0 - dy, yy0 + dx); |
| 5878 |
path2->close(gTrue); |
| 5879 |
path2->addStrokeAdjustHint(0, 2, 0, 4); |
| 5880 |
path2->addStrokeAdjustHint(1, 3, 0, 4); |
| 5881 |
|
| 5882 |
// unclosed rectangle --> close and hint |
| 5883 |
} else if (n == 4 && !(path->flags[0] & splashPathClosed)) { |
| 5884 |
path2->close(gTrue); |
| 5885 |
path2->addStrokeAdjustHint(0, 2, 0, 4); |
| 5886 |
path2->addStrokeAdjustHint(1, 3, 0, 4); |
| 5887 |
|
| 5888 |
// closed rectangle --> hint |
| 5889 |
} else if (n == 5 && (path->flags[0] & splashPathClosed)) { |
| 5890 |
path2->addStrokeAdjustHint(0, 2, 0, 4); |
| 5891 |
path2->addStrokeAdjustHint(1, 3, 0, 4); |
| 5892 |
} |
| 5893 |
|
| 5894 |
return path2; |
| 5895 |
} |
| 5896 |
|
| 5897 |
// Returns true if [path] is entirely outside the current clipping |
| 5898 |
// path. The path coordinates have not been stroke adjusted, so we |
| 5899 |
// compare against the floating point clip rect. If [stroke] is true, |
| 5900 |
// allow for the stroke width and miter limit. |
| 5901 |
GBool Splash::pathAllOutside(SplashPath *path, GBool stroke) { |
| 5902 |
SplashCoord xMin1, yMin1, xMax1, yMax1; |
| 5903 |
SplashCoord xMin2, yMin2, xMax2, yMax2; |
| 5904 |
SplashCoord x, y; |
| 5905 |
int i; |
| 5906 |
|
| 5907 |
//--- compute the path's bbox in user space |
| 5908 |
xMin1 = xMax1 = path->pts[0].x; |
| 5909 |
yMin1 = yMax1 = path->pts[0].y; |
| 5910 |
for (i = 1; i < path->length; ++i) { |
| 5911 |
if (path->pts[i].x < xMin1) { |
| 5912 |
xMin1 = path->pts[i].x; |
| 5913 |
} else if (path->pts[i].x > xMax1) { |
| 5914 |
xMax1 = path->pts[i].x; |
| 5915 |
} |
| 5916 |
if (path->pts[i].y < yMin1) { |
| 5917 |
yMin1 = path->pts[i].y; |
| 5918 |
} else if (path->pts[i].y > yMax1) { |
| 5919 |
yMax1 = path->pts[i].y; |
| 5920 |
} |
| 5921 |
} |
| 5922 |
|
| 5923 |
//--- allow for stroke width and miter limit |
| 5924 |
if (stroke && state->lineWidth > 0) { |
| 5925 |
SplashCoord w = state->lineWidth * 0.5; |
| 5926 |
if (state->lineJoin == splashLineJoinMiter) { |
| 5927 |
w *= state->miterLimit; |
| 5928 |
} |
| 5929 |
xMin1 -= w; |
| 5930 |
yMin1 -= w; |
| 5931 |
xMax1 += w; |
| 5932 |
yMax1 += w; |
| 5933 |
} |
| 5934 |
|
| 5935 |
//--- convert path bbox to device space |
| 5936 |
transform(state->matrix, xMin1, yMin1, &x, &y); |
| 5937 |
xMin2 = xMax2 = x; |
| 5938 |
yMin2 = yMax2 = y; |
| 5939 |
transform(state->matrix, xMin1, yMax1, &x, &y); |
| 5940 |
if (x < xMin2) { |
| 5941 |
xMin2 = x; |
| 5942 |
} else if (x > xMax2) { |
| 5943 |
xMax2 = x; |
| 5944 |
} |
| 5945 |
if (y < yMin2) { |
| 5946 |
yMin2 = y; |
| 5947 |
} else if (y > yMax2) { |
| 5948 |
yMax2 = y; |
| 5949 |
} |
| 5950 |
transform(state->matrix, xMax1, yMin1, &x, &y); |
| 5951 |
if (x < xMin2) { |
| 5952 |
xMin2 = x; |
| 5953 |
} else if (x > xMax2) { |
| 5954 |
xMax2 = x; |
| 5955 |
} |
| 5956 |
if (y < yMin2) { |
| 5957 |
yMin2 = y; |
| 5958 |
} else if (y > yMax2) { |
| 5959 |
yMax2 = y; |
| 5960 |
} |
| 5961 |
transform(state->matrix, xMax1, yMax1, &x, &y); |
| 5962 |
if (x < xMin2) { |
| 5963 |
xMin2 = x; |
| 5964 |
} else if (x > xMax2) { |
| 5965 |
xMax2 = x; |
| 5966 |
} |
| 5967 |
if (y < yMin2) { |
| 5968 |
yMin2 = y; |
| 5969 |
} else if (y > yMax2) { |
| 5970 |
yMax2 = y; |
| 5971 |
} |
| 5972 |
|
| 5973 |
//--- handle zero-width strokes |
| 5974 |
if (stroke && state->lineWidth == 0) { |
| 5975 |
xMin1 -= 1; |
| 5976 |
yMin1 -= 1; |
| 5977 |
xMax1 += 1; |
| 5978 |
yMax1 += 1; |
| 5979 |
} |
| 5980 |
|
| 5981 |
//--- check against the clip rect |
| 5982 |
return xMin2 > state->clip->getXMax() || |
| 5983 |
xMax2 < state->clip->getXMin() || |
| 5984 |
yMin2 > state->clip->getYMax() || |
| 5985 |
yMax2 < state->clip->getYMin(); |
| 5986 |
} |
| 5987 |
|
| 5988 |
SplashError Splash::fillChar(SplashCoord x, SplashCoord y, |
| 5989 |
Guint c, SplashFont *font) { |
| 5990 |
SplashGlyphBitmap glyph; |
| 5991 |
SplashCoord xt, yt; |
| 5992 |
int x0, y0, xFrac, yFrac; |
| 5993 |
SplashError err; |
| 5994 |
|
| 5995 |
if (debugMode) { |
| 5996 |
printf("fillChar: x=%.2f y=%.2f c=%3u=0x%02x='%c'\n", |
| 5997 |
(double)x, (double)y, c, c, c); |
| 5998 |
} |
| 5999 |
transform(state->matrix, x, y, &xt, &yt); |
| 6000 |
x0 = splashFloor(xt); |
| 6001 |
xFrac = splashFloor((xt - x0) * splashFontFraction); |
| 6002 |
y0 = splashFloor(yt); |
| 6003 |
yFrac = splashFloor((yt - y0) * splashFontFraction); |
| 6004 |
if (!font->getGlyph(c, xFrac, yFrac, &glyph)) { |
| 6005 |
return splashErrNoGlyph; |
| 6006 |
} |
| 6007 |
err = fillGlyph2(x0, y0, &glyph); |
| 6008 |
if (glyph.freeData) { |
| 6009 |
gfree(glyph.data); |
| 6010 |
} |
| 6011 |
return err; |
| 6012 |
} |
| 6013 |
|
| 6014 |
SplashError Splash::fillGlyph(SplashCoord x, SplashCoord y, |
| 6015 |
SplashGlyphBitmap *glyph) { |
| 6016 |
SplashCoord xt, yt; |
| 6017 |
int x0, y0; |
| 6018 |
|
| 6019 |
transform(state->matrix, x, y, &xt, &yt); |
| 6020 |
x0 = splashFloor(xt); |
| 6021 |
y0 = splashFloor(yt); |
| 6022 |
return fillGlyph2(x0, y0, glyph); |
| 6023 |
} |
| 6024 |
|
| 6025 |
SplashError Splash::fillGlyph2(int x0, int y0, SplashGlyphBitmap *glyph) { |
| 6026 |
SplashPipe pipe; |
| 6027 |
SplashClipResult clipRes; |
| 6028 |
Guchar alpha; |
| 6029 |
Guchar *p; |
| 6030 |
int xMin, yMin, xMax, yMax; |
| 6031 |
int x, y, xg, yg, xx, t; |
| 6032 |
|
| 6033 |
xg = x0 - glyph->x; |
| 6034 |
yg = y0 - glyph->y; |
| 6035 |
xMin = xg; |
| 6036 |
xMax = xg + glyph->w - 1; |
| 6037 |
yMin = yg; |
| 6038 |
yMax = yg + glyph->h - 1; |
| 6039 |
if ((clipRes = state->clip->testRect(xMin, yMin, xMax, yMax, |
| 6040 |
state->strokeAdjust)) |
| 6041 |
!= splashClipAllOutside) { |
| 6042 |
pipeInit(&pipe, state->fillPattern, |
| 6043 |
(Guchar)splashRound(state->fillAlpha * 255), |
| 6044 |
gFalse, gTrue, gFalse); |
| 6045 |
if (clipRes == splashClipAllInside) { |
| 6046 |
if (glyph->aa) { |
| 6047 |
p = glyph->data; |
| 6048 |
for (y = yMin; y <= yMax; ++y) { |
| 6049 |
(this->*pipe.run)(&pipe, xMin, xMax, y, |
| 6050 |
NULL, |
| 6051 |
glyph->data + (y - yMin) * glyph->w, |
| 6052 |
NULL); |
| 6053 |
} |
| 6054 |
} else { |
| 6055 |
p = glyph->data; |
| 6056 |
for (y = yMin; y <= yMax; ++y) { |
| 6057 |
for (x = xMin; x <= xMax; x += 8) { |
| 6058 |
alpha = *p++; |
| 6059 |
for (xx = 0; xx < 8 && x + xx <= xMax; ++xx) { |
| 6060 |
scanBuf[x + xx] = (alpha & 0x80) ? 0xff : 0x00; |
| 6061 |
alpha = (Guchar)(alpha << 1); |
| 6062 |
} |
| 6063 |
} |
| 6064 |
(this->*pipe.run)(&pipe, xMin, xMax, y, |
| 6065 |
NULL, scanBuf + xMin, NULL); |
| 6066 |
} |
| 6067 |
} |
| 6068 |
} else { |
| 6069 |
if ((t = state->clip->getXMinI(state->strokeAdjust)) > xMin) { |
| 6070 |
xMin = t; |
| 6071 |
} |
| 6072 |
if ((t = state->clip->getXMaxI(state->strokeAdjust)) < xMax) { |
| 6073 |
xMax = t; |
| 6074 |
} |
| 6075 |
if ((t = state->clip->getYMinI(state->strokeAdjust)) > yMin) { |
| 6076 |
yMin = t; |
| 6077 |
} |
| 6078 |
if ((t = state->clip->getYMaxI(state->strokeAdjust)) < yMax) { |
| 6079 |
yMax = t; |
| 6080 |
} |
| 6081 |
if (xMin <= xMax && yMin <= yMax) { |
| 6082 |
if (glyph->aa) { |
| 6083 |
for (y = yMin; y <= yMax; ++y) { |
| 6084 |
p = glyph->data + (y - yg) * glyph->w + (xMin - xg); |
| 6085 |
memcpy(scanBuf + xMin, p, xMax - xMin + 1); |
| 6086 |
state->clip->clipSpan(scanBuf, y, xMin, xMax, |
| 6087 |
state->strokeAdjust); |
| 6088 |
(this->*pipe.run)(&pipe, xMin, xMax, y, |
| 6089 |
NULL, scanBuf + xMin, NULL); |
| 6090 |
} |
| 6091 |
} else { |
| 6092 |
for (y = yMin; y <= yMax; ++y) { |
| 6093 |
p = glyph->data + (y - yg) * ((glyph->w + 7) >> 3) |
| 6094 |
+ ((xMin - xg) >> 3); |
| 6095 |
alpha = *p++; |
| 6096 |
xx = (xMin - xg) & 7; |
| 6097 |
alpha = (Guchar)(alpha << xx); |
| 6098 |
for (x = xMin; xx < 8 && x <= xMax; ++x, ++xx) { |
| 6099 |
scanBuf[x] = (alpha & 0x80) ? 255 : 0; |
| 6100 |
alpha = (Guchar)(alpha << 1); |
| 6101 |
} |
| 6102 |
for (; x <= xMax; x += 8) { |
| 6103 |
alpha = *p++; |
| 6104 |
for (xx = 0; xx < 8 && x + xx <= xMax; ++xx) { |
| 6105 |
scanBuf[x + xx] = (alpha & 0x80) ? 255 : 0; |
| 6106 |
alpha = (Guchar)(alpha << 1); |
| 6107 |
} |
| 6108 |
} |
| 6109 |
state->clip->clipSpanBinary(scanBuf, y, xMin, xMax, |
| 6110 |
state->strokeAdjust); |
| 6111 |
(this->*pipe.run)(&pipe, xMin, xMax, y, |
| 6112 |
NULL, scanBuf + xMin, NULL); |
| 6113 |
} |
| 6114 |
} |
| 6115 |
} |
| 6116 |
} |
| 6117 |
} |
| 6118 |
opClipRes = clipRes; |
| 6119 |
|
| 6120 |
return splashOk; |
| 6121 |
} |
| 6122 |
|
| 6123 |
void Splash::getImageBounds(SplashCoord xyMin, SplashCoord xyMax, |
| 6124 |
int *xyMinI, int *xyMaxI) { |
| 6125 |
if (state->strokeAdjust == splashStrokeAdjustOff) { |
| 6126 |
// make sure the coords fit in 32-bit ints |
| 6127 |
#if USE_FIXEDPOINT |
| 6128 |
if (xyMin < -32767) { |
| 6129 |
xyMin = -32767; |
| 6130 |
} else if (xyMin > 32767) { |
| 6131 |
xyMin = 32767; |
| 6132 |
} |
| 6133 |
if (xyMax < -32767) { |
| 6134 |
xyMax = -32767; |
| 6135 |
} else if (xyMax > 32767) { |
| 6136 |
xyMax = 32767; |
| 6137 |
} |
| 6138 |
#else |
| 6139 |
if (xyMin < -1e9) { |
| 6140 |
xyMin = -1e9; |
| 6141 |
} else if (xyMin > 1e9) { |
| 6142 |
xyMin = 1e9; |
| 6143 |
} |
| 6144 |
if (xyMax < -1e9) { |
| 6145 |
xyMax = -1e9; |
| 6146 |
} else if (xyMax > 1e9) { |
| 6147 |
xyMax = 1e9; |
| 6148 |
} |
| 6149 |
#endif |
| 6150 |
*xyMinI = splashFloor(xyMin); |
| 6151 |
*xyMaxI = splashFloor(xyMax); |
| 6152 |
if (*xyMaxI <= *xyMinI) { |
| 6153 |
*xyMaxI = *xyMinI + 1; |
| 6154 |
} |
| 6155 |
} else { |
| 6156 |
splashStrokeAdjust(xyMin, xyMax, xyMinI, xyMaxI, state->strokeAdjust); |
| 6157 |
} |
| 6158 |
} |
| 6159 |
|
| 6160 |
struct SplashDrawImageMaskRowData { |
| 6161 |
SplashPipe pipe; |
| 6162 |
}; |
| 6163 |
|
| 6164 |
// The glyphMode flag is not currently used, but may be useful if the |
| 6165 |
// stroke adjustment behavior is changed. |
| 6166 |
SplashError Splash::fillImageMask(GString *imageTag, |
| 6167 |
SplashImageMaskSource src, void *srcData, |
| 6168 |
int w, int h, SplashCoord *mat, |
| 6169 |
GBool glyphMode, GBool interpolate, |
| 6170 |
GBool antialias) { |
| 6171 |
if (debugMode) { |
| 6172 |
printf("fillImageMask: w=%d h=%d mat=[%.2f %.2f %.2f %.2f %.2f %.2f]\n", |
| 6173 |
w, h, (double)mat[0], (double)mat[1], (double)mat[2], |
| 6174 |
(double)mat[3], (double)mat[4], (double)mat[5]); |
| 6175 |
} |
| 6176 |
|
| 6177 |
//--- check for singular matrix |
| 6178 |
if (!splashCheckDet(mat[0], mat[1], mat[2], mat[3], 0.000001)) { |
| 6179 |
return splashErrSingularMatrix; |
| 6180 |
} |
| 6181 |
|
| 6182 |
//--- compute image bbox, check clipping |
| 6183 |
GBool flipsOnly = splashAbs(mat[1]) <= 0.0001 && splashAbs(mat[2]) <= 0.0001; |
| 6184 |
GBool rot90Only = splashAbs(mat[0]) <= 0.0001 && splashAbs(mat[3]) <= 0.0001; |
| 6185 |
GBool horizFlip = gFalse; |
| 6186 |
GBool vertFlip = gFalse; |
| 6187 |
int xMin, yMin, xMax, yMax; |
| 6188 |
if (flipsOnly) { |
| 6189 |
horizFlip = mat[0] < 0; |
| 6190 |
vertFlip = mat[3] < 0; |
| 6191 |
if (horizFlip) { |
| 6192 |
getImageBounds(mat[0] + mat[4], mat[4], &xMin, &xMax); |
| 6193 |
} else { |
| 6194 |
getImageBounds(mat[4], mat[0] + mat[4], &xMin, &xMax); |
| 6195 |
} |
| 6196 |
if (vertFlip) { |
| 6197 |
getImageBounds(mat[3] + mat[5], mat[5], &yMin, &yMax); |
| 6198 |
} else { |
| 6199 |
getImageBounds(mat[5], mat[3] + mat[5], &yMin, &yMax); |
| 6200 |
} |
| 6201 |
} else if (rot90Only) { |
| 6202 |
horizFlip = mat[2] < 0; |
| 6203 |
vertFlip = mat[1] < 0; |
| 6204 |
if (horizFlip) { |
| 6205 |
getImageBounds(mat[2] + mat[4], mat[4], &xMin, &xMax); |
| 6206 |
} else { |
| 6207 |
getImageBounds(mat[4], mat[2] + mat[4], &xMin, &xMax); |
| 6208 |
} |
| 6209 |
if (vertFlip) { |
| 6210 |
getImageBounds(mat[1] + mat[5], mat[5], &yMin, &yMax); |
| 6211 |
} else { |
| 6212 |
getImageBounds(mat[5], mat[1] + mat[5], &yMin, &yMax); |
| 6213 |
} |
| 6214 |
} else { |
| 6215 |
int xx = splashRound(mat[4]); // (0,0) |
| 6216 |
int yy = splashRound(mat[5]); |
| 6217 |
xMin = xMax = xx; |
| 6218 |
yMin = yMax = yy; |
| 6219 |
xx = splashRound(mat[0] + mat[4]); // (1,0) |
| 6220 |
yy = splashRound(mat[1] + mat[5]); |
| 6221 |
if (xx < xMin) { |
| 6222 |
xMin = xx; |
| 6223 |
} else if (xx > xMax) { |
| 6224 |
xMax = xx; |
| 6225 |
} |
| 6226 |
if (yy < yMin) { |
| 6227 |
yMin = yy; |
| 6228 |
} else if (yy > yMax) { |
| 6229 |
yMax = yy; |
| 6230 |
} |
| 6231 |
xx = splashRound(mat[2] + mat[4]); // (0,1) |
| 6232 |
yy = splashRound(mat[3] + mat[5]); |
| 6233 |
if (xx < xMin) { |
| 6234 |
xMin = xx; |
| 6235 |
} else if (xx > xMax) { |
| 6236 |
xMax = xx; |
| 6237 |
} |
| 6238 |
if (yy < yMin) { |
| 6239 |
yMin = yy; |
| 6240 |
} else if (yy > yMax) { |
| 6241 |
yMax = yy; |
| 6242 |
} |
| 6243 |
xx = splashRound(mat[0] + mat[2] + mat[4]); // (1,1) |
| 6244 |
yy = splashRound(mat[1] + mat[3] + mat[5]); |
| 6245 |
if (xx < xMin) { |
| 6246 |
xMin = xx; |
| 6247 |
} else if (xx > xMax) { |
| 6248 |
xMax = xx; |
| 6249 |
} |
| 6250 |
if (yy < yMin) { |
| 6251 |
yMin = yy; |
| 6252 |
} else if (yy > yMax) { |
| 6253 |
yMax = yy; |
| 6254 |
} |
| 6255 |
if (xMax <= xMin) { |
| 6256 |
xMax = xMin + 1; |
| 6257 |
} |
| 6258 |
if (yMax <= yMin) { |
| 6259 |
yMax = yMin + 1; |
| 6260 |
} |
| 6261 |
} |
| 6262 |
SplashClipResult clipRes = |
| 6263 |
state->clip->testRect(xMin, yMin, xMax - 1, yMax - 1, |
| 6264 |
state->strokeAdjust); |
| 6265 |
if (clipRes == splashClipAllOutside) { |
| 6266 |
return splashOk; |
| 6267 |
} |
| 6268 |
// If the scaled mask is much wider and/or taller than the clip |
| 6269 |
// region, we use the "arbitrary" scaling path, to avoid a |
| 6270 |
// potentially very slow loop in the flips-only path (which scans |
| 6271 |
// the full width and height of the scaled mask, regardless of the |
| 6272 |
// clip region). |
| 6273 |
int clipW = state->clip->getXMaxI(state->strokeAdjust) |
| 6274 |
- state->clip->getXMinI(state->strokeAdjust); |
| 6275 |
int clipH = state->clip->getYMaxI(state->strokeAdjust) |
| 6276 |
- state->clip->getYMinI(state->strokeAdjust); |
| 6277 |
GBool veryLarge = ((xMax - xMin) / 8 > clipW && xMax - xMin > 1000) || |
| 6278 |
((yMax - yMin) / 8 > clipH && yMax - yMin > 1000); |
| 6279 |
|
| 6280 |
//--- set up the SplashDrawImageMaskRowData object and the pipes |
| 6281 |
SplashDrawImageMaskRowData dd; |
| 6282 |
pipeInit(&dd.pipe, state->fillPattern, |
| 6283 |
(Guchar)splashRound(state->fillAlpha * 255), |
| 6284 |
gFalse, gTrue, gFalse); |
| 6285 |
|
| 6286 |
//--- choose the drawRow function |
| 6287 |
SplashDrawImageMaskRowFunc drawRowFunc; |
| 6288 |
if (clipRes == splashClipAllInside) { |
| 6289 |
drawRowFunc = &Splash::drawImageMaskRowNoClip; |
| 6290 |
} else { |
| 6291 |
if (antialias) { |
| 6292 |
drawRowFunc = &Splash::drawImageMaskRowClipAA; |
| 6293 |
} else { |
| 6294 |
drawRowFunc = &Splash::drawImageMaskRowClipNoAA; |
| 6295 |
} |
| 6296 |
} |
| 6297 |
|
| 6298 |
//--- horizontal/vertical flips only |
| 6299 |
if (flipsOnly && !veryLarge) { |
| 6300 |
int scaledWidth = xMax - xMin; |
| 6301 |
int scaledHeight = yMax - yMin; |
| 6302 |
ImageMaskScaler scaler(src, srcData, w, h, |
| 6303 |
scaledWidth, scaledHeight, interpolate, antialias); |
| 6304 |
Guchar *tmpLine = NULL; |
| 6305 |
if (horizFlip) { |
| 6306 |
tmpLine = (Guchar *)gmalloc(scaledWidth); |
| 6307 |
} |
| 6308 |
if (vertFlip) { |
| 6309 |
if (horizFlip) { // bottom-up, mirrored |
| 6310 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6311 |
scaler.nextLine(); |
| 6312 |
mirrorImageMaskRow(scaler.data(), tmpLine, scaledWidth); |
| 6313 |
(this->*drawRowFunc)(&dd, tmpLine, |
| 6314 |
xMin, yMax - 1 - y, scaledWidth); |
| 6315 |
} |
| 6316 |
} else { // bottom-up |
| 6317 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6318 |
scaler.nextLine(); |
| 6319 |
(this->*drawRowFunc)(&dd, scaler.data(), |
| 6320 |
xMin, yMax - 1 - y, scaledWidth); |
| 6321 |
} |
| 6322 |
} |
| 6323 |
} else { |
| 6324 |
if (horizFlip) { // top-down, mirrored |
| 6325 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6326 |
scaler.nextLine(); |
| 6327 |
mirrorImageMaskRow(scaler.data(), tmpLine, scaledWidth); |
| 6328 |
(this->*drawRowFunc)(&dd, tmpLine, |
| 6329 |
xMin, yMin + y, scaledWidth); |
| 6330 |
} |
| 6331 |
} else { // top-down |
| 6332 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6333 |
scaler.nextLine(); |
| 6334 |
(this->*drawRowFunc)(&dd, scaler.data(), |
| 6335 |
xMin, yMin + y, scaledWidth); |
| 6336 |
} |
| 6337 |
} |
| 6338 |
} |
| 6339 |
gfree(tmpLine); |
| 6340 |
|
| 6341 |
//--- 90/270 rotation |
| 6342 |
} else if (rot90Only && !veryLarge) { |
| 6343 |
|
| 6344 |
// scale the mask |
| 6345 |
int scaledWidth = yMax - yMin; |
| 6346 |
int scaledHeight = xMax - xMin; |
| 6347 |
ImageMaskScaler scaler(src, srcData, w, h, |
| 6348 |
scaledWidth, scaledHeight, interpolate, antialias); |
| 6349 |
Guchar *scaledMask = (Guchar *)gmallocn64(scaledHeight, scaledWidth); |
| 6350 |
Guchar *ptr = scaledMask; |
| 6351 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6352 |
scaler.nextLine(); |
| 6353 |
memcpy(ptr, scaler.data(), scaledWidth); |
| 6354 |
ptr += scaledWidth; |
| 6355 |
} |
| 6356 |
|
| 6357 |
// draw it |
| 6358 |
Guchar *tmpLine = (Guchar *)gmalloc(scaledHeight); |
| 6359 |
for (int y = 0; y < scaledWidth; ++y) { |
| 6360 |
if (vertFlip) { |
| 6361 |
ptr = scaledMask + (scaledWidth - 1 - y); |
| 6362 |
} else { |
| 6363 |
ptr = scaledMask + y; |
| 6364 |
} |
| 6365 |
if (horizFlip) { |
| 6366 |
ptr += (scaledHeight - 1) * (SplashBitmapRowSize)scaledWidth; |
| 6367 |
for (int x = 0; x < scaledHeight; ++x) { |
| 6368 |
tmpLine[x] = *ptr; |
| 6369 |
ptr -= scaledWidth; |
| 6370 |
} |
| 6371 |
} else { |
| 6372 |
for (int x = 0; x < scaledHeight; ++x) { |
| 6373 |
tmpLine[x] = *ptr; |
| 6374 |
ptr += scaledWidth; |
| 6375 |
} |
| 6376 |
} |
| 6377 |
(this->*drawRowFunc)(&dd, tmpLine, xMin, yMin + y, scaledHeight); |
| 6378 |
} |
| 6379 |
|
| 6380 |
gfree(tmpLine); |
| 6381 |
gfree(scaledMask); |
| 6382 |
|
| 6383 |
//--- arbitrary transform |
| 6384 |
} else { |
| 6385 |
// estimate of size of scaled image |
| 6386 |
int scaledWidth = splashRound(splashSqrt(mat[0] * mat[0] |
| 6387 |
+ mat[1] * mat[1])); |
| 6388 |
int scaledHeight = splashRound(splashSqrt(mat[2] * mat[2] |
| 6389 |
+ mat[3] * mat[3])); |
| 6390 |
if (scaledWidth < 1) { |
| 6391 |
scaledWidth = 1; |
| 6392 |
} |
| 6393 |
if (scaledHeight < 1) { |
| 6394 |
scaledHeight = 1; |
| 6395 |
} |
| 6396 |
GBool downscaling = gTrue; |
| 6397 |
if (scaledWidth >= w && scaledHeight >= h) { |
| 6398 |
downscaling = gFalse; |
| 6399 |
scaledWidth = w; |
| 6400 |
scaledHeight = h; |
| 6401 |
} |
| 6402 |
|
| 6403 |
// compute mapping from device space to scaled image space |
| 6404 |
SplashCoord mat1[6]; |
| 6405 |
mat1[0] = mat[0] / scaledWidth; |
| 6406 |
mat1[1] = mat[1] / scaledWidth; |
| 6407 |
mat1[2] = mat[2] / scaledHeight; |
| 6408 |
mat1[3] = mat[3] / scaledHeight; |
| 6409 |
mat1[4] = mat[4]; |
| 6410 |
mat1[5] = mat[5]; |
| 6411 |
SplashCoord det = mat1[0] * mat1[3] - mat1[1] * mat1[2]; |
| 6412 |
if (splashAbs(det) < 1e-6) { |
| 6413 |
// this should be caught by the singular matrix check in drawImage |
| 6414 |
return splashErrSingularMatrix; |
| 6415 |
} |
| 6416 |
SplashCoord invMat[6]; |
| 6417 |
invMat[0] = mat1[3] / det; |
| 6418 |
invMat[1] = -mat1[1] / det; |
| 6419 |
invMat[2] = -mat1[2] / det; |
| 6420 |
invMat[3] = mat1[0] / det; |
| 6421 |
// the extra "+ 0.5 * (...)" terms are here because the |
| 6422 |
// drawImageArbitrary(No)Interp functions multiply by pixel |
| 6423 |
// centers, (x + 0.5, y + 0.5) |
| 6424 |
invMat[4] = (mat1[2] * mat1[5] - mat1[3] * mat1[4]) / det |
| 6425 |
+ (invMat[0] + invMat[2]) * 0.5; |
| 6426 |
invMat[5] = (mat1[1] * mat1[4] - mat1[0] * mat1[5]) / det |
| 6427 |
+ (invMat[1] + invMat[3]) * 0.5; |
| 6428 |
|
| 6429 |
// if downscaling: store the downscaled image mask |
| 6430 |
// if upscaling: store the unscaled image mask |
| 6431 |
Guchar *scaledMask = (Guchar *)gmallocn64(scaledHeight, scaledWidth); |
| 6432 |
if (downscaling) { |
| 6433 |
ImageMaskScaler scaler(src, srcData, w, h, |
| 6434 |
scaledWidth, scaledHeight, interpolate, antialias); |
| 6435 |
Guchar *ptr = scaledMask; |
| 6436 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6437 |
scaler.nextLine(); |
| 6438 |
memcpy(ptr, scaler.data(), scaledWidth); |
| 6439 |
ptr += scaledWidth; |
| 6440 |
} |
| 6441 |
} else { |
| 6442 |
Guchar *ptr = scaledMask; |
| 6443 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6444 |
(*src)(srcData, ptr); |
| 6445 |
for (int x = 0; x < scaledWidth; ++x) { |
| 6446 |
*ptr = (Guchar)(*ptr * 255); |
| 6447 |
++ptr; |
| 6448 |
} |
| 6449 |
} |
| 6450 |
} |
| 6451 |
|
| 6452 |
// draw it |
| 6453 |
if (interpolate && antialias) { |
| 6454 |
drawImageMaskArbitraryInterp(scaledMask, |
| 6455 |
&dd, drawRowFunc, invMat, |
| 6456 |
scaledWidth, scaledHeight, |
| 6457 |
xMin, yMin, xMax, yMax); |
| 6458 |
} else { |
| 6459 |
drawImageMaskArbitraryNoInterp(scaledMask, |
| 6460 |
&dd, drawRowFunc, invMat, |
| 6461 |
scaledWidth, scaledHeight, |
| 6462 |
xMin, yMin, xMax, yMax); |
| 6463 |
} |
| 6464 |
|
| 6465 |
// free the downscaled/unscaled image |
| 6466 |
gfree(scaledMask); |
| 6467 |
} |
| 6468 |
|
| 6469 |
return splashOk; |
| 6470 |
} |
| 6471 |
|
| 6472 |
void Splash::drawImageMaskArbitraryNoInterp( |
| 6473 |
Guchar *scaledMask, |
| 6474 |
SplashDrawImageMaskRowData *dd, |
| 6475 |
SplashDrawImageMaskRowFunc drawRowFunc, |
| 6476 |
SplashCoord *invMat, |
| 6477 |
int scaledWidth, int scaledHeight, |
| 6478 |
int xMin, int yMin, int xMax, int yMax) { |
| 6479 |
int tt = state->clip->getXMinI(state->strokeAdjust); |
| 6480 |
if (tt > xMin) { |
| 6481 |
xMin = tt; |
| 6482 |
} |
| 6483 |
tt = state->clip->getXMaxI(state->strokeAdjust) + 1; |
| 6484 |
if (tt < xMax) { |
| 6485 |
xMax = tt; |
| 6486 |
} |
| 6487 |
tt = state->clip->getYMinI(state->strokeAdjust); |
| 6488 |
if (tt > yMin) { |
| 6489 |
yMin = tt; |
| 6490 |
} |
| 6491 |
tt = state->clip->getYMaxI(state->strokeAdjust) + 1; |
| 6492 |
if (tt < yMax) { |
| 6493 |
yMax = tt; |
| 6494 |
} |
| 6495 |
if (xMax <= xMin || yMax <= yMin) { |
| 6496 |
return; |
| 6497 |
} |
| 6498 |
|
| 6499 |
Guchar *buf = (Guchar *)gmalloc(xMax - xMin); |
| 6500 |
|
| 6501 |
for (int y = yMin; y < yMax; ++y) { |
| 6502 |
int rowMin = xMax; |
| 6503 |
int rowMax = 0; |
| 6504 |
for (int x = xMin; x < xMax; ++x) { |
| 6505 |
// note: invMat includes a "+0.5" factor so that this is really |
| 6506 |
// a multiply by (x+0.5, y+0.5) |
| 6507 |
int xx = splashFloor((SplashCoord)x * invMat[0] |
| 6508 |
+ (SplashCoord)y * invMat[2] + invMat[4]); |
| 6509 |
int yy = splashFloor((SplashCoord)x * invMat[1] |
| 6510 |
+ (SplashCoord)y * invMat[3] + invMat[5]); |
| 6511 |
if (xx >= 0 && xx < scaledWidth && |
| 6512 |
yy >= 0 && yy < scaledHeight) { |
| 6513 |
Guchar *p = scaledMask + (yy * (SplashBitmapRowSize)scaledWidth + xx); |
| 6514 |
Guchar *q = buf + (x - xMin); |
| 6515 |
*q = *p; |
| 6516 |
if (x < rowMin) { |
| 6517 |
rowMin = x; |
| 6518 |
} |
| 6519 |
rowMax = x + 1; |
| 6520 |
} |
| 6521 |
} |
| 6522 |
if (rowMin < rowMax) { |
| 6523 |
(this->*drawRowFunc)(dd, buf + (rowMin - xMin), |
| 6524 |
rowMin, y, rowMax - rowMin); |
| 6525 |
} |
| 6526 |
} |
| 6527 |
|
| 6528 |
gfree(buf); |
| 6529 |
} |
| 6530 |
|
| 6531 |
void Splash::drawImageMaskArbitraryInterp( |
| 6532 |
Guchar *scaledMask, |
| 6533 |
SplashDrawImageMaskRowData *dd, |
| 6534 |
SplashDrawImageMaskRowFunc drawRowFunc, |
| 6535 |
SplashCoord *invMat, |
| 6536 |
int scaledWidth, int scaledHeight, |
| 6537 |
int xMin, int yMin, int xMax, int yMax) { |
| 6538 |
int tt = state->clip->getXMinI(state->strokeAdjust); |
| 6539 |
if (tt > xMin) { |
| 6540 |
xMin = tt; |
| 6541 |
} |
| 6542 |
tt = state->clip->getXMaxI(state->strokeAdjust) + 1; |
| 6543 |
if (tt < xMax) { |
| 6544 |
xMax = tt; |
| 6545 |
} |
| 6546 |
tt = state->clip->getYMinI(state->strokeAdjust); |
| 6547 |
if (tt > yMin) { |
| 6548 |
yMin = tt; |
| 6549 |
} |
| 6550 |
tt = state->clip->getYMaxI(state->strokeAdjust) + 1; |
| 6551 |
if (tt < yMax) { |
| 6552 |
yMax = tt; |
| 6553 |
} |
| 6554 |
if (xMax <= xMin || yMax <= yMin) { |
| 6555 |
return; |
| 6556 |
} |
| 6557 |
|
| 6558 |
Guchar *buf = (Guchar *)gmalloc(xMax - xMin); |
| 6559 |
|
| 6560 |
for (int y = yMin; y < yMax; ++y) { |
| 6561 |
int rowMin = xMax; |
| 6562 |
int rowMax = 0; |
| 6563 |
for (int x = xMin; x < xMax; ++x) { |
| 6564 |
// note: invMat includes a "+0.5" factor so that this is really |
| 6565 |
// a multiply by (x+0.5, y+0.5) |
| 6566 |
SplashCoord xs = (SplashCoord)x * invMat[0] |
| 6567 |
+ (SplashCoord)y * invMat[2] + invMat[4]; |
| 6568 |
SplashCoord ys = (SplashCoord)x * invMat[1] |
| 6569 |
+ (SplashCoord)y * invMat[3] + invMat[5]; |
| 6570 |
int x0 = splashFloor(xs - 0.5); |
| 6571 |
int x1 = x0 + 1; |
| 6572 |
int y0 = splashFloor(ys - 0.5); |
| 6573 |
int y1 = y0 + 1; |
| 6574 |
if (x1 >= 0 && x0 < scaledWidth && y1 >= 0 && y0 < scaledHeight) { |
| 6575 |
SplashCoord sx0 = (SplashCoord)x1 + 0.5 - xs; |
| 6576 |
SplashCoord sx1 = (SplashCoord)1 - sx0; |
| 6577 |
SplashCoord sy0 = (SplashCoord)y1 + 0.5 - ys; |
| 6578 |
SplashCoord sy1 = (SplashCoord)1 - sy0; |
| 6579 |
if (x0 < 0) { |
| 6580 |
x0 = 0; |
| 6581 |
} |
| 6582 |
if (x1 >= scaledWidth) { |
| 6583 |
x1 = scaledWidth - 1; |
| 6584 |
} |
| 6585 |
if (y0 < 0) { |
| 6586 |
y0 = 0; |
| 6587 |
} |
| 6588 |
if (y1 >= scaledHeight) { |
| 6589 |
y1 = scaledHeight - 1; |
| 6590 |
} |
| 6591 |
Guchar *p00 = scaledMask + (y0 * (SplashBitmapRowSize)scaledWidth + x0); |
| 6592 |
Guchar *p10 = scaledMask + (y0 * (SplashBitmapRowSize)scaledWidth + x1); |
| 6593 |
Guchar *p01 = scaledMask + (y1 * (SplashBitmapRowSize)scaledWidth + x0); |
| 6594 |
Guchar *p11 = scaledMask + (y1 * (SplashBitmapRowSize)scaledWidth + x1); |
| 6595 |
Guchar *q = buf + (x - xMin); |
| 6596 |
*q = (Guchar)(int)(sx0 * (sy0 * (int)*p00 + sy1 * (int)*p01) + |
| 6597 |
sx1 * (sy0 * (int)*p10 + sy1 * (int)*p11)); |
| 6598 |
if (x < rowMin) { |
| 6599 |
rowMin = x; |
| 6600 |
} |
| 6601 |
rowMax = x + 1; |
| 6602 |
} |
| 6603 |
} |
| 6604 |
if (rowMin < rowMax) { |
| 6605 |
(this->*drawRowFunc)(dd, buf + (rowMin - xMin), |
| 6606 |
rowMin, y, rowMax - rowMin); |
| 6607 |
} |
| 6608 |
} |
| 6609 |
|
| 6610 |
gfree(buf); |
| 6611 |
} |
| 6612 |
|
| 6613 |
void Splash::mirrorImageMaskRow(Guchar *maskIn, Guchar *maskOut, int width) { |
| 6614 |
Guchar *p, *q; |
| 6615 |
|
| 6616 |
p = maskIn; |
| 6617 |
q = maskOut + (width - 1); |
| 6618 |
for (int i = 0; i < width; ++i) { |
| 6619 |
*q = *p; |
| 6620 |
++p; |
| 6621 |
--q; |
| 6622 |
} |
| 6623 |
} |
| 6624 |
|
| 6625 |
void Splash::drawImageMaskRowNoClip(SplashDrawImageMaskRowData *data, |
| 6626 |
Guchar *maskData, |
| 6627 |
int x, int y, int width) { |
| 6628 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 6629 |
NULL, maskData, NULL); |
| 6630 |
} |
| 6631 |
|
| 6632 |
void Splash::drawImageMaskRowClipNoAA(SplashDrawImageMaskRowData *data, |
| 6633 |
Guchar *maskData, |
| 6634 |
int x, int y, int width) { |
| 6635 |
if (y < 0 || y >= bitmap->height) { |
| 6636 |
return; |
| 6637 |
} |
| 6638 |
if (x < 0) { |
| 6639 |
maskData -= x; |
| 6640 |
width += x; |
| 6641 |
x = 0; |
| 6642 |
} |
| 6643 |
if (x + width > bitmap->width) { |
| 6644 |
width = bitmap->width - x; |
| 6645 |
} |
| 6646 |
if (width <= 0) { |
| 6647 |
return; |
| 6648 |
} |
| 6649 |
memcpy(scanBuf + x, maskData, width); |
| 6650 |
state->clip->clipSpanBinary(scanBuf, y, x, x + width - 1, |
| 6651 |
state->strokeAdjust); |
| 6652 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 6653 |
NULL, scanBuf + x, NULL); |
| 6654 |
} |
| 6655 |
|
| 6656 |
void Splash::drawImageMaskRowClipAA(SplashDrawImageMaskRowData *data, |
| 6657 |
Guchar *maskData, |
| 6658 |
int x, int y, int width) { |
| 6659 |
if (y < 0 || y >= bitmap->height) { |
| 6660 |
return; |
| 6661 |
} |
| 6662 |
if (x < 0) { |
| 6663 |
maskData -= x; |
| 6664 |
width += x; |
| 6665 |
x = 0; |
| 6666 |
} |
| 6667 |
if (x + width > bitmap->width) { |
| 6668 |
width = bitmap->width - x; |
| 6669 |
} |
| 6670 |
if (width <= 0) { |
| 6671 |
return; |
| 6672 |
} |
| 6673 |
memcpy(scanBuf + x, maskData, width); |
| 6674 |
state->clip->clipSpan(scanBuf, y, x, x + width - 1, state->strokeAdjust); |
| 6675 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 6676 |
NULL, scanBuf + x, NULL); |
| 6677 |
} |
| 6678 |
|
| 6679 |
struct SplashDrawImageRowData { |
| 6680 |
int nComps; |
| 6681 |
GBool srcAlpha; |
| 6682 |
SplashPipe pipe; |
| 6683 |
}; |
| 6684 |
|
| 6685 |
SplashError Splash::drawImage(GString *imageTag, |
| 6686 |
SplashImageSource src, void *srcData, |
| 6687 |
SplashColorMode srcMode, GBool srcAlpha, |
| 6688 |
int w, int h, SplashCoord *mat, |
| 6689 |
GBool interpolate) { |
| 6690 |
if (debugMode) { |
| 6691 |
printf("drawImage: srcMode=%d srcAlpha=%d w=%d h=%d mat=[%.2f %.2f %.2f %.2f %.2f %.2f]\n", |
| 6692 |
srcMode, srcAlpha, w, h, (double)mat[0], (double)mat[1], (double)mat[2], |
| 6693 |
(double)mat[3], (double)mat[4], (double)mat[5]); |
| 6694 |
} |
| 6695 |
|
| 6696 |
//--- check color modes |
| 6697 |
GBool ok = gFalse; |
| 6698 |
int nComps = 0; |
| 6699 |
switch (bitmap->mode) { |
| 6700 |
case splashModeMono1: |
| 6701 |
case splashModeMono8: |
| 6702 |
ok = srcMode == splashModeMono8; |
| 6703 |
nComps = 1; |
| 6704 |
break; |
| 6705 |
case splashModeRGB8: |
| 6706 |
case splashModeBGR8: |
| 6707 |
ok = srcMode == splashModeRGB8; |
| 6708 |
nComps = 3; |
| 6709 |
break; |
| 6710 |
#if SPLASH_CMYK |
| 6711 |
case splashModeCMYK8: |
| 6712 |
ok = srcMode == splashModeCMYK8; |
| 6713 |
nComps = 4; |
| 6714 |
break; |
| 6715 |
#endif |
| 6716 |
default: |
| 6717 |
ok = gFalse; |
| 6718 |
break; |
| 6719 |
} |
| 6720 |
if (!ok) { |
| 6721 |
return splashErrModeMismatch; |
| 6722 |
} |
| 6723 |
|
| 6724 |
//--- check for singular matrix |
| 6725 |
if (!splashCheckDet(mat[0], mat[1], mat[2], mat[3], 0.000001)) { |
| 6726 |
return splashErrSingularMatrix; |
| 6727 |
} |
| 6728 |
|
| 6729 |
//--- compute image bbox, check clipping |
| 6730 |
GBool flipsOnly = splashAbs(mat[1]) <= 0.0001 && splashAbs(mat[2]) <= 0.0001; |
| 6731 |
GBool rot90Only = splashAbs(mat[0]) <= 0.0001 && splashAbs(mat[3]) <= 0.0001; |
| 6732 |
GBool horizFlip = gFalse; |
| 6733 |
GBool vertFlip = gFalse; |
| 6734 |
int xMin, yMin, xMax, yMax; |
| 6735 |
if (flipsOnly) { |
| 6736 |
horizFlip = mat[0] < 0; |
| 6737 |
vertFlip = mat[3] < 0; |
| 6738 |
if (horizFlip) { |
| 6739 |
getImageBounds(mat[0] + mat[4], mat[4], &xMin, &xMax); |
| 6740 |
} else { |
| 6741 |
getImageBounds(mat[4], mat[0] + mat[4], &xMin, &xMax); |
| 6742 |
} |
| 6743 |
if (vertFlip) { |
| 6744 |
getImageBounds(mat[3] + mat[5], mat[5], &yMin, &yMax); |
| 6745 |
} else { |
| 6746 |
getImageBounds(mat[5], mat[3] + mat[5], &yMin, &yMax); |
| 6747 |
} |
| 6748 |
} else if (rot90Only) { |
| 6749 |
horizFlip = mat[2] < 0; |
| 6750 |
vertFlip = mat[1] < 0; |
| 6751 |
if (horizFlip) { |
| 6752 |
getImageBounds(mat[2] + mat[4], mat[4], &xMin, &xMax); |
| 6753 |
} else { |
| 6754 |
getImageBounds(mat[4], mat[2] + mat[4], &xMin, &xMax); |
| 6755 |
} |
| 6756 |
if (vertFlip) { |
| 6757 |
getImageBounds(mat[1] + mat[5], mat[5], &yMin, &yMax); |
| 6758 |
} else { |
| 6759 |
getImageBounds(mat[5], mat[1] + mat[5], &yMin, &yMax); |
| 6760 |
} |
| 6761 |
} else { |
| 6762 |
int xx = splashRound(mat[4]); // (0,0) |
| 6763 |
int yy = splashRound(mat[5]); |
| 6764 |
xMin = xMax = xx; |
| 6765 |
yMin = yMax = yy; |
| 6766 |
xx = splashRound(mat[0] + mat[4]); // (1,0) |
| 6767 |
yy = splashRound(mat[1] + mat[5]); |
| 6768 |
if (xx < xMin) { |
| 6769 |
xMin = xx; |
| 6770 |
} else if (xx > xMax) { |
| 6771 |
xMax = xx; |
| 6772 |
} |
| 6773 |
if (yy < yMin) { |
| 6774 |
yMin = yy; |
| 6775 |
} else if (yy > yMax) { |
| 6776 |
yMax = yy; |
| 6777 |
} |
| 6778 |
xx = splashRound(mat[2] + mat[4]); // (0,1) |
| 6779 |
yy = splashRound(mat[3] + mat[5]); |
| 6780 |
if (xx < xMin) { |
| 6781 |
xMin = xx; |
| 6782 |
} else if (xx > xMax) { |
| 6783 |
xMax = xx; |
| 6784 |
} |
| 6785 |
if (yy < yMin) { |
| 6786 |
yMin = yy; |
| 6787 |
} else if (yy > yMax) { |
| 6788 |
yMax = yy; |
| 6789 |
} |
| 6790 |
xx = splashRound(mat[0] + mat[2] + mat[4]); // (1,1) |
| 6791 |
yy = splashRound(mat[1] + mat[3] + mat[5]); |
| 6792 |
if (xx < xMin) { |
| 6793 |
xMin = xx; |
| 6794 |
} else if (xx > xMax) { |
| 6795 |
xMax = xx; |
| 6796 |
} |
| 6797 |
if (yy < yMin) { |
| 6798 |
yMin = yy; |
| 6799 |
} else if (yy > yMax) { |
| 6800 |
yMax = yy; |
| 6801 |
} |
| 6802 |
if (xMax <= xMin) { |
| 6803 |
xMax = xMin + 1; |
| 6804 |
} |
| 6805 |
if (yMax <= yMin) { |
| 6806 |
yMax = yMin + 1; |
| 6807 |
} |
| 6808 |
} |
| 6809 |
SplashClipResult clipRes = |
| 6810 |
state->clip->testRect(xMin, yMin, xMax - 1, yMax - 1, |
| 6811 |
state->strokeAdjust); |
| 6812 |
if (clipRes == splashClipAllOutside) { |
| 6813 |
return splashOk; |
| 6814 |
} |
| 6815 |
// If the scaled image is much wider and/or taller than the clip |
| 6816 |
// region, we use the arbitrary transform path, to avoid a |
| 6817 |
// potentially very slow loop in the flips-only path (which scans |
| 6818 |
// the full width and height of the scaled image, regardless of the |
| 6819 |
// clip region). |
| 6820 |
int clipW = state->clip->getXMaxI(state->strokeAdjust) |
| 6821 |
- state->clip->getXMinI(state->strokeAdjust); |
| 6822 |
int clipH = state->clip->getYMaxI(state->strokeAdjust) |
| 6823 |
- state->clip->getYMinI(state->strokeAdjust); |
| 6824 |
GBool veryLarge = ((xMax - xMin) / 8 > clipW && xMax - xMin > 1000) || |
| 6825 |
((yMax - yMin) / 8 > clipH && yMax - yMin > 1000); |
| 6826 |
|
| 6827 |
//--- set up the SplashDrawImageRowData object and the pipes |
| 6828 |
SplashDrawImageRowData dd; |
| 6829 |
dd.nComps = nComps; |
| 6830 |
dd.srcAlpha = srcAlpha; |
| 6831 |
pipeInit(&dd.pipe, NULL, |
| 6832 |
(Guchar)splashRound(state->fillAlpha * 255), |
| 6833 |
gFalse, clipRes != splashClipAllInside || srcAlpha, |
| 6834 |
gFalse, gFalse, state->alphaIsShape); |
| 6835 |
|
| 6836 |
//--- choose the drawRow function |
| 6837 |
SplashDrawImageRowFunc drawRowFunc; |
| 6838 |
if (clipRes == splashClipAllInside) { |
| 6839 |
if (srcAlpha) { |
| 6840 |
drawRowFunc = &Splash::drawImageRowNoClipAlpha; |
| 6841 |
} else { |
| 6842 |
drawRowFunc = &Splash::drawImageRowNoClipNoAlpha; |
| 6843 |
} |
| 6844 |
} else { |
| 6845 |
if (srcAlpha) { |
| 6846 |
if (vectorAntialias) { |
| 6847 |
drawRowFunc = &Splash::drawImageRowClipAlphaAA; |
| 6848 |
} else { |
| 6849 |
drawRowFunc = &Splash::drawImageRowClipAlphaNoAA; |
| 6850 |
} |
| 6851 |
} else { |
| 6852 |
if (vectorAntialias) { |
| 6853 |
drawRowFunc = &Splash::drawImageRowClipNoAlphaAA; |
| 6854 |
} else { |
| 6855 |
drawRowFunc = &Splash::drawImageRowClipNoAlphaNoAA; |
| 6856 |
} |
| 6857 |
} |
| 6858 |
} |
| 6859 |
|
| 6860 |
//--- horizontal/vertical flips only |
| 6861 |
if (flipsOnly && !veryLarge) { |
| 6862 |
int scaledWidth = xMax - xMin; |
| 6863 |
int scaledHeight = yMax - yMin; |
| 6864 |
ImageScaler *scaler = getImageScaler(imageTag, src, srcData, |
| 6865 |
w, h, nComps, |
| 6866 |
scaledWidth, scaledHeight, |
| 6867 |
srcMode, srcAlpha, interpolate); |
| 6868 |
Guchar *tmpLine = NULL; |
| 6869 |
Guchar *tmpAlphaLine = NULL; |
| 6870 |
if (horizFlip) { |
| 6871 |
tmpLine = (Guchar *)gmallocn(scaledWidth, nComps); |
| 6872 |
if (srcAlpha) { |
| 6873 |
tmpAlphaLine = (Guchar *)gmalloc(scaledWidth); |
| 6874 |
} |
| 6875 |
} |
| 6876 |
if (vertFlip) { |
| 6877 |
if (horizFlip) { // bottom-up, mirrored |
| 6878 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6879 |
scaler->nextLine(); |
| 6880 |
mirrorImageRow(scaler->colorData(), scaler->alphaData(), |
| 6881 |
tmpLine, tmpAlphaLine, |
| 6882 |
scaledWidth, nComps, srcAlpha); |
| 6883 |
(this->*drawRowFunc)(&dd, tmpLine, tmpAlphaLine, |
| 6884 |
xMin, yMax - 1 - y, scaledWidth); |
| 6885 |
} |
| 6886 |
} else { // bottom-up |
| 6887 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6888 |
scaler->nextLine(); |
| 6889 |
(this->*drawRowFunc)(&dd, scaler->colorData(), scaler->alphaData(), |
| 6890 |
xMin, yMax - 1 - y, scaledWidth); |
| 6891 |
} |
| 6892 |
} |
| 6893 |
} else { |
| 6894 |
if (horizFlip) { // top-down, mirrored |
| 6895 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6896 |
scaler->nextLine(); |
| 6897 |
mirrorImageRow(scaler->colorData(), scaler->alphaData(), |
| 6898 |
tmpLine, tmpAlphaLine, |
| 6899 |
scaledWidth, nComps, srcAlpha); |
| 6900 |
(this->*drawRowFunc)(&dd, tmpLine, tmpAlphaLine, |
| 6901 |
xMin, yMin + y, scaledWidth); |
| 6902 |
} |
| 6903 |
} else { // top-down |
| 6904 |
for (int y = 0; y < scaledHeight; ++y) { |
| 6905 |
scaler->nextLine(); |
| 6906 |
(this->*drawRowFunc)(&dd, scaler->colorData(), scaler->alphaData(), |
| 6907 |
xMin, yMin + y, scaledWidth); |
| 6908 |
} |
| 6909 |
} |
| 6910 |
} |
| 6911 |
gfree(tmpLine); |
| 6912 |
gfree(tmpAlphaLine); |
| 6913 |
delete scaler; |
| 6914 |
|
| 6915 |
//--- 90/270 rotation |
| 6916 |
} else if (rot90Only && !veryLarge) { |
| 6917 |
|
| 6918 |
// scale the image |
| 6919 |
int scaledWidth = yMax - yMin; |
| 6920 |
int scaledHeight = xMax - xMin; |
| 6921 |
Guchar *scaledColor, *scaledAlpha; |
| 6922 |
GBool freeScaledImage; |
| 6923 |
getScaledImage(imageTag, src, srcData, w, h, nComps, |
| 6924 |
scaledWidth, scaledHeight, srcMode, srcAlpha, interpolate, |
| 6925 |
&scaledColor, &scaledAlpha, &freeScaledImage); |
| 6926 |
|
| 6927 |
// draw it |
| 6928 |
Guchar *tmpLine = (Guchar *)gmallocn(scaledHeight, nComps); |
| 6929 |
Guchar *tmpAlphaLine = NULL; |
| 6930 |
if (srcAlpha) { |
| 6931 |
tmpAlphaLine = (Guchar *)gmalloc(scaledHeight); |
| 6932 |
} |
| 6933 |
for (int y = 0; y < scaledWidth; ++y) { |
| 6934 |
Guchar *ptr = NULL; |
| 6935 |
Guchar *alphaPtr = NULL; |
| 6936 |
if (vertFlip) { |
| 6937 |
ptr = scaledColor + ((SplashBitmapRowSize)scaledWidth - 1 - y) * nComps; |
| 6938 |
if (srcAlpha) { |
| 6939 |
alphaPtr = scaledAlpha + (scaledWidth - 1 - y); |
| 6940 |
} |
| 6941 |
} else { |
| 6942 |
ptr = scaledColor + y * nComps; |
| 6943 |
if (srcAlpha) { |
| 6944 |
alphaPtr = scaledAlpha + y; |
| 6945 |
} |
| 6946 |
} |
| 6947 |
if (horizFlip) { |
| 6948 |
ptr += (scaledHeight - 1) * (SplashBitmapRowSize)scaledWidth * nComps; |
| 6949 |
Guchar *q = tmpLine; |
| 6950 |
for (int x = 0; x < scaledHeight; ++x) { |
| 6951 |
for (int i = 0; i < nComps; ++i) { |
| 6952 |
*q++ = ptr[i]; |
| 6953 |
} |
| 6954 |
ptr -= scaledWidth * nComps; |
| 6955 |
} |
| 6956 |
if (srcAlpha) { |
| 6957 |
alphaPtr += (scaledHeight - 1) * (SplashBitmapRowSize)scaledWidth; |
| 6958 |
q = tmpAlphaLine; |
| 6959 |
for (int x = 0; x < scaledHeight; ++x) { |
| 6960 |
*q++ = *alphaPtr; |
| 6961 |
alphaPtr -= scaledWidth; |
| 6962 |
} |
| 6963 |
} |
| 6964 |
} else { |
| 6965 |
Guchar *q = tmpLine; |
| 6966 |
for (int x = 0; x < scaledHeight; ++x) { |
| 6967 |
for (int i = 0; i < nComps; ++i) { |
| 6968 |
*q++ = ptr[i]; |
| 6969 |
} |
| 6970 |
ptr += scaledWidth * nComps; |
| 6971 |
} |
| 6972 |
if (srcAlpha) { |
| 6973 |
q = tmpAlphaLine; |
| 6974 |
for (int x = 0; x < scaledHeight; ++x) { |
| 6975 |
*q++ = *alphaPtr; |
| 6976 |
alphaPtr += scaledWidth; |
| 6977 |
} |
| 6978 |
} |
| 6979 |
} |
| 6980 |
(this->*drawRowFunc)(&dd, tmpLine, tmpAlphaLine, |
| 6981 |
xMin, yMin + y, scaledHeight); |
| 6982 |
} |
| 6983 |
|
| 6984 |
gfree(tmpLine); |
| 6985 |
gfree(tmpAlphaLine); |
| 6986 |
if (freeScaledImage) { |
| 6987 |
gfree(scaledColor); |
| 6988 |
gfree(scaledAlpha); |
| 6989 |
} |
| 6990 |
|
| 6991 |
//--- arbitrary transform |
| 6992 |
} else { |
| 6993 |
// estimate of size of scaled image |
| 6994 |
int scaledWidth = splashRound(splashSqrt(mat[0] * mat[0] |
| 6995 |
+ mat[1] * mat[1])); |
| 6996 |
int scaledHeight = splashRound(splashSqrt(mat[2] * mat[2] |
| 6997 |
+ mat[3] * mat[3])); |
| 6998 |
if (scaledWidth < 1) { |
| 6999 |
scaledWidth = 1; |
| 7000 |
} |
| 7001 |
if (scaledHeight < 1) { |
| 7002 |
scaledHeight = 1; |
| 7003 |
} |
| 7004 |
if (scaledWidth >= w && scaledHeight >= h) { |
| 7005 |
scaledWidth = w; |
| 7006 |
scaledHeight = h; |
| 7007 |
} |
| 7008 |
|
| 7009 |
// compute mapping from device space to scaled image space |
| 7010 |
SplashCoord mat1[6]; |
| 7011 |
mat1[0] = mat[0] / scaledWidth; |
| 7012 |
mat1[1] = mat[1] / scaledWidth; |
| 7013 |
mat1[2] = mat[2] / scaledHeight; |
| 7014 |
mat1[3] = mat[3] / scaledHeight; |
| 7015 |
mat1[4] = mat[4]; |
| 7016 |
mat1[5] = mat[5]; |
| 7017 |
SplashCoord det = mat1[0] * mat1[3] - mat1[1] * mat1[2]; |
| 7018 |
if (splashAbs(det) < 1e-6) { |
| 7019 |
// this should be caught by the singular matrix check in drawImage |
| 7020 |
return splashErrSingularMatrix; |
| 7021 |
} |
| 7022 |
SplashCoord invMat[6]; |
| 7023 |
invMat[0] = mat1[3] / det; |
| 7024 |
invMat[1] = -mat1[1] / det; |
| 7025 |
invMat[2] = -mat1[2] / det; |
| 7026 |
invMat[3] = mat1[0] / det; |
| 7027 |
// the extra "+ 0.5 * (...)" terms are here because the |
| 7028 |
// drawImageArbitrary(No)Interp functions multiply by pixel |
| 7029 |
// centers, (x + 0.5, y + 0.5) |
| 7030 |
invMat[4] = (mat1[2] * mat1[5] - mat1[3] * mat1[4]) / det |
| 7031 |
+ (invMat[0] + invMat[2]) * 0.5; |
| 7032 |
invMat[5] = (mat1[1] * mat1[4] - mat1[0] * mat1[5]) / det |
| 7033 |
+ (invMat[1] + invMat[3]) * 0.5; |
| 7034 |
|
| 7035 |
Guchar *scaledColor, *scaledAlpha; |
| 7036 |
GBool freeScaledImage; |
| 7037 |
getScaledImage(imageTag, src, srcData, w, h, nComps, |
| 7038 |
scaledWidth, scaledHeight, srcMode, srcAlpha, interpolate, |
| 7039 |
&scaledColor, &scaledAlpha, &freeScaledImage); |
| 7040 |
|
| 7041 |
// draw it |
| 7042 |
if (interpolate) { |
| 7043 |
drawImageArbitraryInterp(scaledColor, scaledAlpha, |
| 7044 |
&dd, drawRowFunc, invMat, |
| 7045 |
scaledWidth, scaledHeight, |
| 7046 |
xMin, yMin, xMax, yMax, |
| 7047 |
nComps, srcAlpha); |
| 7048 |
} else { |
| 7049 |
drawImageArbitraryNoInterp(scaledColor, scaledAlpha, |
| 7050 |
&dd, drawRowFunc, invMat, |
| 7051 |
scaledWidth, scaledHeight, |
| 7052 |
xMin, yMin, xMax, yMax, |
| 7053 |
nComps, srcAlpha); |
| 7054 |
} |
| 7055 |
|
| 7056 |
// free the downscaled/unscaled image |
| 7057 |
if (freeScaledImage) { |
| 7058 |
gfree(scaledColor); |
| 7059 |
gfree(scaledAlpha); |
| 7060 |
} |
| 7061 |
} |
| 7062 |
|
| 7063 |
return splashOk; |
| 7064 |
} |
| 7065 |
|
| 7066 |
ImageScaler *Splash::getImageScaler(GString *imageTag, |
| 7067 |
SplashImageSource src, void *srcData, |
| 7068 |
int w, int h, int nComps, |
| 7069 |
int scaledWidth, int scaledHeight, |
| 7070 |
SplashColorMode srcMode, |
| 7071 |
GBool srcAlpha, GBool interpolate) { |
| 7072 |
// Notes: |
| 7073 |
// |
| 7074 |
// * If the scaled image is more than 8 Mpixels, we don't cache it. |
| 7075 |
// |
| 7076 |
// * Caching is done on the third consecutive use (second |
| 7077 |
// consecutive reuse) of an image; this avoids overhead on the |
| 7078 |
// common case of single-use images. |
| 7079 |
|
| 7080 |
if (scaledWidth < 8000000 / scaledHeight && |
| 7081 |
imageCache->match(imageTag, scaledWidth, scaledHeight, |
| 7082 |
srcMode, srcAlpha, interpolate)) { |
| 7083 |
if (imageCache->colorData) { |
| 7084 |
return new ReplayImageScaler(nComps, srcAlpha, scaledWidth, |
| 7085 |
imageCache->colorData, |
| 7086 |
imageCache->alphaData); |
| 7087 |
} else { |
| 7088 |
int lineSize; |
| 7089 |
if (scaledWidth < INT_MAX / nComps) { |
| 7090 |
lineSize = scaledWidth * nComps; |
| 7091 |
} else { |
| 7092 |
lineSize = -1; |
| 7093 |
} |
| 7094 |
imageCache->colorData = (Guchar *)gmallocn64(scaledHeight, lineSize); |
| 7095 |
if (srcAlpha) { |
| 7096 |
imageCache->alphaData = (Guchar *)gmallocn64(scaledHeight, scaledWidth); |
| 7097 |
} |
| 7098 |
return new SavingImageScaler(src, srcData, |
| 7099 |
w, h, nComps, srcAlpha, |
| 7100 |
scaledWidth, scaledHeight, |
| 7101 |
interpolate, |
| 7102 |
imageCache->colorData, |
| 7103 |
imageCache->alphaData); |
| 7104 |
} |
| 7105 |
} else { |
| 7106 |
imageCache->reset(imageTag, scaledWidth, scaledHeight, |
| 7107 |
srcMode, srcAlpha, interpolate); |
| 7108 |
return new BasicImageScaler(src, srcData, |
| 7109 |
w, h, nComps, srcAlpha, |
| 7110 |
scaledWidth, scaledHeight, |
| 7111 |
interpolate); |
| 7112 |
} |
| 7113 |
} |
| 7114 |
|
| 7115 |
void Splash::getScaledImage(GString *imageTag, |
| 7116 |
SplashImageSource src, void *srcData, |
| 7117 |
int w, int h, int nComps, |
| 7118 |
int scaledWidth, int scaledHeight, |
| 7119 |
SplashColorMode srcMode, |
| 7120 |
GBool srcAlpha, GBool interpolate, |
| 7121 |
Guchar **scaledColor, Guchar **scaledAlpha, |
| 7122 |
GBool *freeScaledImage) { |
| 7123 |
// Notes: |
| 7124 |
// |
| 7125 |
// * If the scaled image is more than 8 Mpixels, we don't cache it. |
| 7126 |
// |
| 7127 |
// * This buffers the whole image anyway, so there's no reason to |
| 7128 |
// skip caching on the first reuse. |
| 7129 |
|
| 7130 |
if (scaledWidth >= 8000000 / scaledHeight) { |
| 7131 |
int lineSize; |
| 7132 |
if (scaledWidth < INT_MAX / nComps) { |
| 7133 |
lineSize = scaledWidth * nComps; |
| 7134 |
} else { |
| 7135 |
lineSize = -1; |
| 7136 |
} |
| 7137 |
*scaledColor = (Guchar *)gmallocn64(scaledHeight, lineSize); |
| 7138 |
if (srcAlpha) { |
| 7139 |
*scaledAlpha = (Guchar *)gmallocn64(scaledHeight, scaledWidth); |
| 7140 |
} else { |
| 7141 |
*scaledAlpha = NULL; |
| 7142 |
} |
| 7143 |
*freeScaledImage = gTrue; |
| 7144 |
if (scaledWidth == w && scaledHeight == h) { |
| 7145 |
Guchar *colorPtr = *scaledColor; |
| 7146 |
Guchar *alphaPtr = *scaledAlpha; |
| 7147 |
for (int y = 0; y < scaledHeight; ++y) { |
| 7148 |
(*src)(srcData, colorPtr, alphaPtr); |
| 7149 |
colorPtr += scaledWidth * nComps; |
| 7150 |
if (srcAlpha) { |
| 7151 |
alphaPtr += scaledWidth; |
| 7152 |
} |
| 7153 |
} |
| 7154 |
} else { |
| 7155 |
BasicImageScaler scaler(src, srcData, w, h, nComps, srcAlpha, |
| 7156 |
scaledWidth, scaledHeight, interpolate); |
| 7157 |
Guchar *colorPtr = *scaledColor; |
| 7158 |
Guchar *alphaPtr = *scaledAlpha; |
| 7159 |
for (int y = 0; y < scaledHeight; ++y) { |
| 7160 |
scaler.nextLine(); |
| 7161 |
memcpy(colorPtr, scaler.colorData(), scaledWidth * nComps); |
| 7162 |
colorPtr += scaledWidth * nComps; |
| 7163 |
if (srcAlpha) { |
| 7164 |
memcpy(alphaPtr, scaler.alphaData(), scaledWidth); |
| 7165 |
alphaPtr += scaledWidth; |
| 7166 |
} |
| 7167 |
} |
| 7168 |
} |
| 7169 |
} else { |
| 7170 |
if (!imageCache->match(imageTag, scaledWidth, scaledHeight, |
| 7171 |
srcMode, srcAlpha, interpolate) || |
| 7172 |
!imageCache->colorData) { |
| 7173 |
imageCache->reset(imageTag, scaledWidth, scaledHeight, |
| 7174 |
srcMode, srcAlpha, interpolate); |
| 7175 |
int lineSize; |
| 7176 |
if (scaledWidth < INT_MAX / nComps) { |
| 7177 |
lineSize = scaledWidth * nComps; |
| 7178 |
} else { |
| 7179 |
lineSize = -1; |
| 7180 |
} |
| 7181 |
imageCache->colorData = (Guchar *)gmallocn64(scaledHeight, lineSize); |
| 7182 |
if (srcAlpha) { |
| 7183 |
imageCache->alphaData = (Guchar *)gmallocn64(scaledHeight, scaledWidth); |
| 7184 |
} |
| 7185 |
if (scaledWidth == w && scaledHeight == h) { |
| 7186 |
Guchar *colorPtr = imageCache->colorData; |
| 7187 |
Guchar *alphaPtr = imageCache->alphaData; |
| 7188 |
for (int y = 0; y < scaledHeight; ++y) { |
| 7189 |
(*src)(srcData, colorPtr, alphaPtr); |
| 7190 |
colorPtr += scaledWidth * nComps; |
| 7191 |
if (srcAlpha) { |
| 7192 |
alphaPtr += scaledWidth; |
| 7193 |
} |
| 7194 |
} |
| 7195 |
} else { |
| 7196 |
SavingImageScaler scaler(src, srcData, w, h, nComps, srcAlpha, |
| 7197 |
scaledWidth, scaledHeight, interpolate, |
| 7198 |
imageCache->colorData, imageCache->alphaData); |
| 7199 |
Guchar *colorPtr = imageCache->colorData; |
| 7200 |
Guchar *alphaPtr = imageCache->alphaData; |
| 7201 |
for (int y = 0; y < scaledHeight; ++y) { |
| 7202 |
scaler.nextLine(); |
| 7203 |
memcpy(colorPtr, scaler.colorData(), scaledWidth * nComps); |
| 7204 |
colorPtr += scaledWidth * nComps; |
| 7205 |
if (srcAlpha) { |
| 7206 |
memcpy(alphaPtr, scaler.alphaData(), scaledWidth); |
| 7207 |
alphaPtr += scaledWidth; |
| 7208 |
} |
| 7209 |
} |
| 7210 |
} |
| 7211 |
} |
| 7212 |
*scaledColor = imageCache->colorData; |
| 7213 |
*scaledAlpha = imageCache->alphaData; |
| 7214 |
*freeScaledImage = gFalse; |
| 7215 |
} |
| 7216 |
} |
| 7217 |
|
| 7218 |
void Splash::drawImageArbitraryNoInterp(Guchar *scaledColor, |
| 7219 |
Guchar *scaledAlpha, |
| 7220 |
SplashDrawImageRowData *dd, |
| 7221 |
SplashDrawImageRowFunc drawRowFunc, |
| 7222 |
SplashCoord *invMat, |
| 7223 |
int scaledWidth, int scaledHeight, |
| 7224 |
int xMin, int yMin, int xMax, int yMax, |
| 7225 |
int nComps, GBool srcAlpha) { |
| 7226 |
int tt = state->clip->getXMinI(state->strokeAdjust); |
| 7227 |
if (tt > xMin) { |
| 7228 |
xMin = tt; |
| 7229 |
} |
| 7230 |
tt = state->clip->getXMaxI(state->strokeAdjust) + 1; |
| 7231 |
if (tt < xMax) { |
| 7232 |
xMax = tt; |
| 7233 |
} |
| 7234 |
tt = state->clip->getYMinI(state->strokeAdjust); |
| 7235 |
if (tt > yMin) { |
| 7236 |
yMin = tt; |
| 7237 |
} |
| 7238 |
tt = state->clip->getYMaxI(state->strokeAdjust) + 1; |
| 7239 |
if (tt < yMax) { |
| 7240 |
yMax = tt; |
| 7241 |
} |
| 7242 |
if (xMax <= xMin || yMax <= yMin) { |
| 7243 |
return; |
| 7244 |
} |
| 7245 |
|
| 7246 |
Guchar *colorBuf = (Guchar *)gmallocn(xMax - xMin, nComps); |
| 7247 |
Guchar *alphaBuf = NULL; |
| 7248 |
if (srcAlpha) { |
| 7249 |
alphaBuf = (Guchar *)gmalloc(xMax - xMin); |
| 7250 |
} |
| 7251 |
|
| 7252 |
for (int y = yMin; y < yMax; ++y) { |
| 7253 |
int rowMin = xMax; |
| 7254 |
int rowMax = 0; |
| 7255 |
for (int x = xMin; x < xMax; ++x) { |
| 7256 |
// note: invMat includes a "+0.5" factor so that this is really |
| 7257 |
// a multiply by (x+0.5, y+0.5) |
| 7258 |
int xx = splashFloor((SplashCoord)x * invMat[0] |
| 7259 |
+ (SplashCoord)y * invMat[2] + invMat[4]); |
| 7260 |
int yy = splashFloor((SplashCoord)x * invMat[1] |
| 7261 |
+ (SplashCoord)y * invMat[3] + invMat[5]); |
| 7262 |
if (xx >= 0 && xx < scaledWidth && |
| 7263 |
yy >= 0 && yy < scaledHeight) { |
| 7264 |
Guchar *p = scaledColor + |
| 7265 |
(yy * (SplashBitmapRowSize)scaledWidth + xx) * nComps; |
| 7266 |
Guchar *q = colorBuf + (x - xMin) * nComps; |
| 7267 |
for (int i = 0; i < nComps; ++i) { |
| 7268 |
*q++ = *p++; |
| 7269 |
} |
| 7270 |
if (srcAlpha) { |
| 7271 |
alphaBuf[x - xMin] = |
| 7272 |
scaledAlpha[yy * (SplashBitmapRowSize)scaledWidth + xx]; |
| 7273 |
} |
| 7274 |
if (x < rowMin) { |
| 7275 |
rowMin = x; |
| 7276 |
} |
| 7277 |
rowMax = x + 1; |
| 7278 |
} |
| 7279 |
} |
| 7280 |
if (rowMin < rowMax) { |
| 7281 |
(this->*drawRowFunc)(dd, |
| 7282 |
colorBuf + (rowMin - xMin) * nComps, |
| 7283 |
alphaBuf + (rowMin - xMin), |
| 7284 |
rowMin, y, rowMax - rowMin); |
| 7285 |
} |
| 7286 |
} |
| 7287 |
|
| 7288 |
gfree(colorBuf); |
| 7289 |
gfree(alphaBuf); |
| 7290 |
} |
| 7291 |
|
| 7292 |
void Splash::drawImageArbitraryInterp(Guchar *scaledColor, Guchar *scaledAlpha, |
| 7293 |
SplashDrawImageRowData *dd, |
| 7294 |
SplashDrawImageRowFunc drawRowFunc, |
| 7295 |
SplashCoord *invMat, |
| 7296 |
int scaledWidth, int scaledHeight, |
| 7297 |
int xMin, int yMin, int xMax, int yMax, |
| 7298 |
int nComps, GBool srcAlpha) { |
| 7299 |
int tt = state->clip->getXMinI(state->strokeAdjust); |
| 7300 |
if (tt > xMin) { |
| 7301 |
xMin = tt; |
| 7302 |
} |
| 7303 |
tt = state->clip->getXMaxI(state->strokeAdjust) + 1; |
| 7304 |
if (tt < xMax) { |
| 7305 |
xMax = tt; |
| 7306 |
} |
| 7307 |
tt = state->clip->getYMinI(state->strokeAdjust); |
| 7308 |
if (tt > yMin) { |
| 7309 |
yMin = tt; |
| 7310 |
} |
| 7311 |
tt = state->clip->getYMaxI(state->strokeAdjust) + 1; |
| 7312 |
if (tt < yMax) { |
| 7313 |
yMax = tt; |
| 7314 |
} |
| 7315 |
if (xMax <= xMin || yMax <= yMin) { |
| 7316 |
return; |
| 7317 |
} |
| 7318 |
|
| 7319 |
Guchar *colorBuf = (Guchar *)gmallocn(xMax - xMin, nComps); |
| 7320 |
Guchar *alphaBuf = NULL; |
| 7321 |
if (srcAlpha) { |
| 7322 |
alphaBuf = (Guchar *)gmalloc(xMax - xMin); |
| 7323 |
} |
| 7324 |
|
| 7325 |
for (int y = yMin; y < yMax; ++y) { |
| 7326 |
int rowMin = xMax; |
| 7327 |
int rowMax = 0; |
| 7328 |
for (int x = xMin; x < xMax; ++x) { |
| 7329 |
// note: invMat includes a "+0.5" factor so that this is really |
| 7330 |
// a multiply by (x+0.5, y+0.5) |
| 7331 |
SplashCoord xs = (SplashCoord)x * invMat[0] |
| 7332 |
+ (SplashCoord)y * invMat[2] + invMat[4]; |
| 7333 |
SplashCoord ys = (SplashCoord)x * invMat[1] |
| 7334 |
+ (SplashCoord)y * invMat[3] + invMat[5]; |
| 7335 |
int x0 = splashFloor(xs - 0.5); |
| 7336 |
int x1 = x0 + 1; |
| 7337 |
int y0 = splashFloor(ys - 0.5); |
| 7338 |
int y1 = y0 + 1; |
| 7339 |
if (x1 >= 0 && x0 < scaledWidth && y1 >= 0 && y0 < scaledHeight) { |
| 7340 |
SplashCoord sx0 = (SplashCoord)x1 + 0.5 - xs; |
| 7341 |
SplashCoord sx1 = (SplashCoord)1 - sx0; |
| 7342 |
SplashCoord sy0 = (SplashCoord)y1 + 0.5 - ys; |
| 7343 |
SplashCoord sy1 = (SplashCoord)1 - sy0; |
| 7344 |
if (x0 < 0) { |
| 7345 |
x0 = 0; |
| 7346 |
} |
| 7347 |
if (x1 >= scaledWidth) { |
| 7348 |
x1 = scaledWidth - 1; |
| 7349 |
} |
| 7350 |
if (y0 < 0) { |
| 7351 |
y0 = 0; |
| 7352 |
} |
| 7353 |
if (y1 >= scaledHeight) { |
| 7354 |
y1 = scaledHeight - 1; |
| 7355 |
} |
| 7356 |
Guchar *p00 = scaledColor + |
| 7357 |
(y0 * (SplashBitmapRowSize)scaledWidth + x0) * nComps; |
| 7358 |
Guchar *p10 = scaledColor + |
| 7359 |
(y0 * (SplashBitmapRowSize)scaledWidth + x1) * nComps; |
| 7360 |
Guchar *p01 = scaledColor + |
| 7361 |
(y1 * (SplashBitmapRowSize)scaledWidth + x0) * nComps; |
| 7362 |
Guchar *p11 = scaledColor + |
| 7363 |
(y1 * (SplashBitmapRowSize)scaledWidth + x1) * nComps; |
| 7364 |
Guchar *q = colorBuf + (x - xMin) * nComps; |
| 7365 |
for (int i = 0; i < nComps; ++i) { |
| 7366 |
*q++ = (Guchar)(int)(sx0 * (sy0 * (int)*p00++ + sy1 * (int)*p01++) + |
| 7367 |
sx1 * (sy0 * (int)*p10++ + sy1 * (int)*p11++)); |
| 7368 |
} |
| 7369 |
if (srcAlpha) { |
| 7370 |
p00 = scaledAlpha + (y0 * (SplashBitmapRowSize)scaledWidth + x0); |
| 7371 |
p10 = scaledAlpha + (y0 * (SplashBitmapRowSize)scaledWidth + x1); |
| 7372 |
p01 = scaledAlpha + (y1 * (SplashBitmapRowSize)scaledWidth + x0); |
| 7373 |
p11 = scaledAlpha + (y1 * (SplashBitmapRowSize)scaledWidth + x1); |
| 7374 |
q = alphaBuf + (x - xMin); |
| 7375 |
*q = (Guchar)(int)(sx0 * (sy0 * (int)*p00 + sy1 * (int)*p01) + |
| 7376 |
sx1 * (sy0 * (int)*p10 + sy1 * (int)*p11)); |
| 7377 |
} |
| 7378 |
if (x < rowMin) { |
| 7379 |
rowMin = x; |
| 7380 |
} |
| 7381 |
rowMax = x + 1; |
| 7382 |
} |
| 7383 |
} |
| 7384 |
if (rowMin < rowMax) { |
| 7385 |
(this->*drawRowFunc)(dd, |
| 7386 |
colorBuf + (rowMin - xMin) * nComps, |
| 7387 |
alphaBuf + (rowMin - xMin), |
| 7388 |
rowMin, y, rowMax - rowMin); |
| 7389 |
} |
| 7390 |
} |
| 7391 |
|
| 7392 |
gfree(colorBuf); |
| 7393 |
gfree(alphaBuf); |
| 7394 |
} |
| 7395 |
|
| 7396 |
void Splash::mirrorImageRow(Guchar *colorIn, Guchar *alphaIn, |
| 7397 |
Guchar *colorOut, Guchar *alphaOut, |
| 7398 |
int width, int nComps, GBool srcAlpha) { |
| 7399 |
Guchar *p, *q; |
| 7400 |
|
| 7401 |
p = colorIn; |
| 7402 |
q = colorOut + (width - 1) * nComps; |
| 7403 |
for (int i = 0; i < width; ++i) { |
| 7404 |
for (int j = 0; j < nComps; ++j) { |
| 7405 |
q[j] = p[j]; |
| 7406 |
} |
| 7407 |
p += nComps; |
| 7408 |
q -= nComps; |
| 7409 |
} |
| 7410 |
|
| 7411 |
if (srcAlpha) { |
| 7412 |
p = alphaIn; |
| 7413 |
q = alphaOut + (width - 1); |
| 7414 |
for (int i = 0; i < width; ++i) { |
| 7415 |
*q = *p; |
| 7416 |
++p; |
| 7417 |
--q; |
| 7418 |
} |
| 7419 |
} |
| 7420 |
} |
| 7421 |
|
| 7422 |
void Splash::drawImageRowNoClipNoAlpha(SplashDrawImageRowData *data, |
| 7423 |
Guchar *colorData, Guchar *alphaData, |
| 7424 |
int x, int y, int width) { |
| 7425 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 7426 |
NULL, NULL, colorData); |
| 7427 |
} |
| 7428 |
|
| 7429 |
void Splash::drawImageRowNoClipAlpha(SplashDrawImageRowData *data, |
| 7430 |
Guchar *colorData, Guchar *alphaData, |
| 7431 |
int x, int y, int width) { |
| 7432 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 7433 |
NULL, alphaData, colorData); |
| 7434 |
} |
| 7435 |
|
| 7436 |
void Splash::drawImageRowClipNoAlphaNoAA(SplashDrawImageRowData *data, |
| 7437 |
Guchar *colorData, |
| 7438 |
Guchar *alphaData, |
| 7439 |
int x, int y, int width) { |
| 7440 |
if (y < 0 || y >= bitmap->height) { |
| 7441 |
return; |
| 7442 |
} |
| 7443 |
if (x < 0) { |
| 7444 |
colorData -= x * data->nComps; |
| 7445 |
width += x; |
| 7446 |
x = 0; |
| 7447 |
} |
| 7448 |
if (x + width > bitmap->width) { |
| 7449 |
width = bitmap->width - x; |
| 7450 |
} |
| 7451 |
if (width <= 0) { |
| 7452 |
return; |
| 7453 |
} |
| 7454 |
memset(scanBuf + x, 0xff, width); |
| 7455 |
state->clip->clipSpanBinary(scanBuf, y, x, x + width - 1, |
| 7456 |
state->strokeAdjust); |
| 7457 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 7458 |
NULL, scanBuf + x, colorData); |
| 7459 |
} |
| 7460 |
|
| 7461 |
void Splash::drawImageRowClipNoAlphaAA(SplashDrawImageRowData *data, |
| 7462 |
Guchar *colorData, |
| 7463 |
Guchar *alphaData, |
| 7464 |
int x, int y, int width) { |
| 7465 |
if (y < 0 || y >= bitmap->height) { |
| 7466 |
return; |
| 7467 |
} |
| 7468 |
if (x < 0) { |
| 7469 |
colorData -= x * data->nComps; |
| 7470 |
width += x; |
| 7471 |
x = 0; |
| 7472 |
} |
| 7473 |
if (x + width > bitmap->width) { |
| 7474 |
width = bitmap->width - x; |
| 7475 |
} |
| 7476 |
if (width <= 0) { |
| 7477 |
return; |
| 7478 |
} |
| 7479 |
memset(scanBuf + x, 0xff, width); |
| 7480 |
state->clip->clipSpan(scanBuf, y, x, x + width - 1, state->strokeAdjust); |
| 7481 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 7482 |
NULL, scanBuf + x, colorData); |
| 7483 |
} |
| 7484 |
|
| 7485 |
void Splash::drawImageRowClipAlphaNoAA(SplashDrawImageRowData *data, |
| 7486 |
Guchar *colorData, |
| 7487 |
Guchar *alphaData, |
| 7488 |
int x, int y, int width) { |
| 7489 |
if (y < 0 || y >= bitmap->height) { |
| 7490 |
return; |
| 7491 |
} |
| 7492 |
if (x < 0) { |
| 7493 |
colorData -= x * data->nComps; |
| 7494 |
alphaData -= x; |
| 7495 |
width += x; |
| 7496 |
x = 0; |
| 7497 |
} |
| 7498 |
if (x + width > bitmap->width) { |
| 7499 |
width = bitmap->width - x; |
| 7500 |
} |
| 7501 |
if (width <= 0) { |
| 7502 |
return; |
| 7503 |
} |
| 7504 |
memcpy(scanBuf + x, alphaData, width); |
| 7505 |
state->clip->clipSpanBinary(scanBuf, y, x, x + width - 1, |
| 7506 |
state->strokeAdjust); |
| 7507 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 7508 |
NULL, scanBuf + x, colorData); |
| 7509 |
} |
| 7510 |
|
| 7511 |
void Splash::drawImageRowClipAlphaAA(SplashDrawImageRowData *data, |
| 7512 |
Guchar *colorData, |
| 7513 |
Guchar *alphaData, |
| 7514 |
int x, int y, int width) { |
| 7515 |
if (y < 0 || y >= bitmap->height) { |
| 7516 |
return; |
| 7517 |
} |
| 7518 |
if (x < 0) { |
| 7519 |
colorData -= x * data->nComps; |
| 7520 |
alphaData -= x; |
| 7521 |
width += x; |
| 7522 |
x = 0; |
| 7523 |
} |
| 7524 |
if (x + width > bitmap->width) { |
| 7525 |
width = bitmap->width - x; |
| 7526 |
} |
| 7527 |
if (width <= 0) { |
| 7528 |
return; |
| 7529 |
} |
| 7530 |
memcpy(scanBuf + x, alphaData, width); |
| 7531 |
state->clip->clipSpan(scanBuf, y, x, x + width - 1, state->strokeAdjust); |
| 7532 |
(this->*data->pipe.run)(&data->pipe, x, x + width - 1, y, |
| 7533 |
NULL, scanBuf + x, colorData); |
| 7534 |
} |
| 7535 |
|
| 7536 |
SplashError Splash::composite(SplashBitmap *src, SplashAlphaBitmap *srcShape, |
| 7537 |
int xSrc, int ySrc, int xDest, int yDest, |
| 7538 |
int w, int h, GBool noClip, GBool nonIsolated) { |
| 7539 |
SplashPipe pipe; |
| 7540 |
Guchar *mono1Ptr, *lineBuf, *linePtr; |
| 7541 |
Guchar mono1Mask, b; |
| 7542 |
int x0, x1, x, y0, y1, y, t; |
| 7543 |
|
| 7544 |
if (!(src->mode == bitmap->mode || |
| 7545 |
(src->mode == splashModeMono8 && bitmap->mode == splashModeMono1) || |
| 7546 |
(src->mode == splashModeRGB8 && bitmap->mode == splashModeBGR8))) { |
| 7547 |
return splashErrModeMismatch; |
| 7548 |
} |
| 7549 |
|
| 7550 |
GBool usesShape = srcShape && shapeBitmap && src->alpha; |
| 7551 |
GBool usesAlpha = !noClip || src->alpha; |
| 7552 |
pipeInit(&pipe, NULL, |
| 7553 |
(Guchar)splashRound(state->fillAlpha * 255), |
| 7554 |
usesShape, usesAlpha, nonIsolated); |
| 7555 |
if (src->mode == splashModeMono1) { |
| 7556 |
// in mono1 mode, pipeRun expects the source to be in mono8 |
| 7557 |
// format, so we need to extract the source color values into |
| 7558 |
// scanBuf, expanding them from mono1 to mono8 |
| 7559 |
if (noClip) { |
| 7560 |
if (usesShape) { |
| 7561 |
for (y = 0; y < h; ++y) { |
| 7562 |
mono1Ptr = src->data + (ySrc + y) * src->rowSize + (xSrc >> 3); |
| 7563 |
mono1Mask = (Guchar)(0x80 >> (xSrc & 7)); |
| 7564 |
for (x = 0; x < w; ++x) { |
| 7565 |
scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; |
| 7566 |
mono1Ptr += mono1Mask & 1; |
| 7567 |
mono1Mask = (Guchar)((mono1Mask << 7) | (mono1Mask >> 1)); |
| 7568 |
} |
| 7569 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7570 |
srcShape->alpha + |
| 7571 |
(ySrc + y) * srcShape->alphaRowSize + xSrc, |
| 7572 |
src->alpha + |
| 7573 |
(ySrc + y) * src->alphaRowSize + xSrc, |
| 7574 |
scanBuf); |
| 7575 |
} |
| 7576 |
} else if (usesAlpha) { |
| 7577 |
for (y = 0; y < h; ++y) { |
| 7578 |
mono1Ptr = src->data + (ySrc + y) * src->rowSize + (xSrc >> 3); |
| 7579 |
mono1Mask = (Guchar)(0x80 >> (xSrc & 7)); |
| 7580 |
for (x = 0; x < w; ++x) { |
| 7581 |
scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; |
| 7582 |
mono1Ptr += mono1Mask & 1; |
| 7583 |
mono1Mask = (Guchar)((mono1Mask << 7) | (mono1Mask >> 1)); |
| 7584 |
} |
| 7585 |
// this uses shape instead of alpha, which isn't technically |
| 7586 |
// correct, but works out the same |
| 7587 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7588 |
NULL, |
| 7589 |
src->alpha + |
| 7590 |
(ySrc + y) * src->alphaRowSize + xSrc, |
| 7591 |
scanBuf); |
| 7592 |
} |
| 7593 |
} else { |
| 7594 |
for (y = 0; y < h; ++y) { |
| 7595 |
mono1Ptr = src->data + (ySrc + y) * src->rowSize + (xSrc >> 3); |
| 7596 |
mono1Mask = (Guchar)(0x80 >> (xSrc & 7)); |
| 7597 |
for (x = 0; x < w; ++x) { |
| 7598 |
scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; |
| 7599 |
mono1Ptr += mono1Mask & 1; |
| 7600 |
mono1Mask = (Guchar)((mono1Mask << 7) | (mono1Mask >> 1)); |
| 7601 |
} |
| 7602 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7603 |
NULL, NULL, scanBuf); |
| 7604 |
} |
| 7605 |
} |
| 7606 |
} else { |
| 7607 |
x0 = xDest; |
| 7608 |
if ((t = state->clip->getXMinI(state->strokeAdjust)) > x0) { |
| 7609 |
x0 = t; |
| 7610 |
} |
| 7611 |
x1 = xDest + w; |
| 7612 |
if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < x1) { |
| 7613 |
x1 = t; |
| 7614 |
} |
| 7615 |
y0 = yDest; |
| 7616 |
if ((t = state->clip->getYMinI(state->strokeAdjust)) > y0) { |
| 7617 |
y0 = t; |
| 7618 |
} |
| 7619 |
y1 = yDest + h; |
| 7620 |
if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < y1) { |
| 7621 |
y1 = t; |
| 7622 |
} |
| 7623 |
if (x0 < x1 && y0 < y1) { |
| 7624 |
if (usesShape) { |
| 7625 |
for (y = y0; y < y1; ++y) { |
| 7626 |
mono1Ptr = src->data |
| 7627 |
+ (ySrc + y - yDest) * src->rowSize |
| 7628 |
+ ((xSrc + x0 - xDest) >> 3); |
| 7629 |
mono1Mask = (Guchar)(0x80 >> ((xSrc + x0 - xDest) & 7)); |
| 7630 |
for (x = x0; x < x1; ++x) { |
| 7631 |
scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; |
| 7632 |
mono1Ptr += mono1Mask & 1; |
| 7633 |
mono1Mask = (Guchar)((mono1Mask << 7) | (mono1Mask >> 1)); |
| 7634 |
} |
| 7635 |
memcpy(scanBuf2 + x0, |
| 7636 |
srcShape->alpha + |
| 7637 |
(ySrc + y - yDest) * srcShape->alphaRowSize + |
| 7638 |
(xSrc + x0 - xDest), |
| 7639 |
x1 - x0); |
| 7640 |
if (!state->clip->clipSpanBinary(scanBuf2, y, x0, x1 - 1, |
| 7641 |
state->strokeAdjust)) { |
| 7642 |
continue; |
| 7643 |
} |
| 7644 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 7645 |
scanBuf2 + x0, |
| 7646 |
srcShape->alpha + |
| 7647 |
(ySrc + y - yDest) * srcShape->alphaRowSize + |
| 7648 |
(xSrc + x0 - xDest), |
| 7649 |
scanBuf + x0); |
| 7650 |
} |
| 7651 |
} else if (usesAlpha) { |
| 7652 |
for (y = y0; y < y1; ++y) { |
| 7653 |
mono1Ptr = src->data |
| 7654 |
+ (ySrc + y - yDest) * src->rowSize |
| 7655 |
+ ((xSrc + x0 - xDest) >> 3); |
| 7656 |
mono1Mask = (Guchar)(0x80 >> ((xSrc + x0 - xDest) & 7)); |
| 7657 |
for (x = x0; x < x1; ++x) { |
| 7658 |
scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; |
| 7659 |
mono1Ptr += mono1Mask & 1; |
| 7660 |
mono1Mask = (Guchar)((mono1Mask << 7) | (mono1Mask >> 1)); |
| 7661 |
} |
| 7662 |
memcpy(scanBuf2 + x0, |
| 7663 |
src->alpha + (ySrc + y - yDest) * src->alphaRowSize + |
| 7664 |
(xSrc + x0 - xDest), |
| 7665 |
x1 - x0); |
| 7666 |
if (!state->clip->clipSpanBinary(scanBuf2, y, x0, x1 - 1, |
| 7667 |
state->strokeAdjust)) { |
| 7668 |
continue; |
| 7669 |
} |
| 7670 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 7671 |
NULL, scanBuf2 + x0, scanBuf + x0); |
| 7672 |
} |
| 7673 |
} else { |
| 7674 |
for (y = y0; y < y1; ++y) { |
| 7675 |
mono1Ptr = src->data |
| 7676 |
+ (ySrc + y - yDest) * src->rowSize |
| 7677 |
+ ((xSrc + x0 - xDest) >> 3); |
| 7678 |
mono1Mask = (Guchar)(0x80 >> ((xSrc + x0 - xDest) & 7)); |
| 7679 |
for (x = x0; x < x1; ++x) { |
| 7680 |
scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; |
| 7681 |
mono1Ptr += mono1Mask & 1; |
| 7682 |
mono1Mask = (Guchar)((mono1Mask << 7) | (mono1Mask >> 1)); |
| 7683 |
} |
| 7684 |
memset(scanBuf2 + x0, 0xff, x1 - x0); |
| 7685 |
if (!state->clip->clipSpanBinary(scanBuf2, y, x0, x1 - 1, |
| 7686 |
state->strokeAdjust)) { |
| 7687 |
continue; |
| 7688 |
} |
| 7689 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 7690 |
NULL, scanBuf2 + x0, scanBuf + x0); |
| 7691 |
} |
| 7692 |
} |
| 7693 |
} |
| 7694 |
} |
| 7695 |
|
| 7696 |
} else if (src->mode == splashModeBGR8) { |
| 7697 |
// in BGR8 mode, pipeRun expects the source to be in RGB8 format, |
| 7698 |
// so we need to swap bytes |
| 7699 |
lineBuf = (Guchar *)gmallocn(w, 3); |
| 7700 |
if (noClip) { |
| 7701 |
if (usesShape) { |
| 7702 |
for (y = 0; y < h; ++y) { |
| 7703 |
memcpy(lineBuf, |
| 7704 |
src->data + (ySrc + y) * src->rowSize + xSrc * 3, |
| 7705 |
w * 3); |
| 7706 |
for (x = 0, linePtr = lineBuf; x < w; ++x, linePtr += 3) { |
| 7707 |
b = linePtr[0]; |
| 7708 |
linePtr[0] = linePtr[2]; |
| 7709 |
linePtr[2] = b; |
| 7710 |
} |
| 7711 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7712 |
srcShape->alpha + |
| 7713 |
(ySrc + y) * srcShape->alphaRowSize + xSrc, |
| 7714 |
src->alpha + |
| 7715 |
(ySrc + y) * src->alphaRowSize + xSrc, |
| 7716 |
lineBuf); |
| 7717 |
} |
| 7718 |
} else if (usesAlpha) { |
| 7719 |
for (y = 0; y < h; ++y) { |
| 7720 |
memcpy(lineBuf, |
| 7721 |
src->data + (ySrc + y) * src->rowSize + xSrc * 3, |
| 7722 |
w * 3); |
| 7723 |
for (x = 0, linePtr = lineBuf; x < w; ++x, linePtr += 3) { |
| 7724 |
b = linePtr[0]; |
| 7725 |
linePtr[0] = linePtr[2]; |
| 7726 |
linePtr[2] = b; |
| 7727 |
} |
| 7728 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7729 |
NULL, |
| 7730 |
src->alpha + |
| 7731 |
(ySrc + y) * src->alphaRowSize + xSrc, |
| 7732 |
lineBuf); |
| 7733 |
} |
| 7734 |
} else { |
| 7735 |
for (y = 0; y < h; ++y) { |
| 7736 |
memcpy(lineBuf, |
| 7737 |
src->data + (ySrc + y) * src->rowSize + xSrc * 3, |
| 7738 |
w * 3); |
| 7739 |
for (x = 0, linePtr = lineBuf; x < w; ++x, linePtr += 3) { |
| 7740 |
b = linePtr[0]; |
| 7741 |
linePtr[0] = linePtr[2]; |
| 7742 |
linePtr[2] = b; |
| 7743 |
} |
| 7744 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7745 |
NULL, NULL, lineBuf); |
| 7746 |
} |
| 7747 |
} |
| 7748 |
} else { |
| 7749 |
x0 = xDest; |
| 7750 |
if ((t = state->clip->getXMinI(state->strokeAdjust)) > x0) { |
| 7751 |
x0 = t; |
| 7752 |
} |
| 7753 |
x1 = xDest + w; |
| 7754 |
if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < x1) { |
| 7755 |
x1 = t; |
| 7756 |
} |
| 7757 |
y0 = yDest; |
| 7758 |
if ((t = state->clip->getYMinI(state->strokeAdjust)) > y0) { |
| 7759 |
y0 = t; |
| 7760 |
} |
| 7761 |
y1 = yDest + h; |
| 7762 |
if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < y1) { |
| 7763 |
y1 = t; |
| 7764 |
} |
| 7765 |
if (x0 < x1 && y0 < y1) { |
| 7766 |
if (usesShape) { |
| 7767 |
for (y = y0; y < y1; ++y) { |
| 7768 |
memcpy(scanBuf + x0, |
| 7769 |
srcShape->alpha + |
| 7770 |
(ySrc + y - yDest) * srcShape->alphaRowSize + |
| 7771 |
(xSrc + x0 - xDest), |
| 7772 |
x1 - x0); |
| 7773 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 7774 |
memcpy(lineBuf, |
| 7775 |
src->data + |
| 7776 |
(ySrc + y - yDest) * src->rowSize + |
| 7777 |
(xSrc + x0 - xDest) * 3, |
| 7778 |
(x1 - x0) * 3); |
| 7779 |
for (x = 0, linePtr = lineBuf; x < x1 - x0; ++x, linePtr += 3) { |
| 7780 |
b = linePtr[0]; |
| 7781 |
linePtr[0] = linePtr[2]; |
| 7782 |
linePtr[2] = b; |
| 7783 |
} |
| 7784 |
// this uses shape instead of alpha, which isn't technically |
| 7785 |
// correct, but works out the same |
| 7786 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 7787 |
scanBuf + x0, |
| 7788 |
src->alpha + |
| 7789 |
(ySrc + y - yDest) * src->alphaRowSize + |
| 7790 |
(xSrc + x0 - xDest), |
| 7791 |
lineBuf); |
| 7792 |
} |
| 7793 |
} else if (usesAlpha) { |
| 7794 |
for (y = y0; y < y1; ++y) { |
| 7795 |
memcpy(scanBuf + x0, |
| 7796 |
src->alpha + (ySrc + y - yDest) * src->alphaRowSize + |
| 7797 |
(xSrc + x0 - xDest), |
| 7798 |
x1 - x0); |
| 7799 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 7800 |
memcpy(lineBuf, |
| 7801 |
src->data + |
| 7802 |
(ySrc + y - yDest) * src->rowSize + |
| 7803 |
(xSrc + x0 - xDest) * 3, |
| 7804 |
(x1 - x0) * 3); |
| 7805 |
for (x = 0, linePtr = lineBuf; x < x1 - x0; ++x, linePtr += 3) { |
| 7806 |
b = linePtr[0]; |
| 7807 |
linePtr[0] = linePtr[2]; |
| 7808 |
linePtr[2] = b; |
| 7809 |
} |
| 7810 |
// this uses shape instead of alpha, which isn't technically |
| 7811 |
// correct, but works out the same |
| 7812 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 7813 |
NULL, scanBuf + x0, lineBuf); |
| 7814 |
} |
| 7815 |
} else { |
| 7816 |
for (y = y0; y < y1; ++y) { |
| 7817 |
memset(scanBuf + x0, 0xff, x1 - x0); |
| 7818 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 7819 |
memcpy(lineBuf, |
| 7820 |
src->data + |
| 7821 |
(ySrc + y - yDest) * src->rowSize + |
| 7822 |
(xSrc + x0 - xDest) * 3, |
| 7823 |
(x1 - x0) * 3); |
| 7824 |
for (x = 0, linePtr = lineBuf; x < x1 - x0; ++x, linePtr += 3) { |
| 7825 |
b = linePtr[0]; |
| 7826 |
linePtr[0] = linePtr[2]; |
| 7827 |
linePtr[2] = b; |
| 7828 |
} |
| 7829 |
(this->*pipe.run)(&pipe, x0, x1 - 1, yDest + y, |
| 7830 |
NULL, |
| 7831 |
scanBuf + x0, |
| 7832 |
src->data + |
| 7833 |
(ySrc + y - yDest) * src->rowSize + |
| 7834 |
(xSrc + x0 - xDest) * bitmapComps); |
| 7835 |
} |
| 7836 |
} |
| 7837 |
} |
| 7838 |
} |
| 7839 |
gfree(lineBuf); |
| 7840 |
|
| 7841 |
} else { // src->mode not mono1 or BGR8 |
| 7842 |
if (noClip) { |
| 7843 |
if (usesShape) { |
| 7844 |
for (y = 0; y < h; ++y) { |
| 7845 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7846 |
srcShape->alpha + |
| 7847 |
(ySrc + y) * srcShape->alphaRowSize + xSrc, |
| 7848 |
src->alpha + |
| 7849 |
(ySrc + y) * src->alphaRowSize + xSrc, |
| 7850 |
src->data + (ySrc + y) * src->rowSize + |
| 7851 |
xSrc * bitmapComps); |
| 7852 |
} |
| 7853 |
} else if (usesAlpha) { |
| 7854 |
for (y = 0; y < h; ++y) { |
| 7855 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7856 |
NULL, |
| 7857 |
src->alpha + |
| 7858 |
(ySrc + y) * src->alphaRowSize + xSrc, |
| 7859 |
src->data + (ySrc + y) * src->rowSize + |
| 7860 |
xSrc * bitmapComps); |
| 7861 |
} |
| 7862 |
} else { |
| 7863 |
for (y = 0; y < h; ++y) { |
| 7864 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7865 |
NULL, NULL, |
| 7866 |
src->data + (ySrc + y) * src->rowSize + |
| 7867 |
xSrc * bitmapComps); |
| 7868 |
} |
| 7869 |
} |
| 7870 |
} else { |
| 7871 |
x0 = xDest; |
| 7872 |
if ((t = state->clip->getXMinI(state->strokeAdjust)) > x0) { |
| 7873 |
x0 = t; |
| 7874 |
} |
| 7875 |
x1 = xDest + w; |
| 7876 |
if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < x1) { |
| 7877 |
x1 = t; |
| 7878 |
} |
| 7879 |
y0 = yDest; |
| 7880 |
if ((t = state->clip->getYMinI(state->strokeAdjust)) > y0) { |
| 7881 |
y0 = t; |
| 7882 |
} |
| 7883 |
y1 = yDest + h; |
| 7884 |
if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < y1) { |
| 7885 |
y1 = t; |
| 7886 |
} |
| 7887 |
if (x0 < x1 && y0 < y1) { |
| 7888 |
if (usesShape) { |
| 7889 |
for (y = y0; y < y1; ++y) { |
| 7890 |
memcpy(scanBuf + x0, |
| 7891 |
srcShape->alpha + |
| 7892 |
(ySrc + y - yDest) * srcShape->alphaRowSize + |
| 7893 |
(xSrc + x0 - xDest), |
| 7894 |
x1 - x0); |
| 7895 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 7896 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 7897 |
scanBuf + x0, |
| 7898 |
src->alpha + |
| 7899 |
(ySrc + y - yDest) * src->alphaRowSize + |
| 7900 |
(xSrc + x0 - xDest), |
| 7901 |
src->data + |
| 7902 |
(ySrc + y - yDest) * src->rowSize + |
| 7903 |
(xSrc + x0 - xDest) * bitmapComps); |
| 7904 |
} |
| 7905 |
} else if (usesAlpha) { |
| 7906 |
for (y = y0; y < y1; ++y) { |
| 7907 |
memcpy(scanBuf + x0, |
| 7908 |
src->alpha + (ySrc + y - yDest) * src->alphaRowSize + |
| 7909 |
(xSrc + x0 - xDest), |
| 7910 |
x1 - x0); |
| 7911 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 7912 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 7913 |
NULL, |
| 7914 |
scanBuf + x0, |
| 7915 |
src->data + |
| 7916 |
(ySrc + y - yDest) * src->rowSize + |
| 7917 |
(xSrc + x0 - xDest) * bitmapComps); |
| 7918 |
} |
| 7919 |
} else { |
| 7920 |
for (y = y0; y < y1; ++y) { |
| 7921 |
memset(scanBuf + x0, 0xff, x1 - x0); |
| 7922 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 7923 |
(this->*pipe.run)(&pipe, x0, x1 - 1, yDest + y, |
| 7924 |
NULL, |
| 7925 |
scanBuf + x0, |
| 7926 |
src->data + |
| 7927 |
(ySrc + y - yDest) * src->rowSize + |
| 7928 |
(xSrc + x0 - xDest) * bitmapComps); |
| 7929 |
} |
| 7930 |
} |
| 7931 |
} |
| 7932 |
} |
| 7933 |
} |
| 7934 |
|
| 7935 |
return splashOk; |
| 7936 |
} |
| 7937 |
|
| 7938 |
SplashError Splash::compositeWithOverprint(SplashBitmap *src, |
| 7939 |
SplashAlphaBitmap *srcShape, |
| 7940 |
Guint *srcOverprintMaskBitmap, |
| 7941 |
int xSrc, int ySrc, |
| 7942 |
int xDest, int yDest, int w, int h, |
| 7943 |
GBool noClip, GBool nonIsolated) { |
| 7944 |
SplashPipe pipe; |
| 7945 |
int x0, x1, y0, y1, y, t; |
| 7946 |
|
| 7947 |
if (!(src->mode == bitmap->mode || |
| 7948 |
(src->mode == splashModeMono8 && bitmap->mode == splashModeMono1) || |
| 7949 |
(src->mode == splashModeRGB8 && bitmap->mode == splashModeBGR8))) { |
| 7950 |
return splashErrModeMismatch; |
| 7951 |
} |
| 7952 |
|
| 7953 |
GBool usesShape = srcShape && shapeBitmap && src->alpha; |
| 7954 |
GBool usesAlpha = !noClip || src->alpha; |
| 7955 |
pipeInit(&pipe, NULL, |
| 7956 |
(Guchar)splashRound(state->fillAlpha * 255), |
| 7957 |
usesShape, usesAlpha, nonIsolated, gTrue); |
| 7958 |
|
| 7959 |
if (noClip) { |
| 7960 |
if (usesShape) { |
| 7961 |
for (y = 0; y < h; ++y) { |
| 7962 |
pipe.srcOverprintMaskPtr = srcOverprintMaskBitmap + y * w + xSrc; |
| 7963 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7964 |
srcShape->alpha + |
| 7965 |
(ySrc + y) * srcShape->alphaRowSize + xSrc, |
| 7966 |
src->alpha + |
| 7967 |
(ySrc + y) * src->alphaRowSize + xSrc, |
| 7968 |
src->data + (ySrc + y) * src->rowSize + |
| 7969 |
xSrc * bitmapComps); |
| 7970 |
} |
| 7971 |
} else if (usesAlpha) { |
| 7972 |
for (y = 0; y < h; ++y) { |
| 7973 |
pipe.srcOverprintMaskPtr = srcOverprintMaskBitmap + y * w + xSrc; |
| 7974 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7975 |
NULL, |
| 7976 |
src->alpha + |
| 7977 |
(ySrc + y) * src->alphaRowSize + xSrc, |
| 7978 |
src->data + (ySrc + y) * src->rowSize + |
| 7979 |
xSrc * bitmapComps); |
| 7980 |
} |
| 7981 |
} else { |
| 7982 |
for (y = 0; y < h; ++y) { |
| 7983 |
pipe.srcOverprintMaskPtr = srcOverprintMaskBitmap + y * w + xSrc; |
| 7984 |
(this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, |
| 7985 |
NULL, NULL, |
| 7986 |
src->data + (ySrc + y) * src->rowSize + |
| 7987 |
xSrc * bitmapComps); |
| 7988 |
} |
| 7989 |
} |
| 7990 |
} else { |
| 7991 |
x0 = xDest; |
| 7992 |
if ((t = state->clip->getXMinI(state->strokeAdjust)) > x0) { |
| 7993 |
x0 = t; |
| 7994 |
} |
| 7995 |
x1 = xDest + w; |
| 7996 |
if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < x1) { |
| 7997 |
x1 = t; |
| 7998 |
} |
| 7999 |
y0 = yDest; |
| 8000 |
if ((t = state->clip->getYMinI(state->strokeAdjust)) > y0) { |
| 8001 |
y0 = t; |
| 8002 |
} |
| 8003 |
y1 = yDest + h; |
| 8004 |
if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < y1) { |
| 8005 |
y1 = t; |
| 8006 |
} |
| 8007 |
if (x0 < x1 && y0 < y1) { |
| 8008 |
if (usesShape) { |
| 8009 |
for (y = y0; y < y1; ++y) { |
| 8010 |
memcpy(scanBuf + x0, |
| 8011 |
srcShape->alpha + |
| 8012 |
(ySrc + y - yDest) * srcShape->alphaRowSize + |
| 8013 |
(xSrc + x0 - xDest), |
| 8014 |
x1 - x0); |
| 8015 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 8016 |
pipe.srcOverprintMaskPtr = srcOverprintMaskBitmap |
| 8017 |
+ (ySrc + y - yDest) * w |
| 8018 |
+ (xSrc + x0 - xDest); |
| 8019 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 8020 |
scanBuf + x0, |
| 8021 |
src->alpha + |
| 8022 |
(ySrc + y - yDest) * src->alphaRowSize + |
| 8023 |
(xSrc + x0 - xDest), |
| 8024 |
src->data + |
| 8025 |
(ySrc + y - yDest) * src->rowSize + |
| 8026 |
(xSrc + x0 - xDest) * bitmapComps); |
| 8027 |
} |
| 8028 |
} else if (usesAlpha) { |
| 8029 |
for (y = y0; y < y1; ++y) { |
| 8030 |
memcpy(scanBuf + x0, |
| 8031 |
src->alpha + (ySrc + y - yDest) * src->alphaRowSize + |
| 8032 |
(xSrc + x0 - xDest), |
| 8033 |
x1 - x0); |
| 8034 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 8035 |
pipe.srcOverprintMaskPtr = srcOverprintMaskBitmap |
| 8036 |
+ (ySrc + y - yDest) * w |
| 8037 |
+ (xSrc + x0 - xDest); |
| 8038 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 8039 |
NULL, |
| 8040 |
scanBuf + x0, |
| 8041 |
src->data + |
| 8042 |
(ySrc + y - yDest) * src->rowSize + |
| 8043 |
(xSrc + x0 - xDest) * bitmapComps); |
| 8044 |
} |
| 8045 |
} else { |
| 8046 |
for (y = y0; y < y1; ++y) { |
| 8047 |
memset(scanBuf + x0, 0xff, x1 - x0); |
| 8048 |
state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); |
| 8049 |
pipe.srcOverprintMaskPtr = srcOverprintMaskBitmap |
| 8050 |
+ (ySrc + y - yDest) * w |
| 8051 |
+ (xSrc + x0 - xDest); |
| 8052 |
(this->*pipe.run)(&pipe, x0, x1 - 1, y, |
| 8053 |
NULL, |
| 8054 |
scanBuf + x0, |
| 8055 |
src->data + |
| 8056 |
(ySrc + y - yDest) * src->rowSize + |
| 8057 |
(xSrc + x0 - xDest) * bitmapComps); |
| 8058 |
} |
| 8059 |
} |
| 8060 |
} |
| 8061 |
} |
| 8062 |
|
| 8063 |
return splashOk; |
| 8064 |
} |
| 8065 |
|
| 8066 |
void Splash::compositeBackground(SplashColorPtr color) { |
| 8067 |
SplashColorPtr p; |
| 8068 |
Guchar *q; |
| 8069 |
Guchar alpha, alpha1, c, color0, color1, color2, mask; |
| 8070 |
#if SPLASH_CMYK |
| 8071 |
Guchar color3; |
| 8072 |
#endif |
| 8073 |
int x, y; |
| 8074 |
|
| 8075 |
switch (bitmap->mode) { |
| 8076 |
case splashModeMono1: |
| 8077 |
color0 = color[0]; |
| 8078 |
for (y = 0; y < bitmap->height; ++y) { |
| 8079 |
p = &bitmap->data[y * bitmap->rowSize]; |
| 8080 |
q = &bitmap->alpha[y * bitmap->alphaRowSize]; |
| 8081 |
mask = 0x80; |
| 8082 |
for (x = 0; x < bitmap->width; ++x) { |
| 8083 |
alpha = *q++; |
| 8084 |
if (alpha == 0) { |
| 8085 |
if (color0 & 0x80) { |
| 8086 |
*p |= mask; |
| 8087 |
} else { |
| 8088 |
*p &= (Guchar)~mask; |
| 8089 |
} |
| 8090 |
} else if (alpha != 255) { |
| 8091 |
alpha1 = (Guchar)(255 - alpha); |
| 8092 |
c = (*p & mask) ? 0xff : 0x00; |
| 8093 |
c = div255(alpha1 * color0 + alpha * c); |
| 8094 |
if (c & 0x80) { |
| 8095 |
*p |= mask; |
| 8096 |
} else { |
| 8097 |
*p &= (Guchar)~mask; |
| 8098 |
} |
| 8099 |
} |
| 8100 |
if (!(mask = (Guchar)(mask >> 1))) { |
| 8101 |
mask = 0x80; |
| 8102 |
++p; |
| 8103 |
} |
| 8104 |
} |
| 8105 |
} |
| 8106 |
break; |
| 8107 |
case splashModeMono8: |
| 8108 |
color0 = color[0]; |
| 8109 |
for (y = 0; y < bitmap->height; ++y) { |
| 8110 |
p = &bitmap->data[y * bitmap->rowSize]; |
| 8111 |
q = &bitmap->alpha[y * bitmap->alphaRowSize]; |
| 8112 |
for (x = 0; x < bitmap->width; ++x) { |
| 8113 |
alpha = *q++; |
| 8114 |
if (alpha == 0) { |
| 8115 |
p[0] = color0; |
| 8116 |
} else if (alpha != 255) { |
| 8117 |
alpha1 = (Guchar)(255 - alpha); |
| 8118 |
p[0] = div255(alpha1 * color0 + alpha * p[0]); |
| 8119 |
} |
| 8120 |
++p; |
| 8121 |
} |
| 8122 |
} |
| 8123 |
break; |
| 8124 |
case splashModeRGB8: |
| 8125 |
case splashModeBGR8: |
| 8126 |
color0 = color[0]; |
| 8127 |
color1 = color[1]; |
| 8128 |
color2 = color[2]; |
| 8129 |
for (y = 0; y < bitmap->height; ++y) { |
| 8130 |
p = &bitmap->data[y * bitmap->rowSize]; |
| 8131 |
q = &bitmap->alpha[y * bitmap->alphaRowSize]; |
| 8132 |
for (x = 0; x < bitmap->width; ++x) { |
| 8133 |
alpha = *q++; |
| 8134 |
if (alpha == 0) { |
| 8135 |
p[0] = color0; |
| 8136 |
p[1] = color1; |
| 8137 |
p[2] = color2; |
| 8138 |
} else if (alpha != 255) { |
| 8139 |
alpha1 = (Guchar)(255 - alpha); |
| 8140 |
p[0] = div255(alpha1 * color0 + alpha * p[0]); |
| 8141 |
p[1] = div255(alpha1 * color1 + alpha * p[1]); |
| 8142 |
p[2] = div255(alpha1 * color2 + alpha * p[2]); |
| 8143 |
} |
| 8144 |
p += 3; |
| 8145 |
} |
| 8146 |
} |
| 8147 |
break; |
| 8148 |
#if SPLASH_CMYK |
| 8149 |
case splashModeCMYK8: |
| 8150 |
color0 = color[0]; |
| 8151 |
color1 = color[1]; |
| 8152 |
color2 = color[2]; |
| 8153 |
color3 = color[3]; |
| 8154 |
for (y = 0; y < bitmap->height; ++y) { |
| 8155 |
p = &bitmap->data[y * bitmap->rowSize]; |
| 8156 |
q = &bitmap->alpha[y * bitmap->alphaRowSize]; |
| 8157 |
for (x = 0; x < bitmap->width; ++x) { |
| 8158 |
alpha = *q++; |
| 8159 |
if (alpha == 0) { |
| 8160 |
p[0] = color0; |
| 8161 |
p[1] = color1; |
| 8162 |
p[2] = color2; |
| 8163 |
p[3] = color3; |
| 8164 |
} else if (alpha != 255) { |
| 8165 |
alpha1 = (Guchar)(255 - alpha); |
| 8166 |
p[0] = div255(alpha1 * color0 + alpha * p[0]); |
| 8167 |
p[1] = div255(alpha1 * color1 + alpha * p[1]); |
| 8168 |
p[2] = div255(alpha1 * color2 + alpha * p[2]); |
| 8169 |
p[3] = div255(alpha1 * color3 + alpha * p[3]); |
| 8170 |
} |
| 8171 |
p += 4; |
| 8172 |
} |
| 8173 |
} |
| 8174 |
break; |
| 8175 |
#endif |
| 8176 |
} |
| 8177 |
memset(bitmap->alpha, 255, bitmap->alphaRowSize * bitmap->height); |
| 8178 |
} |
| 8179 |
|
| 8180 |
SplashPath *Splash::makeStrokePath(SplashPath *path, SplashCoord w, |
| 8181 |
int lineCap, int lineJoin, |
| 8182 |
GBool flatten) { |
| 8183 |
SplashPath *pathIn, *dashPath, *pathOut; |
| 8184 |
SplashCoord d, dx, dy, wdx, wdy, dxNext, dyNext, wdxNext, wdyNext; |
| 8185 |
SplashCoord crossprod, dotprod, miter, m; |
| 8186 |
SplashCoord angle, angleNext, dAngle, xc, yc; |
| 8187 |
SplashCoord dxJoin, dyJoin, dJoin, kappa; |
| 8188 |
SplashCoord cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; |
| 8189 |
GBool first, last, closed; |
| 8190 |
int subpathStart0, subpathStart1, seg, i0, i1, j0, j1, k0, k1; |
| 8191 |
int left0, left1, left2, right0, right1, right2, join0, join1, join2; |
| 8192 |
int leftFirst, rightFirst, firstPt; |
| 8193 |
|
| 8194 |
pathOut = new SplashPath(); |
| 8195 |
|
| 8196 |
if (path->length == 0) { |
| 8197 |
return pathOut; |
| 8198 |
} |
| 8199 |
|
| 8200 |
if (flatten) { |
| 8201 |
pathIn = flattenPath(path, state->matrix, state->flatness); |
| 8202 |
if (state->lineDashLength > 0) { |
| 8203 |
dashPath = makeDashedPath(pathIn); |
| 8204 |
delete pathIn; |
| 8205 |
pathIn = dashPath; |
| 8206 |
if (pathIn->length == 0) { |
| 8207 |
delete pathIn; |
| 8208 |
return pathOut; |
| 8209 |
} |
| 8210 |
} |
| 8211 |
} else { |
| 8212 |
pathIn = path; |
| 8213 |
} |
| 8214 |
|
| 8215 |
subpathStart0 = subpathStart1 = 0; // make gcc happy |
| 8216 |
seg = 0; // make gcc happy |
| 8217 |
closed = gFalse; // make gcc happy |
| 8218 |
left0 = left1 = right0 = right1 = join0 = join1 = 0; // make gcc happy |
| 8219 |
leftFirst = rightFirst = firstPt = 0; // make gcc happy |
| 8220 |
|
| 8221 |
i0 = 0; |
| 8222 |
for (i1 = i0; |
| 8223 |
!(pathIn->flags[i1] & splashPathLast) && |
| 8224 |
i1 + 1 < pathIn->length && |
| 8225 |
pathIn->pts[i1+1].x == pathIn->pts[i1].x && |
| 8226 |
pathIn->pts[i1+1].y == pathIn->pts[i1].y; |
| 8227 |
++i1) ; |
| 8228 |
|
| 8229 |
while (i1 < pathIn->length) { |
| 8230 |
if ((first = pathIn->flags[i0] & splashPathFirst)) { |
| 8231 |
subpathStart0 = i0; |
| 8232 |
subpathStart1 = i1; |
| 8233 |
seg = 0; |
| 8234 |
closed = pathIn->flags[i0] & splashPathClosed; |
| 8235 |
} |
| 8236 |
j0 = i1 + 1; |
| 8237 |
if (j0 < pathIn->length) { |
| 8238 |
for (j1 = j0; |
| 8239 |
!(pathIn->flags[j1] & splashPathLast) && |
| 8240 |
j1 + 1 < pathIn->length && |
| 8241 |
pathIn->pts[j1+1].x == pathIn->pts[j1].x && |
| 8242 |
pathIn->pts[j1+1].y == pathIn->pts[j1].y; |
| 8243 |
++j1) ; |
| 8244 |
} else { |
| 8245 |
j1 = j0; |
| 8246 |
} |
| 8247 |
if (pathIn->flags[i1] & splashPathLast) { |
| 8248 |
if (first && lineCap == splashLineCapRound) { |
| 8249 |
// special case: zero-length subpath with round line caps --> |
| 8250 |
// draw a circle |
| 8251 |
pathOut->moveTo(pathIn->pts[i0].x + (SplashCoord)0.5 * w, |
| 8252 |
pathIn->pts[i0].y); |
| 8253 |
pathOut->curveTo(pathIn->pts[i0].x + (SplashCoord)0.5 * w, |
| 8254 |
pathIn->pts[i0].y + bezierCircle2 * w, |
| 8255 |
pathIn->pts[i0].x + bezierCircle2 * w, |
| 8256 |
pathIn->pts[i0].y + (SplashCoord)0.5 * w, |
| 8257 |
pathIn->pts[i0].x, |
| 8258 |
pathIn->pts[i0].y + (SplashCoord)0.5 * w); |
| 8259 |
pathOut->curveTo(pathIn->pts[i0].x - bezierCircle2 * w, |
| 8260 |
pathIn->pts[i0].y + (SplashCoord)0.5 * w, |
| 8261 |
pathIn->pts[i0].x - (SplashCoord)0.5 * w, |
| 8262 |
pathIn->pts[i0].y + bezierCircle2 * w, |
| 8263 |
pathIn->pts[i0].x - (SplashCoord)0.5 * w, |
| 8264 |
pathIn->pts[i0].y); |
| 8265 |
pathOut->curveTo(pathIn->pts[i0].x - (SplashCoord)0.5 * w, |
| 8266 |
pathIn->pts[i0].y - bezierCircle2 * w, |
| 8267 |
pathIn->pts[i0].x - bezierCircle2 * w, |
| 8268 |
pathIn->pts[i0].y - (SplashCoord)0.5 * w, |
| 8269 |
pathIn->pts[i0].x, |
| 8270 |
pathIn->pts[i0].y - (SplashCoord)0.5 * w); |
| 8271 |
pathOut->curveTo(pathIn->pts[i0].x + bezierCircle2 * w, |
| 8272 |
pathIn->pts[i0].y - (SplashCoord)0.5 * w, |
| 8273 |
pathIn->pts[i0].x + (SplashCoord)0.5 * w, |
| 8274 |
pathIn->pts[i0].y - bezierCircle2 * w, |
| 8275 |
pathIn->pts[i0].x + (SplashCoord)0.5 * w, |
| 8276 |
pathIn->pts[i0].y); |
| 8277 |
pathOut->close(); |
| 8278 |
} |
| 8279 |
i0 = j0; |
| 8280 |
i1 = j1; |
| 8281 |
continue; |
| 8282 |
} |
| 8283 |
last = pathIn->flags[j1] & splashPathLast; |
| 8284 |
if (last) { |
| 8285 |
k0 = subpathStart1 + 1; |
| 8286 |
} else { |
| 8287 |
k0 = j1 + 1; |
| 8288 |
} |
| 8289 |
for (k1 = k0; |
| 8290 |
!(pathIn->flags[k1] & splashPathLast) && |
| 8291 |
k1 + 1 < pathIn->length && |
| 8292 |
pathIn->pts[k1+1].x == pathIn->pts[k1].x && |
| 8293 |
pathIn->pts[k1+1].y == pathIn->pts[k1].y; |
| 8294 |
++k1) ; |
| 8295 |
|
| 8296 |
// compute the deltas for segment (i1, j0) |
| 8297 |
#if USE_FIXEDPOINT |
| 8298 |
// the 1/d value can be small, which introduces significant |
| 8299 |
// inaccuracies in fixed point mode |
| 8300 |
d = splashDist(pathIn->pts[i1].x, pathIn->pts[i1].y, |
| 8301 |
pathIn->pts[j0].x, pathIn->pts[j0].y); |
| 8302 |
dx = (pathIn->pts[j0].x - pathIn->pts[i1].x) / d; |
| 8303 |
dy = (pathIn->pts[j0].y - pathIn->pts[i1].y) / d; |
| 8304 |
#else |
| 8305 |
d = (SplashCoord)1 / splashDist(pathIn->pts[i1].x, pathIn->pts[i1].y, |
| 8306 |
pathIn->pts[j0].x, pathIn->pts[j0].y); |
| 8307 |
dx = d * (pathIn->pts[j0].x - pathIn->pts[i1].x); |
| 8308 |
dy = d * (pathIn->pts[j0].y - pathIn->pts[i1].y); |
| 8309 |
#endif |
| 8310 |
wdx = (SplashCoord)0.5 * w * dx; |
| 8311 |
wdy = (SplashCoord)0.5 * w * dy; |
| 8312 |
|
| 8313 |
// draw the start cap |
| 8314 |
if (i0 == subpathStart0) { |
| 8315 |
firstPt = pathOut->length; |
| 8316 |
} |
| 8317 |
if (first && !closed) { |
| 8318 |
switch (lineCap) { |
| 8319 |
case splashLineCapButt: |
| 8320 |
pathOut->moveTo(pathIn->pts[i0].x - wdy, pathIn->pts[i0].y + wdx); |
| 8321 |
pathOut->lineTo(pathIn->pts[i0].x + wdy, pathIn->pts[i0].y - wdx); |
| 8322 |
break; |
| 8323 |
case splashLineCapRound: |
| 8324 |
pathOut->moveTo(pathIn->pts[i0].x - wdy, pathIn->pts[i0].y + wdx); |
| 8325 |
pathOut->curveTo(pathIn->pts[i0].x - wdy - bezierCircle * wdx, |
| 8326 |
pathIn->pts[i0].y + wdx - bezierCircle * wdy, |
| 8327 |
pathIn->pts[i0].x - wdx - bezierCircle * wdy, |
| 8328 |
pathIn->pts[i0].y - wdy + bezierCircle * wdx, |
| 8329 |
pathIn->pts[i0].x - wdx, |
| 8330 |
pathIn->pts[i0].y - wdy); |
| 8331 |
pathOut->curveTo(pathIn->pts[i0].x - wdx + bezierCircle * wdy, |
| 8332 |
pathIn->pts[i0].y - wdy - bezierCircle * wdx, |
| 8333 |
pathIn->pts[i0].x + wdy - bezierCircle * wdx, |
| 8334 |
pathIn->pts[i0].y - wdx - bezierCircle * wdy, |
| 8335 |
pathIn->pts[i0].x + wdy, |
| 8336 |
pathIn->pts[i0].y - wdx); |
| 8337 |
break; |
| 8338 |
case splashLineCapProjecting: |
| 8339 |
pathOut->moveTo(pathIn->pts[i0].x - wdx - wdy, |
| 8340 |
pathIn->pts[i0].y + wdx - wdy); |
| 8341 |
pathOut->lineTo(pathIn->pts[i0].x - wdx + wdy, |
| 8342 |
pathIn->pts[i0].y - wdx - wdy); |
| 8343 |
break; |
| 8344 |
} |
| 8345 |
} else { |
| 8346 |
pathOut->moveTo(pathIn->pts[i0].x - wdy, pathIn->pts[i0].y + wdx); |
| 8347 |
pathOut->lineTo(pathIn->pts[i0].x + wdy, pathIn->pts[i0].y - wdx); |
| 8348 |
} |
| 8349 |
|
| 8350 |
// draw the left side of the segment rectangle and the end cap |
| 8351 |
left2 = pathOut->length - 1; |
| 8352 |
if (last && !closed) { |
| 8353 |
switch (lineCap) { |
| 8354 |
case splashLineCapButt: |
| 8355 |
pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); |
| 8356 |
pathOut->lineTo(pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); |
| 8357 |
break; |
| 8358 |
case splashLineCapRound: |
| 8359 |
pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); |
| 8360 |
pathOut->curveTo(pathIn->pts[j0].x + wdy + bezierCircle * wdx, |
| 8361 |
pathIn->pts[j0].y - wdx + bezierCircle * wdy, |
| 8362 |
pathIn->pts[j0].x + wdx + bezierCircle * wdy, |
| 8363 |
pathIn->pts[j0].y + wdy - bezierCircle * wdx, |
| 8364 |
pathIn->pts[j0].x + wdx, |
| 8365 |
pathIn->pts[j0].y + wdy); |
| 8366 |
pathOut->curveTo(pathIn->pts[j0].x + wdx - bezierCircle * wdy, |
| 8367 |
pathIn->pts[j0].y + wdy + bezierCircle * wdx, |
| 8368 |
pathIn->pts[j0].x - wdy + bezierCircle * wdx, |
| 8369 |
pathIn->pts[j0].y + wdx + bezierCircle * wdy, |
| 8370 |
pathIn->pts[j0].x - wdy, |
| 8371 |
pathIn->pts[j0].y + wdx); |
| 8372 |
break; |
| 8373 |
case splashLineCapProjecting: |
| 8374 |
pathOut->lineTo(pathIn->pts[j0].x + wdy + wdx, |
| 8375 |
pathIn->pts[j0].y - wdx + wdy); |
| 8376 |
pathOut->lineTo(pathIn->pts[j0].x - wdy + wdx, |
| 8377 |
pathIn->pts[j0].y + wdx + wdy); |
| 8378 |
break; |
| 8379 |
} |
| 8380 |
} else { |
| 8381 |
pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); |
| 8382 |
pathOut->lineTo(pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); |
| 8383 |
} |
| 8384 |
|
| 8385 |
// draw the right side of the segment rectangle |
| 8386 |
// (NB: if stroke adjustment is enabled, the closepath operation MUST |
| 8387 |
// add a segment because this segment is used for a hint) |
| 8388 |
right2 = pathOut->length - 1; |
| 8389 |
pathOut->close(state->strokeAdjust != splashStrokeAdjustOff); |
| 8390 |
|
| 8391 |
// draw the join |
| 8392 |
join2 = pathOut->length; |
| 8393 |
if (!last || closed) { |
| 8394 |
|
| 8395 |
// compute the deltas for segment (j1, k0) |
| 8396 |
#if USE_FIXEDPOINT |
| 8397 |
// the 1/d value can be small, which introduces significant |
| 8398 |
// inaccuracies in fixed point mode |
| 8399 |
d = splashDist(pathIn->pts[j1].x, pathIn->pts[j1].y, |
| 8400 |
pathIn->pts[k0].x, pathIn->pts[k0].y); |
| 8401 |
dxNext = (pathIn->pts[k0].x - pathIn->pts[j1].x) / d; |
| 8402 |
dyNext = (pathIn->pts[k0].y - pathIn->pts[j1].y) / d; |
| 8403 |
#else |
| 8404 |
d = (SplashCoord)1 / splashDist(pathIn->pts[j1].x, pathIn->pts[j1].y, |
| 8405 |
pathIn->pts[k0].x, pathIn->pts[k0].y); |
| 8406 |
dxNext = d * (pathIn->pts[k0].x - pathIn->pts[j1].x); |
| 8407 |
dyNext = d * (pathIn->pts[k0].y - pathIn->pts[j1].y); |
| 8408 |
#endif |
| 8409 |
wdxNext = (SplashCoord)0.5 * w * dxNext; |
| 8410 |
wdyNext = (SplashCoord)0.5 * w * dyNext; |
| 8411 |
|
| 8412 |
// compute the join parameters |
| 8413 |
crossprod = dx * dyNext - dy * dxNext; |
| 8414 |
dotprod = -(dx * dxNext + dy * dyNext); |
| 8415 |
if (dotprod > 0.9999) { |
| 8416 |
// avoid a divide-by-zero -- set miter to something arbitrary |
| 8417 |
// such that sqrt(miter) will exceed miterLimit (and m is never |
| 8418 |
// used in that situation) |
| 8419 |
// (note: the comparison value (0.9999) has to be less than |
| 8420 |
// 1-epsilon, where epsilon is the smallest value |
| 8421 |
// representable in the fixed point format) |
| 8422 |
miter = (state->miterLimit + 1) * (state->miterLimit + 1); |
| 8423 |
m = 0; |
| 8424 |
} else { |
| 8425 |
miter = (SplashCoord)2 / ((SplashCoord)1 - dotprod); |
| 8426 |
if (miter < 1) { |
| 8427 |
// this can happen because of floating point inaccuracies |
| 8428 |
miter = 1; |
| 8429 |
} |
| 8430 |
m = splashSqrt(miter - 1); |
| 8431 |
} |
| 8432 |
|
| 8433 |
// round join |
| 8434 |
if (lineJoin == splashLineJoinRound) { |
| 8435 |
// join angle < 180 |
| 8436 |
if (crossprod < 0) { |
| 8437 |
angle = atan2((double)dx, (double)-dy); |
| 8438 |
angleNext = atan2((double)dxNext, (double)-dyNext); |
| 8439 |
if (angle < angleNext) { |
| 8440 |
angle += 2 * M_PI; |
| 8441 |
} |
| 8442 |
dAngle = (angle - angleNext) / M_PI; |
| 8443 |
if (dAngle < 0.501) { |
| 8444 |
// span angle is <= 90 degrees -> draw a single arc |
| 8445 |
kappa = dAngle * bezierCircle * w; |
| 8446 |
cx1 = pathIn->pts[j0].x - wdy + kappa * dx; |
| 8447 |
cy1 = pathIn->pts[j0].y + wdx + kappa * dy; |
| 8448 |
cx2 = pathIn->pts[j0].x - wdyNext - kappa * dxNext; |
| 8449 |
cy2 = pathIn->pts[j0].y + wdxNext - kappa * dyNext; |
| 8450 |
pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); |
| 8451 |
pathOut->lineTo(pathIn->pts[j0].x - wdyNext, |
| 8452 |
pathIn->pts[j0].y + wdxNext); |
| 8453 |
pathOut->curveTo(cx2, cy2, cx1, cy1, |
| 8454 |
pathIn->pts[j0].x - wdy, |
| 8455 |
pathIn->pts[j0].y + wdx); |
| 8456 |
} else { |
| 8457 |
// span angle is > 90 degrees -> split into two arcs |
| 8458 |
dJoin = splashDist(-wdy, wdx, -wdyNext, wdxNext); |
| 8459 |
if (dJoin > 0) { |
| 8460 |
dxJoin = (-wdyNext + wdy) / dJoin; |
| 8461 |
dyJoin = (wdxNext - wdx) / dJoin; |
| 8462 |
xc = pathIn->pts[j0].x |
| 8463 |
+ (SplashCoord)0.5 * w |
| 8464 |
* cos((double)((SplashCoord)0.5 * (angle + angleNext))); |
| 8465 |
yc = pathIn->pts[j0].y |
| 8466 |
+ (SplashCoord)0.5 * w |
| 8467 |
* sin((double)((SplashCoord)0.5 * (angle + angleNext))); |
| 8468 |
kappa = dAngle * bezierCircle2 * w; |
| 8469 |
cx1 = pathIn->pts[j0].x - wdy + kappa * dx; |
| 8470 |
cy1 = pathIn->pts[j0].y + wdx + kappa * dy; |
| 8471 |
cx2 = xc - kappa * dxJoin; |
| 8472 |
cy2 = yc - kappa * dyJoin; |
| 8473 |
cx3 = xc + kappa * dxJoin; |
| 8474 |
cy3 = yc + kappa * dyJoin; |
| 8475 |
cx4 = pathIn->pts[j0].x - wdyNext - kappa * dxNext; |
| 8476 |
cy4 = pathIn->pts[j0].y + wdxNext - kappa * dyNext; |
| 8477 |
pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); |
| 8478 |
pathOut->lineTo(pathIn->pts[j0].x - wdyNext, |
| 8479 |
pathIn->pts[j0].y + wdxNext); |
| 8480 |
pathOut->curveTo(cx4, cy4, cx3, cy3, xc, yc); |
| 8481 |
pathOut->curveTo(cx2, cy2, cx1, cy1, |
| 8482 |
pathIn->pts[j0].x - wdy, |
| 8483 |
pathIn->pts[j0].y + wdx); |
| 8484 |
} |
| 8485 |
} |
| 8486 |
|
| 8487 |
// join angle >= 180 |
| 8488 |
} else { |
| 8489 |
angle = atan2((double)-dx, (double)dy); |
| 8490 |
angleNext = atan2((double)-dxNext, (double)dyNext); |
| 8491 |
if (angleNext < angle) { |
| 8492 |
angleNext += 2 * M_PI; |
| 8493 |
} |
| 8494 |
dAngle = (angleNext - angle) / M_PI; |
| 8495 |
if (dAngle < 0.501) { |
| 8496 |
// span angle is <= 90 degrees -> draw a single arc |
| 8497 |
kappa = dAngle * bezierCircle * w; |
| 8498 |
cx1 = pathIn->pts[j0].x + wdy + kappa * dx; |
| 8499 |
cy1 = pathIn->pts[j0].y - wdx + kappa * dy; |
| 8500 |
cx2 = pathIn->pts[j0].x + wdyNext - kappa * dxNext; |
| 8501 |
cy2 = pathIn->pts[j0].y - wdxNext - kappa * dyNext; |
| 8502 |
pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); |
| 8503 |
pathOut->lineTo(pathIn->pts[j0].x + wdy, |
| 8504 |
pathIn->pts[j0].y - wdx); |
| 8505 |
pathOut->curveTo(cx1, cy1, cx2, cy2, |
| 8506 |
pathIn->pts[j0].x + wdyNext, |
| 8507 |
pathIn->pts[j0].y - wdxNext); |
| 8508 |
} else { |
| 8509 |
// span angle is > 90 degrees -> split into two arcs |
| 8510 |
dJoin = splashDist(wdy, -wdx, wdyNext, -wdxNext); |
| 8511 |
if (dJoin > 0) { |
| 8512 |
dxJoin = (wdyNext - wdy) / dJoin; |
| 8513 |
dyJoin = (-wdxNext + wdx) / dJoin; |
| 8514 |
xc = pathIn->pts[j0].x |
| 8515 |
+ (SplashCoord)0.5 * w |
| 8516 |
* cos((double)((SplashCoord)0.5 * (angle + angleNext))); |
| 8517 |
yc = pathIn->pts[j0].y |
| 8518 |
+ (SplashCoord)0.5 * w |
| 8519 |
* sin((double)((SplashCoord)0.5 * (angle + angleNext))); |
| 8520 |
kappa = dAngle * bezierCircle2 * w; |
| 8521 |
cx1 = pathIn->pts[j0].x + wdy + kappa * dx; |
| 8522 |
cy1 = pathIn->pts[j0].y - wdx + kappa * dy; |
| 8523 |
cx2 = xc - kappa * dxJoin; |
| 8524 |
cy2 = yc - kappa * dyJoin; |
| 8525 |
cx3 = xc + kappa * dxJoin; |
| 8526 |
cy3 = yc + kappa * dyJoin; |
| 8527 |
cx4 = pathIn->pts[j0].x + wdyNext - kappa * dxNext; |
| 8528 |
cy4 = pathIn->pts[j0].y - wdxNext - kappa * dyNext; |
| 8529 |
pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); |
| 8530 |
pathOut->lineTo(pathIn->pts[j0].x + wdy, |
| 8531 |
pathIn->pts[j0].y - wdx); |
| 8532 |
pathOut->curveTo(cx1, cy1, cx2, cy2, xc, yc); |
| 8533 |
pathOut->curveTo(cx3, cy3, cx4, cy4, |
| 8534 |
pathIn->pts[j0].x + wdyNext, |
| 8535 |
pathIn->pts[j0].y - wdxNext); |
| 8536 |
} |
| 8537 |
} |
| 8538 |
} |
| 8539 |
|
| 8540 |
} else { |
| 8541 |
pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); |
| 8542 |
|
| 8543 |
// join angle < 180 |
| 8544 |
if (crossprod < 0) { |
| 8545 |
pathOut->lineTo(pathIn->pts[j0].x - wdyNext, |
| 8546 |
pathIn->pts[j0].y + wdxNext); |
| 8547 |
// miter join inside limit |
| 8548 |
if (lineJoin == splashLineJoinMiter && |
| 8549 |
splashSqrt(miter) <= state->miterLimit) { |
| 8550 |
pathOut->lineTo(pathIn->pts[j0].x - wdy + wdx * m, |
| 8551 |
pathIn->pts[j0].y + wdx + wdy * m); |
| 8552 |
pathOut->lineTo(pathIn->pts[j0].x - wdy, |
| 8553 |
pathIn->pts[j0].y + wdx); |
| 8554 |
// bevel join or miter join outside limit |
| 8555 |
} else { |
| 8556 |
pathOut->lineTo(pathIn->pts[j0].x - wdy, |
| 8557 |
pathIn->pts[j0].y + wdx); |
| 8558 |
} |
| 8559 |
|
| 8560 |
// join angle >= 180 |
| 8561 |
} else { |
| 8562 |
pathOut->lineTo(pathIn->pts[j0].x + wdy, |
| 8563 |
pathIn->pts[j0].y - wdx); |
| 8564 |
// miter join inside limit |
| 8565 |
if (lineJoin == splashLineJoinMiter && |
| 8566 |
splashSqrt(miter) <= state->miterLimit) { |
| 8567 |
pathOut->lineTo(pathIn->pts[j0].x + wdy + wdx * m, |
| 8568 |
pathIn->pts[j0].y - wdx + wdy * m); |
| 8569 |
pathOut->lineTo(pathIn->pts[j0].x + wdyNext, |
| 8570 |
pathIn->pts[j0].y - wdxNext); |
| 8571 |
// bevel join or miter join outside limit |
| 8572 |
} else { |
| 8573 |
pathOut->lineTo(pathIn->pts[j0].x + wdyNext, |
| 8574 |
pathIn->pts[j0].y - wdxNext); |
| 8575 |
} |
| 8576 |
} |
| 8577 |
} |
| 8578 |
|
| 8579 |
pathOut->close(); |
| 8580 |
} |
| 8581 |
|
| 8582 |
// add stroke adjustment hints |
| 8583 |
if (state->strokeAdjust != splashStrokeAdjustOff) { |
| 8584 |
|
| 8585 |
// subpath with one segment |
| 8586 |
if (seg == 0 && last) { |
| 8587 |
switch (lineCap) { |
| 8588 |
case splashLineCapButt: |
| 8589 |
pathOut->addStrokeAdjustHint(firstPt, left2 + 1, |
| 8590 |
firstPt, pathOut->length - 1); |
| 8591 |
break; |
| 8592 |
case splashLineCapProjecting: |
| 8593 |
pathOut->addStrokeAdjustHint(firstPt, left2 + 1, |
| 8594 |
firstPt, pathOut->length - 1, gTrue); |
| 8595 |
break; |
| 8596 |
case splashLineCapRound: |
| 8597 |
break; |
| 8598 |
} |
| 8599 |
pathOut->addStrokeAdjustHint(left2, right2, |
| 8600 |
firstPt, pathOut->length - 1); |
| 8601 |
} else { |
| 8602 |
|
| 8603 |
// start of subpath |
| 8604 |
if (seg == 1) { |
| 8605 |
|
| 8606 |
// start cap |
| 8607 |
if (!closed) { |
| 8608 |
switch (lineCap) { |
| 8609 |
case splashLineCapButt: |
| 8610 |
pathOut->addStrokeAdjustHint(firstPt, left1 + 1, |
| 8611 |
firstPt, firstPt + 1); |
| 8612 |
pathOut->addStrokeAdjustHint(firstPt, left1 + 1, |
| 8613 |
right1 + 1, right1 + 1); |
| 8614 |
break; |
| 8615 |
case splashLineCapProjecting: |
| 8616 |
pathOut->addStrokeAdjustHint(firstPt, left1 + 1, |
| 8617 |
firstPt, firstPt + 1, gTrue); |
| 8618 |
pathOut->addStrokeAdjustHint(firstPt, left1 + 1, |
| 8619 |
right1 + 1, right1 + 1, gTrue); |
| 8620 |
break; |
| 8621 |
case splashLineCapRound: |
| 8622 |
break; |
| 8623 |
} |
| 8624 |
} |
| 8625 |
|
| 8626 |
// first segment |
| 8627 |
pathOut->addStrokeAdjustHint(left1, right1, firstPt, left2); |
| 8628 |
pathOut->addStrokeAdjustHint(left1, right1, right2 + 1, right2 + 1); |
| 8629 |
} |
| 8630 |
|
| 8631 |
// middle of subpath |
| 8632 |
if (seg > 1) { |
| 8633 |
pathOut->addStrokeAdjustHint(left1, right1, left0 + 1, right0); |
| 8634 |
pathOut->addStrokeAdjustHint(left1, right1, join0, left2); |
| 8635 |
pathOut->addStrokeAdjustHint(left1, right1, right2 + 1, right2 + 1); |
| 8636 |
} |
| 8637 |
|
| 8638 |
// end of subpath |
| 8639 |
if (last) { |
| 8640 |
|
| 8641 |
if (closed) { |
| 8642 |
// first segment |
| 8643 |
pathOut->addStrokeAdjustHint(leftFirst, rightFirst, |
| 8644 |
left2 + 1, right2); |
| 8645 |
pathOut->addStrokeAdjustHint(leftFirst, rightFirst, |
| 8646 |
join2, pathOut->length - 1); |
| 8647 |
|
| 8648 |
// last segment |
| 8649 |
pathOut->addStrokeAdjustHint(left2, right2, |
| 8650 |
left1 + 1, right1); |
| 8651 |
pathOut->addStrokeAdjustHint(left2, right2, |
| 8652 |
join1, pathOut->length - 1); |
| 8653 |
pathOut->addStrokeAdjustHint(left2, right2, |
| 8654 |
leftFirst - 1, leftFirst); |
| 8655 |
pathOut->addStrokeAdjustHint(left2, right2, |
| 8656 |
rightFirst + 1, rightFirst + 1); |
| 8657 |
|
| 8658 |
} else { |
| 8659 |
|
| 8660 |
// last segment |
| 8661 |
pathOut->addStrokeAdjustHint(left2, right2, |
| 8662 |
left1 + 1, right1); |
| 8663 |
pathOut->addStrokeAdjustHint(left2, right2, |
| 8664 |
join1, pathOut->length - 1); |
| 8665 |
|
| 8666 |
// end cap |
| 8667 |
switch (lineCap) { |
| 8668 |
case splashLineCapButt: |
| 8669 |
pathOut->addStrokeAdjustHint(left2 - 1, left2 + 1, |
| 8670 |
left2 + 1, left2 + 2); |
| 8671 |
break; |
| 8672 |
case splashLineCapProjecting: |
| 8673 |
pathOut->addStrokeAdjustHint(left2 - 1, left2 + 1, |
| 8674 |
left2 + 1, left2 + 2, gTrue); |
| 8675 |
break; |
| 8676 |
case splashLineCapRound: |
| 8677 |
break; |
| 8678 |
} |
| 8679 |
} |
| 8680 |
} |
| 8681 |
} |
| 8682 |
|
| 8683 |
left0 = left1; |
| 8684 |
left1 = left2; |
| 8685 |
right0 = right1; |
| 8686 |
right1 = right2; |
| 8687 |
join0 = join1; |
| 8688 |
join1 = join2; |
| 8689 |
if (seg == 0) { |
| 8690 |
leftFirst = left2; |
| 8691 |
rightFirst = right2; |
| 8692 |
} |
| 8693 |
} |
| 8694 |
|
| 8695 |
i0 = j0; |
| 8696 |
i1 = j1; |
| 8697 |
++seg; |
| 8698 |
} |
| 8699 |
|
| 8700 |
if (pathIn != path) { |
| 8701 |
delete pathIn; |
| 8702 |
} |
| 8703 |
|
| 8704 |
return pathOut; |
| 8705 |
} |
| 8706 |
|
| 8707 |
SplashClipResult Splash::limitRectToClipRect(int *xMin, int *yMin, |
| 8708 |
int *xMax, int *yMax) { |
| 8709 |
int t; |
| 8710 |
|
| 8711 |
if ((t = state->clip->getXMinI(state->strokeAdjust)) > *xMin) { |
| 8712 |
*xMin = t; |
| 8713 |
} |
| 8714 |
if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < *xMax) { |
| 8715 |
*xMax = t; |
| 8716 |
} |
| 8717 |
if ((t = state->clip->getYMinI(state->strokeAdjust)) > *yMin) { |
| 8718 |
*yMin = t; |
| 8719 |
} |
| 8720 |
if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < *yMax) { |
| 8721 |
*yMax = t; |
| 8722 |
} |
| 8723 |
if (*xMin >= *xMax || *yMin >= *yMax) { |
| 8724 |
return splashClipAllOutside; |
| 8725 |
} |
| 8726 |
return state->clip->testRect(*xMin, *yMin, *xMax - 1, *yMax - 1, |
| 8727 |
state->strokeAdjust); |
| 8728 |
} |
| 8729 |
|
| 8730 |
void Splash::dumpPath(SplashPath *path) { |
| 8731 |
int i; |
| 8732 |
|
| 8733 |
for (i = 0; i < path->length; ++i) { |
| 8734 |
printf(" %3d: x=%8.2f y=%8.2f%s%s%s%s\n", |
| 8735 |
i, (double)path->pts[i].x, (double)path->pts[i].y, |
| 8736 |
(path->flags[i] & splashPathFirst) ? " first" : "", |
| 8737 |
(path->flags[i] & splashPathLast) ? " last" : "", |
| 8738 |
(path->flags[i] & splashPathClosed) ? " closed" : "", |
| 8739 |
(path->flags[i] & splashPathCurve) ? " curve" : ""); |
| 8740 |
} |
| 8741 |
if (path->hintsLength == 0) { |
| 8742 |
printf(" no hints\n"); |
| 8743 |
} else { |
| 8744 |
for (i = 0; i < path->hintsLength; ++i) { |
| 8745 |
printf(" hint %3d: ctrl0=%d ctrl1=%d pts=%d..%d\n", |
| 8746 |
i, path->hints[i].ctrl0, path->hints[i].ctrl1, |
| 8747 |
path->hints[i].firstPt, path->hints[i].lastPt); |
| 8748 |
} |
| 8749 |
} |
| 8750 |
} |
| 8751 |
|
| 8752 |
void Splash::dumpXPath(SplashXPath *path) { |
| 8753 |
int i; |
| 8754 |
|
| 8755 |
for (i = 0; i < path->length; ++i) { |
| 8756 |
printf(" %4d: x0=%8.2f y0=%8.2f x1=%8.2f y1=%8.2f count=%d\n", |
| 8757 |
i, (double)path->segs[i].x0, (double)path->segs[i].y0, |
| 8758 |
(double)path->segs[i].x1, (double)path->segs[i].y1, |
| 8759 |
path->segs[i].count); |
| 8760 |
} |
| 8761 |
} |
| 8762 |
|