comparison data/model/PowerOfSqrtTwoZoomConstraint.cpp @ 1550:1ae6a19464a7 zoom-double

Messing with non-integer zoom ratios. But I don't think this is going anywhere as it stands
author Chris Cannam
date Mon, 08 Oct 2018 13:39:40 +0100
parents c1c45c5146bb
children
comparison
equal deleted inserted replaced
1547:32400727bcbd 1550:1ae6a19464a7
24 ZoomLevel 24 ZoomLevel
25 PowerOfSqrtTwoZoomConstraint::getNearestZoomLevel(ZoomLevel requested, 25 PowerOfSqrtTwoZoomConstraint::getNearestZoomLevel(ZoomLevel requested,
26 RoundingDirection dir) const 26 RoundingDirection dir) const
27 { 27 {
28 int type, power; 28 int type, power;
29 int blockSize; 29 double blockSize;
30 30
31 if (requested.zone == ZoomLevel::FramesPerPixel) { 31 if (requested.zone == ZoomLevel::FramesPerPixel) {
32 blockSize = getNearestBlockSize(requested.level, type, power, dir); 32 blockSize = getNearestBlockSize(requested.level, type, power, dir);
33 return { requested.zone, blockSize }; 33 return { requested.zone, blockSize };
34 } else { 34 } else {
45 return { requested.zone, blockSize }; 45 return { requested.zone, blockSize };
46 } 46 }
47 } 47 }
48 } 48 }
49 49
50 int 50 double
51 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(int blockSize, 51 PowerOfSqrtTwoZoomConstraint::getNearestBlockSize(double blockSize,
52 int &type, 52 int &type,
53 int &power, 53 int &power,
54 RoundingDirection dir) const 54 RoundingDirection dir) const
55 { 55 {
56 // SVCERR << "given " << blockSize << endl; 56 // SVCERR << "given " << blockSize << endl;
57 57
58 int minCachePower = getMinCachePower(); 58 int minCachePower = getMinCachePower();
59 59
60 double eps = 1e-8;
61
60 if (blockSize < (1 << minCachePower)) { 62 if (blockSize < (1 << minCachePower)) {
61 type = -1; 63 type = -1;
62 power = 0; 64 power = 0;
63 float val = 1.0, prevVal = 1.0; 65 double val = 1.0, prevVal = 1.0;
64 while (val + 0.01 < blockSize) { 66 while (val + eps < blockSize) {
65 prevVal = val; 67 prevVal = val;
66 val *= sqrtf(2.f); 68 val *= sqrtf(2.f);
67 } 69 }
68 int rval = int(val + 0.01f); 70 double rval = val;
69 // SVCERR << "got val = " << val << ", rval = " << rval << ", prevVal = " << prevVal << endl; 71 // SVCERR << "got val = " << val << ", rval = " << rval << ", prevVal = " << prevVal << endl;
70 if (rval != blockSize && dir != RoundUp) { 72 if (rval != blockSize && dir != RoundUp) {
71 if (dir == RoundDown) { 73 if (dir == RoundDown) {
72 rval = int(prevVal + 0.01f); 74 rval = prevVal;
73 } else if (val - float(blockSize) < float(blockSize) - prevVal) { 75 } else if (val - blockSize < blockSize - prevVal) {
74 rval = int(val + 0.01f); 76 rval = val;
75 } else { 77 } else {
76 rval = int(prevVal + 0.01); 78 rval = prevVal;
77 } 79 }
78 } 80 }
79 // SVCERR << "returning " << rval << endl; 81 // SVCERR << "returning " << rval << endl;
80 return rval; 82 return rval;
81 } 83 }
82 84
83 int prevBase = (1 << minCachePower); 85 double prevBase = (1 << minCachePower);
84 int prevPower = minCachePower; 86 int prevPower = minCachePower;
85 int prevType = 0; 87 int prevType = 0;
86 88
87 int result = 0; 89 double result = 0;
88 90
89 for (unsigned int i = 0; ; ++i) { 91 for (unsigned int i = 0; ; ++i) {
90 92
91 power = minCachePower + i/2; 93 power = minCachePower + i/2;
92 type = i % 2; 94 type = i % 2;
93 95
94 int base; 96 double base;
95 if (type == 0) { 97 if (type == 0) {
96 base = (1 << power); 98 base = pow(2.0, power);
97 } else { 99 } else {
98 base = (((unsigned int)((1 << minCachePower) * sqrt(2.) + 0.01)) 100 base = sqrt(2.0) * pow(2.0, power);
99 << (power - minCachePower));
100 } 101 }
101 102
102 // SVCERR << "Testing base " << base << " (i = " << i << ", power = " << power << ", type = " << type << ")" << endl; 103 // SVCERR << "Testing base " << base << " (i = " << i << ", power = " << power << ", type = " << type << ")" << endl;
103 104
104 if (base == blockSize) { 105 if (base == blockSize) {