2 #include <freerdp/config.h>
7 #include <winpr/print.h>
9 #include <freerdp/freerdp.h>
10 #include <freerdp/codec/color.h>
11 #include <freerdp/codec/bitmap.h>
12 #include <freerdp/codec/interleaved.h>
13 #include <winpr/crypto.h>
14 #include <freerdp/utils/profiler.h>
16 static BOOL run_encode_decode_single(UINT16 bpp, BITMAP_INTERLEAVED_CONTEXT* encoder,
17 BITMAP_INTERLEAVED_CONTEXT* decoder
18 #
if defined(WITH_PROFILER)
20 PROFILER* profiler_comp, PROFILER* profiler_decomp
30 const UINT32 format = PIXEL_FORMAT_RGBX32;
31 const UINT32 bstep = FreeRDPGetBytesPerPixel(format);
32 const size_t step = (13ULL + w) * 4ULL;
33 const size_t SrcSize = step * h;
34 const float maxDiff = 4.0f * ((bpp < 24) ? 2.0f : 1.0f);
35 UINT32 DstSize = SrcSize;
36 BYTE* pSrcData = calloc(1, SrcSize);
37 BYTE* pDstData = calloc(1, SrcSize);
38 BYTE* tmp = calloc(1, SrcSize);
40 if (!pSrcData || !pDstData || !tmp)
43 winpr_RAND(pSrcData, SrcSize);
45 if (!bitmap_interleaved_context_reset(encoder) || !bitmap_interleaved_context_reset(decoder))
48 PROFILER_ENTER(profiler_comp)
50 interleaved_compress(encoder, tmp, &DstSize, w, h, pSrcData, format, step, x, y, NULL, bpp);
51 PROFILER_EXIT(profiler_comp)
56 PROFILER_ENTER(profiler_decomp)
57 rc = interleaved_decompress(decoder, tmp, DstSize, w, h, bpp, pDstData, format, step, x, y, w,
59 PROFILER_EXIT(profiler_decomp)
64 for (UINT32 i = 0; i < h; i++)
66 const BYTE* srcLine = &pSrcData[i * step];
67 const BYTE* dstLine = &pDstData[i * step];
69 for (UINT32 j = 0; j < w; j++)
77 const UINT32 srcColor = FreeRDPReadColor(&srcLine[1ULL * j * bstep], format);
78 const UINT32 dstColor = FreeRDPReadColor(&dstLine[1ULL * j * bstep], format);
79 FreeRDPSplitColor(srcColor, format, &r, &g, &b, NULL, NULL);
80 FreeRDPSplitColor(dstColor, format, &dr, &dg, &db, NULL, NULL);
82 if (fabsf((
float)r - dr) > maxDiff)
85 if (fabsf((
float)g - dg) > maxDiff)
88 if (fabsf((
float)b - db) > maxDiff)
101 static const char* get_profiler_name(BOOL encode, UINT16 bpp)
107 return "interleaved_compress 24bpp";
109 return "interleaved_decompress 24bpp";
113 return "interleaved_compress 16bpp";
115 return "interleaved_decompress 16bpp";
119 return "interleaved_compress 15bpp";
121 return "interleaved_decompress 15bpp";
124 return "configuration error!";
128 static BOOL run_encode_decode(UINT16 bpp, BITMAP_INTERLEAVED_CONTEXT* encoder,
129 BITMAP_INTERLEAVED_CONTEXT* decoder)
132 PROFILER_DEFINE(profiler_comp)
133 PROFILER_DEFINE(profiler_decomp)
134 PROFILER_CREATE(profiler_comp, get_profiler_name(TRUE, bpp))
135 PROFILER_CREATE(profiler_decomp, get_profiler_name(FALSE, bpp))
137 for (UINT32 x = 0; x < 50; x++)
139 if (!run_encode_decode_single(bpp, encoder, decoder
140 #
if defined(WITH_PROFILER)
142 profiler_comp, profiler_decomp
150 PROFILER_PRINT_HEADER
151 PROFILER_PRINT(profiler_comp)
152 PROFILER_PRINT(profiler_decomp)
153 PROFILER_PRINT_FOOTER
154 PROFILER_FREE(profiler_comp)
155 PROFILER_FREE(profiler_decomp)
159 static BOOL TestColorConversion(
void)
161 const UINT32 formats[] = { PIXEL_FORMAT_RGB15, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_ABGR15,
162 PIXEL_FORMAT_ARGB15, PIXEL_FORMAT_BGR16, PIXEL_FORMAT_RGB16 };
165 for (UINT32 x = 0; x < ARRAYSIZE(formats); x++)
167 const UINT32 dstFormat = PIXEL_FORMAT_RGBA32;
168 const UINT32 format = formats[x];
169 const UINT32 colorLow = FreeRDPGetColor(format, 0, 0, 0, 255);
170 const UINT32 colorHigh = FreeRDPGetColor(format, 255, 255, 255, 255);
171 const UINT32 colorLow32 = FreeRDPConvertColor(colorLow, format, dstFormat, NULL);
172 const UINT32 colorHigh32 = FreeRDPConvertColor(colorHigh, format, dstFormat, NULL);
177 FreeRDPSplitColor(colorLow32, dstFormat, &r, &g, &b, &a, NULL);
178 if ((r != 0) || (g != 0) || (b != 0))
181 FreeRDPSplitColor(colorHigh32, dstFormat, &r, &g, &b, &a, NULL);
182 if ((r != 255) || (g != 255) || (b != 255))
189 int TestFreeRDPCodecInterleaved(
int argc,
char* argv[])
191 BITMAP_INTERLEAVED_CONTEXT* encoder = NULL;
192 BITMAP_INTERLEAVED_CONTEXT* decoder = NULL;
196 encoder = bitmap_interleaved_context_new(TRUE);
197 decoder = bitmap_interleaved_context_new(FALSE);
199 if (!encoder || !decoder)
202 if (!run_encode_decode(24, encoder, decoder))
205 if (!run_encode_decode(16, encoder, decoder))
208 if (!run_encode_decode(15, encoder, decoder))
211 if (!TestColorConversion())
216 bitmap_interleaved_context_free(encoder);
217 bitmap_interleaved_context_free(decoder);