Stefan Schuermans commited on 2014-01-03 12:40:21
Showing 9 changed files, with 393 additions and 0 deletions.
... | ... |
@@ -0,0 +1 @@ |
1 |
+dot |
... | ... |
@@ -0,0 +1 @@ |
1 |
+rotdot |
... | ... |
@@ -0,0 +1 @@ |
1 |
+rotcw |
... | ... |
@@ -0,0 +1,82 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#include <sstream> |
|
7 |
+#include <string> |
|
8 |
+ |
|
9 |
+#include "Transform.h" |
|
10 |
+ |
|
11 |
+namespace Blinker { |
|
12 |
+ |
|
13 |
+/// constructor |
|
14 |
+Transform::Transform(): |
|
15 |
+ m_type(None) |
|
16 |
+{ |
|
17 |
+} |
|
18 |
+ |
|
19 |
+/** |
|
20 |
+ * @brief parse from string format |
|
21 |
+ * @param[in] str string format |
|
22 |
+ * @return if parsing was successful |
|
23 |
+ */ |
|
24 |
+bool Transform::fromStr(const std::string &str) |
|
25 |
+{ |
|
26 |
+ if (str == "none") { |
|
27 |
+ m_type = None; |
|
28 |
+ return true; |
|
29 |
+ } |
|
30 |
+ else if (str == "rotcw") { |
|
31 |
+ m_type = RotCW; |
|
32 |
+ return true; |
|
33 |
+ } |
|
34 |
+ else if (str == "rotccw") { |
|
35 |
+ m_type = RotCCW; |
|
36 |
+ return true; |
|
37 |
+ } |
|
38 |
+ else if (str == "rothalf") { |
|
39 |
+ m_type = RotHalf; |
|
40 |
+ return true; |
|
41 |
+ } |
|
42 |
+ else if (str == "mirhor") { |
|
43 |
+ m_type = MirHor; |
|
44 |
+ return true; |
|
45 |
+ } |
|
46 |
+ else if (str == "mirver") { |
|
47 |
+ m_type = MirVer; |
|
48 |
+ return true; |
|
49 |
+ } |
|
50 |
+ else if (str == "mirdiag") { |
|
51 |
+ m_type = MirDiag; |
|
52 |
+ return true; |
|
53 |
+ } |
|
54 |
+ else if (str == "mirdiag2") { |
|
55 |
+ m_type = MirDiag2; |
|
56 |
+ return true; |
|
57 |
+ } |
|
58 |
+ else |
|
59 |
+ return false; |
|
60 |
+} |
|
61 |
+ |
|
62 |
+/** |
|
63 |
+ * @brief convert to string format |
|
64 |
+ * @return string format |
|
65 |
+ */ |
|
66 |
+std::string Transform::toStr() const |
|
67 |
+{ |
|
68 |
+ switch (m_type) { |
|
69 |
+ case None: return "none"; |
|
70 |
+ case RotCW: return "rotcw"; |
|
71 |
+ case RotCCW: return "rotccw"; |
|
72 |
+ case RotHalf: return "rothalf"; |
|
73 |
+ case MirHor: return "mirhor"; |
|
74 |
+ case MirVer: return "mirver"; |
|
75 |
+ case MirDiag: return "mirdiag"; |
|
76 |
+ case MirDiag2: return "mirdiag2"; |
|
77 |
+ default: return ""; |
|
78 |
+ } |
|
79 |
+} |
|
80 |
+ |
|
81 |
+} // namespace Blinker |
|
82 |
+ |
... | ... |
@@ -0,0 +1,54 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#ifndef BLINKER_TRANSFORM_H |
|
7 |
+#define BLINKER_TRANSFORM_H |
|
8 |
+ |
|
9 |
+#include <string> |
|
10 |
+ |
|
11 |
+namespace Blinker { |
|
12 |
+ |
|
13 |
+/// a tranformation, i.e. rotation or mirroring |
|
14 |
+class Transform |
|
15 |
+{ |
|
16 |
+public: |
|
17 |
+ /// transformation types |
|
18 |
+ enum Type { |
|
19 |
+ None, ///< no transformation |
|
20 |
+ RotCW, ///< 90 degrees clockwise rotation |
|
21 |
+ RotCCW, ///< 90 degrees counter-clockwise rotation |
|
22 |
+ RotHalf, ///< 180 degrees rotation |
|
23 |
+ MirHor, ///< horizontal mirroring |
|
24 |
+ MirVer, ///< vertical mirroring |
|
25 |
+ MirDiag, ///< diagonal (\) mirroring |
|
26 |
+ MirDiag2, ///< diagonal (/) mirroring |
|
27 |
+ }; |
|
28 |
+ |
|
29 |
+public: |
|
30 |
+ /// constructor |
|
31 |
+ Transform(); |
|
32 |
+ |
|
33 |
+public: |
|
34 |
+ /** |
|
35 |
+ * @brief parse from string format |
|
36 |
+ * @param[in] str string format |
|
37 |
+ * @return if parsing was successful |
|
38 |
+ */ |
|
39 |
+ bool fromStr(const std::string &str); |
|
40 |
+ |
|
41 |
+ /** |
|
42 |
+ * @brief convert to string format |
|
43 |
+ * @return string format |
|
44 |
+ */ |
|
45 |
+ std::string toStr() const; |
|
46 |
+ |
|
47 |
+public: |
|
48 |
+ Type m_type; ///< transformation type |
|
49 |
+}; // class Transform |
|
50 |
+ |
|
51 |
+} // namespace Blinker |
|
52 |
+ |
|
53 |
+#endif // #ifndef BLINKER_TRANSFORM_H |
|
54 |
+ |
... | ... |
@@ -0,0 +1,20 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#ifndef BLINKER_TRANSFORMFILE_H |
|
7 |
+#define BLINKER_TRANSFORMFILE_H |
|
8 |
+ |
|
9 |
+#include "Transform.h" |
|
10 |
+#include "SettingFile_impl.h" |
|
11 |
+ |
|
12 |
+namespace Blinker { |
|
13 |
+ |
|
14 |
+/// setting file containting a transformation |
|
15 |
+typedef SettingFile<Transform> TransformFile; |
|
16 |
+ |
|
17 |
+} // namespace Blinker |
|
18 |
+ |
|
19 |
+#endif // #ifndef BLINKER_TRANSFORMFILE_H |
|
20 |
+ |
... | ... |
@@ -0,0 +1,152 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#include <stdlib.h> |
|
7 |
+#include <string> |
|
8 |
+ |
|
9 |
+#include <BlinkenLib/BlinkenFrame.h> |
|
10 |
+ |
|
11 |
+#include "Directory.h" |
|
12 |
+#include "File.h" |
|
13 |
+#include "InStreamFile.h" |
|
14 |
+#include "Mgrs.h" |
|
15 |
+#include "Module.h" |
|
16 |
+#include "OutStreamFile.h" |
|
17 |
+#include "Transformer.h" |
|
18 |
+#include "StreamRecv.h" |
|
19 |
+#include "Transform.h" |
|
20 |
+#include "TransformFile.h" |
|
21 |
+ |
|
22 |
+namespace Blinker { |
|
23 |
+ |
|
24 |
+/** |
|
25 |
+ * @brief constructor |
|
26 |
+ * @param[in] name module name |
|
27 |
+ * @param[in] mgrs managers |
|
28 |
+ * @param[in] dirBase base directory |
|
29 |
+ */ |
|
30 |
+Transformer::Transformer(const std::string &name, Mgrs &mgrs, |
|
31 |
+ const Directory &dirBase): |
|
32 |
+ Module(name, mgrs, dirBase), |
|
33 |
+ m_fileInStream(dirBase.getFile("instream"), mgrs.m_streamMgr), |
|
34 |
+ m_fileTransform(dirBase.getFile("transform")), |
|
35 |
+ m_fileOutStream(dirBase.getFile("outstream"), mgrs.m_streamMgr) |
|
36 |
+{ |
|
37 |
+ // set up |
|
38 |
+ getTransform(); |
|
39 |
+ m_fileInStream.setStreamRecv(this); |
|
40 |
+} |
|
41 |
+ |
|
42 |
+/// virtual destructor |
|
43 |
+Transformer::~Transformer() |
|
44 |
+{ |
|
45 |
+ // clean up |
|
46 |
+ m_fileInStream.setStreamRecv(NULL); |
|
47 |
+} |
|
48 |
+ |
|
49 |
+/// check for update of configuration |
|
50 |
+void Transformer::updateConfig() |
|
51 |
+{ |
|
52 |
+ // stream name or transform file was modified -> re-get stream or transform |
|
53 |
+ if (m_fileInStream.checkModified()) |
|
54 |
+ m_fileInStream.update(); |
|
55 |
+ if (m_fileTransform.checkModified()) |
|
56 |
+ getTransform(); |
|
57 |
+ if (m_fileOutStream.checkModified()) |
|
58 |
+ m_fileOutStream.update(); |
|
59 |
+} |
|
60 |
+ |
|
61 |
+/** |
|
62 |
+ * @brief set current frame |
|
63 |
+ * @param[in] stream stream name |
|
64 |
+ * @param[in] pFrame current frame (NULL for none) |
|
65 |
+ */ |
|
66 |
+void Transformer::setFrame(const std::string &stream, stBlinkenFrame *pFrame) |
|
67 |
+{ |
|
68 |
+ procFrame(pFrame); |
|
69 |
+ (void)stream; // unused |
|
70 |
+} |
|
71 |
+ |
|
72 |
+/// (re-)get transformation to apply |
|
73 |
+void Transformer::getTransform() |
|
74 |
+{ |
|
75 |
+ // read transformation from transformation file |
|
76 |
+ m_fileTransform.update(); |
|
77 |
+ |
|
78 |
+ // send current frame to output stream |
|
79 |
+ sendFrame(); |
|
80 |
+} |
|
81 |
+ |
|
82 |
+/// send current frame to output stream |
|
83 |
+void Transformer::sendFrame() |
|
84 |
+{ |
|
85 |
+ // get current frame from input stream and process it |
|
86 |
+ procFrame(m_fileInStream.getCurFrame()); |
|
87 |
+} |
|
88 |
+ |
|
89 |
+/** |
|
90 |
+ * @brief process frame |
|
91 |
+ * @param[in] pFrame frame to process (NULL for none) |
|
92 |
+ */ |
|
93 |
+void Transformer::procFrame(stBlinkenFrame *pFrame) |
|
94 |
+{ |
|
95 |
+ stBlinkenFrame *pProcFrame; |
|
96 |
+ |
|
97 |
+ // no frame or no transformation -> pass "no frame" |
|
98 |
+ if (!pFrame || !m_fileTransform.m_valid) { |
|
99 |
+ m_fileOutStream.setFrame(NULL); |
|
100 |
+ return; |
|
101 |
+ } |
|
102 |
+ |
|
103 |
+ // no transformation -> pass frame directly |
|
104 |
+ if (m_fileTransform.m_obj.m_type == Transform::None) { |
|
105 |
+ m_fileOutStream.setFrame(pFrame); |
|
106 |
+ return; |
|
107 |
+ } |
|
108 |
+ |
|
109 |
+ // clone frame |
|
110 |
+ pProcFrame = BlinkenFrameClone(pFrame); |
|
111 |
+ if (!pProcFrame){ |
|
112 |
+ m_fileOutStream.setFrame(NULL); |
|
113 |
+ return; |
|
114 |
+ } |
|
115 |
+ |
|
116 |
+ // transform frame |
|
117 |
+ switch (m_fileTransform.m_obj.m_type) { |
|
118 |
+ case Transform::None: |
|
119 |
+ // this case is handled above, just handle it here to avoid warning |
|
120 |
+ break; |
|
121 |
+ case Transform::RotCW: |
|
122 |
+ BlinkenFrameRotateCw(pProcFrame); |
|
123 |
+ break; |
|
124 |
+ case Transform::RotCCW: |
|
125 |
+ BlinkenFrameRotateCcw(pProcFrame); |
|
126 |
+ break; |
|
127 |
+ case Transform::RotHalf: |
|
128 |
+ BlinkenFrameRotateHalf(pProcFrame); |
|
129 |
+ break; |
|
130 |
+ case Transform::MirHor: |
|
131 |
+ BlinkenFrameMirrorHor(pProcFrame); |
|
132 |
+ break; |
|
133 |
+ case Transform::MirVer: |
|
134 |
+ BlinkenFrameMirrorVer(pProcFrame); |
|
135 |
+ break; |
|
136 |
+ case Transform::MirDiag: |
|
137 |
+ BlinkenFrameMirrorDiag(pProcFrame); |
|
138 |
+ break; |
|
139 |
+ case Transform::MirDiag2: |
|
140 |
+ BlinkenFrameMirrorDiag2(pProcFrame); |
|
141 |
+ break; |
|
142 |
+ } |
|
143 |
+ |
|
144 |
+ // pass processed frame to output stream |
|
145 |
+ m_fileOutStream.setFrame(pProcFrame); |
|
146 |
+ |
|
147 |
+ // free cloned frame |
|
148 |
+ BlinkenFrameFree(pProcFrame); |
|
149 |
+} |
|
150 |
+ |
|
151 |
+} // namespace Blinker |
|
152 |
+ |
... | ... |
@@ -0,0 +1,80 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#ifndef BLINKER_TRANSFORMER_H |
|
7 |
+#define BLINKER_TRANSFORMER_H |
|
8 |
+ |
|
9 |
+#include <string> |
|
10 |
+ |
|
11 |
+#include <BlinkenLib/BlinkenFrame.h> |
|
12 |
+ |
|
13 |
+#include "Directory.h" |
|
14 |
+#include "File.h" |
|
15 |
+#include "InStreamFile.h" |
|
16 |
+#include "Mgrs.h" |
|
17 |
+#include "Module.h" |
|
18 |
+#include "OutStreamFile.h" |
|
19 |
+#include "StreamRecv.h" |
|
20 |
+#include "Transform.h" |
|
21 |
+#include "TransformFile.h" |
|
22 |
+ |
|
23 |
+namespace Blinker { |
|
24 |
+ |
|
25 |
+/// a stream transformer (i.e. rotate or mirror) |
|
26 |
+class Transformer: public Module, public StreamRecv |
|
27 |
+{ |
|
28 |
+public: |
|
29 |
+ /** |
|
30 |
+ * @brief constructor |
|
31 |
+ * @param[in] name module name |
|
32 |
+ * @param[in] mgrs managers |
|
33 |
+ * @param[in] dirBase base directory |
|
34 |
+ */ |
|
35 |
+ Transformer(const std::string &name, Mgrs &mgrs, const Directory &dirBase); |
|
36 |
+ |
|
37 |
+ /// virtual destructor |
|
38 |
+ virtual ~Transformer(); |
|
39 |
+ |
|
40 |
+private: |
|
41 |
+ /// copy constructor disabled |
|
42 |
+ Transformer(const Transformer &that); |
|
43 |
+ |
|
44 |
+ /// assignment operator disabled |
|
45 |
+ const Transformer & operator=(const Transformer &that); |
|
46 |
+ |
|
47 |
+public: |
|
48 |
+ /// check for update of configuration |
|
49 |
+ virtual void updateConfig(); |
|
50 |
+ |
|
51 |
+ /** |
|
52 |
+ * @brief set current frame |
|
53 |
+ * @param[in] stream stream name |
|
54 |
+ * @param[in] pFrame current frame (NULL for none) |
|
55 |
+ */ |
|
56 |
+ virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame); |
|
57 |
+ |
|
58 |
+protected: |
|
59 |
+ /// (re-)get transformation to apply |
|
60 |
+ void getTransform(); |
|
61 |
+ |
|
62 |
+ /// send current frame to output stream |
|
63 |
+ void sendFrame(); |
|
64 |
+ |
|
65 |
+ /** |
|
66 |
+ * @brief process frame |
|
67 |
+ * @param[in] pFrame frame to process (NULL for none) |
|
68 |
+ */ |
|
69 |
+ void procFrame(stBlinkenFrame *pFrame); |
|
70 |
+ |
|
71 |
+protected: |
|
72 |
+ InStreamFile m_fileInStream; ///< input stream name file |
|
73 |
+ TransformFile m_fileTransform; ///< transformation file |
|
74 |
+ OutStreamFile m_fileOutStream; ///< output stream name file |
|
75 |
+}; // class Transformer |
|
76 |
+ |
|
77 |
+} // namespace Blinker |
|
78 |
+ |
|
79 |
+#endif // #ifndef BLINKER_TRANSFORMER_H |
|
80 |
+ |
... | ... |
@@ -22,6 +22,7 @@ |
22 | 22 |
#include "RateLimiter.h" |
23 | 23 |
#include "Resizer.h" |
24 | 24 |
#include "Scaler.h" |
25 |
+#include "Transformer.h" |
|
25 | 26 |
#include "Udp4Phone.h" |
26 | 27 |
#include "Udp4Receiver.h" |
27 | 28 |
#include "Udp4Sender.h" |
... | ... |
@@ -52,6 +53,7 @@ void run(const std::string &dirConfig) |
52 | 53 |
MODULEMGR(Resizer, resizers); |
53 | 54 |
MODULEMGR(RateLimiter, ratelimiters); |
54 | 55 |
MODULEMGR(Scaler, scalers); |
56 |
+ MODULEMGR(Transformer, transformers); |
|
55 | 57 |
MODULEMGR(Udp4Phone, udp4phones); |
56 | 58 |
MODULEMGR(Udp4Receiver, udp4receivers); |
57 | 59 |
MODULEMGR(Udp4Sender, udp4senders); |
58 | 60 |