FreeRDP
Loading...
Searching...
No Matches
zgfx.c
1
21
22#include <freerdp/config.h>
23
24#include <winpr/assert.h>
25#include <winpr/cast.h>
26#include <winpr/crt.h>
27#include <winpr/print.h>
28#include <winpr/bitstream.h>
29
30#include <freerdp/log.h>
31#include <freerdp/codec/zgfx.h>
32
33#define TAG FREERDP_TAG("codec")
34
44
45typedef struct
46{
47 UINT32 prefixLength;
48 UINT32 prefixCode;
49 UINT32 valueBits;
50 UINT32 tokenType;
51 UINT32 valueBase;
52} ZGFX_TOKEN;
53
54struct S_ZGFX_CONTEXT
55{
56 BOOL Compressor;
57
58 const BYTE* pbInputCurrent;
59 const BYTE* pbInputEnd;
60
61 UINT32 bits;
62 UINT32 cBitsRemaining;
63 UINT32 BitsCurrent;
64 UINT32 cBitsCurrent;
65
66 BYTE OutputBuffer[65536];
67 UINT32 OutputCount;
68
69 BYTE HistoryBuffer[2500000];
70 UINT32 HistoryIndex;
71 UINT32 HistoryBufferSize;
72 UINT32 HistoryFilled;
73};
74
75static const ZGFX_TOKEN ZGFX_TOKEN_TABLE[] = {
76 // len code vbits type vbase
77 { 1, 0, 8, 0, 0 }, // 0
78 { 5, 17, 5, 1, 0 }, // 10001
79 { 5, 18, 7, 1, 32 }, // 10010
80 { 5, 19, 9, 1, 160 }, // 10011
81 { 5, 20, 10, 1, 672 }, // 10100
82 { 5, 21, 12, 1, 1696 }, // 10101
83 { 5, 24, 0, 0, 0x00 }, // 11000
84 { 5, 25, 0, 0, 0x01 }, // 11001
85 { 6, 44, 14, 1, 5792 }, // 101100
86 { 6, 45, 15, 1, 22176 }, // 101101
87 { 6, 52, 0, 0, 0x02 }, // 110100
88 { 6, 53, 0, 0, 0x03 }, // 110101
89 { 6, 54, 0, 0, 0xFF }, // 110110
90 { 7, 92, 18, 1, 54944 }, // 1011100
91 { 7, 93, 20, 1, 317088 }, // 1011101
92 { 7, 110, 0, 0, 0x04 }, // 1101110
93 { 7, 111, 0, 0, 0x05 }, // 1101111
94 { 7, 112, 0, 0, 0x06 }, // 1110000
95 { 7, 113, 0, 0, 0x07 }, // 1110001
96 { 7, 114, 0, 0, 0x08 }, // 1110010
97 { 7, 115, 0, 0, 0x09 }, // 1110011
98 { 7, 116, 0, 0, 0x0A }, // 1110100
99 { 7, 117, 0, 0, 0x0B }, // 1110101
100 { 7, 118, 0, 0, 0x3A }, // 1110110
101 { 7, 119, 0, 0, 0x3B }, // 1110111
102 { 7, 120, 0, 0, 0x3C }, // 1111000
103 { 7, 121, 0, 0, 0x3D }, // 1111001
104 { 7, 122, 0, 0, 0x3E }, // 1111010
105 { 7, 123, 0, 0, 0x3F }, // 1111011
106 { 7, 124, 0, 0, 0x40 }, // 1111100
107 { 7, 125, 0, 0, 0x80 }, // 1111101
108 { 8, 188, 20, 1, 1365664 }, // 10111100
109 { 8, 189, 21, 1, 2414240 }, // 10111101
110 { 8, 252, 0, 0, 0x0C }, // 11111100
111 { 8, 253, 0, 0, 0x38 }, // 11111101
112 { 8, 254, 0, 0, 0x39 }, // 11111110
113 { 8, 255, 0, 0, 0x66 }, // 11111111
114 { 9, 380, 22, 1, 4511392 }, // 101111100
115 { 9, 381, 23, 1, 8705696 }, // 101111101
116 { 9, 382, 24, 1, 17094304 }, // 101111110
117 WINPR_C_ARRAY_INIT
118};
119
120static inline BOOL zgfx_GetBits(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, UINT32 nbits)
121{
122 if (!zgfx)
123 return FALSE;
124
125 while (zgfx->cBitsCurrent < nbits)
126 {
127 zgfx->BitsCurrent <<= 8;
128
129 if (zgfx->pbInputCurrent < zgfx->pbInputEnd)
130 zgfx->BitsCurrent += *(zgfx->pbInputCurrent)++;
131
132 zgfx->cBitsCurrent += 8;
133 }
134
135 zgfx->cBitsRemaining -= nbits;
136 zgfx->cBitsCurrent -= nbits;
137 zgfx->bits = zgfx->BitsCurrent >> zgfx->cBitsCurrent;
138 zgfx->BitsCurrent &= ((1u << zgfx->cBitsCurrent) - 1);
139 return TRUE;
140}
141
142static inline void zgfx_history_buffer_filled(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, size_t count)
143{
144 if (count >= zgfx->HistoryBufferSize - zgfx->HistoryFilled)
145 zgfx->HistoryFilled = zgfx->HistoryBufferSize;
146 else
147 zgfx->HistoryFilled += (UINT32)count;
148}
149
150static inline void zgfx_history_buffer_ring_write(ZGFX_CONTEXT* WINPR_RESTRICT zgfx,
151 const BYTE* WINPR_RESTRICT src, size_t count)
152{
153 if (count <= 0)
154 return;
155
156 zgfx_history_buffer_filled(zgfx, count);
157
158 if (count > zgfx->HistoryBufferSize)
159 {
160 const size_t residue = count - zgfx->HistoryBufferSize;
161 count = zgfx->HistoryBufferSize;
162 src += residue;
163 zgfx->HistoryIndex = (zgfx->HistoryIndex + residue) % zgfx->HistoryBufferSize;
164 }
165
166 if (zgfx->HistoryIndex + count <= zgfx->HistoryBufferSize)
167 {
168 CopyMemory(&(zgfx->HistoryBuffer[zgfx->HistoryIndex]), src, count);
169
170 zgfx->HistoryIndex += WINPR_ASSERTING_INT_CAST(uint32_t, count);
171 if (zgfx->HistoryIndex == zgfx->HistoryBufferSize)
172 zgfx->HistoryIndex = 0;
173 }
174 else
175 {
176 const UINT32 front = zgfx->HistoryBufferSize - zgfx->HistoryIndex;
177 CopyMemory(&(zgfx->HistoryBuffer[zgfx->HistoryIndex]), src, front);
178 CopyMemory(zgfx->HistoryBuffer, &src[front], count - front);
179 zgfx->HistoryIndex = (UINT32)(count - front);
180 }
181}
182
183static inline void zgfx_history_buffer_ring_read(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, int offset,
184 BYTE* WINPR_RESTRICT dst, UINT32 count)
185{
186 UINT32 front = 0;
187 UINT32 index = 0;
188 INT32 bytes = 0;
189 UINT32 valid = 0;
190 INT32 bytesLeft = 0;
191 BYTE* dptr = dst;
192 BYTE* origDst = dst;
193
194 if ((count <= 0) || (count > INT32_MAX))
195 return;
196
197 bytesLeft = (INT32)count;
198 index = (zgfx->HistoryIndex + zgfx->HistoryBufferSize -
199 WINPR_ASSERTING_INT_CAST(uint32_t, offset)) %
200 zgfx->HistoryBufferSize;
201 bytes = MIN(bytesLeft, offset);
202
203 if ((index + WINPR_ASSERTING_INT_CAST(uint32_t, bytes)) <= zgfx->HistoryBufferSize)
204 {
205 CopyMemory(dptr, &(zgfx->HistoryBuffer[index]), WINPR_ASSERTING_INT_CAST(size_t, bytes));
206 }
207 else
208 {
209 front = zgfx->HistoryBufferSize - index;
210 CopyMemory(dptr, &(zgfx->HistoryBuffer[index]), front);
211 CopyMemory(&dptr[front], zgfx->HistoryBuffer,
212 WINPR_ASSERTING_INT_CAST(uint32_t, bytes) - front);
213 }
214
215 if ((bytesLeft -= bytes) == 0)
216 return;
217
218 dptr += bytes;
219 valid = WINPR_ASSERTING_INT_CAST(uint32_t, bytes);
220
221 do
222 {
223 bytes = WINPR_ASSERTING_INT_CAST(int32_t, valid);
224
225 if (bytes > bytesLeft)
226 bytes = bytesLeft;
227
228 CopyMemory(dptr, origDst, WINPR_ASSERTING_INT_CAST(size_t, bytes));
229 dptr += bytes;
230 valid <<= 1;
231 } while ((bytesLeft -= bytes) > 0);
232}
233
234static inline BOOL zgfx_decompress_segment(ZGFX_CONTEXT* WINPR_RESTRICT zgfx,
235 wStream* WINPR_RESTRICT stream, size_t segmentSize)
236{
237 BYTE c = 0;
238 BYTE flags = 0;
239 UINT32 extra = 0;
240 int opIndex = 0;
241 UINT32 haveBits = 0;
242 UINT32 inPrefix = 0;
243 UINT32 count = 0;
244 UINT32 distance = 0;
245 BYTE* pbSegment = nullptr;
246
247 WINPR_ASSERT(zgfx);
248 WINPR_ASSERT(stream);
249
250 if (segmentSize < 2)
251 return FALSE;
252
253 const size_t cbSegment = segmentSize - 1;
254
255 if (!Stream_CheckAndLogRequiredLength(TAG, stream, segmentSize) || (segmentSize > UINT32_MAX))
256 return FALSE;
257
258 Stream_Read_UINT8(stream, flags); /* header (1 byte) */
259 zgfx->OutputCount = 0;
260 pbSegment = Stream_Pointer(stream);
261 if (!Stream_SafeSeek(stream, cbSegment))
262 return FALSE;
263
264 if (!(flags & PACKET_COMPRESSED))
265 {
266 zgfx_history_buffer_ring_write(zgfx, pbSegment, cbSegment);
267
268 if (cbSegment > sizeof(zgfx->OutputBuffer))
269 return FALSE;
270
271 CopyMemory(zgfx->OutputBuffer, pbSegment, cbSegment);
272 zgfx->OutputCount = (UINT32)cbSegment;
273 return TRUE;
274 }
275
276 zgfx->pbInputCurrent = pbSegment;
277 zgfx->pbInputEnd = &pbSegment[cbSegment - 1];
278 /* NumberOfBitsToDecode = ((NumberOfBytesToDecode - 1) * 8) - ValueOfLastByte */
279 const size_t bits = 8u * (cbSegment - 1u);
280 if (bits > UINT32_MAX)
281 return FALSE;
282 if (bits < *zgfx->pbInputEnd)
283 return FALSE;
284
285 zgfx->cBitsRemaining = (UINT32)(bits - *zgfx->pbInputEnd);
286 zgfx->cBitsCurrent = 0;
287 zgfx->BitsCurrent = 0;
288
289 while (zgfx->cBitsRemaining)
290 {
291 haveBits = 0;
292 inPrefix = 0;
293
294 for (opIndex = 0; ZGFX_TOKEN_TABLE[opIndex].prefixLength != 0; opIndex++)
295 {
296 while (haveBits < ZGFX_TOKEN_TABLE[opIndex].prefixLength)
297 {
298 zgfx_GetBits(zgfx, 1);
299 inPrefix = (inPrefix << 1) + zgfx->bits;
300 haveBits++;
301 }
302
303 if (inPrefix == ZGFX_TOKEN_TABLE[opIndex].prefixCode)
304 {
305 if (ZGFX_TOKEN_TABLE[opIndex].tokenType == 0)
306 {
307 /* Literal */
308 zgfx_GetBits(zgfx, ZGFX_TOKEN_TABLE[opIndex].valueBits);
309 c = (BYTE)(ZGFX_TOKEN_TABLE[opIndex].valueBase + zgfx->bits);
310 zgfx->HistoryBuffer[zgfx->HistoryIndex] = c;
311 zgfx_history_buffer_filled(zgfx, 1);
312
313 if (++zgfx->HistoryIndex == zgfx->HistoryBufferSize)
314 zgfx->HistoryIndex = 0;
315
316 if (zgfx->OutputCount >= sizeof(zgfx->OutputBuffer))
317 return FALSE;
318
319 zgfx->OutputBuffer[zgfx->OutputCount++] = c;
320 }
321 else
322 {
323 zgfx_GetBits(zgfx, ZGFX_TOKEN_TABLE[opIndex].valueBits);
324 distance = ZGFX_TOKEN_TABLE[opIndex].valueBase + zgfx->bits;
325
326 if (distance != 0)
327 {
328 /* Match */
329 zgfx_GetBits(zgfx, 1);
330
331 if (zgfx->bits == 0)
332 {
333 count = 3;
334 }
335 else
336 {
337 count = 4;
338 extra = 2;
339 zgfx_GetBits(zgfx, 1);
340
341 while (zgfx->bits == 1)
342 {
343 count *= 2;
344 extra++;
345 zgfx_GetBits(zgfx, 1);
346 }
347
348 zgfx_GetBits(zgfx, extra);
349 count += zgfx->bits;
350 }
351
352 if (count > sizeof(zgfx->OutputBuffer) - zgfx->OutputCount)
353 return FALSE;
354
355 if (distance > zgfx->HistoryFilled)
356 {
357 WLog_ERR(TAG,
358 "match distance %" PRIu32 " beyond the %" PRIu32
359 " bytes of history",
360 distance, zgfx->HistoryFilled);
361 return FALSE;
362 }
363
364 zgfx_history_buffer_ring_read(zgfx, WINPR_ASSERTING_INT_CAST(int, distance),
365 &(zgfx->OutputBuffer[zgfx->OutputCount]),
366 count);
367 zgfx_history_buffer_ring_write(
368 zgfx, &(zgfx->OutputBuffer[zgfx->OutputCount]), count);
369 zgfx->OutputCount += count;
370 }
371 else
372 {
373 /* Unencoded */
374 zgfx_GetBits(zgfx, 15);
375 count = zgfx->bits;
376 zgfx->cBitsRemaining -= zgfx->cBitsCurrent;
377 zgfx->cBitsCurrent = 0;
378 zgfx->BitsCurrent = 0;
379
380 if (count > sizeof(zgfx->OutputBuffer) - zgfx->OutputCount)
381 return FALSE;
382 else if (count > zgfx->cBitsRemaining / 8)
383 return FALSE;
384 else if (zgfx->pbInputCurrent + count > zgfx->pbInputEnd)
385 return FALSE;
386
387 CopyMemory(&(zgfx->OutputBuffer[zgfx->OutputCount]), zgfx->pbInputCurrent,
388 count);
389 zgfx_history_buffer_ring_write(zgfx, zgfx->pbInputCurrent, count);
390 zgfx->pbInputCurrent += count;
391 zgfx->cBitsRemaining -= (8 * count);
392 zgfx->OutputCount += count;
393 }
394 }
395
396 break;
397 }
398 }
399 }
400
401 return TRUE;
402}
403
404static inline BOOL zgfx_append(ZGFX_CONTEXT* WINPR_RESTRICT zgfx,
405 BYTE** WINPR_RESTRICT ppConcatenated, size_t uncompressedSize,
406 size_t* WINPR_RESTRICT pUsed)
407{
408 WINPR_ASSERT(zgfx);
409 WINPR_ASSERT(ppConcatenated);
410 WINPR_ASSERT(pUsed);
411
412 const size_t used = *pUsed;
413 if (zgfx->OutputCount > UINT32_MAX - used)
414 return FALSE;
415
416 if (used + zgfx->OutputCount > uncompressedSize)
417 return FALSE;
418
419 BYTE* tmp = realloc(*ppConcatenated, used + zgfx->OutputCount + 64ull);
420 if (!tmp)
421 return FALSE;
422 *ppConcatenated = tmp;
423 CopyMemory(&tmp[used], zgfx->OutputBuffer, zgfx->OutputCount);
424 *pUsed = used + zgfx->OutputCount;
425 return TRUE;
426}
427
428int zgfx_decompress(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, const BYTE* WINPR_RESTRICT pSrcData,
429 UINT32 SrcSize, BYTE** WINPR_RESTRICT ppDstData,
430 UINT32* WINPR_RESTRICT pDstSize, WINPR_ATTR_UNUSED UINT32 flags)
431{
432 int status = -1;
433 BYTE descriptor = 0;
434 wStream sbuffer = WINPR_C_ARRAY_INIT;
435 size_t used = 0;
436 BYTE* pConcatenated = nullptr;
437 wStream* stream = Stream_StaticConstInit(&sbuffer, pSrcData, SrcSize);
438
439 WINPR_ASSERT(zgfx);
440 WINPR_ASSERT(stream);
441 WINPR_ASSERT(ppDstData);
442 WINPR_ASSERT(pDstSize);
443
444 *ppDstData = nullptr;
445 *pDstSize = 0;
446
447 if (!Stream_CheckAndLogRequiredLength(TAG, stream, 1))
448 goto fail;
449
450 Stream_Read_UINT8(stream, descriptor); /* descriptor (1 byte) */
451
452 if (descriptor == ZGFX_SEGMENTED_SINGLE)
453 {
454 if (!zgfx_decompress_segment(zgfx, stream, Stream_GetRemainingLength(stream)))
455 goto fail;
456
457 if (zgfx->OutputCount > 0)
458 {
459 if (!zgfx_append(zgfx, &pConcatenated, zgfx->OutputCount, &used))
460 goto fail;
461 if (used != zgfx->OutputCount)
462 goto fail;
463 *ppDstData = pConcatenated;
464 *pDstSize = zgfx->OutputCount;
465 }
466 }
467 else if (descriptor == ZGFX_SEGMENTED_MULTIPART)
468 {
469 UINT32 segmentSize = 0;
470 UINT16 segmentNumber = 0;
471 UINT16 segmentCount = 0;
472 UINT32 uncompressedSize = 0;
473
474 if (!Stream_CheckAndLogRequiredLength(TAG, stream, 6))
475 goto fail;
476
477 Stream_Read_UINT16(stream, segmentCount); /* segmentCount (2 bytes) */
478 Stream_Read_UINT32(stream, uncompressedSize); /* uncompressedSize (4 bytes) */
479
480 for (segmentNumber = 0; segmentNumber < segmentCount; segmentNumber++)
481 {
482 if (!Stream_CheckAndLogRequiredLength(TAG, stream, sizeof(UINT32)))
483 goto fail;
484
485 Stream_Read_UINT32(stream, segmentSize); /* segmentSize (4 bytes) */
486
487 if (!zgfx_decompress_segment(zgfx, stream, segmentSize))
488 goto fail;
489
490 if (!zgfx_append(zgfx, &pConcatenated, uncompressedSize, &used))
491 goto fail;
492 }
493
494 if (used != uncompressedSize)
495 goto fail;
496
497 *ppDstData = pConcatenated;
498 *pDstSize = uncompressedSize;
499 }
500 else
501 {
502 goto fail;
503 }
504
505 status = 1;
506fail:
507 if (status < 0)
508 free(pConcatenated);
509 return status;
510}
511
512static BOOL zgfx_compress_segment(WINPR_ATTR_UNUSED ZGFX_CONTEXT* WINPR_RESTRICT zgfx,
513 wStream* WINPR_RESTRICT s, const BYTE* WINPR_RESTRICT pSrcData,
514 UINT32 SrcSize, UINT32* WINPR_RESTRICT pFlags)
515{
516 /* FIXME: Currently compression not implemented. Just copy the raw source */
517 if (!Stream_EnsureRemainingCapacity(s, SrcSize + 1ull))
518 {
519 WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
520 return FALSE;
521 }
522
523 (*pFlags) |= ZGFX_PACKET_COMPR_TYPE_RDP8; /* RDP 8.0 compression format */
524 Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, *pFlags)); /* header (1 byte) */
525 Stream_Write(s, pSrcData, SrcSize);
526 return TRUE;
527}
528
529int zgfx_compress_to_stream(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, wStream* WINPR_RESTRICT sDst,
530 const BYTE* WINPR_RESTRICT pUncompressed, UINT32 uncompressedSize,
531 UINT32* WINPR_RESTRICT pFlags)
532{
533 int fragment = 0;
534 UINT16 maxLength = 0;
535 UINT32 totalLength = 0;
536 size_t posSegmentCount = 0;
537 const BYTE* pSrcData = nullptr;
538 int status = 0;
539 maxLength = ZGFX_SEGMENTED_MAXSIZE;
540 totalLength = uncompressedSize;
541 pSrcData = pUncompressed;
542
543 for (; (totalLength > 0) || (fragment == 0); fragment++)
544 {
545 size_t posDstSize = 0;
546 size_t posDataStart = 0;
547
548 const UINT32 SrcSize = (totalLength > maxLength) ? maxLength : totalLength;
549 posDstSize = 0;
550 totalLength -= SrcSize;
551
552 /* Ensure we have enough space for headers */
553 if (!Stream_EnsureRemainingCapacity(sDst, 12))
554 {
555 WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
556 return -1;
557 }
558
559 if (fragment == 0)
560 {
561 /* First fragment */
562 /* descriptor (1 byte) */
563 Stream_Write_UINT8(sDst, (totalLength == 0) ? ZGFX_SEGMENTED_SINGLE
564 : ZGFX_SEGMENTED_MULTIPART);
565
566 if (totalLength > 0)
567 {
568 posSegmentCount = Stream_GetPosition(sDst); /* segmentCount (2 bytes) */
569 Stream_Seek(sDst, 2);
570 Stream_Write_UINT32(sDst, uncompressedSize); /* uncompressedSize (4 bytes) */
571 }
572 }
573
574 if (fragment > 0 || totalLength > 0)
575 {
576 /* Multipart */
577 posDstSize = Stream_GetPosition(sDst); /* size (4 bytes) */
578 Stream_Seek(sDst, 4);
579 }
580
581 posDataStart = Stream_GetPosition(sDst);
582
583 if (!zgfx_compress_segment(zgfx, sDst, pSrcData, SrcSize, pFlags))
584 return -1;
585
586 if (posDstSize)
587 {
588 /* Fill segment data size */
589 const size_t DstSize = Stream_GetPosition(sDst) - posDataStart;
590 if (DstSize > UINT32_MAX)
591 return -1;
592 if (!Stream_SetPosition(sDst, posDstSize))
593 return -1;
594 Stream_Write_UINT32(sDst, (UINT32)DstSize);
595 if (!Stream_SetPosition(sDst, posDataStart + DstSize))
596 return -1;
597 }
598
599 pSrcData += SrcSize;
600 }
601
602 Stream_SealLength(sDst);
603
604 /* fill back segmentCount */
605 if (posSegmentCount)
606 {
607 if (!Stream_SetPosition(sDst, posSegmentCount))
608 return -1;
609 Stream_Write_UINT16(sDst, WINPR_ASSERTING_INT_CAST(uint16_t, fragment));
610 if (!Stream_SetPosition(sDst, Stream_Length(sDst)))
611 return -1;
612 }
613
614 return status;
615}
616
617int zgfx_compress(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, const BYTE* WINPR_RESTRICT pSrcData,
618 UINT32 SrcSize, BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize,
619 UINT32* WINPR_RESTRICT pFlags)
620{
621 int status = 0;
622 wStream* s = Stream_New(nullptr, SrcSize);
623 if (!s)
624 return -1;
625 status = zgfx_compress_to_stream(zgfx, s, pSrcData, SrcSize, pFlags);
626 const size_t pos = Stream_GetPosition(s);
627 if (pos > UINT32_MAX)
628 status = -1;
629 else
630 {
631 (*ppDstData) = Stream_Buffer(s);
632 (*pDstSize) = (UINT32)pos;
633 }
634 Stream_Free(s, FALSE);
635 return status;
636}
637
638void zgfx_context_reset(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, WINPR_ATTR_UNUSED BOOL flush)
639{
640 zgfx->HistoryIndex = 0;
641 zgfx->HistoryFilled = 0;
642}
643
644ZGFX_CONTEXT* zgfx_context_new(BOOL Compressor)
645{
646 ZGFX_CONTEXT* zgfx = nullptr;
647 zgfx = (ZGFX_CONTEXT*)calloc(1, sizeof(ZGFX_CONTEXT));
648
649 if (zgfx)
650 {
651 zgfx->Compressor = Compressor;
652 zgfx->HistoryBufferSize = sizeof(zgfx->HistoryBuffer);
653 zgfx_context_reset(zgfx, FALSE);
654 }
655
656 return zgfx;
657}
658
659void zgfx_context_free(ZGFX_CONTEXT* zgfx)
660{
661 free(zgfx);
662}