FreeRDP
Loading...
Searching...
No Matches
TestPrimitivesYCoCg.c
1/* test_YCoCg.c
2 * vi:ts=4 sw=4
3 *
4 * (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include <freerdp/config.h>
20
21#include <winpr/sysinfo.h>
22#include "prim_test.h"
23#include <freerdp/utils/profiler.h>
24
25/* ------------------------------------------------------------------------- */
26static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height)
27{
28 pstatus_t status = -1;
29 BYTE* out_sse = nullptr;
30 BYTE* in = nullptr;
31 BYTE* out_c = nullptr;
32 const UINT32 srcStride = width * 4;
33 const UINT32 size = srcStride * height;
34 const UINT32 formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_RGBA32,
35 PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
36 PROFILER_DEFINE(genericProf)
37 PROFILER_DEFINE(optProf)
38 in = winpr_aligned_calloc(1, size, 16);
39 out_c = winpr_aligned_calloc(1, size, 16);
40 out_sse = winpr_aligned_calloc(1, size, 16);
41
42 if (!in || !out_c || !out_sse)
43 goto fail;
44
45 if (winpr_RAND(in, size) < 0)
46 goto fail;
47
48 for (size_t x = 0; x < sizeof(formats) / sizeof(formats[0]); x++)
49 {
50 const UINT32 format = formats[x];
51 const UINT32 dstStride = width * FreeRDPGetBytesPerPixel(format);
52 const char* formatName = FreeRDPGetColorFormatName(format);
53 PROFILER_CREATE(genericProf, "YCoCgRToRGB_8u_AC4R-GENERIC")
54 PROFILER_CREATE(optProf, "YCoCgRToRGB_8u_AC4R-OPT")
55 PROFILER_ENTER(genericProf)
56 status = generic->YCoCgToRGB_8u_AC4R(in, WINPR_ASSERTING_INT_CAST(int, srcStride), out_c,
57 format, WINPR_ASSERTING_INT_CAST(int, dstStride),
58 width, height, 2, TRUE);
59 PROFILER_EXIT(genericProf)
60
61 if (status != PRIMITIVES_SUCCESS)
62 goto loop_fail;
63
64 PROFILER_ENTER(optProf)
65 status = optimized->YCoCgToRGB_8u_AC4R(
66 in, WINPR_ASSERTING_INT_CAST(int, srcStride), out_sse, format,
67 WINPR_ASSERTING_INT_CAST(int, dstStride), width, height, 2, TRUE);
68 PROFILER_EXIT(optProf)
69
70 if (status != PRIMITIVES_SUCCESS)
71 goto loop_fail;
72
73 if (memcmp(out_c, out_sse, 1ULL * dstStride * height) != 0)
74 {
75 for (size_t i = 0; i < 1ull * width * height; ++i)
76 {
77 const UINT32 c = FreeRDPReadColor(out_c + 4 * i, format);
78 const UINT32 sse = FreeRDPReadColor(out_sse + 4 * i, format);
79
80 if (c != sse)
81 {
82 printf("optimized->YCoCgRToRGB FAIL[%s] [%" PRIuz "]: 0x%08" PRIx32
83 " -> C 0x%08" PRIx32 " vs optimized 0x%08" PRIx32 "\n",
84 formatName, i, in[i + 1], c, sse);
85 status = -1;
86 }
87 }
88 }
89
90 printf("--------------------------- [%s] [%" PRIu32 "x%" PRIu32
91 "] ---------------------------\n",
92 formatName, width, height);
93 PROFILER_PRINT_HEADER
94 PROFILER_PRINT(genericProf)
95 PROFILER_PRINT(optProf)
96 PROFILER_PRINT_FOOTER
97 loop_fail:
98 PROFILER_FREE(genericProf)
99 PROFILER_FREE(optProf)
100
101 if (status != PRIMITIVES_SUCCESS)
102 goto fail;
103 }
104
105fail:
106 winpr_aligned_free(in);
107 winpr_aligned_free(out_c);
108 winpr_aligned_free(out_sse);
109 return status == PRIMITIVES_SUCCESS;
110}
111
112int TestPrimitivesYCoCg(int argc, char* argv[])
113{
114 WINPR_UNUSED(argc);
115 WINPR_UNUSED(argv);
116 prim_test_setup(FALSE);
117
118 /* Random resolution tests */
119 if (argc < 2)
120 {
121 for (UINT32 x = 0; x < 10; x++)
122 {
123 UINT32 w = 0;
124 UINT32 h = 0;
125
126 do
127 {
128 if (winpr_RAND(&w, sizeof(w)) < 0)
129 return -1;
130 w %= 2048 / 4;
131 } while (w < 16);
132
133 do
134 {
135 if (winpr_RAND(&h, sizeof(h)) < 0)
136 return -1;
137 h %= 2048 / 4;
138 } while (h < 16);
139
140 if (!test_YCoCgRToRGB_8u_AC4R_func(w, h))
141 return 1;
142 }
143 }
144
145 /* Test once with full HD/4 */
146 if (!test_YCoCgRToRGB_8u_AC4R_func(1920 / 4, 1080 / 4))
147 return 1;
148
149 return 0;
150}