Commit f9d208e8 authored by Albert Astals Cid's avatar Albert Astals Cid

Merge SplashScreen.[cc|h] from xpdf 3.01

parent 7d46ac00
2005-09-20 Albert Astals Cid <aacid@kde.org>
* splash/SplashXPathScanner.cc: Merge from xpdf 3.01
* splash/SplashScreen.[cc|h]: Merge from xpdf 3.01
2005-10-05 Kristian Høgsberg <krh@redhat.com> 2005-10-05 Kristian Høgsberg <krh@redhat.com>
* glib/poppler-page.cc (poppler_page_render_to_ps): Fix another * glib/poppler-page.cc (poppler_page_render_to_ps): Fix another
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#pragma implementation #pragma implementation
#endif #endif
#include <string.h>
#include "goo/gmem.h" #include "goo/gmem.h"
#include "SplashMath.h" #include "SplashMath.h"
#include "SplashScreen.h" #include "SplashScreen.h"
...@@ -23,85 +24,118 @@ ...@@ -23,85 +24,118 @@
// Gamma correction (gamma = 1 / 1.33) is also computed here. // Gamma correction (gamma = 1 / 1.33) is also computed here.
SplashScreen::SplashScreen(int sizeA) { SplashScreen::SplashScreen(int sizeA) {
SplashCoord *dist; SplashCoord *dist;
SplashCoord u, v, d; SplashCoord u, v, d, val;
int x, y, x1, y1, i; int size2, x, y, x1, y1, i;
size = sizeA >> 1; size2 = sizeA >> 1;
if (size < 1) { if (size2 < 1) {
size = 1; size2 = 1;
} }
size = size2 << 1;
// initialize the threshold matrix // initialize the threshold matrix
mat = (SplashCoord *)gmallocn(2 * size * size, sizeof(SplashCoord)); mat = (SplashCoord *)gmallocn(size * size, sizeof(SplashCoord));
for (y = 0; y < 2 * size; ++y) { for (y = 0; y < size; ++y) {
for (x = 0; x < size; ++x) { for (x = 0; x < size; ++x) {
mat[y * size + x] = -1; mat[y * size + x] = -1;
} }
} }
// build the distance matrix // build the distance matrix
dist = (SplashCoord *)gmallocn(2 * size * size, sizeof(SplashCoord)); dist = (SplashCoord *)gmallocn(size * size2, sizeof(SplashCoord));
for (y = 0; y < size; ++y) { for (y = 0; y < size2; ++y) {
for (x = 0; x < size; ++x) { for (x = 0; x < size2; ++x) {
if (x + y < size - 1) { if (x + y < size2 - 1) {
u = (SplashCoord)x + 0.5 - 0; //~ (-0.5); u = (SplashCoord)x + 0.5 - 0;
v = (SplashCoord)y + 0.5 - 0; v = (SplashCoord)y + 0.5 - 0;
} else { } else {
u = (SplashCoord)x + 0.5 - (SplashCoord)size; //~ ((SplashCoord)size - 0.5); u = (SplashCoord)x + 0.5 - (SplashCoord)size2;
v = (SplashCoord)y + 0.5 - (SplashCoord)size; v = (SplashCoord)y + 0.5 - (SplashCoord)size2;
} }
dist[y * size + x] = u*u + v*v; dist[y * size2 + x] = u*u + v*v;
} }
} }
for (y = 0; y < size; ++y) { for (y = 0; y < size2; ++y) {
for (x = 0; x < size; ++x) { for (x = 0; x < size2; ++x) {
if (x < y) { if (x < y) {
u = (SplashCoord)x + 0.5 - 0; //~ (-0.5); u = (SplashCoord)x + 0.5 - 0;
v = (SplashCoord)y + 0.5 - (SplashCoord)size; v = (SplashCoord)y + 0.5 - (SplashCoord)size2;
} else { } else {
u = (SplashCoord)x + 0.5 - (SplashCoord)size; //~ ((SplashCoord)size - 0.5); u = (SplashCoord)x + 0.5 - (SplashCoord)size2;
v = (SplashCoord)y + 0.5 - 0; v = (SplashCoord)y + 0.5 - 0;
} }
dist[(size + y) * size + x] = u*u + v*v; dist[(size2 + y) * size2 + x] = u*u + v*v;
} }
} }
// build the threshold matrix // build the threshold matrix
minVal = 1;
maxVal = 0;
x1 = y1 = 0; // make gcc happy x1 = y1 = 0; // make gcc happy
for (i = 1; i <= 2 * size * size; ++i) { for (i = 1; i <= size * size2; ++i) {
d = 2 * size * size; d = size * size2;
for (y = 0; y < 2 * size; ++y) { for (y = 0; y < size; ++y) {
for (x = 0; x < size; ++x) { for (x = 0; x < size2; ++x) {
if (mat[y * size + x] < 0 && if (mat[y * size + x] < 0 &&
dist[y * size + x] < d) { dist[y * size2 + x] < d) {
x1 = x; x1 = x;
y1 = y; y1 = y;
d = dist[y1 * size + x1]; d = dist[y1 * size2 + x1];
} }
} }
} }
u = 1.0 - (SplashCoord)i / (SplashCoord)(2 * size * size + 1); u = (SplashCoord)1 - (SplashCoord)i / (SplashCoord)(size * size2 + 1);
mat[y1 * size + x1] = splashPow(u, 1.33); val = splashPow(u, 1.33);
if (val < minVal) {
minVal = val;
}
if (val > maxVal) {
maxVal = val;
}
mat[y1 * size + x1] = val;
if (y1 < size2) {
mat[(y1 + size2) * size + x1 + size2] = val;
} else {
mat[(y1 - size2) * size + x1 + size2] = val;
}
} }
gfree(dist); gfree(dist);
} }
SplashScreen::SplashScreen(SplashScreen *screen) {
int n;
size = screen->size;
n = size * size * sizeof(SplashCoord);
mat = (SplashCoord *)gmalloc(n);
memcpy(mat, screen->mat, n);
minVal = screen->minVal;
maxVal = screen->maxVal;
}
SplashScreen::~SplashScreen() { SplashScreen::~SplashScreen() {
gfree(mat); gfree(mat);
} }
int SplashScreen::test(int x, int y, SplashCoord value) { int SplashScreen::test(int x, int y, SplashCoord value) {
SplashCoord *mat1;
int xx, yy; int xx, yy;
xx = x % (2 * size); if (value < minVal) {
yy = y % (2 * size); return 0;
mat1 = mat; }
if ((xx / size) ^ (yy / size)) { if (value >= maxVal) {
mat1 += size * size; return 1;
} }
xx %= size; if ((xx = x % size) < 0) {
yy %= size; xx = -xx;
return value < mat1[yy * size + xx] ? 0 : 1; }
if ((yy = y % size) < 0) {
yy = -yy;
}
return value < mat[yy * size + xx] ? 0 : 1;
}
GBool SplashScreen::isStatic(SplashCoord value) {
return value < minVal || value >= maxVal;
} }
...@@ -21,18 +21,28 @@ class SplashScreen { ...@@ -21,18 +21,28 @@ class SplashScreen {
public: public:
SplashScreen(int sizeA); SplashScreen(int sizeA);
SplashScreen(SplashScreen *screen);
~SplashScreen(); ~SplashScreen();
SplashScreen *copy() { return new SplashScreen(size << 1); } SplashScreen *copy() { return new SplashScreen(this); }
// Return the computed pixel value (0=black, 1=white) for the gray // Return the computed pixel value (0=black, 1=white) for the gray
// level <value> at (<x>, <y>). // level <value> at (<x>, <y>).
int test(int x, int y, SplashCoord value); int test(int x, int y, SplashCoord value);
// Returns true if value is above the white threshold or below the
// black threshold, i.e., if the corresponding halftone will be
// solid white or black.
GBool isStatic(SplashCoord value);
private: private:
SplashCoord *mat; // threshold matrix SplashCoord *mat; // threshold matrix
int size; // size of the threshold matrix int size; // size of the threshold matrix
SplashCoord minVal; // any pixel value below minVal generates
// solid black
SplashCoord maxVal; // any pixel value above maxVal generates
// solid white
}; };
#endif #endif
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