mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
libfreerdp-codec: add NCrush unit tests and tables
This commit is contained in:
@@ -35,6 +35,7 @@ struct _NCRUSH_CONTEXT
|
||||
UINT32 HistoryOffset;
|
||||
UINT32 HistoryBufferSize;
|
||||
BYTE HistoryBuffer[65536];
|
||||
UINT32 OffsetCache[4];
|
||||
};
|
||||
typedef struct _NCRUSH_CONTEXT NCRUSH_CONTEXT;
|
||||
|
||||
|
||||
@@ -27,12 +27,450 @@
|
||||
|
||||
#include <freerdp/codec/ncrush.h>
|
||||
|
||||
int ncrush_compress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE* pDstData, UINT32* pDstSize, UINT32* pFlags)
|
||||
const BYTE NCrushMaskTable[39] =
|
||||
{
|
||||
0x11, /* 0 */
|
||||
0x9E, /* 1 */
|
||||
0xA1, /* 2 */
|
||||
0x00, /* 3 */
|
||||
0x00, /* 4 */
|
||||
0x01, /* 5 */
|
||||
0x00, /* 6 */
|
||||
0x03, /* 7 */
|
||||
0x00, /* 8 */
|
||||
0x07, /* 9 */
|
||||
0x00, /* 10 */
|
||||
0x0F, /* 11 */
|
||||
0x00, /* 12 */
|
||||
0x1F, /* 13 */
|
||||
0x00, /* 14 */
|
||||
0x3F, /* 15 */
|
||||
0x00, /* 16 */
|
||||
0x7F, /* 17 */
|
||||
0x00, /* 18 */
|
||||
0xFF, /* 19 */
|
||||
0x00, /* 20 */
|
||||
0xFF, /* 21 */
|
||||
0x01, /* 22 */
|
||||
0xFF, /* 23 */
|
||||
0x03, /* 24 */
|
||||
0xFF, /* 25 */
|
||||
0x07, /* 26 */
|
||||
0xFF, /* 27 */
|
||||
0x0F, /* 28 */
|
||||
0xFF, /* 29 */
|
||||
0x1F, /* 30 */
|
||||
0xFF, /* 31 */
|
||||
0x3F, /* 32 */
|
||||
0xFF, /* 33 */
|
||||
0x7F, /* 34 */
|
||||
0xFF, /* 35 */
|
||||
0xFF, /* 36 */
|
||||
0x00, /* 37 */
|
||||
0x00 /* 38 */
|
||||
};
|
||||
|
||||
const BYTE HuffLengthLEC[294] =
|
||||
{
|
||||
6, /* 0 */
|
||||
6, /* 1 */
|
||||
6, /* 2 */
|
||||
7, /* 3 */
|
||||
7, /* 4 */
|
||||
7, /* 5 */
|
||||
7, /* 6 */
|
||||
7, /* 7 */
|
||||
7, /* 8 */
|
||||
7, /* 9 */
|
||||
7, /* 10 */
|
||||
8, /* 11 */
|
||||
8, /* 12 */
|
||||
8, /* 13 */
|
||||
8, /* 14 */
|
||||
8, /* 15 */
|
||||
8, /* 16 */
|
||||
8, /* 17 */
|
||||
9, /* 18 */
|
||||
8, /* 19 */
|
||||
9, /* 20 */
|
||||
9, /* 21 */
|
||||
9, /* 22 */
|
||||
9, /* 23 */
|
||||
8, /* 24 */
|
||||
8, /* 25 */
|
||||
9, /* 26 */
|
||||
9, /* 27 */
|
||||
9, /* 28 */
|
||||
9, /* 29 */
|
||||
9, /* 30 */
|
||||
9, /* 31 */
|
||||
8, /* 32 */
|
||||
9, /* 33 */
|
||||
9, /* 34 */
|
||||
10, /* 35 */
|
||||
9, /* 36 */
|
||||
9, /* 37 */
|
||||
9, /* 38 */
|
||||
9, /* 39 */
|
||||
9, /* 40 */
|
||||
9, /* 41 */
|
||||
9, /* 42 */
|
||||
10, /* 43 */
|
||||
9, /* 44 */
|
||||
10, /* 45 */
|
||||
10, /* 46 */
|
||||
10, /* 47 */
|
||||
9, /* 48 */
|
||||
9, /* 49 */
|
||||
10, /* 50 */
|
||||
9, /* 51 */
|
||||
10, /* 52 */
|
||||
9, /* 53 */
|
||||
10, /* 54 */
|
||||
9, /* 55 */
|
||||
9, /* 56 */
|
||||
9, /* 57 */
|
||||
10, /* 58 */
|
||||
10, /* 59 */
|
||||
9, /* 60 */
|
||||
10, /* 61 */
|
||||
9, /* 62 */
|
||||
9, /* 63 */
|
||||
8, /* 64 */
|
||||
9, /* 65 */
|
||||
9, /* 66 */
|
||||
9, /* 67 */
|
||||
9, /* 68 */
|
||||
10, /* 69 */
|
||||
10, /* 70 */
|
||||
10, /* 71 */
|
||||
9, /* 72 */
|
||||
9, /* 73 */
|
||||
10, /* 74 */
|
||||
10, /* 75 */
|
||||
10, /* 76 */
|
||||
10, /* 77 */
|
||||
10, /* 78 */
|
||||
10, /* 79 */
|
||||
9, /* 80 */
|
||||
9, /* 81 */
|
||||
10, /* 82 */
|
||||
10, /* 83 */
|
||||
10, /* 84 */
|
||||
10, /* 85 */
|
||||
10, /* 86 */
|
||||
10, /* 87 */
|
||||
10, /* 88 */
|
||||
9, /* 89 */
|
||||
10, /* 90 */
|
||||
10, /* 91 */
|
||||
10, /* 92 */
|
||||
10, /* 93 */
|
||||
10, /* 94 */
|
||||
10, /* 95 */
|
||||
8, /* 96 */
|
||||
10, /* 97 */
|
||||
10, /* 98 */
|
||||
10, /* 99 */
|
||||
10, /* 100 */
|
||||
10, /* 101 */
|
||||
10, /* 102 */
|
||||
10, /* 103 */
|
||||
10, /* 104 */
|
||||
10, /* 105 */
|
||||
10, /* 106 */
|
||||
10, /* 107 */
|
||||
10, /* 108 */
|
||||
10, /* 109 */
|
||||
10, /* 110 */
|
||||
10, /* 111 */
|
||||
9, /* 112 */
|
||||
10, /* 113 */
|
||||
10, /* 114 */
|
||||
10, /* 115 */
|
||||
10, /* 116 */
|
||||
10, /* 117 */
|
||||
10, /* 118 */
|
||||
10, /* 119 */
|
||||
9, /* 120 */
|
||||
10, /* 121 */
|
||||
10, /* 122 */
|
||||
10, /* 123 */
|
||||
10, /* 124 */
|
||||
10, /* 125 */
|
||||
10, /* 126 */
|
||||
9, /* 127 */
|
||||
7, /* 128 */
|
||||
9, /* 129 */
|
||||
9, /* 130 */
|
||||
10, /* 131 */
|
||||
9, /* 132 */
|
||||
10, /* 133 */
|
||||
10, /* 134 */
|
||||
10, /* 135 */
|
||||
9, /* 136 */
|
||||
10, /* 137 */
|
||||
10, /* 138 */
|
||||
10, /* 139 */
|
||||
10, /* 140 */
|
||||
10, /* 141 */
|
||||
10, /* 142 */
|
||||
10, /* 143 */
|
||||
9, /* 144 */
|
||||
10, /* 145 */
|
||||
10, /* 146 */
|
||||
10, /* 147 */
|
||||
10, /* 148 */
|
||||
10, /* 149 */
|
||||
10, /* 150 */
|
||||
10, /* 151 */
|
||||
10, /* 152 */
|
||||
10, /* 153 */
|
||||
10, /* 154 */
|
||||
10, /* 155 */
|
||||
10, /* 156 */
|
||||
10, /* 157 */
|
||||
10, /* 158 */
|
||||
10, /* 159 */
|
||||
10, /* 160 */
|
||||
10, /* 161 */
|
||||
10, /* 162 */
|
||||
10, /* 163 */
|
||||
10, /* 164 */
|
||||
10, /* 165 */
|
||||
10, /* 166 */
|
||||
10, /* 167 */
|
||||
10, /* 168 */
|
||||
10, /* 169 */
|
||||
10, /* 170 */
|
||||
13, /* 171 */
|
||||
10, /* 172 */
|
||||
10, /* 173 */
|
||||
10, /* 174 */
|
||||
10, /* 175 */
|
||||
10, /* 176 */
|
||||
10, /* 177 */
|
||||
11, /* 178 */
|
||||
10, /* 179 */
|
||||
10, /* 180 */
|
||||
10, /* 181 */
|
||||
10, /* 182 */
|
||||
10, /* 183 */
|
||||
10, /* 184 */
|
||||
10, /* 185 */
|
||||
10, /* 186 */
|
||||
10, /* 187 */
|
||||
10, /* 188 */
|
||||
10, /* 189 */
|
||||
10, /* 190 */
|
||||
10, /* 191 */
|
||||
9, /* 192 */
|
||||
10, /* 193 */
|
||||
10, /* 194 */
|
||||
10, /* 195 */
|
||||
10, /* 196 */
|
||||
10, /* 197 */
|
||||
9, /* 198 */
|
||||
10, /* 199 */
|
||||
10, /* 200 */
|
||||
10, /* 201 */
|
||||
10, /* 202 */
|
||||
10, /* 203 */
|
||||
9, /* 204 */
|
||||
10, /* 205 */
|
||||
10, /* 206 */
|
||||
10, /* 207 */
|
||||
9, /* 208 */
|
||||
10, /* 209 */
|
||||
10, /* 210 */
|
||||
10, /* 211 */
|
||||
10, /* 212 */
|
||||
10, /* 213 */
|
||||
10, /* 214 */
|
||||
10, /* 215 */
|
||||
10, /* 216 */
|
||||
10, /* 217 */
|
||||
10, /* 218 */
|
||||
10, /* 219 */
|
||||
10, /* 220 */
|
||||
10, /* 221 */
|
||||
10, /* 222 */
|
||||
10, /* 223 */
|
||||
9, /* 224 */
|
||||
10, /* 225 */
|
||||
10, /* 226 */
|
||||
10, /* 227 */
|
||||
10, /* 228 */
|
||||
10, /* 229 */
|
||||
10, /* 230 */
|
||||
10, /* 231 */
|
||||
10, /* 232 */
|
||||
10, /* 233 */
|
||||
10, /* 234 */
|
||||
10, /* 235 */
|
||||
10, /* 236 */
|
||||
10, /* 237 */
|
||||
9, /* 238 */
|
||||
10, /* 239 */
|
||||
8, /* 240 */
|
||||
9, /* 241 */
|
||||
9, /* 242 */
|
||||
10, /* 243 */
|
||||
9, /* 244 */
|
||||
10, /* 245 */
|
||||
10, /* 246 */
|
||||
10, /* 247 */
|
||||
9, /* 248 */
|
||||
10, /* 249 */
|
||||
10, /* 250 */
|
||||
10, /* 251 */
|
||||
9, /* 252 */
|
||||
9, /* 253 */
|
||||
8, /* 254 */
|
||||
7, /* 255 */
|
||||
13, /* 256 */
|
||||
13, /* 257 */
|
||||
7, /* 258 */
|
||||
7, /* 259 */
|
||||
10, /* 260 */
|
||||
7, /* 261 */
|
||||
7, /* 262 */
|
||||
6, /* 263 */
|
||||
6, /* 264 */
|
||||
6, /* 265 */
|
||||
6, /* 266 */
|
||||
5, /* 267 */
|
||||
6, /* 268 */
|
||||
6, /* 269 */
|
||||
6, /* 270 */
|
||||
5, /* 271 */
|
||||
6, /* 272 */
|
||||
5, /* 273 */
|
||||
6, /* 274 */
|
||||
6, /* 275 */
|
||||
6, /* 276 */
|
||||
6, /* 277 */
|
||||
6, /* 278 */
|
||||
6, /* 279 */
|
||||
6, /* 280 */
|
||||
6, /* 281 */
|
||||
6, /* 282 */
|
||||
6, /* 283 */
|
||||
6, /* 284 */
|
||||
6, /* 285 */
|
||||
6, /* 286 */
|
||||
6, /* 287 */
|
||||
8, /* 288 */
|
||||
5, /* 289 */
|
||||
6, /* 290 */
|
||||
7, /* 291 */
|
||||
7, /* 292 */
|
||||
13 /* 293 */
|
||||
};
|
||||
|
||||
const BYTE HuffLengthL[32] =
|
||||
{
|
||||
4, /* 0 */
|
||||
2, /* 1 */
|
||||
3, /* 2 */
|
||||
4, /* 3 */
|
||||
3, /* 4 */
|
||||
4, /* 5 */
|
||||
4, /* 6 */
|
||||
5, /* 7 */
|
||||
4, /* 8 */
|
||||
5, /* 9 */
|
||||
5, /* 10 */
|
||||
6, /* 11 */
|
||||
6, /* 12 */
|
||||
7, /* 13 */
|
||||
7, /* 14 */
|
||||
8, /* 15 */
|
||||
7, /* 16 */
|
||||
8, /* 17 */
|
||||
8, /* 18 */
|
||||
9, /* 19 */
|
||||
9, /* 20 */
|
||||
8, /* 21 */
|
||||
9, /* 22 */
|
||||
9, /* 23 */
|
||||
9, /* 24 */
|
||||
9, /* 25 */
|
||||
9, /* 26 */
|
||||
9, /* 27 */
|
||||
9, /* 28 */
|
||||
9, /* 29 */
|
||||
9, /* 30 */
|
||||
9 /* 31 */
|
||||
};
|
||||
|
||||
int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32 flags)
|
||||
{
|
||||
UINT32 bits;
|
||||
UINT32 nbits;
|
||||
BYTE* SrcPtr;
|
||||
UINT32 CopyOffset;
|
||||
UINT32 LengthOfMatch;
|
||||
UINT32 accumulator;
|
||||
BYTE* HistoryPtr;
|
||||
UINT32 HistoryOffset;
|
||||
BYTE* HistoryBuffer;
|
||||
BYTE* HistoryBufferEnd;
|
||||
UINT32 HistoryBufferSize;
|
||||
wBitStream* bs = ncrush->bs;
|
||||
|
||||
HistoryBuffer = ncrush->HistoryBuffer;
|
||||
HistoryBufferSize = ncrush->HistoryBufferSize;
|
||||
HistoryBufferEnd = &HistoryBuffer[HistoryBufferSize - 1];
|
||||
|
||||
BitStream_Attach(bs, pSrcData, SrcSize);
|
||||
BitStream_Fetch(bs);
|
||||
|
||||
if (flags & PACKET_AT_FRONT)
|
||||
{
|
||||
if ((ncrush->HistoryPtr - 32768) <= HistoryBuffer)
|
||||
return -1;
|
||||
|
||||
CopyMemory(HistoryBuffer, (ncrush->HistoryPtr - 32768), 32768);
|
||||
ncrush->HistoryOffset = 32768;
|
||||
ncrush->HistoryPtr = &(HistoryBuffer[ncrush->HistoryOffset]);
|
||||
}
|
||||
|
||||
if (flags & PACKET_FLUSHED)
|
||||
{
|
||||
ncrush->HistoryOffset = 0;
|
||||
ncrush->HistoryPtr = HistoryBuffer;
|
||||
ZeroMemory(HistoryBuffer, ncrush->HistoryBufferSize);
|
||||
ZeroMemory(&(ncrush->OffsetCache), sizeof(ncrush->OffsetCache));
|
||||
}
|
||||
|
||||
HistoryPtr = ncrush->HistoryPtr;
|
||||
HistoryOffset = ncrush->HistoryOffset;
|
||||
|
||||
if (!(flags & PACKET_COMPRESSED))
|
||||
{
|
||||
CopyMemory(HistoryPtr, pSrcData, SrcSize);
|
||||
HistoryPtr += SrcSize;
|
||||
HistoryOffset += SrcSize;
|
||||
ncrush->HistoryPtr = HistoryPtr;
|
||||
ncrush->HistoryOffset = HistoryOffset;
|
||||
*ppDstData = HistoryPtr;
|
||||
*pDstSize = SrcSize;
|
||||
return 1;
|
||||
}
|
||||
|
||||
nbits = 32;
|
||||
bits = *((UINT32*) pSrcData);
|
||||
SrcPtr = pSrcData + 4;
|
||||
|
||||
accumulator = bits & *((UINT16*) &NCrushMaskTable[29]);
|
||||
|
||||
printf("MaskedBits: 0x%04X Mask: 0x%04X\n", accumulator, *((UINT16*) &NCrushMaskTable[29]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32 flags)
|
||||
int ncrush_compress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE* pDstData, UINT32* pDstSize, UINT32* pFlags)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -51,6 +489,7 @@ NCRUSH_CONTEXT* ncrush_context_new(BOOL Compressor)
|
||||
|
||||
ncrush->HistoryBufferSize = 65536;
|
||||
ZeroMemory(&(ncrush->HistoryBuffer), sizeof(ncrush->HistoryBuffer));
|
||||
ZeroMemory(&(ncrush->OffsetCache), sizeof(ncrush->OffsetCache));
|
||||
|
||||
ncrush->HistoryOffset = 0;
|
||||
ncrush->HistoryPtr = &(ncrush->HistoryBuffer[ncrush->HistoryOffset]);
|
||||
|
||||
@@ -688,18 +688,18 @@ static BYTE TEST_RDP5_UNCOMPRESSED_DATA[] =
|
||||
* 00 Trailing Bits
|
||||
*/
|
||||
|
||||
const BYTE TEST_MPPC_BELLS[] = "for.whom.the.bell.tolls,.the.bell.tolls.for.thee!";
|
||||
static const BYTE TEST_MPPC_BELLS[] = "for.whom.the.bell.tolls,.the.bell.tolls.for.thee!";
|
||||
|
||||
/* Flags: 0x0060 Length: 33 */
|
||||
|
||||
const BYTE TEST_MPPC_BELLS_RDP4[] =
|
||||
static const BYTE TEST_MPPC_BELLS_RDP4[] =
|
||||
"\x66\x6f\x72\x2e\x77\x68\x6f\x6d\x2e\x74\x68\x65\x2e\x62\x65\x6c"
|
||||
"\x6c\x2e\x74\x6f\x6c\x6c\x73\x2c\xf4\x37\x2e\x66\xfa\x1f\x19\x94"
|
||||
"\x84";
|
||||
|
||||
/* Flags: 0x0061 Length: 34 */
|
||||
|
||||
const BYTE TEST_MPPC_BELLS_RDP5[] =
|
||||
static const BYTE TEST_MPPC_BELLS_RDP5[] =
|
||||
"\x66\x6f\x72\x2e\x77\x68\x6f\x6d\x2e\x74\x68\x65\x2e\x62\x65\x6c"
|
||||
"\x6c\x2e\x74\x6f\x6c\x6c\x73\x2c\xfa\x1b\x97\x33\x7e\x87\xe3\x32"
|
||||
"\x90\x80";
|
||||
|
||||
@@ -3,7 +3,103 @@
|
||||
|
||||
#include <freerdp/codec/ncrush.h>
|
||||
|
||||
static const BYTE TEST_BELLS_DATA[] = "for.whom.the.bell.tolls,.the.bell.tolls.for.thee!";
|
||||
|
||||
const BYTE TEST_BELLS_NCRUSH[] =
|
||||
"\xfb\x1d\x7e\xe4\xda\xc7\x1d\x70\xf8\xa1\x6b\x1f\x7d\xc0\xbe\x6b"
|
||||
"\xef\xb5\xef\x21\x87\xd0\xc5\xe1\x85\x71\xd4\x10\x16\xe7\xda\xfb"
|
||||
"\x1d\x7e\xe4\xda\x47\x1f\xb0\xef\xbe\xbd\xff\x2f";
|
||||
|
||||
int test_NCrushCompressBells()
|
||||
{
|
||||
int status;
|
||||
UINT32 Flags;
|
||||
UINT32 SrcSize;
|
||||
BYTE* pSrcData;
|
||||
UINT32 DstSize;
|
||||
UINT32 expectedSize;
|
||||
BYTE OutputBuffer[65536];
|
||||
NCRUSH_CONTEXT* ncrush;
|
||||
|
||||
ncrush = ncrush_context_new(TRUE);
|
||||
|
||||
SrcSize = sizeof(TEST_BELLS_DATA) - 1;
|
||||
pSrcData = (BYTE*) TEST_BELLS_DATA;
|
||||
DstSize = sizeof(OutputBuffer);
|
||||
expectedSize = sizeof(TEST_BELLS_NCRUSH) - 1;
|
||||
|
||||
status = ncrush_compress(ncrush, pSrcData, SrcSize, OutputBuffer, &DstSize, &Flags);
|
||||
|
||||
printf("Flags: 0x%04X DstSize: %d\n", Flags, DstSize);
|
||||
|
||||
if (DstSize != expectedSize)
|
||||
{
|
||||
printf("NCrushCompressBells: output size mismatch: Actual: %d, Expected: %d\n", DstSize, expectedSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (memcmp(OutputBuffer, TEST_BELLS_NCRUSH, DstSize) != 0)
|
||||
{
|
||||
printf("NCrushCompressBells: output mismatch\n");
|
||||
|
||||
printf("Actual\n");
|
||||
BitDump(OutputBuffer, DstSize * 8, 0);
|
||||
|
||||
printf("Expected\n");
|
||||
BitDump(TEST_BELLS_NCRUSH, DstSize * 8, 0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
ncrush_context_free(ncrush);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_NCrushDecompressBells()
|
||||
{
|
||||
int status;
|
||||
UINT32 Flags;
|
||||
BYTE* pSrcData;
|
||||
UINT32 SrcSize;
|
||||
UINT32 DstSize;
|
||||
UINT32 expectedSize;
|
||||
BYTE* pDstData = NULL;
|
||||
NCRUSH_CONTEXT* ncrush;
|
||||
|
||||
ncrush = ncrush_context_new(FALSE);
|
||||
|
||||
SrcSize = sizeof(TEST_BELLS_NCRUSH) - 1;
|
||||
pSrcData = (BYTE*) TEST_BELLS_NCRUSH;
|
||||
Flags = PACKET_COMPRESSED | 2;
|
||||
expectedSize = sizeof(TEST_BELLS_DATA) - 1;
|
||||
|
||||
status = ncrush_decompress(ncrush, pSrcData, SrcSize, &pDstData, &DstSize, Flags);
|
||||
printf("Flags: 0x%04X DstSize: %d\n", Flags, DstSize);
|
||||
|
||||
if (DstSize != expectedSize)
|
||||
{
|
||||
printf("NCrushDecompressBells: output size mismatch: Actual: %d, Expected: %d\n", DstSize, expectedSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (memcmp(pDstData, TEST_BELLS_DATA, DstSize) != 0)
|
||||
{
|
||||
printf("NCrushDecompressBells: output mismatch\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ncrush_context_free(ncrush);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TestFreeRDPCodecNCrush(int argc, char* argv[])
|
||||
{
|
||||
//test_NCrushCompressBells();
|
||||
test_NCrushDecompressBells();
|
||||
|
||||
//BitDump(TEST_BELLS_NCRUSH, (sizeof(TEST_BELLS_NCRUSH) - 1) * 8, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user