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;
115 dst->HL1 = q1->HL1 - q2->HL1;
116 dst->LH1 = q1->LH1 - q2->LH1;
117 dst->HH1 = q1->HH1 - q2->HH1;
118 dst->HL2 = q1->HL2 - q2->HL2;
119 dst->LH2 = q1->LH2 - q2->LH2;
120 dst->HH2 = q1->HH2 - q2->HH2;
121 dst->HL3 = q1->HL3 - q2->HL3;
122 dst->LH3 = q1->LH3 - q2->LH3;
123 dst->HH3 = q1->HH3 - q2->HH3;
124 dst->LL3 = q1->LL3 - q2->LL3;
203 if (q1->HL1 != q2->HL1)
206 if (q1->LH1 != q2->LH1)
209 if (q1->HH1 != q2->HH1)
212 if (q1->HL2 != q2->HL2)
215 if (q1->LH2 != q2->LH2)
218 if (q1->HH2 != q2->HH2)
221 if (q1->HL3 != q2->HL3)
224 if (q1->LH3 != q2->LH3)
227 if (q1->HH3 != q2->HH3)
230 if (q1->LL3 != q2->LL3)
236static inline BOOL progressive_set_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
241 key = ((ULONG_PTR)surfaceId) + 1;
244 return HashTable_Insert(progressive->SurfaceContexts, (
void*)key, pData);
246 HashTable_Remove(progressive->SurfaceContexts, (
void*)key);
251progressive_get_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, UINT16 surfaceId)
253 void* key = (
void*)(((ULONG_PTR)surfaceId) + 1);
258 return HashTable_GetItemValue(progressive->SurfaceContexts, key);
265 winpr_aligned_free(tile->sign);
266 winpr_aligned_free(tile->current);
267 winpr_aligned_free(tile->data);
268 winpr_aligned_free(tile);
272static void progressive_surface_context_free(
void* ptr)
281 for (
size_t index = 0; index < surface->tilesSize; index++)
284 progressive_tile_free(tile);
288 winpr_aligned_free((
void*)surface->tiles);
289 winpr_aligned_free(surface->updatedTileIndices);
290 winpr_aligned_free(surface);
301 tile->stride = 4 * tile->width;
303 size_t dataLen = 1ull * tile->stride * tile->height;
304 tile->data = (BYTE*)winpr_aligned_malloc(dataLen, 16);
307 memset(tile->data, 0xFF, dataLen);
309 size_t signLen = (8192ULL + 32ULL) * 3ULL;
310 tile->sign = (BYTE*)winpr_aligned_malloc(signLen, 16);
314 size_t currentLen = (8192ULL + 32ULL) * 3ULL;
315 tile->current = (BYTE*)winpr_aligned_malloc(currentLen, 16);
322 progressive_tile_free(tile);
331 WINPR_ASSERT(surface);
332 WINPR_ASSERT(surface->gridSize > 0);
336 oldIndex = surface->gridSize;
337 while (surface->gridSize < min)
338 surface->gridSize += 1024;
341 void* tmp = winpr_aligned_recalloc((
void*)surface->tiles, surface->gridSize,
345 surface->tilesSize = surface->gridSize;
348 for (
size_t x = oldIndex; x < surface->tilesSize; x++)
350 surface->tiles[x] = progressive_tile_new();
351 if (!surface->tiles[x])
356 winpr_aligned_recalloc(surface->updatedTileIndices, surface->gridSize,
sizeof(UINT32), 32);
360 surface->updatedTileIndices = tmp;
374 surface->id = surfaceId;
375 surface->width = width;
376 surface->height = height;
377 surface->gridWidth = (width + (64 - width % 64)) / 64;
378 surface->gridHeight = (height + (64 - height % 64)) / 64;
379 surface->gridSize = surface->gridWidth * surface->gridHeight;
381 if (!progressive_allocate_tile_cache(surface, surface->gridSize))
383 progressive_surface_context_free(surface);
392 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
398 if (!surface || !tile)
401 zIdx = (tile->yIdx * surface->gridWidth) + tile->xIdx;
403 if (zIdx >= surface->tilesSize)
405 WLog_ERR(TAG,
"Invalid zIndex %" PRIuz, zIdx);
409 t = surface->tiles[zIdx];
411 t->blockType = tile->blockType;
412 t->blockLen = tile->blockLen;
413 t->quantIdxY = tile->quantIdxY;
414 t->quantIdxCb = tile->quantIdxCb;
415 t->quantIdxCr = tile->quantIdxCr;
416 t->xIdx = tile->xIdx;
417 t->yIdx = tile->yIdx;
418 t->flags = tile->flags;
419 t->quality = tile->quality;
420 t->x = tile->xIdx * t->width;
421 t->y = tile->yIdx * t->height;
425 t->ySrlLen = tile->ySrlLen;
426 t->yRawLen = tile->yRawLen;
427 t->cbSrlLen = tile->cbSrlLen;
428 t->cbRawLen = tile->cbRawLen;
429 t->crSrlLen = tile->crSrlLen;
430 t->crRawLen = tile->crRawLen;
431 t->ySrlData = tile->ySrlData;
432 t->yRawData = tile->yRawData;
433 t->cbSrlData = tile->cbSrlData;
434 t->cbRawData = tile->cbRawData;
435 t->crSrlData = tile->crSrlData;
436 t->crRawData = tile->crRawData;
440 t->yLen = tile->yLen;
441 t->cbLen = tile->cbLen;
442 t->crLen = tile->crLen;
443 t->tailLen = tile->tailLen;
444 t->yData = tile->yData;
445 t->cbData = tile->cbData;
446 t->crData = tile->crData;
447 t->tailData = tile->tailData;
450 if (region->usedTiles >= region->numTiles)
452 WLog_ERR(TAG,
"Invalid tile count, only expected %" PRIu16
", got %" PRIu16,
453 region->numTiles, region->usedTiles);
457 region->tiles[region->usedTiles++] = t;
460 if (surface->numUpdatedTiles >= surface->gridSize)
462 if (!progressive_allocate_tile_cache(surface, surface->numUpdatedTiles + 1))
466 surface->updatedTileIndices[surface->numUpdatedTiles++] = (UINT32)zIdx;
473INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
474 UINT16 surfaceId, UINT32 width, UINT32 height)
480 surface = progressive_surface_context_new(surfaceId, width, height);
485 if (!progressive_set_surface_data(progressive, surfaceId, (
void*)surface))
487 progressive_surface_context_free(surface);
495int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
498 progressive_set_surface_data(progressive, surfaceId, NULL);
521static int16_t clampi16(
int val)
530static inline void progressive_rfx_idwt_x(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
531 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
532 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
533 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
538 for (
size_t i = 0; i < nDstCount; i++)
540 const INT16* pL = pLowBand;
541 const INT16* pH = pHighBand;
542 INT16* pX = pDstBand;
545 INT16 X0 = clampi16((int32_t)L0 - H0);
546 INT16 X2 = clampi16((int32_t)L0 - H0);
548 for (
size_t j = 0; j < (nHighCount - 1); j++)
554 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
555 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
563 if (nLowCount <= (nHighCount + 1))
565 if (nLowCount <= nHighCount)
568 pX[1] = clampi16((int32_t)X2 + (2 * H0));
574 X0 = clampi16((int32_t)L0 - H0);
576 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
584 X0 = clampi16((int32_t)L0 - (H0 / 2));
586 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
590 pX[3] = clampi16((int32_t)(X0 + L0) / 2);
593 pLowBand += nLowStep;
594 pHighBand += nHighStep;
595 pDstBand += nDstStep;
599static inline void progressive_rfx_idwt_y(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
600 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
601 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
602 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
604 for (
size_t i = 0; i < nDstCount; i++)
608 const INT16* pL = pLowBand;
609 const INT16* pH = pHighBand;
610 INT16* pX = pDstBand;
615 int16_t X0 = clampi16((int32_t)L0 - H0);
616 int16_t 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));
634 if (nLowCount <= (nHighCount + 1))
636 if (nLowCount <= nHighCount)
640 *pX = clampi16((int32_t)X2 + (2 * H0));
645 X0 = clampi16((int32_t)L0 - H0);
648 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
657 X0 = clampi16((int32_t)L0 - (H0 / 2));
660 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
665 *pX = clampi16((int32_t)(X0 + L0) / 2);
674static inline size_t progressive_rfx_get_band_l_count(
size_t level)
676 return (64 >> level) + 1;
679static inline size_t progressive_rfx_get_band_h_count(
size_t level)
682 return (64 >> 1) - 1;
684 return (64 + (1 << (level - 1))) >> level;
687static inline void progressive_rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer,
688 INT16* WINPR_RESTRICT temp,
size_t level)
690 size_t nDstStepX = 0;
691 size_t nDstStepY = 0;
692 const INT16* WINPR_RESTRICT HL = NULL;
693 const INT16* WINPR_RESTRICT LH = NULL;
694 const INT16* WINPR_RESTRICT HH = NULL;
695 INT16* WINPR_RESTRICT LL = NULL;
696 INT16* WINPR_RESTRICT L = NULL;
697 INT16* WINPR_RESTRICT H = NULL;
698 INT16* WINPR_RESTRICT LLx = NULL;
700 const size_t nBandL = progressive_rfx_get_band_l_count(level);
701 const size_t nBandH = progressive_rfx_get_band_h_count(level);
704 HL = &buffer[offset];
705 offset += (nBandH * nBandL);
706 LH = &buffer[offset];
707 offset += (nBandL * nBandH);
708 HH = &buffer[offset];
709 offset += (nBandH * nBandH);
710 LL = &buffer[offset];
711 nDstStepX = (nBandL + nBandH);
712 nDstStepY = (nBandL + nBandH);
715 offset += (nBandL * nDstStepX);
720 progressive_rfx_idwt_x(LL, nBandL, HL, nBandH, L, nDstStepX, nBandL, nBandH, nBandL);
723 progressive_rfx_idwt_x(LH, nBandL, HH, nBandH, H, nDstStepX, nBandL, nBandH, nBandH);
726 progressive_rfx_idwt_y(L, nDstStepX, H, nDstStepX, LLx, nDstStepY, nBandL, nBandH,
730void rfx_dwt_2d_extrapolate_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT temp)
732 WINPR_ASSERT(buffer);
734 progressive_rfx_dwt_2d_decode_block(&buffer[3807], temp, 3);
735 progressive_rfx_dwt_2d_decode_block(&buffer[3007], temp, 2);
736 progressive_rfx_dwt_2d_decode_block(&buffer[0], temp, 1);
739static inline int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
740 INT16* WINPR_RESTRICT buffer,
741 INT16* WINPR_RESTRICT current, BOOL coeffDiff,
742 BOOL extrapolate, BOOL reverse)
746 if (!progressive || !buffer || !current)
749 const uint32_t belements = 4096;
750 const uint32_t bsize = belements *
sizeof(INT16);
752 memcpy(buffer, current, bsize);
754 memcpy(current, buffer, bsize);
758 INT16* temp = (INT16*)BufferPool_Take(progressive->bufferPool, -1);
765 progressive->rfx_context->dwt_2d_decode(buffer, temp);
769 WINPR_ASSERT(progressive->rfx_context->dwt_2d_extrapolate_decode);
770 progressive->rfx_context->dwt_2d_extrapolate_decode(buffer, temp);
772 BufferPool_Return(progressive->bufferPool, temp);
776static inline void progressive_rfx_decode_block(
const primitives_t* prims,
777 INT16* WINPR_RESTRICT buffer, UINT32 length,
787progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
789 const BYTE* WINPR_RESTRICT data, UINT32 length,
790 INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
791 INT16* WINPR_RESTRICT sign, BOOL coeffDiff,
792 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
797 status = progressive->rfx_context->rlgr_decode(RLGR1, data, length, buffer, 4096);
802 CopyMemory(sign, buffer, 4096ULL * 2ULL);
805 rfx_differential_decode(buffer + 4032, 64);
806 progressive_rfx_decode_block(prims, &buffer[0], 1024, shift->HL1);
807 progressive_rfx_decode_block(prims, &buffer[1024], 1024, shift->LH1);
808 progressive_rfx_decode_block(prims, &buffer[2048], 1024, shift->HH1);
809 progressive_rfx_decode_block(prims, &buffer[3072], 256, shift->HL2);
810 progressive_rfx_decode_block(prims, &buffer[3328], 256, shift->LH2);
811 progressive_rfx_decode_block(prims, &buffer[3584], 256, shift->HH2);
812 progressive_rfx_decode_block(prims, &buffer[3840], 64, shift->HL3);
813 progressive_rfx_decode_block(prims, &buffer[3904], 64, shift->LH3);
814 progressive_rfx_decode_block(prims, &buffer[3968], 64, shift->HH3);
815 progressive_rfx_decode_block(prims, &buffer[4032], 64, shift->LL3);
819 progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1);
820 progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1);
821 progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1);
822 progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2);
823 progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2);
824 progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2);
825 progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3);
826 progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3);
827 progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3);
828 rfx_differential_decode(&buffer[4015], 81);
829 progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3);
831 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
836progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
838 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
844 BOOL extrapolate = 0;
845 BYTE* pBuffer = NULL;
863 diff = tile->flags & RFX_TILE_DIFFERENCE;
864 sub = context->flags & RFX_SUBBAND_DIFFING;
865 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
867#if defined(WITH_DEBUG_CODECS)
868 WLog_Print(progressive->log, WLOG_DEBUG,
869 "ProgressiveTile%s: quantIdx Y: %" PRIu8
" Cb: %" PRIu8
" Cr: %" PRIu8
870 " xIdx: %" PRIu16
" yIdx: %" PRIu16
" flags: 0x%02" PRIX8
" quality: %" PRIu8
871 " yLen: %" PRIu16
" cbLen: %" PRIu16
" crLen: %" PRIu16
" tailLen: %" PRIu16
"",
872 (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ?
"First" :
"Simple",
873 tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx,
874 tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
877 if (tile->quantIdxY >= region->numQuant)
879 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
883 quantY = &(region->quantVals[tile->quantIdxY]);
885 if (tile->quantIdxCb >= region->numQuant)
887 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
892 quantCb = &(region->quantVals[tile->quantIdxCb]);
894 if (tile->quantIdxCr >= region->numQuant)
896 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
901 quantCr = &(region->quantVals[tile->quantIdxCr]);
903 if (tile->quality == 0xFF)
905 quantProgVal = &(progressive->quantProgValFull);
909 if (tile->quality >= region->numProgQuant)
911 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
912 region->numProgQuant);
916 quantProgVal = &(region->quantProgVals[tile->quality]);
919 quantProgY = &(quantProgVal->yQuantValues);
920 quantProgCb = &(quantProgVal->cbQuantValues);
921 quantProgCr = &(quantProgVal->crQuantValues);
923 tile->yQuant = *quantY;
924 tile->cbQuant = *quantCb;
925 tile->crQuant = *quantCr;
926 tile->yProgQuant = *quantProgY;
927 tile->cbProgQuant = *quantProgCb;
928 tile->crProgQuant = *quantProgCr;
930 progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
931 progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
932 progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
933 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
934 progressive_rfx_quant_lsub(&shiftY, 1);
935 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
936 progressive_rfx_quant_lsub(&shiftCb, 1);
937 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
938 progressive_rfx_quant_lsub(&shiftCr, 1);
940 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
941 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
942 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
944 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
945 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
946 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
948 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
949 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
950 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
951 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
953 rc = progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0],
954 pCurrent[0], pSign[0], diff, sub, extrapolate);
957 rc = progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen,
958 pSrcDst[1], pCurrent[1], pSign[1], diff, sub,
962 rc = progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen,
963 pSrcDst[2], pCurrent[2], pSign[2], diff, sub,
968 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
969 rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride, progressive->format,
972 BufferPool_Return(progressive->bufferPool, pBuffer);
976static inline INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
990 const UINT32 k = state->kp / 8;
995 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
996 BitStream_Shift(bs, 1);
1001 state->nz = (1 << k);
1018 bs->mask = ((1 << k) - 1);
1020 WINPR_ASSERTING_INT_CAST(int16_t, ((bs->accumulator >> (32u - k)) & bs->mask));
1021 BitStream_Shift(bs, k);
1035 const UINT32 sign = (bs->accumulator & 0x80000000) ? 1 : 0;
1036 BitStream_Shift(bs, 1);
1044 return sign ? -1 : 1;
1047 const UINT32 max = (1 << numBits) - 1;
1051 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1052 BitStream_Shift(bs, 1);
1060 if (mag > INT16_MAX)
1062 return (INT16)(sign ? -1 * (int)mag : (INT16)mag);
1066progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state)
1077 pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
1080 BitStream_Shift(raw, pad);
1082 pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
1085 BitStream_Shift(srl, pad);
1087 if (BitStream_GetRemainingLength(srl) == 8)
1088 BitStream_Shift(srl, 8);
1093static inline int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1094 INT16* WINPR_RESTRICT buffer,
1095 INT16* WINPR_RESTRICT sign, UINT32 length,
1096 UINT32 shift, WINPR_ATTR_UNUSED UINT32 bitPos,
1107 for (UINT32 index = 0; index < length; index++)
1109 raw->mask = ((1 << numBits) - 1);
1110 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1111 BitStream_Shift(raw, numBits);
1113 const int32_t shifted = input << shift;
1114 const int32_t val = buffer[index] + shifted;
1115 const int16_t ival = WINPR_ASSERTING_INT_CAST(int16_t, val);
1116 buffer[index] = ival;
1122 for (UINT32 index = 0; index < length; index++)
1124 if (sign[index] > 0)
1127 raw->mask = ((1 << numBits) - 1);
1128 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1129 BitStream_Shift(raw, numBits);
1131 else if (sign[index] < 0)
1134 raw->mask = ((1 << numBits) - 1);
1135 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1136 BitStream_Shift(raw, numBits);
1142 input = progressive_rfx_srl_read(state, numBits);
1143 sign[index] = WINPR_ASSERTING_INT_CAST(int16_t, input);
1146 const int32_t val = input << shift;
1147 const int32_t ival = buffer[index] + val;
1148 buffer[index] = WINPR_ASSERTING_INT_CAST(INT16, ival);
1154static inline int progressive_rfx_upgrade_component(
1155 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1159 INT16* WINPR_RESTRICT current, INT16* WINPR_RESTRICT sign,
const BYTE* WINPR_RESTRICT srlData,
1160 UINT32 srlLen,
const BYTE* WINPR_RESTRICT rawData, UINT32 rawLen, BOOL coeffDiff,
1161 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
1168 RFX_PROGRESSIVE_UPGRADE_STATE state = { 0 };
1174 BitStream_Attach(state.srl, srlData, srlLen);
1175 BitStream_Fetch(state.srl);
1176 BitStream_Attach(state.raw, rawData, rawLen);
1177 BitStream_Fetch(state.raw);
1180 rc = progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1,
1184 rc = progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1,
1185 bitPos->LH1, numBits->LH1);
1188 rc = progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1,
1189 bitPos->HH1, numBits->HH1);
1192 rc = progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2,
1193 bitPos->HL2, numBits->HL2);
1196 rc = progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2,
1197 bitPos->LH2, numBits->LH2);
1200 rc = progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2,
1201 bitPos->HH2, numBits->HH2);
1204 rc = progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3,
1205 bitPos->HL3, numBits->HL3);
1208 rc = progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3,
1209 bitPos->LH3, numBits->LH3);
1212 rc = progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3,
1213 bitPos->HH3, numBits->HH3);
1217 state.nonLL = FALSE;
1218 rc = progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3,
1219 bitPos->LL3, numBits->LL3);
1222 rc = progressive_rfx_upgrade_state_finish(&state);
1225 aRawLen = (state.raw->position + 7) / 8;
1226 aSrlLen = (state.srl->position + 7) / 8;
1228 if ((aRawLen != rawLen) || (aSrlLen != srlLen))
1234 pRawLen = (int)((((
float)aRawLen) / ((
float)rawLen)) * 100.0f);
1237 pSrlLen = (int)((((
float)aSrlLen) / ((
float)srlLen)) * 100.0f);
1239 WLog_Print(progressive->log, WLOG_WARN,
1240 "RAW: %" PRIu32
"/%" PRIu32
" %d%% (%" PRIu32
"/%" PRIu32
":%" PRIu32
1241 ")\tSRL: %" PRIu32
"/%" PRIu32
" %d%% (%" PRIu32
"/%" PRIu32
":%" PRIu32
")",
1242 aRawLen, rawLen, pRawLen, state.raw->position, rawLen * 8,
1243 (rawLen * 8) - state.raw->position, aSrlLen, srlLen, pSrlLen,
1244 state.srl->position, srlLen * 8, (srlLen * 8) - state.srl->position);
1248 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
1253progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1255 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1261 BOOL extrapolate = 0;
1262 BYTE* pBuffer = NULL;
1263 INT16* pSign[3] = { 0 };
1264 INT16* pSrcDst[3] = { 0 };
1265 INT16* pCurrent[3] = { 0 };
1285 coeffDiff = tile->flags & RFX_TILE_DIFFERENCE;
1286 sub = context->flags & RFX_SUBBAND_DIFFING;
1287 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
1291#if defined(WITH_DEBUG_CODECS)
1292 WLog_Print(progressive->log, WLOG_DEBUG,
1293 "ProgressiveTileUpgrade: pass: %" PRIu16
" quantIdx Y: %" PRIu8
" Cb: %" PRIu8
1294 " Cr: %" PRIu8
" xIdx: %" PRIu16
" yIdx: %" PRIu16
" quality: %" PRIu8
1295 " ySrlLen: %" PRIu16
" yRawLen: %" PRIu16
" cbSrlLen: %" PRIu16
" cbRawLen: %" PRIu16
1296 " crSrlLen: %" PRIu16
" crRawLen: %" PRIu16
"",
1297 tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx,
1298 tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen,
1299 tile->cbRawLen, tile->crSrlLen, tile->crRawLen);
1302 if (tile->quantIdxY >= region->numQuant)
1304 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
1308 quantY = &(region->quantVals[tile->quantIdxY]);
1310 if (tile->quantIdxCb >= region->numQuant)
1312 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
1317 quantCb = &(region->quantVals[tile->quantIdxCb]);
1319 if (tile->quantIdxCr >= region->numQuant)
1321 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1326 quantCr = &(region->quantVals[tile->quantIdxCr]);
1328 if (tile->quality == 0xFF)
1330 quantProg = &(progressive->quantProgValFull);
1334 if (tile->quality >= region->numProgQuant)
1336 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1337 region->numProgQuant);
1341 quantProg = &(region->quantProgVals[tile->quality]);
1344 quantProgY = &(quantProg->yQuantValues);
1345 quantProgCb = &(quantProg->cbQuantValues);
1346 quantProgCr = &(quantProg->crQuantValues);
1348 if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
1349 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantY has changed!");
1351 if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
1352 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCb has changed!");
1354 if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
1355 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCr has changed!");
1357 if (!(context->flags & RFX_SUBBAND_DIFFING))
1358 WLog_WARN(TAG,
"PROGRESSIVE_BLOCK_CONTEXT::flags & RFX_SUBBAND_DIFFING not set");
1360 progressive_rfx_quant_add(quantY, quantProgY, &yBitPos);
1361 progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos);
1362 progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos);
1363 progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits);
1364 progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits);
1365 progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits);
1366 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1367 progressive_rfx_quant_lsub(&shiftY, 1);
1368 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1369 progressive_rfx_quant_lsub(&shiftCb, 1);
1370 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1371 progressive_rfx_quant_lsub(&shiftCr, 1);
1373 tile->yBitPos = yBitPos;
1374 tile->cbBitPos = cbBitPos;
1375 tile->crBitPos = crBitPos;
1376 tile->yQuant = *quantY;
1377 tile->cbQuant = *quantCb;
1378 tile->crQuant = *quantCr;
1379 tile->yProgQuant = *quantProgY;
1380 tile->cbProgQuant = *quantProgCb;
1381 tile->crProgQuant = *quantProgCr;
1383 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
1384 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
1385 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
1387 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
1388 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
1389 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
1391 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1392 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
1393 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
1394 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
1396 status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
1397 pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData,
1398 tile->ySrlLen, tile->yRawData, tile->yRawLen,
1399 coeffDiff, sub, extrapolate);
1404 status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
1405 pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData,
1406 tile->cbSrlLen, tile->cbRawData, tile->cbRawLen,
1407 coeffDiff, sub, extrapolate);
1412 status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
1413 pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData,
1414 tile->crSrlLen, tile->crRawData, tile->crRawLen,
1415 coeffDiff, sub, extrapolate);
1420 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1421 status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1422 progressive->format, &roi_64x64);
1424 BufferPool_Return(progressive->bufferPool, pBuffer);
1428static inline BOOL progressive_tile_read_upgrade(
1429 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1431 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1435 const size_t expect = 20;
1437 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1440 tile.blockType = blockType;
1441 tile.blockLen = blockLen;
1444 Stream_Read_UINT8(s, tile.quantIdxY);
1445 Stream_Read_UINT8(s, tile.quantIdxCb);
1446 Stream_Read_UINT8(s, tile.quantIdxCr);
1447 Stream_Read_UINT16(s, tile.xIdx);
1448 Stream_Read_UINT16(s, tile.yIdx);
1449 Stream_Read_UINT8(s, tile.quality);
1450 Stream_Read_UINT16(s, tile.ySrlLen);
1451 Stream_Read_UINT16(s, tile.yRawLen);
1452 Stream_Read_UINT16(s, tile.cbSrlLen);
1453 Stream_Read_UINT16(s, tile.cbRawLen);
1454 Stream_Read_UINT16(s, tile.crSrlLen);
1455 Stream_Read_UINT16(s, tile.crRawLen);
1457 tile.ySrlData = Stream_Pointer(s);
1458 if (!Stream_SafeSeek(s, tile.ySrlLen))
1460 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.ySrlLen);
1464 tile.yRawData = Stream_Pointer(s);
1465 if (!Stream_SafeSeek(s, tile.yRawLen))
1467 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yRawLen);
1471 tile.cbSrlData = Stream_Pointer(s);
1472 if (!Stream_SafeSeek(s, tile.cbSrlLen))
1474 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1479 tile.cbRawData = Stream_Pointer(s);
1480 if (!Stream_SafeSeek(s, tile.cbRawLen))
1482 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1487 tile.crSrlData = Stream_Pointer(s);
1488 if (!Stream_SafeSeek(s, tile.crSrlLen))
1490 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1495 tile.crRawData = Stream_Pointer(s);
1496 if (!Stream_SafeSeek(s, tile.crRawLen))
1498 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1503 return progressive_surface_tile_replace(surface, region, &tile, TRUE);
1507progressive_tile_read(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, BOOL simple,
1508 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
1510 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1514 size_t expect = simple ? 16 : 17;
1516 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1519 tile.blockType = blockType;
1520 tile.blockLen = blockLen;
1522 Stream_Read_UINT8(s, tile.quantIdxY);
1523 Stream_Read_UINT8(s, tile.quantIdxCb);
1524 Stream_Read_UINT8(s, tile.quantIdxCr);
1525 Stream_Read_UINT16(s, tile.xIdx);
1526 Stream_Read_UINT16(s, tile.yIdx);
1527 Stream_Read_UINT8(s, tile.flags);
1530 Stream_Read_UINT8(s, tile.quality);
1532 tile.quality = 0xFF;
1533 Stream_Read_UINT16(s, tile.yLen);
1534 Stream_Read_UINT16(s, tile.cbLen);
1535 Stream_Read_UINT16(s, tile.crLen);
1536 Stream_Read_UINT16(s, tile.tailLen);
1538 tile.yData = Stream_Pointer(s);
1539 if (!Stream_SafeSeek(s, tile.yLen))
1541 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yLen);
1545 tile.cbData = Stream_Pointer(s);
1546 if (!Stream_SafeSeek(s, tile.cbLen))
1548 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.cbLen);
1552 tile.crData = Stream_Pointer(s);
1553 if (!Stream_SafeSeek(s, tile.crLen))
1555 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.crLen);
1559 tile.tailData = Stream_Pointer(s);
1560 if (!Stream_SafeSeek(s, tile.tailLen))
1562 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.tailLen);
1566 return progressive_surface_tile_replace(surface, region, &tile, FALSE);
1569static void CALLBACK progressive_process_tiles_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1570 void* context, PTP_WORK work)
1574 WINPR_UNUSED(instance);
1577 switch (param->tile->blockType)
1579 case PROGRESSIVE_WBT_TILE_SIMPLE:
1580 case PROGRESSIVE_WBT_TILE_FIRST:
1581 progressive_decompress_tile_first(param->progressive, param->tile, param->region,
1585 case PROGRESSIVE_WBT_TILE_UPGRADE:
1586 progressive_decompress_tile_upgrade(param->progressive, param->tile, param->region,
1590 WLog_Print(param->progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16
" (%s)",
1591 param->tile->blockType,
1592 rfx_get_progressive_block_type_string(param->tile->blockType));
1597static inline SSIZE_T
1598progressive_process_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1600 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1606 const size_t start = Stream_GetPosition(s);
1607 UINT16 blockType = 0;
1608 UINT32 blockLen = 0;
1610 UINT16 close_cnt = 0;
1612 WINPR_ASSERT(progressive);
1613 WINPR_ASSERT(region);
1615 if (!Stream_CheckAndLogRequiredLength(TAG, s, region->tileDataSize))
1618 while ((Stream_GetRemainingLength(s) >= 6) &&
1619 (region->tileDataSize > (Stream_GetPosition(s) - start)))
1621 const size_t pos = Stream_GetPosition(s);
1623 Stream_Read_UINT16(s, blockType);
1624 Stream_Read_UINT32(s, blockLen);
1626#if defined(WITH_DEBUG_CODECS)
1627 WLog_Print(progressive->log, WLOG_DEBUG,
"%s",
1628 rfx_get_progressive_block_type_string(blockType));
1633 WLog_Print(progressive->log, WLOG_ERROR,
"Expected >= %" PRIu32
" remaining %" PRIu32,
1637 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
1642 case PROGRESSIVE_WBT_TILE_SIMPLE:
1643 if (!progressive_tile_read(progressive, TRUE, s, blockType, blockLen, surface,
1648 case PROGRESSIVE_WBT_TILE_FIRST:
1649 if (!progressive_tile_read(progressive, FALSE, s, blockType, blockLen, surface,
1654 case PROGRESSIVE_WBT_TILE_UPGRADE:
1655 if (!progressive_tile_read_upgrade(progressive, s, blockType, blockLen, surface,
1660 WLog_ERR(TAG,
"Invalid block type %04" PRIx16
" (%s)", blockType,
1661 rfx_get_progressive_block_type_string(blockType));
1665 size_t rem = Stream_GetPosition(s);
1666 if ((rem - pos) != blockLen)
1668 WLog_Print(progressive->log, WLOG_ERROR,
1669 "Actual block read %" PRIuz
" but expected %" PRIu32, rem - pos, blockLen);
1675 end = Stream_GetPosition(s);
1676 if ((end - start) != region->tileDataSize)
1678 WLog_Print(progressive->log, WLOG_ERROR,
1679 "Actual total blocks read %" PRIuz
" but expected %" PRIu32, end - start,
1680 region->tileDataSize);
1684 if (count != region->numTiles)
1686 WLog_Print(progressive->log, WLOG_WARN,
1687 "numTiles inconsistency: actual: %" PRIu32
", expected: %" PRIu16
"\n", count,
1692 for (UINT32 idx = 0; idx < region->numTiles; idx++)
1696 param->progressive = progressive;
1697 param->region = region;
1698 param->context = context;
1701 if (progressive->rfx_context->priv->UseThreads)
1703 progressive->work_objects[idx] = CreateThreadpoolWork(
1704 progressive_process_tiles_tile_work_callback, (
void*)param, NULL);
1705 if (!progressive->work_objects[idx])
1707 WLog_Print(progressive->log, WLOG_ERROR,
1708 "Failed to create ThreadpoolWork for tile %" PRIu32, idx);
1713 SubmitThreadpoolWork(progressive->work_objects[idx]);
1715 close_cnt = WINPR_ASSERTING_INT_CAST(UINT16, idx + 1);
1719 progressive_process_tiles_tile_work_callback(0, param, 0);
1724 WLog_Print(progressive->log, WLOG_ERROR,
"Failed to decompress %s at %" PRIu16,
1725 rfx_get_progressive_block_type_string(tile->blockType), idx);
1730 if (progressive->rfx_context->priv->UseThreads)
1732 for (UINT32 idx = 0; idx < close_cnt; idx++)
1734 WaitForThreadpoolWorkCallbacks(progressive->work_objects[idx], FALSE);
1735 CloseThreadpoolWork(progressive->work_objects[idx]);
1744 return (SSIZE_T)(end - start);
1747static inline SSIZE_T progressive_wb_sync(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1748 wStream* WINPR_RESTRICT s, UINT16 blockType,
1751 const UINT32 magic = 0xCACCACCA;
1752 const UINT16 version = 0x0100;
1755 sync.blockType = blockType;
1756 sync.blockLen = blockLen;
1758 if (sync.blockLen != 12)
1760 WLog_Print(progressive->log, WLOG_ERROR,
1761 "PROGRESSIVE_BLOCK_SYNC::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1762 sync.blockLen, 12u);
1766 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1769#if defined(WITH_DEBUG_CODECS)
1770 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveSync");
1773 Stream_Read_UINT32(s, sync.magic);
1774 Stream_Read_UINT16(s, sync.version);
1776 if (sync.magic != magic)
1778 WLog_Print(progressive->log, WLOG_ERROR,
1779 "PROGRESSIVE_BLOCK_SYNC::magic = 0x%08" PRIx32
" != 0x%08" PRIx32, sync.magic,
1784 if (sync.version != 0x0100)
1786 WLog_Print(progressive->log, WLOG_ERROR,
1787 "PROGRESSIVE_BLOCK_SYNC::version = 0x%04" PRIx16
" != 0x%04" PRIu16,
1788 sync.version, version);
1792 if ((progressive->state & FLAG_WBT_SYNC) != 0)
1793 WLog_WARN(TAG,
"Duplicate PROGRESSIVE_BLOCK_SYNC, ignoring");
1795 progressive->state |= FLAG_WBT_SYNC;
1799static inline SSIZE_T progressive_wb_frame_begin(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1800 wStream* WINPR_RESTRICT s, UINT16 blockType,
1805 frameBegin.blockType = blockType;
1806 frameBegin.blockLen = blockLen;
1808 if (frameBegin.blockLen != 12)
1810 WLog_Print(progressive->log, WLOG_ERROR,
1811 " RFX_PROGRESSIVE_FRAME_BEGIN::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1812 frameBegin.blockLen, 12u);
1816 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1819 Stream_Read_UINT32(s, frameBegin.frameIndex);
1820 Stream_Read_UINT16(s, frameBegin.regionCount);
1822#if defined(WITH_DEBUG_CODECS)
1823 WLog_Print(progressive->log, WLOG_DEBUG,
1824 "ProgressiveFrameBegin: frameIndex: %" PRIu32
" regionCount: %" PRIu16
"",
1825 frameBegin.frameIndex, frameBegin.regionCount);
1834 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1836 WLog_ERR(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_BEGIN in stream, this is not allowed!");
1840 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1842 WLog_ERR(TAG,
"RFX_PROGRESSIVE_FRAME_BEGIN after RFX_PROGRESSIVE_FRAME_END in stream, this "
1847 progressive->state |= FLAG_WBT_FRAME_BEGIN;
1851static inline SSIZE_T progressive_wb_frame_end(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1852 wStream* WINPR_RESTRICT s, UINT16 blockType,
1857 frameEnd.blockType = blockType;
1858 frameEnd.blockLen = blockLen;
1860 if (frameEnd.blockLen != 6)
1862 WLog_Print(progressive->log, WLOG_ERROR,
1863 " RFX_PROGRESSIVE_FRAME_END::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1864 frameEnd.blockLen, 6u);
1868 if (Stream_GetRemainingLength(s) != 0)
1870 WLog_Print(progressive->log, WLOG_ERROR,
1871 "ProgressiveFrameEnd short %" PRIuz
", expected %u",
1872 Stream_GetRemainingLength(s), 0U);
1876#if defined(WITH_DEBUG_CODECS)
1877 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveFrameEnd");
1880 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
1881 WLog_WARN(TAG,
"RFX_PROGRESSIVE_FRAME_END before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
1882 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1883 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_END, ignoring");
1885 progressive->state |= FLAG_WBT_FRAME_END;
1889static inline SSIZE_T progressive_wb_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1890 wStream* WINPR_RESTRICT s, UINT16 blockType,
1894 context->blockType = blockType;
1895 context->blockLen = blockLen;
1897 if (context->blockLen != 10)
1899 WLog_Print(progressive->log, WLOG_ERROR,
1900 "RFX_PROGRESSIVE_CONTEXT::blockLen = 0x%08" PRIx32
" != 0x%08x",
1901 context->blockLen, 10u);
1905 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1908 Stream_Read_UINT8(s, context->ctxId);
1909 Stream_Read_UINT16(s, context->tileSize);
1910 Stream_Read_UINT8(s, context->flags);
1912 if (context->ctxId != 0x00)
1913 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT::ctxId != 0x00: %" PRIu8, context->ctxId);
1915 if (context->tileSize != 64)
1917 WLog_ERR(TAG,
"RFX_PROGRESSIVE_CONTEXT::tileSize != 0x40: %" PRIu16, context->tileSize);
1921 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1922 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_BEGIN");
1923 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1924 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_END");
1925 if ((progressive->state & FLAG_WBT_CONTEXT) != 0)
1926 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_CONTEXT received, ignoring.");
1928#if defined(WITH_DEBUG_CODECS)
1929 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveContext: flags: 0x%02" PRIX8
"",
1933 progressive->state |= FLAG_WBT_CONTEXT;
1937static inline SSIZE_T
1938progressive_wb_read_region_header(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1939 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
1940 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
1942 region->usedTiles = 0;
1944 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
1947 region->blockType = blockType;
1948 region->blockLen = blockLen;
1949 Stream_Read_UINT8(s, region->tileSize);
1950 Stream_Read_UINT16(s, region->numRects);
1951 Stream_Read_UINT8(s, region->numQuant);
1952 Stream_Read_UINT8(s, region->numProgQuant);
1953 Stream_Read_UINT8(s, region->flags);
1954 Stream_Read_UINT16(s, region->numTiles);
1955 Stream_Read_UINT32(s, region->tileDataSize);
1957 if (region->tileSize != 64)
1959 WLog_Print(progressive->log, WLOG_ERROR,
1960 "ProgressiveRegion tile size %" PRIu8
", expected %u", region->tileSize, 64U);
1964 if (region->numRects < 1)
1966 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion missing rect count %" PRIu16,
1971 if (region->numQuant > 7)
1973 WLog_Print(progressive->log, WLOG_ERROR,
1974 "ProgressiveRegion quant count too high %" PRIu8
", expected < %u",
1975 region->numQuant, 7U);
1979 const SSIZE_T rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, Stream_GetRemainingLength(s));
1980 const SSIZE_T expect = region->numRects * 8ll + region->numQuant * 5ll +
1981 region->numProgQuant * 16ll + region->tileDataSize;
1985 if (len / 8LL < region->numRects)
1987 WLog_Print(progressive->log, WLOG_ERROR,
1988 "ProgressiveRegion data short for region->rects");
1991 len -= region->numRects * 8LL;
1993 if (len / 5LL < region->numQuant)
1995 WLog_Print(progressive->log, WLOG_ERROR,
1996 "ProgressiveRegion data short for region->cQuant");
1999 len -= region->numQuant * 5LL;
2001 if (len / 16LL < region->numProgQuant)
2003 WLog_Print(progressive->log, WLOG_ERROR,
2004 "ProgressiveRegion data short for region->cProgQuant");
2007 len -= region->numProgQuant * 16LL;
2009 if (len < region->tileDataSize * 1ll)
2011 WLog_Print(progressive->log, WLOG_ERROR,
2012 "ProgressiveRegion data short for region->tiles");
2015 len -= region->tileDataSize;
2018 WLog_Print(progressive->log, WLOG_WARN,
2019 "Unused bytes detected, %" PRIdz
" bytes not processed", len);
2025static inline SSIZE_T progressive_wb_skip_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2026 wStream* WINPR_RESTRICT s, UINT16 blockType,
2029 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2032 progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2036 if (!Stream_SafeSeek(s, WINPR_ASSERTING_INT_CAST(
size_t, rc)))
2042static inline SSIZE_T progressive_wb_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2043 wStream* WINPR_RESTRICT s, UINT16 blockType,
2046 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2051 UINT16 boxRight = 0;
2052 UINT16 boxBottom = 0;
2055 UINT16 idxRight = 0;
2056 UINT16 idxBottom = 0;
2059 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
2061 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
2062 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2064 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2066 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION after RFX_PROGRESSIVE_FRAME_END, ignoring");
2067 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2070 progressive->state |= FLAG_WBT_REGION;
2072 rc = progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2076 for (UINT16 index = 0; index < region->numRects; index++)
2078 RFX_RECT* rect = &(region->rects[index]);
2079 Stream_Read_UINT16(s, rect->x);
2080 Stream_Read_UINT16(s, rect->y);
2081 Stream_Read_UINT16(s, rect->width);
2082 Stream_Read_UINT16(s, rect->height);
2085 for (BYTE index = 0; index < region->numQuant; index++)
2088 progressive_component_codec_quant_read(s, quantVal);
2090 if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
2092 WLog_Print(progressive->log, WLOG_ERROR,
2093 "ProgressiveRegion region->cQuant[%" PRIu32
"] < 6", index);
2097 if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
2099 WLog_Print(progressive->log, WLOG_ERROR,
2100 "ProgressiveRegion region->cQuant[%" PRIu32
"] > 15", index);
2105 for (BYTE index = 0; index < region->numProgQuant; index++)
2109 Stream_Read_UINT8(s, quantProgVal->quality);
2111 progressive_component_codec_quant_read(s, &(quantProgVal->yQuantValues));
2112 progressive_component_codec_quant_read(s, &(quantProgVal->cbQuantValues));
2113 progressive_component_codec_quant_read(s, &(quantProgVal->crQuantValues));
2116#if defined(WITH_DEBUG_CODECS)
2117 WLog_Print(progressive->log, WLOG_DEBUG,
2118 "ProgressiveRegion: numRects: %" PRIu16
" numTiles: %" PRIu16
2119 " tileDataSize: %" PRIu32
" flags: 0x%02" PRIX8
" numQuant: %" PRIu8
2120 " numProgQuant: %" PRIu8
"",
2121 region->numRects, region->numTiles, region->tileDataSize, region->flags,
2122 region->numQuant, region->numProgQuant);
2125 boxLeft = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridWidth);
2126 boxTop = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridHeight);
2130 for (UINT16 index = 0; index < region->numRects; index++)
2132 RFX_RECT* rect = &(region->rects[index]);
2133 idxLeft = rect->x / 64;
2134 idxTop = rect->y / 64;
2135 idxRight = (rect->x + rect->width + 63) / 64;
2136 idxBottom = (rect->y + rect->height + 63) / 64;
2138 if (idxLeft < boxLeft)
2141 if (idxTop < boxTop)
2144 if (idxRight > boxRight)
2145 boxRight = idxRight;
2147 if (idxBottom > boxBottom)
2148 boxBottom = idxBottom;
2150#if defined(WITH_DEBUG_CODECS)
2151 WLog_Print(progressive->log, WLOG_DEBUG,
2152 "rect[%" PRIu16
"]: x: %" PRIu16
" y: %" PRIu16
" w: %" PRIu16
" h: %" PRIu16
"",
2153 index, rect->x, rect->y, rect->width, rect->height);
2157 const SSIZE_T res = progressive_process_tiles(progressive, s, region, surface, context);
2163static inline SSIZE_T progressive_parse_block(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2166 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2168 UINT16 blockType = 0;
2169 UINT32 blockLen = 0;
2173 WINPR_ASSERT(progressive);
2175 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
2178 Stream_Read_UINT16(s, blockType);
2179 Stream_Read_UINT32(s, blockLen);
2183 WLog_WARN(TAG,
"Invalid blockLen %" PRIu32
", expected >= 6", blockLen);
2186 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
2188 Stream_StaticConstInit(&sub, Stream_Pointer(s), blockLen - 6);
2189 Stream_Seek(s, blockLen - 6);
2193 case PROGRESSIVE_WBT_SYNC:
2194 rc = progressive_wb_sync(progressive, &sub, blockType, blockLen);
2197 case PROGRESSIVE_WBT_FRAME_BEGIN:
2198 rc = progressive_wb_frame_begin(progressive, &sub, blockType, blockLen);
2201 case PROGRESSIVE_WBT_FRAME_END:
2202 rc = progressive_wb_frame_end(progressive, &sub, blockType, blockLen);
2205 case PROGRESSIVE_WBT_CONTEXT:
2206 rc = progressive_wb_context(progressive, &sub, blockType, blockLen);
2209 case PROGRESSIVE_WBT_REGION:
2210 rc = progressive_wb_region(progressive, &sub, blockType, blockLen, surface, region);
2214 WLog_Print(progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16, blockType);
2221 if (Stream_GetRemainingLength(&sub) > 0)
2223 WLog_Print(progressive->log, WLOG_ERROR,
2224 "block len %" PRIu32
" does not match read data %" PRIuz, blockLen,
2225 blockLen - Stream_GetRemainingLength(&sub));
2232static inline BOOL update_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2234 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2235 UINT32 nXDst, UINT32 nYDst,
2236 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
2237 REGION16* WINPR_RESTRICT invalidRegion)
2241 region16_init(&clippingRects);
2243 for (UINT32 i = 0; i < region->numRects; i++)
2246 const RFX_RECT* rect = &(region->rects[i]);
2248 clippingRect.left = (UINT16)nXDst + rect->x;
2249 clippingRect.top = (UINT16)nYDst + rect->y;
2250 clippingRect.right = clippingRect.left + rect->width;
2251 clippingRect.bottom = clippingRect.top + rect->height;
2252 region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
2255 for (UINT32 i = 0; i < surface->numUpdatedTiles; i++)
2257 UINT32 nbUpdateRects = 0;
2261 WINPR_ASSERT(surface->updatedTileIndices);
2262 const UINT32 index = surface->updatedTileIndices[i];
2264 WINPR_ASSERT(index < surface->tilesSize);
2268 const UINT32 dl = nXDst + tile->x;
2269 updateRect.left = WINPR_ASSERTING_INT_CAST(UINT16, dl);
2271 const UINT32 dt = nYDst + tile->y;
2272 updateRect.top = WINPR_ASSERTING_INT_CAST(UINT16, dt);
2273 updateRect.right = updateRect.left + 64;
2274 updateRect.bottom = updateRect.top + 64;
2277 region16_init(&updateRegion);
2278 region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
2279 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
2281 for (UINT32 j = 0; j < nbUpdateRects; j++)
2285 if (rect->left < updateRect.left)
2287 const UINT32 nXSrc = rect->left - updateRect.left;
2288 const UINT32 nYSrc = rect->top - updateRect.top;
2289 const UINT32 width = rect->right - rect->left;
2290 const UINT32 height = rect->bottom - rect->top;
2292 if (rect->left + width > surface->width)
2294 if (rect->top + height > surface->height)
2296 rc = freerdp_image_copy_no_overlap(
2297 pDstData, DstFormat, nDstStep, rect->left, rect->top, width, height, tile->data,
2298 progressive->format, tile->stride, nXSrc, nYSrc, NULL, FREERDP_KEEP_DST_ALPHA);
2303 region16_union_rect(invalidRegion, invalidRegion, rect);
2306 region16_uninit(&updateRegion);
2309 tile->dirty = FALSE;
2313 region16_uninit(&clippingRects);
2317INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2318 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
2319 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2320 UINT32 nXDst, UINT32 nYDst,
REGION16* WINPR_RESTRICT invalidRegion,
2321 UINT16 surfaceId, UINT32 frameId)
2325 WINPR_ASSERT(progressive);
2330 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion no surface for %" PRIu16,
2335 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2336 WINPR_ASSERT(region);
2338 if (surface->frameId != frameId)
2340 surface->frameId = frameId;
2341 surface->numUpdatedTiles = 0;
2345 wStream* s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
2350 case PIXEL_FORMAT_RGBA32:
2351 case PIXEL_FORMAT_RGBX32:
2352 case PIXEL_FORMAT_BGRA32:
2353 case PIXEL_FORMAT_BGRX32:
2354 progressive->format = DstFormat;
2357 progressive->format = PIXEL_FORMAT_XRGB32;
2361 const size_t start = Stream_GetPosition(s);
2362 progressive->state = 0;
2363 while (Stream_GetRemainingLength(s) > 0)
2365 if (progressive_parse_block(progressive, s, surface, region) < 0)
2369 const size_t end = Stream_GetPosition(s);
2370 if ((end - start) != SrcSize)
2372 WLog_Print(progressive->log, WLOG_ERROR,
2373 "total block len %" PRIuz
" does not match read data %" PRIu32, end - start,
2379 if (!update_tiles(progressive, surface, pDstData, DstFormat, nDstStep, nXDst, nYDst, region,
2386BOOL progressive_rfx_write_message_progressive_simple(
2387 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s,
2388 const RFX_MESSAGE* WINPR_RESTRICT msg)
2390 RFX_CONTEXT* context = NULL;
2392 WINPR_ASSERT(progressive);
2395 context = progressive->rfx_context;
2396 return rfx_write_message_progressive_simple(context, s, msg);
2399int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2400 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 SrcFormat,
2401 UINT32 Width, UINT32 Height, UINT32 ScanLine,
2402 const REGION16* WINPR_RESTRICT invalidRegion,
2403 BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize)
2408 UINT32 numRects = 0;
2410 RFX_MESSAGE* message = NULL;
2412 if (!progressive || !pSrcData || !ppDstData || !pDstSize)
2421 case PIXEL_FORMAT_ABGR32:
2422 case PIXEL_FORMAT_ARGB32:
2423 case PIXEL_FORMAT_XBGR32:
2424 case PIXEL_FORMAT_XRGB32:
2425 case PIXEL_FORMAT_BGRA32:
2426 case PIXEL_FORMAT_BGRX32:
2427 case PIXEL_FORMAT_RGBA32:
2428 case PIXEL_FORMAT_RGBX32:
2429 ScanLine = Width * 4;
2436 if (SrcSize < Height * ScanLine)
2441 numRects = (Width + 63) / 64;
2442 numRects *= (Height + 63) / 64;
2446 const int nr = region16_n_rects(invalidRegion);
2447 numRects = WINPR_ASSERTING_INT_CAST(uint32_t, nr);
2453 if (!Stream_EnsureRemainingCapacity(progressive->rects, numRects *
sizeof(
RFX_RECT)))
2455 rects = Stream_BufferAs(progressive->rects,
RFX_RECT);
2458 const RECTANGLE_16* region_rects = region16_rects(invalidRegion, NULL);
2459 for (UINT32 idx = 0; idx < numRects; idx++)
2466 rect->width = r->right - r->left;
2467 rect->height = r->bottom - r->top;
2475 for (UINT32 i = 0; i < numRects; i++)
2481 WINPR_ASSERT(Width >= x);
2482 WINPR_ASSERT(Height >= y);
2483 r->width = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Width - x));
2484 r->height = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Height - y));
2486 if (x + 64UL >= Width)
2494 WINPR_ASSERT(r->x % 64 == 0);
2495 WINPR_ASSERT(r->y % 64 == 0);
2496 WINPR_ASSERT(r->width <= 64);
2497 WINPR_ASSERT(r->height <= 64);
2500 s = progressive->buffer;
2501 Stream_SetPosition(s, 0);
2503 progressive->rfx_context->mode = RLGR1;
2505 progressive->rfx_context->width = WINPR_ASSERTING_INT_CAST(UINT16, Width);
2506 progressive->rfx_context->height = WINPR_ASSERTING_INT_CAST(UINT16, Height);
2507 rfx_context_set_pixel_format(progressive->rfx_context, SrcFormat);
2508 message = rfx_encode_message(progressive->rfx_context, rects, numRects, pSrcData, Width, Height,
2512 WLog_ERR(TAG,
"failed to encode rfx message");
2516 rc = progressive_rfx_write_message_progressive_simple(progressive, s, message);
2517 rfx_message_free(progressive->rfx_context, message);
2521 const size_t pos = Stream_GetPosition(s);
2522 WINPR_ASSERT(pos <= UINT32_MAX);
2523 *pDstSize = (UINT32)pos;
2524 *ppDstData = Stream_Buffer(s);
2530BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive)
2538PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
2540 return progressive_context_new_ex(Compressor, 0);
2543PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, UINT32 ThreadingFlags)
2545 PROGRESSIVE_CONTEXT* progressive =
2546 (PROGRESSIVE_CONTEXT*)winpr_aligned_calloc(1,
sizeof(PROGRESSIVE_CONTEXT), 32);
2551 progressive->Compressor = Compressor;
2552 progressive->quantProgValFull.quality = 100;
2553 progressive->log = WLog_Get(TAG);
2554 if (!progressive->log)
2556 progressive->rfx_context = rfx_context_new_ex(Compressor, ThreadingFlags);
2557 if (!progressive->rfx_context)
2559 progressive->buffer = Stream_New(NULL, 1024);
2560 if (!progressive->buffer)
2562 progressive->rects = Stream_New(NULL, 1024);
2563 if (!progressive->rects)
2565 progressive->bufferPool = BufferPool_New(TRUE, (8192LL + 32LL) * 3LL, 16);
2566 if (!progressive->bufferPool)
2568 progressive->SurfaceContexts = HashTable_New(TRUE);
2569 if (!progressive->SurfaceContexts)
2573 wObject* obj = HashTable_ValueObject(progressive->SurfaceContexts);
2575 obj->fnObjectFree = progressive_surface_context_free;
2579 WINPR_PRAGMA_DIAG_PUSH
2580 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2581 progressive_context_free(progressive);
2582 WINPR_PRAGMA_DIAG_POP
2586void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
2591 Stream_Free(progressive->buffer, TRUE);
2592 Stream_Free(progressive->rects, TRUE);
2593 rfx_context_free(progressive->rfx_context);
2595 BufferPool_Free(progressive->bufferPool);
2596 HashTable_Free(progressive->SurfaceContexts);
2598 winpr_aligned_free(progressive);
fn_add_16s_inplace_t add_16s_inplace
Do vecotor addition, store result in both input buffers pSrcDst1 = pSrcDst2 = pSrcDst1 + pSrcDst2.
fn_lShiftC_16s_inplace_t lShiftC_16s_inplace
This struct contains function pointer to initialize/free objects.