BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
f0c104c
Branches
Tags
master
Blinker
src
noarch
Resizer.cpp
implemented specialized setting files for different data types, simplified input/output stream handling in modules
Stefan Schuermans
commited
f0c104c
at 2011-12-04 20:10:37
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 "FormatFile.h" #include "InStreamFile.h" #include "Module.h" #include "OutStreamFile.h" #include "Resizer.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"), streamMgr), m_fileFormat(dirBase.getFile("format")), m_fileOutStream(dirBase.getFile("outstream"), streamMgr) { // set up getFormat(); m_fileInStream.setStreamRecv(this); } /// virtual destructor Resizer::~Resizer() { // clean up m_fileInStream.setStreamRecv(NULL); } /// check for update of configuration void Resizer::updateConfig() { // stream name or format file was modified -> re-get stream or format if (m_fileInStream.checkModified()) m_fileInStream.update(); if (m_fileFormat.checkModified()) getFormat(); if (m_fileOutStream.checkModified()) m_fileOutStream.update(); } /** * @brief set current frame * @param[in] stream stream name * @param[in] pFrame current frame (NULL for none) */ void Resizer::setFrame(const std::string &stream, stBlinkenFrame *pFrame) { procFrame(pFrame); (void)stream; // unused } /// (re-)get format to resize to void Resizer::getFormat() { // read format from format file m_fileFormat.update(); // send current frame to output stream sendFrame(); } /// send current frame to output stream void Resizer::sendFrame() { // get current frame from input stream and process it procFrame(m_fileInStream.getCurFrame()); } /** * @brief process frame * @param[in] pFrame frame to process (NULL for none) */ void Resizer::procFrame(stBlinkenFrame *pFrame) { int width, height, channels, maxval; stBlinkenFrame *pProcFrame; // no frame or no format -> pass "no frame" if (!pFrame || !m_fileFormat.m_valid) { m_fileOutStream.setFrame(NULL); return; } width = m_fileFormat.m_obj.m_width; height = m_fileFormat.m_obj.m_height; channels = m_fileFormat.m_obj.m_channels; maxval = m_fileFormat.m_obj.m_maxval; // format matches -> pass frame directly if (BlinkenFrameGetWidth(pFrame) == width && BlinkenFrameGetHeight(pFrame) == height && BlinkenFrameGetChannels(pFrame) == channels && BlinkenFrameGetMaxval(pFrame) == maxval) { m_fileOutStream.setFrame(NULL); return; } // clone frame pProcFrame = BlinkenFrameClone(pFrame); if (!pProcFrame){ m_fileOutStream.setFrame(NULL); return; } // resize frame BlinkenFrameResize(pProcFrame, height, width, channels, maxval); // pass process frame to output stream m_fileOutStream.setFrame(pProcFrame); // free cloned frame BlinkenFrameFree(pProcFrame); } } // namespace Blinker