MCPcopy Create free account
hub / github.com/GPUOpen-Tools/compressonator / RunChannelTest

Function RunChannelTest

cmp_unittests/codecbuffer_tests.cpp:327–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325
326template <typename T>
327static void RunChannelTest(CCodecBuffer* buffer, TestChannel testChannel, bool convertedType = false)
328{
329 T* srcData = GetSrcDataOfType<T>();
330
331 bool noAlpha = testChannel == ALPHA_CHANNEL && buffer->GetChannelCount() < 4;
332
333 bool error = false;
334
335 if (testChannel == RED_CHANNEL)
336 error = buffer->WriteBlockR(0, 0, 4, 4, srcData);
337 else if (testChannel == GREEN_CHANNEL)
338 error = buffer->WriteBlockG(0, 0, 4, 4, srcData);
339 else if (testChannel == BLUE_CHANNEL)
340 error = buffer->WriteBlockB(0, 0, 4, 4, srcData);
341 else if (testChannel == ALPHA_CHANNEL)
342 error = buffer->WriteBlockA(0, 0, 4, 4, srcData);
343
344 if (noAlpha)
345 CHECK_FALSE(error);
346 else
347 CHECK(error);
348
349 // check data from raw pointer to make sure it is correct
350 // we can only check the raw pointer for types that are native to the codec, otherwise the conversion will result in expected values
351 if (!convertedType)
352 {
353 uint channelCount = buffer->GetChannelCount();
354 uint channelIndex = 0;
355
356 if (testChannel == RED_CHANNEL)
357 channelIndex = RGBA8888_CHANNEL_R;
358 else if (testChannel == GREEN_CHANNEL)
359 channelIndex = RGBA8888_CHANNEL_G;
360 else if (testChannel == BLUE_CHANNEL)
361 channelIndex = RGBA8888_CHANNEL_B;
362 else if (testChannel == ALPHA_CHANNEL)
363 channelIndex = RGBA8888_CHANNEL_A;
364
365 CMP_BYTE* bufferData = buffer->GetData();
366 for (int i = 0; i < 16 * channelCount; ++i)
367 {
368 if (!noAlpha && i % channelCount == channelIndex)
369 CHECK(bufferData[i] == (CMP_BYTE)srcData[i / channelCount]);
370 else
371 CHECK(bufferData[i] == 0);
372 }
373 }
374
375 // verify each channel's read functions
376
377 VerifyRedChannel<T>(buffer, 0, 0, 4, 4, testChannel != RED_CHANNEL);
378 VerifyGreenChannel<T>(buffer, 0, 0, 4, 4, testChannel != GREEN_CHANNEL);
379 VerifyBlueChannel<T>(buffer, 0, 0, 4, 4, testChannel != BLUE_CHANNEL);
380 VerifyAlphaChannel<T>(buffer, 0, 0, 4, 4, noAlpha || testChannel != ALPHA_CHANNEL);
381
382 VerifyRGBA<T>(buffer, 0, 0, 4, 4, testChannel, convertedType);
383}
384

Callers

nothing calls this directly

Calls 6

GetDataMethod · 0.80
GetChannelCountMethod · 0.45
WriteBlockRMethod · 0.45
WriteBlockGMethod · 0.45
WriteBlockBMethod · 0.45
WriteBlockAMethod · 0.45

Tested by

no test coverage detected