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;
304 const size_t dataLen = 1ull * tile->stride * tile->height;
305 tile->data = (BYTE*)winpr_aligned_malloc(dataLen, 16);
308 memset(tile->data, 0xFF, dataLen);
312 const size_t signLen = (8192ULL + 32ULL) * 3ULL;
313 tile->sign = (BYTE*)winpr_aligned_malloc(signLen, 16);
320 const size_t currentLen = (8192ULL + 32ULL) * 3ULL;
321 tile->current = (BYTE*)winpr_aligned_malloc(currentLen, 16);
329 progressive_tile_free(tile);
338 WINPR_ASSERT(surface);
339 WINPR_ASSERT(surface->gridSize > 0);
343 oldIndex = surface->gridSize;
344 while (surface->gridSize < min)
345 surface->gridSize += 1024;
348 void* tmp = winpr_aligned_recalloc((
void*)surface->tiles, surface->gridSize,
352 surface->tilesSize = surface->gridSize;
355 for (
size_t x = oldIndex; x < surface->tilesSize; x++)
357 surface->tiles[x] = progressive_tile_new();
358 if (!surface->tiles[x])
363 winpr_aligned_recalloc(surface->updatedTileIndices, surface->gridSize,
sizeof(UINT32), 32);
367 surface->updatedTileIndices = tmp;
381 surface->id = surfaceId;
382 surface->width = width;
383 surface->height = height;
384 surface->gridWidth = (width + (64 - width % 64)) / 64;
385 surface->gridHeight = (height + (64 - height % 64)) / 64;
386 surface->gridSize = surface->gridWidth * surface->gridHeight;
388 if (!progressive_allocate_tile_cache(surface, surface->gridSize))
390 progressive_surface_context_free(surface);
399 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
405 if (!surface || !tile)
408 zIdx = (tile->yIdx * surface->gridWidth) + tile->xIdx;
410 if (zIdx >= surface->tilesSize)
412 WLog_ERR(TAG,
"Invalid zIndex %" PRIuz, zIdx);
416 t = surface->tiles[zIdx];
418 t->blockType = tile->blockType;
419 t->blockLen = tile->blockLen;
420 t->quantIdxY = tile->quantIdxY;
421 t->quantIdxCb = tile->quantIdxCb;
422 t->quantIdxCr = tile->quantIdxCr;
423 t->xIdx = tile->xIdx;
424 t->yIdx = tile->yIdx;
425 t->flags = tile->flags;
426 t->quality = tile->quality;
427 t->x = tile->xIdx * t->width;
428 t->y = tile->yIdx * t->height;
432 t->ySrlLen = tile->ySrlLen;
433 t->yRawLen = tile->yRawLen;
434 t->cbSrlLen = tile->cbSrlLen;
435 t->cbRawLen = tile->cbRawLen;
436 t->crSrlLen = tile->crSrlLen;
437 t->crRawLen = tile->crRawLen;
438 t->ySrlData = tile->ySrlData;
439 t->yRawData = tile->yRawData;
440 t->cbSrlData = tile->cbSrlData;
441 t->cbRawData = tile->cbRawData;
442 t->crSrlData = tile->crSrlData;
443 t->crRawData = tile->crRawData;
447 t->yLen = tile->yLen;
448 t->cbLen = tile->cbLen;
449 t->crLen = tile->crLen;
450 t->tailLen = tile->tailLen;
451 t->yData = tile->yData;
452 t->cbData = tile->cbData;
453 t->crData = tile->crData;
454 t->tailData = tile->tailData;
457 if (region->usedTiles >= region->numTiles)
459 WLog_ERR(TAG,
"Invalid tile count, only expected %" PRIu16
", got %" PRIu16,
460 region->numTiles, region->usedTiles);
464 region->tiles[region->usedTiles++] = t;
467 if (surface->numUpdatedTiles >= surface->gridSize)
469 if (!progressive_allocate_tile_cache(surface, surface->numUpdatedTiles + 1))
473 surface->updatedTileIndices[surface->numUpdatedTiles++] = (UINT32)zIdx;
480INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
481 UINT16 surfaceId, UINT32 width, UINT32 height)
487 surface = progressive_surface_context_new(surfaceId, width, height);
492 if (!progressive_set_surface_data(progressive, surfaceId, (
void*)surface))
494 progressive_surface_context_free(surface);
502int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
505 progressive_set_surface_data(progressive, surfaceId,
nullptr);
528static int16_t clampi16(
int val)
537static inline void progressive_rfx_idwt_x(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
538 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
539 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
540 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
545 for (
size_t i = 0; i < nDstCount; i++)
547 const INT16* pL = pLowBand;
548 const INT16* pH = pHighBand;
549 INT16* pX = pDstBand;
552 INT16 X0 = clampi16((int32_t)L0 - H0);
553 INT16 X2 = clampi16((int32_t)L0 - H0);
555 for (
size_t j = 0; j < (nHighCount - 1); j++)
561 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
562 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
570 if (nLowCount <= (nHighCount + 1))
572 if (nLowCount <= nHighCount)
575 pX[1] = clampi16((int32_t)X2 + (2 * H0));
581 X0 = clampi16((int32_t)L0 - H0);
583 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
591 X0 = clampi16((int32_t)L0 - (H0 / 2));
593 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
597 pX[3] = clampi16((int32_t)(X0 + L0) / 2);
600 pLowBand += nLowStep;
601 pHighBand += nHighStep;
602 pDstBand += nDstStep;
606static inline void progressive_rfx_idwt_y(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
607 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
608 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
609 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
611 for (
size_t i = 0; i < nDstCount; i++)
615 const INT16* pL = pLowBand;
616 const INT16* pH = pHighBand;
617 INT16* pX = pDstBand;
622 int16_t X0 = clampi16((int32_t)L0 - H0);
623 int16_t X2 = clampi16((int32_t)L0 - H0);
625 for (
size_t j = 0; j < (nHighCount - 1); j++)
631 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
632 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
641 if (nLowCount <= (nHighCount + 1))
643 if (nLowCount <= nHighCount)
647 *pX = clampi16((int32_t)X2 + (2 * H0));
652 X0 = clampi16((int32_t)L0 - H0);
655 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
664 X0 = clampi16((int32_t)L0 - (H0 / 2));
667 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
672 *pX = clampi16((int32_t)(X0 + L0) / 2);
681static inline size_t progressive_rfx_get_band_l_count(
size_t level)
683 return (64 >> level) + 1;
686static inline size_t progressive_rfx_get_band_h_count(
size_t level)
689 return (64 >> 1) - 1;
691 return (64 + (1 << (level - 1))) >> level;
694static inline void progressive_rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer,
695 INT16* WINPR_RESTRICT temp,
size_t level)
697 size_t nDstStepX = 0;
698 size_t nDstStepY = 0;
699 const INT16* WINPR_RESTRICT HL =
nullptr;
700 const INT16* WINPR_RESTRICT LH =
nullptr;
701 const INT16* WINPR_RESTRICT HH =
nullptr;
702 INT16* WINPR_RESTRICT LL =
nullptr;
703 INT16* WINPR_RESTRICT L =
nullptr;
704 INT16* WINPR_RESTRICT H =
nullptr;
705 INT16* WINPR_RESTRICT LLx =
nullptr;
707 const size_t nBandL = progressive_rfx_get_band_l_count(level);
708 const size_t nBandH = progressive_rfx_get_band_h_count(level);
711 HL = &buffer[offset];
712 offset += (nBandH * nBandL);
713 LH = &buffer[offset];
714 offset += (nBandL * nBandH);
715 HH = &buffer[offset];
716 offset += (nBandH * nBandH);
717 LL = &buffer[offset];
718 nDstStepX = (nBandL + nBandH);
719 nDstStepY = (nBandL + nBandH);
722 offset += (nBandL * nDstStepX);
727 progressive_rfx_idwt_x(LL, nBandL, HL, nBandH, L, nDstStepX, nBandL, nBandH, nBandL);
730 progressive_rfx_idwt_x(LH, nBandL, HH, nBandH, H, nDstStepX, nBandL, nBandH, nBandH);
733 progressive_rfx_idwt_y(L, nDstStepX, H, nDstStepX, LLx, nDstStepY, nBandL, nBandH,
737void rfx_dwt_2d_extrapolate_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
739 WINPR_ASSERT(buffer);
740 WINPR_ASSERT(dwt_buffer);
741 progressive_rfx_dwt_2d_decode_block(&buffer[3807], dwt_buffer, 3);
742 progressive_rfx_dwt_2d_decode_block(&buffer[3007], dwt_buffer, 2);
743 progressive_rfx_dwt_2d_decode_block(&buffer[0], dwt_buffer, 1);
746static inline int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
747 INT16* WINPR_RESTRICT buffer,
748 INT16* WINPR_RESTRICT current, BOOL coeffDiff,
749 BOOL extrapolate, BOOL reverse)
753 if (!progressive || !buffer || !current)
756 const uint32_t belements = 4096;
757 const uint32_t bsize = belements *
sizeof(INT16);
759 memcpy(buffer, current, bsize);
761 memcpy(current, buffer, bsize);
764 const pstatus_t rc = prims->
add_16s_inplace(buffer, current, belements);
765 if (rc != PRIMITIVES_SUCCESS)
769 INT16* temp = (INT16*)BufferPool_Take(progressive->bufferPool, -1);
776 progressive->rfx_context->dwt_2d_decode(buffer, temp);
780 WINPR_ASSERT(progressive->rfx_context->dwt_2d_extrapolate_decode);
781 progressive->rfx_context->dwt_2d_extrapolate_decode(buffer, temp);
783 BufferPool_Return(progressive->bufferPool, temp);
787static inline BOOL progressive_rfx_decode_block(
const primitives_t* prims,
788 INT16* WINPR_RESTRICT buffer, UINT32 length,
798progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
800 const BYTE* WINPR_RESTRICT data, UINT32 length,
801 INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
802 INT16* WINPR_RESTRICT sign, BOOL coeffDiff,
803 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
808 status = progressive->rfx_context->rlgr_decode(RLGR1, data, length, buffer, 4096);
813 CopyMemory(sign, buffer, 4096ULL * 2ULL);
816 rfx_differential_decode(buffer + 4032, 64);
817 if (!progressive_rfx_decode_block(prims, &buffer[0], 1024, shift->HL1))
819 if (!progressive_rfx_decode_block(prims, &buffer[1024], 1024, shift->LH1))
821 if (!progressive_rfx_decode_block(prims, &buffer[2048], 1024, shift->HH1))
823 if (!progressive_rfx_decode_block(prims, &buffer[3072], 256, shift->HL2))
825 if (!progressive_rfx_decode_block(prims, &buffer[3328], 256, shift->LH2))
827 if (!progressive_rfx_decode_block(prims, &buffer[3584], 256, shift->HH2))
829 if (!progressive_rfx_decode_block(prims, &buffer[3840], 64, shift->HL3))
831 if (!progressive_rfx_decode_block(prims, &buffer[3904], 64, shift->LH3))
833 if (!progressive_rfx_decode_block(prims, &buffer[3968], 64, shift->HH3))
835 if (!progressive_rfx_decode_block(prims, &buffer[4032], 64, shift->LL3))
840 if (!progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1))
842 if (!progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1))
844 if (!progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1))
846 if (!progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2))
848 if (!progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2))
850 if (!progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2))
852 if (!progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3))
854 if (!progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3))
856 if (!progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3))
858 rfx_differential_decode(&buffer[4015], 81);
859 if (!progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3))
862 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
867progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
869 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
875 BOOL extrapolate = 0;
876 BYTE* pBuffer =
nullptr;
894 diff = tile->flags & RFX_TILE_DIFFERENCE;
895 sub = context->flags & RFX_SUBBAND_DIFFING;
896 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
898#if defined(WITH_DEBUG_CODECS)
899 WLog_Print(progressive->log, WLOG_DEBUG,
900 "ProgressiveTile%s: quantIdx Y: %" PRIu8
" Cb: %" PRIu8
" Cr: %" PRIu8
901 " xIdx: %" PRIu16
" yIdx: %" PRIu16
" flags: 0x%02" PRIX8
" quality: %" PRIu8
902 " yLen: %" PRIu16
" cbLen: %" PRIu16
" crLen: %" PRIu16
" tailLen: %" PRIu16
"",
903 (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ?
"First" :
"Simple",
904 tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx,
905 tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
908 if (tile->quantIdxY >= region->numQuant)
910 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
914 quantY = &(region->quantVals[tile->quantIdxY]);
916 if (tile->quantIdxCb >= region->numQuant)
918 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
923 quantCb = &(region->quantVals[tile->quantIdxCb]);
925 if (tile->quantIdxCr >= region->numQuant)
927 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
932 quantCr = &(region->quantVals[tile->quantIdxCr]);
934 if (tile->quality == 0xFF)
936 quantProgVal = &(progressive->quantProgValFull);
940 if (tile->quality >= region->numProgQuant)
942 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
943 region->numProgQuant);
947 quantProgVal = &(region->quantProgVals[tile->quality]);
950 quantProgY = &(quantProgVal->yQuantValues);
951 quantProgCb = &(quantProgVal->cbQuantValues);
952 quantProgCr = &(quantProgVal->crQuantValues);
954 tile->yQuant = *quantY;
955 tile->cbQuant = *quantCb;
956 tile->crQuant = *quantCr;
957 tile->yProgQuant = *quantProgY;
958 tile->cbProgQuant = *quantProgCb;
959 tile->crProgQuant = *quantProgCr;
961 progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
962 progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
963 progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
964 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
965 progressive_rfx_quant_lsub(&shiftY, 1);
966 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
967 progressive_rfx_quant_lsub(&shiftCb, 1);
968 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
969 progressive_rfx_quant_lsub(&shiftCr, 1);
971 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
972 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
973 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
975 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
976 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
977 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
979 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
980 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
981 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
982 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
984 rc = progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0],
985 pCurrent[0], pSign[0], diff, sub, extrapolate);
988 rc = progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen,
989 pSrcDst[1], pCurrent[1], pSign[1], diff, sub,
993 rc = progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen,
994 pSrcDst[2], pCurrent[2], pSign[2], diff, sub,
1000 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1001 rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1002 progressive->format, &roi_64x64);
1005 BufferPool_Return(progressive->bufferPool, pBuffer);
1009static inline INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1012 WINPR_ASSERT(state);
1023 const UINT32 k = state->kp / 8;
1028 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1029 BitStream_Shift(bs, 1);
1034 state->nz = (1 << k);
1051 bs->mask = ((1 << k) - 1);
1053 WINPR_ASSERTING_INT_CAST(int16_t, ((bs->accumulator >> (32u - k)) & bs->mask));
1054 BitStream_Shift(bs, k);
1068 const UINT32 sign = (bs->accumulator & 0x80000000) ? 1 : 0;
1069 BitStream_Shift(bs, 1);
1077 return sign ? -1 : 1;
1080 const UINT32 max = (1 << numBits) - 1;
1084 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1085 BitStream_Shift(bs, 1);
1093 if (mag > INT16_MAX)
1095 return (INT16)(sign ? -1 * (int)mag : (INT16)mag);
1099progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state)
1110 pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
1113 BitStream_Shift(raw, pad);
1115 pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
1118 BitStream_Shift(srl, pad);
1120 if (BitStream_GetRemainingLength(srl) == 8)
1121 BitStream_Shift(srl, 8);
1126static inline int16_t rawShift(
wBitStream* raw, UINT32 numBits)
1129 WINPR_ASSERT(numBits > 0);
1131 raw->mask = ((1 << numBits) - 1);
1132 const int16_t input = (int16_t)((raw->accumulator >> (32 - numBits)) & raw->mask);
1133 BitStream_Shift(raw, numBits);
1137static inline int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1138 INT16* WINPR_RESTRICT buffer,
1139 INT16* WINPR_RESTRICT sign, UINT32 length,
1140 UINT32 shift, WINPR_ATTR_UNUSED UINT32 bitPos,
1151 for (UINT32 index = 0; index < length; index++)
1153 input = rawShift(raw, numBits);
1155 const int32_t shifted = input << shift;
1156 const int32_t val = buffer[index] + shifted;
1157 const int16_t ival = WINPR_ASSERTING_INT_CAST(int16_t, val);
1158 buffer[index] = ival;
1164 for (UINT32 index = 0; index < length; index++)
1166 if (sign[index] > 0)
1169 input = rawShift(raw, numBits);
1171 else if (sign[index] < 0)
1174 input = rawShift(raw, numBits);
1180 input = progressive_rfx_srl_read(state, numBits);
1181 sign[index] = WINPR_ASSERTING_INT_CAST(int16_t, input);
1184 const int32_t val = input << shift;
1185 const int32_t ival = buffer[index] + val;
1186 buffer[index] = WINPR_ASSERTING_INT_CAST(INT16, ival);
1192static inline int progressive_rfx_upgrade_component(
1193 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1197 INT16* WINPR_RESTRICT current, INT16* WINPR_RESTRICT sign,
const BYTE* WINPR_RESTRICT srlData,
1198 UINT32 srlLen,
const BYTE* WINPR_RESTRICT rawData, UINT32 rawLen, BOOL coeffDiff,
1199 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
1206 RFX_PROGRESSIVE_UPGRADE_STATE state = WINPR_C_ARRAY_INIT;
1212 BitStream_Attach(state.srl, srlData, srlLen);
1213 BitStream_Fetch(state.srl);
1214 BitStream_Attach(state.raw, rawData, rawLen);
1215 BitStream_Fetch(state.raw);
1218 rc = progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1,
1222 rc = progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1,
1223 bitPos->LH1, numBits->LH1);
1226 rc = progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1,
1227 bitPos->HH1, numBits->HH1);
1230 rc = progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2,
1231 bitPos->HL2, numBits->HL2);
1234 rc = progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2,
1235 bitPos->LH2, numBits->LH2);
1238 rc = progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2,
1239 bitPos->HH2, numBits->HH2);
1242 rc = progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3,
1243 bitPos->HL3, numBits->HL3);
1246 rc = progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3,
1247 bitPos->LH3, numBits->LH3);
1250 rc = progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3,
1251 bitPos->HH3, numBits->HH3);
1255 state.nonLL = FALSE;
1256 rc = progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3,
1257 bitPos->LL3, numBits->LL3);
1260 rc = progressive_rfx_upgrade_state_finish(&state);
1263 aRawLen = (state.raw->position + 7) / 8;
1264 aSrlLen = (state.srl->position + 7) / 8;
1266 if ((aRawLen != rawLen) || (aSrlLen != srlLen))
1272 pRawLen = (int)((((
float)aRawLen) / ((
float)rawLen)) * 100.0f);
1275 pSrlLen = (int)((((
float)aSrlLen) / ((
float)srlLen)) * 100.0f);
1277 WLog_Print(progressive->log, WLOG_WARN,
1278 "RAW: %" PRIu32
"/%" PRIu32
" %d%% (%" PRIu32
"/%" PRIu32
":%" PRIu32
1279 ")\tSRL: %" PRIu32
"/%" PRIu32
" %d%% (%" PRIu32
"/%" PRIu32
":%" PRIu32
")",
1280 aRawLen, rawLen, pRawLen, state.raw->position, rawLen * 8,
1281 (rawLen * 8) - state.raw->position, aSrlLen, srlLen, pSrlLen,
1282 state.srl->position, srlLen * 8, (srlLen * 8) - state.srl->position);
1286 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
1291progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1293 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1299 BOOL extrapolate = 0;
1300 BYTE* pBuffer =
nullptr;
1301 INT16* pSign[3] = WINPR_C_ARRAY_INIT;
1302 INT16* pSrcDst[3] = WINPR_C_ARRAY_INIT;
1303 INT16* pCurrent[3] = WINPR_C_ARRAY_INIT;
1323 coeffDiff = tile->flags & RFX_TILE_DIFFERENCE;
1324 sub = context->flags & RFX_SUBBAND_DIFFING;
1325 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
1329#if defined(WITH_DEBUG_CODECS)
1330 WLog_Print(progressive->log, WLOG_DEBUG,
1331 "ProgressiveTileUpgrade: pass: %" PRIu16
" quantIdx Y: %" PRIu8
" Cb: %" PRIu8
1332 " Cr: %" PRIu8
" xIdx: %" PRIu16
" yIdx: %" PRIu16
" quality: %" PRIu8
1333 " ySrlLen: %" PRIu16
" yRawLen: %" PRIu16
" cbSrlLen: %" PRIu16
" cbRawLen: %" PRIu16
1334 " crSrlLen: %" PRIu16
" crRawLen: %" PRIu16
"",
1335 tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx,
1336 tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen,
1337 tile->cbRawLen, tile->crSrlLen, tile->crRawLen);
1340 if (tile->quantIdxY >= region->numQuant)
1342 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
1346 quantY = &(region->quantVals[tile->quantIdxY]);
1348 if (tile->quantIdxCb >= region->numQuant)
1350 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
1355 quantCb = &(region->quantVals[tile->quantIdxCb]);
1357 if (tile->quantIdxCr >= region->numQuant)
1359 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1364 quantCr = &(region->quantVals[tile->quantIdxCr]);
1366 if (tile->quality == 0xFF)
1368 quantProg = &(progressive->quantProgValFull);
1372 if (tile->quality >= region->numProgQuant)
1374 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1375 region->numProgQuant);
1379 quantProg = &(region->quantProgVals[tile->quality]);
1382 quantProgY = &(quantProg->yQuantValues);
1383 quantProgCb = &(quantProg->cbQuantValues);
1384 quantProgCr = &(quantProg->crQuantValues);
1386 if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
1387 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantY has changed!");
1389 if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
1390 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCb has changed!");
1392 if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
1393 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCr has changed!");
1395 if (!(context->flags & RFX_SUBBAND_DIFFING))
1396 WLog_WARN(TAG,
"PROGRESSIVE_BLOCK_CONTEXT::flags & RFX_SUBBAND_DIFFING not set");
1398 progressive_rfx_quant_add(quantY, quantProgY, &yBitPos);
1399 progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos);
1400 progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos);
1401 progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits);
1402 progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits);
1403 progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits);
1404 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1405 progressive_rfx_quant_lsub(&shiftY, 1);
1406 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1407 progressive_rfx_quant_lsub(&shiftCb, 1);
1408 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1409 progressive_rfx_quant_lsub(&shiftCr, 1);
1411 tile->yBitPos = yBitPos;
1412 tile->cbBitPos = cbBitPos;
1413 tile->crBitPos = crBitPos;
1414 tile->yQuant = *quantY;
1415 tile->cbQuant = *quantCb;
1416 tile->crQuant = *quantCr;
1417 tile->yProgQuant = *quantProgY;
1418 tile->cbProgQuant = *quantProgCb;
1419 tile->crProgQuant = *quantProgCr;
1421 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
1422 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
1423 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
1425 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
1426 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
1427 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
1429 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1430 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
1431 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
1432 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
1434 status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
1435 pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData,
1436 tile->ySrlLen, tile->yRawData, tile->yRawLen,
1437 coeffDiff, sub, extrapolate);
1442 status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
1443 pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData,
1444 tile->cbSrlLen, tile->cbRawData, tile->cbRawLen,
1445 coeffDiff, sub, extrapolate);
1450 status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
1451 pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData,
1452 tile->crSrlLen, tile->crRawData, tile->crRawLen,
1453 coeffDiff, sub, extrapolate);
1459 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1460 status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1461 progressive->format, &roi_64x64);
1464 BufferPool_Return(progressive->bufferPool, pBuffer);
1468static inline BOOL progressive_tile_read_upgrade(
1469 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1471 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1475 const size_t expect = 20;
1477 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1480 tile.blockType = blockType;
1481 tile.blockLen = blockLen;
1484 Stream_Read_UINT8(s, tile.quantIdxY);
1485 Stream_Read_UINT8(s, tile.quantIdxCb);
1486 Stream_Read_UINT8(s, tile.quantIdxCr);
1487 Stream_Read_UINT16(s, tile.xIdx);
1488 Stream_Read_UINT16(s, tile.yIdx);
1489 Stream_Read_UINT8(s, tile.quality);
1490 Stream_Read_UINT16(s, tile.ySrlLen);
1491 Stream_Read_UINT16(s, tile.yRawLen);
1492 Stream_Read_UINT16(s, tile.cbSrlLen);
1493 Stream_Read_UINT16(s, tile.cbRawLen);
1494 Stream_Read_UINT16(s, tile.crSrlLen);
1495 Stream_Read_UINT16(s, tile.crRawLen);
1497 tile.ySrlData = Stream_Pointer(s);
1498 if (!Stream_SafeSeek(s, tile.ySrlLen))
1500 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.ySrlLen);
1504 tile.yRawData = Stream_Pointer(s);
1505 if (!Stream_SafeSeek(s, tile.yRawLen))
1507 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yRawLen);
1511 tile.cbSrlData = Stream_Pointer(s);
1512 if (!Stream_SafeSeek(s, tile.cbSrlLen))
1514 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1519 tile.cbRawData = Stream_Pointer(s);
1520 if (!Stream_SafeSeek(s, tile.cbRawLen))
1522 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1527 tile.crSrlData = Stream_Pointer(s);
1528 if (!Stream_SafeSeek(s, tile.crSrlLen))
1530 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1535 tile.crRawData = Stream_Pointer(s);
1536 if (!Stream_SafeSeek(s, tile.crRawLen))
1538 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1543 return progressive_surface_tile_replace(surface, region, &tile, TRUE);
1547progressive_tile_read(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, BOOL simple,
1548 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
1550 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1554 size_t expect = simple ? 16 : 17;
1556 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1559 tile.blockType = blockType;
1560 tile.blockLen = blockLen;
1562 Stream_Read_UINT8(s, tile.quantIdxY);
1563 Stream_Read_UINT8(s, tile.quantIdxCb);
1564 Stream_Read_UINT8(s, tile.quantIdxCr);
1565 Stream_Read_UINT16(s, tile.xIdx);
1566 Stream_Read_UINT16(s, tile.yIdx);
1567 Stream_Read_UINT8(s, tile.flags);
1570 Stream_Read_UINT8(s, tile.quality);
1572 tile.quality = 0xFF;
1573 Stream_Read_UINT16(s, tile.yLen);
1574 Stream_Read_UINT16(s, tile.cbLen);
1575 Stream_Read_UINT16(s, tile.crLen);
1576 Stream_Read_UINT16(s, tile.tailLen);
1578 tile.yData = Stream_Pointer(s);
1579 if (!Stream_SafeSeek(s, tile.yLen))
1581 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yLen);
1585 tile.cbData = Stream_Pointer(s);
1586 if (!Stream_SafeSeek(s, tile.cbLen))
1588 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.cbLen);
1592 tile.crData = Stream_Pointer(s);
1593 if (!Stream_SafeSeek(s, tile.crLen))
1595 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.crLen);
1599 tile.tailData = Stream_Pointer(s);
1600 if (!Stream_SafeSeek(s, tile.tailLen))
1602 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.tailLen);
1606 return progressive_surface_tile_replace(surface, region, &tile, FALSE);
1609static void CALLBACK progressive_process_tiles_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1610 void* context, PTP_WORK work)
1614 WINPR_UNUSED(instance);
1617 switch (param->tile->blockType)
1619 case PROGRESSIVE_WBT_TILE_SIMPLE:
1620 case PROGRESSIVE_WBT_TILE_FIRST:
1621 progressive_decompress_tile_first(param->progressive, param->tile, param->region,
1625 case PROGRESSIVE_WBT_TILE_UPGRADE:
1626 progressive_decompress_tile_upgrade(param->progressive, param->tile, param->region,
1630 WLog_Print(param->progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16
" (%s)",
1631 param->tile->blockType,
1632 rfx_get_progressive_block_type_string(param->tile->blockType));
1637static inline SSIZE_T
1638progressive_process_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1640 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1646 const size_t start = Stream_GetPosition(s);
1647 UINT16 blockType = 0;
1648 UINT32 blockLen = 0;
1650 UINT16 close_cnt = 0;
1652 WINPR_ASSERT(progressive);
1653 WINPR_ASSERT(region);
1655 if (!Stream_CheckAndLogRequiredLength(TAG, s, region->tileDataSize))
1658 while ((Stream_GetRemainingLength(s) >= 6) &&
1659 (region->tileDataSize > (Stream_GetPosition(s) - start)))
1661 const size_t pos = Stream_GetPosition(s);
1663 Stream_Read_UINT16(s, blockType);
1664 Stream_Read_UINT32(s, blockLen);
1666#if defined(WITH_DEBUG_CODECS)
1667 WLog_Print(progressive->log, WLOG_DEBUG,
"%s",
1668 rfx_get_progressive_block_type_string(blockType));
1673 WLog_Print(progressive->log, WLOG_ERROR,
"Expected >= %" PRIu32
" remaining %" PRIu32,
1677 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
1682 case PROGRESSIVE_WBT_TILE_SIMPLE:
1683 if (!progressive_tile_read(progressive, TRUE, s, blockType, blockLen, surface,
1688 case PROGRESSIVE_WBT_TILE_FIRST:
1689 if (!progressive_tile_read(progressive, FALSE, s, blockType, blockLen, surface,
1694 case PROGRESSIVE_WBT_TILE_UPGRADE:
1695 if (!progressive_tile_read_upgrade(progressive, s, blockType, blockLen, surface,
1700 WLog_ERR(TAG,
"Invalid block type %04" PRIx16
" (%s)", blockType,
1701 rfx_get_progressive_block_type_string(blockType));
1705 size_t rem = Stream_GetPosition(s);
1706 if ((rem - pos) != blockLen)
1708 WLog_Print(progressive->log, WLOG_ERROR,
1709 "Actual block read %" PRIuz
" but expected %" PRIu32, rem - pos, blockLen);
1715 end = Stream_GetPosition(s);
1716 if ((end - start) != region->tileDataSize)
1718 WLog_Print(progressive->log, WLOG_ERROR,
1719 "Actual total blocks read %" PRIuz
" but expected %" PRIu32, end - start,
1720 region->tileDataSize);
1724 if (count != region->numTiles)
1726 WLog_Print(progressive->log, WLOG_WARN,
1727 "numTiles inconsistency: actual: %" PRIu32
", expected: %" PRIu16
"\n", count,
1732 for (UINT32 idx = 0; idx < region->numTiles; idx++)
1736 param->progressive = progressive;
1737 param->region = region;
1738 param->context = context;
1741 if (progressive->rfx_context->priv->UseThreads)
1743 progressive->work_objects[idx] = CreateThreadpoolWork(
1744 progressive_process_tiles_tile_work_callback, (
void*)param,
nullptr);
1745 if (!progressive->work_objects[idx])
1747 WLog_Print(progressive->log, WLOG_ERROR,
1748 "Failed to create ThreadpoolWork for tile %" PRIu32, idx);
1753 SubmitThreadpoolWork(progressive->work_objects[idx]);
1755 close_cnt = WINPR_ASSERTING_INT_CAST(UINT16, idx + 1);
1759 progressive_process_tiles_tile_work_callback(
nullptr, param,
nullptr);
1764 WLog_Print(progressive->log, WLOG_ERROR,
"Failed to decompress %s at %" PRIu16,
1765 rfx_get_progressive_block_type_string(tile->blockType), idx);
1770 if (progressive->rfx_context->priv->UseThreads)
1772 for (UINT32 idx = 0; idx < close_cnt; idx++)
1774 WaitForThreadpoolWorkCallbacks(progressive->work_objects[idx], FALSE);
1775 CloseThreadpoolWork(progressive->work_objects[idx]);
1784 return (SSIZE_T)(end - start);
1787static inline SSIZE_T progressive_wb_sync(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1788 wStream* WINPR_RESTRICT s, UINT16 blockType,
1791 const UINT32 magic = 0xCACCACCA;
1792 const UINT16 version = 0x0100;
1795 sync.blockType = blockType;
1796 sync.blockLen = blockLen;
1798 if (sync.blockLen != 12)
1800 WLog_Print(progressive->log, WLOG_ERROR,
1801 "PROGRESSIVE_BLOCK_SYNC::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1802 sync.blockLen, 12u);
1806 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1809#if defined(WITH_DEBUG_CODECS)
1810 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveSync");
1813 Stream_Read_UINT32(s, sync.magic);
1814 Stream_Read_UINT16(s, sync.version);
1816 if (sync.magic != magic)
1818 WLog_Print(progressive->log, WLOG_ERROR,
1819 "PROGRESSIVE_BLOCK_SYNC::magic = 0x%08" PRIx32
" != 0x%08" PRIx32, sync.magic,
1824 if (sync.version != 0x0100)
1826 WLog_Print(progressive->log, WLOG_ERROR,
1827 "PROGRESSIVE_BLOCK_SYNC::version = 0x%04" PRIx16
" != 0x%04" PRIu16,
1828 sync.version, version);
1832 if ((progressive->state & FLAG_WBT_SYNC) != 0)
1833 WLog_WARN(TAG,
"Duplicate PROGRESSIVE_BLOCK_SYNC, ignoring");
1835 progressive->state |= FLAG_WBT_SYNC;
1839static inline SSIZE_T progressive_wb_frame_begin(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1840 wStream* WINPR_RESTRICT s, UINT16 blockType,
1845 frameBegin.blockType = blockType;
1846 frameBegin.blockLen = blockLen;
1848 if (frameBegin.blockLen != 12)
1850 WLog_Print(progressive->log, WLOG_ERROR,
1851 " RFX_PROGRESSIVE_FRAME_BEGIN::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1852 frameBegin.blockLen, 12u);
1856 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1859 Stream_Read_UINT32(s, frameBegin.frameIndex);
1860 Stream_Read_UINT16(s, frameBegin.regionCount);
1862#if defined(WITH_DEBUG_CODECS)
1863 WLog_Print(progressive->log, WLOG_DEBUG,
1864 "ProgressiveFrameBegin: frameIndex: %" PRIu32
" regionCount: %" PRIu16
"",
1865 frameBegin.frameIndex, frameBegin.regionCount);
1874 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1876 WLog_ERR(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_BEGIN in stream, this is not allowed!");
1880 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1882 WLog_ERR(TAG,
"RFX_PROGRESSIVE_FRAME_BEGIN after RFX_PROGRESSIVE_FRAME_END in stream, this "
1887 progressive->state |= FLAG_WBT_FRAME_BEGIN;
1891static inline SSIZE_T progressive_wb_frame_end(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1892 wStream* WINPR_RESTRICT s, UINT16 blockType,
1897 frameEnd.blockType = blockType;
1898 frameEnd.blockLen = blockLen;
1900 if (frameEnd.blockLen != 6)
1902 WLog_Print(progressive->log, WLOG_ERROR,
1903 " RFX_PROGRESSIVE_FRAME_END::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1904 frameEnd.blockLen, 6u);
1908 if (Stream_GetRemainingLength(s) != 0)
1910 WLog_Print(progressive->log, WLOG_ERROR,
1911 "ProgressiveFrameEnd short %" PRIuz
", expected %u",
1912 Stream_GetRemainingLength(s), 0U);
1916#if defined(WITH_DEBUG_CODECS)
1917 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveFrameEnd");
1920 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
1921 WLog_WARN(TAG,
"RFX_PROGRESSIVE_FRAME_END before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
1922 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1923 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_END, ignoring");
1925 progressive->state |= FLAG_WBT_FRAME_END;
1929static inline SSIZE_T progressive_wb_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1930 wStream* WINPR_RESTRICT s, UINT16 blockType,
1934 context->blockType = blockType;
1935 context->blockLen = blockLen;
1937 if (context->blockLen != 10)
1939 WLog_Print(progressive->log, WLOG_ERROR,
1940 "RFX_PROGRESSIVE_CONTEXT::blockLen = 0x%08" PRIx32
" != 0x%08x",
1941 context->blockLen, 10u);
1945 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1948 Stream_Read_UINT8(s, context->ctxId);
1949 Stream_Read_UINT16(s, context->tileSize);
1950 Stream_Read_UINT8(s, context->flags);
1952 if (context->ctxId != 0x00)
1953 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT::ctxId != 0x00: %" PRIu8, context->ctxId);
1955 if (context->tileSize != 64)
1957 WLog_ERR(TAG,
"RFX_PROGRESSIVE_CONTEXT::tileSize != 0x40: %" PRIu16, context->tileSize);
1961 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1962 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_BEGIN");
1963 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1964 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_END");
1965 if ((progressive->state & FLAG_WBT_CONTEXT) != 0)
1966 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_CONTEXT received, ignoring.");
1968#if defined(WITH_DEBUG_CODECS)
1969 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveContext: flags: 0x%02" PRIX8
"",
1973 progressive->state |= FLAG_WBT_CONTEXT;
1977static inline SSIZE_T
1978progressive_wb_read_region_header(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1979 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
1980 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
1982 region->usedTiles = 0;
1984 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
1987 region->blockType = blockType;
1988 region->blockLen = blockLen;
1989 Stream_Read_UINT8(s, region->tileSize);
1990 Stream_Read_UINT16(s, region->numRects);
1991 Stream_Read_UINT8(s, region->numQuant);
1992 Stream_Read_UINT8(s, region->numProgQuant);
1993 Stream_Read_UINT8(s, region->flags);
1994 Stream_Read_UINT16(s, region->numTiles);
1995 Stream_Read_UINT32(s, region->tileDataSize);
1997 if (region->tileSize != 64)
1999 WLog_Print(progressive->log, WLOG_ERROR,
2000 "ProgressiveRegion tile size %" PRIu8
", expected %u", region->tileSize, 64U);
2004 if (region->numRects < 1)
2006 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion missing rect count %" PRIu16,
2011 if (region->numQuant > 7)
2013 WLog_Print(progressive->log, WLOG_ERROR,
2014 "ProgressiveRegion quant count too high %" PRIu8
", expected < %u",
2015 region->numQuant, 7U);
2019 const SSIZE_T rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, Stream_GetRemainingLength(s));
2020 const SSIZE_T expect = region->numRects * 8ll + region->numQuant * 5ll +
2021 region->numProgQuant * 16ll + region->tileDataSize;
2025 if (len / 8LL < region->numRects)
2027 WLog_Print(progressive->log, WLOG_ERROR,
2028 "ProgressiveRegion data short for region->rects");
2031 len -= region->numRects * 8LL;
2033 if (len / 5LL < region->numQuant)
2035 WLog_Print(progressive->log, WLOG_ERROR,
2036 "ProgressiveRegion data short for region->cQuant");
2039 len -= region->numQuant * 5LL;
2041 if (len / 16LL < region->numProgQuant)
2043 WLog_Print(progressive->log, WLOG_ERROR,
2044 "ProgressiveRegion data short for region->cProgQuant");
2047 len -= region->numProgQuant * 16LL;
2049 if (len < region->tileDataSize * 1ll)
2051 WLog_Print(progressive->log, WLOG_ERROR,
2052 "ProgressiveRegion data short for region->tiles");
2055 len -= region->tileDataSize;
2058 WLog_Print(progressive->log, WLOG_WARN,
2059 "Unused bytes detected, %" PRIdz
" bytes not processed", len);
2065static inline SSIZE_T progressive_wb_skip_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2066 wStream* WINPR_RESTRICT s, UINT16 blockType,
2069 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2072 progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2076 if (!Stream_SafeSeek(s, WINPR_ASSERTING_INT_CAST(
size_t, rc)))
2082static inline SSIZE_T progressive_wb_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2083 wStream* WINPR_RESTRICT s, UINT16 blockType,
2086 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2091 UINT16 boxRight = 0;
2092 UINT16 boxBottom = 0;
2095 UINT16 idxRight = 0;
2096 UINT16 idxBottom = 0;
2099 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
2101 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
2102 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2104 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2106 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION after RFX_PROGRESSIVE_FRAME_END, ignoring");
2107 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2110 progressive->state |= FLAG_WBT_REGION;
2112 rc = progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2116 for (UINT16 index = 0; index < region->numRects; index++)
2118 RFX_RECT* rect = &(region->rects[index]);
2119 Stream_Read_UINT16(s, rect->x);
2120 Stream_Read_UINT16(s, rect->y);
2121 Stream_Read_UINT16(s, rect->width);
2122 Stream_Read_UINT16(s, rect->height);
2125 for (BYTE index = 0; index < region->numQuant; index++)
2128 progressive_component_codec_quant_read(s, quantVal);
2130 if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
2132 WLog_Print(progressive->log, WLOG_ERROR,
2133 "ProgressiveRegion region->cQuant[%" PRIu32
"] < 6", index);
2137 if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
2139 WLog_Print(progressive->log, WLOG_ERROR,
2140 "ProgressiveRegion region->cQuant[%" PRIu32
"] > 15", index);
2145 for (BYTE index = 0; index < region->numProgQuant; index++)
2149 Stream_Read_UINT8(s, quantProgVal->quality);
2151 progressive_component_codec_quant_read(s, &(quantProgVal->yQuantValues));
2152 progressive_component_codec_quant_read(s, &(quantProgVal->cbQuantValues));
2153 progressive_component_codec_quant_read(s, &(quantProgVal->crQuantValues));
2156#if defined(WITH_DEBUG_CODECS)
2157 WLog_Print(progressive->log, WLOG_DEBUG,
2158 "ProgressiveRegion: numRects: %" PRIu16
" numTiles: %" PRIu16
2159 " tileDataSize: %" PRIu32
" flags: 0x%02" PRIX8
" numQuant: %" PRIu8
2160 " numProgQuant: %" PRIu8
"",
2161 region->numRects, region->numTiles, region->tileDataSize, region->flags,
2162 region->numQuant, region->numProgQuant);
2165 boxLeft = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridWidth);
2166 boxTop = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridHeight);
2170 for (UINT16 index = 0; index < region->numRects; index++)
2172 RFX_RECT* rect = &(region->rects[index]);
2173 idxLeft = rect->x / 64;
2174 idxTop = rect->y / 64;
2175 idxRight = (rect->x + rect->width + 63) / 64;
2176 idxBottom = (rect->y + rect->height + 63) / 64;
2178 if (idxLeft < boxLeft)
2181 if (idxTop < boxTop)
2184 if (idxRight > boxRight)
2185 boxRight = idxRight;
2187 if (idxBottom > boxBottom)
2188 boxBottom = idxBottom;
2190#if defined(WITH_DEBUG_CODECS)
2191 WLog_Print(progressive->log, WLOG_DEBUG,
2192 "rect[%" PRIu16
"]: x: %" PRIu16
" y: %" PRIu16
" w: %" PRIu16
" h: %" PRIu16
"",
2193 index, rect->x, rect->y, rect->width, rect->height);
2197 const SSIZE_T res = progressive_process_tiles(progressive, s, region, surface, context);
2203static inline SSIZE_T progressive_parse_block(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2206 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2208 UINT16 blockType = 0;
2209 UINT32 blockLen = 0;
2211 wStream sub = WINPR_C_ARRAY_INIT;
2213 WINPR_ASSERT(progressive);
2215 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
2218 Stream_Read_UINT16(s, blockType);
2219 Stream_Read_UINT32(s, blockLen);
2223 WLog_WARN(TAG,
"Invalid blockLen %" PRIu32
", expected >= 6", blockLen);
2226 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
2228 Stream_StaticConstInit(&sub, Stream_Pointer(s), blockLen - 6);
2229 Stream_Seek(s, blockLen - 6);
2233 case PROGRESSIVE_WBT_SYNC:
2234 rc = progressive_wb_sync(progressive, &sub, blockType, blockLen);
2237 case PROGRESSIVE_WBT_FRAME_BEGIN:
2238 rc = progressive_wb_frame_begin(progressive, &sub, blockType, blockLen);
2241 case PROGRESSIVE_WBT_FRAME_END:
2242 rc = progressive_wb_frame_end(progressive, &sub, blockType, blockLen);
2245 case PROGRESSIVE_WBT_CONTEXT:
2246 rc = progressive_wb_context(progressive, &sub, blockType, blockLen);
2249 case PROGRESSIVE_WBT_REGION:
2250 rc = progressive_wb_region(progressive, &sub, blockType, blockLen, surface, region);
2254 WLog_Print(progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16, blockType);
2261 if (Stream_GetRemainingLength(&sub) > 0)
2263 WLog_Print(progressive->log, WLOG_ERROR,
2264 "block len %" PRIu32
" does not match read data %" PRIuz, blockLen,
2265 blockLen - Stream_GetRemainingLength(&sub));
2272static inline BOOL update_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2274 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2275 UINT32 nXDst, UINT32 nYDst,
2276 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
2277 REGION16* WINPR_RESTRICT invalidRegion)
2280 REGION16 clippingRects = WINPR_C_ARRAY_INIT;
2281 region16_init(&clippingRects);
2283 for (UINT32 i = 0; i < region->numRects; i++)
2286 const RFX_RECT* rect = &(region->rects[i]);
2288 clippingRect.left = (UINT16)nXDst + rect->x;
2289 clippingRect.top = (UINT16)nYDst + rect->y;
2290 clippingRect.right = clippingRect.left + rect->width;
2291 clippingRect.bottom = clippingRect.top + rect->height;
2292 if (!region16_union_rect(&clippingRects, &clippingRects, &clippingRect))
2294 region16_uninit(&clippingRects);
2299 for (UINT32 i = 0; i < surface->numUpdatedTiles; i++)
2301 UINT32 nbUpdateRects = 0;
2305 WINPR_ASSERT(surface->updatedTileIndices);
2306 const UINT32 index = surface->updatedTileIndices[i];
2308 WINPR_ASSERT(index < surface->tilesSize);
2312 const UINT32 dl = nXDst + tile->x;
2313 updateRect.left = WINPR_ASSERTING_INT_CAST(UINT16, dl);
2315 const UINT32 dt = nYDst + tile->y;
2316 updateRect.top = WINPR_ASSERTING_INT_CAST(UINT16, dt);
2317 updateRect.right = updateRect.left + 64;
2318 updateRect.bottom = updateRect.top + 64;
2320 REGION16 updateRegion = WINPR_C_ARRAY_INIT;
2321 region16_init(&updateRegion);
2322 if (!region16_intersect_rect(&updateRegion, &clippingRects, &updateRect))
2324 region16_uninit(&updateRegion);
2327 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
2329 for (UINT32 j = 0; j < nbUpdateRects; j++)
2333 if (rect->left < updateRect.left)
2335 const UINT32 nXSrc = rect->left - updateRect.left;
2336 const UINT32 nYSrc = rect->top - updateRect.top;
2337 const UINT32 width = rect->right - rect->left;
2338 const UINT32 height = rect->bottom - rect->top;
2340 if (rect->left + width > surface->width)
2342 if (rect->top + height > surface->height)
2344 rc = freerdp_image_copy_no_overlap(
2345 pDstData, DstFormat, nDstStep, rect->left, rect->top, width, height, tile->data,
2346 progressive->format, tile->stride, nXSrc, nYSrc,
nullptr, FREERDP_KEEP_DST_ALPHA);
2352 if (!region16_union_rect(invalidRegion, invalidRegion, rect))
2354 region16_uninit(&updateRegion);
2360 region16_uninit(&updateRegion);
2363 tile->dirty = FALSE;
2367 region16_uninit(&clippingRects);
2371INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2372 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
2373 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2374 UINT32 nXDst, UINT32 nYDst,
REGION16* WINPR_RESTRICT invalidRegion,
2375 UINT16 surfaceId, UINT32 frameId)
2379 WINPR_ASSERT(progressive);
2384 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion no surface for %" PRIu16,
2389 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2390 WINPR_ASSERT(region);
2392 if (surface->frameId != frameId)
2394 surface->frameId = frameId;
2395 surface->numUpdatedTiles = 0;
2398 wStream ss = WINPR_C_ARRAY_INIT;
2399 wStream* s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
2404 case PIXEL_FORMAT_RGBA32:
2405 case PIXEL_FORMAT_RGBX32:
2406 case PIXEL_FORMAT_BGRA32:
2407 case PIXEL_FORMAT_BGRX32:
2408 progressive->format = DstFormat;
2411 progressive->format = PIXEL_FORMAT_XRGB32;
2415 const size_t start = Stream_GetPosition(s);
2416 progressive->state = 0;
2417 while (Stream_GetRemainingLength(s) > 0)
2419 if (progressive_parse_block(progressive, s, surface, region) < 0)
2424 const size_t end = Stream_GetPosition(s);
2425 if ((end - start) != SrcSize)
2427 WLog_Print(progressive->log, WLOG_ERROR,
2428 "total block len %" PRIuz
" does not match read data %" PRIu32, end - start,
2435 if (!update_tiles(progressive, surface, pDstData, DstFormat, nDstStep, nXDst, nYDst, region,
2442BOOL progressive_rfx_write_message_progressive_simple(
2443 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s,
2444 const RFX_MESSAGE* WINPR_RESTRICT msg)
2446 RFX_CONTEXT* context =
nullptr;
2448 WINPR_ASSERT(progressive);
2451 context = progressive->rfx_context;
2452 return rfx_write_message_progressive_simple(context, s, msg);
2455int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2456 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 SrcFormat,
2457 UINT32 Width, UINT32 Height, UINT32 ScanLine,
2458 const REGION16* WINPR_RESTRICT invalidRegion,
2459 BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize)
2464 UINT32 numRects = 0;
2466 RFX_MESSAGE* message =
nullptr;
2468 if (!progressive || !pSrcData || !ppDstData || !pDstSize)
2477 case PIXEL_FORMAT_ABGR32:
2478 case PIXEL_FORMAT_ARGB32:
2479 case PIXEL_FORMAT_XBGR32:
2480 case PIXEL_FORMAT_XRGB32:
2481 case PIXEL_FORMAT_BGRA32:
2482 case PIXEL_FORMAT_BGRX32:
2483 case PIXEL_FORMAT_RGBA32:
2484 case PIXEL_FORMAT_RGBX32:
2485 ScanLine = Width * 4;
2492 if (SrcSize < Height * ScanLine)
2497 numRects = (Width + 63) / 64;
2498 numRects *= (Height + 63) / 64;
2502 const int nr = region16_n_rects(invalidRegion);
2503 numRects = WINPR_ASSERTING_INT_CAST(uint32_t, nr);
2509 if (!Stream_EnsureRemainingCapacity(progressive->rects, numRects *
sizeof(
RFX_RECT)))
2511 rects = Stream_BufferAs(progressive->rects,
RFX_RECT);
2514 const RECTANGLE_16* region_rects = region16_rects(invalidRegion,
nullptr);
2515 for (UINT32 idx = 0; idx < numRects; idx++)
2522 rect->width = r->right - r->left;
2523 rect->height = r->bottom - r->top;
2531 for (UINT32 i = 0; i < numRects; i++)
2537 WINPR_ASSERT(Width >= x);
2538 WINPR_ASSERT(Height >= y);
2539 r->width = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Width - x));
2540 r->height = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Height - y));
2542 if (x + 64UL >= Width)
2550 WINPR_ASSERT(r->x % 64 == 0);
2551 WINPR_ASSERT(r->y % 64 == 0);
2552 WINPR_ASSERT(r->width <= 64);
2553 WINPR_ASSERT(r->height <= 64);
2556 s = progressive->buffer;
2557 Stream_SetPosition(s, 0);
2559 progressive->rfx_context->mode = RLGR1;
2561 progressive->rfx_context->width = WINPR_ASSERTING_INT_CAST(UINT16, Width);
2562 progressive->rfx_context->height = WINPR_ASSERTING_INT_CAST(UINT16, Height);
2563 rfx_context_set_pixel_format(progressive->rfx_context, SrcFormat);
2564 message = rfx_encode_message(progressive->rfx_context, rects, numRects, pSrcData, Width, Height,
2568 WLog_ERR(TAG,
"failed to encode rfx message");
2572 rc = progressive_rfx_write_message_progressive_simple(progressive, s, message);
2573 rfx_message_free(progressive->rfx_context, message);
2578 const size_t pos = Stream_GetPosition(s);
2579 WINPR_ASSERT(pos <= UINT32_MAX);
2580 *pDstSize = (UINT32)pos;
2582 *ppDstData = Stream_Buffer(s);
2588BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive)
2590 return (progressive !=
nullptr);
2593PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
2595 return progressive_context_new_ex(Compressor, 0);
2598PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, UINT32 ThreadingFlags)
2600 PROGRESSIVE_CONTEXT* progressive =
2601 (PROGRESSIVE_CONTEXT*)winpr_aligned_calloc(1,
sizeof(PROGRESSIVE_CONTEXT), 32);
2606 progressive->Compressor = Compressor;
2607 progressive->quantProgValFull.quality = 100;
2608 progressive->log = WLog_Get(TAG);
2609 if (!progressive->log)
2611 progressive->rfx_context = rfx_context_new_ex(Compressor, ThreadingFlags);
2612 if (!progressive->rfx_context)
2614 progressive->buffer = Stream_New(
nullptr, 1024);
2615 if (!progressive->buffer)
2617 progressive->rects = Stream_New(
nullptr, 1024);
2618 if (!progressive->rects)
2620 progressive->bufferPool = BufferPool_New(TRUE, (8192LL + 32LL) * 3LL, 16);
2621 if (!progressive->bufferPool)
2623 progressive->SurfaceContexts = HashTable_New(TRUE);
2624 if (!progressive->SurfaceContexts)
2628 wObject* obj = HashTable_ValueObject(progressive->SurfaceContexts);
2634 WINPR_PRAGMA_DIAG_PUSH
2635 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2636 progressive_context_free(progressive);
2637 WINPR_PRAGMA_DIAG_POP
2641void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
2646 Stream_Free(progressive->buffer, TRUE);
2647 Stream_Free(progressive->rects, TRUE);
2648 rfx_context_free(progressive->rfx_context);
2650 BufferPool_Free(progressive->bufferPool);
2651 HashTable_Free(progressive->SurfaceContexts);
2653 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