QImage KisVisualColorSelectorShape::getImageMap() { //qDebug() << this << ">>>>>>>>> getImageMap()" << m_d->imagesNeedUpdate; if (m_d->imagesNeedUpdate == true) { m_d->gradient = QImage(width(), height(), QImage::Format_ARGB32); m_d->gradient.fill(Qt::transparent); // KoColor c = m_d->currentColor; // Fill a buffer with the right kocolors quint8 *data = new quint8[width() * height() * height()]; quint8 *dataPtr = data; for (int y = 0; y < m_d->gradient.height(); y++) { for (int x=0; x < m_d->gradient.width(); x++) { QPointF newcoordinate = convertWidgetCoordinateToShapeCoordinate(QPoint(x, y)); KoColor c = convertShapeCoordinateToKoColor(newcoordinate); memcpy(dataPtr, c.data(), m_d->currentColor.colorSpace()->pixelSize()); dataPtr += m_d->currentColor.colorSpace()->pixelSize(); } } // Convert the buffer to a qimage if (m_d->displayRenderer) { m_d->gradient = m_d->displayRenderer->convertToQImage(m_d->currentColor.colorSpace(), data, width(), height()); } else { m_d->gradient = m_d->currentColor.colorSpace()->convertToQImage(data, width(), height(), 0, KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags()); } delete[] data; m_d->imagesNeedUpdate = false; } return m_d->gradient; }
void SprayBrush::paintDistanceMap(KisPaintDeviceSP dev, const KisPaintInformation &info, const KoColor &painterColor){ KisRandomAccessor accessor = dev->createRandomAccessor(0, 0); KoColor color = painterColor; qreal posX = info.pos().x(); qreal posY = info.pos().y(); qreal opacity = 255; for (int y = -m_radius; y <= m_radius; y++){ for (int x = -m_radius; x <= m_radius; x++){ //opacity = sqrt(y*y + x*x) / m_radius; opacity = (y*y + x*x) / (m_radius * m_radius); opacity = 1.0 - opacity; opacity *= m_scale; if (opacity < 0) continue; if (opacity > 1.0) opacity = 1.0; if ( (y*y + x*x) <= (m_radius * m_radius) ) { color.setOpacity( opacity * 255); accessor.moveTo(x + posX, y + posY); memcpy( accessor.rawData(), color.data(), dev->colorSpace()->pixelSize() ); } } } }
void TestKoColor::testForModel(QString model) { QColor qc(200, 125, 100); QList<KoID> depthIDs = KoColorSpaceRegistry::instance()->colorDepthList(model, KoColorSpaceRegistry::AllColorSpaces); foreach(const KoID& depthId, depthIDs) { const KoColorSpace* cs = KoColorSpaceRegistry::instance()->colorSpace(model, depthId.id() , ""); if (cs) { KoColor kc(cs); kc.fromQColor(qc); QDomDocument doc; QDomElement elt = doc.createElement("color"); kc.toXML(doc, elt); doc.appendChild(elt); dbgPigment << doc.toString(); KoColor kcu = KoColor::fromXML(elt.firstChildElement(), depthId.id(), QHash<QString, QString>()); QVERIFY2(*(kc.colorSpace()) == *(kcu.colorSpace()), QString("Not identical color space (colorModelId = %1 depthId = %2) != (colorModelId = %3 depthId = %4) ") .arg(kc.colorSpace()->colorModelId().id()) .arg(kc.colorSpace()->colorDepthId().id()) .arg(kcu.colorSpace()->colorModelId().id()) .arg(kcu.colorSpace()->colorDepthId().id()).toLatin1()); QVERIFY(cs->difference(kcu.data(), kc.data()) <= 1); } } }
void KisWdgIndexColors::setConfiguration(const KisPropertiesConfigurationSP config) { PaletteGeneratorConfig palCfg; palCfg.fromByteArray(config->getProperty("paletteGen").toByteArray()); ui->luminanceSlider->setValue(config->getFloat("LFactor")*100); ui->aSlider->setValue(config->getFloat("aFactor")*100); ui->bSlider->setValue(config->getFloat("bFactor")*100); ui->alphaStepsSpinBox->setValue(config->getInt("alphaSteps")); ui->colorLimitCheck->setChecked(config->getBool("reduceColorsEnabled")); ui->colorLimit->setEnabled(config->getBool("reduceColorsEnabled")); ui->colorLimit->setValue(config->getInt("colorLimit")); ui->diagCheck->setChecked(palCfg.diagonalGradients); ui->inbetweenSpinBox->setValue(palCfg.inbetweenRampSteps); for(int y = 0; y < 4; ++y) for(int x = 0; x < 4; ++x) { m_colorSelectors[y][x].checkbox->setChecked(palCfg.colorsEnabled[y][x]); m_colorSelectors[y][x].button->setEnabled(palCfg.colorsEnabled[y][x]); KoColor c; c.fromQColor(palCfg.colors[y][x]); m_colorSelectors[y][x].button->setColor(c); } for(int y = 0; y < 3; ++y) m_stepSpinners[y]->setValue(palCfg.gradientSteps[y]); IndexColorPalette pal = palCfg.generate(); ui->colorCount->setText(QString::number(pal.numColors())); }
inline void HairyBrush::darkenPixel(int wx, int wy, const KoColor &color) { m_dabAccessor->moveTo(wx, wy); if (m_dab->colorSpace()->opacityU8(m_dabAccessor->rawData()) < color.opacityU8()) { memcpy(m_dabAccessor->rawData(), color.data(), m_pixelSize); } }
void HairyBrush::paintParticle(QPointF pos, const KoColor& color) { // opacity top left, right, bottom left, right memcpy(m_color.data(), color.data(), m_pixelSize); quint8 opacity = color.opacityU8(); int ipx = int (pos.x()); int ipy = int (pos.y()); qreal fx = pos.x() - ipx; qreal fy = pos.y() - ipy; quint8 btl = qRound((1.0 - fx) * (1.0 - fy) * opacity); quint8 btr = qRound((fx) * (1.0 - fy) * opacity); quint8 bbl = qRound((1.0 - fx) * (fy) * opacity); quint8 bbr = qRound((fx) * (fy) * opacity); m_color.setOpacity(btl); plotPixel(ipx , ipy, m_color); m_color.setOpacity(btr); plotPixel(ipx + 1 , ipy, m_color); m_color.setOpacity(bbl); plotPixel(ipx , ipy + 1, m_color); m_color.setOpacity(bbr); plotPixel(ipx + 1 , ipy + 1, m_color); }
void KisColorPatches::mouseMoveEvent(QMouseEvent *event) { event->ignore(); KisColorSelectorBase::mouseMoveEvent(event); if(event->isAccepted()) return; if (!(event->buttons() & Qt::LeftButton)) return; if ((event->pos() - m_dragStartPos).manhattanLength() < QApplication::startDragDistance()) return; KoColor koColor; if(!colorAt(m_dragStartPos, &koColor)) return; QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; QColor color = koColor.toQColor(); mimeData->setColorData(color); mimeData->setText(color.name()); drag->setMimeData(mimeData); drag->exec(Qt::CopyAction); event->accept(); }
void HairyBrush::saturationDepletion(Bristle * bristle, KoColor &bristleColor, qreal pressure, qreal inkDeplation) { qreal saturation; if (m_properties->useWeights) { // new weighted way (experiment) saturation = ( (pressure * m_properties->pressureWeight) + (bristle->length() * m_properties->bristleLengthWeight) + (bristle->inkAmount() * m_properties->bristleInkAmountWeight) + ((1.0 - inkDeplation) * m_properties->inkDepletionWeight)) - 1.0; } else { // old way of computing saturation saturation = ( pressure * bristle->length() * bristle->inkAmount() * (1.0 - inkDeplation)) - 1.0; } m_transfo->setParameter(m_transfo->parameterId("h"), 0.0); m_transfo->setParameter(m_transfo->parameterId("v"), 0.0); m_transfo->setParameter(m_saturationId, saturation); m_transfo->setParameter(3, 1);//sets the type to m_transfo->setParameter(4, false);//sets the colorize to none. m_transfo->transform(bristleColor.data(), bristleColor.data() , 1); }
void IndexColorPalette::insertColor(QColor qclr) { KoColor koclr; koclr.fromQColor(qclr); koclr.convertTo(KoColorSpaceRegistry::instance()->lab16()); LabColor clr = *(reinterpret_cast<LabColor*>(koclr.data())); insertColor(clr); }
void IndexColorPalette::insertShades(KoColor koclrA, KoColor koclrB, int shades) { koclrA.convertTo(KoColorSpaceRegistry::instance()->lab16()); koclrB.convertTo(KoColorSpaceRegistry::instance()->lab16()); LabColor clrA = *(reinterpret_cast<LabColor*>(koclrA.data())); LabColor clrB = *(reinterpret_cast<LabColor*>(koclrB.data())); insertShades(clrA, clrB, shades); }
bool KisColorSelectorTriangle::containsPointInComponentCoords(int x, int y) const { QPoint triangleCoords = widgetToTriangleCoordinates(QPoint(x, y)); if (!m_realPixelCache) return false; KoColor pixel = Acs::pickColor(m_realPixelCache, triangleCoords); return pixel.opacityU8() == OPACITY_OPAQUE_U8; }
void KoStopGradient::setStops(QList< KoGradientStop > stops) { m_stops.clear(); KoColor color; Q_FOREACH (const KoGradientStop & stop, stops) { color = stop.second; color.convertTo(colorSpace()); m_stops.append(KoGradientStop(stop.first, color)); }
QColor KisVisualColorSelectorShape::getColorFromConverter(KoColor c){ QColor col; KoColor color = c; if (m_d->displayRenderer) { color.convertTo(m_d->displayRenderer->getPaintingColorSpace()); col = m_d->displayRenderer->toQColor(c); } else { col = c.toQColor(); } return col; }
void KisVisualColorSelectorShape::setColorFromSibling(KoColor c) { //qDebug() << this << "setColorFromSibling"; if (c.colorSpace() != m_d->colorSpace) { c.convertTo(m_d->colorSpace); } m_d->currentColor = c; Q_EMIT sigNewColor(c); m_d->imagesNeedUpdate = true; update(); }
void KisVisualColorSelectorShape::setColor(KoColor c) { //qDebug() << this << "KisVisualColorSelectorShape::setColor"; if (c.colorSpace() != m_d->colorSpace) { c.convertTo(m_d->colorSpace); } m_d->currentColor = c; updateCursor(); m_d->imagesNeedUpdate = true; update(); }
void KoStopGradient::colorAt(KoColor& dst, qreal t) const { if (! m_stops.count()) return; if (t <= m_stops.first().first || m_stops.count() == 1) { // we have only one stop or t is before the first stop // -> use the color of the first stop dst.fromKoColor(m_stops.first().second); } else if (t >= m_stops.last().first) { // t is after the last stop // -> use the color of the last stop dst.fromKoColor(m_stops.last().second); } else { // we have at least two color stops // -> find the two stops which frame our t QList<KoGradientStop>::const_iterator stop = m_stops.begin(); QList<KoGradientStop>::const_iterator lastStop = m_stops.end(); // we already checked the first stop, so we start at the second for (++stop; stop != lastStop; ++stop) { // we break at the stop which is just after our t if (stop->first > t) break; } if ( !(*buffer.colorSpace() == *colorSpace())) { buffer = KoColor(colorSpace()); } const KoGradientStop& leftStop = *(stop - 1); const KoGradientStop& rightStop = *(stop); const quint8 *colors[2]; colors[0] = leftStop.second.data(); colors[1] = rightStop.second.data(); qreal localT; qreal stopDistance = rightStop.first - leftStop.first; if (stopDistance < DBL_EPSILON) { localT = 0.5; } else { localT = (t - leftStop.first) / stopDistance; } qint16 colorWeights[2]; colorWeights[0] = static_cast<quint8>((1.0 - localT) * 255 + 0.5); colorWeights[1] = 255 - colorWeights[0]; colorSpace()->mixColorsOp()->mixColors(colors, colorWeights, 2, buffer.data()); dst.fromKoColor(buffer); } }
void KisColorPatches::mousePressEvent(QMouseEvent *event) { KoColor koColor; if(!colorAt(event->pos(), &koColor)) return; KisColorSelectorBase::mousePressEvent(event); if(event->isAccepted()) return; updateColorPreview(koColor.toQColor()); if (event->button() == Qt::LeftButton) m_dragStartPos = event->pos(); }
void KisBrushOp::paintAt(const KisPaintInformation& info) { if (!painter()->device()) return; KisBrushSP brush = m_brush; Q_ASSERT(brush); if (!brush) return; KisPaintInformation adjustedInfo = settings->m_optionsWidget->m_sizeOption->apply(info); if (!brush->canPaintFor(adjustedInfo)) return; KisPaintDeviceSP device = painter()->device(); double pScale = KisPaintOp::scaleForPressure(adjustedInfo.pressure()); // TODO: why is there scale and pScale that seems to contains the same things ? QPointF hotSpot = brush->hotSpot(pScale, pScale); QPointF pt = info.pos() - hotSpot; // Split the coordinates into integer plus fractional parts. The integer // is where the dab will be positioned and the fractional part determines // the sub-pixel positioning. qint32 x; double xFraction; qint32 y; double yFraction; splitCoordinate(pt.x(), &x, &xFraction); splitCoordinate(pt.y(), &y, &yFraction); quint8 origOpacity = settings->m_optionsWidget->m_opacityOption->apply(painter(), info.pressure()); KoColor origColor = settings->m_optionsWidget->m_darkenOption->apply(painter(), info.pressure()); double scale = KisPaintOp::scaleForPressure(adjustedInfo.pressure()); KisFixedPaintDeviceSP dab = cachedDab(device->colorSpace()); if (brush->brushType() == IMAGE || brush->brushType() == PIPE_IMAGE) { dab = brush->image(device->colorSpace(), scale, 0.0, adjustedInfo, xFraction, yFraction); } else { KoColor color = painter()->paintColor(); color.convertTo(dab->colorSpace()); brush->mask(dab, color, scale, scale, 0.0, info, xFraction, yFraction); } painter()->bltFixed(QPoint(x, y), dab, dab->bounds()); painter()->setOpacity(origOpacity); painter()->setPaintColor(origColor); }
KisShadeSelectorLineComboBox::KisShadeSelectorLineComboBox(QWidget *parent) : QComboBox(parent), m_popup(new KisShadeSelectorLineComboBoxPopup(this)), m_parentProxy(new KisColorSelectorBaseProxyNoop()), m_currentLine(new KisShadeSelectorLine(0,0,0, m_parentProxy.data(), this)) { QGridLayout* l = new QGridLayout(this); l->addWidget(m_currentLine); m_currentLine->setEnabled(false); KoColor color; color.fromQColor(QColor(190, 50, 50)); m_currentLine->setColor(color); updateSettings(); }
bool pick(KisPaintDeviceSP dev, const QPoint& pos, KoColor *color) { KIS_ASSERT(dev); KoColor pickedColor; dev->pixel(pos.x(), pos.y(), &pickedColor); pickedColor.convertTo(dev->compositionSourceColorSpace()); bool validColorPicked = pickedColor.opacityU8() != OPACITY_TRANSPARENT_U8; if (validColorPicked) { pickedColor.setOpacity(OPACITY_OPAQUE_U8); *color = pickedColor; } return validColorPicked; }
/*compares c1 and c2 based on HSV. c1 < c2, returns -1 c1 = c2, returns 0 c1 > c2, returns 1 */ int hsvComparison(const KoColor& c1, const KoColor& c2) { QColor qc1 = c1.toQColor(); QColor qc2 = c2.toQColor(); if (qc1.hue() < qc2.hue()) return -1; if (qc1.hue() > qc2.hue()) return 1; // hue is the same, ok let's compare saturation if (qc1.saturation() < qc2.saturation()) return -1; if (qc1.saturation() > qc2.saturation()) return 1; // oh, also saturation is same? if (qc1.value() < qc2.value()) return -1; if (qc1.value() > qc2.value()) return 1; // user selected two similar colors return 0; }
KoColor::KoColor(const KoColor & rhs) : d(new Private()) { d->colorSpace = rhs.colorSpace(); Q_ASSERT(*d->colorSpace == *KoColorSpaceRegistry::instance()->permanentColorspace(d->colorSpace)); if (d->colorSpace && rhs.d->data) { d->data = new quint8[d->colorSpace->pixelSize()]; memcpy(d->data, rhs.d->data, d->colorSpace->pixelSize()); } }
KoColor::KoColor(const KoColor &src, const KoColorSpace * colorSpace) : d(new Private()) { Q_ASSERT(colorSpace); d->colorSpace = KoColorSpaceRegistry::instance()->permanentColorspace(colorSpace); d->data = new quint8[colorSpace->pixelSize()]; memset(d->data, 0, d->colorSpace->pixelSize()); src.colorSpace()->convertPixelsTo(src.d->data, d->data, colorSpace, 1); }
void KisVisualColorSelectorShape::mouseMoveEvent(QMouseEvent *e) { if (m_d->mousePressActive==true && this->mask().contains(e->pos())) { QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->pos()); quint8* oldData = m_d->currentColor.data(); KoColor col = convertShapeCoordinateToKoColor(coordinates, true); QRect offsetrect(this->geometry().topLeft()+QPoint(7.0,7.0), this->geometry().bottomRight()-QPoint(7.0,7.0)); if (offsetrect.contains(e->pos()) || (m_d->colorSpace->difference(col.data(), oldData)>5)) { setColor(col); if (!m_d->updateTimer->isActive()) { Q_EMIT sigNewColor(col); m_d->updateTimer->start(); } } } else { e->ignore(); } }
KoColor::KoColor(const KoColor &src, const KoColorSpace * colorSpace) : d(new Private()) { Q_ASSERT(colorSpace); d->colorSpace = KoColorSpaceRegistry::instance()->permanentColorspace(colorSpace); d->data = new quint8[colorSpace->pixelSize()]; memset(d->data, 0, d->colorSpace->pixelSize()); src.colorSpace()->convertPixelsTo(src.d->data, d->data, colorSpace, 1, KoColorConversionTransformation::InternalRenderingIntent, KoColorConversionTransformation::InternalConversionFlags); }
void KisBrightnessContrastConfigWidget::slotDrawLine(const KoColor &color) { QColor colorNew = color.toQColor(); int i = (colorNew.red() + colorNew.green() + colorNew.blue())/3 ; QPixmap pix = m_page->curveWidget->getBasePixmap(); QPainter p(&pix); p.setPen(QPen(Qt::black, 1, Qt::SolidLine)); p.drawLine(i,0,i,255); QString label = "x:"; label.insert(2,QString(QString::number(i))); p.drawText(i,250,label); m_page->curveWidget->setPixmap(pix); }
void HairyBrush::paintParticle(QPointF pos, const KoColor& color, qreal weight) { // opacity top left, right, bottom left, right quint8 opacity = color.opacityU8(); opacity *= weight; int ipx = int (pos.x()); int ipy = int (pos.y()); qreal fx = pos.x() - ipx; qreal fy = pos.y() - ipy; quint8 btl = qRound((1.0 - fx) * (1.0 - fy) * opacity); quint8 btr = qRound((fx) * (1.0 - fy) * opacity); quint8 bbl = qRound((1.0 - fx) * (fy) * opacity); quint8 bbr = qRound((fx) * (fy) * opacity); const KoColorSpace * cs = m_dab->colorSpace(); m_dabAccessor->moveTo(ipx , ipy); btl = quint8(qBound<quint16>(OPACITY_TRANSPARENT_U8, btl + cs->opacityU8(m_dabAccessor->rawData()), OPACITY_OPAQUE_U8)); memcpy(m_dabAccessor->rawData(), color.data(), cs->pixelSize()); cs->setOpacity(m_dabAccessor->rawData(), btl, 1); m_dabAccessor->moveTo(ipx + 1, ipy); btr = quint8(qBound<quint16>(OPACITY_TRANSPARENT_U8, btr + cs->opacityU8(m_dabAccessor->rawData()), OPACITY_OPAQUE_U8)); memcpy(m_dabAccessor->rawData(), color.data(), cs->pixelSize()); cs->setOpacity(m_dabAccessor->rawData(), btr, 1); m_dabAccessor->moveTo(ipx, ipy + 1); bbl = quint8(qBound<quint16>(OPACITY_TRANSPARENT_U8, bbl + cs->opacityU8(m_dabAccessor->rawData()), OPACITY_OPAQUE_U8)); memcpy(m_dabAccessor->rawData(), color.data(), cs->pixelSize()); cs->setOpacity(m_dabAccessor->rawData(), bbl, 1); m_dabAccessor->moveTo(ipx + 1, ipy + 1); bbr = quint8(qBound<quint16>(OPACITY_TRANSPARENT_U8, bbr + cs->opacityU8(m_dabAccessor->rawData()), OPACITY_OPAQUE_U8)); memcpy(m_dabAccessor->rawData(), color.data(), cs->pixelSize()); cs->setOpacity(m_dabAccessor->rawData(), bbr, 1); }
void KoXYColorSelector::drawContents( QPainter *painter ) { KoColor c = m_colors[0]; // quick way to set the colorspace QColor color; const quint8 *colors[4]; colors[0] = m_colors[0].data(); colors[1] = m_colors[1].data(); colors[2] = m_colors[2].data(); colors[3] = m_colors[3].data(); QRect contentsRect_(contentsRect()); QImage image(contentsRect_.width(), contentsRect_.height(), QImage::Format_ARGB32 ); KoMixColorsOp * mixOp = m_colorSpace->mixColorsOp(); for (int x = 0; x < contentsRect_.width(); x++) for (int y = 0; y < contentsRect_.height(); y++){ qreal xVal = static_cast<qreal>(x) / (contentsRect_.width() - 1); qreal yVal = static_cast<qreal>(y) / (contentsRect_.height() - 1); qint16 colorWeights[4]; colorWeights[0] = static_cast<quint8>((1.0 - yVal) * (1.0 - xVal) * 255 + 0.5); colorWeights[1] = static_cast<quint8>((1.0 - yVal) * (xVal) * 255 + 0.5); colorWeights[2] = static_cast<quint8>((yVal) * (1.0 - xVal) * 255 + 0.5); colorWeights[3] = static_cast<quint8>((yVal) * (xVal) * 255 + 0.5); mixOp->mixColors(colors, colorWeights, 4, c.data()); c.toQColor( &color); image.setPixel(x, y, color.rgba()); } painter->drawImage( contentsRect_, image, QRect( 0, 0, image.width(), image.height()) ); }
void KoColorPopupAction::setCurrentColor( const KoColor &color ) { d->colorChooser->slotSetColor( color ); KoColor minColor( color ); d->currentColor = minColor; KoColor maxColor( color ); minColor.setOpacity( OPACITY_TRANSPARENT_U8 ); maxColor.setOpacity( OPACITY_OPAQUE_U8 ); d->opacitySlider->blockSignals( true ); d->opacitySlider->setColors( minColor, maxColor ); d->opacitySlider->setValue( color.opacityU8() ); d->opacitySlider->blockSignals( false ); updateIcon(); }
void HairyBrush::opacityDepletion(Bristle* bristle, KoColor& bristleColor, qreal pressure, qreal inkDeplation) { qreal opacity = OPACITY_OPAQUE_F; if (m_properties->useWeights) { opacity = qBound(0.0, (pressure * m_properties->pressureWeight) + (bristle->length() * m_properties->bristleLengthWeight) + (bristle->inkAmount() * m_properties->bristleInkAmountWeight) + ((1.0 - inkDeplation) * m_properties->inkDepletionWeight),1.0); } else { opacity = bristle->length() * bristle->inkAmount(); } bristleColor.setOpacity(opacity); }