static float compareToNeighbor (const FuzzyCompareParams& params, de::Random& rnd, deUint32 pixel, const ConstPixelBufferAccess& surface, int x, int y)
{
	float minErr = +100.f;

	// (x, y) + (0, 0)
	minErr = deFloatMin(minErr, compareColors(pixel, readUnorm8<NumChannels>(surface, x, y), params.minErrThreshold));
	if (minErr == 0.0f)
		return minErr;

	// Area around (x, y)
	static const int s_coords[][2] =
	{
		{-1, -1},
		{ 0, -1},
		{+1, -1},
		{-1,  0},
		{+1,  0},
		{-1, +1},
		{ 0, +1},
		{+1, +1}
	};

	for (int d = 0; d < (int)DE_LENGTH_OF_ARRAY(s_coords); d++)
	{
		int dx = x + s_coords[d][0];
		int dy = y + s_coords[d][1];

		if (!deInBounds32(dx, 0, surface.getWidth()) || !deInBounds32(dy, 0, surface.getHeight()))
			continue;

		minErr = deFloatMin(minErr, compareColors(pixel, readUnorm8<NumChannels>(surface, dx, dy), params.minErrThreshold));
		if (minErr == 0.0f)
			return minErr;
	}

	// Random bilinear-interpolated samples around (x, y)
	for (int s = 0; s < 32; s++)
	{
		float dx = (float)x + rnd.getFloat()*2.0f - 0.5f;
		float dy = (float)y + rnd.getFloat()*2.0f - 0.5f;

		deUint32 sample = bilinearSample<NumChannels>(surface, dx, dy);

		minErr = deFloatMin(minErr, compareColors(pixel, sample, params.minErrThreshold));
		if (minErr == 0.0f)
			return minErr;
	}

	return minErr;
}
示例#2
0
static const char* qpLookupString (const qpKeyStringMap* keyMap, int keyMapSize, int key)
{
	DE_ASSERT(keyMap);
	DE_ASSERT(deInBounds32(key, 0, keyMapSize));
	DE_ASSERT(keyMap[key].key == key);
	DE_UNREF(keyMapSize); /* for asserting only */
	return keyMap[key].string;
}
static const char* getLoopCountTypeName (LoopCountType countType)
{
	static const char* s_names[] =
	{
		"constant",
		"uniform",
		"dynamic"
	};

	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == LOOPCOUNT_LAST);
	DE_ASSERT(deInBounds32((int)countType, 0, LOOPCOUNT_LAST));
	return s_names[(int)countType];
}
static const char* getLoopTypeName (LoopType loopType)
{
	static const char* s_names[] =
	{
		"for",
		"while",
		"do_while"
	};

	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == LOOPTYPE_LAST);
	DE_ASSERT(deInBounds32((int)loopType, 0, LOOPTYPE_LAST));
	return s_names[(int)loopType];
}
static const char* getLoopCaseName (LoopCase loopCase)
{
	static const char* s_names[] =
	{
		"empty_body",
		"infinite_with_unconditional_break_first",
		"infinite_with_unconditional_break_last",
		"infinite_with_conditional_break",
		"single_statement",
		"compound_statement",
		"sequence_statement",
		"no_iterations",
		"single_iteration",
		"select_iteration_count",
		"conditional_continue",
		"unconditional_continue",
		"only_continue",
		"double_continue",
		"conditional_break",
		"unconditional_break",
		"pre_increment",
		"post_increment",
		"mixed_break_continue",
		"vector_counter",
		"101_iterations",
		"sequence",
		"nested",
		"nested_sequence",
		"nested_tricky_dataflow_1",
		"nested_tricky_dataflow_2"
		//"multi_declaration",
	};

	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == LOOPCASE_LAST);
	DE_ASSERT(deInBounds32((int)loopCase, 0, LOOPCASE_LAST));
	return s_names[(int)loopCase];
}
示例#6
0
void dePoolHash_selfTest (void)
{
	deMemPool*	pool	= deMemPool_createRoot(DE_NULL, 0);
	deTestHash*	hash	= deTestHash_create(pool);
	int			iter;

	for (iter = 0; iter < 3; iter++)
	{
		int i;

		/* Test find() on empty hash. */
		DE_TEST_ASSERT(deTestHash_getNumElements(hash) == 0);
		for (i = 0; i < 15000; i++)
		{
			const int* val = deTestHash_find(hash, (deInt16)i);
			DE_TEST_ASSERT(!val);
		}

		/* Test insert(). */
		for (i = 0; i < 5000; i++)
		{
			deTestHash_insert(hash, (deInt16)i, -i);
		}

		DE_TEST_ASSERT(deTestHash_getNumElements(hash) == 5000);
		for (i = 0; i < 5000; i++)
		{
			const int* val = deTestHash_find(hash, (deInt16)i);
			DE_TEST_ASSERT(val && (*val == -i));
		}

		/* Test delete(). */
		for (i = 0; i < 1000; i++)
			deTestHash_delete(hash, (deInt16)i);

		DE_TEST_ASSERT(deTestHash_getNumElements(hash) == 4000);
		for (i = 0; i < 25000; i++)
		{
			const int* val = deTestHash_find(hash, (deInt16)i);
			if (deInBounds32(i, 1000, 5000))
				DE_TEST_ASSERT(val && (*val == -i));
			else
				DE_TEST_ASSERT(!val);
		}

		/* Test insert() after delete(). */
		for (i = 10000; i < 12000; i++)
			deTestHash_insert(hash, (deInt16)i, -i);

		for (i = 0; i < 25000; i++)
		{
			const int* val = deTestHash_find(hash, (deInt16)i);
			if (deInBounds32(i, 1000, 5000) || deInBounds32(i, 10000, 12000))
				DE_TEST_ASSERT(val && (*val == -i));
			else
				DE_TEST_ASSERT(!val);
		}

		/* Test iterator. */
		{
			deTestHashIter	testIter;
			int				numFound = 0;

			for (deTestHashIter_init(hash, &testIter); deTestHashIter_hasItem(&testIter); deTestHashIter_next(&testIter))
			{
				deInt16	key	= deTestHashIter_getKey(&testIter);
				int		val	= deTestHashIter_getValue(&testIter);
				DE_TEST_ASSERT(deInBounds32(key, 1000, 5000) || deInBounds32(key, 10000, 12000));
				DE_TEST_ASSERT(*deTestHash_find(hash, key) == -key);
				DE_TEST_ASSERT(val == -key);
				numFound++;
			}

			DE_TEST_ASSERT(numFound == deTestHash_getNumElements(hash));
		}

		/* Test copy-to-array. */
		{
			deTestInt16Array*	keyArray	= deTestInt16Array_create(pool);
			deTestIntArray*		valueArray	= deTestIntArray_create(pool);
			int					numElements	= deTestHash_getNumElements(hash);
			int					ndx;

			deTestHash_copyToArray(hash, keyArray, DE_NULL);
			DE_TEST_ASSERT(deTestInt16Array_getNumElements(keyArray) == numElements);

			deTestHash_copyToArray(hash, DE_NULL, valueArray);
			DE_TEST_ASSERT(deTestIntArray_getNumElements(valueArray) == numElements);

			deTestInt16Array_setSize(keyArray, 0);
			deTestIntArray_setSize(valueArray, 0);
			deTestHash_copyToArray(hash, keyArray, valueArray);
			DE_TEST_ASSERT(deTestInt16Array_getNumElements(keyArray) == numElements);
			DE_TEST_ASSERT(deTestIntArray_getNumElements(valueArray) == numElements);

			for (ndx = 0; ndx < numElements; ndx++)
			{
				deInt16 key = deTestInt16Array_get(keyArray, ndx);
				int		val = deTestIntArray_get(valueArray, ndx);

				DE_TEST_ASSERT(val == -key);
				DE_TEST_ASSERT(*deTestHash_find(hash, key) == val);
			}
		}

		/* Test reset(). */
		deTestHash_reset(hash);
		DE_TEST_ASSERT(deTestHash_getNumElements(hash) == 0);
	}

	deMemPool_destroy(pool);
}