-
Notifications
You must be signed in to change notification settings - Fork 0
/
PTWithCompression.cpp
64 lines (49 loc) · 1.46 KB
/
PTWithCompression.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "PTWithCompression.h"
#include <imagina/output_info_helper.h>
#include <imagina/pixel_management.h>
namespace PTWithCompression {
const PixelDataInfo *PTWithCompressionEvaluator::GetOutputInfo() {
IM_GET_OUTPUT_INFO_IMPL(Output, Value);
}
void PTWithCompressionEvaluator::Prepare(const real_hp &x, const real_hp &y, real_hr radius, const StandardEvaluationParameters ¶meters) {
this->parameters = parameters;
complex_hp C = complex_hp(x, y);
complex_hp Z = C;
complex z = complex(Z), dzdc = 1.0;
ReferenceCompressor compressor(reference, complex(C));
size_t i = 1;
while (i < parameters.Iterations) {
compressor.Add(z);
dzdc = 2.0 * z * dzdc + 1.0;
Z = Z * Z + C;
z = complex(Z);
i++;
if (radius * chebyshev_norm(dzdc) * 2.0 > chebyshev_norm(z)) break;
if (norm(z) > 16.0) break;
};
compressor.Finalize(z);
}
void PTWithCompressionEvaluator::Evaluate(IRasterizer rasterizer) {
real_hr x, y;
while (rasterizer.GetPixel(x, y)) {
complex dc = { real(x), real(y) };
complex Z = 0.0, z = 0.0, dz = 0.0;
ReferenceDecompressor decompressor(reference);
uint_iter i = 0;
while (i < parameters.Iterations) {
dz = dz * (Z + z) + dc;
i++;
Z = decompressor.Next();
z = Z + dz;
if (norm(z) > 4096.0) break;
if (decompressor.End() || norm(z) < norm(dz)) {
Z = decompressor.Reset();
dz = z;
}
}
Output output;
output.Value = i;
rasterizer.WriteResults(&output);
}
}
}