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

This is an example of how to implement an ImageOperation that converts image to grayscale using a direct access to ImageBuffer.

/*
* 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/>.
*/
#include "BWconversion_direct.hpp"
template <ValueType::Enum PixelFormat>
void BWconversion::convert(MipMap* srcMipMap, MipMap* destMipMap, vector<UpdateInfo>& ROIlist, const long stamp) {
for (typename std::vector<UpdateInfo>::iterator ROI = ROIlist.begin(); ROI != ROIlist.end(); ++ROI) {
const int level = ROI->ROI->mipmapLevel;
ImageBuffer<PixelFormat>* src = static_cast<ImageBuffer<PixelFormat>*>((*srcMipMap)[level]);
ImageBuffer<PixelFormat>* dest = static_cast<ImageBuffer<PixelFormat>*>((*destMipMap)[level]);
unsigned int startTileVert = ROI->ROI->y / src->getTileExtent();
unsigned int endTileVert = startTileVert + (ROI->ROI->sizeY - 1) / src->getTileExtent();
unsigned int startTileHoriz = ROI->ROI->x / src->getTileExtent();
unsigned int endTileHoriz = startTileHoriz + (ROI->ROI->sizeX - 1) / src->getTileExtent();
for (unsigned int tileVert = startTileVert; tileVert <= endTileVert; tileVert++) {
for (unsigned int tileHoriz = startTileHoriz; tileHoriz <= endTileHoriz; tileHoriz++) {
Tile<PixelFormat>* destTile = dest->getTile(tileHoriz, tileVert);
if (destTile->getStamp() != stamp) {
typename Tile<PixelFormat>::Iterator srcIt = src->getTile(tileHoriz, tileVert)->upperLeft();
typename Tile<PixelFormat>::Iterator srcLr = src->getTile(tileHoriz, tileVert)->lowerRight();
typename Tile<PixelFormat>::Iterator destIt = destTile->upperLeft();
unsigned int bands = dest->getPixelData().numOfBands();
for (; srcIt != srcLr; ++srcIt, ++destIt) {
for (unsigned int i = 0; i < bands; i++) {
destIt[i] = srcIt[0];
}
}
destTile->setStamp(stamp);
}
}
}
}
}
void BWconversion::runOperation (const Inputs& sources, const Outputs& dest, vector<UpdateInfo>& ROI, const long stamp) {
switch(sources[0]->getPixelData().format()) {
#define FORMAT_DO_STH(T,U) convert<T>(sources[0], dest[0], ROI, stamp);
case_ANY;
#undef FORMAT_DO_STH
}
}