ExtraFiltersPlugin Class Reference

#include <extrafiltersplugin.h>

Inheritance diagram for ExtraFiltersPlugin:

Inheritance graph
[legend]
Collaboration diagram for ExtraFiltersPlugin:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 33 of file extrafiltersplugin.h.

Public Member Functions

QStringList filters () const
QImage filterImage (const QString &filter, const QImage &image, QWidget *parent)


Member Function Documentation

QStringList ExtraFiltersPlugin::filters (  )  const [virtual]

Implements FilterInterface.

Definition at line 31 of file extrafiltersplugin.cpp.

00032 {
00033     return QStringList() << tr("Flip Horizontally") << tr("Flip Vertically")
00034                          << tr("Smudge...") << tr("Threshold...");
00035 }

QImage ExtraFiltersPlugin::filterImage ( const QString filter,
const QImage image,
QWidget parent 
) [virtual]

Implements FilterInterface.

Definition at line 37 of file extrafiltersplugin.cpp.

References alpha, Qt::blue, QImage::Format_RGB32, QInputDialog::getInteger(), green, QImage::height(), i, image, QObject::parent(), QImage::pixel(), qAlpha(), qBlue(), qGreen(), qRed(), qRgba(), red, QImage::setPixel(), QImage::width(), x, and y.

00039 {
00040     QImage original = image.convertToFormat(QImage::Format_RGB32);
00041     QImage result = original;
00042 
00043     if (filter == tr("Flip Horizontally")) {
00044         for (int y = 0; y < original.height(); ++y) {
00045             for (int x = 0; x < original.width(); ++x) {
00046                 int pixel = original.pixel(original.width() - x - 1, y);
00047                 result.setPixel(x, y, pixel);
00048             }
00049         }
00050     } else if (filter == tr("Flip Vertically")) {
00051         for (int y = 0; y < original.height(); ++y) {
00052             for (int x = 0; x < original.width(); ++x) {
00053                 int pixel = original.pixel(x, original.height() - y - 1);
00054                 result.setPixel(x, y, pixel);
00055             }
00056         }
00057     } else if (filter == tr("Smudge...")) {
00058         bool ok;
00059         int numIters = QInputDialog::getInteger(parent, tr("Smudge Filter"),
00060                                     tr("Enter number of iterations:"),
00061                                     5, 1, 20, 1, &ok);
00062         if (ok) {
00063             for (int i = 0; i < numIters; ++i) {
00064                 for (int y = 1; y < original.height() - 1; ++y) {
00065                     for (int x = 1; x < original.width() - 1; ++x) {
00066                         int p1 = original.pixel(x, y);
00067                         int p2 = original.pixel(x, y + 1);
00068                         int p3 = original.pixel(x, y - 1);
00069                         int p4 = original.pixel(x + 1, y);
00070                         int p5 = original.pixel(x - 1, y);
00071 
00072                         int red = (qRed(p1) + qRed(p2) + qRed(p3) + qRed(p4)
00073                                    + qRed(p5)) / 5;
00074                         int green = (qGreen(p1) + qGreen(p2) + qGreen(p3)
00075                                      + qGreen(p4) + qGreen(p5)) / 5;
00076                         int blue = (qBlue(p1) + qBlue(p2) + qBlue(p3)
00077                                     + qBlue(p4) + qBlue(p5)) / 5;
00078                         int alpha = (qAlpha(p1) + qAlpha(p2) + qAlpha(p3)
00079                                      + qAlpha(p4) + qAlpha(p5)) / 5;
00080 
00081                         result.setPixel(x, y, qRgba(red, green, blue, alpha));
00082                     }
00083                 }
00084             }
00085         }
00086     } else if (filter == tr("Threshold...")) {
00087         bool ok;
00088         int threshold = QInputDialog::getInteger(parent, tr("Threshold Filter"),
00089                                                  tr("Enter threshold:"),
00090                                                  10, 1, 256, 1, &ok);
00091         if (ok) {
00092             int factor = 256 / threshold;
00093             for (int y = 0; y < original.height(); ++y) {
00094                 for (int x = 0; x < original.width(); ++x) {
00095                     int pixel = original.pixel(x, y);
00096                     result.setPixel(x, y, qRgba(qRed(pixel) / factor * factor,
00097                                                 qGreen(pixel) / factor * factor,
00098                                                 qBlue(pixel) / factor * factor,
00099                                                 qAlpha(pixel)));
00100                 }
00101             }
00102         }
00103     }
00104     return result;
00105 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 14:58:33 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1