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
|
From 2ee0e053e39587d29789a26a37309445df222a0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?=
<jeromelebleu@users.noreply.github.com>
Date: Fri, 8 Jul 2022 09:41:21 +0200
Subject: [PATCH] Round values explicitly in FadeChannel and KeyPadParser
Fix #1344
---
engine/src/fadechannel.cpp | 9 +++------
engine/src/keypadparser.cpp | 6 ++++--
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/engine/src/fadechannel.cpp b/engine/src/fadechannel.cpp
index 537b0fd9f..c642360be 100644
--- a/engine/src/fadechannel.cpp
+++ b/engine/src/fadechannel.cpp
@@ -323,14 +323,11 @@ uchar FadeChannel::calculateCurrent(uint fadeTime, uint elapsedTime)
// 16 bit fading works as long as MSB and LSB channels
// are targeting the same value. E.g. Red and Red Fine both at 158
float val = (float(m_target - m_start) * (float(elapsedTime) / float(fadeTime))) + float(m_start);
+ long rval = lrintf(val * 256);
if (m_flags & Fine)
- {
- m_current = ((val - floor(val)) * float(UCHAR_MAX));
- }
+ m_current = rval & 0xff;
else
- {
- m_current = val;
- }
+ m_current = rval / 256;
}
return uchar(m_current);
diff --git a/engine/src/keypadparser.cpp b/engine/src/keypadparser.cpp
index bc2d64cbc..36a4fe9b9 100644
--- a/engine/src/keypadparser.cpp
+++ b/engine/src/keypadparser.cpp
@@ -17,6 +17,8 @@
limitations under the License.
*/
+#include <cmath>
+
#include "keypadparser.h"
#include "qlcmacros.h"
@@ -194,9 +196,9 @@ QList<SceneValue> KeyPadParser::parseCommand(Doc *doc, QString command,
else if (lastCommand == CommandMinus)
scv.value = CLAMP(uniValue - toValue, 0, 255);
else if (lastCommand == CommandPlusPercent)
- scv.value = CLAMP(uniValue * (1.0 + toValue), 0, 255);
+ scv.value = CLAMP(lrintf(uniValue * (1.0 + toValue)), 0, 255);
else if (lastCommand == CommandMinusPercent)
- scv.value = CLAMP(uniValue - (float(uniValue) * toValue), 0, 255);
+ scv.value = CLAMP(lrintf(uniValue - (float(uniValue) * toValue)), 0, 255);
else if (lastCommand == CommandZERO)
scv.value = 0;
else if (lastCommand == CommandFULL)
|