forked from xLightsSequencer/xLights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutputProcessThreeToFour.cpp
101 lines (87 loc) · 2.67 KB
/
OutputProcessThreeToFour.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***************************************************************
* This source files comes from the xLights project
* https://www.xlights.org
* https://github.com/smeighan/xLights
* See the github commit history for a record of contributing
* developers.
* Copyright claimed based on commit dates recorded in Github
* License: https://github.com/smeighan/xLights/blob/master/License.txt
**************************************************************/
#include "OutputProcessThreeToFour.h"
#include <wx/xml/xml.h>
OutputProcessThreeToFour::OutputProcessThreeToFour(OutputManager* outputManager, wxXmlNode* node) : OutputProcess(outputManager, node)
{
_nodes = wxAtol(node->GetAttribute("Nodes", "1"));
_colourOrder = node->GetAttribute("ColourOrder", "RGBW").ToStdString();
}
OutputProcessThreeToFour::OutputProcessThreeToFour(const OutputProcessThreeToFour& op) : OutputProcess(op)
{
_nodes = op._nodes;
_colourOrder = op._colourOrder;
}
OutputProcessThreeToFour::OutputProcessThreeToFour(OutputManager* outputManager) : OutputProcess(outputManager)
{
_nodes = 1;
_colourOrder = "RGBW";
}
OutputProcessThreeToFour::OutputProcessThreeToFour(OutputManager* outputManager, std::string startChannel, size_t p1, std::string colourOrder, const std::string& description) : OutputProcess(outputManager, startChannel, description)
{
_nodes = p1;
_colourOrder = colourOrder;
}
wxXmlNode* OutputProcessThreeToFour::Save()
{
wxXmlNode* res = new wxXmlNode(nullptr, wxXML_ELEMENT_NODE, "OP3To4");
res->AddAttribute("Nodes", wxString::Format(wxT("%ld"), (long)_nodes));
res->AddAttribute("ColourOrder", _colourOrder);
OutputProcess::Save(res);
return res;
}
void OutputProcessThreeToFour::Frame(uint8_t* buffer, size_t size, std::list<OutputProcess*>& processes)
{
if (!_enabled) return;
size_t sc = GetStartChannelAsNumber();
size_t nodes = std::min(_nodes, (size - (sc - 1)) / 4); // divide by 4 as that is what we are expanding it to
uint8_t* target = buffer + sc - 1 + (nodes - 1) * 4;
uint8_t* source = buffer + sc - 1 + (nodes - 1) * 3;
for (int i = 0; i < nodes; i++)
{
uint8_t white = 0;
if (*source == *(source + 1) && *source == *(source + 2))
{
white = *source;
}
if (_colourOrder == "RGBW")
{
if (white != 0)
{
memset(target, 0x00, 3);
*(target+3) = white;
}
else
{
memcpy(target, source, 3);
*(target+3) = 0x00;
}
}
else if (_colourOrder == "WRGB")
{
if (white != 0)
{
memset(target + 1, 0x00, 3);
*target = white;
}
else
{
memcpy(target + 1, source, 3);
*target = 0x00;
}
}
else
{
wxASSERT(false);
}
source -= 3;
target -= 4;
}
}