/*!
** @brief   Process an image
**
** @param [In] image    Image to process
**
** @return  True/False
*/
bool ClassicPrintFilm::process(QImage& image) {
    QtImageFilter* filter;
	QList<QVariant> levels;

    int green_level = (22 * m_temperature / 100) - 11;
    int blue_level = -((64 * m_temperature / 100) - 32);

    emit progress(0);

    for (int i = 0; i < 256; ++i) {
		levels.push_back(QVariant((qlonglong)qRgb(0,
												  qBound(0, i + green_level, 255),
												  qBound(0, i + blue_level, 255))));
    }

    filter = QtImageFilterFactory::createImageFilter("Levels");
	filter->setOption(QtImageFilter::FilterChannels, "gb");
	filter->setOption(LevelsFilter::Levels, levels);
    image = filter->apply(image);

    emit progress(66);
    filter = QtImageFilterFactory::createImageFilter("Noise");
    filter->setOption(NoiseFilter::NoisePercent, m_noise);
    image = filter->apply(image);
    delete filter;

    emit progress(100);
    return true;
}
Ejemplo n.º 2
0
void ImageToolWidget::filterImage()
{
    if (ui.PixmapLabel->pixmap() == 0) {
        QMessageBox::information(this, "QImageTool", "Sorry, you must load an image first\n");
    } else {
        setCursor(Qt::WaitCursor);
        QImage imgToFilter = ui.PixmapLabel->pixmap()->toImage();
        QtImageFilter *filter = m_imageFilters[ui.FiltersCombo->currentIndex()];
        if (filter->name() == "Punch") {
            filter->setOption(QtImageFilter::Radius, qMin(imgToFilter.width(), imgToFilter.height())/2);
            filter->setOption(QtImageFilter::Center, QPointF(imgToFilter.width()/2.0,imgToFilter.height()/2.0));
            filter->setOption(QtImageFilter::Force, 0.5);
        } else if (filter->name() == "ConvolutionFilter") {
            // A simple mean filter just to demonstrate that we can add our own kernels.
            static int kernelElements[9] =
            {   1,  1,  1,
                1,  1,  1,
                1,  1,  1
            };
            QtConvolutionKernelMatrix kernel(kernelElements, 3, 3);
            QVariant value;
            qVariantSetValue<QtConvolutionKernelMatrix>(value, kernel);
            filter->setOption(QtImageFilter::ConvolutionKernelMatrix, value);

        }
        if (filter->supportsOption(MirrorFilter::MirrorHorizontal))
            filter->setOption(MirrorFilter::MirrorHorizontal, ui.ckHorizontal->isChecked() );
        if (filter->supportsOption(MirrorFilter::MirrorVertical))
            filter->setOption(MirrorFilter::MirrorVertical, ui.ckVertical->isChecked());

        if (filter->supportsOption(QtImageFilter::FilterChannels)) {
            QString rgba = ui.ckRed->isChecked() ? "r" : "";
            rgba+= ui.ckGreen->isChecked() ? "g" : "";
            rgba+= ui.ckBlue->isChecked() ? "b" : "";
            rgba+= ui.ckAlpha->isChecked() ? "a" : "";
            filter->setOption(QtImageFilter::FilterChannels, rgba);
        }

        if (filter->supportsOption(QtImageFilter::FilterBorderPolicy)) {
            QString borderPolicy;
            if (ui.rbExtend->isChecked()) borderPolicy = "Extend";
            else if (ui.rbMirror->isChecked()) borderPolicy = "Mirror";
            else borderPolicy = "Wrap";
            filter->setOption(QtImageFilter::FilterBorderPolicy, borderPolicy);
        }

        imgToFilter = filter->apply(imgToFilter);
        setCursor(Qt::ArrowCursor);
        setPixmapAndResize(QPixmap::fromImage(imgToFilter));
    }
}