Beispiel #1
0
QImage QSGSoftwareRenderLoop::grab(QQuickWindow *window)
{
    //If the window was never shown, create a new backing store
    if (!m_backingStores.contains(window)) {
        m_backingStores[window] = new QBackingStore(window);
        // Call create on window to make sure platform window is created
        window->create();
    }

    //If there is no WindowData, add one
    if (!m_windows.contains(window)) {
        WindowData data;
        data.updatePending = false;
        m_windows[window] = data;
    }

    m_windows[window].grabOnly = true;

    renderWindow(window);

    QImage grabbed = grabContent;
    grabbed.detach();
    grabContent = QImage();
    return grabbed;
}
Beispiel #2
0
/*!
  Returns the QImage called \a name. You should avoid including
  any filename type extension (e.g. .png, .xpm).
*/
QImage Resource::loadImage( const QString &name)
{
#ifndef QT_NO_DEPTH_32	// have alpha-blended pixmaps
    static QImage last_enabled;
    static QString last_enabled_name;
    if ( name == last_enabled_name )
	return last_enabled;
#endif
    QImage img = load_image(name);
#ifndef QT_NO_DEPTH_32	// have alpha-blended pixmaps
    if ( img.isNull() ) {
	// No file, try generating
	if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) {
	    last_enabled_name = name.left(name.length()-9);
	    last_enabled = load_image(last_enabled_name);
	    if ( last_enabled.isNull() ) {
		last_enabled_name = QString::null;
	    } else {
		img.detach();
		img.create( last_enabled.width(), last_enabled.height(), 32 );
		for ( int y = 0; y < img.height(); y++ ) {
		    for ( int x = 0; x < img.width(); x++ ) {
			QRgb p = last_enabled.pixel( x, y );
			int a = qAlpha(p)/3;
			int g = qGray(qRed(p),qGreen(p),qBlue(p));
			img.setPixel( x, y, qRgba(g,g,g,a) );
		    }
		}
		img.setAlphaBuffer( TRUE );
	    }
	}
    }
#endif
    return img;
}
Beispiel #3
0
template< int operation( int, int ) > static QImage changeImage( const QImage& image, int value )
{
    QImage im = image;
    im.detach();
    if( im.colorCount() == 0 ) /* truecolor */
    {
        if( im.format() != QImage::Format_RGB32 ) /* just in case */
            im = im.convertToFormat( QImage::Format_RGB32 );
        int table[ 256 ];
        for( int i = 0;
                i < 256;
                ++i )
            table[ i ] = operation( i, value );
        if( im.hasAlphaChannel() )
        {
            for( int y = 0;
                    y < im.height();
                    ++y )
            {
                QRgb* line = reinterpret_cast< QRgb* >( im.scanLine( y ));
                for( int x = 0;
                        x < im.width();
                        ++x )
                    line[ x ] = qRgba( changeUsingTable( qRed( line[ x ] ), table ),
                            changeUsingTable( qGreen( line[ x ] ), table ),
                            changeUsingTable( qBlue( line[ x ] ), table ),
                            changeUsingTable( qAlpha( line[ x ] ), table ));
            }
        }
        else
        {
            for( int y = 0;
                    y < im.height();
                    ++y )
            {
                QRgb* line = reinterpret_cast< QRgb* >( im.scanLine( y ));
                for( int x = 0;
                        x < im.width();
                        ++x )
                    line[ x ] = qRgb( changeUsingTable( qRed( line[ x ] ), table ),
                            changeUsingTable( qGreen( line[ x ] ), table ),
                            changeUsingTable( qBlue( line[ x ] ), table ));
            }
        }
    }
    else
    {
        QVector<QRgb> colors = im.colorTable();
        for( int i = 0;
                i < im.colorCount();
                ++i )
            colors[ i ] = qRgb( operation( qRed( colors[ i ] ), value ),
                    operation( qGreen( colors[ i ] ), value ),
                    operation( qBlue( colors[ i ] ), value ));
    }
    return im;
}
QPixmap PsiTrayIcon::makeIcon()
{
	if ( !icon_ )
		return QPixmap();

#ifdef Q_WS_X11
	// on X11, the KDE dock is 22x22.  let's make our icon_ "seem" bigger.
	QImage real(22,22,32);
	QImage in = icon_->image();
	in.detach();
	real.setAlphaBuffer(true);

	// make sure it is no bigger than 16x16
	if(in.width() > 16 || in.height() > 16)
		in = in.smoothScale(16,16);

	int xo = (real.width() - in.width()) / 2;
	int yo = (real.height() - in.height()) / 2;

	int n, n2;

	// clear the output and make it transparent
	// deprecates real.fill(0)
	for(n2 = 0; n2 < real.height(); ++n2)
		for(n = 0; n < real.width(); ++n)
			real.setPixel(n, n2, qRgba(0,0,0,0));

	// draw a dropshadow
	for(n2 = 0; n2 < in.height(); ++n2) {
		for(n = 0; n < in.width(); ++n) {
			if(int a = qAlpha(in.pixel(n,n2))) {
				int x = n + xo + 2;
				int y = n2 + yo + 2;
				real.setPixel(x, y, qRgba(0x80,0x80,0x80,a));
			}
		}
	}

	// draw the image
	for(n2 = 0; n2 < in.height(); ++n2) {
		for(n = 0; n < in.width(); ++n) {
			if(qAlpha(in.pixel(n,n2))) {
				QRgb pold = real.pixel(n + xo , n2 + yo);
				QRgb pnew = in.pixel(n , n2);
				real.setPixel(n + xo, n2 + yo, pixelBlend(pold, pnew));
			}
		}
	}

	QPixmap pixmap;
	pixmap.convertFromImage(real);
	return pixmap;
#else
	return icon_->pixmap();
#endif
}
Beispiel #5
0
void QGLPixmapData::createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
{
    if (image.size() == QSize(w, h))
        setSerialNumber(++qt_gl_pixmap_serial);

    resize(image.width(), image.height());

    if (pixelType() == BitmapType) {
        QImage convertedImage = image.convertToFormat(QImage::Format_MonoLSB);
        if (image.format() == QImage::Format_MonoLSB)
            convertedImage.detach();

        m_source = QVolatileImage(convertedImage);

    } else {
        QImage::Format format = idealFormat(image, flags);

        if (inPlace && image.data_ptr()->convertInPlace(format, flags)) {
            m_source = QVolatileImage(image);
        } else {
            QImage convertedImage = image.convertToFormat(format);

            // convertToFormat won't detach the image if format stays the same.
            if (image.format() == format)
                convertedImage.detach();

            m_source = QVolatileImage(convertedImage);
        }
    }

    m_dirty = true;
    m_hasFillColor = false;

    m_hasAlpha = m_source.hasAlphaChannel();
    w = image.width();
    h = image.height();
    is_null = (w <= 0 || h <= 0);
    d = m_source.depth();

    destroyTexture();
}
Beispiel #6
0
void BaseFrame::image_receivedCB(const sensor_msgs::ImageConstPtr & msg)
{
	if(first_image || base_frame_graphics_view->get_correct_bb())
	{
		try
		{
			if (enc::isColor(msg->encoding))
				cv_ptr = cv_bridge::toCvShare(msg, enc::RGB8);
			else
				cv_ptr = cv_bridge::toCvShare(msg, enc::MONO8);
		}
		catch (cv_bridge::Exception& e)
		{
			ROS_ERROR("cv_bridge exception: %s", e.what());
			return;
		}

		QImage image;

		if (enc::isColor(msg->encoding))
		{
            // Force QImage to do a deep copy of the image data
			QImage tmpImage = QImage((const unsigned char*)(cv_ptr->image.data),cv_ptr->image.cols,cv_ptr->image.rows,QImage::Format_RGB888);
			image = QImage(tmpImage);
			image.detach();
			//image.rgbSwapped();
		}
		else
		{
			QImage tmpImage = QImage((const unsigned char*)(cv_ptr->image.data),cv_ptr->image.cols,cv_ptr->image.rows,QImage::Format_Indexed8);
			image = QImage(tmpImage);
			image.detach();
		}

		emit sig_image_received(image);

		if(first_image)
			first_image = false;
	}
}
QPixmap* HostWindowDataSoftware::acquirePixmap(QPixmap& screenPixmap)
{
	if (m_dirty) {

	    if (G_UNLIKELY(!m_ipcBuffer))
		return &screenPixmap;

		m_ipcBuffer->lock();
	    QImage sharedImage = QImage((const uchar*) m_ipcBuffer->data(), m_width, m_height,
					QImage::Format_ARGB32_Premultiplied);
	    sharedImage.detach();
	    screenPixmap = QPixmap::fromImage(sharedImage);
		m_ipcBuffer->unlock();
	}

	return &screenPixmap;
}
Beispiel #8
0
void QVGPixmapData::createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
{
    resize(image.width(), image.height());

    QImage::Format format = idealFormat(&image, flags);

    if (inPlace && image.data_ptr()->convertInPlace(format, flags)) {
        source = QVolatileImage(image);
    } else {
        QImage convertedImage = image.convertToFormat(format);
        // convertToFormat won't detach the image if format stays the
        // same. Detaching is needed to prevent issues with painting
        // onto this QPixmap later on.
        convertedImage.detach();
        source = QVolatileImage(convertedImage);
    }

    recreate = true;
}
Beispiel #9
0
static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat)
{
    QByteArray str;
    QImage image = sourceImage;
    QByteArray format = sourceFormat;

    format = format.left(3);                        // ignore RAW part
    bool gray = format == "pgm";

    if (format == "pbm") {
        image = image.convertToFormat(QImage::Format_Mono);
    } else if (gray) {
        image = image.convertToFormat(QImage::Format_Grayscale8);
    } else {
        switch (image.format()) {
        case QImage::Format_Mono:
        case QImage::Format_MonoLSB:
            image = image.convertToFormat(QImage::Format_Indexed8);
            break;
        case QImage::Format_Indexed8:
        case QImage::Format_RGB32:
        case QImage::Format_ARGB32:
            break;
        default:
            if (image.hasAlphaChannel())
                image = image.convertToFormat(QImage::Format_ARGB32);
            else
                image = image.convertToFormat(QImage::Format_RGB32);
            break;
        }
    }

    if (image.depth() == 1 && image.colorCount() == 2) {
        if (qGray(image.color(0)) < qGray(image.color(1))) {
            // 0=dark/black, 1=light/white - invert
            image.detach();
            for (int y=0; y<image.height(); y++) {
                uchar *p = image.scanLine(y);
                uchar *end = p + image.bytesPerLine();
                while (p < end)
                    *p++ ^= 0xff;
            }
        }
    }

    uint w = image.width();
    uint h = image.height();

    str = "P\n";
    str += QByteArray::number(w);
    str += ' ';
    str += QByteArray::number(h);
    str += '\n';

    switch (image.depth()) {
        case 1: {
            str.insert(1, '4');
            if (out->write(str, str.length()) != str.length())
                return false;
            w = (w+7)/8;
            for (uint y=0; y<h; y++) {
                uchar* line = image.scanLine(y);
                if (w != (uint)out->write((char*)line, w))
                    return false;
            }
            }
            break;

        case 8: {
            str.insert(1, gray ? '5' : '6');
            str.append("255\n");
            if (out->write(str, str.length()) != str.length())
                return false;
            uint bpl = w * (gray ? 1 : 3);
            uchar *buf = new uchar[bpl];
            if (image.format() == QImage::Format_Indexed8) {
                QVector<QRgb> color = image.colorTable();
                for (uint y=0; y<h; y++) {
                    const uchar *b = image.constScanLine(y);
                    uchar *p = buf;
                    uchar *end = buf+bpl;
                    if (gray) {
                        while (p < end) {
                            uchar g = (uchar)qGray(color[*b++]);
                            *p++ = g;
                        }
                    } else {
                        while (p < end) {
                            QRgb rgb = color[*b++];
                            *p++ = qRed(rgb);
                            *p++ = qGreen(rgb);
                            *p++ = qBlue(rgb);
                        }
                    }
                    if (bpl != (uint)out->write((char*)buf, bpl))
                        return false;
                }
            } else {
                for (uint y=0; y<h; y++) {
                    const uchar *b = image.constScanLine(y);
                    uchar *p = buf;
                    uchar *end = buf + bpl;
                    if (gray) {
                        while (p < end)
                            *p++ = *b++;
                    } else {
                        while (p < end) {
                            uchar color = *b++;
                            *p++ = color;
                            *p++ = color;
                            *p++ = color;
                        }
                    }
                    if (bpl != (uint)out->write((char*)buf, bpl))
                        return false;
                }
            }
            delete [] buf;
            break;
        }

        case 32: {
            str.insert(1, '6');
            str.append("255\n");
            if (out->write(str, str.length()) != str.length())
                return false;
            uint bpl = w * 3;
            uchar *buf = new uchar[bpl];
            for (uint y=0; y<h; y++) {
                const QRgb  *b = reinterpret_cast<const QRgb *>(image.constScanLine(y));
                uchar *p = buf;
                uchar *end = buf+bpl;
                while (p < end) {
                    QRgb rgb = *b++;
                    *p++ = qRed(rgb);
                    *p++ = qGreen(rgb);
                    *p++ = qBlue(rgb);
                }
                if (bpl != (uint)out->write((char*)buf, bpl))
                    return false;
            }
            delete [] buf;
            break;
        }

    default:
        return false;
    }

    return true;
}
Beispiel #10
0
void KSVGLoader::slotResult(KIO::Job *job)
{
	if(job == m_job)
	{
		if(m_job->error() == 0)
		{
			QString check = static_cast<KIO::TransferJob *>(job)->url().prettyURL();
			if(check.contains(".svgz") || check.contains(".svg.gz"))
			{
				// decode the gzipped svg and emit it
				QIODevice *dev = KFilterDev::device(new QBuffer(m_data), "application/x-gzip");
				dev->open(IO_ReadOnly);
				emit gotResult(dev);
			}
			else
			{
				m_job = 0;
				emit gotResult(new QBuffer(m_data));
				m_data.resize(0);
			}
		}
	}
	else if(m_postUrlData.job == job)
	{
		// Notify that we're done
		KJS::List callBackArgs;
		callBackArgs.append(*m_postUrlData.status);

		m_postUrlData.status->put(m_postUrlData.exec, KJS::Identifier("success"), KJS::Boolean(true));
		m_postUrlData.callBackFunction->call(m_postUrlData.exec, *m_postUrlData.callBackFunction, callBackArgs);
	}
	else
	{
		QMap<KIO::TransferJob *, ImageStreamMap *>::Iterator it;
		for(it = m_imageJobs.begin(); it != m_imageJobs.end(); ++it)
		{
			if(it.key() == job)
			{
				ImageStreamMap *streamMap = it.data();

				QBuffer buffer(*(streamMap->data));

				if(buffer.open(IO_ReadOnly))
				{
					const char *imageFormat = QImageIO::imageFormat(&buffer);

					if(imageFormat != 0)
					{
						QImageIO imageIO(&buffer, imageFormat);

						// Gamma correction
						imageIO.setGamma(1/0.45454); 

						if(imageIO.read())
						{
							QImage *image = new QImage(imageIO.image());
							image->detach();
							(streamMap->imageElement)->setImage(image);
						}
					}

					buffer.close();
				}

				(streamMap->data)->resize(0);

				m_imageJobs.remove(static_cast<KIO::TransferJob *>(job));

				emit imageReady(streamMap->imageElement);
				break;
			}
		}
	}
}