// Compare images:
QBitArray OKFilter::imageToVect(const QString &inputImage)
{
    // Check src file:
    QFileInfo fi(inputImage);

    // Check files:
    if (!fi.exists())
        return QBitArray();

    QImage img(inputImage);
    if (img.isNull())
        return QBitArray();
    QBitArray result;
    result.resize(img.width()*img.height());
    int c = 0;
    for (int j=0; j<img.height(); j++)
        for (int i=0; i<img.width(); i++)
        {
            QRgb color = img.pixel(i, j);
            int alpha = qAlpha(color);
            result[c++] = (alpha>0);
        }

    return result;
}
Exemple #2
0
void KeyWidget::map(const KeyMap& newMap){
    keyMap = newMap;
    selection = QBitArray(keyMap.count());
    newSelection = QBitArray(keyMap.count());
    animation = QBitArray(keyMap.count());
    setFixedSize((keyMap.width() + KEY_SIZE) * 2.3, (keyMap.height() + KEY_SIZE) * 2.3);
    update();
}
Exemple #3
0
 BuddyMonitor::BuddyMonitor(const QSharedPointer<BuddyPolicy> &bp, int min_anon) :
   m_bp(bp),
   m_used_nyms(m_bp->GetCount(), false),
   m_min_anon(min_anon)
 {
   Q_ASSERT(m_bp);
   for(int idx = 0; idx < m_bp->GetCount(); idx++) {
     m_member_set.append(QBitArray(m_bp->GetCount(), true));
     m_nym_set.append(QBitArray(m_bp->GetCount(), true));
   }
 }
void ChanMappingController::saveSettings()
{
    QSettings settings(SETTINGS_DOMAIN, SETTINGS_APP);

	settings.beginGroup("ChanMappingController2");
	
	for (int i = 0; i < (int)DAQ::N_Modes; ++i) {
		settings.setValue(QString("terseString_%1").arg(i), mapping[i].toTerseString(QBitArray(mapping[i].size(),true)));
		settings.setValue(QString("terseString2_%1").arg(i), mapping2[i].toTerseString(QBitArray(mapping2[i].size(),true)));
	}
	settings.setValue("lastCMDlgDir", lastDir);
}
void KisConvolutionFilter::process(KisConstProcessingInformation srcInfo,
                                   KisProcessingInformation dstInfo,
                                   const QSize& size,
                                   const KisFilterConfiguration* config,
                                   KoUpdater* progressUpdater
                                  ) const
{
    Q_UNUSED(config);

    const KisPaintDeviceSP src = srcInfo.paintDevice();
    KisPaintDeviceSP dst = dstInfo.paintDevice();
    QPoint dstTopLeft = dstInfo.topLeft();
    QPoint srcTopLeft = srcInfo.topLeft();
    Q_ASSERT(src != 0);
    Q_ASSERT(dst != 0);

    KisConvolutionPainter painter(dst, dstInfo.selection());

    QBitArray channelFlags;
    if (config) {
        channelFlags = config->channelFlags();
    }
    if (channelFlags.isEmpty() || !config) {
        channelFlags = QBitArray(src->colorSpace()->channelCount(), true);
    }
 
    // disable alpha channel
    channelFlags.clearBit(1);

    painter.setChannelFlags(channelFlags);
    painter.setProgress(progressUpdater);
    painter.applyMatrix(m_matrix, src, srcTopLeft, dstTopLeft, size, BORDER_REPEAT);

}
Exemple #6
0
void LayerStack::resize(int top, int right, int bottom, int left)
{
	int newtop = -top;
	int newleft = -left;
	int newright = _width + right;
	int newbottom = _height + bottom;
	if(newtop >= newbottom || newleft >= newright) {
		qWarning() << "Invalid resize: borders reversed";
		return;
	}
	_width = newright - newleft;
	_height = newbottom - newtop;

	_xtiles = Tile::roundTiles(_width);
	_ytiles = Tile::roundTiles(_height);
	_cache = QPixmap(_width, _height);
	_dirtytiles = QBitArray(_xtiles*_ytiles, true);

	foreach(Layer *l, _layers)
		l->resize(top, right, bottom, left);

	if(left || top) {
		// Update annotation positions
		QPoint offset(left, top);
		foreach(Annotation *a, _annotations) {
			a->setRect(a->rect().translated(offset));
			emit annotationChanged(a->id());
		}
Exemple #7
0
void LayerStack::resize(int top, int right, int bottom, int left)
{
	const QSize oldsize(_width, _height);

	int newtop = -top;
	int newleft = -left;
	int newright = _width + right;
	int newbottom = _height + bottom;
	if(newtop >= newbottom || newleft >= newright) {
		qWarning() << "Invalid resize: borders reversed";
		return;
	}
	_width = newright - newleft;
	_height = newbottom - newtop;

	_xtiles = Tile::roundTiles(_width);
	_ytiles = Tile::roundTiles(_height);
	_dirtytiles = QBitArray(_xtiles*_ytiles, true);

	for(Layer *l : m_layers)
		l->resize(top, right, bottom, left);

	if(left || top) {
		// Update annotation positions
		QPoint offset(left, top);
		Q_FOREACH(const Annotation &a, m_annotations->getAnnotations()) {
			m_annotations->reshapeAnnotation(a.id, a.rect.translated(offset));
		}
	}
FlagArray::FlagArray(DFInstance *df, VIRTADDR base_addr)
{
    m_df = df;
    //get the array from the pointer
    VIRTADDR flags_addr = m_df->read_addr(base_addr);
    //size of the byte array
    quint32 size_in_bytes = m_df->read_addr(base_addr + 0x4);

    m_flags = QBitArray(size_in_bytes * 8);
    if(size_in_bytes > 1000){
        LOGW << "aborting reading flags, size too large" << size_in_bytes;
        return;
    }
    BYTE b;
    int position;
    for(uint i = 0; i < size_in_bytes; i++){
        position = 7;
        b = m_df->read_byte(flags_addr);
        if(b > 0){
            for(int t=128; t>0; t = t/2){
                if(b & t)
                    m_flags.setBit(i*8 + position, true);
                position--;
            }
        }
        flags_addr += 0x1;
    }
}
uint32_t OsmAnd::RoutingProfile::registerTagValueAttribute( const QString& tag, const QString& value )
{
    auto key = tag + "$" + value;

    auto itId = _universalRules.find(key);
    if(itId != _universalRules.end())
        return *itId;
    
    auto id = _universalRules.size();
    _universalRulesKeysById.push_back(key);
    _universalRules.insert(key, id);

    auto itTagRuleMask = _tagRuleMask.find(tag);
    if(itTagRuleMask == _tagRuleMask.end())
        itTagRuleMask = _tagRuleMask.insert(tag, QBitArray());
    
    if(itTagRuleMask->size() <= id)
    {
        assert(id < std::numeric_limits<int>::max());
        itTagRuleMask->resize(id + 1);
    }
    itTagRuleMask->setBit(id);
    
    return id;
}
void KisConvolutionFilter::process(KisPaintDeviceSP device,
                                  const QRect& applyRect,
                                  const KisFilterConfiguration* config,
                                  KoUpdater* progressUpdater) const
{
    Q_UNUSED(config);

    QPoint srcTopLeft = applyRect.topLeft();
    Q_ASSERT(device != 0);

    KisConvolutionPainter painter(device);

    QBitArray channelFlags;
    if (config) {
        channelFlags = config->channelFlags();
    }
    if (channelFlags.isEmpty() || !config) {
        channelFlags = QBitArray(device->colorSpace()->channelCount(), true);
    }
 
    painter.setChannelFlags(channelFlags);
    painter.setProgress(progressUpdater);
    painter.applyMatrix(m_matrix, device, srcTopLeft, srcTopLeft, applyRect.size(), BORDER_REPEAT);

}
void LayerStackObserver::canvasResized(int xoffset, int yoffset, const QSize &oldsize)
{
	Q_ASSERT(m_layerstack);
	m_dirtytiles = QBitArray(m_layerstack->m_xtiles * m_layerstack->m_ytiles, true);
	m_dirtyrect = QRect(QPoint(), m_layerstack->size());
	resized(xoffset, yoffset, oldsize);
}
Exemple #12
0
 void applyGaussian(KisPixelSelectionSP selection,
                    const QRect &applyRect,
                    qreal radius)
 {
     KisGaussianKernel::applyGaussian(selection, applyRect,
                                      radius, radius,
                                      QBitArray(), 0);
 }
Exemple #13
0
void KeyWidget::map(const KeyMap& newMap){
    keyMap = newMap;
    selection = QBitArray(keyMap.count());
    newSelection = QBitArray(keyMap.count());
    animation = QBitArray(keyMap.count());
    int width, height;
    if(keyMap.isMouse()){
        width = (keyMap.width() + KEY_SIZE) * 2.6;
        height = (keyMap.height() + KEY_SIZE) * 2.6;
    } else {
        width = (keyMap.width() + KEY_SIZE) * 2.3;
        height = (keyMap.height() + KEY_SIZE) * 2.3;
    }
    if(width < 500)
        width = 500;
    setFixedSize(width, height);
    update();
}
Exemple #14
0
Domain::Domain(block *parentBlock)
{
    this->parentPosBlock = parentBlock;
    mySettings = Settings::instance();
    myExamples = Examples::instance();
    for(unsigned int i = 0; i < myExamples->getAllExamples()->size(); ++i)
    {
        termOccurences4Examples.push_back(QBitArray());
        domainMap.push_back(QMultiHash<int, int>());
    }
}
Exemple #15
0
/**
 * If not already initialized, this is called automatically when the
 * first layer is added.
 * @param size the size of the layers (each layer must be this big)
 */
void LayerStack::init(const QSize& size)
{
	Q_ASSERT(!size.isEmpty());
	_width = size.width();
	_height = size.height();
	_xtiles = _width / Tile::SIZE + ((_width % Tile::SIZE)>0);
	_ytiles = _height / Tile::SIZE + ((_height % Tile::SIZE)>0);
	_cache = QPixmap(size);
	_dirtytiles = QBitArray(_xtiles*_ytiles, true);
	emit resized();
}
Exemple #16
0
    foreach(PainterInfo *info, m_painterInfos) {
        KisPainter *painter = info->painter;

        painter->begin(targetDevice, !hasIndirectPainting ? selection : 0);
        m_resources->setupPainter(painter);

        if(hasIndirectPainting) {
            painter->setCompositeOp(targetDevice->colorSpace()->compositeOp(indirectPaintingCompositeOp));
            painter->setOpacity(OPACITY_OPAQUE_U8);
            painter->setChannelFlags(QBitArray());
        }
    }
void KisBlurFilter::processImpl(KisPaintDeviceSP device,
                                const QRect& rect,
                                const KisFilterConfiguration* config,
                                KoUpdater* progressUpdater
                                ) const
{
    QPoint srcTopLeft = rect.topLeft();
    Q_ASSERT(device != 0);
    if (!config) config = new KisFilterConfiguration(id().id(), 1);

    QVariant value;
    int shape = (config->getProperty("shape", value)) ? value.toInt() : 0;
    uint halfWidth = (config->getProperty("halfWidth", value)) ? value.toUInt() : 5;
    uint width = 2 * halfWidth + 1;
    uint halfHeight = (config->getProperty("halfHeight", value)) ? value.toUInt() : 5;
    uint height = 2 * halfHeight + 1;
    int rotate = (config->getProperty("rotate", value)) ? value.toInt() : 0;
    int strength = 100 - (config->getProperty("strength", value) ? value.toUInt() : 0);

    int hFade = (halfWidth * strength) / 100;
    int vFade = (halfHeight * strength) / 100;

    KisMaskGenerator* kas;
    dbgKrita << width << "" << height << "" << hFade << "" << vFade;
    switch (shape) {
    case 1:
        kas = new KisRectangleMaskGenerator(width, width / height , hFade, vFade, 2);
        break;
    case 0:
    default:
        kas = new KisCircleMaskGenerator(width, width / height, hFade, vFade, 2);
        break;
    }

    QBitArray channelFlags;
    if (config) {
        channelFlags = config->channelFlags();
    } 
    if (channelFlags.isEmpty() || !config) {
        channelFlags = QBitArray(device->colorSpace()->channelCount(), true);
    }

    KisConvolutionKernelSP kernel = KisConvolutionKernel::fromMaskGenerator(kas, rotate * M_PI / 180.0);
    delete kas;
    KisConvolutionPainter painter(device);
    painter.setChannelFlags(channelFlags);
    painter.setProgress(progressUpdater);
    painter.applyMatrix(kernel, device, srcTopLeft, srcTopLeft, rect.size(), BORDER_REPEAT);

}
void KisLsOverlayFilter::applyOverlay(KisPaintDeviceSP srcDevice,
                                      KisMultipleProjection *dst,
                                      const QRect &applyRect,
                                      const psd_layer_effects_overlay_base *config,
                                      KisLayerStyleFilterEnvironment *env) const
{
    if (applyRect.isEmpty()) return;

    KisPaintDeviceSP tempDevice = new KisPaintDevice(srcDevice->colorSpace());

    {
        // Create overlay device

        KisPaintDeviceSP fillDevice = new KisPaintDevice(srcDevice->colorSpace());
        KisLsUtils::fillOverlayDevice(fillDevice, applyRect, config, env);

        KisPainter gc(tempDevice);
        gc.setCompositeOp(COMPOSITE_OVER);
        gc.bitBlt(applyRect.topLeft(), srcDevice, applyRect);

        QBitArray channelFlags = srcDevice->colorSpace()->channelFlags(true, false);
        gc.setChannelFlags(channelFlags);
        gc.bitBlt(applyRect.topLeft(), fillDevice, applyRect);
        gc.end();
    }

    {
        // Paint over destination

        const QString compositeOp = config->blendMode();
        const quint8 opacityU8 = 255.0 / 100.0 * config->opacity();
        KisPaintDeviceSP dstDevice = dst->getProjection(KisMultipleProjection::defaultProjectionId(), compositeOp, srcDevice);

        KisPainter gc(dstDevice);

        gc.setCompositeOp(COMPOSITE_OVER);
        env->setupFinalPainter(&gc, opacityU8, QBitArray());

        gc.bitBlt(applyRect.topLeft(), tempDevice, applyRect);
        gc.end();
    }
}
Exemple #19
0
void KisImagePyramid::setChannelFlags(const QBitArray &channelFlags)
{
    m_channelFlags = channelFlags;
    int selectedChannels = 0;
    const KoColorSpace *projectionCs = m_originalImage->projection()->colorSpace();
    QList<KoChannelInfo*> channelInfo = projectionCs->channels();

    if (channelInfo.size() != m_channelFlags.size()) {
        m_channelFlags = QBitArray();
    }

    for (int i = 0; i < m_channelFlags.size(); ++i) {
        if (m_channelFlags.testBit(i) && channelInfo[i]->channelType() == KoChannelInfo::COLOR) {
            selectedChannels++;
            m_selectedChannelIndex = i;
        }
    }
    m_allChannelsSelected = (selectedChannels == m_channelFlags.size());
    m_onlyOneChannelSelected = (selectedChannels == 1);
}
QList<HighlightSettingsEntry> HighlightSettings::loadSettings(QString group) {
    QMutexLocker locker(&m_mutex);
    QList<HighlightSettingsEntry> settingsList = QList<HighlightSettingsEntry>();
    int size = settings->beginReadArray(group);
    for (int i = 0; i < size; i++) {
        settings->setArrayIndex(i);
        settingsList.append(HighlightSettingsEntry((const int&)i,
                (const QString&)settings->value("value", "").toString(),
                (const QString&)settings->value("group", "").toString(),
                (const QColor&)settings->value("color", QColor()).value<QColor>(),
                (const bool&)settings->value("alert", false).toBool(),
                (const QString&)settings->value("alertValue", "").toString(),
                (const bool&)settings->value("timer", false).toBool(),
                (const int&)settings->value("timerValue", 0).toInt(),
                (const QString&)settings->value("timerAction", "").toString(),
                (const QBitArray&)settings->value("options", QBitArray(3)).value<QBitArray>()));
    }
    settings->endArray();
    return settingsList;
}
Exemple #21
0
      void Resume(int idx)
      {
        m_resumed = true;
        _state->slots_open = QBitArray(GetGroup().Count(), false);
        _state->slots_open[idx] = true;
        _state->blogdrop_clients[idx]->GetParameters()->SetNElements(5);

        if(IsServer()) {
          _server_state->blogdrop_servers[idx]->GetParameters()->SetNElements(5);
        }

        if(idx == _state->my_idx) {
          _state->blogdrop_author->GetParameters()->SetNElements(5);
        }

        if(IsServer()) {
          ServerTestInteractive();
        } else {
          SubmitClientCiphertext();
        }
      }
Exemple #22
0
QBitArray KisChannelFlagsWidget::channelFlags() const
{
    bool allTrue = true;
    QBitArray ba(m_channelChecks.size());

    for (int i = 0; i < m_channelChecks.size(); ++i) {
        
        bool flag = m_channelChecks.at(i)->isChecked();
        if (!flag) allTrue = false;
        
        ba.setBit(i, flag);
        dbgUI << " channel " << i << " is " << flag << ", allTrue = " << allTrue << ", so ba.testBit("<<i<<")" << " is " << ba.testBit(i);
    }
    if (allTrue)
        return QBitArray();
    else {
        QBitArray result = m_colorSpace->setChannelFlagsToPixelOrder(ba);
        for (int i = 0; i < result.size(); ++i) {
            dbgUI << "On conversion to the pixel order, flag " << i << " is " << result.testBit(i);
        }
        return result;
    }
}
/**
 * Inicjalizuje mapę wartości domyślnych.
 */
void SimpleBirdSettings::initDefaults()
{
    defaults["firstRun"]                    = true;
    defaults["general/defaultDirectory"]    = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
    defaults["general/verbosity"]           = 1;
    defaults["sound/frameLength"]           = 20;
    defaults["sound/frameOverlap"]          = 0.66;
    defaults["sound/windowType"]            = "Rectangular";
    defaults["sound/windowTypeIndex"]       = 0; // rectangular
    defaults["sound/preemphasis"]           = 0.9375;
    defaults["sound/paramsPerFrame"]        = 10;
    defaults["sound/enabledFilters"]        = QBitArray(Aquila::MELFILTERS, true);
    defaults["dtw/distanceType"]            = 0; // euclidean
    defaults["dtw/normalizationType"]       = 1; // diagonal
    defaults["dtw/passType"]                = 0; // neighbors
    defaults["recognizing/minPatternSize"]  = 0.6; // 60%
    defaults["recognizing/maxPatternSize"]  = 1.4; // 140%
    defaults["charts/addOverlay"]           = true;
    defaults["charts/defaultImageFormat"]   = ".png";
    defaults["charts/drawDtwAccumulated"]   = false;
    defaults["appearance/useStylesheet"]    = true;
    defaults["appearance/stylesheet"]       = "default";
    defaults["appearance/waveformColor"]    = QColor(Qt::red);
}
Exemple #24
0
void tst_QBitArray::invertOnNull() const
{
    QBitArray a;
    QCOMPARE(a = ~a, QBitArray());
}
void KisMotionBlurFilter::process(KisPaintDeviceSP device,
                            const QRect& rect,
                            const KisFilterConfiguration* config,
                            KoUpdater* progressUpdater
                           ) const
{
    QPoint srcTopLeft = rect.topLeft();

    Q_ASSERT(device != 0);

    if (!config) config = new KisFilterConfiguration(id().id(), 1);

    QVariant value;
    config->getProperty("blurAngle", value);
    uint blurAngle = value.toUInt();
    config->getProperty("blurLength", value);
    uint blurLength = value.toUInt();
    
    if (blurLength == 0)
        return;

    QBitArray channelFlags;
    if (config) {
        channelFlags = config->channelFlags();
    } 
    if (channelFlags.isEmpty() || !config) {
        channelFlags = QBitArray(device->colorSpace()->channelCount(), true);
    }

    // convert angle to radians
    qreal angleRadians = blurAngle / 360.0 * 2 * M_PI;

    // construct image
    qreal halfWidth = blurLength / 2.0 * cos(angleRadians);
    qreal halfHeight = blurLength / 2.0 * sin(angleRadians);

    int kernelWidth = ceil(fabs(halfWidth)) * 2;
    int kernelHeight = ceil(fabs(halfHeight)) * 2;

    // check for zero dimensions (vertical/horizontal motion vectors)
    kernelWidth = (kernelWidth == 0) ? 1 : kernelWidth;
    kernelHeight = (kernelHeight == 0) ? 1 : kernelHeight;

    QImage kernelRepresentation(kernelWidth, kernelHeight, QImage::Format_RGB32);
    kernelRepresentation.fill(0);

    QPainter imagePainter(&kernelRepresentation);
    imagePainter.setRenderHint(QPainter::Antialiasing);
    imagePainter.setPen(QPen(QColor::fromRgb(255, 255, 255), 1.0));
    imagePainter.drawLine(QPointF(kernelWidth / 2 - halfWidth, kernelHeight / 2 + halfHeight), 
                          QPointF(kernelWidth / 2 + halfWidth, kernelHeight / 2 - halfHeight));

    // construct kernel from image
    Matrix<qreal, Dynamic, Dynamic> motionBlurKernel(kernelHeight, kernelWidth);
    for (int j = 0; j < kernelHeight; ++j) {
        for (int i = 0; i < kernelWidth; ++i) {
            motionBlurKernel(j, i) = qRed(kernelRepresentation.pixel(i, j));
        }
    }

    // apply convolution
    KisConvolutionPainter painter(device);
    painter.setChannelFlags(channelFlags);
    painter.setProgress(progressUpdater);

    KisConvolutionKernelSP kernel = KisConvolutionKernel::fromMatrix(motionBlurKernel, 0, motionBlurKernel.sum());
    painter.applyMatrix(kernel, device, srcTopLeft, srcTopLeft, rect.size(), BORDER_REPEAT);
}
Exemple #26
0
void TestEngine::init()
{
    QString dsn("TestEngine");
    
    // QVariant::Invalid
    // QVariant::BitArray
    setData(dsn, "QBitArray", QVariant(QBitArray(97, false)));
    // QVariant::Bitmap
    setData(dsn, "QBitmap", QVariant(QBitmap(12, 57)));
    // QVariant::Bool
    setData(dsn, "bool", QVariant((bool)true));
    // QVariant::Brush
    setData(dsn, "QBrush", QVariant(QBrush(Qt::SolidPattern)));
    // QVariant::ByteArray
    QByteArray byteArray;
    for (int i=0; i<256; ++i) {
        byteArray.append(i);
    }
    setData(dsn, "QByteArray1", QVariant(byteArray));
    setData(dsn, "QByteArray2", QVariant(QByteArray("KDE4")));
    // QVariant::Char
    setData(dsn, "QChar", QVariant(QChar(0x4B)));
    // QVariant::Color
    setData(dsn, "QColor", QVariant(QColor("#031337")));
    // QVariant::Cursor
    setData(dsn, "QCursor", QVariant(QCursor(Qt::ArrowCursor)));
    // QVariant::Date
    setData(dsn, "QDate", QVariant(QDate(2008, 1, 11)));
    // QVariant::DateTime
    setData(dsn, "QDateTime", QVariant(QDateTime(QDate(2008, 1, 11), QTime(12, 34, 56))));
    // QVariant::Double
    setData(dsn, "double", QVariant((double)12.34));
    // QVariant::Font
    setData(dsn, "QFont", QVariant(QFont()));
    // QVariant::Icon
    setData(dsn, "QIcon", QVariant(QIcon(QPixmap(12, 34))));
    // QVariant::Image
    setData(dsn, "QImage", QVariant(QImage(56, 78, QImage::Format_Mono)));
    // QVariant::Int
    setData(dsn, "int", QVariant((int)-4321));
    // QVariant::KeySequence (???)
    // QVariant::Line
    setData(dsn, "QLine", QVariant(QLine(12, 34, 56, 78)));
    // QVariant::LineF
    setData(dsn, "QLineF", QVariant(QLineF(1.2, 3.4, 5.6, 7.8)));
    // QVariant::List
    QList<QVariant> list;
    list << QString("KDE4") << QBrush() << QPen();
    setData(dsn, "QList", QVariant(list));
    // QVariant::Locale
    setData(dsn, "QLocale", QVariant(QLocale("fr_FR")));
    // QVariant::LongLong
    setData(dsn, "qlonglong", QVariant((qlonglong)-4321));
    // QVariant::Map
    QMap<QString, QVariant> map;
    for (int i=0; i<123; ++i) {
        QString key = QString("key%1").arg(i);
        QString val = QString("value%1").arg(i);
        map[key] = val;
    }
    setData(dsn, "QMap", QVariant(map));
    // QVariant::Matrix
    setData(dsn, "QMatrix", QVariant(QMatrix()));
    // QVariant::Transform
    setData(dsn, "QTransform", QVariant(QTransform()));
    // QVariant::Palette
    setData(dsn, "QPalette", QVariant(QPalette()));
    // QVariant::Pen
    setData(dsn, "QPen", QVariant(QPen(Qt::SolidLine)));
    // QVariant::Pixmap
    setData(dsn, "QPixmap", QVariant(QPixmap(12, 34)));
    // QVariant::Point
    setData(dsn, "QPoint", QVariant(QPoint(12, 34)));
    // QVariant::PointArray (obsoloted in Qt4, see QPolygon)
    // QVariant::PointF
    setData(dsn, "QPointF", QVariant(QPointF(12.34, 56.78)));
    // QVariant::Polygon
    setData(dsn, "QPolygon", QVariant(QPolygon(42)));
    // QVariant::Rect
    setData(dsn, "QRect", QVariant(QRect(12, 34, 56, 78)));
    // QVariant::RectF
    setData(dsn, "QRectF", QVariant(QRectF(1.2, 3.4, 5.6, 7.8)));
    // QVariant::RegExp
    setData(dsn, "QRegExp", QVariant(QRegExp("^KDE4$")));
    // QVariant::Region
    setData(dsn, "QRegion", QVariant(QRegion(10, 20, 30, 40)));
    // QVariant::Size
    setData(dsn, "QSize", QVariant(QSize(12, 34)));
    // QVariant::SizeF
    setData(dsn, "QSizeF", QVariant(QSizeF(12.34, 56.78)));
    // QVariant::SizePolicy
    setData(dsn, "QSizePolicy", QVariant(QSizePolicy()));
    // QVariant::String
    setData(dsn, "QString", QVariant(QString("KDE4 ROCKS!")));
    // QVariant::StringList
    QStringList stringList;
    stringList << "K" << "D" << "E" << "4";
    setData(dsn, "QStringList", QVariant(stringList));
    // QVariant::TextFormat
    setData(dsn, "QTextFormat", QVariant(QTextFormat()));
    // QVariant::TextLength
    setData(dsn, "QTextLength", QVariant(QTextLength()));
    // QVariant::Time
    setData(dsn, "QTime", QVariant(QTime(12, 34, 56)));
    // QVariant::UInt
    setData(dsn, "uint", QVariant((uint)4321));
    // QVariant::ULongLong
    setData(dsn, "qulonglong", QVariant((qulonglong)4321));
    // QVariant::Url
    setData(dsn, "QUrl", QVariant(QUrl("http://*****:*****@example.com:80/test.php?param1=foo&param2=bar")));
    // QVariant::UserType
    MyUserType userType;
    QVariant v;
    v.setValue(userType);
    setData(dsn, "UserType", v);
}; // init()
FlagArray::FlagArray(){
    m_df = 0;
    m_flags = QBitArray(0);
}
Exemple #28
0
void KisImagePyramid::retrieveImageData(const QRect &rect)
{
    // XXX: use QThreadStorage to cache the two patches (512x512) of pixels. Note
    // that when we do that, we need to reset that cache when the projection's
    // colorspace changes.
    const KoColorSpace *projectionCs = m_originalImage->projection()->colorSpace();
    KisPaintDeviceSP originalProjection = m_originalImage->projection();
    quint32 numPixels = rect.width() * rect.height();

    QScopedArrayPointer<quint8> originalBytes(
        new quint8[originalProjection->colorSpace()->pixelSize() * numPixels]);

    originalProjection->readBytes(originalBytes.data(), rect);

    if (m_displayFilter &&
        m_useOcio &&
        projectionCs->colorModelId() == RGBAColorModelID) {

#ifdef HAVE_OCIO
        const KoColorProfile *destinationProfile =
            m_displayFilter->useInternalColorManagement() ?
            m_monitorProfile : projectionCs->profile();

        const KoColorSpace *floatCs =
            KoColorSpaceRegistry::instance()->colorSpace(
                RGBAColorModelID.id(),
                Float32BitsColorDepthID.id(),
                destinationProfile);

        const KoColorSpace *modifiedMonitorCs =
            KoColorSpaceRegistry::instance()->colorSpace(
                RGBAColorModelID.id(),
                Integer8BitsColorDepthID.id(),
                destinationProfile);

        if (projectionCs->colorDepthId() == Float32BitsColorDepthID) {
            m_displayFilter->filter(originalBytes.data(), numPixels);
        } else {
            QScopedArrayPointer<quint8> dst(new quint8[floatCs->pixelSize() * numPixels]);
            projectionCs->convertPixelsTo(originalBytes.data(), dst.data(), floatCs, numPixels, KoColorConversionTransformation::InternalRenderingIntent, KoColorConversionTransformation::InternalConversionFlags);
            m_displayFilter->filter(dst.data(), numPixels);
            originalBytes.swap(dst);
        }

        {
            QScopedArrayPointer<quint8> dst(new quint8[modifiedMonitorCs->pixelSize() * numPixels]);
            floatCs->convertPixelsTo(originalBytes.data(), dst.data(), modifiedMonitorCs, numPixels, KoColorConversionTransformation::InternalRenderingIntent, KoColorConversionTransformation::InternalConversionFlags);
            originalBytes.swap(dst);
        }
#endif
    }
    else {
        QList<KoChannelInfo*> channelInfo = projectionCs->channels();
        if (!m_channelFlags.size() == channelInfo.size()) {
            setChannelFlags(QBitArray());
        }
        if (!m_channelFlags.isEmpty() && !m_allChannelsSelected) {
            QScopedArrayPointer<quint8> dst(new quint8[projectionCs->pixelSize() * numPixels]);

            int channelSize = channelInfo[m_selectedChannelIndex]->size();
            int pixelSize = projectionCs->pixelSize();

            KisConfig cfg;

            if (m_onlyOneChannelSelected && !cfg.showSingleChannelAsColor()) {
                int selectedChannelPos = channelInfo[m_selectedChannelIndex]->pos();
                for (uint pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex) {
                    for (uint channelIndex = 0; channelIndex < projectionCs->channelCount(); ++channelIndex) {

                        if (channelInfo[channelIndex]->channelType() == KoChannelInfo::COLOR) {
                            memcpy(dst.data() + (pixelIndex * pixelSize) + (channelIndex * channelSize),
                                   originalBytes.data() + (pixelIndex * pixelSize) + selectedChannelPos,
                                   channelSize);
                        }
                        else if (channelInfo[channelIndex]->channelType() == KoChannelInfo::ALPHA) {
                            memcpy(dst.data() + (pixelIndex * pixelSize) + (channelIndex * channelSize),
                                   originalBytes.data()  + (pixelIndex * pixelSize) + (channelIndex * channelSize),
                                   channelSize);
                        }
                    }
                }
            }
            else {
                for (uint pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex) {
                    for (uint channelIndex = 0; channelIndex < projectionCs->channelCount(); ++channelIndex) {
                        if (m_channelFlags.testBit(channelIndex)) {
                            memcpy(dst.data() + (pixelIndex * pixelSize) + (channelIndex * channelSize),
                                   originalBytes.data()  + (pixelIndex * pixelSize) + (channelIndex * channelSize),
                                   channelSize);
                        }
                        else {
                            memset(dst.data() + (pixelIndex * pixelSize) + (channelIndex * channelSize), 0, channelSize);
                        }
                    }
                }

            }
            originalBytes.swap(dst);
        }

        QScopedArrayPointer<quint8> dst(new quint8[m_monitorColorSpace->pixelSize() * numPixels]);
        projectionCs->convertPixelsTo(originalBytes.data(), dst.data(), m_monitorColorSpace, numPixels, m_renderingIntent, m_conversionFlags);
        originalBytes.swap(dst);
    }

    m_pyramid[ORIGINAL_INDEX]->writeBytes(originalBytes.data(), rect);
}
/*! \internal

  If \a confirm is true, all edit operations (inserts, updates and
  deletes) will be confirmed by the user.  If \a confirm is false (the
  default), all edits are posted to the database immediately.

*/
void Q3DataManager::setConfirmEdits(bool confirm)
{
    d->confEdits = QBitArray(d->confEdits.size(), confirm);
}
void KisGaussianBlurFilter::process(KisPaintDeviceSP device,
                            const QRect& rect,
                            const KisFilterConfiguration* config,
                            KoUpdater* progressUpdater
                           ) const
{
    QPoint srcTopLeft = rect.topLeft();

    Q_ASSERT(device != 0);

    if (!config) config = new KisFilterConfiguration(id().id(), 1);

    QVariant value;
    config->getProperty("horizRadius", value);
    uint horizontalRadius = value.toUInt();
    config->getProperty("vertRadius", value);
    uint verticalRadius = value.toUInt();

    QBitArray channelFlags;
    if (config) {
        channelFlags = config->channelFlags();
    } 
    if (channelFlags.isEmpty() || !config) {
        channelFlags = QBitArray(device->colorSpace()->channelCount(), true);
    }

    // compute horizontal kernel
    uint horizKernelSize = horizontalRadius * 2 + 1;
    Matrix<qreal, Dynamic, Dynamic> horizGaussian(1, horizKernelSize);

    qreal horizSigma = horizontalRadius;
    const qreal horizMultiplicand = 1 / (2 * M_PI * horizSigma * horizSigma);
    const qreal horizExponentMultiplicand = 1 / (2 * horizSigma * horizSigma);

    for (uint x = 0; x < horizKernelSize; x++)
    {
        uint xDistance = qAbs((int)horizontalRadius - (int)x);
        horizGaussian(0, x) = horizMultiplicand * exp( -(qreal)((xDistance * xDistance) + (horizontalRadius * horizontalRadius)) * horizExponentMultiplicand );
    }

    // compute vertical kernel
    uint verticalKernelSize = verticalRadius * 2 + 1;
    Matrix<qreal, Dynamic, Dynamic> verticalGaussian(verticalKernelSize, 1);

    qreal verticalSigma = verticalRadius;
    const qreal verticalMultiplicand = 1 / (2 * M_PI * verticalSigma * verticalSigma);
    const qreal verticalExponentMultiplicand = 1 / (2 * verticalSigma * verticalSigma);

    for (uint y = 0; y < verticalKernelSize; y++)
    {
        uint yDistance = qAbs((int)verticalRadius - (int)y);
        verticalGaussian(y, 0) = verticalMultiplicand * exp( -(qreal)((yDistance * yDistance) + (verticalRadius * verticalRadius)) * verticalExponentMultiplicand );
    }

    if ( (horizontalRadius > 0) && (verticalRadius > 0) )
    {
        KisPaintDeviceSP interm = new KisPaintDevice(device->colorSpace());

        KisConvolutionKernelSP kernelHoriz = KisConvolutionKernel::fromMatrix(horizGaussian, 0, horizGaussian.sum());
        KisConvolutionKernelSP kernelVertical = KisConvolutionKernel::fromMatrix(verticalGaussian, 0, verticalGaussian.sum());

        KisConvolutionPainter horizPainter(interm);
        horizPainter.setChannelFlags(channelFlags);
        horizPainter.setProgress(progressUpdater);
        horizPainter.applyMatrix(kernelHoriz, device, 
                                 srcTopLeft - QPoint(0, verticalRadius), 
                                 srcTopLeft - QPoint(0, verticalRadius), 
                                 rect.size() + QSize(0, 2 * verticalRadius), BORDER_REPEAT);
        
        
        KisConvolutionPainter verticalPainter(device);
        verticalPainter.setChannelFlags(channelFlags);
        verticalPainter.setProgress(progressUpdater);
        verticalPainter.applyMatrix(kernelVertical, interm, srcTopLeft, srcTopLeft, rect.size(), BORDER_REPEAT);
    }
    else
    {
        if (horizontalRadius > 0)
        {
            KisConvolutionPainter painter(device);
            painter.setChannelFlags(channelFlags);
            painter.setProgress(progressUpdater);

            KisConvolutionKernelSP kernelHoriz = KisConvolutionKernel::fromMatrix(horizGaussian, 0, horizGaussian.sum());
            painter.applyMatrix(kernelHoriz, device, srcTopLeft, srcTopLeft, rect.size(), BORDER_REPEAT);
        }

        if (verticalRadius > 0)
        {
            KisConvolutionPainter painter(device);
            painter.setChannelFlags(channelFlags);
            painter.setProgress(progressUpdater);

            KisConvolutionKernelSP kernelVertical = KisConvolutionKernel::fromMatrix(verticalGaussian, 0, verticalGaussian.sum());
            painter.applyMatrix(kernelVertical, device, srcTopLeft, srcTopLeft, rect.size(), BORDER_REPEAT);
        }
    }
}