void KisTransformMaskTest::testMaskOnCloneLayer()
{
    QImage refImage(TestUtil::fetchDataFileLazy("test_transform_quality.png"));
    QRect refRect = refImage.rect();
    TestUtil::MaskParent p(refRect);

    p.layer->paintDevice()->convertFromQImage(refImage, 0);

    KisPaintLayerSP player = new KisPaintLayer(p.image, "bg", OPACITY_OPAQUE_U8, p.image->colorSpace());
    p.image->addNode(player, p.image->root(), KisNodeSP());

    KisCloneLayerSP clone = new KisCloneLayer(p.layer, p.image, "clone", OPACITY_OPAQUE_U8);
    p.image->addNode(clone, p.image->root());

    KisTransformMaskSP mask = new KisTransformMask();
    p.image->addNode(mask, clone);

    QTransform transform(-0.177454, -0.805953, -0.00213713,
                         -1.9295, -0.371835, -0.00290463,
                         3075.05, 2252.32, 7.62371);

    mask->setTransformParams(KisTransformMaskParamsInterfaceSP(
                                 new KisDumbTransformMaskParams(transform)));

    QVERIFY(doPartialTests("cl", p.image, p.layer, clone, mask));
}
Example #2
0
Genpix::Genpix(char *inIMG, char *refimage, double lowL, double highL, double lowB, double highB, int oversample)
try : m_instrument(0) {
  
  // Create reference image containing WCS parameters:
  std::cout << "[Genpix]: Ref image =" << refimage << std::endl;
  Pix::Image refImage(refimage);

  std::cout << "[Genpix]: Processing for instrument " << refImage.instrument() << " will be run." << std::endl;
  
  m_instrument = Pix::Factory::createInstrument(refImage.instrument());
  m_instrument->setup(inIMG, refImage, lowL, highL, lowB, highB, oversample);
  
  // Run the processing:
  m_instrument->run_loop();
  
      } catch ( ... ) { std::cerr << "Genpix::Genpix: ERROR in member initialization." << std::endl; }
/*
 * Compute the measure distance between pairs of images in a folder
 * @parameter 1: folderPath - the path of images folder
 * @parameter 2: method - the matching method
 * @parameter 3: angleAcc - the angle accuracy
 * @parameter 4: distanceAcc - the distance accuracy
 */
void GeometricHistogram::phgHistogramDirMatching(string folderPath,
		MatchingMethod method, LocalHistogram::AccuracyPGH angleAcc,
		int distanceAcc) {
	QFileInfoList files = Image::readImagesFolder(folderPath);

	QString refName;
	QString sceneName;
	ofstream of("matching_result.txt");

	for (int i = 0; i < files.size(); i++) {
		QFileInfo reffile = files.at(i);
		QString _name = reffile.absoluteFilePath();
		int index2 = _name.lastIndexOf("/");
		refName = _name.mid(index2 + 1, _name.length() - index2).replace(" ",
				"");
		Image refImage(_name.toStdString());
		ShapeHistogram refHist = refImage.getShapeHistogram();
		vector<LocalHistogram>refLocalHist = refHist.constructPGH(refImage.lineSegment());
		refHist.constructMatPGH(refLocalHist, angleAcc, distanceAcc);
		of << refName.toStdString() << "\t";
		for (int j = 0; j < files.size(); j++) {
			if (j >= i) {
				QFileInfo scenefile = files.at(j);
				QString _name2 = scenefile.absoluteFilePath();
				int index2 = _name2.lastIndexOf("/");
				sceneName =
						_name2.mid(index2 + 1, _name2.length() - index2).replace(
								" ", "");
				Image sceneImage(_name2.toStdString());
				ShapeHistogram sceneHist = sceneImage.getShapeHistogram();
				vector<LocalHistogram> sceneLocalHists = sceneHist.constructPGH(sceneImage.lineSegment());
				sceneHist.constructMatPGH(sceneLocalHists, angleAcc, distanceAcc);
				double distance = getDistanceMetric(refHist, sceneHist, method);

				of << distance << "\t";
				qDebug() << refName << "\t" << sceneName;
				qDebug() << "Metric: " << QString::number(distance, 'f', 20);
			} else {
				of << "\t";
			}

		}
		of << "\n";
	}
	of.close();

}
void KisAsyncMergerTest::testSubgraphingWithoutUpdatingParent()
{
    const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(0, 128, 128, colorSpace, "clones test");

    KisPaintDeviceSP device1 = new KisPaintDevice(colorSpace);
    device1->fill(image->bounds(), KoColor(Qt::white, colorSpace));
    KisLayerSP paintLayer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, device1);

    KisPaintDeviceSP device2 = new KisPaintDevice(colorSpace);
    device2->fill(image->bounds(), KoColor(Qt::black, colorSpace));
    KisLayerSP paintLayer2 = new KisPaintLayer(image, "paint2", 128, device2);

    image->addNode(paintLayer1, image->rootLayer());
    image->addNode(paintLayer2, image->rootLayer());

    image->initialRefreshGraph();

    QImage refImage(QString(FILES_DATA_DIR) + QDir::separator() + "subgraphing_without_updating.png");

    {
        QImage resultImage = image->projection()->convertToQImage(0);
        QCOMPARE(resultImage, refImage);
    }

    QRect cropRect(image->bounds());

    KisRefreshSubtreeWalker walker(cropRect);
    KisAsyncMerger merger;

    walker.collectRects(paintLayer2, image->bounds());
    merger.startMerge(walker);

    {
        QImage resultImage = image->projection()->convertToQImage(0);
        QCOMPARE(resultImage, refImage);
    }
}
TestCase::IterateResult ReadPixelsCase::iterate (void)
{
	const tcu::RenderTarget&	renderTarget	= m_context.getRenderTarget();
	tcu::PixelFormat			pixelFormat		= renderTarget.getPixelFormat();
	int							targetWidth		= renderTarget.getWidth();
	int							targetHeight	= renderTarget.getHeight();
	int							x				= 0;
	int							y				= 0;
	int							imageWidth		= 0;
	int							imageHeight		= 0;

	deRandom rnd;
	deRandom_init(&rnd, deInt32Hash(m_curIter));

	switch (m_curIter)
	{
		case 0:
			// Fullscreen
			x = 0;
			y = 0;
			imageWidth  = targetWidth;
			imageHeight = targetHeight;
			break;
		case 1:
			// Upper left corner
			x = 0;
			y = 0;
			imageWidth = targetWidth / 2;
			imageHeight = targetHeight / 2;
			break;
		case 2:
			// Lower right corner
			x = targetWidth / 2;
			y = targetHeight / 2;
			imageWidth = targetWidth - x;
			imageHeight = targetHeight - y;
			break;
		default:
			x = deRandom_getUint32(&rnd) % (targetWidth - 1);
			y = deRandom_getUint32(&rnd) % (targetHeight - 1);
			imageWidth = 1 + (deRandom_getUint32(&rnd) % (targetWidth - x - 1));
			imageHeight = 1 + (deRandom_getUint32(&rnd) % (targetHeight - y - 1));
			break;
	}

	Surface	resImage(imageWidth, imageHeight);
	Surface	refImage(imageWidth, imageHeight);
	Surface	diffImage(imageWidth, imageHeight);

	int r = (int)(deRandom_getUint32(&rnd) & 0xFF);
	int g = (int)(deRandom_getUint32(&rnd) & 0xFF);
	int b = (int)(deRandom_getUint32(&rnd) & 0xFF);

	tcu::clear(refImage.getAccess(), tcu::IVec4(r, g, b, 255));
	glClearColor(r/255.0f, g/255.0f, b/255.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	glu::readPixels(m_context.getRenderContext(), x, y, resImage.getAccess());
	GLU_CHECK_MSG("glReadPixels() failed.");

	RGBA colorThreshold = pixelFormat.getColorThreshold();
	RGBA matchColor(0, 255, 0, 255);
	RGBA diffColor(255, 0, 0, 255);
	bool isImageOk = true;

	for (int j = 0; j < imageHeight; j++)
	{
		for (int i = 0; i < imageWidth; i++)
		{
			RGBA		resRGBA		= resImage.getPixel(i, j);
			RGBA		refRGBA		= refImage.getPixel(i, j);
			bool		isPixelOk	= compareThreshold(refRGBA, resRGBA, colorThreshold);
			diffImage.setPixel(i, j, isPixelOk ? matchColor : diffColor);

			isImageOk = isImageOk && isPixelOk;
		}
	}

	if (isImageOk)
		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
	else
	{
		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");

		TestLog& log = m_testCtx.getLog();
		log << TestLog::ImageSet("Result", "Resulting framebuffer")
			<< TestLog::Image("Result",		"Resulting framebuffer",	resImage)
			<< TestLog::Image("Reference",	"Reference image",			refImage)
			<< TestLog::Image("DiffMask",	"Failing pixels",			diffImage)
			<< TestLog::EndImageSet;
	}

	return (++m_curIter < m_numIters) ? CONTINUE : STOP;
}