1 //========================================================================
5 //========================================================================
10 #pragma implementation
14 #include "SplashMath.h"
15 #include "SplashScreen.h"
17 //------------------------------------------------------------------------
19 //------------------------------------------------------------------------
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) {
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;
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;
50 u = (SplashCoord)x + 0.5 - (SplashCoord)size; //~ ((SplashCoord)size - 0.5);
51 v = (SplashCoord)y + 0.5 - (SplashCoord)size;
53 dist[y * size + x] = u*u + v*v;
56 for (y = 0; y < size; ++y) {
57 for (x = 0; x < size; ++x) {
59 u = (SplashCoord)x + 0.5 - 0; //~ (-0.5);
60 v = (SplashCoord)y + 0.5 - (SplashCoord)size;
62 u = (SplashCoord)x + 0.5 - (SplashCoord)size; //~ ((SplashCoord)size - 0.5);
63 v = (SplashCoord)y + 0.5 - 0;
65 dist[(size + y) * size + x] = u*u + v*v;
69 // build the threshold matrix
70 x1 = y1 = 0; // make gcc happy
71 for (i = 1; i <= 2 * size * size; ++i) {
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) {
79 d = dist[y1 * size + x1];
83 u = 1.0 - (SplashCoord)i / (SplashCoord)(2 * size * size + 1);
84 mat[y1 * size + x1] = splashPow(u, 1.33);
90 SplashScreen::~SplashScreen() {
94 int SplashScreen::test(int x, int y, SplashCoord value) {
101 if ((xx / size) ^ (yy / size)) {
106 return value < mat1[yy * size + xx] ? 0 : 1;