JNIEXPORT void JNICALL Java_joxy_utils_JoxyGraphics_drawStringNative
  (JNIEnv *env, jclass cl, jstring str, jobject image, jint width,
jint height, jstring fontname, jint fontsize, jint style, jint color)
{
    QImage qimage(width, height, QImage::Format_ARGB32);
    QColor qcolor = QColor::fromRgb(color);
    qcolor.setAlpha(0);
    qimage.fill(qcolor);
    QPainter painter(&qimage);
    painter.setPen(QColor::fromRgb(color));
    const char* cfontname = env->GetStringUTFChars(fontname, JNI_FALSE);
    bool italic = (style >= 2);
    bool bold = (style % 2 == 1);
    painter.setFont(QFont(cfontname, fontsize, (bold ? 75 : 50), italic));
    const char* cstr = env->GetStringUTFChars(str, JNI_FALSE);
    painter.drawText(0, 0, width + 10, height, Qt::AlignLeft, QString::fromUtf8(cstr));
    env->ReleaseStringUTFChars(str, cfontname);
    env->ReleaseStringUTFChars(str, cstr);
    // TODO do this with the int[] version, so the for-loop is unnecessary
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int pixel = qimage.pixel(i, j);
            // if it is transparent, it is useless to copy it...
            if (pixel != 0) {
                env->CallVoidMethod(image, mid, i, j, pixel);
            }
        }
    }
}
示例#2
0
bool KisCrashFilterTest::applyFilter(const KoColorSpace * cs,  KisFilterSP f)
{

    QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "carrot.png");

    KisPaintDeviceSP dev = new KisPaintDevice(cs);
//    dev->fill(0, 0, 100, 100, dev->defaultPixel());
    dev->convertFromQImage(qimage, 0, 0, 0);

    // Get the predefined configuration from a file
    KisFilterConfigurationSP  kfc = f->defaultConfiguration(dev);

    QFile file(QString(FILES_DATA_DIR) + QDir::separator() + f->id() + ".cfg");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        dbgKrita << "creating new file for " << f->id();
        file.open(QIODevice::WriteOnly | QIODevice::Text);
        QTextStream out(&file);
        out.setCodec("UTF-8");
        out << kfc->toXML();
    } else {
        QString s;
        QTextStream in(&file);
        in.setCodec("UTF-8");
        s = in.readAll();
        kfc->fromXML(s);
    }
    dbgKrita << f->id() << ", " << cs->id() << ", " << cs->profile()->name();// << kfc->toXML() << "\n";

    f->process(dev, QRect(QPoint(0,0), qimage.size()), kfc);

    return true;

}
bool applyFilter(const KoColorSpace * cs,  KisFilterSP f)
{

    QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "lena.png");

    KisPaintDeviceSP dev = new KisPaintDevice(cs);
//    dev->fill(0, 0, 100, 100, dev->defaultPixel());
    dev->convertFromQImage(qimage, "", 0, 0);

    // Get the predefined configuration from a file
    KisFilterConfiguration * kfc = f->defaultConfiguration(dev);

    QFile file(QString(FILES_DATA_DIR) + QDir::separator() + f->id() + ".cfg");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qDebug() << "creating new file for " << f->id();
        file.open(QIODevice::WriteOnly | QIODevice::Text);
        QTextStream out(&file);
        out << kfc->toXML();
    } else {
        QString s;
        QTextStream in(&file);
        s = in.readAll();
        kfc->fromXML(s);
    }
    qDebug() << f->id() << ", " << cs->id() << ", " << cs->profile()->name();// << kfc->toXML() << "\n";

    KisConstProcessingInformation src(dev,  QPoint(0, 0), 0);
    KisProcessingInformation dst(dev, QPoint(0, 0), 0);

    f->process(src, dst, qimage.size(), kfc);

    return true;

}
示例#4
0
void KisFilterMaskTest::testProjectionSelected()
{
    KisImageSP image;
    KisPaintLayerSP layer;

    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();

    QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "hakonepa.png");
    QImage inverted(QString(FILES_DATA_DIR) + QDir::separator() + "inverted_hakonepa.png");

    KisFilterSP f = KisFilterRegistry::instance()->value("invert");
    Q_ASSERT(f);
    KisFilterConfiguration * kfc = f->defaultConfiguration(0);
    Q_ASSERT(kfc);

    KisFilterMaskSP mask = new KisFilterMask();
    mask->setFilter(kfc);
    mask->createNodeProgressProxy();

    KisPaintDeviceSP projection = new KisPaintDevice(cs);
    initImage(image, layer, projection, mask);
    projection->convertFromQImage(qimage, 0, 0, 0);

    mask->initSelection(layer);
    mask->select(qimage.rect(), MAX_SELECTED);
    mask->apply(projection, qimage.rect(), qimage.rect(), KisNode::N_FILTHY);
    QCOMPARE(mask->exactBounds(), QRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT));

    QPoint errpoint;
    if (!TestUtil::compareQImages(errpoint, inverted, projection->convertToQImage(0, 0, 0, qimage.width(), qimage.height()))) {
        projection->convertToQImage(0, 0, 0, qimage.width(), qimage.height()).save("filtermasktest2.png");
        QFAIL(QString("Failed to create inverted image, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
    }

}
示例#5
0
文件: ImageDraw.cpp 项目: caomw/sara
 void draw_point(Image<Rgb8>& image, int x, int y, const Color3ub& c)
 {
   QImage qimage(as_QImage(image));
   QPainter p(&qimage);
   p.setPen(to_QColor(c));
   p.drawPoint(x, y);
 }
void KisPrescaledProjectionTest::testScalingUndeferredSmoothing()
{
    // Set up a nice image
    QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "lena.png");

    // Undo adapter not necessary
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(0, qimage.width(), qimage.height(), cs, "projection test");

    // 300 dpi recalculated to pixels per point (of which there are 72
    // to the inch)
    image->setResolution(100, 100);

    KisPaintLayerSP layer = new KisPaintLayer(image, "test", OPACITY_OPAQUE_U8, cs);
    image->addNode(layer.data(), image->rootLayer(), 0);
    layer->paintDevice()->convertFromQImage(qimage, 0);

    KisPrescaledProjection projection;
    KisCoordinatesConverter converter;
    
    converter.setImage(image);
    projection.setCoordinatesConverter(&converter);
    projection.setMonitorProfile(0,
                                 KoColorConversionTransformation::internalRenderingIntent(),
                                 KoColorConversionTransformation::internalConversionFlags());
    projection.setImage(image);

    testProjectionScenario(projection, &converter, "120dpi");

}
void KisConvolutionPainterTest::testIdentityConvolution()
{
    QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "hakonepa.png");

    KisPaintDeviceSP dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
    dev->convertFromQImage(qimage, 0, 0, 0);

    KisConvolutionKernelSP kernel = new KisConvolutionKernel(3, 3, 0, 0);
    kernel->data()(0) = 0;
    kernel->data()(1) = 0;
    kernel->data()(2) = 0;
    kernel->data()(3) = 0;
    kernel->data()(4) = 1;
    kernel->data()(5) = 0;
    kernel->data()(6) = 0;
    kernel->data()(7) = 0;
    kernel->data()(8) = 0;
    KisConvolutionPainter gc(dev);
    gc.beginTransaction();
    gc.applyMatrix(kernel, dev, QPoint(0, 0), QPoint(0, 0), QSize(qimage.width(), qimage.height()));
    gc.deleteTransaction();

    QImage resultImage = dev->convertToQImage(0, 0, 0, qimage.width(), qimage.height());

    QPoint errpoint;
    if (!TestUtil::compareQImages(errpoint, qimage, resultImage)) {
        resultImage.save("identity_convolution.png");
        QFAIL(QString("Identity kernel did change image, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
    }
}
示例#8
0
void cTexture::FromQByteArray(QByteArray buffer)
{
	if (bitmap)
	{
		//qDebug() << "void cTexture::FromQByteArray(QByteArray buffer): delete[] bitmap;:" << width * height * sizeof(sRGB8);
		delete[] bitmap;
	}

	bitmap = NULL;
	QImage qimage(buffer);
	qimage.loadFromData(buffer);
	qimage = qimage.convertToFormat(QImage::Format_RGB888);
	if (!qimage.isNull())
	{
		width = qimage.width();
		height = qimage.height();
		bitmap = new sRGB8[width * height];
		memcpy(bitmap, qimage.constBits(), sizeof(sRGB8) * width * height);
		//qDebug() << "void cTexture::FromQByteArray(QByteArray buffer): (sRGB8*)(qimage.bits()):" << width * height * sizeof(sRGB8);
		CreateMipMaps();
		loaded = true;
	}
	else
	{
		cErrorMessage::showMessage(QObject::tr("Can't load texture from QByteArray!\n"),
															 cErrorMessage::errorMessage);
	}
}
void VideoQLabel::update(Mat *frame){
    if(frame==NULL || frame->empty())
        return;
    QImage qimage((uchar*)(*frame).data,(*frame).cols,(*frame).rows,(*frame).step,QImage::Format_RGB888);
    setPixmap(QPixmap::fromImage(qimage));
    delete frame;
}
示例#10
0
文件: ImageDraw.cpp 项目: caomw/sara
 void fill_rect(Image<Rgb8>& image,
                int x, int y, int w, int h, const Color3ub& c)
 {
   QImage qimage(as_QImage(image));
   QPainter p(&qimage);
   p.fillRect(x, y, w, h, to_QColor(c));
 }
QPixmap
TextStyleToPixmap(const MapTextStyleConfig &config,
                  const QColor &bgColor, uint overrideSize)
{
  // generate string to render
  QString weightLabel;
  switch (config.weight) {
    case MapTextStyleConfig::Regular:
      weightLabel = "";
      break;
    case MapTextStyleConfig::Bold:
      weightLabel = "/b";
      break;
    case MapTextStyleConfig::Italic:
      weightLabel = "/i";
      break;
    case MapTextStyleConfig::BoldItalic:
      weightLabel = "/bi";
      break;
  }
  QString text = QString("%1/%2%3")
                 .arg(config.font)
                 .arg(config.size)
                 .arg(weightLabel);

  MapTextStyleConfig configCopy = config;
  if (overrideSize) {
    configCopy.size = overrideSize;
  }
  maprender::TextRenderer textRenderer(configCopy, false, true);

  // figure out how big of a pixmap we need and where we want to draw the text
  SkScalar textWidth = 0;
  SkScalar textAscent = 0;
  SkScalar textDescent = 0;
  textWidth = textRenderer.MeasureText(text, &textAscent, &textDescent);
  textAscent = -textAscent;
  SkScalar margin = 1;
  SkScalar pixelWidth  = textWidth + margin * 2;
  SkScalar pixelHeight = textAscent + textDescent + margin * 2;
  SkScalar posX = margin;
  SkScalar posY = margin + textAscent;

  // create the SkCanvas
  QImage qimage(int(pixelWidth), int(pixelHeight), 32);
  // qimage.setAlphaBuffer(true);
  qimage.fill(bgColor.rgb());

  SkBitmap bitmap;
  bitmap.setConfig(SkBitmap::kARGB_8888_Config,
                   uint(pixelWidth), uint(pixelHeight));
  bitmap.setPixels(qimage.bits());
  SkCanvas canvas(bitmap);

  // render the preview into a canvas
  textRenderer.DrawText(canvas, text, posX, posY);

  // convert to a QPixmap
  return QPixmap(qimage);
}
示例#12
0
QImage qt_imageToQImage(int M, int N, coordval* image, t_imagecolor color_mode)
{
	QImage qimage(QSize(M, N), QImage::Format_ARGB32_Premultiplied);

	rgb_color rgb1;
	rgb255_color rgb255;

	// TrueColor 24-bit color mode
	if (color_mode == IC_RGB)
		for (int n = 0; n < N; n++)
		{
			QRgb* line = (QRgb*)(qimage.scanLine(n));
			for (int m = 0; m < M; m++)
			{
				rgb1.r = *image++;
				rgb1.g = *image++;
				rgb1.b = *image++;
				rgb255_from_rgb1(rgb1, &rgb255);
				*line++ = qRgb(rgb255.r, rgb255.g, rgb255.b);
			}
		}
	else if (color_mode == IC_RGBA)
		for (int n = 0; n < N; n++)
		{
			QRgb* line = (QRgb*)(qimage.scanLine(n));
			for (int m = 0; m < M; m++)
			{
				unsigned char alpha255 = *(image + 3);
				float alpha1 = float(alpha255 / 255.);
				rgb1.r = alpha1 * (*image++);
				rgb1.g = alpha1 * (*image++);
				rgb1.b = alpha1 * (*image++);
				image++;
				rgb255_from_rgb1(rgb1, &rgb255);
				*line++ = qRgba(rgb255.r, rgb255.g, rgb255.b, alpha255);
			}
		}
	// Palette color lookup from gray value
	else
		for (int n = 0; n < N; n++)
		{
			QRgb* line = (QRgb*)(qimage.scanLine(n));
			for (int m = 0; m < M; m++)
			{
				if (isnan(*image))
				{
					image++;
					*line++ = 0x00000000;
				}
				else
				{
					rgb255maxcolors_from_gray(*image++, &rgb255);
					*line++ = qRgb(rgb255.r, rgb255.g, rgb255.b);
				}
			}
		}

	return qimage;
}
示例#13
0
文件: ImageDraw.cpp 项目: caomw/sara
 void draw_circle(Image<Rgb8>& image,
                  int xc, int yc, int r, const Color3ub& c, int penWidth)
 {
   QImage qimage(as_QImage(image));
   QPainter p(&qimage);
   p.setPen(QPen(to_QColor(c), penWidth));
   p.drawEllipse(QPoint(xc, yc), r, r);
 }
示例#14
0
文件: ImageDraw.cpp 项目: caomw/sara
 void draw_rect(Image<Rgb8>& image,
                int x, int y, int w, int h, const Color3ub& c,
                int penWidth)
 {
   QImage qimage(as_QImage(image));
   QPainter p(&qimage);
   p.setPen(QPen(to_QColor(c), penWidth));
   p.drawRect(x, y, w, h);
 }
示例#15
0
文件: ImageDraw.cpp 项目: caomw/sara
 void draw_line(Image<Rgb8>& image,
                int x1, int y1, int x2, int y2, const Color3ub& c,
                int penWidth)
 {
   QImage qimage(as_QImage(image));
   QPainter p(&qimage);
   p.setPen(QPen(to_QColor(c), penWidth));
   p.drawLine(x1, y1, x2, y2);
 }
示例#16
0
文件: ImageDraw.cpp 项目: caomw/sara
 void fill_circle(Image<Rgb8>& image,
                  int x, int y, int r, const Color3ub& c)
 {
   QImage qimage(as_QImage(image));
   QPainter p(&qimage);
   QPainterPath path;
   path.addEllipse(QPointF(x,y), qreal(r), qreal(r));
   p.fillPath(path, to_QColor(c));
 }
示例#17
0
void ObjectScene::syncQuad(Kite::KQuadCom *Quad) {
	auto pixItem = (QGraphicsPixmapItem *)Quad->getSceneItem();

	Kite::KRectF32 brect;
	Quad->getBoundingRect(brect);

	if (!Quad->getAtlasTextureArray().str.empty()) {
		Kite::KAtlasTextureArray *tarray = nullptr;
		emit(tarray = (Kite::KAtlasTextureArray *)requestResource(Quad->getAtlasTextureArray().str.c_str()));

		if (tarray) {
			auto atex = tarray->getItem(Quad->getTextureArrayIndex());
			if (atex) {
				Kite::KTexture *tex = atex->getTexture();
				if (tex) {
					Kite::KImage image;
					tex->getImage(image);
					QImage qimage(image.getPixelsData(), image.getWidth(), image.getHeight(), QImage::Format::Format_RGBA8888);
					auto procimgae = qimage.copy(Quad->getAtlasItem().xpos, Quad->getAtlasItem().ypos,
																	  Quad->getAtlasItem().width, Quad->getAtlasItem().height)
														  .mirrored(Quad->getAtlasItem().getFlipH(), !Quad->getAtlasItem().getFlipV())
														  .scaled(Quad->getWidth(), Quad->getHeight());

					//blend
					if (Quad->getBlendColor() != Kite::KColor(Kite::Colors::WHITE)) {
						QColor col(Quad->getBlendColor().getR(), Quad->getBlendColor().getG(),
								   Quad->getBlendColor().getB(), Quad->getBlendColor().getA());

						auto alpha = procimgae.alphaChannel();
						for (int x = 0; x != procimgae.width(); ++x) {
							for (int y(0); y != procimgae.height(); ++y) {
								if (qAlpha(procimgae.pixel(x, y)) == 0) continue; // transparrent pixels

								QColor icol(procimgae.pixel(x, y));
								icol.setRed(BLEND_Multiply(icol.red(), col.red()));
								icol.setBlue(BLEND_Multiply(icol.blue(), col.blue()));
								icol.setGreen(BLEND_Multiply(icol.green(), col.green()));
								procimgae.setPixel(x, y, icol.rgb());
							}
						}
						procimgae.setAlphaChannel(alpha);
					}

					pixItem->setPixmap(QPixmap::fromImage(procimgae));
					pixItem->setOpacity(Quad->getBlendColor().getGLA());
					return;
				}
			}
		}
	}
	
	QPixmap pm(Quad->getWidth(), Quad->getHeight());
	pm.fill(QColor(Quad->getBlendColor().getR(), Quad->getBlendColor().getG(), Quad->getBlendColor().getB(), Quad->getBlendColor().getA()));
	pixItem->setPixmap(pm);
	pixItem->setOpacity(Quad->getBlendColor().getGLA());
}
示例#18
0
void Image_controls::set_thumbnail(const Image_buffer<rendering::Color4c>& source)
{
	To_BGRA filter(true);
	filter.filter(thumbnail_, source);

	QImage qimage(reinterpret_cast<const uchar*>(thumbnail_.data()),
				  thumbnail_.dimensions().x, thumbnail_.dimensions().y, QImage::Format_RGB32);

	QPixmap pixmap = QPixmap::fromImage(qimage);

	ui->image_label_->setPixmap(pixmap);
}
示例#19
0
QImage SNIProxy::getImageNonComposite()
{
    auto c = QX11Info::connection();
    auto cookie = xcb_get_geometry(c, m_windowId);
    QScopedPointer<xcb_get_geometry_reply_t> geom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR));

    xcb_image_t *image = xcb_image_get(c, m_windowId, 0, 0, geom->width, geom->height, 0xFFFFFF, XCB_IMAGE_FORMAT_Z_PIXMAP);

    QImage qimage(image->data, image->width, image->height, image->stride, QImage::Format_ARGB32, sni_cleanup_xcb_image, image);

    return qimage;
}
示例#20
0
void QOpenCV::OpenCVWindow::setLabel( cv::Mat image )
{
	if ( image.empty() ) {
		mWindowLabel->setText( tr( "Image empty" ) );
		return;
	}

	QImage qimage( image.data, image.cols, image.rows,static_cast<int>( image.step ), QImage::Format_RGB888 );

	mWindowLabel->setPixmap( QPixmap::fromImage( qimage ) );

	image.~Mat();
}
示例#21
0
void Kinect::KinectWindow::setLabel( cv::Mat image )
{
	if ( image.empty() ) {
		mWindowLabel->setText( tr( "Image empty" ) );
		return;
	}
	//convert to QImage - for Label
	cv::cvtColor( image, image, CV_BGR2RGB );
	QImage qimage( image.data, image.cols, image.rows, static_cast<int>( image.step ), QImage::Format_RGB888 );

	mWindowLabel->setPixmap( QPixmap::fromImage( qimage ) );

	image.~Mat();

}
示例#22
0
static Error atleast1image(Object o)
{
    Object subo, old;
    int i;

    switch (DXGetObjectClass(o)) {
      case CLASS_FIELD:
	if (qimage(o))
	    return OK;
	break;

      case CLASS_GROUP:
	/* traverse members */
	for (i=0; subo = DXGetEnumeratedMember((Group)o, i, NULL); i++)
	    if (atleast1image(subo))
		return OK;
	break;
    
      case CLASS_SCREEN:
	if (!DXGetScreenInfo((Screen)o, &subo, NULL, NULL))
	    return ERROR;

	return atleast1image(subo);

      case CLASS_XFORM:
	if (!DXGetXformInfo((Xform)o, &subo, NULL))
	    return ERROR;

	return atleast1image(subo);

      case CLASS_CLIPPED:
	if (!DXGetClippedInfo((Clipped)o, &subo, NULL))
	    return ERROR;

	return atleast1image(subo);

      default:
	break;
    }

    return ERROR;
}
示例#23
0
int qt_drawmap(GDALDatasetH dataset, void *painter,
	       GInt32 imageWidth, GInt32 imageHeight,
	       GInt32 mapWest, GInt32 mapNorth,
	       GInt32 mapWidth, GInt32 mapHeight,
	       GInt32 xPos, GInt32 yPos, int mode)
{
  QPainter *qpainter = (QPainter *)painter;
  QImage qimage(imageWidth, imageHeight, 32);
  GUInt32 *imageData = (GUInt32 *)qimage.bits();

  // Fill image
  gdal2argb(dataset, imageData, imageWidth, imageHeight,
	    mapWest, mapNorth, mapWidth, mapHeight,
	    3, 0, 1, 2, mode);

  // Draw image
  qpainter->drawImage(xPos, yPos, qimage);

  return 1;
}
示例#24
0
void Image_controls::set_thumbnail(const Image_buffer<rendering::Color4>& source)
{
	const uint2& source_dimensions = source.dimensions();
	const uint2& thumbnail_dimensions = thumbnail_.dimensions();

	if (source_dimensions.x < thumbnail_dimensions.x || source_dimensions.y < thumbnail_dimensions.y)
	{
		Copy<rendering::Color4c> copy;
		copy.filter(thumbnail_, thumbnail_provider_->checkerboard());
	}

	To_BGRA filter(true);
	filter.filter(thumbnail_, source);

	QImage qimage(reinterpret_cast<const uchar*>(thumbnail_.data()),
				  thumbnail_dimensions.x, thumbnail_dimensions.y, QImage::Format_RGB32);

	QPixmap pixmap = QPixmap::fromImage(qimage);

	ui->image_label_->setPixmap(pixmap);
}
示例#25
0
static int openWindow(const cv::Mat_<cv::Vec3b>& image)
{
	char *argv[1] = { 0 };
	int argc = 0;
	QApplication app(argc, argv);
	QWidget *window = new QWidget;
	QVBoxLayout *layout = new QVBoxLayout;

	// adapted from http://www.qtcentre.org/threads/11655-OpenCV-integration
	cv::Mat rgb = image;
	std::vector<cv::Mat> channels;
	cv::split(rgb, channels);  // split the image into r, g, b channels
	cv::Mat alpha = cv::Mat_<uchar>(image.size());
	alpha.setTo(cv::Scalar(255));
	channels.push_back(alpha);
	cv::Mat rgba = cv::Mat_<cv::Vec4b>(image.size());
	cv::merge(channels, rgba);  // add an alpha (so the image is r, g, b, a
	IplImage iplImage = (IplImage) rgba;  // get the raw bytes
	const unsigned char *imageData = (unsigned char *)(iplImage.imageData);
	QImage qimage(imageData, iplImage.width, iplImage.height, iplImage.widthStep,
		QImage::Format_RGB32); // and convert to a QImage

	QLabel *imageFrame = new QLabel;
	imageFrame->setPixmap(QPixmap::fromImage(qimage, 0));

	QPushButton *quit = new QPushButton(QString("Quit"));
    quit->setGeometry(62, 40, 75, 30);
    quit->setFont(QFont("Times", 18, QFont::Bold));
	window->connect(quit, SIGNAL(clicked()), &app, SLOT(quit()));

	layout->addWidget(new QLabel("top"));
	layout->addWidget(imageFrame);
	layout->addWidget(new QLabel("bottom"));
	layout->addWidget(quit);

	window->setLayout(layout);
	window->setWindowTitle(QString("Qt Image Display"));
	window->show();
	return app.exec();
}
示例#26
0
void Image_controls::set_thumbnail(const Image_buffer<rendering::Color4>& source, uint32_t channel, bool inverted, float modulate_factor)
{
	Image_buffer<rendering::Color4>& scratch_buffer = thumbnail_provider_->scratch_buffer();

	Channel_to_grayscale<rendering::Color4> to_grayscale(channel);
	to_grayscale.filter(scratch_buffer, source);

	if (inverted)
	{
		Invert<rendering::Color4> invert;
		invert.filter(scratch_buffer, scratch_buffer);
	}

	if (1.f != modulate_factor)
	{
		Modulate modulate(modulate_factor);
		modulate.filter(scratch_buffer, scratch_buffer);
	}

	const uint2& source_dimensions = source.dimensions();
	const uint2& thumbnail_dimensions = thumbnail_.dimensions();

	if (source_dimensions.x < thumbnail_dimensions.x || source_dimensions.y < thumbnail_dimensions.y)
	{
		Copy<rendering::Color4c> copy;
		copy.filter(thumbnail_, thumbnail_provider_->checkerboard());
	}

	// No need to swap channels for Qt here, as it is grayscale
	To_BGRA filter(false);
	filter.filter(thumbnail_, scratch_buffer, source.dimensions());

	QImage qimage(reinterpret_cast<const uchar*>(thumbnail_.data()),
				  thumbnail_dimensions.x, thumbnail_dimensions.y, QImage::Format_RGB32);

	QPixmap pixmap = QPixmap::fromImage(qimage);

	ui->image_label_->setPixmap(pixmap);
}
示例#27
0
//--
void
Display::DrawColor(const unsigned char* data)
{
    QImage qimage((const unsigned char*) data, m_width, m_height, QImage::Format_RGB32);
    m_label->setPixmap(QPixmap::fromImage(qimage.scaled(m_label->frameSize())));
}
void ManualPatchSelectionDialog<TImage>::slot_UpdateResult(const itk::ImageRegion<2>& sourceRegion,
                                                           const itk::ImageRegion<2>& targetRegion)
{
  assert(sourceRegion.GetSize() == targetRegion.GetSize());

  if(!this->Image->GetLargestPossibleRegion().IsInside(sourceRegion))
  {
    std::cerr << "Source region is outside the image!" << std::endl;
    return;
  }
  
  QImage qimage(sourceRegion.GetSize()[0], sourceRegion.GetSize()[1], QImage::Format_RGB888);

  if(MaskImage->CountHolePixels(sourceRegion) > 0)
  {
    //std::cerr << "The source patch must not have any hole pixels!" << std::endl;
    //btnAccept->setVisible(false);
    qimage.fill(Qt::green);
  }
  else
  {
    typename TImage::Pointer tempImage = TImage::New();
    ITKHelpers::ConvertTo3Channel(this->Image, tempImage.GetPointer());
    if(this->Image->GetNumberOfComponentsPerPixel() != 3)
      {
      ITKHelpers::ScaleAllChannelsTo255(tempImage.GetPointer());
      }

    itk::ImageRegionIterator<TImage> sourceIterator(tempImage, sourceRegion);
    itk::ImageRegionIterator<TImage> targetIterator(tempImage, targetRegion);
    itk::ImageRegionIterator<Mask> maskIterator(MaskImage, targetRegion);

    typename TImage::Pointer resultPatch = TImage::New();
    resultPatch->SetNumberOfComponentsPerPixel(Image->GetNumberOfComponentsPerPixel());
    itk::ImageRegion<2> resultPatchRegion;
    resultPatchRegion.SetSize(sourceRegion.GetSize());
    resultPatch->SetRegions(resultPatchRegion);
    resultPatch->Allocate();

    while(!maskIterator.IsAtEnd())
      {
      ITKHelpers::FloatVectorImageType::PixelType pixel;

      if(MaskImage->IsHole(maskIterator.GetIndex()))
        {
        pixel = sourceIterator.Get();
        }
      else
        {
        pixel = targetIterator.Get();
        }

      itk::Offset<2> offset = sourceIterator.GetIndex() - sourceRegion.GetIndex();
      itk::Index<2> offsetIndex;
      offsetIndex[0] = offset[0];
      offsetIndex[1] = offset[1];
      resultPatch->SetPixel(offsetIndex, pixel);

      ++sourceIterator;
      ++targetIterator;
      ++maskIterator;
      } // end iterator loop

    qimage = ITKQtHelpers::GetQImageColor(resultPatch.GetPointer(), resultPatch->GetLargestPossibleRegion());
  } // end else

  this->ResultPatchScene->clear();
  QGraphicsPixmapItem* item = this->ResultPatchScene->addPixmap(QPixmap::fromImage(qimage));
  gfxResult->fitInView(item);

}
示例#29
0
/** Properties dialog addon*/
FileInfoDlg* BaseTreeView::addFileInfoPage(KPropertiesDialog* propDlg)
{
  //If the item is a file, add the Quanta file info page
  FileInfoDlg *quantaFileProperties = 0L;
  if ( !currentKFileTreeViewItem()->isDir() )
  {

    QFrame *quantaFilePage = propDlg->addPage(i18n("Quanta File Info"));
    QVBoxLayout *topLayout = new QVBoxLayout( quantaFilePage);
    quantaFileProperties = new FileInfoDlg( quantaFilePage, i18n("Quanta") );

    int fsize,fimgsize=0;
    int ct=0,imgct=0,position=0;
    KURL u = currentURL();
    if (u.isLocalFile())   //get the file info only for local file. TODO: for non-local ones
    {
       QString nameForInfo = u.path();
       QString path =u.directory(0,0);       //extract path for images
       QString sourcename=u.fileName(0);

       QFile qfile(nameForInfo);
       fsize=qfile.size();                              //html file size

       QString mimetype = KMimeType::findByFileContent(nameForInfo)->name();
       if (mimetype.contains("text"))
       {
        qfile.open(IO_ReadOnly);
        QString imgname,imgpath;
        QTextStream stream(&qfile);
        stream.setEncoding(QTextStream::UnicodeUTF8);
        while (!stream.atEnd())     //open & parse file
        {
          imgname = stream.readLine();
          ct++;
          position=imgname.find("<img",0,false);              //check for images
          if (position!=-1)
          {
            imgname.remove(0,position+4);
            position=imgname.find("src=",0,false);              //extract images names
            imgname.remove(0,position+4);
            if (imgname.startsWith("\"")) imgname.remove(0,1);
            if (imgname.startsWith("'")) imgname.remove(0,1);
            position=imgname.find(" ",0,false);
            if (position!=-1) imgname=imgname.left(position);
            position=imgname.find(">",0,false);
            if (position!=-1) imgname=imgname.left(position);
            position=imgname.find("\"",0,false);
            if (position!=-1) imgname=imgname.left(position);
            position=imgname.find("'",0,false);
            if (position!=-1) imgname=imgname.left(position);
            if (!quantaFileProperties->imageList->findItem(imgname,Qt::ExactMatch))     //check if image was already counted
            {
              KURL v(KURL::fromPathOrURL( path ),imgname);
              imgpath=v.path();
              QFile qimage(imgpath);
              if (qimage.exists() && v.isLocalFile())
              {
               fimgsize+=qimage.size();
               quantaFileProperties->imageList->insertItem(imgname);
               imgct++;
              }
             }
           }
         }
         qfile.close();

         quantaFileProperties->lineNum->setText(i18n("Number of lines: %1").arg(ct));
         quantaFileProperties->imageNum->setText(i18n("Number of images included: %1").arg(imgct));
         quantaFileProperties->imageSize->setText(i18n("Size of the included images: %1 bytes").arg(fimgsize));
         quantaFileProperties->totalSize->setText(i18n("Total size with images: %1 bytes").arg(fsize+fimgsize));
        }
        else if (mimetype.contains("image"))
        {              // assume it's an image file
          QImage imagefile=QImage(nameForInfo);
          quantaFileProperties->lineNum->setText(i18n("Image size: %1 x %2").arg(imagefile.width()).arg(imagefile.height()));
          quantaFileProperties->imageNum->hide();
          quantaFileProperties->imageSize->hide();
          quantaFileProperties->totalSize->hide();
          quantaFileProperties->includedLabel->hide();
          quantaFileProperties->imageList->hide();
        }
        quantaFileProperties->fileDescLbl->setText(i18n("Description:"));
        quantaFileProperties->fileDesc->setText(currentKFileTreeViewItem()->text(1));
        // disable per default
        quantaFileProperties->fileDescLbl->hide();
        quantaFileProperties->fileDesc->hide();
        topLayout->addWidget(quantaFileProperties);
    } //if localfile
  }
  return quantaFileProperties;
}
void SmallScalePreviewRayCast::Update(){
    if (!m_kernel){
        m_program = CLM::get()->buildProgram("kernel.cl");
        m_kernel = CLM::get()->buildKernel(*m_program,"raytrace");
        return;
    }

    //------------------------------------------------
    // First we fill the image on GPU
    //------------------------------------------------

    // Creation of the GPU object
    cl::ImageFormat formatFloat;
            formatFloat.image_channel_order = CL_RGBA;
            formatFloat.image_channel_data_type = CL_FLOAT;
    cl::ImageFormat formatInt;
            formatInt.image_channel_order = CL_RGBA;
            formatInt.image_channel_data_type = CL_SIGNED_INT32;
    cl::size_t<3> origin; origin[0] = 0; origin[1] = 0, origin[2] = 0;
    cl::size_t<3> region; region[0] = width; region[1] = 1; region[2] = 1;
    cl::Image2D local_image = cl::Image2D(CLM::get()->context(), CL_MEM_WRITE_ONLY, formatFloat,width, height, 0, NULL, NULL);

    // Creation of the data

    // Vertices
    cl::Image2D vbo = cl::Image2D(CLM::get()->context(), CL_MEM_READ_ONLY, formatFloat, m_params->getNbVertices(), 1, 0, NULL, NULL);
    Vertex * vertices = m_params->getVertices();
    cl_float4 * vertices_f4 = new cl_float4[m_params->getNbVertices()];
    for (int i = 0; i < m_params->getNbVertices(); ++i){
        vertices_f4[i].s[0] = vertices[i].position().x;
        vertices_f4[i].s[1] = vertices[i].position().y;
        vertices_f4[i].s[2] = vertices[i].position().z;
        vertices_f4[i].s[3] = 1.f; // Arbitrary value, no meaning
    }
    region[0] = m_params->getNbVertices();
    CLM::get()->queue().enqueueWriteImage(vbo, CL_TRUE, origin, region,
                              0, 0, vertices_f4);

    // Indices
    cl::Image2D ibo = cl::Image2D(CLM::get()->context(), CL_MEM_READ_ONLY, formatInt, m_params->getNbIndices() / 3, 1, 0, NULL, NULL);
    int * indices = m_params->getIndices();
    cl_int4 * indices_f4 = new cl_int4[m_params->getNbIndices() / 3];
    for (int i = 0; i < m_params->getNbIndices() / 3; ++i){
        indices_f4[i].s[0] = indices[3 * i + 0];
        indices_f4[i].s[1] = indices[3 * i + 1];
        indices_f4[i].s[2] = indices[3 * i + 2];
        indices_f4[i].s[3] = 1.f; // Arbitrary value, no meaning
    }
    region[0] = m_params->getNbIndices() / 3;
    CLM::get()->queue().enqueueWriteImage(ibo, CL_TRUE, origin, region,
                             0, 0, indices_f4);

    // Normals
    cl::Image2D nbo = cl::Image2D(CLM::get()->context(), CL_MEM_READ_ONLY, formatFloat, m_params->getNbNormals(), 1, 0, NULL, NULL);
    glm::vec3 * normals = m_params->getNormals();
    cl_float4 * normals_f4 = new cl_float4[m_params->getNbNormals()];
    for (int i = 0; i < m_params->getNbNormals(); ++i){
        normals_f4[i].s[0] = normals[i].x;
        normals_f4[i].s[1] = normals[i].y;
        normals_f4[i].s[2] = normals[i].z;
        normals_f4[i].s[3] = 1.f; // Arbitrary value, no meaning
    }
    region[0] = m_params->getNbNormals();
    CLM::get()->queue().enqueueWriteImage(nbo, CL_TRUE, origin, region,
                             0, 0, normals_f4);

    // Offset
    std::vector<glm::vec3> * positions = m_params->getDistribution();
    cl::Image2D offset = cl::Image2D(CLM::get()->context(), CL_MEM_READ_ONLY, formatFloat,positions->size() , 1, 0, NULL, NULL);
    cl_float4 * offset_f4 = new cl_float4[positions->size()];
    for (int i = 0; i < positions->size(); ++i){
        offset_f4[i].s[0] = (*positions)[i].x;
        offset_f4[i].s[1] = (*positions)[i].y;
        offset_f4[i].s[2] = (*positions)[i].z;
        offset_f4[i].s[3] = 1.f; // Arbitrary value, no meaning
    }
    region[0] = positions->size();
    CLM::get()->queue().enqueueWriteImage(offset, CL_TRUE, origin, region, 0, 0, offset_f4);



    // Setting up of the kernel
    m_kernel->setArg(0, local_image);
    m_kernel->setArg(1, vbo);
    m_kernel->setArg(2, ibo);
    m_kernel->setArg(3, nbo);
    m_kernel->setArg(4, offset);


    // Running of kernel
    cl::NDRange global(width,height);
    cl::NDRange local(1,1);
    CLM::get()->queue().enqueueNDRangeKernel(*m_kernel, cl::NullRange, global, local);

    // We copy the GPU object (now filled) on a CPU object
    origin[0] = 0; origin[1] = 0, origin[2] = 0;
    region[0] = width; region[1] = height; region[2] = 1;
    CLM::get()->queue().enqueueReadImage(local_image, CL_TRUE, origin, region,
                             0, 0, image);

    //------------------------------------------------
    // Then we copy this image on the label
    //------------------------------------------------
    QImage qimage(width, height, QImage::Format_ARGB32);

    for (int j = 0; j < height; ++j){
        QRgb * rgb = (QRgb*) qimage.scanLine(height - j - 1);
        for (int i = 0; i < width; ++i){
            int r = image[j * width + i].s[0] * 255;
            int g = image[j * width + i].s[1] * 255;
            int b = image[j * width + i].s[2] * 255;
            int a = image[j * width + i].s[3] * 255;
            rgb[i] = qRgba(r,g,b,a);
        }
    }

    m_label.setPixmap(QPixmap::fromImage(qimage));
    m_label.setAlignment(Qt::AlignCenter);

}