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

Added flip operation

parent caba9c9d
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 <Image.h>
#include "ImgWidget.h"
#include "FlipOp.h"
using namespace std;
using namespace imagein;
FlipOp::FlipOp(Direction dir)
: Operation(QString(tr("Flip %1")).arg(dir == Horizontal ? tr("horizontal") : tr("vertical")).toStdString()), _dir(dir)
{
}
bool FlipOp::needCurrentImg() {
return true;
}
std::vector<QWidget*> FlipOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>&) {
vector<QWidget*> result;
Image* resImg = new Image(image->getWidth(), image->getHeight(), image->getNbChannels());
if(_dir == Horizontal) {
for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) {
for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
Image::depth_t value = image->getPixel(image->getWidth() - i - 1, j, c);
resImg->setPixel(i, j, c, value);
}
}
}
}
else if(_dir == Vertical) {
for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) {
for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
Image::depth_t value = image->getPixel(i, image->getHeight() - j - 1, c);
resImg->setPixel(i, j, c, value);
}
}
}
}
QString name = QString(tr(" - flipped %1")).arg(_dir == Horizontal ? tr("horizontal") : tr("vertical"));
result.push_back(new ImgWidget(resImg, name.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 FLIPOP_H
#define FLIPOP_H
#include <QApplication>
#include <Operation.h>
#include <Image.h>
class FlipOp : public Operation
{
public:
enum Direction {Horizontal, Vertical};
FlipOp(Direction);
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();
private:
Direction _dir;
};
#endif // FLIPOP_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