MCPcopy Create free account
hub / github.com/awawa-dev/HyperHDR / Init

Method Init

sources/effects/Animation_Fade.cpp:75–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73 (uint8_t)(std::min(std::max(int(std::round(colorStart.i + color_step.i*step)),0), int((colorStart.i < colorEnd.i) ? colorEnd.i : colorStart.i)))
74
75void Animation_Fade::Init(
76 HyperImage& hyperImage,
77 int hyperLatchTime
78)
79{
80 fadeInTime /= 1000.0;
81 fadeOutTime /= 1000.0;
82
83 colorStartTime /= 1000.0;
84 colorEndTime /= 1000.0;
85
86 minStepTime = float(hyperLatchTime) / 1000.0;
87 if (minStepTime < 0.012)
88 minStepTime = 0.012;
89
90
91 steps = double(std::max(std::abs(colorEnd.x - colorStart.x),
92 std::max(std::abs(colorEnd.y - colorStart.y),
93 std::abs(colorEnd.z - colorStart.z))));
94
95 struct { double x, y, z; } color_step = { 0,0,0 };
96
97 if (steps == 0)
98 steps = 1;
99 else
100 color_step = {
101 ((colorEnd.x - colorStart.x) / steps),
102 ((colorEnd.y - colorStart.y) / steps),
103 ((colorEnd.z - colorStart.z) / steps) };
104
105
106
107 colors.clear();
108 for (int step = 0; step < (int(steps) + 1); step++)
109 colors.push_back(Point3d{ calcChannel(x), calcChannel(y), calcChannel(z) });
110
111
112 if (fadeInTime > 0)
113 {
114 incrementIn = std::max(1, int(std::round(steps / (fadeInTime / minStepTime))));
115 double mstep = fadeInTime / (steps / incrementIn);
116 sleepTimeIn = mstep;
117
118 while (sleepTimeIn < 0.015 && mstep > 0.0001)
119 {
120 sleepTimeIn += mstep;
121 incrementIn++;
122 }
123 }
124 else
125 incrementIn = sleepTimeIn = 1;
126
127 if (fadeOutTime > 0)
128 {
129 incrementOut = std::max(1, int(std::round(steps / (fadeOutTime / minStepTime))));
130 double mstep = fadeOutTime / (steps / incrementOut);
131 sleepTimeOut = mstep;
132

Callers 1

startMethod · 0.45

Calls 2

roundFunction · 0.85
clearMethod · 0.45

Tested by

no test coverage detected