1a209d467a4bce9c08e380b6847f228d624aa951
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

1) /* Blinker
Stefan Schuermans update copyright years

Stefan Schuermans authored 10 years ago

2)    Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org>
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

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 "Format.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

14) #include "FormatFile.h"
15) #include "InStreamFile.h"
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

16) #include "Mgrs.h"
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

17) #include "Module.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

18) #include "OutStreamFile.h"
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

19) #include "Resizer.h"
20) #include "StreamRecv.h"
21) 
22) namespace Blinker {
23) 
24) /**
25)  * @brief constructor
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

26)  * @param[in] name module name
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

27)  * @param[in] mgrs managers
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

28)  * @param[in] dirBase base directory
29)  */
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

30) Resizer::Resizer(const std::string &name, Mgrs &mgrs,
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

31)                  const Directory &dirBase):
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

32)   Module(name, mgrs, dirBase),
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

33)   m_fileInStream(dirBase.getFile("instream"), mgrs.m_streamMgr),
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

34)   m_fileFormat(dirBase.getFile("format")),
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

35)   m_fileOutStream(dirBase.getFile("outstream"), mgrs.m_streamMgr)
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

36) {
37)   // set up
38)   getFormat();
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

39)   m_fileInStream.setStreamRecv(this);
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

40) }
41) 
42) /// virtual destructor
43) Resizer::~Resizer()
44) {
45)   // clean up
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

46)   m_fileInStream.setStreamRecv(NULL);
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

47) }
48) 
49) /// check for update of configuration
50) void Resizer::updateConfig()
51) {
52)   // stream name or format file was modified -> re-get stream or format
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

53)   if (m_fileInStream.checkModified())
54)     m_fileInStream.update();
55)   if (m_fileFormat.checkModified())
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

56)     getFormat();
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

57)   if (m_fileOutStream.checkModified())
58)     m_fileOutStream.update();
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

59) }
60) 
61) /**
62)  * @brief set current frame
63)  * @param[in] stream stream name
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

64)  * @param[in] pFrame current frame (NULL for none)
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

65)  */
66) void Resizer::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
67) {
68)   procFrame(pFrame);
69)   (void)stream; // unused
70) }
71) 
72) /// (re-)get format to resize to
73) void Resizer::getFormat()
74) {
75)   // read format from format file
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

76)   m_fileFormat.update();
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

77) 
78)   // send current frame to output stream
79)   sendFrame();
80) }
81) 
82) /// send current frame to output stream
83) void Resizer::sendFrame()
84) {
85)   // get current frame from input stream and process it
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

86)   procFrame(m_fileInStream.getCurFrame());
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

87) }
88) 
89) /**
90)  * @brief process frame
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

91)  * @param[in] pFrame frame to process (NULL for none)
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

92)  */
93) void Resizer::procFrame(stBlinkenFrame *pFrame)
94) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

95)   int width, height, channels, maxval;
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

96)   stBlinkenFrame *pProcFrame;
97) 
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

98)   // no frame or no format -> pass "no frame"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

99)   if (!pFrame || !m_fileFormat.m_valid) {
100)     m_fileOutStream.setFrame(NULL);
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

101)     return;
102)   }
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

103)   width = m_fileFormat.m_obj.m_width;
104)   height = m_fileFormat.m_obj.m_height;
105)   channels = m_fileFormat.m_obj.m_channels;
106)   maxval = m_fileFormat.m_obj.m_maxval;
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

107) 
108)   // format matches -> pass frame directly
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

109)   if (BlinkenFrameGetWidth(pFrame) == width &&
110)       BlinkenFrameGetHeight(pFrame) == height &&
111)       BlinkenFrameGetChannels(pFrame) == channels &&
112)       BlinkenFrameGetMaxval(pFrame) == maxval) {
Stefan Schuermans fix passing frames if forma...

Stefan Schuermans authored 12 years ago

113)     m_fileOutStream.setFrame(pFrame);
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

114)     return;
115)   }
116) 
117)   // clone frame
118)   pProcFrame = BlinkenFrameClone(pFrame);
119)   if (!pProcFrame){
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

120)     m_fileOutStream.setFrame(NULL);
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

121)     return;
122)   }
123) 
124)   // resize frame
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

125)   BlinkenFrameResize(pProcFrame, height, width, channels, maxval);
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 13 years ago

126) 
Stefan Schuermans implement frame rate limiter

Stefan Schuermans authored 10 years ago

127)   // pass processed frame to output stream
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

128)   m_fileOutStream.setFrame(pProcFrame);