]> www.fi.muni.cz Git - evince.git/blob - pdf/splash/SplashScreen.cc
added.
[evince.git] / pdf / splash / SplashScreen.cc
1 //========================================================================
2 //
3 // SplashScreen.cc
4 //
5 //========================================================================
6
7 #include <aconf.h>
8
9 #ifdef USE_GCC_PRAGMAS
10 #pragma implementation
11 #endif
12
13 #include "gmem.h"
14 #include "SplashMath.h"
15 #include "SplashScreen.h"
16
17 //------------------------------------------------------------------------
18 // SplashScreen
19 //------------------------------------------------------------------------
20
21 // This generates a 45 degree screen using a circular dot spot
22 // function.  DPI = resolution / ((size / 2) * sqrt(2)).
23 // Gamma correction (gamma = 1 / 1.33) is also computed here.
24 SplashScreen::SplashScreen(int sizeA) {
25   SplashCoord *dist;
26   SplashCoord u, v, d;
27   int x, y, x1, y1, i;
28
29   size = sizeA >> 1;
30   if (size < 1) {
31     size = 1;
32   }
33
34   // initialize the threshold matrix
35   mat = (SplashCoord *)gmalloc(2 * size * size * sizeof(SplashCoord));
36   for (y = 0; y < 2 * size; ++y) {
37     for (x = 0; x < size; ++x) {
38       mat[y * size + x] = -1;
39     }
40   }
41
42   // build the distance matrix
43   dist = (SplashCoord *)gmalloc(2 * size * size * sizeof(SplashCoord));
44   for (y = 0; y < size; ++y) {
45     for (x = 0; x < size; ++x) {
46       if (x + y < size - 1) {
47         u = (SplashCoord)x + 0.5 - 0;  //~ (-0.5);
48         v = (SplashCoord)y + 0.5 - 0;
49       } else {
50         u = (SplashCoord)x + 0.5 - (SplashCoord)size; //~ ((SplashCoord)size - 0.5);
51         v = (SplashCoord)y + 0.5 - (SplashCoord)size;
52       }
53       dist[y * size + x] = u*u + v*v;
54     }
55   }
56   for (y = 0; y < size; ++y) {
57     for (x = 0; x < size; ++x) {
58       if (x < y) {
59         u = (SplashCoord)x + 0.5 - 0;  //~ (-0.5);
60         v = (SplashCoord)y + 0.5 - (SplashCoord)size;
61       } else {
62         u = (SplashCoord)x + 0.5 - (SplashCoord)size; //~ ((SplashCoord)size - 0.5);
63         v = (SplashCoord)y + 0.5 - 0;
64       }
65       dist[(size + y) * size + x] = u*u + v*v;
66     }
67   }
68
69   // build the threshold matrix
70   x1 = y1 = 0; // make gcc happy
71   for (i = 1; i <= 2 * size * size; ++i) {
72     d = 2 * size * size;
73     for (y = 0; y < 2 * size; ++y) {
74       for (x = 0; x < size; ++x) {
75         if (mat[y * size + x] < 0 &&
76             dist[y * size + x] < d) {
77           x1 = x;
78           y1 = y;
79           d = dist[y1 * size + x1];
80         }
81       }
82     }
83     u = 1.0 - (SplashCoord)i / (SplashCoord)(2 * size * size + 1);
84     mat[y1 * size + x1] = splashPow(u, 1.33);
85   }
86
87   gfree(dist);
88 }
89
90 SplashScreen::~SplashScreen() {
91   gfree(mat);
92 }
93
94 int SplashScreen::test(int x, int y, SplashCoord value) {
95   SplashCoord *mat1;
96   int xx, yy;
97
98   xx = x % (2 * size);
99   yy = y % (2 * size);
100   mat1 = mat;
101   if ((xx / size) ^ (yy / size)) {
102     mat1 += size * size;
103   }
104   xx %= size;
105   yy %= size;
106   return value < mat1[yy * size + xx] ? 0 : 1;
107 }