BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
105f9e6
Branches
Tags
master
Blinker
src
noarch
Resizer.cpp
implemented resizer module
Stefan Schuermans
commited
105f9e6
at 2011-11-19 21:52:49
Resizer.cpp
Blame
History
Raw
/* Blinker Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #include <iostream> #include <stdlib.h> #include <string> #include <BlinkenLib/BlinkenFrame.h> #include "CallMgr.h" #include "Directory.h" #include "File.h" #include "Format.h" #include "Module.h" #include "Resizer.h" #include "SettingFile.h" #include "StreamMgr.h" #include "StreamRecv.h" namespace Blinker { /** * @brief constructor * @param[in] callMgr callback manager * @param[in] streamMgr stream manager * @param[in] dirBase base directory */ Resizer::Resizer(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase): Module(callMgr, streamMgr, dirBase), m_fileInStream(dirBase.getFile("instream")), m_fileFormat(dirBase.getFile("format")), m_fileOutStream(dirBase.getFile("outstream")), m_pInStream(NULL), m_haveFormat(false), m_pOutStream(NULL) { // set up getInStream(); getFormat(); getOutStream(); } /// virtual destructor Resizer::~Resizer() { // clean up releaseInStream(); releaseOutStream(); } /// check for update of configuration void Resizer::updateConfig() { // stream name or format file was modified -> re-get stream or format if (m_fileInStream.checkModified()) { releaseInStream(); getInStream(); } if (m_fileFormat.checkModified()) { getFormat(); } if (m_fileOutStream.checkModified()) { releaseOutStream(); getOutStream(); } } /** * @brief set current frame * @param[in] stream stream name * @param[in] pFrame current frame */ void Resizer::setFrame(const std::string &stream, stBlinkenFrame *pFrame) { procFrame(pFrame); (void)stream; // unused } /** * @brief set current frame to none * @param[in] stream stream name */ void Resizer::setNoFrame(const std::string &stream) { procNoFrame(); (void)stream; // unused } /// get input stream and attach to it void Resizer::getInStream() { // get input stream m_fileInStream.getStr(m_nameInStream); m_pInStream = &m_streamMgr.refStream(m_nameInStream); // attach to input stream if (m_pInStream) m_pInStream->attach(this); } /// detach from input stream and release it void Resizer::releaseInStream() { // detach from input stream if (m_pInStream) m_pInStream->detach(this); // unreference stream m_pInStream = NULL; m_streamMgr.unrefStream(m_nameInStream); } /// (re-)get format to resize to void Resizer::getFormat() { std::string strFormat; // read format from format file m_haveFormat = m_fileFormat.getStr(strFormat) && m_format.fromStr(strFormat); // send current frame to output stream sendFrame(); } /// get output stream void Resizer::getOutStream() { // get output stream m_fileOutStream.getStr(m_nameOutStream); m_pOutStream = &m_streamMgr.refStream(m_nameOutStream); // send current frame to output stream sendFrame(); } /// release output stream void Resizer::releaseOutStream() { // send no frame information if (m_pOutStream) m_pOutStream->setNoFrame(); // unreference stream m_pOutStream = NULL; m_streamMgr.unrefStream(m_nameOutStream); } /// send current frame to output stream void Resizer::sendFrame() { stBlinkenFrame *pFrame; // get current frame from input stream and process it if (m_pInStream && m_pInStream->getCurFrame(pFrame)) procFrame(pFrame); else procNoFrame(); } /** * @brief process frame * @param[in] pFrame frame to process */ void Resizer::procFrame(stBlinkenFrame *pFrame) { stBlinkenFrame *pProcFrame; // no output stream -> nothing to do if (!m_pOutStream) return; // no format -> pass "no frame" if (!m_haveFormat) { m_pOutStream->setNoFrame(); return; } // format matches -> pass frame directly if ((unsigned int)BlinkenFrameGetWidth(pFrame) == m_format.m_width && (unsigned int)BlinkenFrameGetHeight(pFrame) == m_format.m_height && (unsigned int)BlinkenFrameGetChannels(pFrame) == m_format.m_channels && (unsigned int)BlinkenFrameGetMaxval(pFrame) == m_format.m_maxval) { m_pOutStream->setFrame(pFrame); return; } // clone frame pProcFrame = BlinkenFrameClone(pFrame); if (!pProcFrame){ m_pOutStream->setNoFrame(); return; } // resize frame BlinkenFrameResize(pProcFrame, m_format.m_height, m_format.m_width, m_format.m_channels, m_format.m_maxval); // pass process frame to output stream m_pOutStream->setFrame(pProcFrame); // free cloned frame BlinkenFrameFree(pProcFrame); } /// process "no frame" void Resizer::procNoFrame() { // pass "no frame" to output stream if (m_pOutStream) m_pOutStream->setNoFrame(); } } // namespace Blinker