Beispiel #1
0
void V_equalization(QImage &image)
{
    int width = image.width();
    int height = image.height();

    int histSize = 256;
    std::vector<double> histV(histSize, 0.0);

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QColor oldColor(image.pixel(x, y));
            int v = oldColor.value();
            ++histV[v];
        }

    for (int i = 1; i < histSize; ++i)
        histV[i] += histV[i - 1];

    for (int i = 0; i < histSize; ++i)
        histV[i] /= width * height;

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QColor oldColor(image.pixel(x, y));
            int h = oldColor.hue();
            int s = oldColor.saturation();
            int v = oldColor.value();
            int newV = qMin(qFloor(histSize * histV[v]), histSize - 1);
            QColor newColor;
            newColor.setHsv(h, s, newV);
            image.setPixel(x, y, newColor.rgb());
        }
}
Beispiel #2
0
void MainWindow::on_actionBrightness_normalization_triggered()
{
    QPixmap pixmap = pixmapItem->pixmap().copy();

    QImage image = pixmap.toImage();
    int width = image.width();
    int height = image.height();

    if (width == 0 || height == 0)
    {
        ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
        return;
    }

    int minV = 256;
    int maxV = -1;

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QColor oldColor(image.pixel(x, y));
            int v = oldColor.value();
            if (v < minV)
                minV = v;
            if (v > maxV)
                maxV = v;
        }

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QColor oldColor(image.pixel(x, y));
            int v = ( oldColor.value() - minV) * 255 / (maxV - minV);
            if (v < 0)
                v = 0;
            if (v > 255)
                v = 255;
            QColor newColor;
            newColor.setHsv(oldColor.hue(), oldColor.saturation(), v);
            image.setPixel(x, y, newColor.rgb());
        }

    pixmap.convertFromImage(image);

    pixmapItem_2->setPixmap(pixmap);
    scene_2->setSceneRect(QRectF(pixmap.rect()));

    calcHist(pixmap, hist_2, maxLevel_2);
    drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
Beispiel #3
0
void calcHist(QPixmap &pixmap, std::vector<int> &hist, int &maxLevel)
{
    QImage image = pixmap.toImage();
    const int histSize = 256;
    hist.assign(histSize, 0);
    maxLevel = -1;
    for (int y = 0; y < image.height(); ++y)
        for (int x = 0; x < image.width(); ++x)
        {
            QColor oldColor(image.pixel(x, y));
            int gray = oldColor.value();
            ++hist[gray];
            if (hist[gray] > maxLevel)
                maxLevel = hist[gray];
        }
}
Beispiel #4
0
void Dialog::drawFill()
{
    QColor switchColor = Qt::darkGreen;
    QImage img = pix.toImage();

    x = ui->label->x;
    y = ui->label->y;

    QRgb pixel(img.pixel(x,y));
    QColor oldColor(pixel);

    if(switchColor != oldColor)
    {
        fillRecurs(x, y, switchColor.rgb(), oldColor.rgb(),img);
        pix = QPixmap::fromImage(img);
        damj();
    }
}
void FillInstrument::paint(ImageArea &imageArea, bool isSecondaryColor, bool)
{
    QColor switchColor;
    if(!isSecondaryColor)
        switchColor = DataSingleton::Instance()->getPrimaryColor();
    else
        switchColor = DataSingleton::Instance()->getSecondaryColor();

    QRgb pixel(imageArea.getImage()->pixel(mStartPoint));
    QColor oldColor(pixel);

    if(switchColor != oldColor)
    {
        fillRecurs(mStartPoint.x(), mStartPoint.y(),
                   switchColor.rgb(), oldColor.rgb(),
                   *imageArea.getImage());
    }
    imageArea.setEdited(true);
    imageArea.update();
}
//-----  SetWireframeColor()  -------------------------------------------------
DWORD DirectXMeshCollision::SetWireframeColor(const DWORD color)
{
	DWORD	oldColor(_wireframeColor);

	//  set new color
	_wireframeColor = color;

	//  wireframe mode?
	if ((_renderMode == DXRM_WIREFRAME) && (!_vecVBuffer.empty()))
	{
		_forceNoRender = true;		//  disable rendering

		for (auto pIter=_vecVBuffer.begin(), pEnd=_vecVBuffer.end(); pIter != pEnd; ++pIter)
		{
			(*pIter)->Release();
		}
		_vecVBuffer.clear();

		_forceNoRender = false;		//  enable rendering

	}  //  if (_renderMode == DXRM_WIREFRAME)

	return oldColor;
}
Beispiel #7
0
void
KnobGuiColor::showColorDialog()
{
    QColorDialog dialog( _colorLabel->parentWidget() );

    dialog.setOption(QColorDialog::DontUseNativeDialog);
    KnobColorPtr knob = _knob.lock();
    if (!knob) {
        return;
    }
    const int nDims = knob->getNDimensions();
    ViewIdx view = getView();
    double curR = knob->getValue(DimIdx(0), view, false /*clampToMinmax*/);

    _lastColor.resize(nDims);
    _lastColor[0] = curR;
    double curG = curR;
    double curB = curR;
    double curA = 1.;
    if (nDims > 1) {
        curG = knob->getValue(DimIdx(1), view, false /*clampToMinmax*/);
        _lastColor[1] =  curG;
        curB = knob->getValue(DimIdx(2), view, false /*clampToMinmax*/);
        _lastColor[2] = curB;
    }
    if (nDims > 3) {
        dialog.setOption(QColorDialog::ShowAlphaChannel);
        curA = knob->getValue(DimIdx(3), view, false /*clampToMinmax*/);
        _lastColor[3] = curA;
    }

    convertFromInternalToUIColorspace(&curR, &curG, &curB);


    QColor curColor;
    curColor.setRgbF( Image::clamp<qreal>(curR, 0., 1.),
                      Image::clamp<qreal>(curG, 0., 1.),
                      Image::clamp<qreal>(curB, 0., 1.),
                      Image::clamp<qreal>(curA, 0., 1.) );
    dialog.setCurrentColor(curColor);
    QObject::connect( &dialog, SIGNAL(currentColorChanged(QColor)), this, SLOT(onDialogCurrentColorChanged(QColor)) );
    if ( !dialog.exec() ) {
        knob->setValueAcrossDimensions(_lastColor, DimIdx(0), view, eValueChangedReasonUserEdited);
    } else {
        QColor userColor = dialog.currentColor();
        std::vector<double> color(nDims);
        color[0] = userColor.redF();
        convertFromUIToInternalColorspace(&color[0]);
        if (nDims > 1) {
            color[1] =  userColor.greenF();
            convertFromUIToInternalColorspace(&color[1]);
        }
        if (nDims > 2) {
            color[2] = userColor.blueF();
            convertFromUIToInternalColorspace(&color[2]);
        }
        if (nDims > 3) {
            color[3] = userColor.alphaF();
        }



        for (int i = 0; i < 3; ++i) {
            SpinBox* sb = 0;
            getSpinBox(DimIdx(i), &sb);
            if (sb) {
                sb->setValue(color[i]);
            }
        }

        std::vector<double> oldColor(nDims);
        for (int i = 0; i < nDims; ++i) {
            oldColor[i] = _lastColor[i];
        }
        KnobGuiPtr knobUI = getKnobGui();
        knobUI->pushUndoCommand( new KnobUndoCommand<double>(knob, oldColor, color, getView()) );

    }
    KnobGuiPtr knobUI = getKnobGui();
    if ( knobUI->getGui() ) {
        knobUI->getGui()->setDraftRenderEnabled(false);
    }
} // showColorDialog