summaryrefslogtreecommitdiff
path: root/splash/SplashScreen.cc
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2011-09-01 00:11:49 +0200
committerAlbert Astals Cid <aacid@kde.org>2011-09-01 00:11:49 +0200
commitd00d56e4a46e8534378534de0d94ce0551d75d84 (patch)
tree1372df250d1040bc0c378e486ba4664dc1ec1caa /splash/SplashScreen.cc
parent5e8debf96ab1bb9db31a0332a482d08c181d52ea (diff)
xpdf303: Speedup SplashScreen
By using << instead of * and by putting some functions on the header so they can be inlined
Diffstat (limited to 'splash/SplashScreen.cc')
-rw-r--r--splash/SplashScreen.cc89
1 files changed, 30 insertions, 59 deletions
diff --git a/splash/SplashScreen.cc b/splash/SplashScreen.cc
index 40f24664..d7412469 100644
--- a/splash/SplashScreen.cc
+++ b/splash/SplashScreen.cc
@@ -78,41 +78,38 @@ SplashScreen::SplashScreen(SplashScreenParams *params) {
void SplashScreen::createMatrix()
{
- Guchar u, black, white;
- int i;
+ Guchar u;
+ int black, white, i;
SplashScreenParams *params = screenParams;
+ // size must be a power of 2, and at least 2
+ for (size = 2, log2Size = 1; size < params->size; size <<= 1, ++log2Size) ;
+
switch (params->type) {
case splashScreenDispersed:
- // size must be a power of 2
- for (size = 1; size < params->size; size <<= 1) ;
mat = (Guchar *)gmallocn(size * size, sizeof(Guchar));
buildDispersedMatrix(size/2, size/2, 1, size/2, 1);
break;
case splashScreenClustered:
- // size must be even
- size = (params->size >> 1) << 1;
- if (size < 2) {
- size = 2;
- }
mat = (Guchar *)gmallocn(size * size, sizeof(Guchar));
buildClusteredMatrix();
break;
case splashScreenStochasticClustered:
// size must be at least 2*r
- if (params->size < 2 * params->dotRadius) {
- size = 2 * params->dotRadius;
- } else {
- size = params->size;
+ while (size < (params->dotRadius << 1)) {
+ size <<= 1;
+ ++log2Size;
}
mat = (Guchar *)gmallocn(size * size, sizeof(Guchar));
buildSCDMatrix(params->dotRadius);
break;
}
+
+ sizeM1 = size - 1;
// do gamma correction and compute minVal/maxVal
minVal = 255;
@@ -131,9 +128,9 @@ void SplashScreen::createMatrix()
u = splashRound((SplashCoord)255.0 *
splashPow((SplashCoord)mat[i] / 255.0, params->gamma));
if (u < black) {
- u = black;
+ u = (Guchar)black;
} else if (u >= white) {
- u = white;
+ u = (Guchar)white;
}
mat[i] = u;
if (u < minVal) {
@@ -148,7 +145,7 @@ void SplashScreen::buildDispersedMatrix(int i, int j, int val,
int delta, int offset) {
if (delta == 0) {
// map values in [1, size^2] --> [1, 255]
- mat[i * size + j] = 1 + (254 * (val - 1)) / (size * size - 1);
+ mat[(i << log2Size) + j] = 1 + (254 * (val - 1)) / (size * size - 1);
} else {
buildDispersedMatrix(i, j,
val, delta / 2, 4*offset);
@@ -172,7 +169,7 @@ void SplashScreen::buildClusteredMatrix() {
// initialize the threshold matrix
for (y = 0; y < size; ++y) {
for (x = 0; x < size; ++x) {
- mat[y * size + x] = 0;
+ mat[(y << log2Size) + x] = 0;
}
}
@@ -204,14 +201,12 @@ void SplashScreen::buildClusteredMatrix() {
}
// build the threshold matrix
- minVal = 1;
- maxVal = 0;
x1 = y1 = 0; // make gcc happy
for (i = 0; i < size * size2; ++i) {
d = -1;
for (y = 0; y < size; ++y) {
for (x = 0; x < size2; ++x) {
- if (mat[y * size + x] == 0 &&
+ if (mat[(y << log2Size) + x] == 0 &&
dist[y * size2 + x] > d) {
x1 = x;
y1 = y;
@@ -221,12 +216,12 @@ void SplashScreen::buildClusteredMatrix() {
}
// map values in [0, 2*size*size2-1] --> [1, 255]
val = 1 + (254 * (2*i)) / (2*size*size2 - 1);
- mat[y1 * size + x1] = val;
+ mat[(y1 << log2Size) + x1] = val;
val = 1 + (254 * (2*i+1)) / (2*size*size2 - 1);
if (y1 < size2) {
- mat[(y1 + size2) * size + x1 + size2] = val;
+ mat[((y1 + size2) << log2Size) + x1 + size2] = val;
} else {
- mat[(y1 - size2) * size + x1 + size2] = val;
+ mat[((y1 - size2) << log2Size) + x1 + size2] = val;
}
}
@@ -294,7 +289,7 @@ void SplashScreen::buildSCDMatrix(int r) {
grid = (char *)gmallocn(size * size, sizeof(char));
for (y = 0; y < size; ++y) {
for (x = 0; x < size; ++x) {
- grid[y*size + x] = 0;
+ grid[(y << log2Size) + x] = 0;
}
}
@@ -305,7 +300,7 @@ void SplashScreen::buildSCDMatrix(int r) {
for (i = 0; i < size * size; ++i) {
x = pts[i].x;
y = pts[i].y;
- if (!grid[y*size + x]) {
+ if (!grid[(y << log2Size) + x]) {
if (dotsLen == dotsSize) {
dotsSize *= 2;
dots = (SplashScreenPoint *)greallocn(dots, dotsSize,
@@ -319,10 +314,10 @@ void SplashScreen::buildSCDMatrix(int r) {
if (tmpl[yy*(r+1) + xx]) {
x0 = (x + xx) % size;
x1 = (x - xx + size) % size;
- grid[y0*size + x0] = 1;
- grid[y0*size + x1] = 1;
- grid[y1*size + x0] = 1;
- grid[y1*size + x1] = 1;
+ grid[(y0 << log2Size) + x0] = 1;
+ grid[(y0 << log2Size) + x1] = 1;
+ grid[(y1 << log2Size) + x0] = 1;
+ grid[(y1 << log2Size) + x1] = 1;
}
}
}
@@ -346,8 +341,8 @@ void SplashScreen::buildSCDMatrix(int r) {
dMin = d;
}
}
- region[y*size + x] = iMin;
- dist[y*size + x] = dMin;
+ region[(y << log2Size) + x] = iMin;
+ dist[(y << log2Size) + x] = dMin;
}
}
@@ -356,7 +351,7 @@ void SplashScreen::buildSCDMatrix(int r) {
n = 0;
for (y = 0; y < size; ++y) {
for (x = 0; x < size; ++x) {
- if (region[y*size + x] == i) {
+ if (region[(y << log2Size) + x] == i) {
pts[n].x = x;
pts[n].y = y;
pts[n].dist = distance(dots[i].x, dots[i].y, x, y);
@@ -367,7 +362,7 @@ void SplashScreen::buildSCDMatrix(int r) {
std::sort(pts, pts + n, cmpDistancesFunctor());
for (j = 0; j < n; ++j) {
// map values in [0 .. n-1] --> [255 .. 1]
- mat[pts[j].y * size + pts[j].x] = 255 - (254 * j) / (n - 1);
+ mat[(pts[j].y << log2Size) + pts[j].x] = 255 - (254 * j) / (n - 1);
}
}
@@ -381,6 +376,8 @@ void SplashScreen::buildSCDMatrix(int r) {
SplashScreen::SplashScreen(SplashScreen *screen) {
screenParams = screen->screenParams;
size = screen->size;
+ sizeM1 = screen->sizeM1;
+ log2Size = screen->log2Size;
mat = (Guchar *)gmallocn(size * size, sizeof(Guchar));
memcpy(mat, screen->mat, size * size * sizeof(Guchar));
minVal = screen->minVal;
@@ -390,29 +387,3 @@ SplashScreen::SplashScreen(SplashScreen *screen) {
SplashScreen::~SplashScreen() {
gfree(mat);
}
-
-int SplashScreen::test(int x, int y, Guchar value) {
- int xx, yy;
-
- if (mat == NULL) createMatrix();
-
- if (value < minVal) {
- return 0;
- }
- if (value >= maxVal) {
- return 1;
- }
- if ((xx = x % size) < 0) {
- xx = -xx;
- }
- if ((yy = y % size) < 0) {
- yy = -yy;
- }
- return value < mat[yy * size + xx] ? 0 : 1;
-}
-
-GBool SplashScreen::isStatic(Guchar value) {
- if (mat == NULL) createMatrix();
-
- return value < minVal || value >= maxVal;
-}