FotoSHOCK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
BWconversion_direct/RGB2Gray.cpp

The example shows how to use the operation from the examples BWconversion_direct/BWconversion.hpp and BWconversion_direct/BWconversion.cpp

/*
* Copyright 2011, 2012 Lukas Jirkovsky
*
* This file is part of FotoSHOCK.
*
* FotoSHOCK is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* FotoSHOCK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FotoSHOCK. If not, see <http://www.gnu.org/licenses/>.
*/
// Defines GraphManager and GraphNode classes.
#include <GraphManager.hpp>
// Contains definition if the saveImage function.
#include <IO/ImageIO.hpp>
// The operation.
#include "BWconversion_direct.hpp"
#include "rootops/RootLoadImage.hpp"
#include <iostream>
int main(int argc, const char* argv[]) {
if (argc != 3) {
std::cerr << "Usage:" << std::endl
<< "input output" << std::endl;
return 1;
}
// GraphManager which represents graph.
GraphManager graph;
// Create a new root in graph and load image into it.
RootLoadImageDescriptor loaderOp(argv[1]);
GraphNode* root = graph.insertOperation(&loaderOp);
// Insert a new operation into the graph.
// The returned GraphNode can be used to work with the operation.
BWconversionDescr description;
GraphNode* op = graph.insertOperation(&description, root, NULL, NULL);
// Confirm the operation.
// It means that the operation will not change and the cache can be cleaned up.
// In this case this is not useful, but with larger graphs it should be called to
// lower the memory requirements.
op->confirmOperation();
// Request the rectangle to be redrawn.
// The rectangle used has the dimenesions of the whole image.
// The image is redrawn immediatelly.
op->addROI(0, 0, op->getBuffer()->getWidth(), op->getBuffer()->getHeight(), 0);
// because the operations is carried out in a separate thread, we must for the
// thread to finish
graph.join();
// Print the time necessary to apply the operation
std::cout << "Time elapsed: " << op->getElapsedTime() << std::endl;
// Request recalculate of the operation "op" and all dependend operations.
// In this case it is not useful, because the redraw has been done when addROI()
// was called.
// It is useful when the operation parameters change and it is necessary to recalculate
// the image.
//op->recalculate();
// Create an ImageInfo object which will be used to describe the parameters of the stored image
// In this case it is the same as loadInfo object, only with a different name.
IO::SaveInfo saveInfo(argv[2]);
// Save the buffer according to saveInfo.
op->saveBuffer(saveInfo);
return 0;
}