Beispiel #1
0
static void devectorizeARGB(const ImageContainer& srcImages, const QVector<Vec<16>>& vectors, const VectorQuantizer<16>& vq, int format, QVector<QImage>& indexedImages, QVector<quint64>& codebook) {
	int vindex = 0;

	for (int i=0; i<srcImages.imageCount(); i++) {
		const QSize size = srcImages.getByIndex(i).size();
		if (size.width() == 1 || size.height() == 1)
			continue;
		QImage img(size.width()/2, size.height()/2, QImage::Format_Indexed8);
		img.setColorCount(256);
		for (int y=0; y<img.height(); y++) {
			for (int x=0; x<img.width(); x++) {
				const Vec<16>& vec = vectors[vindex];
				int codeIndex = vq.findClosest(vec);
				img.setPixel(x, y, codeIndex);
				vindex++;
			}
		}
		indexedImages.push_back(img);
	}

	for (int i=0; i<vq.codeCount(); i++) {
		const Vec<16>& vec = vq.codeVector(i);
		QColor tl = QColor::fromRgbF(vec[1], vec[2], vec[3], vec[0]);
		QColor tr = QColor::fromRgbF(vec[5], vec[6], vec[7], vec[4]);
		QColor bl = QColor::fromRgbF(vec[9], vec[10], vec[11], vec[8]);
		QColor br = QColor::fromRgbF(vec[13], vec[14], vec[15], vec[12]);
		quint64 quad = packQuad(tl.rgba(), tr.rgba(), bl.rgba(), br.rgba(), format);
		codebook.push_back(quad);
	}
}
Beispiel #2
0
void tst_QVolatileImage::fill()
{
    QVolatileImage img(100, 100, QImage::Format_ARGB32_Premultiplied);
    QColor col = QColor(10, 20, 30);
    img.fill(col.rgba());
    QVERIFY(img.imageRef().pixel(1, 1) == col.rgba());
    QVERIFY(img.toImage().pixel(1, 1) == col.rgba());
}
Beispiel #3
0
BitmapImage::BitmapImage(const QRect& rectangle, const QColor& colour)
{
    mBounds = rectangle;
    mImage = std::make_shared<QImage>(mBounds.size(), QImage::Format_ARGB32_Premultiplied);
    mImage->fill(colour.rgba());
    mMinBound = false;
}
QImage HistogramGenerator::drawComponent(const int *y, const QSize &size, const float &scaling, const QColor &color,
                                         const bool &unscaled, const uint &max) const
{
    QImage component(max, size.height(), QImage::Format_ARGB32);
    component.fill(qRgba(0, 0, 0, 0));
    Q_ASSERT(scaling != INFINITY);

    const int partH = size.height();
    int partY;

    for (uint x = 0; x < max; x++) {
        // Calculate the height of the curve at position x
        partY = scaling*y[x];

        // Invert the y axis
        if (partY > partH-1) { partY = partH-1; }
        partY = partH-1 - partY;

        for (int k = partH-1; k >= partY; k--) {
            component.setPixel(x, k, color.rgba());
        }
    }
    if (unscaled && size.width() >= component.width()) {
        return component;
    } else {
        return component.scaled(size, Qt::IgnoreAspectRatio, Qt::FastTransformation);
    }
}
void QPdfEngine::setBrush()
{
    Q_D(QPdfEngine);
    Qt::BrushStyle style = d->brush.style();
    if (style == Qt::NoBrush)
        return;

    bool specifyColor;
    int gStateObject = 0;
    int patternObject = d->addBrushPattern(d->stroker.matrix, &specifyColor, &gStateObject);

    *d->currentPage << (patternObject ? "/PCSp cs " : "/CSp cs ");
    if (specifyColor) {
        QColor rgba = d->brush.color();
        if (d->colorMode == QPrinter::GrayScale) {
            qreal gray = qGray(rgba.rgba())/255.;
            *d->currentPage << gray << gray << gray;
        } else {
            *d->currentPage << rgba.redF()
                            << rgba.greenF()
                            << rgba.blueF();
        }
    }
    if (patternObject)
        *d->currentPage << "/Pat" << patternObject;
    *d->currentPage << "scn\n";

    if (gStateObject)
        *d->currentPage << "/GState" << gStateObject << "gs\n";
    else
        *d->currentPage << "/GSa gs\n";
}
void KermitScreen::solidFill(const QColor &color, const QRegion &region)
{
    //qDebug("KermitScreen::solidFill  ");
    if (depth() != 8)
    {
        qWarning("Fallback to QScreen as the depth is not 8 %d", depth());
        QScreen::solidFill(color, region);
        return;
    }

    unsigned char *base = QScreen::data;
    if (base == 0)
    {
        qWarning("Framebuffer is empty.");
        return;
    }

    unsigned char gray = (qGray(color.rgba()) & 0xff);
    const QVector<QRect> rects = region.rects();
    for (int i = 0; i < rects.size(); ++i)
    {
        const QRect r = rects.at(i);

        for(int y = r.top(); y < r.top() + r.height(); ++y)
        {
            unsigned char *p = base + y * QScreen::w + r.left();
            memset(p, r.width(), gray);
        }
    }
    // qDebug("KermitScreen::solidFill done");
}
Beispiel #7
0
uint QColormap::pixel(const QColor &color) const
{
    QRgb rgb = color.rgba();
    if (d->mode == QColormap::Direct) {
        switch(d->depth) {
        case 16:
            return qt_convRgbTo16(rgb);
        case 24:
        case 32:
        {
            const int r = qRed(rgb);
            const int g = qGreen(rgb);
            const int b = qBlue(rgb);
            const int red_shift = 16;
            const int green_shift = 8;
            const int red_mask   = 0xff0000;
            const int green_mask = 0x00ff00;
            const int blue_mask  = 0x0000ff;
            const int tg = g << green_shift;
#ifdef QT_QWS_DEPTH_32_BGR
            if (qt_screen->pixelType() == QScreen::BGRPixel) {
                const int tb = b << red_shift;
                return 0xff000000 | (r & blue_mask) | (tg & green_mask) | (tb & red_mask);
            }
#endif
            const int tr = r << red_shift;
            return 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask);
        }
        }
    }
    return qt_screen->alloc(qRed(rgb), qGreen(rgb), qBlue(rgb));
}
void RedEyeReductionImageOperation::apply(QImage* img, const QRectF& rectF)
{
    const QRect rect = PaintUtils::containingRect(rectF);
    const qreal radius = rectF.width() / 2;
    const qreal centerX = rectF.x() + radius;
    const qreal centerY = rectF.y() + radius;
    const Ramp radiusRamp(qMin(double(radius * 0.7), double(radius - 1)), radius, 1., 0.);

    uchar* line = img->scanLine(rect.top()) + rect.left() * 4;
    for (int y = rect.top(); y < rect.bottom(); ++y, line += img->bytesPerLine()) {
        QRgb* ptr = (QRgb*)line;

        for (int x = rect.left(); x < rect.right(); ++x, ++ptr) {
            const qreal currentRadius = sqrt(pow(y - centerY, 2) + pow(x - centerX, 2));
            qreal alpha = radiusRamp(currentRadius);
            if (qFuzzyCompare(alpha, 0)) {
                continue;
            }

            const QColor src(*ptr);
            alpha *= computeRedEyeAlpha(src);
            int r = src.red();
            int g = src.green();
            int b = src.blue();
            QColor dst;
            // Replace red with green, and blend according to alpha
            dst.setRed(int((1 - alpha) * r + alpha * g));
            dst.setGreen(int((1 - alpha) * g + alpha * g));
            dst.setBlue(int((1 - alpha) * b + alpha * b));
            *ptr = dst.rgba();
        }
    }
}
Beispiel #9
0
QImage QtNativeFont::nativeFontRasterize(String const &text,
                                         Vector4ub const &foreground,
                                         Vector4ub const &background) const
{
#ifdef LIBGUI_ACCURATE_TEXT_BOUNDS
    Rectanglei const bounds = measure(text);
#else
    Rectanglei const bounds(Vector2i(0, -d->metrics->ascent()),
                            Vector2i(d->metrics->width(text),
                                     d->metrics->descent()));
#endif

    QColor const fgColor(foreground.x, foreground.y, foreground.z, foreground.w);
    QColor const bgColor(background.x, background.y, background.z, background.w);

    QImage img(QSize(bounds.width() + 1, bounds.height() + 1),
               QImage::Format_ARGB32);

    img.fill(bgColor.rgba());

    QPainter painter(&img);
    painter.setCompositionMode(QPainter::CompositionMode_Source);

    painter.setFont(d->font);
    painter.setPen(fgColor);
    painter.setBrush(bgColor);
    painter.drawText(-bounds.left(), -bounds.top(), text);

    return img;
}
Beispiel #10
0
void QGstreamerVideoWindow::setColorKey(const QColor &color)
{
    m_colorKey = color;

    if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "colorkey"))
        g_object_set(G_OBJECT(m_videoSink), "colorkey", color.rgba(), NULL);
}
Beispiel #11
0
void QGLPixmapData::fill(const QColor &color)
{
    if (!isValid())
        return;

    bool hasAlpha = color.alpha() != 255;
    if (hasAlpha && !m_hasAlpha) {
        if (m_texture.id) {
            destroyTexture();
            m_dirty = true;
        }
        m_hasAlpha = color.alpha() != 255;
    }

    if (useFramebufferObjects()) {
        m_source = QVolatileImage();
        m_hasFillColor = true;
        m_fillColor = color;
    } else {
        forceToImage();

        if (m_source.depth() == 32) {
            m_source.fill(PREMUL(color.rgba()));

        } else if (m_source.depth() == 1) {
            if (color == Qt::color1)
                m_source.fill(1);
            else
                m_source.fill(0);
        }
    }
}
Beispiel #12
0
void Tile::fillColor(const QColor& color)
{
	const quint32 c = color.rgba();
	quint32 *ptr = getOrCreateUninitializedData();
	for(int i=0;i<LENGTH;++i)
		*(ptr++) = c;
}
Beispiel #13
0
/**
 * @param values array of alpha values
 * @param color composite color
 * @param x offset in the tile
 * @param y offset in the tile
 * @param w values in tile (must be < SIZE)
 * @param h values in tile (must be < SIZE)
 * @param skip values to skip to reach the next line
 */
void Tile::composite(int mode, const uchar *values, const QColor& color, int x, int y, int w, int h, int skip)
{
	Q_ASSERT(x>=0 && x<SIZE && y>=0 && y<SIZE);
	Q_ASSERT((x+w)<=SIZE && (y+h)<=SIZE);
	compositeMask(mode, getOrCreateData() + y * SIZE + x,
			color.rgba(), values, w, h, skip, SIZE-w);
}
Beispiel #14
0
QImage edge_detector::smoothImage(const QImage image)
{
    QImage destImage = QImage( image);
    QColor qc;
    int Gauss[5][5] = {{2, 4, 5, 4, 2}, {4, 9, 12, 9, 4}, {5, 12, 15, 12, 5},
                       {4, 9, 12, 9, 4}, {2, 4, 5, 4, 2}};

    int **G = new int*[5];
    for (int i=0; i<5; i++)
    {
        G[i] = new int[5];
        for(int j=0; j<5; j++)
            G[i][j] = Gauss[i][j];
    }

    int H = image.height();
    int W = image.width();

    int* destData= (int *)destImage.bits();

    int **a, smooth;
    for (int y=2; y<H-2; y++)
    {
        for (int x=2; x<W-2; x++)
        {
            a = get_neighbor_pixels(image, x, y, 2);
            smooth = convolve(a, G, 5) / 159.f;
            deleteArray(a, 5); //2*2+1

            qc.setRgb(smooth, smooth, smooth);
            destData[x + y*W] = qc.rgba();
        }
    }
    return destImage;
}
Beispiel #15
0
void QBlittablePlatformPixmap::fill(const QColor &color)
{
    if (blittable()->capabilities() & QBlittable::AlphaFillRectCapability) {
        blittable()->unlock();
        blittable()->alphaFillRect(QRectF(0,0,w,h),color,QPainter::CompositionMode_Source);
    } else if (color.alpha() == 255 && blittable()->capabilities() & QBlittable::SolidRectCapability) {
        blittable()->unlock();
        blittable()->fillRect(QRectF(0,0,w,h),color);
    } else {
        // Need to be backed with an alpha channel now. It would be nice
        // if we could just change the format, e.g. when going from
        // RGB32 -> ARGB8888.
        if (color.alpha() != 255 && !hasAlphaChannel()) {
            m_blittable.reset(0);
            m_engine.reset(0);
            m_alpha = true;
        }

        uint pixel = PREMUL(color.rgba());
        const QPixelLayout *layout = &qPixelLayouts[blittable()->lock()->format()];
        Q_ASSERT(layout->convertFromARGB32PM);
        layout->convertFromARGB32PM(&pixel, &pixel, 1, layout, 0);

        //so premultiplied formats are supported and ARGB32 and RGB32
        blittable()->lock()->fill(pixel);
    }

}
Beispiel #16
0
BitmapImage::BitmapImage(QRect rectangle, QColor colour)
{
    mBounds = rectangle;
    mImage = new QImage( mBounds.size(), QImage::Format_ARGB32_Premultiplied);
    mImage->fill(colour.rgba());
    mExtendable = true;
}
Beispiel #17
0
static void qt_plastique_draw_handle(QPainter *painter, const QStyleOption *option,
                                     const QRect &rect, Qt::Orientation orientation,
                                     const QWidget *widget)
{
    QColor borderColor = option->palette.background().color().darker(178);
    QColor alphaCornerColor;
    if (widget) {
        // ### backgroundrole/foregroundrole should be part of the style option
        alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
    } else {
        alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
    }
	
    QImage handle(qt_simple_toolbarhandle);
    handle.setColor(1, alphaCornerColor.rgba());
    handle.setColor(2, mergedColors(alphaCornerColor, option->palette.base().color()).rgba());
    handle.setColor(3, option->palette.base().color().rgba());
	
    const int spacing = 2;
	
    if (orientation == Qt::Vertical) {
        int nchunks = rect.width() / (handle.width() + spacing);
        for (int i = 0; i < nchunks; ++i)
            painter->drawImage(QPoint(rect.left() + i * (handle.width() + spacing), rect.top()), handle);
    } else {
        int nchunks = rect.height() / (handle.height() + spacing);
        for (int i = 0; i < nchunks; ++i)
            painter->drawImage(QPoint(rect.left(), rect.top() + i * (handle.height() + spacing)), handle);
    }
}
Beispiel #18
0
void QAhiScreen::solidFill(const QColor &color, const QRegion &reg)
{
    AhiSts_t status = AhiStsOk;

    switch (pixelFormat()) {
    case QImage::Format_ARGB32_Premultiplied:
    case QImage::Format_ARGB32:
    case QImage::Format_RGB32:
        status = AhiDrawBrushFgColorSet(d_ptr->context, color.rgba());
        break;
    case QImage::Format_RGB16:
        status = AhiDrawBrushFgColorSet(d_ptr->context, qt_convRgbTo16(color.rgb()));
        break;
    default:
        qFatal("QAhiScreen::solidFill(): Not implemented for pixel format %d",
               int(pixelFormat()));
        break;
    }

    if (status != AhiStsOk) {
        qWarning("QAhiScreen::solidFill(): AhiDrawBrushFgColorSet failed: %x",
                 status);
        return;
    }

    status = AhiDrawBrushSet(d_ptr->context, 0, 0, 0, AHIFLAG_BRUSHSOLID);
    if (status != AhiStsOk) {
        qWarning("QAhiScreen::solidFill(): AhiDrawBrushSet failed: %x",
                 status);
        return;
    }

    status = AhiDrawRopSet(d_ptr->context, AHIMAKEROP3(AHIROPPATCOPY));
    if (status != AhiStsOk) {
        qWarning("QAhiScreen::solidFill(): AhiDrawRopSet failed: %x", status);
        return;
    }

    status = AhiDrawSurfDstSet(d_ptr->context, d_ptr->surface, 0);
    if (status != AhiStsOk) {
        qWarning("QAhiScreen::solidFill(): AhiDrawSurfDst failed: %x", status);
        return;
    }

    const QVector<QRect> rects = (reg & region()).rects();
    QVarLengthArray<AhiRect_t> ahiRects(rects.size());

    for (int i = 0; i < rects.size(); ++i) {
        const QRect rect = rects.at(i);
        ahiRects[i].left = rect.left();
        ahiRects[i].top = rect.top();
        ahiRects[i].right = rect.x() + rect.width();
        ahiRects[i].bottom = rect.y() + rect.height();
    }

    status = AhiDrawBitBltMulti(d_ptr->context, ahiRects.data(),
                                0, ahiRects.size());
    if (status != AhiStsOk)
        qWarning("QAhiScreen::solidFill(): AhiDrawBitBlt failed: %x", status);
}
Beispiel #19
0
QPixmap
IconLoader::invert(QPixmap pmap)
{
    QImage img = pmap.toImage().convertToFormat(QImage::Format_ARGB32);

    for (int y = 0; y < img.height(); ++y) {
        for (int x = 0; x < img.width(); ++x) {

            QRgb rgba = img.pixel(x, y);
            QColor colour = QColor
                (qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));

            int alpha = colour.alpha();
            if (colour.saturation() < 5 && colour.alpha() > 10) {
                colour.setHsv(colour.hue(),
                              colour.saturation(),
                              255 - colour.value());
                colour.setAlpha(alpha);
                img.setPixel(x, y, colour.rgba());
            }
        }
    }

    pmap = QPixmap::fromImage(img);
    return pmap;
}
void GLWidget::SetImage(int width, int height, std::vector<QColor> colorList)
{
	//textEdit->append("width :" + QString::number(width));
	//textEdit->append("height :" + QString::number(height));
	//textEdit->append("colorList size :" + QString::number(colorList.size()));

	bool isLoaded = true;
	_imgOriginal = QImage(width, height, QImage::Format_RGB32);

	// size
	this->_img_width = _imgOriginal.width();
	this->_img_height = _imgOriginal.height();

	for (int x = 0; x < this->_img_width; x++)
	{
		for (int y = 0; y < this->_img_height; y++)
		{
			//int idx = x + y * this->_img_width;
			//QColor col = colorList[idx];
			//QColor col = QColor(0, 255, 0, 255);
			QColor col = QColor(rand() % 255, rand() % 255, rand() % 255, 255);
			_imgOriginal.setPixel(x, y, col.rgba());
		}
	}

	// calculating power-of-two (pow) size
	int xpow = (int)std::pow(2.0, std::ceil(std::log10((double)_img_width) / std::log10(2.0)));
	int ypow = (int)std::pow(2.0, std::ceil(std::log10((double)_img_height) / std::log10(2.0)));

	xpow = my_max(xpow, ypow);	// the texture should be square too
	xpow = my_min(xpow, 1024);	// shrink if the size is too big
	ypow = xpow;

	// transform the image to square pow size
	_imgGL = _imgOriginal.scaled(xpow, ypow, Qt::IgnoreAspectRatio);
	_imgGL = QGLWidget::convertToGLFormat(_imgGL);

	_imgID = 0;

	glBindTexture(GL_TEXTURE_2D, 0); // I just want to make sure...
	//glEnable(GL_TEXTURE_2D); // should I have this ?

	glGenTextures(1, &_imgID);

	if (!_imgID)
	{
		//glGetError 1282 ???
		textEdit->append("glGetError :" + QString::number(glGetError()));
	}

	glBindTexture(GL_TEXTURE_2D, _imgID);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _imgGL.width(), _imgGL.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, _imgGL.bits());

	//glDisable(GL_TEXTURE_2D);  // should I have this ?
	//textEdit->append("_imgID :" + QString::number(_imgID));
}
Beispiel #21
0
void ColorPaletteWidget::clickAddColorButton()
{
    QColor prevColor = Qt::white;

    if ( currentColourNumber() > -1 )
    {
        prevColor = core()->object()->getColour(currentColourNumber()).colour;
    }

    bool ok;
    QRgb qrgba = QColorDialog::getRgba( prevColor.rgba(), &ok, this );
    if ( ok )
    {
        ColourRef ref = ColourRef(QColor::fromRgba(qrgba));
        bool ok;
        QString text = QInputDialog::getText(this,
            tr("Colour name"),
            tr("Colour name:"),
            QLineEdit::Normal,
            QString(tr("Colour %1")).arg( ui->colorListWidget->count()),
            &ok );
        if (ok)
        {
            ref.name = text;
            core()->object()->addColour(ref);
            refreshColorList();
            core()->color()->setColor( core()->object()->getColourCount() - 1 );
        }
    }
}
Beispiel #22
0
QImage edge_detector::double_thresholding(const QImage image)
{
    QImage destImage = QImage( image);
    QColor qc;

    int T1 = 16;
    int T2 = 12;

    int H = image.height();
    int W = image.width();

    for (int i=0; i<H; i++)
        for (int j=0; j<W; j++)
        {
            qc = ((QColor)image.pixel(j, i));
            int lightness = qc.lightness();
            int r = qc.red(), g = qc.green(), b = qc.blue();

            if (lightness > 200 || lightness < T2)
            {
                qc.setRgb(0, 0, 0);
            }
            else if (lightness > T1)
            {                
                qc.setRgb(255, 255, 255);
            }
            else
            {
                qc.setRgb(r?255:0, g?255:0, b?255:0);
            }
            destImage.setPixel( j, i, qc.rgba());
        }
    return destImage;
}
Beispiel #23
0
void Tile::fillChecker(quint32 *data, const QColor& dark, const QColor& light)
{
	const int HALF = SIZE/2;
	quint32 d = dark.rgba();
	quint32 l = light.rgba();
	quint32 *q1 = data, *q2 = data+HALF, *q3 = data + SIZE*HALF, *q4 = data + SIZE*(HALF)+HALF;
	for(int y=0;y<HALF;++y) {
		for(int x=0;x<HALF;++x) {
			*(q1++) = d;
			*(q2++) = l;
			*(q3++) = l;
			*(q4++) = d;
		}
		q1 += HALF; q2 += HALF; q3 += HALF; q4 += HALF;
	}
}
Beispiel #24
0
void QRasterPlatformPixmap::fill(const QColor &color)
{
    uint pixel;

    if (image.depth() == 1) {
        int gray = qGray(color.rgba());
        // Pick the best approximate color in the image's colortable.
        if (qAbs(qGray(image.color(0)) - gray) < qAbs(qGray(image.color(1)) - gray))
            pixel = 0;
        else
            pixel = 1;
    } else if (image.depth() >= 15) {
        int alpha = color.alpha();
        if (alpha != 255) {
            if (!image.hasAlphaChannel()) {
                QImage::Format toFormat;
#if !(defined(__ARM_NEON__) || defined(__SSE2__))
                if (image.format() == QImage::Format_RGB16)
                    toFormat = QImage::Format_ARGB8565_Premultiplied;
                else if (image.format() == QImage::Format_RGB666)
                    toFormat = QImage::Format_ARGB6666_Premultiplied;
                else if (image.format() == QImage::Format_RGB555)
                    toFormat = QImage::Format_ARGB8555_Premultiplied;
                else if (image.format() == QImage::Format_RGB444)
                    toFormat = QImage::Format_ARGB4444_Premultiplied;
                else
#endif
                    toFormat = QImage::Format_ARGB32_Premultiplied;

                if (!image.isNull() && qt_depthForFormat(image.format()) == qt_depthForFormat(toFormat)) {
                    image.detach();
                    image.d->format = toFormat;
                } else {
                    image = QImage(image.width(), image.height(), toFormat);
                }
            }
        }
        pixel = qPremultiply(color.rgba());
        const QPixelLayout *layout = &qPixelLayouts[image.format()];
        layout->convertFromARGB32PM(&pixel, &pixel, 1, layout, 0);
    } else {
        pixel = 0;
        // ### what about 8 bits
    }

    image.fill(pixel);
}
Beispiel #25
0
QImage edge_detector::detectEdgeImage(const QImage image, int kernel)
{
    QImage destImage = QImage( image);
    QRect rect = image.rect();
    QColor qc;

    int H = rect.height();
    int W = rect.width();
    int **a;
    qreal gradient, gangle;

    int r, g, b;
    int maxg(0);

    for (int y=0; y<H; y++) // y=1; y<H-1;
    {
        for (int x=0; x<W; x++) // x=1; x<W-1;
        {
            a = get_neighbor_pixels(image, x, y, 1, true);
            edge_detect(a, kernel, &gradient, &gangle);
            deleteArray(a, 3); //size of array allocated by get_neighbor_pixels is 3x3, 3 = (range=1)*2+1

            if ((gangle >= -22.5 && gangle < 22.5) || (gangle >= 157.5 || gangle < -157.5))
            {
                r = 0;
                g = 0;
                b = 255;
            }
            else if ((gangle >= 22.5 && gangle < 67.5) || (gangle <= -112.5 && gangle > -157.5))
            {
                r = 0;
                g = 255;
                b = 0;
            }
            else if ((gangle >= 67.5 && gangle < 112.5) || (gangle <= -67.5 && gangle > -112.5))
            {
                r = 255;
                g = 255;
                b = 0;
            }
            else if ((gangle >= 112.5 && gangle < 157.5) || (gangle <= -22.5 && gangle > -67.5))
            {
                r = 255;
                g = 0;
                b = 0;
            }

            if (gradient > maxg)
                maxg = gradient;

            qc.setRgb((int)gradient & r, (int)gradient & g, (int)gradient & b);

            destImage.setPixel( x, y, qc.rgba());
        }
    }

    //printf("gangle = %f, maxg = %d\n", gangle, maxg);
    return destImage;
}
Beispiel #26
0
BitmapImage::BitmapImage(Object* parent, QRect rectangle, QColor colour)
{
    myParent = parent;
    boundaries = rectangle;
    image = new QImage( boundaries.size(), QImage::Format_ARGB32_Premultiplied);
    image->fill(colour.rgba());
    extendable = true;
}
Beispiel #27
0
// protected virtual [base QWidget]
void kpDualColorButton::dropEvent (QDropEvent *e)
{
    QColor col = KColorMimeData::fromMimeData (e->mimeData ());
#if DEBUG_KP_DUAL_COLOR_BUTTON
    qCDebug(kpLogWidgets) << "kpDualColorButton::dropEvent() col="
              << (int *) col.rgba()
              << " (with alpha=" << (int *) col.rgba () << ")" << endl;
#endif

    if (col.isValid ())
    {
        if (foregroundRect ().contains (e->pos ()))
            setForegroundColor (kpColor (col.rgba()));
        else if (backgroundRect ().contains (e->pos ()))
            setBackgroundColor (kpColor (col.rgba()));
    }
}
Beispiel #28
0
void QVGPixmapData::fill(const QColor &color)
{
    if (!isValid())
        return;
    forceToImage();
    if (source.depth() == 1) {
        // Pick the best approximate color in the image's colortable.
        int gray = qGray(color.rgba());
        if (qAbs(qGray(source.imageRef().color(0)) - gray)
            < qAbs(qGray(source.imageRef().color(1)) - gray))
            source.fill(0);
        else
            source.fill(1);
    } else {
        source.fill(PREMUL(color.rgba()));
    }
}
Beispiel #29
0
Tile::Tile(const QColor& color)
	: _data(new TileData)
{
	quint32 *ptr = _data->data;
	quint32 col = color.rgba();
	for(int i=0;i<SIZE*SIZE;++i)
		*(ptr++) = col;
}
void  OgreWidget::setBackgroundColor(QColor c)
{
  if (m_viewport)
    {
      Ogre::ColourValue ogreColour;
      ogreColour.setAsARGB(c.rgba());
      m_viewport->setBackgroundColour(ogreColour);
    }
}