Commit 68af136f authored by Albert Astals Cid's avatar Albert Astals Cid Committed by Albert Astals Cid

Implement Splash::gouraudTriangleShadedFill for non parametrized shadings

Fixes #881

Unfortunately only implemented for shadings where the 3 vertices of the
triangle have the same color for now since i got lost trying to
implement the coloring (and also have no pdf to check against)

The reason this fixes #881 is because if Splash::gouraudTriangleShadedFill
returns false because it doesn't natively support this shading, the
default rendering algorithm of Gfx.cc kicks in, and that rendering what
does is render different triangles without them knowing they belong to
the same shading, meaning that if you have some opacity the edges of the
triangles will overlap and and up having different color than the one
you really wanted
parent d4a7367d
......@@ -82,9 +82,9 @@
static const double s_minLineWidth = 0.0;
static inline void convertGfxColor(SplashColorPtr dest,
SplashColorMode colorMode,
GfxColorSpace *colorSpace,
GfxColor *src) {
const SplashColorMode colorMode,
const GfxColorSpace *colorSpace,
const GfxColor *src) {
SplashColor color;
GfxGray gray;
GfxRGB rgb;
......@@ -134,9 +134,9 @@ static inline void convertGfxColor(SplashColorPtr dest,
// to ensure that everything is initialized.
static inline void convertGfxShortColor(SplashColorPtr dest,
SplashColorMode colorMode,
GfxColorSpace *colorSpace,
GfxColor *src) {
const SplashColorMode colorMode,
const GfxColorSpace *colorSpace,
const GfxColor *src) {
switch (colorMode) {
case splashModeMono1:
case splashModeMono8:
......@@ -194,21 +194,29 @@ SplashGouraudPattern::SplashGouraudPattern(bool bDirectColorTranslationA,
SplashGouraudPattern::~SplashGouraudPattern() {
}
void SplashGouraudPattern::getNonParametrizedTriangle(int i, SplashColorMode mode, double *x0, double *y0, SplashColorPtr color0,
double *x1, double *y1, SplashColorPtr color1,
double *x2, double *y2, SplashColorPtr color2) {
GfxColor c0, c1, c2;
shading->getTriangle(i, x0, y0, &c0, x1, y1, &c1, x2, y2, &c2);
const GfxColorSpace* srcColorSpace = shading->getColorSpace();
convertGfxColor(color0, mode, srcColorSpace, &c0);
convertGfxColor(color1, mode, srcColorSpace, &c1);
convertGfxColor(color2, mode, srcColorSpace, &c2);
}
void SplashGouraudPattern::getParameterizedColor(double colorinterp, SplashColorMode mode, SplashColorPtr dest) {
GfxColor src;
GfxColorSpace* srcColorSpace = shading->getColorSpace();
int colorComps = 3;
if (mode == splashModeCMYK8)
colorComps=4;
else if (mode == splashModeDeviceN8)
colorComps=4 + SPOT_NCOMPS;
shading->getParameterizedColor(colorinterp, &src);
if (bDirectColorTranslation) {
const int colorComps = splashColorModeNComps[mode];
for (int m = 0; m < colorComps; ++m)
dest[m] = colToByte(src.c[m]);
} else {
GfxColorSpace* srcColorSpace = shading->getColorSpace();
convertGfxShortColor(dest, mode, srcColorSpace, &src);
}
}
......@@ -4540,17 +4548,12 @@ bool SplashOutputDev::gouraudTriangleShadedFill(GfxState *state, GfxGouraudTrian
break;
}
// restore vector antialias because we support it here
if (shading->isParameterized()) {
SplashGouraudColor *splashShading = new SplashGouraudPattern(bDirectColorTranslation, state, shading);
bool vaa = getVectorAntialias();
bool retVal = false;
setVectorAntialias(true);
retVal = splash->gouraudTriangleShadedFill(splashShading);
setVectorAntialias(vaa);
delete splashShading;
return retVal;
}
return false;
SplashGouraudPattern splashShading(bDirectColorTranslation, state, shading);
const bool vaa = getVectorAntialias();
setVectorAntialias(true);
const bool retVal = splash->gouraudTriangleShadedFill(&splashShading);
setVectorAntialias(vaa);
return retVal;
}
bool SplashOutputDev::univariateShadedFill(GfxState *state, SplashUnivariatePattern *pattern, double tMin, double tMax) {
......
......@@ -147,11 +147,16 @@ public:
bool isParameterized() override { return shading->isParameterized(); }
int getNTriangles() override { return shading->getNTriangles(); }
void getTriangle(int i, double *x0, double *y0, double *color0,
double *x1, double *y1, double *color1,
double *x2, double *y2, double *color2) override
void getParametrizedTriangle(int i, double *x0, double *y0, double *color0,
double *x1, double *y1, double *color1,
double *x2, double *y2, double *color2) override
{ shading->getTriangle(i, x0, y0, color0, x1, y1, color1, x2, y2, color2); }
void getNonParametrizedTriangle(int i, SplashColorMode mode,
double *x0, double *y0, SplashColorPtr color0,
double *x1, double *y1, SplashColorPtr color1,
double *x2, double *y2, SplashColorPtr color2) override;
void getParameterizedColor(double colorinterp, SplashColorMode mode, SplashColorPtr dest) override;
private:
......
This diff is collapsed.
......@@ -94,10 +94,15 @@ public:
virtual int getNTriangles() = 0;
virtual void getTriangle(int i, double *x0, double *y0, double *color0,
virtual void getParametrizedTriangle(int i, double *x0, double *y0, double *color0,
double *x1, double *y1, double *color1,
double *x2, double *y2, double *color2) = 0;
virtual void getNonParametrizedTriangle(int i, SplashColorMode mode,
double *x0, double *y0, SplashColorPtr color0,
double *x1, double *y1, SplashColorPtr color1,
double *x2, double *y2, SplashColorPtr color2) = 0;
virtual void getParameterizedColor(double t, SplashColorMode mode, SplashColorPtr c) = 0;
};
......
......@@ -128,6 +128,13 @@ static inline void splashColorCopy(SplashColorPtr dest, SplashColorConstPtr src)
dest[i] = src[i];
}
static inline bool splashColorEqual(SplashColorConstPtr dest, SplashColorConstPtr src) {
for (int i = 0; i < SPOT_NCOMPS + 4; i++)
if (dest[i] != src[i])
return false;
return true;
}
static inline void splashColorXor(SplashColorPtr dest, SplashColorConstPtr src) {
dest[0] ^= src[0];
dest[1] ^= src[1];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment