2014-07-03 00:30:04 +04:00
|
|
|
/* test_YCoCg.c
|
|
|
|
* vi:ts=4 sw=4
|
|
|
|
*
|
|
|
|
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2014-07-03 00:30:04 +04:00
|
|
|
|
|
|
|
#include <winpr/sysinfo.h>
|
|
|
|
#include "prim_test.h"
|
2017-02-13 18:09:28 +03:00
|
|
|
#include <freerdp/utils/profiler.h>
|
2014-07-03 00:30:04 +04:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2017-02-13 18:09:28 +03:00
|
|
|
static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height)
|
2014-07-03 00:30:04 +04:00
|
|
|
{
|
2017-02-16 14:14:36 +03:00
|
|
|
pstatus_t status = -1;
|
2017-02-13 18:09:28 +03:00
|
|
|
BYTE* out_sse = NULL;
|
|
|
|
BYTE* in = NULL;
|
|
|
|
BYTE* out_c = NULL;
|
|
|
|
const UINT32 srcStride = width * 4;
|
|
|
|
const UINT32 size = srcStride * height;
|
2019-11-06 17:24:51 +03:00
|
|
|
const UINT32 formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_RGBA32,
|
|
|
|
PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_DEFINE(genericProf)
|
|
|
|
PROFILER_DEFINE(optProf)
|
2023-03-24 14:57:57 +03:00
|
|
|
in = winpr_aligned_calloc(1, size, 16);
|
|
|
|
out_c = winpr_aligned_calloc(1, size, 16);
|
|
|
|
out_sse = winpr_aligned_calloc(1, size, 16);
|
2016-07-13 15:04:48 +03:00
|
|
|
|
2017-02-13 18:09:28 +03:00
|
|
|
if (!in || !out_c || !out_sse)
|
|
|
|
goto fail;
|
2016-07-13 15:04:48 +03:00
|
|
|
|
2017-06-06 15:01:41 +03:00
|
|
|
winpr_RAND(in, size);
|
2016-07-13 15:04:48 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < sizeof(formats) / sizeof(formats[0]); x++)
|
2017-02-13 18:09:28 +03:00
|
|
|
{
|
|
|
|
const UINT32 format = formats[x];
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 dstStride = width * FreeRDPGetBytesPerPixel(format);
|
2017-11-24 15:19:48 +03:00
|
|
|
const char* formatName = FreeRDPGetColorFormatName(format);
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_CREATE(genericProf, "YCoCgRToRGB_8u_AC4R-GENERIC")
|
|
|
|
PROFILER_CREATE(optProf, "YCoCgRToRGB_8u_AC4R-OPT")
|
|
|
|
PROFILER_ENTER(genericProf)
|
2019-11-06 17:24:51 +03:00
|
|
|
status = generic->YCoCgToRGB_8u_AC4R(in, srcStride, out_c, format, dstStride, width, height,
|
|
|
|
2, TRUE);
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_EXIT(genericProf)
|
2016-07-13 15:04:48 +03:00
|
|
|
|
|
|
|
if (status != PRIMITIVES_SUCCESS)
|
2017-02-16 14:14:36 +03:00
|
|
|
goto loop_fail;
|
2017-02-13 18:09:28 +03:00
|
|
|
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_ENTER(optProf)
|
2019-11-06 17:24:51 +03:00
|
|
|
status = optimized->YCoCgToRGB_8u_AC4R(in, srcStride, out_sse, format, dstStride, width,
|
|
|
|
height, 2, TRUE);
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_EXIT(optProf)
|
2017-02-13 18:09:28 +03:00
|
|
|
|
2016-07-13 15:04:48 +03:00
|
|
|
if (status != PRIMITIVES_SUCCESS)
|
2017-02-16 14:14:36 +03:00
|
|
|
goto loop_fail;
|
2014-07-03 00:30:04 +04:00
|
|
|
|
2017-02-13 18:09:28 +03:00
|
|
|
if (memcmp(out_c, out_sse, dstStride * height) != 0)
|
2014-07-03 00:30:04 +04:00
|
|
|
{
|
2024-02-15 15:10:45 +03:00
|
|
|
for (size_t i = 0; i < 1ull * width * height; ++i)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 c = FreeRDPReadColor(out_c + 4 * i, format);
|
|
|
|
const UINT32 sse = FreeRDPReadColor(out_sse + 4 * i, format);
|
2017-02-13 18:09:28 +03:00
|
|
|
|
|
|
|
if (c != sse)
|
|
|
|
{
|
2024-04-17 22:56:37 +03:00
|
|
|
printf("optimized->YCoCgRToRGB FAIL[%s] [%" PRIuz "]: 0x%08" PRIx32
|
2019-11-06 17:24:51 +03:00
|
|
|
" -> C 0x%08" PRIx32 " vs optimized 0x%08" PRIx32 "\n",
|
2017-02-13 18:09:28 +03:00
|
|
|
formatName, i, in[i + 1], c, sse);
|
|
|
|
status = -1;
|
|
|
|
}
|
2014-07-03 00:30:04 +04:00
|
|
|
}
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("--------------------------- [%s] [%" PRIu32 "x%" PRIu32
|
|
|
|
"] ---------------------------\n",
|
2017-02-16 14:14:36 +03:00
|
|
|
formatName, width, height);
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_PRINT_HEADER
|
|
|
|
PROFILER_PRINT(genericProf)
|
|
|
|
PROFILER_PRINT(optProf)
|
|
|
|
PROFILER_PRINT_FOOTER
|
2017-02-16 14:14:36 +03:00
|
|
|
loop_fail:
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_FREE(genericProf)
|
|
|
|
PROFILER_FREE(optProf)
|
2017-02-16 14:14:36 +03:00
|
|
|
|
|
|
|
if (status != PRIMITIVES_SUCCESS)
|
|
|
|
goto fail;
|
2014-07-03 00:30:04 +04:00
|
|
|
}
|
2016-07-13 15:04:48 +03:00
|
|
|
|
2017-02-13 18:09:28 +03:00
|
|
|
fail:
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(in);
|
|
|
|
winpr_aligned_free(out_c);
|
|
|
|
winpr_aligned_free(out_sse);
|
2017-02-13 18:09:28 +03:00
|
|
|
return status == PRIMITIVES_SUCCESS;
|
2014-07-03 00:30:04 +04:00
|
|
|
}
|
2014-09-04 23:46:20 +04:00
|
|
|
|
|
|
|
int TestPrimitivesYCoCg(int argc, char* argv[])
|
|
|
|
{
|
2020-09-07 11:42:28 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
2016-07-13 15:04:48 +03:00
|
|
|
prim_test_setup(FALSE);
|
2014-09-04 23:46:20 +04:00
|
|
|
|
2017-02-16 14:14:36 +03:00
|
|
|
/* Random resolution tests */
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < 10; x++)
|
2017-02-16 14:14:36 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 w = 0;
|
|
|
|
UINT32 h = 0;
|
2017-02-16 14:14:36 +03:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2023-06-20 10:03:21 +03:00
|
|
|
winpr_RAND(&w, sizeof(w));
|
2021-06-02 16:46:27 +03:00
|
|
|
w %= 2048 / 4;
|
2019-11-06 17:24:51 +03:00
|
|
|
} while (w < 16);
|
2017-02-16 14:14:36 +03:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2023-06-20 10:03:21 +03:00
|
|
|
winpr_RAND(&h, sizeof(h));
|
2021-06-02 16:46:27 +03:00
|
|
|
h %= 2048 / 4;
|
2019-11-06 17:24:51 +03:00
|
|
|
} while (h < 16);
|
2017-02-16 14:14:36 +03:00
|
|
|
|
|
|
|
if (!test_YCoCgRToRGB_8u_AC4R_func(w, h))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-02 16:46:27 +03:00
|
|
|
/* Test once with full HD/4 */
|
|
|
|
if (!test_YCoCgRToRGB_8u_AC4R_func(1920 / 4, 1080 / 4))
|
2014-09-04 23:46:20 +04:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|