Skip to content
Snippets Groups Projects
Commit b9560566 authored by Sacha Percot-Tétu's avatar Sacha Percot-Tétu
Browse files

Added center operation

parent 3fe046e6
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EIImage 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include <QApplication>
#include <Operation.h>
#include <Image.h>
#include <ImgWidget.h>
#include "CenterOp.h"
using namespace std;
using namespace imagein;
CenterOp::CenterOp() : Operation(tr("Center").toStdString())
{
}
bool CenterOp::needCurrentImg() {
return true;
}
std::vector<QWidget*> CenterOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>&) {
vector<QWidget*> result;
Image* resImg = new Image(image->getWidth()-image->getWidth()%2, image->getHeight()-image->getHeight()%2, image->getNbChannels());
for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) {
for(unsigned int j = 0; j < resImg->getHeight()/2; ++j)
{
for(unsigned int i = 0; i < resImg->getWidth()/2; ++i) {
Image::depth_t value = image->getPixel(i, j, c);
resImg->setPixel(resImg->getWidth()/2 - i - 1, resImg->getHeight()/2 - j - 1, c, value);
}
for(unsigned int i = 0; i < resImg->getWidth()/2; ++i) {
Image::depth_t value = image->getPixel(image->getWidth()/2 + i, j, c);
resImg->setPixel(resImg->getWidth() - i - 1, resImg->getHeight()/2 - j - 1, c, value);
}
}
for(unsigned int j = 0; j < resImg->getHeight()/2; ++j)
{
for(unsigned int i = 0; i < resImg->getWidth()/2; ++i) {
Image::depth_t value = image->getPixel(i, image->getHeight()/2 + j, c);
resImg->setPixel(resImg->getWidth()/2 - i - 1, resImg->getHeight() - j - 1, c, value);
}
for(unsigned int i = 0; i < resImg->getWidth()/2; ++i) {
Image::depth_t value = image->getPixel(image->getWidth()/2 + i, image->getHeight()/2 + j, c);
resImg->setPixel(resImg->getWidth() - i - 1, resImg->getHeight() - j - 1, c, value);
}
}
}
result.push_back(new ImgWidget(resImg, QString(" - centered").toStdString()));
return result;
}
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EIImage 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CENTEROP_H
#define CENTEROP_H
#include <QApplication>
#include <Operation.h>
#include <Image.h>
class CenterOp : public Operation
{
public:
CenterOp();
std::vector<QWidget*> operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&);
static QString tr(const char* str) { return QApplication::tr(str); }
bool needCurrentImg();
};
#endif // CENTEROP_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment