b6b2996b76e1b0f0e403b4be40430a445bc0873c
Stefan Schuermans implemented resizer module

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

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 make modules know their name

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

129)   m_fileOutStream.setFrame(pProcFrame);