[TASK] Finish border overflow filter.

This commit is contained in:
Jan Philipp Timme 2015-12-04 13:18:39 +01:00
parent 57923519df
commit f5393d74b6
3 changed files with 35 additions and 12 deletions

View File

@ -543,9 +543,16 @@ void ImageViewer::applyBasicFilter() {
* @brief ImageViewer::applyBasicFilterWithOverflowHandling
*/
void ImageViewer::applyBasicFilterWithOverflowHandling() {
// TODO: Get overflow mode here
LazyImage::overflowMode overflowMode = LazyImage::CONSTANT;
logFile << "Applying basic filter - overflow mode: " << overflowMode << std::endl;
QString chosen_mode = filter_mode_combobox->currentText();
LazyImage::overflowMode overflow_mode;
if(chosen_mode == "Zero padding") overflow_mode = LazyImage::ZERO_PADDING;
else if(chosen_mode == "Constant") overflow_mode = LazyImage::CONSTANT;
else if(chosen_mode == "Continuous") overflow_mode = LazyImage::CONTINUOUS;
else if(chosen_mode == "Mirrored") overflow_mode = LazyImage::MIRRORED;
else {
logFile << "Could not determine chosen mode, this is a problem!" << std::endl;
}
logFile << "Applying basic filter - overflow mode: " << chosen_mode.toStdString() << " -> " << overflow_mode << std::endl;
renewLogging();
int* data = filter_gui->getData();
@ -574,7 +581,7 @@ void ImageViewer::applyBasicFilterWithOverflowHandling() {
int dx = fx - (filter_size / 2);
for(int fy=0; fy<filter_size; fy++) {
int dy = fy - (filter_size / 2);
QColor color = QColor::fromRgb(original->getPixel(x+dx, y+dy, overflowMode));
QColor color = QColor::fromRgb(original->getPixel(x+dx, y+dy, overflow_mode));
color.getHsl(&h, &s, &l);
//std::cout << "[" << fx << "," << fy <<"] " << l << " * " << data[fx*filter_size + fy] << " = ";
intensity_sum += (l * data[fx*filter_size + fy]);
@ -829,9 +836,21 @@ void ImageViewer::generateControlPanels() {
apply_filter = new QPushButton("Apply filter");
QObject::connect(apply_filter, SIGNAL(clicked()), this, SLOT(applyBasicFilter()));
filter_mode_combobox = new QComboBox();
filter_mode_combobox->addItem("Zero padding");
filter_mode_combobox->addItem("Constant");
filter_mode_combobox->addItem("Mirrored");
filter_mode_combobox->addItem("Continuous");
apply_border_mode_filter = new QPushButton("Apply filter with overflow handling");
QObject::connect(apply_border_mode_filter, SIGNAL(clicked()), this, SLOT(applyBasicFilterWithOverflowHandling()));
task_tab4_scrolllayout->addWidget(filter_size_slider);
task_tab4_scrolllayout->addWidget(filter_gui->getWidget());
task_tab4_scrolllayout->addWidget(apply_filter);
task_tab4_scrolllayout->addWidget(new QLabel("Choose border overflow mode:"));
task_tab4_scrolllayout->addWidget(filter_mode_combobox);
task_tab4_scrolllayout->addWidget(apply_border_mode_filter);
tabWidget->addTab(task_tab4_widget, "Task #4");

View File

@ -135,6 +135,8 @@ class ImageViewer : public QMainWindow {
QSlider* filter_size_slider;
FilterGui* filter_gui;
QPushButton* apply_filter;
QComboBox* filter_mode_combobox;
QPushButton* apply_border_mode_filter;
// "My" space for storing data/results
LazyImage* original;

View File

@ -211,14 +211,16 @@ class LazyImage {
*
* @brief LazyImage::getPixel
*/
QColor getPixel(int x, int y, overflowMode mode) {
QRgb getPixel(int x, int y, overflowMode mode) {
int width = this->img->width();
int height = this->img->height();
QRgb result = NULL;
bool return_result = false;
QRgb result;
switch(mode) {
case ZERO_PADDING: // Return black for all out of bound requests
if(x < 0 || x >= width || y < 0 || y >= height) {
result = QRgb(qRgb(0, 0, 0);
result = qRgb(0, 0, 0);
return_result = true;
}
break;
case CONSTANT: // Simply clamp to the border it is stuck on
@ -240,17 +242,17 @@ class LazyImage {
}
break;
case CONTINUOUS: // simply start over at the other side again
x = x % width;
y = y % height;
x = std::abs(x % width);
y = std::abs(y % height);
break;
default:
std::cout << "HELP, SOMETHING WENT WRONG! I DON'T KNOW THIS MODE!" << std::endl;
break; // BOOM!
}
if(result == NULL) {
return this->img->pixel(x, y);
} else {
if(return_result) {
return result;
} else {
return this->img->pixel(x, y);
}
};