baf52dacd8003c3ac6d43bfef7073aae9e871e3b
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 12 years ago

1) /* Blinker
2)    Copyright 2011 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 <iostream>
7) #include <stdlib.h>
8) #include <string>
9) 
10) #include <BlinkenLib/BlinkenFrame.h>
11) 
12) #include "Directory.h"
13) #include "File.h"
14) #include "Format.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

20) #include "Resizer.h"
21) #include "StreamRecv.h"
22) 
23) namespace Blinker {
24) 
25) /**
26)  * @brief constructor
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 12 years ago

28)  * @param[in] dirBase base directory
29)  */
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

30) Resizer::Resizer(Mgrs &mgrs,
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 12 years ago

31)                  const Directory &dirBase):
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 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 12 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 12 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 12 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 12 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 12 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 12 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 12 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 12 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 12 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 12 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 12 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 12 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) {
113)     m_fileOutStream.setFrame(NULL);
Stefan Schuermans implemented resizer module

Stefan Schuermans authored 12 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 12 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 12 years ago

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

Stefan Schuermans authored 12 years ago

128)   m_fileOutStream.setFrame(pProcFrame);