22#include <freerdp/config.h>
24#include <winpr/assert.h>
25#include <winpr/cast.h>
27#include <winpr/print.h>
28#include <winpr/bitstream.h>
30#include <freerdp/primitives.h>
31#include <freerdp/codec/color.h>
32#include <freerdp/codec/progressive.h>
33#include <freerdp/codec/region.h>
34#include <freerdp/log.h>
36#include "rfx_differential.h"
37#include "rfx_quantization.h"
40#include "rfx_constants.h"
42#include "progressive.h"
44#define TAG FREERDP_TAG("codec.progressive")
57} RFX_PROGRESSIVE_UPGRADE_STATE;
60progressive_component_codec_quant_read(
wStream* WINPR_RESTRICT s,
64 Stream_Read_UINT8(s, b);
65 quantVal->LL3 = b & 0x0F;
66 quantVal->HL3 = b >> 4;
67 Stream_Read_UINT8(s, b);
68 quantVal->LH3 = b & 0x0F;
69 quantVal->HH3 = b >> 4;
70 Stream_Read_UINT8(s, b);
71 quantVal->HL2 = b & 0x0F;
72 quantVal->LH2 = b >> 4;
73 Stream_Read_UINT8(s, b);
74 quantVal->HH2 = b & 0x0F;
75 quantVal->HL1 = b >> 4;
76 Stream_Read_UINT8(s, b);
77 quantVal->LH1 = b & 0x0F;
78 quantVal->HH1 = b >> 4;
85 dst->HL1 = q1->HL1 + q2->HL1;
86 dst->LH1 = q1->LH1 + q2->LH1;
87 dst->HH1 = q1->HH1 + q2->HH1;
88 dst->HL2 = q1->HL2 + q2->HL2;
89 dst->LH2 = q1->LH2 + q2->LH2;
90 dst->HH2 = q1->HH2 + q2->HH2;
91 dst->HL3 = q1->HL3 + q2->HL3;
92 dst->LH3 = q1->LH3 + q2->LH3;
93 dst->HH3 = q1->HH3 + q2->HH3;
94 dst->LL3 = q1->LL3 + q2->LL3;
147 if (q1->HL1 < q2->HL1)
149 dst->HL1 = q1->HL1 - q2->HL1;
151 if (q1->LH1 < q2->LH1)
153 dst->LH1 = q1->LH1 - q2->LH1;
155 if (q1->HH1 < q2->HH1)
157 dst->HH1 = q1->HH1 - q2->HH1;
159 if (q1->HL2 < q2->HL2)
161 dst->HL2 = q1->HL2 - q2->HL2;
163 if (q1->LH2 < q2->LH2)
165 dst->LH2 = q1->LH2 - q2->LH2;
167 if (q1->HH2 < q2->HH2)
169 dst->HH2 = q1->HH2 - q2->HH2;
171 if (q1->HL3 < q2->HL3)
173 dst->HL3 = q1->HL3 - q2->HL3;
175 if (q1->LH3 < q2->LH3)
177 dst->LH3 = q1->LH3 - q2->LH3;
179 if (q1->HH3 < q2->HH3)
181 dst->HH3 = q1->HH3 - q2->HH3;
183 if (q1->LL3 < q2->LL3)
185 dst->LL3 = q1->LL3 - q2->LL3;
266 if (q1->HL1 != q2->HL1)
269 if (q1->LH1 != q2->LH1)
272 if (q1->HH1 != q2->HH1)
275 if (q1->HL2 != q2->HL2)
278 if (q1->LH2 != q2->LH2)
281 if (q1->HH2 != q2->HH2)
284 if (q1->HL3 != q2->HL3)
287 if (q1->LH3 != q2->LH3)
290 if (q1->HH3 != q2->HH3)
293 if (q1->LL3 != q2->LL3)
299static inline BOOL progressive_set_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
304 key = ((ULONG_PTR)surfaceId) + 1;
307 return HashTable_Insert(progressive->SurfaceContexts, (
void*)key, pData);
309 HashTable_Remove(progressive->SurfaceContexts, (
void*)key);
314progressive_get_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, UINT16 surfaceId)
316 void* key = (
void*)(((ULONG_PTR)surfaceId) + 1);
321 return HashTable_GetItemValue(progressive->SurfaceContexts, key);
328 winpr_aligned_free(tile->sign);
329 winpr_aligned_free(tile->current);
330 winpr_aligned_free(tile->data);
331 winpr_aligned_free(tile);
335static void progressive_surface_context_free(
void* ptr)
344 for (
size_t index = 0; index < surface->tilesSize; index++)
347 progressive_tile_free(tile);
351 winpr_aligned_free((
void*)surface->tiles);
352 winpr_aligned_free(surface->updatedTileIndices);
353 winpr_aligned_free(surface);
364 tile->stride = 4 * tile->width;
367 const size_t dataLen = 1ull * tile->stride * tile->height;
368 tile->data = (BYTE*)winpr_aligned_malloc(dataLen, 16);
371 memset(tile->data, 0xFF, dataLen);
375 const size_t signLen = (8192ULL + 32ULL) * 3ULL;
376 tile->sign = (BYTE*)winpr_aligned_malloc(signLen, 16);
383 const size_t currentLen = (8192ULL + 32ULL) * 3ULL;
384 tile->current = (BYTE*)winpr_aligned_malloc(currentLen, 16);
392 progressive_tile_free(tile);
401 WINPR_ASSERT(surface);
402 WINPR_ASSERT(surface->gridSize > 0);
406 oldIndex = surface->gridSize;
407 while (surface->gridSize < min)
408 surface->gridSize += 1024;
411 void* tmp = winpr_aligned_recalloc((
void*)surface->tiles, surface->gridSize,
415 surface->tilesSize = surface->gridSize;
418 for (
size_t x = oldIndex; x < surface->tilesSize; x++)
420 surface->tiles[x] = progressive_tile_new();
421 if (!surface->tiles[x])
426 winpr_aligned_recalloc(surface->updatedTileIndices, surface->gridSize,
sizeof(UINT32), 32);
430 surface->updatedTileIndices = tmp;
444 surface->id = surfaceId;
445 surface->width = width;
446 surface->height = height;
447 surface->gridWidth = (width + (64 - width % 64)) / 64;
448 surface->gridHeight = (height + (64 - height % 64)) / 64;
449 surface->gridSize = surface->gridWidth * surface->gridHeight;
451 if (!progressive_allocate_tile_cache(surface, surface->gridSize))
453 progressive_surface_context_free(surface);
462 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
468 if (!surface || !tile)
471 zIdx = (tile->yIdx * surface->gridWidth) + tile->xIdx;
473 if (zIdx >= surface->tilesSize)
475 WLog_ERR(TAG,
"Invalid zIndex %" PRIuz, zIdx);
479 t = surface->tiles[zIdx];
481 t->blockType = tile->blockType;
482 t->blockLen = tile->blockLen;
483 t->quantIdxY = tile->quantIdxY;
484 t->quantIdxCb = tile->quantIdxCb;
485 t->quantIdxCr = tile->quantIdxCr;
486 t->xIdx = tile->xIdx;
487 t->yIdx = tile->yIdx;
488 t->flags = tile->flags;
489 t->quality = tile->quality;
490 t->x = tile->xIdx * t->width;
491 t->y = tile->yIdx * t->height;
495 t->ySrlLen = tile->ySrlLen;
496 t->yRawLen = tile->yRawLen;
497 t->cbSrlLen = tile->cbSrlLen;
498 t->cbRawLen = tile->cbRawLen;
499 t->crSrlLen = tile->crSrlLen;
500 t->crRawLen = tile->crRawLen;
501 t->ySrlData = tile->ySrlData;
502 t->yRawData = tile->yRawData;
503 t->cbSrlData = tile->cbSrlData;
504 t->cbRawData = tile->cbRawData;
505 t->crSrlData = tile->crSrlData;
506 t->crRawData = tile->crRawData;
510 t->yLen = tile->yLen;
511 t->cbLen = tile->cbLen;
512 t->crLen = tile->crLen;
513 t->tailLen = tile->tailLen;
514 t->yData = tile->yData;
515 t->cbData = tile->cbData;
516 t->crData = tile->crData;
517 t->tailData = tile->tailData;
520 if (region->usedTiles >= region->numTiles)
522 WLog_ERR(TAG,
"Invalid tile count, only expected %" PRIu16
", got %" PRIu16,
523 region->numTiles, region->usedTiles);
527 region->tiles[region->usedTiles++] = t;
530 if (surface->numUpdatedTiles >= surface->gridSize)
532 if (!progressive_allocate_tile_cache(surface, surface->numUpdatedTiles + 1))
536 surface->updatedTileIndices[surface->numUpdatedTiles++] = (UINT32)zIdx;
543INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
544 UINT16 surfaceId, UINT32 width, UINT32 height)
550 surface = progressive_surface_context_new(surfaceId, width, height);
555 if (!progressive_set_surface_data(progressive, surfaceId, (
void*)surface))
557 progressive_surface_context_free(surface);
565int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
568 progressive_set_surface_data(progressive, surfaceId,
nullptr);
591static int16_t clampi16(
int val)
600static inline void progressive_rfx_idwt_x(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
601 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
602 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
603 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
608 for (
size_t i = 0; i < nDstCount; i++)
610 const INT16* pL = pLowBand;
611 const INT16* pH = pHighBand;
612 INT16* pX = pDstBand;
615 INT16 X0 = clampi16((int32_t)L0 - H0);
616 INT16 X2 = clampi16((int32_t)L0 - H0);
618 for (
size_t j = 0; j < (nHighCount - 1); j++)
624 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
625 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
633 if (nLowCount <= (nHighCount + 1))
635 if (nLowCount <= nHighCount)
638 pX[1] = clampi16((int32_t)X2 + (2 * H0));
644 X0 = clampi16((int32_t)L0 - H0);
646 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
654 X0 = clampi16((int32_t)L0 - (H0 / 2));
656 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
660 pX[3] = clampi16((int32_t)(X0 + L0) / 2);
663 pLowBand += nLowStep;
664 pHighBand += nHighStep;
665 pDstBand += nDstStep;
669static inline void progressive_rfx_idwt_y(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
670 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
671 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
672 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
674 for (
size_t i = 0; i < nDstCount; i++)
678 const INT16* pL = pLowBand;
679 const INT16* pH = pHighBand;
680 INT16* pX = pDstBand;
685 int16_t X0 = clampi16((int32_t)L0 - H0);
686 int16_t X2 = clampi16((int32_t)L0 - H0);
688 for (
size_t j = 0; j < (nHighCount - 1); j++)
694 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
695 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
704 if (nLowCount <= (nHighCount + 1))
706 if (nLowCount <= nHighCount)
710 *pX = clampi16((int32_t)X2 + (2 * H0));
715 X0 = clampi16((int32_t)L0 - H0);
718 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
727 X0 = clampi16((int32_t)L0 - (H0 / 2));
730 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
735 *pX = clampi16((int32_t)(X0 + L0) / 2);
744static inline size_t progressive_rfx_get_band_l_count(
size_t level)
746 return (64 >> level) + 1;
749static inline size_t progressive_rfx_get_band_h_count(
size_t level)
752 return (64 >> 1) - 1;
754 return (64 + (1u << (level - 1))) >> level;
757static inline void progressive_rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer,
758 INT16* WINPR_RESTRICT temp,
size_t level)
760 size_t nDstStepX = 0;
761 size_t nDstStepY = 0;
762 const INT16* WINPR_RESTRICT HL =
nullptr;
763 const INT16* WINPR_RESTRICT LH =
nullptr;
764 const INT16* WINPR_RESTRICT HH =
nullptr;
765 INT16* WINPR_RESTRICT LL =
nullptr;
766 INT16* WINPR_RESTRICT L =
nullptr;
767 INT16* WINPR_RESTRICT H =
nullptr;
768 INT16* WINPR_RESTRICT LLx =
nullptr;
770 const size_t nBandL = progressive_rfx_get_band_l_count(level);
771 const size_t nBandH = progressive_rfx_get_band_h_count(level);
774 HL = &buffer[offset];
775 offset += (nBandH * nBandL);
776 LH = &buffer[offset];
777 offset += (nBandL * nBandH);
778 HH = &buffer[offset];
779 offset += (nBandH * nBandH);
780 LL = &buffer[offset];
781 nDstStepX = (nBandL + nBandH);
782 nDstStepY = (nBandL + nBandH);
785 offset += (nBandL * nDstStepX);
790 progressive_rfx_idwt_x(LL, nBandL, HL, nBandH, L, nDstStepX, nBandL, nBandH, nBandL);
793 progressive_rfx_idwt_x(LH, nBandL, HH, nBandH, H, nDstStepX, nBandL, nBandH, nBandH);
796 progressive_rfx_idwt_y(L, nDstStepX, H, nDstStepX, LLx, nDstStepY, nBandL, nBandH,
800void rfx_dwt_2d_extrapolate_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
802 WINPR_ASSERT(buffer);
803 WINPR_ASSERT(dwt_buffer);
804 progressive_rfx_dwt_2d_decode_block(&buffer[3807], dwt_buffer, 3);
805 progressive_rfx_dwt_2d_decode_block(&buffer[3007], dwt_buffer, 2);
806 progressive_rfx_dwt_2d_decode_block(&buffer[0], dwt_buffer, 1);
809static inline int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
810 INT16* WINPR_RESTRICT buffer,
811 INT16* WINPR_RESTRICT current, BOOL coeffDiff,
812 BOOL extrapolate, BOOL reverse)
816 if (!progressive || !buffer || !current)
819 const uint32_t belements = 4096;
820 const uint32_t bsize = belements *
sizeof(INT16);
822 memcpy(buffer, current, bsize);
824 memcpy(current, buffer, bsize);
827 const pstatus_t rc = prims->
add_16s_inplace(buffer, current, belements);
828 if (rc != PRIMITIVES_SUCCESS)
832 INT16* temp = (INT16*)BufferPool_Take(progressive->bufferPool, -1);
839 progressive->rfx_context->dwt_2d_decode(buffer, temp);
843 WINPR_ASSERT(progressive->rfx_context->dwt_2d_extrapolate_decode);
844 progressive->rfx_context->dwt_2d_extrapolate_decode(buffer, temp);
846 BufferPool_Return(progressive->bufferPool, temp);
850static inline BOOL progressive_rfx_decode_block(
const primitives_t* prims,
851 INT16* WINPR_RESTRICT buffer, UINT32 length,
861progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
863 const BYTE* WINPR_RESTRICT data, UINT32 length,
864 INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
865 INT16* WINPR_RESTRICT sign, BOOL coeffDiff,
866 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
871 status = progressive->rfx_context->rlgr_decode(RLGR1, data, length, buffer, 4096);
876 CopyMemory(sign, buffer, 4096ULL * 2ULL);
879 rfx_differential_decode(buffer + 4032, 64);
880 if (!progressive_rfx_decode_block(prims, &buffer[0], 1024, shift->HL1))
882 if (!progressive_rfx_decode_block(prims, &buffer[1024], 1024, shift->LH1))
884 if (!progressive_rfx_decode_block(prims, &buffer[2048], 1024, shift->HH1))
886 if (!progressive_rfx_decode_block(prims, &buffer[3072], 256, shift->HL2))
888 if (!progressive_rfx_decode_block(prims, &buffer[3328], 256, shift->LH2))
890 if (!progressive_rfx_decode_block(prims, &buffer[3584], 256, shift->HH2))
892 if (!progressive_rfx_decode_block(prims, &buffer[3840], 64, shift->HL3))
894 if (!progressive_rfx_decode_block(prims, &buffer[3904], 64, shift->LH3))
896 if (!progressive_rfx_decode_block(prims, &buffer[3968], 64, shift->HH3))
898 if (!progressive_rfx_decode_block(prims, &buffer[4032], 64, shift->LL3))
903 if (!progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1))
905 if (!progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1))
907 if (!progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1))
909 if (!progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2))
911 if (!progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2))
913 if (!progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2))
915 if (!progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3))
917 if (!progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3))
919 if (!progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3))
921 rfx_differential_decode(&buffer[4015], 81);
922 if (!progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3))
925 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
930progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
932 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
938 BOOL extrapolate = 0;
939 BYTE* pBuffer =
nullptr;
957 diff = tile->flags & RFX_TILE_DIFFERENCE;
958 sub = context->flags & RFX_SUBBAND_DIFFING;
959 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
961#if defined(WITH_DEBUG_CODECS)
962 WLog_Print(progressive->log, WLOG_DEBUG,
963 "ProgressiveTile%s: quantIdx Y: %" PRIu8
" Cb: %" PRIu8
" Cr: %" PRIu8
964 " xIdx: %" PRIu16
" yIdx: %" PRIu16
" flags: 0x%02" PRIX8
" quality: %" PRIu8
965 " yLen: %" PRIu16
" cbLen: %" PRIu16
" crLen: %" PRIu16
" tailLen: %" PRIu16
"",
966 (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ?
"First" :
"Simple",
967 tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx,
968 tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
971 if (tile->quantIdxY >= region->numQuant)
973 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
977 quantY = &(region->quantVals[tile->quantIdxY]);
979 if (tile->quantIdxCb >= region->numQuant)
981 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
986 quantCb = &(region->quantVals[tile->quantIdxCb]);
988 if (tile->quantIdxCr >= region->numQuant)
990 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
995 quantCr = &(region->quantVals[tile->quantIdxCr]);
997 if (tile->quality == 0xFF)
999 quantProgVal = &(progressive->quantProgValFull);
1003 if (tile->quality >= region->numProgQuant)
1005 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1006 region->numProgQuant);
1010 quantProgVal = &(region->quantProgVals[tile->quality]);
1013 quantProgY = &(quantProgVal->yQuantValues);
1014 quantProgCb = &(quantProgVal->cbQuantValues);
1015 quantProgCr = &(quantProgVal->crQuantValues);
1017 tile->yQuant = *quantY;
1018 tile->cbQuant = *quantCb;
1019 tile->crQuant = *quantCr;
1020 tile->yProgQuant = *quantProgY;
1021 tile->cbProgQuant = *quantProgCb;
1022 tile->crProgQuant = *quantProgCr;
1024 progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
1025 progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
1026 progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
1027 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1028 if (!progressive_rfx_quant_lsub(&shiftY, 1))
1030 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1031 if (!progressive_rfx_quant_lsub(&shiftCb, 1))
1033 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1034 if (!progressive_rfx_quant_lsub(&shiftCr, 1))
1037 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
1038 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
1039 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
1041 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
1042 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
1043 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
1045 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1046 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
1047 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
1048 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
1050 rc = progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0],
1051 pCurrent[0], pSign[0], diff, sub, extrapolate);
1054 rc = progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen,
1055 pSrcDst[1], pCurrent[1], pSign[1], diff, sub,
1059 rc = progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen,
1060 pSrcDst[2], pCurrent[2], pSign[2], diff, sub,
1066 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1067 rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1068 progressive->format, &roi_64x64);
1071 BufferPool_Return(progressive->bufferPool, pBuffer);
1075static inline INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1078 WINPR_ASSERT(state);
1089 const UINT32 k = state->kp / 8;
1094 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1095 BitStream_Shift(bs, 1);
1100 state->nz = (1 << k);
1117 bs->mask = ((1u << k) - 1);
1119 WINPR_ASSERTING_INT_CAST(int16_t, ((bs->accumulator >> (32u - k)) & bs->mask));
1120 BitStream_Shift(bs, k);
1134 const UINT32 sign = (bs->accumulator & 0x80000000) ? 1 : 0;
1135 BitStream_Shift(bs, 1);
1143 return sign ? -1 : 1;
1146 const UINT32 max = (1u << numBits) - 1;
1150 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1151 BitStream_Shift(bs, 1);
1159 if (mag > INT16_MAX)
1161 return (INT16)(sign ? -1 * (int)mag : (INT16)mag);
1165progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state)
1176 pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
1179 BitStream_Shift(raw, pad);
1181 pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
1184 BitStream_Shift(srl, pad);
1186 if (BitStream_GetRemainingLength(srl) == 8)
1187 BitStream_Shift(srl, 8);
1192static inline int16_t rawShift(
wBitStream* raw, UINT32 numBits)
1195 WINPR_ASSERT(numBits > 0);
1197 raw->mask = ((1u << numBits) - 1);
1198 const int16_t input = (int16_t)((raw->accumulator >> (32 - numBits)) & raw->mask);
1199 BitStream_Shift(raw, numBits);
1203static inline int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1204 INT16* WINPR_RESTRICT buffer,
1205 INT16* WINPR_RESTRICT sign, UINT32 length,
1206 UINT32 shift, WINPR_ATTR_UNUSED UINT32 bitPos,
1217 for (UINT32 index = 0; index < length; index++)
1219 input = rawShift(raw, numBits);
1221 const int32_t shifted = input << shift;
1222 const int32_t val = buffer[index] + shifted;
1223 const int16_t ival = WINPR_ASSERTING_INT_CAST(int16_t, val);
1224 buffer[index] = ival;
1230 for (UINT32 index = 0; index < length; index++)
1232 if (sign[index] > 0)
1235 input = rawShift(raw, numBits);
1237 else if (sign[index] < 0)
1240 input = rawShift(raw, numBits);
1246 input = progressive_rfx_srl_read(state, numBits);
1247 sign[index] = WINPR_ASSERTING_INT_CAST(int16_t, input);
1250 const int32_t val = input << shift;
1251 const int32_t ival = buffer[index] + val;
1252 buffer[index] = WINPR_ASSERTING_INT_CAST(INT16, ival);
1258static inline int progressive_rfx_upgrade_component(
1259 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1263 INT16* WINPR_RESTRICT current, INT16* WINPR_RESTRICT sign,
const BYTE* WINPR_RESTRICT srlData,
1264 UINT32 srlLen,
const BYTE* WINPR_RESTRICT rawData, UINT32 rawLen, BOOL coeffDiff,
1265 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
1270 RFX_PROGRESSIVE_UPGRADE_STATE state = WINPR_C_ARRAY_INIT;
1276 BitStream_Attach(state.srl, srlData, srlLen);
1277 BitStream_Fetch(state.srl);
1278 BitStream_Attach(state.raw, rawData, rawLen);
1279 BitStream_Fetch(state.raw);
1282 rc = progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1,
1286 rc = progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1,
1287 bitPos->LH1, numBits->LH1);
1290 rc = progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1,
1291 bitPos->HH1, numBits->HH1);
1294 rc = progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2,
1295 bitPos->HL2, numBits->HL2);
1298 rc = progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2,
1299 bitPos->LH2, numBits->LH2);
1302 rc = progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2,
1303 bitPos->HH2, numBits->HH2);
1306 rc = progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3,
1307 bitPos->HL3, numBits->HL3);
1310 rc = progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3,
1311 bitPos->LH3, numBits->LH3);
1314 rc = progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3,
1315 bitPos->HH3, numBits->HH3);
1319 state.nonLL = FALSE;
1320 rc = progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3,
1321 bitPos->LL3, numBits->LL3);
1324 rc = progressive_rfx_upgrade_state_finish(&state);
1327 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
1332progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1334 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1340 BOOL extrapolate = 0;
1341 BYTE* pBuffer =
nullptr;
1342 INT16* pSign[3] = WINPR_C_ARRAY_INIT;
1343 INT16* pSrcDst[3] = WINPR_C_ARRAY_INIT;
1344 INT16* pCurrent[3] = WINPR_C_ARRAY_INIT;
1364 coeffDiff = tile->flags & RFX_TILE_DIFFERENCE;
1365 sub = context->flags & RFX_SUBBAND_DIFFING;
1366 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
1370#if defined(WITH_DEBUG_CODECS)
1371 WLog_Print(progressive->log, WLOG_DEBUG,
1372 "ProgressiveTileUpgrade: pass: %" PRIu16
" quantIdx Y: %" PRIu8
" Cb: %" PRIu8
1373 " Cr: %" PRIu8
" xIdx: %" PRIu16
" yIdx: %" PRIu16
" quality: %" PRIu8
1374 " ySrlLen: %" PRIu16
" yRawLen: %" PRIu16
" cbSrlLen: %" PRIu16
" cbRawLen: %" PRIu16
1375 " crSrlLen: %" PRIu16
" crRawLen: %" PRIu16
"",
1376 tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx,
1377 tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen,
1378 tile->cbRawLen, tile->crSrlLen, tile->crRawLen);
1381 if (tile->quantIdxY >= region->numQuant)
1383 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
1387 quantY = &(region->quantVals[tile->quantIdxY]);
1389 if (tile->quantIdxCb >= region->numQuant)
1391 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
1396 quantCb = &(region->quantVals[tile->quantIdxCb]);
1398 if (tile->quantIdxCr >= region->numQuant)
1400 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1405 quantCr = &(region->quantVals[tile->quantIdxCr]);
1407 if (tile->quality == 0xFF)
1409 quantProg = &(progressive->quantProgValFull);
1413 if (tile->quality >= region->numProgQuant)
1415 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1416 region->numProgQuant);
1420 quantProg = &(region->quantProgVals[tile->quality]);
1423 quantProgY = &(quantProg->yQuantValues);
1424 quantProgCb = &(quantProg->cbQuantValues);
1425 quantProgCr = &(quantProg->crQuantValues);
1427 if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
1428 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantY has changed!");
1430 if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
1431 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCb has changed!");
1433 if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
1434 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCr has changed!");
1436 if (!(context->flags & RFX_SUBBAND_DIFFING))
1437 WLog_WARN(TAG,
"PROGRESSIVE_BLOCK_CONTEXT::flags & RFX_SUBBAND_DIFFING not set");
1439 progressive_rfx_quant_add(quantY, quantProgY, &yBitPos);
1440 progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos);
1441 progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos);
1442 if (!progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits))
1444 if (!progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits))
1446 if (!progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits))
1448 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1449 if (!progressive_rfx_quant_lsub(&shiftY, 1))
1451 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1452 if (!progressive_rfx_quant_lsub(&shiftCb, 1))
1454 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1455 if (!progressive_rfx_quant_lsub(&shiftCr, 1))
1458 tile->yBitPos = yBitPos;
1459 tile->cbBitPos = cbBitPos;
1460 tile->crBitPos = crBitPos;
1461 tile->yQuant = *quantY;
1462 tile->cbQuant = *quantCb;
1463 tile->crQuant = *quantCr;
1464 tile->yProgQuant = *quantProgY;
1465 tile->cbProgQuant = *quantProgCb;
1466 tile->crProgQuant = *quantProgCr;
1468 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
1469 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
1470 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
1472 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
1473 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
1474 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
1476 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1477 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
1478 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
1479 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
1481 status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
1482 pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData,
1483 tile->ySrlLen, tile->yRawData, tile->yRawLen,
1484 coeffDiff, sub, extrapolate);
1489 status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
1490 pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData,
1491 tile->cbSrlLen, tile->cbRawData, tile->cbRawLen,
1492 coeffDiff, sub, extrapolate);
1497 status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
1498 pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData,
1499 tile->crSrlLen, tile->crRawData, tile->crRawLen,
1500 coeffDiff, sub, extrapolate);
1506 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1507 status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1508 progressive->format, &roi_64x64);
1511 BufferPool_Return(progressive->bufferPool, pBuffer);
1515static inline BOOL progressive_tile_read_upgrade(
1516 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1518 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1522 const size_t expect = 20;
1524 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1527 tile.blockType = blockType;
1528 tile.blockLen = blockLen;
1531 Stream_Read_UINT8(s, tile.quantIdxY);
1532 Stream_Read_UINT8(s, tile.quantIdxCb);
1533 Stream_Read_UINT8(s, tile.quantIdxCr);
1534 Stream_Read_UINT16(s, tile.xIdx);
1535 Stream_Read_UINT16(s, tile.yIdx);
1536 Stream_Read_UINT8(s, tile.quality);
1537 Stream_Read_UINT16(s, tile.ySrlLen);
1538 Stream_Read_UINT16(s, tile.yRawLen);
1539 Stream_Read_UINT16(s, tile.cbSrlLen);
1540 Stream_Read_UINT16(s, tile.cbRawLen);
1541 Stream_Read_UINT16(s, tile.crSrlLen);
1542 Stream_Read_UINT16(s, tile.crRawLen);
1544 tile.ySrlData = Stream_Pointer(s);
1545 if (!Stream_SafeSeek(s, tile.ySrlLen))
1547 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.ySrlLen);
1551 tile.yRawData = Stream_Pointer(s);
1552 if (!Stream_SafeSeek(s, tile.yRawLen))
1554 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yRawLen);
1558 tile.cbSrlData = Stream_Pointer(s);
1559 if (!Stream_SafeSeek(s, tile.cbSrlLen))
1561 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1566 tile.cbRawData = Stream_Pointer(s);
1567 if (!Stream_SafeSeek(s, tile.cbRawLen))
1569 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1574 tile.crSrlData = Stream_Pointer(s);
1575 if (!Stream_SafeSeek(s, tile.crSrlLen))
1577 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1582 tile.crRawData = Stream_Pointer(s);
1583 if (!Stream_SafeSeek(s, tile.crRawLen))
1585 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1590 return progressive_surface_tile_replace(surface, region, &tile, TRUE);
1594progressive_tile_read(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, BOOL simple,
1595 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
1597 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1601 size_t expect = simple ? 16 : 17;
1603 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1606 tile.blockType = blockType;
1607 tile.blockLen = blockLen;
1609 Stream_Read_UINT8(s, tile.quantIdxY);
1610 Stream_Read_UINT8(s, tile.quantIdxCb);
1611 Stream_Read_UINT8(s, tile.quantIdxCr);
1612 Stream_Read_UINT16(s, tile.xIdx);
1613 Stream_Read_UINT16(s, tile.yIdx);
1614 Stream_Read_UINT8(s, tile.flags);
1617 Stream_Read_UINT8(s, tile.quality);
1619 tile.quality = 0xFF;
1620 Stream_Read_UINT16(s, tile.yLen);
1621 Stream_Read_UINT16(s, tile.cbLen);
1622 Stream_Read_UINT16(s, tile.crLen);
1623 Stream_Read_UINT16(s, tile.tailLen);
1625 tile.yData = Stream_Pointer(s);
1626 if (!Stream_SafeSeek(s, tile.yLen))
1628 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yLen);
1632 tile.cbData = Stream_Pointer(s);
1633 if (!Stream_SafeSeek(s, tile.cbLen))
1635 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.cbLen);
1639 tile.crData = Stream_Pointer(s);
1640 if (!Stream_SafeSeek(s, tile.crLen))
1642 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.crLen);
1646 tile.tailData = Stream_Pointer(s);
1647 if (!Stream_SafeSeek(s, tile.tailLen))
1649 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.tailLen);
1653 return progressive_surface_tile_replace(surface, region, &tile, FALSE);
1656static void CALLBACK progressive_process_tiles_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1657 void* context, PTP_WORK work)
1661 WINPR_UNUSED(instance);
1664 switch (param->tile->blockType)
1666 case PROGRESSIVE_WBT_TILE_SIMPLE:
1667 case PROGRESSIVE_WBT_TILE_FIRST:
1668 progressive_decompress_tile_first(param->progressive, param->tile, param->region,
1672 case PROGRESSIVE_WBT_TILE_UPGRADE:
1673 progressive_decompress_tile_upgrade(param->progressive, param->tile, param->region,
1677 WLog_Print(param->progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16
" (%s)",
1678 param->tile->blockType,
1679 rfx_get_progressive_block_type_string(param->tile->blockType));
1684static inline SSIZE_T
1685progressive_process_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1687 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1693 const size_t start = Stream_GetPosition(s);
1694 UINT16 blockType = 0;
1695 UINT32 blockLen = 0;
1697 UINT16 close_cnt = 0;
1699 WINPR_ASSERT(progressive);
1700 WINPR_ASSERT(region);
1702 if (!Stream_CheckAndLogRequiredLength(TAG, s, region->tileDataSize))
1705 while ((Stream_GetRemainingLength(s) >= 6) &&
1706 (region->tileDataSize > (Stream_GetPosition(s) - start)))
1708 const size_t pos = Stream_GetPosition(s);
1710 Stream_Read_UINT16(s, blockType);
1711 Stream_Read_UINT32(s, blockLen);
1713#if defined(WITH_DEBUG_CODECS)
1714 WLog_Print(progressive->log, WLOG_DEBUG,
"%s",
1715 rfx_get_progressive_block_type_string(blockType));
1720 WLog_Print(progressive->log, WLOG_ERROR,
"Expected >= %" PRIu32
" remaining %" PRIu32,
1724 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
1729 case PROGRESSIVE_WBT_TILE_SIMPLE:
1730 if (!progressive_tile_read(progressive, TRUE, s, blockType, blockLen, surface,
1735 case PROGRESSIVE_WBT_TILE_FIRST:
1736 if (!progressive_tile_read(progressive, FALSE, s, blockType, blockLen, surface,
1741 case PROGRESSIVE_WBT_TILE_UPGRADE:
1742 if (!progressive_tile_read_upgrade(progressive, s, blockType, blockLen, surface,
1747 WLog_ERR(TAG,
"Invalid block type %04" PRIx16
" (%s)", blockType,
1748 rfx_get_progressive_block_type_string(blockType));
1752 size_t rem = Stream_GetPosition(s);
1753 if ((rem - pos) != blockLen)
1755 WLog_Print(progressive->log, WLOG_ERROR,
1756 "Actual block read %" PRIuz
" but expected %" PRIu32, rem - pos, blockLen);
1762 end = Stream_GetPosition(s);
1763 if ((end - start) != region->tileDataSize)
1765 WLog_Print(progressive->log, WLOG_ERROR,
1766 "Actual total blocks read %" PRIuz
" but expected %" PRIu32, end - start,
1767 region->tileDataSize);
1771 if (count != region->numTiles)
1773 WLog_Print(progressive->log, WLOG_WARN,
1774 "numTiles inconsistency: actual: %" PRIu32
", expected: %" PRIu16
"\n", count,
1779 for (UINT32 idx = 0; idx < region->numTiles; idx++)
1783 param->progressive = progressive;
1784 param->region = region;
1785 param->context = context;
1788 if (progressive->rfx_context->priv->UseThreads)
1790 progressive->work_objects[idx] = CreateThreadpoolWork(
1791 progressive_process_tiles_tile_work_callback, (
void*)param,
nullptr);
1792 if (!progressive->work_objects[idx])
1794 WLog_Print(progressive->log, WLOG_ERROR,
1795 "Failed to create ThreadpoolWork for tile %" PRIu32, idx);
1800 SubmitThreadpoolWork(progressive->work_objects[idx]);
1802 close_cnt = WINPR_ASSERTING_INT_CAST(UINT16, idx + 1);
1806 progressive_process_tiles_tile_work_callback(
nullptr, param,
nullptr);
1811 WLog_Print(progressive->log, WLOG_ERROR,
"Failed to decompress %s at %" PRIu16,
1812 rfx_get_progressive_block_type_string(tile->blockType), idx);
1817 if (progressive->rfx_context->priv->UseThreads)
1819 for (UINT32 idx = 0; idx < close_cnt; idx++)
1821 WaitForThreadpoolWorkCallbacks(progressive->work_objects[idx], FALSE);
1822 CloseThreadpoolWork(progressive->work_objects[idx]);
1831 return (SSIZE_T)(end - start);
1834static inline SSIZE_T progressive_wb_sync(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1835 wStream* WINPR_RESTRICT s, UINT16 blockType,
1838 const UINT32 magic = 0xCACCACCA;
1839 const UINT16 version = 0x0100;
1842 sync.blockType = blockType;
1843 sync.blockLen = blockLen;
1845 if (sync.blockLen != 12)
1847 WLog_Print(progressive->log, WLOG_ERROR,
1848 "PROGRESSIVE_BLOCK_SYNC::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1849 sync.blockLen, 12u);
1853 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1856#if defined(WITH_DEBUG_CODECS)
1857 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveSync");
1860 Stream_Read_UINT32(s, sync.magic);
1861 Stream_Read_UINT16(s, sync.version);
1863 if (sync.magic != magic)
1865 WLog_Print(progressive->log, WLOG_ERROR,
1866 "PROGRESSIVE_BLOCK_SYNC::magic = 0x%08" PRIx32
" != 0x%08" PRIx32, sync.magic,
1871 if (sync.version != 0x0100)
1873 WLog_Print(progressive->log, WLOG_ERROR,
1874 "PROGRESSIVE_BLOCK_SYNC::version = 0x%04" PRIx16
" != 0x%04" PRIu16,
1875 sync.version, version);
1879 if ((progressive->state & FLAG_WBT_SYNC) != 0)
1880 WLog_WARN(TAG,
"Duplicate PROGRESSIVE_BLOCK_SYNC, ignoring");
1882 progressive->state |= FLAG_WBT_SYNC;
1886static inline SSIZE_T progressive_wb_frame_begin(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1887 wStream* WINPR_RESTRICT s, UINT16 blockType,
1892 frameBegin.blockType = blockType;
1893 frameBegin.blockLen = blockLen;
1895 if (frameBegin.blockLen != 12)
1897 WLog_Print(progressive->log, WLOG_ERROR,
1898 " RFX_PROGRESSIVE_FRAME_BEGIN::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1899 frameBegin.blockLen, 12u);
1903 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1906 Stream_Read_UINT32(s, frameBegin.frameIndex);
1907 Stream_Read_UINT16(s, frameBegin.regionCount);
1909#if defined(WITH_DEBUG_CODECS)
1910 WLog_Print(progressive->log, WLOG_DEBUG,
1911 "ProgressiveFrameBegin: frameIndex: %" PRIu32
" regionCount: %" PRIu16
"",
1912 frameBegin.frameIndex, frameBegin.regionCount);
1921 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1923 WLog_ERR(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_BEGIN in stream, this is not allowed!");
1927 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1929 WLog_ERR(TAG,
"RFX_PROGRESSIVE_FRAME_BEGIN after RFX_PROGRESSIVE_FRAME_END in stream, this "
1934 progressive->state |= FLAG_WBT_FRAME_BEGIN;
1938static inline SSIZE_T progressive_wb_frame_end(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1939 wStream* WINPR_RESTRICT s, UINT16 blockType,
1944 frameEnd.blockType = blockType;
1945 frameEnd.blockLen = blockLen;
1947 if (frameEnd.blockLen != 6)
1949 WLog_Print(progressive->log, WLOG_ERROR,
1950 " RFX_PROGRESSIVE_FRAME_END::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1951 frameEnd.blockLen, 6u);
1955 if (Stream_GetRemainingLength(s) != 0)
1957 WLog_Print(progressive->log, WLOG_ERROR,
1958 "ProgressiveFrameEnd short %" PRIuz
", expected %u",
1959 Stream_GetRemainingLength(s), 0U);
1963#if defined(WITH_DEBUG_CODECS)
1964 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveFrameEnd");
1967 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
1968 WLog_WARN(TAG,
"RFX_PROGRESSIVE_FRAME_END before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
1969 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1970 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_END, ignoring");
1972 progressive->state |= FLAG_WBT_FRAME_END;
1976static inline SSIZE_T progressive_wb_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1977 wStream* WINPR_RESTRICT s, UINT16 blockType,
1981 context->blockType = blockType;
1982 context->blockLen = blockLen;
1984 if (context->blockLen != 10)
1986 WLog_Print(progressive->log, WLOG_ERROR,
1987 "RFX_PROGRESSIVE_CONTEXT::blockLen = 0x%08" PRIx32
" != 0x%08x",
1988 context->blockLen, 10u);
1992 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1995 Stream_Read_UINT8(s, context->ctxId);
1996 Stream_Read_UINT16(s, context->tileSize);
1997 Stream_Read_UINT8(s, context->flags);
1999 if (context->ctxId != 0x00)
2000 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT::ctxId != 0x00: %" PRIu8, context->ctxId);
2002 if (context->tileSize != 64)
2004 WLog_ERR(TAG,
"RFX_PROGRESSIVE_CONTEXT::tileSize != 0x40: %" PRIu16, context->tileSize);
2008 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
2009 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_BEGIN");
2010 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2011 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_END");
2012 if ((progressive->state & FLAG_WBT_CONTEXT) != 0)
2013 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_CONTEXT received, ignoring.");
2015#if defined(WITH_DEBUG_CODECS)
2016 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveContext: flags: 0x%02" PRIX8
"",
2020 progressive->state |= FLAG_WBT_CONTEXT;
2024static inline SSIZE_T
2025progressive_wb_read_region_header(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2026 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
2027 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2029 region->usedTiles = 0;
2031 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2034 region->blockType = blockType;
2035 region->blockLen = blockLen;
2036 Stream_Read_UINT8(s, region->tileSize);
2037 Stream_Read_UINT16(s, region->numRects);
2038 Stream_Read_UINT8(s, region->numQuant);
2039 Stream_Read_UINT8(s, region->numProgQuant);
2040 Stream_Read_UINT8(s, region->flags);
2041 Stream_Read_UINT16(s, region->numTiles);
2042 Stream_Read_UINT32(s, region->tileDataSize);
2044 if (region->tileSize != 64)
2046 WLog_Print(progressive->log, WLOG_ERROR,
2047 "ProgressiveRegion tile size %" PRIu8
", expected %u", region->tileSize, 64U);
2051 if (region->numRects < 1)
2053 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion missing rect count %" PRIu16,
2058 if (region->numQuant > 7)
2060 WLog_Print(progressive->log, WLOG_ERROR,
2061 "ProgressiveRegion quant count too high %" PRIu8
", expected < %u",
2062 region->numQuant, 7U);
2066 const SSIZE_T rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, Stream_GetRemainingLength(s));
2067 const SSIZE_T expect = region->numRects * 8ll + region->numQuant * 5ll +
2068 region->numProgQuant * 16ll + region->tileDataSize;
2072 if (len / 8LL < region->numRects)
2074 WLog_Print(progressive->log, WLOG_ERROR,
2075 "ProgressiveRegion data short for region->rects");
2078 len -= region->numRects * 8LL;
2080 if (len / 5LL < region->numQuant)
2082 WLog_Print(progressive->log, WLOG_ERROR,
2083 "ProgressiveRegion data short for region->cQuant");
2086 len -= region->numQuant * 5LL;
2088 if (len / 16LL < region->numProgQuant)
2090 WLog_Print(progressive->log, WLOG_ERROR,
2091 "ProgressiveRegion data short for region->cProgQuant");
2094 len -= region->numProgQuant * 16LL;
2096 if (len < region->tileDataSize * 1ll)
2098 WLog_Print(progressive->log, WLOG_ERROR,
2099 "ProgressiveRegion data short for region->tiles");
2102 len -= region->tileDataSize;
2105 WLog_Print(progressive->log, WLOG_WARN,
2106 "Unused bytes detected, %" PRIdz
" bytes not processed", len);
2112static inline SSIZE_T progressive_wb_skip_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2113 wStream* WINPR_RESTRICT s, UINT16 blockType,
2116 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2119 progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2123 if (!Stream_SafeSeek(s, WINPR_ASSERTING_INT_CAST(
size_t, rc)))
2129static inline SSIZE_T progressive_wb_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2130 wStream* WINPR_RESTRICT s, UINT16 blockType,
2133 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2138 UINT16 boxRight = 0;
2139 UINT16 boxBottom = 0;
2142 UINT16 idxRight = 0;
2143 UINT16 idxBottom = 0;
2146 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
2148 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
2149 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2151 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2153 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION after RFX_PROGRESSIVE_FRAME_END, ignoring");
2154 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2157 progressive->state |= FLAG_WBT_REGION;
2159 rc = progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2163 for (UINT16 index = 0; index < region->numRects; index++)
2165 RFX_RECT* rect = &(region->rects[index]);
2166 Stream_Read_UINT16(s, rect->x);
2167 Stream_Read_UINT16(s, rect->y);
2168 Stream_Read_UINT16(s, rect->width);
2169 Stream_Read_UINT16(s, rect->height);
2172 for (BYTE index = 0; index < region->numQuant; index++)
2175 progressive_component_codec_quant_read(s, quantVal);
2177 if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
2179 WLog_Print(progressive->log, WLOG_ERROR,
2180 "ProgressiveRegion region->cQuant[%" PRIu32
"] < 6", index);
2184 if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
2186 WLog_Print(progressive->log, WLOG_ERROR,
2187 "ProgressiveRegion region->cQuant[%" PRIu32
"] > 15", index);
2192 for (BYTE index = 0; index < region->numProgQuant; index++)
2196 Stream_Read_UINT8(s, quantProgVal->quality);
2198 progressive_component_codec_quant_read(s, &(quantProgVal->yQuantValues));
2199 progressive_component_codec_quant_read(s, &(quantProgVal->cbQuantValues));
2200 progressive_component_codec_quant_read(s, &(quantProgVal->crQuantValues));
2203#if defined(WITH_DEBUG_CODECS)
2204 WLog_Print(progressive->log, WLOG_DEBUG,
2205 "ProgressiveRegion: numRects: %" PRIu16
" numTiles: %" PRIu16
2206 " tileDataSize: %" PRIu32
" flags: 0x%02" PRIX8
" numQuant: %" PRIu8
2207 " numProgQuant: %" PRIu8
"",
2208 region->numRects, region->numTiles, region->tileDataSize, region->flags,
2209 region->numQuant, region->numProgQuant);
2212 boxLeft = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridWidth);
2213 boxTop = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridHeight);
2217 for (UINT16 index = 0; index < region->numRects; index++)
2219 RFX_RECT* rect = &(region->rects[index]);
2220 idxLeft = rect->x / 64;
2221 idxTop = rect->y / 64;
2222 idxRight = (rect->x + rect->width + 63) / 64;
2223 idxBottom = (rect->y + rect->height + 63) / 64;
2225 if (idxLeft < boxLeft)
2228 if (idxTop < boxTop)
2231 if (idxRight > boxRight)
2232 boxRight = idxRight;
2234 if (idxBottom > boxBottom)
2235 boxBottom = idxBottom;
2237#if defined(WITH_DEBUG_CODECS)
2238 WLog_Print(progressive->log, WLOG_DEBUG,
2239 "rect[%" PRIu16
"]: x: %" PRIu16
" y: %" PRIu16
" w: %" PRIu16
" h: %" PRIu16
"",
2240 index, rect->x, rect->y, rect->width, rect->height);
2244 const SSIZE_T res = progressive_process_tiles(progressive, s, region, surface, context);
2250static inline SSIZE_T progressive_parse_block(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2253 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2255 UINT16 blockType = 0;
2256 UINT32 blockLen = 0;
2258 wStream sub = WINPR_C_ARRAY_INIT;
2260 WINPR_ASSERT(progressive);
2262 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
2265 Stream_Read_UINT16(s, blockType);
2266 Stream_Read_UINT32(s, blockLen);
2270 WLog_WARN(TAG,
"Invalid blockLen %" PRIu32
", expected >= 6", blockLen);
2273 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
2275 Stream_StaticConstInit(&sub, Stream_Pointer(s), blockLen - 6);
2276 Stream_Seek(s, blockLen - 6);
2280 case PROGRESSIVE_WBT_SYNC:
2281 rc = progressive_wb_sync(progressive, &sub, blockType, blockLen);
2284 case PROGRESSIVE_WBT_FRAME_BEGIN:
2285 rc = progressive_wb_frame_begin(progressive, &sub, blockType, blockLen);
2288 case PROGRESSIVE_WBT_FRAME_END:
2289 rc = progressive_wb_frame_end(progressive, &sub, blockType, blockLen);
2292 case PROGRESSIVE_WBT_CONTEXT:
2293 rc = progressive_wb_context(progressive, &sub, blockType, blockLen);
2296 case PROGRESSIVE_WBT_REGION:
2297 rc = progressive_wb_region(progressive, &sub, blockType, blockLen, surface, region);
2301 WLog_Print(progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16, blockType);
2308 if (Stream_GetRemainingLength(&sub) > 0)
2310 WLog_Print(progressive->log, WLOG_ERROR,
2311 "block len %" PRIu32
" does not match read data %" PRIuz, blockLen,
2312 blockLen - Stream_GetRemainingLength(&sub));
2319static inline BOOL update_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2321 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2322 UINT32 nXDst, UINT32 nYDst,
2323 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
2324 REGION16* WINPR_RESTRICT invalidRegion)
2327 REGION16 clippingRects = WINPR_C_ARRAY_INIT;
2328 region16_init(&clippingRects);
2330 for (UINT32 i = 0; i < region->numRects; i++)
2333 const RFX_RECT* rect = &(region->rects[i]);
2335 clippingRect.left = (UINT16)nXDst + rect->x;
2336 clippingRect.top = (UINT16)nYDst + rect->y;
2337 clippingRect.right = clippingRect.left + rect->width;
2338 clippingRect.bottom = clippingRect.top + rect->height;
2339 if (!region16_union_rect(&clippingRects, &clippingRects, &clippingRect))
2341 region16_uninit(&clippingRects);
2346 for (UINT32 i = 0; i < surface->numUpdatedTiles; i++)
2348 UINT32 nbUpdateRects = 0;
2352 WINPR_ASSERT(surface->updatedTileIndices);
2353 const UINT32 index = surface->updatedTileIndices[i];
2355 WINPR_ASSERT(index < surface->tilesSize);
2359 const UINT32 dl = nXDst + tile->x;
2360 updateRect.left = WINPR_ASSERTING_INT_CAST(UINT16, dl);
2362 const UINT32 dt = nYDst + tile->y;
2363 updateRect.top = WINPR_ASSERTING_INT_CAST(UINT16, dt);
2364 updateRect.right = updateRect.left + 64;
2365 updateRect.bottom = updateRect.top + 64;
2367 REGION16 updateRegion = WINPR_C_ARRAY_INIT;
2368 region16_init(&updateRegion);
2369 if (!region16_intersect_rect(&updateRegion, &clippingRects, &updateRect))
2371 region16_uninit(&updateRegion);
2374 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
2376 for (UINT32 j = 0; j < nbUpdateRects; j++)
2380 if (rect->left < updateRect.left)
2382 const UINT32 nXSrc = rect->left - updateRect.left;
2383 const UINT32 nYSrc = rect->top - updateRect.top;
2384 const UINT32 width = rect->right - rect->left;
2385 const UINT32 height = rect->bottom - rect->top;
2387 if (rect->left + width > surface->width)
2389 if (rect->top + height > surface->height)
2391 rc = freerdp_image_copy_no_overlap(
2392 pDstData, DstFormat, nDstStep, rect->left, rect->top, width, height, tile->data,
2393 progressive->format, tile->stride, nXSrc, nYSrc,
nullptr, FREERDP_KEEP_DST_ALPHA);
2399 if (!region16_union_rect(invalidRegion, invalidRegion, rect))
2401 region16_uninit(&updateRegion);
2407 region16_uninit(&updateRegion);
2410 tile->dirty = FALSE;
2414 region16_uninit(&clippingRects);
2418INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2419 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
2420 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2421 UINT32 nXDst, UINT32 nYDst,
REGION16* WINPR_RESTRICT invalidRegion,
2422 UINT16 surfaceId, UINT32 frameId)
2426 WINPR_ASSERT(progressive);
2431 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion no surface for %" PRIu16,
2436 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2437 WINPR_ASSERT(region);
2439 if (surface->frameId != frameId)
2441 surface->frameId = frameId;
2442 surface->numUpdatedTiles = 0;
2445 wStream ss = WINPR_C_ARRAY_INIT;
2446 wStream* s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
2451 case PIXEL_FORMAT_RGBA32:
2452 case PIXEL_FORMAT_RGBX32:
2453 case PIXEL_FORMAT_BGRA32:
2454 case PIXEL_FORMAT_BGRX32:
2455 progressive->format = DstFormat;
2458 progressive->format = PIXEL_FORMAT_XRGB32;
2462 const size_t start = Stream_GetPosition(s);
2463 progressive->state = 0;
2464 while (Stream_GetRemainingLength(s) > 0)
2466 if (progressive_parse_block(progressive, s, surface, region) < 0)
2471 const size_t end = Stream_GetPosition(s);
2472 if ((end - start) != SrcSize)
2474 WLog_Print(progressive->log, WLOG_ERROR,
2475 "total block len %" PRIuz
" does not match read data %" PRIu32, end - start,
2482 if (!update_tiles(progressive, surface, pDstData, DstFormat, nDstStep, nXDst, nYDst, region,
2489BOOL progressive_rfx_write_message_progressive_simple(
2490 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s,
2491 const RFX_MESSAGE* WINPR_RESTRICT msg)
2493 RFX_CONTEXT* context =
nullptr;
2495 WINPR_ASSERT(progressive);
2498 context = progressive->rfx_context;
2499 return rfx_write_message_progressive_simple(context, s, msg);
2502int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2503 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 SrcFormat,
2504 UINT32 Width, UINT32 Height, UINT32 ScanLine,
2505 const REGION16* WINPR_RESTRICT invalidRegion,
2506 BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize)
2511 UINT32 numRects = 0;
2513 RFX_MESSAGE* message =
nullptr;
2515 if (!progressive || !pSrcData || !ppDstData || !pDstSize)
2524 case PIXEL_FORMAT_ABGR32:
2525 case PIXEL_FORMAT_ARGB32:
2526 case PIXEL_FORMAT_XBGR32:
2527 case PIXEL_FORMAT_XRGB32:
2528 case PIXEL_FORMAT_BGRA32:
2529 case PIXEL_FORMAT_BGRX32:
2530 case PIXEL_FORMAT_RGBA32:
2531 case PIXEL_FORMAT_RGBX32:
2532 ScanLine = Width * 4;
2539 if (SrcSize < Height * ScanLine)
2544 numRects = (Width + 63) / 64;
2545 numRects *= (Height + 63) / 64;
2549 const int nr = region16_n_rects(invalidRegion);
2550 numRects = WINPR_ASSERTING_INT_CAST(uint32_t, nr);
2556 if (!Stream_EnsureRemainingCapacity(progressive->rects, numRects *
sizeof(
RFX_RECT)))
2558 rects = Stream_BufferAs(progressive->rects,
RFX_RECT);
2561 const RECTANGLE_16* region_rects = region16_rects(invalidRegion,
nullptr);
2562 for (UINT32 idx = 0; idx < numRects; idx++)
2569 rect->width = r->right - r->left;
2570 rect->height = r->bottom - r->top;
2578 for (UINT32 i = 0; i < numRects; i++)
2584 WINPR_ASSERT(Width >= x);
2585 WINPR_ASSERT(Height >= y);
2586 r->width = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Width - x));
2587 r->height = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Height - y));
2589 if (x + 64UL >= Width)
2597 WINPR_ASSERT(r->x % 64 == 0);
2598 WINPR_ASSERT(r->y % 64 == 0);
2599 WINPR_ASSERT(r->width <= 64);
2600 WINPR_ASSERT(r->height <= 64);
2603 s = progressive->buffer;
2604 Stream_ResetPosition(s);
2606 progressive->rfx_context->mode = RLGR1;
2608 progressive->rfx_context->width = WINPR_ASSERTING_INT_CAST(UINT16, Width);
2609 progressive->rfx_context->height = WINPR_ASSERTING_INT_CAST(UINT16, Height);
2610 rfx_context_set_pixel_format(progressive->rfx_context, SrcFormat);
2611 message = rfx_encode_message(progressive->rfx_context, rects, numRects, pSrcData, Width, Height,
2615 WLog_ERR(TAG,
"failed to encode rfx message");
2619 rc = progressive_rfx_write_message_progressive_simple(progressive, s, message);
2620 rfx_message_free(progressive->rfx_context, message);
2625 const size_t pos = Stream_GetPosition(s);
2626 WINPR_ASSERT(pos <= UINT32_MAX);
2627 *pDstSize = (UINT32)pos;
2629 *ppDstData = Stream_Buffer(s);
2635BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive)
2637 return (progressive !=
nullptr);
2640PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
2642 return progressive_context_new_ex(Compressor, 0);
2645PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, UINT32 ThreadingFlags)
2647 PROGRESSIVE_CONTEXT* progressive =
2648 (PROGRESSIVE_CONTEXT*)winpr_aligned_calloc(1,
sizeof(PROGRESSIVE_CONTEXT), 32);
2653 progressive->Compressor = Compressor;
2654 progressive->quantProgValFull.quality = 100;
2655 progressive->log = WLog_Get(TAG);
2656 if (!progressive->log)
2658 progressive->rfx_context = rfx_context_new_ex(Compressor, ThreadingFlags);
2659 if (!progressive->rfx_context)
2661 progressive->buffer = Stream_New(
nullptr, 1024);
2662 if (!progressive->buffer)
2664 progressive->rects = Stream_New(
nullptr, 1024);
2665 if (!progressive->rects)
2667 progressive->bufferPool = BufferPool_New(TRUE, (8192LL + 32LL) * 3LL, 16);
2668 if (!progressive->bufferPool)
2670 progressive->SurfaceContexts = HashTable_New(TRUE);
2671 if (!progressive->SurfaceContexts)
2675 wObject* obj = HashTable_ValueObject(progressive->SurfaceContexts);
2681 WINPR_PRAGMA_DIAG_PUSH
2682 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2683 progressive_context_free(progressive);
2684 WINPR_PRAGMA_DIAG_POP
2688void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
2693 Stream_Free(progressive->buffer, TRUE);
2694 Stream_Free(progressive->rects, TRUE);
2695 rfx_context_free(progressive->rfx_context);
2697 BufferPool_Free(progressive->bufferPool);
2698 HashTable_Free(progressive->SurfaceContexts);
2700 winpr_aligned_free(progressive);
WINPR_ATTR_NODISCARD fn_lShiftC_16s_inplace_t lShiftC_16s_inplace
WINPR_ATTR_NODISCARD fn_add_16s_inplace_t add_16s_inplace
Do vecotor addition, store result in both input buffers pSrcDst1 = pSrcDst2 = pSrcDst1 + pSrcDst2.
This struct contains function pointer to initialize/free objects.
OBJECT_FREE_FN fnObjectFree