22#include <freerdp/config.h>
24#include <winpr/assert.h>
25#include <winpr/cast.h>
27#include <winpr/print.h>
28#include <winpr/bitstream.h>
30#include <freerdp/primitives.h>
31#include <freerdp/codec/color.h>
32#include <freerdp/codec/progressive.h>
33#include <freerdp/codec/region.h>
34#include <freerdp/log.h>
36#include "rfx_differential.h"
37#include "rfx_quantization.h"
40#include "rfx_constants.h"
42#include "progressive.h"
44#define TAG FREERDP_TAG("codec.progressive")
57} RFX_PROGRESSIVE_UPGRADE_STATE;
60progressive_component_codec_quant_read(
wStream* WINPR_RESTRICT s,
64 Stream_Read_UINT8(s, b);
65 quantVal->LL3 = b & 0x0F;
66 quantVal->HL3 = b >> 4;
67 Stream_Read_UINT8(s, b);
68 quantVal->LH3 = b & 0x0F;
69 quantVal->HH3 = b >> 4;
70 Stream_Read_UINT8(s, b);
71 quantVal->HL2 = b & 0x0F;
72 quantVal->LH2 = b >> 4;
73 Stream_Read_UINT8(s, b);
74 quantVal->HH2 = b & 0x0F;
75 quantVal->HL1 = b >> 4;
76 Stream_Read_UINT8(s, b);
77 quantVal->LH1 = b & 0x0F;
78 quantVal->HH1 = b >> 4;
85 dst->HL1 = q1->HL1 + q2->HL1;
86 dst->LH1 = q1->LH1 + q2->LH1;
87 dst->HH1 = q1->HH1 + q2->HH1;
88 dst->HL2 = q1->HL2 + q2->HL2;
89 dst->LH2 = q1->LH2 + q2->LH2;
90 dst->HH2 = q1->HH2 + q2->HH2;
91 dst->HL3 = q1->HL3 + q2->HL3;
92 dst->LH3 = q1->LH3 + q2->LH3;
93 dst->HH3 = q1->HH3 + q2->HH3;
94 dst->LL3 = q1->LL3 + q2->LL3;
147 if (q1->HL1 < q2->HL1)
149 dst->HL1 = q1->HL1 - q2->HL1;
151 if (q1->LH1 < q2->LH1)
153 dst->LH1 = q1->LH1 - q2->LH1;
155 if (q1->HH1 < q2->HH1)
157 dst->HH1 = q1->HH1 - q2->HH1;
159 if (q1->HL2 < q2->HL2)
161 dst->HL2 = q1->HL2 - q2->HL2;
163 if (q1->LH2 < q2->LH2)
165 dst->LH2 = q1->LH2 - q2->LH2;
167 if (q1->HH2 < q2->HH2)
169 dst->HH2 = q1->HH2 - q2->HH2;
171 if (q1->HL3 < q2->HL3)
173 dst->HL3 = q1->HL3 - q2->HL3;
175 if (q1->LH3 < q2->LH3)
177 dst->LH3 = q1->LH3 - q2->LH3;
179 if (q1->HH3 < q2->HH3)
181 dst->HH3 = q1->HH3 - q2->HH3;
183 if (q1->LL3 < q2->LL3)
185 dst->LL3 = q1->LL3 - q2->LL3;
266 if (q1->HL1 != q2->HL1)
269 if (q1->LH1 != q2->LH1)
272 if (q1->HH1 != q2->HH1)
275 if (q1->HL2 != q2->HL2)
278 if (q1->LH2 != q2->LH2)
281 if (q1->HH2 != q2->HH2)
284 if (q1->HL3 != q2->HL3)
287 if (q1->LH3 != q2->LH3)
290 if (q1->HH3 != q2->HH3)
293 if (q1->LL3 != q2->LL3)
299static inline BOOL progressive_set_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
304 key = ((ULONG_PTR)surfaceId) + 1;
307 return HashTable_Insert(progressive->SurfaceContexts, (
void*)key, pData);
309 HashTable_Remove(progressive->SurfaceContexts, (
void*)key);
314progressive_get_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, UINT16 surfaceId)
316 void* key = (
void*)(((ULONG_PTR)surfaceId) + 1);
321 return HashTable_GetItemValue(progressive->SurfaceContexts, key);
328 winpr_aligned_free(tile->sign);
329 winpr_aligned_free(tile->current);
330 winpr_aligned_free(tile->data);
331 winpr_aligned_free(tile);
335static void progressive_surface_context_free(
void* ptr)
344 for (
size_t index = 0; index < surface->tilesSize; index++)
347 progressive_tile_free(tile);
351 winpr_aligned_free((
void*)surface->tiles);
352 winpr_aligned_free(surface->updatedTileIndices);
353 winpr_aligned_free(surface);
364 tile->stride = 4 * tile->width;
367 const size_t dataLen = 1ull * tile->stride * tile->height;
368 tile->data = (BYTE*)winpr_aligned_malloc(dataLen, 16);
371 memset(tile->data, 0xFF, dataLen);
375 const size_t signLen = (8192ULL + 32ULL) * 3ULL;
376 tile->sign = (BYTE*)winpr_aligned_malloc(signLen, 16);
383 const size_t currentLen = (8192ULL + 32ULL) * 3ULL;
384 tile->current = (BYTE*)winpr_aligned_malloc(currentLen, 16);
392 progressive_tile_free(tile);
401 WINPR_ASSERT(surface);
402 WINPR_ASSERT(surface->gridSize > 0);
406 oldIndex = surface->gridSize;
407 while (surface->gridSize < min)
408 surface->gridSize += 1024;
411 void* tmp = winpr_aligned_recalloc((
void*)surface->tiles, surface->gridSize,
415 surface->tilesSize = surface->gridSize;
418 for (
size_t x = oldIndex; x < surface->tilesSize; x++)
420 surface->tiles[x] = progressive_tile_new();
421 if (!surface->tiles[x])
426 winpr_aligned_recalloc(surface->updatedTileIndices, surface->gridSize,
sizeof(UINT32), 32);
430 surface->updatedTileIndices = tmp;
444 surface->id = surfaceId;
445 surface->width = width;
446 surface->height = height;
447 surface->gridWidth = (width + (64 - width % 64)) / 64;
448 surface->gridHeight = (height + (64 - height % 64)) / 64;
449 surface->gridSize = surface->gridWidth * surface->gridHeight;
451 if (!progressive_allocate_tile_cache(surface, surface->gridSize))
453 progressive_surface_context_free(surface);
462 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
468 if (!surface || !tile)
471 zIdx = (tile->yIdx * surface->gridWidth) + tile->xIdx;
473 if (zIdx >= surface->tilesSize)
475 WLog_ERR(TAG,
"Invalid zIndex %" PRIuz, zIdx);
479 t = surface->tiles[zIdx];
481 t->blockType = tile->blockType;
482 t->blockLen = tile->blockLen;
483 t->quantIdxY = tile->quantIdxY;
484 t->quantIdxCb = tile->quantIdxCb;
485 t->quantIdxCr = tile->quantIdxCr;
486 t->xIdx = tile->xIdx;
487 t->yIdx = tile->yIdx;
488 t->flags = tile->flags;
489 t->quality = tile->quality;
490 t->x = tile->xIdx * t->width;
491 t->y = tile->yIdx * t->height;
495 t->ySrlLen = tile->ySrlLen;
496 t->yRawLen = tile->yRawLen;
497 t->cbSrlLen = tile->cbSrlLen;
498 t->cbRawLen = tile->cbRawLen;
499 t->crSrlLen = tile->crSrlLen;
500 t->crRawLen = tile->crRawLen;
501 t->ySrlData = tile->ySrlData;
502 t->yRawData = tile->yRawData;
503 t->cbSrlData = tile->cbSrlData;
504 t->cbRawData = tile->cbRawData;
505 t->crSrlData = tile->crSrlData;
506 t->crRawData = tile->crRawData;
510 t->yLen = tile->yLen;
511 t->cbLen = tile->cbLen;
512 t->crLen = tile->crLen;
513 t->tailLen = tile->tailLen;
514 t->yData = tile->yData;
515 t->cbData = tile->cbData;
516 t->crData = tile->crData;
517 t->tailData = tile->tailData;
520 if (region->usedTiles >= region->numTiles)
522 WLog_ERR(TAG,
"Invalid tile count, only expected %" PRIu16
", got %" PRIu16,
523 region->numTiles, region->usedTiles);
527 region->tiles[region->usedTiles++] = t;
530 if (surface->numUpdatedTiles >= surface->gridSize)
532 if (!progressive_allocate_tile_cache(surface, surface->numUpdatedTiles + 1))
536 surface->updatedTileIndices[surface->numUpdatedTiles++] = (UINT32)zIdx;
543INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
544 UINT16 surfaceId, UINT32 width, UINT32 height)
550 surface = progressive_surface_context_new(surfaceId, width, height);
555 if (!progressive_set_surface_data(progressive, surfaceId, (
void*)surface))
557 progressive_surface_context_free(surface);
565int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
568 progressive_set_surface_data(progressive, surfaceId,
nullptr);
591static int16_t clampi16(
int val)
600static inline void progressive_rfx_idwt_x(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
601 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
602 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
603 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
608 for (
size_t i = 0; i < nDstCount; i++)
610 const INT16* pL = pLowBand;
611 const INT16* pH = pHighBand;
612 INT16* pX = pDstBand;
615 INT16 X0 = clampi16((int32_t)L0 - H0);
616 INT16 X2 = clampi16((int32_t)L0 - H0);
618 for (
size_t j = 0; j < (nHighCount - 1); j++)
624 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
625 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
633 if (nLowCount <= (nHighCount + 1))
635 if (nLowCount <= nHighCount)
638 pX[1] = clampi16((int32_t)X2 + (2 * H0));
644 X0 = clampi16((int32_t)L0 - H0);
646 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
654 X0 = clampi16((int32_t)L0 - (H0 / 2));
656 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
660 pX[3] = clampi16((int32_t)(X0 + L0) / 2);
663 pLowBand += nLowStep;
664 pHighBand += nHighStep;
665 pDstBand += nDstStep;
669static inline void progressive_rfx_idwt_y(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
670 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
671 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
672 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
674 for (
size_t i = 0; i < nDstCount; i++)
678 const INT16* pL = pLowBand;
679 const INT16* pH = pHighBand;
680 INT16* pX = pDstBand;
685 int16_t X0 = clampi16((int32_t)L0 - H0);
686 int16_t X2 = clampi16((int32_t)L0 - H0);
688 for (
size_t j = 0; j < (nHighCount - 1); j++)
694 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
695 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
704 if (nLowCount <= (nHighCount + 1))
706 if (nLowCount <= nHighCount)
710 *pX = clampi16((int32_t)X2 + (2 * H0));
715 X0 = clampi16((int32_t)L0 - H0);
718 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
727 X0 = clampi16((int32_t)L0 - (H0 / 2));
730 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
735 *pX = clampi16((int32_t)(X0 + L0) / 2);
744static inline size_t progressive_rfx_get_band_l_count(
size_t level)
746 return (64 >> level) + 1;
749static inline size_t progressive_rfx_get_band_h_count(
size_t level)
752 return (64 >> 1) - 1;
754 return (64 + (1u << (level - 1))) >> level;
757static inline void progressive_rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer,
758 INT16* WINPR_RESTRICT temp,
size_t level)
760 size_t nDstStepX = 0;
761 size_t nDstStepY = 0;
762 const INT16* WINPR_RESTRICT HL =
nullptr;
763 const INT16* WINPR_RESTRICT LH =
nullptr;
764 const INT16* WINPR_RESTRICT HH =
nullptr;
765 INT16* WINPR_RESTRICT LL =
nullptr;
766 INT16* WINPR_RESTRICT L =
nullptr;
767 INT16* WINPR_RESTRICT H =
nullptr;
768 INT16* WINPR_RESTRICT LLx =
nullptr;
770 const size_t nBandL = progressive_rfx_get_band_l_count(level);
771 const size_t nBandH = progressive_rfx_get_band_h_count(level);
774 HL = &buffer[offset];
775 offset += (nBandH * nBandL);
776 LH = &buffer[offset];
777 offset += (nBandL * nBandH);
778 HH = &buffer[offset];
779 offset += (nBandH * nBandH);
780 LL = &buffer[offset];
781 nDstStepX = (nBandL + nBandH);
782 nDstStepY = (nBandL + nBandH);
785 offset += (nBandL * nDstStepX);
790 progressive_rfx_idwt_x(LL, nBandL, HL, nBandH, L, nDstStepX, nBandL, nBandH, nBandL);
793 progressive_rfx_idwt_x(LH, nBandL, HH, nBandH, H, nDstStepX, nBandL, nBandH, nBandH);
796 progressive_rfx_idwt_y(L, nDstStepX, H, nDstStepX, LLx, nDstStepY, nBandL, nBandH,
800void rfx_dwt_2d_extrapolate_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
802 WINPR_ASSERT(buffer);
803 WINPR_ASSERT(dwt_buffer);
804 progressive_rfx_dwt_2d_decode_block(&buffer[3807], dwt_buffer, 3);
805 progressive_rfx_dwt_2d_decode_block(&buffer[3007], dwt_buffer, 2);
806 progressive_rfx_dwt_2d_decode_block(&buffer[0], dwt_buffer, 1);
809static inline int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
810 INT16* WINPR_RESTRICT buffer,
811 INT16* WINPR_RESTRICT current, BOOL coeffDiff,
812 BOOL extrapolate, BOOL reverse)
816 if (!progressive || !buffer || !current)
819 const uint32_t belements = 4096;
820 const uint32_t bsize = belements *
sizeof(INT16);
822 memcpy(buffer, current, bsize);
824 memcpy(current, buffer, bsize);
827 const pstatus_t rc = prims->
add_16s_inplace(buffer, current, belements);
828 if (rc != PRIMITIVES_SUCCESS)
832 INT16* temp = (INT16*)BufferPool_Take(progressive->bufferPool, -1);
839 progressive->rfx_context->dwt_2d_decode(buffer, temp);
843 WINPR_ASSERT(progressive->rfx_context->dwt_2d_extrapolate_decode);
844 progressive->rfx_context->dwt_2d_extrapolate_decode(buffer, temp);
846 BufferPool_Return(progressive->bufferPool, temp);
850static inline BOOL progressive_rfx_decode_block(
const primitives_t* prims,
851 INT16* WINPR_RESTRICT buffer, UINT32 length,
861progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
863 const BYTE* WINPR_RESTRICT data, UINT32 length,
864 INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
865 INT16* WINPR_RESTRICT sign, BOOL coeffDiff,
866 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
871 status = progressive->rfx_context->rlgr_decode(RLGR1, data, length, buffer, 4096);
876 CopyMemory(sign, buffer, 4096ULL * 2ULL);
879 rfx_differential_decode(buffer + 4032, 64);
880 if (!progressive_rfx_decode_block(prims, &buffer[0], 1024, shift->HL1))
882 if (!progressive_rfx_decode_block(prims, &buffer[1024], 1024, shift->LH1))
884 if (!progressive_rfx_decode_block(prims, &buffer[2048], 1024, shift->HH1))
886 if (!progressive_rfx_decode_block(prims, &buffer[3072], 256, shift->HL2))
888 if (!progressive_rfx_decode_block(prims, &buffer[3328], 256, shift->LH2))
890 if (!progressive_rfx_decode_block(prims, &buffer[3584], 256, shift->HH2))
892 if (!progressive_rfx_decode_block(prims, &buffer[3840], 64, shift->HL3))
894 if (!progressive_rfx_decode_block(prims, &buffer[3904], 64, shift->LH3))
896 if (!progressive_rfx_decode_block(prims, &buffer[3968], 64, shift->HH3))
898 if (!progressive_rfx_decode_block(prims, &buffer[4032], 64, shift->LL3))
903 if (!progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1))
905 if (!progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1))
907 if (!progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1))
909 if (!progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2))
911 if (!progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2))
913 if (!progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2))
915 if (!progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3))
917 if (!progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3))
919 if (!progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3))
921 rfx_differential_decode(&buffer[4015], 81);
922 if (!progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3))
925 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
930progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
932 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
938 BOOL extrapolate = 0;
939 BYTE* pBuffer =
nullptr;
957 diff = tile->flags & RFX_TILE_DIFFERENCE;
958 sub = context->flags & RFX_SUBBAND_DIFFING;
959 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
961#if defined(WITH_DEBUG_CODECS)
962 WLog_Print(progressive->log, WLOG_DEBUG,
963 "ProgressiveTile%s: quantIdx Y: %" PRIu8
" Cb: %" PRIu8
" Cr: %" PRIu8
964 " xIdx: %" PRIu16
" yIdx: %" PRIu16
" flags: 0x%02" PRIX8
" quality: %" PRIu8
965 " yLen: %" PRIu16
" cbLen: %" PRIu16
" crLen: %" PRIu16
" tailLen: %" PRIu16
"",
966 (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ?
"First" :
"Simple",
967 tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx,
968 tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
971 if (tile->quantIdxY >= region->numQuant)
973 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
977 quantY = &(region->quantVals[tile->quantIdxY]);
979 if (tile->quantIdxCb >= region->numQuant)
981 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
986 quantCb = &(region->quantVals[tile->quantIdxCb]);
988 if (tile->quantIdxCr >= region->numQuant)
990 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
995 quantCr = &(region->quantVals[tile->quantIdxCr]);
997 if (tile->quality == 0xFF)
999 quantProgVal = &(progressive->quantProgValFull);
1003 if (tile->quality >= region->numProgQuant)
1005 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1006 region->numProgQuant);
1010 quantProgVal = &(region->quantProgVals[tile->quality]);
1013 quantProgY = &(quantProgVal->yQuantValues);
1014 quantProgCb = &(quantProgVal->cbQuantValues);
1015 quantProgCr = &(quantProgVal->crQuantValues);
1017 tile->yQuant = *quantY;
1018 tile->cbQuant = *quantCb;
1019 tile->crQuant = *quantCr;
1020 tile->yProgQuant = *quantProgY;
1021 tile->cbProgQuant = *quantProgCb;
1022 tile->crProgQuant = *quantProgCr;
1024 progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
1025 progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
1026 progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
1027 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1028 if (!progressive_rfx_quant_lsub(&shiftY, 1))
1030 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1031 if (!progressive_rfx_quant_lsub(&shiftCb, 1))
1033 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1034 if (!progressive_rfx_quant_lsub(&shiftCr, 1))
1038 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 0) + 16]));
1040 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 1) + 16]));
1042 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 2) + 16]));
1045 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 0) + 16]));
1047 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 1) + 16]));
1049 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 2) + 16]));
1051 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1053 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 0) + 16]));
1055 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 1) + 16]));
1057 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 2) + 16]));
1059 rc = progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0],
1060 pCurrent[0], pSign[0], diff, sub, extrapolate);
1063 rc = progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen,
1064 pSrcDst[1], pCurrent[1], pSign[1], diff, sub,
1068 rc = progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen,
1069 pSrcDst[2], pCurrent[2], pSign[2], diff, sub,
1075 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1076 rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1077 progressive->format, &roi_64x64);
1080 BufferPool_Return(progressive->bufferPool, pBuffer);
1084static inline INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1087 WINPR_ASSERT(state);
1098 const UINT32 k = state->kp / 8;
1103 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1104 BitStream_Shift(bs, 1);
1109 state->nz = (1 << k);
1126 bs->mask = ((1u << k) - 1);
1128 WINPR_ASSERTING_INT_CAST(int16_t, ((bs->accumulator >> (32u - k)) & bs->mask));
1129 BitStream_Shift(bs, k);
1143 const UINT32 sign = (bs->accumulator & 0x80000000) ? 1 : 0;
1144 BitStream_Shift(bs, 1);
1152 return sign ? -1 : 1;
1155 const UINT32 max = (1u << numBits) - 1;
1159 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1160 BitStream_Shift(bs, 1);
1168 if (mag > INT16_MAX)
1170 return (INT16)(sign ? -1 * (int)mag : (INT16)mag);
1174progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state)
1185 pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
1188 BitStream_Shift(raw, pad);
1190 pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
1193 BitStream_Shift(srl, pad);
1195 if (BitStream_GetRemainingLength(srl) == 8)
1196 BitStream_Shift(srl, 8);
1201static inline int16_t rawShift(
wBitStream* raw, UINT32 numBits)
1204 WINPR_ASSERT(numBits > 0);
1206 raw->mask = ((1u << numBits) - 1);
1207 const int16_t input = (int16_t)((raw->accumulator >> (32 - numBits)) & raw->mask);
1208 BitStream_Shift(raw, numBits);
1212static inline int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1213 INT16* WINPR_RESTRICT buffer,
1214 INT16* WINPR_RESTRICT sign, UINT32 length,
1215 UINT32 shift, WINPR_ATTR_UNUSED UINT32 bitPos,
1226 for (UINT32 index = 0; index < length; index++)
1228 input = rawShift(raw, numBits);
1230 const int32_t shifted = input << shift;
1231 const int32_t val = buffer[index] + shifted;
1232 const int16_t ival = WINPR_ASSERTING_INT_CAST(int16_t, val);
1233 buffer[index] = ival;
1239 for (UINT32 index = 0; index < length; index++)
1241 if (sign[index] > 0)
1244 input = rawShift(raw, numBits);
1246 else if (sign[index] < 0)
1249 input = rawShift(raw, numBits);
1255 input = progressive_rfx_srl_read(state, numBits);
1256 sign[index] = WINPR_ASSERTING_INT_CAST(int16_t, input);
1259 const int32_t val = input << shift;
1260 const int32_t ival = buffer[index] + val;
1261 buffer[index] = WINPR_ASSERTING_INT_CAST(INT16, ival);
1267static inline int progressive_rfx_upgrade_component(
1268 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1272 INT16* WINPR_RESTRICT current, INT16* WINPR_RESTRICT sign,
const BYTE* WINPR_RESTRICT srlData,
1273 UINT32 srlLen,
const BYTE* WINPR_RESTRICT rawData, UINT32 rawLen, BOOL coeffDiff,
1274 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
1279 RFX_PROGRESSIVE_UPGRADE_STATE state = WINPR_C_ARRAY_INIT;
1285 BitStream_Attach(state.srl, srlData, srlLen);
1286 BitStream_Fetch(state.srl);
1287 BitStream_Attach(state.raw, rawData, rawLen);
1288 BitStream_Fetch(state.raw);
1291 rc = progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1,
1295 rc = progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1,
1296 bitPos->LH1, numBits->LH1);
1299 rc = progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1,
1300 bitPos->HH1, numBits->HH1);
1303 rc = progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2,
1304 bitPos->HL2, numBits->HL2);
1307 rc = progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2,
1308 bitPos->LH2, numBits->LH2);
1311 rc = progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2,
1312 bitPos->HH2, numBits->HH2);
1315 rc = progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3,
1316 bitPos->HL3, numBits->HL3);
1319 rc = progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3,
1320 bitPos->LH3, numBits->LH3);
1323 rc = progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3,
1324 bitPos->HH3, numBits->HH3);
1328 state.nonLL = FALSE;
1329 rc = progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3,
1330 bitPos->LL3, numBits->LL3);
1333 rc = progressive_rfx_upgrade_state_finish(&state);
1336 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
1341progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1343 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1349 BOOL extrapolate = 0;
1350 BYTE* pBuffer =
nullptr;
1351 INT16* pSign[3] = WINPR_C_ARRAY_INIT;
1352 INT16* pSrcDst[3] = WINPR_C_ARRAY_INIT;
1353 INT16* pCurrent[3] = WINPR_C_ARRAY_INIT;
1373 coeffDiff = tile->flags & RFX_TILE_DIFFERENCE;
1374 sub = context->flags & RFX_SUBBAND_DIFFING;
1375 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
1379#if defined(WITH_DEBUG_CODECS)
1380 WLog_Print(progressive->log, WLOG_DEBUG,
1381 "ProgressiveTileUpgrade: pass: %" PRIu16
" quantIdx Y: %" PRIu8
" Cb: %" PRIu8
1382 " Cr: %" PRIu8
" xIdx: %" PRIu16
" yIdx: %" PRIu16
" quality: %" PRIu8
1383 " ySrlLen: %" PRIu16
" yRawLen: %" PRIu16
" cbSrlLen: %" PRIu16
" cbRawLen: %" PRIu16
1384 " crSrlLen: %" PRIu16
" crRawLen: %" PRIu16
"",
1385 tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx,
1386 tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen,
1387 tile->cbRawLen, tile->crSrlLen, tile->crRawLen);
1390 if (tile->quantIdxY >= region->numQuant)
1392 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
1396 quantY = &(region->quantVals[tile->quantIdxY]);
1398 if (tile->quantIdxCb >= region->numQuant)
1400 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
1405 quantCb = &(region->quantVals[tile->quantIdxCb]);
1407 if (tile->quantIdxCr >= region->numQuant)
1409 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1414 quantCr = &(region->quantVals[tile->quantIdxCr]);
1416 if (tile->quality == 0xFF)
1418 quantProg = &(progressive->quantProgValFull);
1422 if (tile->quality >= region->numProgQuant)
1424 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1425 region->numProgQuant);
1429 quantProg = &(region->quantProgVals[tile->quality]);
1432 quantProgY = &(quantProg->yQuantValues);
1433 quantProgCb = &(quantProg->cbQuantValues);
1434 quantProgCr = &(quantProg->crQuantValues);
1436 if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
1437 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantY has changed!");
1439 if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
1440 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCb has changed!");
1442 if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
1443 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCr has changed!");
1445 if (!(context->flags & RFX_SUBBAND_DIFFING))
1446 WLog_WARN(TAG,
"PROGRESSIVE_BLOCK_CONTEXT::flags & RFX_SUBBAND_DIFFING not set");
1448 progressive_rfx_quant_add(quantY, quantProgY, &yBitPos);
1449 progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos);
1450 progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos);
1451 if (!progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits))
1453 if (!progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits))
1455 if (!progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits))
1457 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1458 if (!progressive_rfx_quant_lsub(&shiftY, 1))
1460 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1461 if (!progressive_rfx_quant_lsub(&shiftCb, 1))
1463 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1464 if (!progressive_rfx_quant_lsub(&shiftCr, 1))
1467 tile->yBitPos = yBitPos;
1468 tile->cbBitPos = cbBitPos;
1469 tile->crBitPos = crBitPos;
1470 tile->yQuant = *quantY;
1471 tile->cbQuant = *quantCb;
1472 tile->crQuant = *quantCr;
1473 tile->yProgQuant = *quantProgY;
1474 tile->cbProgQuant = *quantProgCb;
1475 tile->crProgQuant = *quantProgCr;
1478 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 0) + 16]));
1480 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 1) + 16]));
1482 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 2) + 16]));
1485 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 0) + 16]));
1487 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 1) + 16]));
1489 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 2) + 16]));
1491 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1493 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 0) + 16]));
1495 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 1) + 16]));
1497 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 2) + 16]));
1499 status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
1500 pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData,
1501 tile->ySrlLen, tile->yRawData, tile->yRawLen,
1502 coeffDiff, sub, extrapolate);
1507 status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
1508 pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData,
1509 tile->cbSrlLen, tile->cbRawData, tile->cbRawLen,
1510 coeffDiff, sub, extrapolate);
1515 status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
1516 pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData,
1517 tile->crSrlLen, tile->crRawData, tile->crRawLen,
1518 coeffDiff, sub, extrapolate);
1524 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1525 status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1526 progressive->format, &roi_64x64);
1529 BufferPool_Return(progressive->bufferPool, pBuffer);
1533static inline BOOL progressive_tile_read_upgrade(
1534 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1536 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1540 const size_t expect = 20;
1542 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1545 tile.blockType = blockType;
1546 tile.blockLen = blockLen;
1549 Stream_Read_UINT8(s, tile.quantIdxY);
1550 Stream_Read_UINT8(s, tile.quantIdxCb);
1551 Stream_Read_UINT8(s, tile.quantIdxCr);
1552 Stream_Read_UINT16(s, tile.xIdx);
1553 Stream_Read_UINT16(s, tile.yIdx);
1554 Stream_Read_UINT8(s, tile.quality);
1555 Stream_Read_UINT16(s, tile.ySrlLen);
1556 Stream_Read_UINT16(s, tile.yRawLen);
1557 Stream_Read_UINT16(s, tile.cbSrlLen);
1558 Stream_Read_UINT16(s, tile.cbRawLen);
1559 Stream_Read_UINT16(s, tile.crSrlLen);
1560 Stream_Read_UINT16(s, tile.crRawLen);
1562 tile.ySrlData = Stream_Pointer(s);
1563 if (!Stream_SafeSeek(s, tile.ySrlLen))
1565 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.ySrlLen);
1569 tile.yRawData = Stream_Pointer(s);
1570 if (!Stream_SafeSeek(s, tile.yRawLen))
1572 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yRawLen);
1576 tile.cbSrlData = Stream_Pointer(s);
1577 if (!Stream_SafeSeek(s, tile.cbSrlLen))
1579 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1584 tile.cbRawData = Stream_Pointer(s);
1585 if (!Stream_SafeSeek(s, tile.cbRawLen))
1587 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1592 tile.crSrlData = Stream_Pointer(s);
1593 if (!Stream_SafeSeek(s, tile.crSrlLen))
1595 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1600 tile.crRawData = Stream_Pointer(s);
1601 if (!Stream_SafeSeek(s, tile.crRawLen))
1603 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1608 return progressive_surface_tile_replace(surface, region, &tile, TRUE);
1612progressive_tile_read(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, BOOL simple,
1613 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
1615 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1619 size_t expect = simple ? 16 : 17;
1621 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1624 tile.blockType = blockType;
1625 tile.blockLen = blockLen;
1627 Stream_Read_UINT8(s, tile.quantIdxY);
1628 Stream_Read_UINT8(s, tile.quantIdxCb);
1629 Stream_Read_UINT8(s, tile.quantIdxCr);
1630 Stream_Read_UINT16(s, tile.xIdx);
1631 Stream_Read_UINT16(s, tile.yIdx);
1632 Stream_Read_UINT8(s, tile.flags);
1635 Stream_Read_UINT8(s, tile.quality);
1637 tile.quality = 0xFF;
1638 Stream_Read_UINT16(s, tile.yLen);
1639 Stream_Read_UINT16(s, tile.cbLen);
1640 Stream_Read_UINT16(s, tile.crLen);
1641 Stream_Read_UINT16(s, tile.tailLen);
1643 tile.yData = Stream_Pointer(s);
1644 if (!Stream_SafeSeek(s, tile.yLen))
1646 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yLen);
1650 tile.cbData = Stream_Pointer(s);
1651 if (!Stream_SafeSeek(s, tile.cbLen))
1653 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.cbLen);
1657 tile.crData = Stream_Pointer(s);
1658 if (!Stream_SafeSeek(s, tile.crLen))
1660 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.crLen);
1664 tile.tailData = Stream_Pointer(s);
1665 if (!Stream_SafeSeek(s, tile.tailLen))
1667 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.tailLen);
1671 return progressive_surface_tile_replace(surface, region, &tile, FALSE);
1674static void CALLBACK progressive_process_tiles_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1675 void* context, PTP_WORK work)
1679 WINPR_UNUSED(instance);
1682 switch (param->tile->blockType)
1684 case PROGRESSIVE_WBT_TILE_SIMPLE:
1685 case PROGRESSIVE_WBT_TILE_FIRST:
1686 progressive_decompress_tile_first(param->progressive, param->tile, param->region,
1690 case PROGRESSIVE_WBT_TILE_UPGRADE:
1691 progressive_decompress_tile_upgrade(param->progressive, param->tile, param->region,
1695 WLog_Print(param->progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16
" (%s)",
1696 param->tile->blockType,
1697 rfx_get_progressive_block_type_string(param->tile->blockType));
1702static inline SSIZE_T
1703progressive_process_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1705 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1711 const size_t start = Stream_GetPosition(s);
1712 UINT16 blockType = 0;
1713 UINT32 blockLen = 0;
1715 UINT16 close_cnt = 0;
1717 WINPR_ASSERT(progressive);
1718 WINPR_ASSERT(region);
1720 if (!Stream_CheckAndLogRequiredLength(TAG, s, region->tileDataSize))
1723 while ((Stream_GetRemainingLength(s) >= 6) &&
1724 (region->tileDataSize > (Stream_GetPosition(s) - start)))
1726 const size_t pos = Stream_GetPosition(s);
1728 Stream_Read_UINT16(s, blockType);
1729 Stream_Read_UINT32(s, blockLen);
1731#if defined(WITH_DEBUG_CODECS)
1732 WLog_Print(progressive->log, WLOG_DEBUG,
"%s",
1733 rfx_get_progressive_block_type_string(blockType));
1738 WLog_Print(progressive->log, WLOG_ERROR,
"Expected >= %" PRIu32
" remaining %" PRIu32,
1742 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
1747 case PROGRESSIVE_WBT_TILE_SIMPLE:
1748 if (!progressive_tile_read(progressive, TRUE, s, blockType, blockLen, surface,
1753 case PROGRESSIVE_WBT_TILE_FIRST:
1754 if (!progressive_tile_read(progressive, FALSE, s, blockType, blockLen, surface,
1759 case PROGRESSIVE_WBT_TILE_UPGRADE:
1760 if (!progressive_tile_read_upgrade(progressive, s, blockType, blockLen, surface,
1765 WLog_ERR(TAG,
"Invalid block type %04" PRIx16
" (%s)", blockType,
1766 rfx_get_progressive_block_type_string(blockType));
1770 size_t rem = Stream_GetPosition(s);
1771 if ((rem - pos) != blockLen)
1773 WLog_Print(progressive->log, WLOG_ERROR,
1774 "Actual block read %" PRIuz
" but expected %" PRIu32, rem - pos, blockLen);
1780 end = Stream_GetPosition(s);
1781 if ((end - start) != region->tileDataSize)
1783 WLog_Print(progressive->log, WLOG_ERROR,
1784 "Actual total blocks read %" PRIuz
" but expected %" PRIu32, end - start,
1785 region->tileDataSize);
1789 if (count != region->numTiles)
1791 WLog_Print(progressive->log, WLOG_WARN,
1792 "numTiles inconsistency: actual: %" PRIu32
", expected: %" PRIu16
"\n", count,
1797 for (UINT32 idx = 0; idx < region->numTiles; idx++)
1801 param->progressive = progressive;
1802 param->region = region;
1803 param->context = context;
1806 if (progressive->rfx_context->priv->UseThreads)
1808 progressive->work_objects[idx] = CreateThreadpoolWork(
1809 progressive_process_tiles_tile_work_callback, (
void*)param,
nullptr);
1810 if (!progressive->work_objects[idx])
1812 WLog_Print(progressive->log, WLOG_ERROR,
1813 "Failed to create ThreadpoolWork for tile %" PRIu32, idx);
1818 SubmitThreadpoolWork(progressive->work_objects[idx]);
1820 close_cnt = WINPR_ASSERTING_INT_CAST(UINT16, idx + 1);
1824 progressive_process_tiles_tile_work_callback(
nullptr, param,
nullptr);
1829 WLog_Print(progressive->log, WLOG_ERROR,
"Failed to decompress %s at %" PRIu16,
1830 rfx_get_progressive_block_type_string(tile->blockType), idx);
1835 if (progressive->rfx_context->priv->UseThreads)
1837 for (UINT32 idx = 0; idx < close_cnt; idx++)
1839 WaitForThreadpoolWorkCallbacks(progressive->work_objects[idx], FALSE);
1840 CloseThreadpoolWork(progressive->work_objects[idx]);
1849 return (SSIZE_T)(end - start);
1852static inline SSIZE_T progressive_wb_sync(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1853 wStream* WINPR_RESTRICT s, UINT16 blockType,
1856 const UINT32 magic = 0xCACCACCA;
1857 const UINT16 version = 0x0100;
1860 sync.blockType = blockType;
1861 sync.blockLen = blockLen;
1863 if (sync.blockLen != 12)
1865 WLog_Print(progressive->log, WLOG_ERROR,
1866 "PROGRESSIVE_BLOCK_SYNC::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1867 sync.blockLen, 12u);
1871 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1874#if defined(WITH_DEBUG_CODECS)
1875 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveSync");
1878 Stream_Read_UINT32(s, sync.magic);
1879 Stream_Read_UINT16(s, sync.version);
1881 if (sync.magic != magic)
1883 WLog_Print(progressive->log, WLOG_ERROR,
1884 "PROGRESSIVE_BLOCK_SYNC::magic = 0x%08" PRIx32
" != 0x%08" PRIx32, sync.magic,
1889 if (sync.version != 0x0100)
1891 WLog_Print(progressive->log, WLOG_ERROR,
1892 "PROGRESSIVE_BLOCK_SYNC::version = 0x%04" PRIx16
" != 0x%04" PRIu16,
1893 sync.version, version);
1897 if ((progressive->state & FLAG_WBT_SYNC) != 0)
1898 WLog_WARN(TAG,
"Duplicate PROGRESSIVE_BLOCK_SYNC, ignoring");
1900 progressive->state |= FLAG_WBT_SYNC;
1904static inline SSIZE_T progressive_wb_frame_begin(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1905 wStream* WINPR_RESTRICT s, UINT16 blockType,
1910 frameBegin.blockType = blockType;
1911 frameBegin.blockLen = blockLen;
1913 if (frameBegin.blockLen != 12)
1915 WLog_Print(progressive->log, WLOG_ERROR,
1916 " RFX_PROGRESSIVE_FRAME_BEGIN::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1917 frameBegin.blockLen, 12u);
1921 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1924 Stream_Read_UINT32(s, frameBegin.frameIndex);
1925 Stream_Read_UINT16(s, frameBegin.regionCount);
1927#if defined(WITH_DEBUG_CODECS)
1928 WLog_Print(progressive->log, WLOG_DEBUG,
1929 "ProgressiveFrameBegin: frameIndex: %" PRIu32
" regionCount: %" PRIu16
"",
1930 frameBegin.frameIndex, frameBegin.regionCount);
1939 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1941 WLog_ERR(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_BEGIN in stream, this is not allowed!");
1945 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1947 WLog_ERR(TAG,
"RFX_PROGRESSIVE_FRAME_BEGIN after RFX_PROGRESSIVE_FRAME_END in stream, this "
1952 progressive->state |= FLAG_WBT_FRAME_BEGIN;
1956static inline SSIZE_T progressive_wb_frame_end(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1957 wStream* WINPR_RESTRICT s, UINT16 blockType,
1962 frameEnd.blockType = blockType;
1963 frameEnd.blockLen = blockLen;
1965 if (frameEnd.blockLen != 6)
1967 WLog_Print(progressive->log, WLOG_ERROR,
1968 " RFX_PROGRESSIVE_FRAME_END::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1969 frameEnd.blockLen, 6u);
1973 if (Stream_GetRemainingLength(s) != 0)
1975 WLog_Print(progressive->log, WLOG_ERROR,
1976 "ProgressiveFrameEnd short %" PRIuz
", expected %u",
1977 Stream_GetRemainingLength(s), 0U);
1981#if defined(WITH_DEBUG_CODECS)
1982 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveFrameEnd");
1985 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
1986 WLog_WARN(TAG,
"RFX_PROGRESSIVE_FRAME_END before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
1987 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1988 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_END, ignoring");
1990 progressive->state |= FLAG_WBT_FRAME_END;
1994static inline SSIZE_T progressive_wb_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1995 wStream* WINPR_RESTRICT s, UINT16 blockType,
1999 context->blockType = blockType;
2000 context->blockLen = blockLen;
2002 if (context->blockLen != 10)
2004 WLog_Print(progressive->log, WLOG_ERROR,
2005 "RFX_PROGRESSIVE_CONTEXT::blockLen = 0x%08" PRIx32
" != 0x%08x",
2006 context->blockLen, 10u);
2010 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2013 Stream_Read_UINT8(s, context->ctxId);
2014 Stream_Read_UINT16(s, context->tileSize);
2015 Stream_Read_UINT8(s, context->flags);
2017 if (context->ctxId != 0x00)
2018 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT::ctxId != 0x00: %" PRIu8, context->ctxId);
2020 if (context->tileSize != 64)
2022 WLog_ERR(TAG,
"RFX_PROGRESSIVE_CONTEXT::tileSize != 0x40: %" PRIu16, context->tileSize);
2026 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
2027 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_BEGIN");
2028 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2029 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_END");
2030 if ((progressive->state & FLAG_WBT_CONTEXT) != 0)
2031 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_CONTEXT received, ignoring.");
2033#if defined(WITH_DEBUG_CODECS)
2034 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveContext: flags: 0x%02" PRIX8
"",
2038 progressive->state |= FLAG_WBT_CONTEXT;
2042static inline SSIZE_T
2043progressive_wb_read_region_header(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2044 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
2045 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2047 region->usedTiles = 0;
2049 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2052 region->blockType = blockType;
2053 region->blockLen = blockLen;
2054 Stream_Read_UINT8(s, region->tileSize);
2055 Stream_Read_UINT16(s, region->numRects);
2056 Stream_Read_UINT8(s, region->numQuant);
2057 Stream_Read_UINT8(s, region->numProgQuant);
2058 Stream_Read_UINT8(s, region->flags);
2059 Stream_Read_UINT16(s, region->numTiles);
2060 Stream_Read_UINT32(s, region->tileDataSize);
2062 if (region->tileSize != 64)
2064 WLog_Print(progressive->log, WLOG_ERROR,
2065 "ProgressiveRegion tile size %" PRIu8
", expected %u", region->tileSize, 64U);
2069 if (region->numRects < 1)
2071 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion missing rect count %" PRIu16,
2076 if (region->numQuant > 7)
2078 WLog_Print(progressive->log, WLOG_ERROR,
2079 "ProgressiveRegion quant count too high %" PRIu8
", expected < %u",
2080 region->numQuant, 7U);
2084 const SSIZE_T rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, Stream_GetRemainingLength(s));
2085 const SSIZE_T expect = region->numRects * 8ll + region->numQuant * 5ll +
2086 region->numProgQuant * 16ll + region->tileDataSize;
2090 if (len / 8LL < region->numRects)
2092 WLog_Print(progressive->log, WLOG_ERROR,
2093 "ProgressiveRegion data short for region->rects");
2096 len -= region->numRects * 8LL;
2098 if (len / 5LL < region->numQuant)
2100 WLog_Print(progressive->log, WLOG_ERROR,
2101 "ProgressiveRegion data short for region->cQuant");
2104 len -= region->numQuant * 5LL;
2106 if (len / 16LL < region->numProgQuant)
2108 WLog_Print(progressive->log, WLOG_ERROR,
2109 "ProgressiveRegion data short for region->cProgQuant");
2112 len -= region->numProgQuant * 16LL;
2114 if (len < region->tileDataSize * 1ll)
2116 WLog_Print(progressive->log, WLOG_ERROR,
2117 "ProgressiveRegion data short for region->tiles");
2120 len -= region->tileDataSize;
2123 WLog_Print(progressive->log, WLOG_WARN,
2124 "Unused bytes detected, %" PRIdz
" bytes not processed", len);
2130static inline SSIZE_T progressive_wb_skip_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2131 wStream* WINPR_RESTRICT s, UINT16 blockType,
2134 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2137 progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2141 if (!Stream_SafeSeek(s, WINPR_ASSERTING_INT_CAST(
size_t, rc)))
2147static inline SSIZE_T progressive_wb_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2148 wStream* WINPR_RESTRICT s, UINT16 blockType,
2151 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2156 UINT16 boxRight = 0;
2157 UINT16 boxBottom = 0;
2160 UINT16 idxRight = 0;
2161 UINT16 idxBottom = 0;
2164 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
2166 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
2167 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2169 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2171 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION after RFX_PROGRESSIVE_FRAME_END, ignoring");
2172 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2175 progressive->state |= FLAG_WBT_REGION;
2177 rc = progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2181 for (UINT16 index = 0; index < region->numRects; index++)
2183 RFX_RECT* rect = &(region->rects[index]);
2184 Stream_Read_UINT16(s, rect->x);
2185 Stream_Read_UINT16(s, rect->y);
2186 Stream_Read_UINT16(s, rect->width);
2187 Stream_Read_UINT16(s, rect->height);
2190 for (BYTE index = 0; index < region->numQuant; index++)
2193 progressive_component_codec_quant_read(s, quantVal);
2195 if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
2197 WLog_Print(progressive->log, WLOG_ERROR,
2198 "ProgressiveRegion region->cQuant[%" PRIu32
"] < 6", index);
2202 if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
2204 WLog_Print(progressive->log, WLOG_ERROR,
2205 "ProgressiveRegion region->cQuant[%" PRIu32
"] > 15", index);
2210 for (BYTE index = 0; index < region->numProgQuant; index++)
2214 Stream_Read_UINT8(s, quantProgVal->quality);
2216 progressive_component_codec_quant_read(s, &(quantProgVal->yQuantValues));
2217 progressive_component_codec_quant_read(s, &(quantProgVal->cbQuantValues));
2218 progressive_component_codec_quant_read(s, &(quantProgVal->crQuantValues));
2221#if defined(WITH_DEBUG_CODECS)
2222 WLog_Print(progressive->log, WLOG_DEBUG,
2223 "ProgressiveRegion: numRects: %" PRIu16
" numTiles: %" PRIu16
2224 " tileDataSize: %" PRIu32
" flags: 0x%02" PRIX8
" numQuant: %" PRIu8
2225 " numProgQuant: %" PRIu8
"",
2226 region->numRects, region->numTiles, region->tileDataSize, region->flags,
2227 region->numQuant, region->numProgQuant);
2230 boxLeft = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridWidth);
2231 boxTop = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridHeight);
2235 for (UINT16 index = 0; index < region->numRects; index++)
2237 RFX_RECT* rect = &(region->rects[index]);
2238 idxLeft = rect->x / 64;
2239 idxTop = rect->y / 64;
2240 idxRight = (rect->x + rect->width + 63) / 64;
2241 idxBottom = (rect->y + rect->height + 63) / 64;
2243 if (idxLeft < boxLeft)
2246 if (idxTop < boxTop)
2249 if (idxRight > boxRight)
2250 boxRight = idxRight;
2252 if (idxBottom > boxBottom)
2253 boxBottom = idxBottom;
2255#if defined(WITH_DEBUG_CODECS)
2256 WLog_Print(progressive->log, WLOG_DEBUG,
2257 "rect[%" PRIu16
"]: x: %" PRIu16
" y: %" PRIu16
" w: %" PRIu16
" h: %" PRIu16
"",
2258 index, rect->x, rect->y, rect->width, rect->height);
2262 const SSIZE_T res = progressive_process_tiles(progressive, s, region, surface, context);
2268static inline SSIZE_T progressive_parse_block(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2271 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2273 UINT16 blockType = 0;
2274 UINT32 blockLen = 0;
2276 wStream sub = WINPR_C_ARRAY_INIT;
2278 WINPR_ASSERT(progressive);
2280 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
2283 Stream_Read_UINT16(s, blockType);
2284 Stream_Read_UINT32(s, blockLen);
2288 WLog_WARN(TAG,
"Invalid blockLen %" PRIu32
", expected >= 6", blockLen);
2291 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
2293 Stream_StaticConstInit(&sub, Stream_Pointer(s), blockLen - 6);
2294 Stream_Seek(s, blockLen - 6);
2298 case PROGRESSIVE_WBT_SYNC:
2299 rc = progressive_wb_sync(progressive, &sub, blockType, blockLen);
2302 case PROGRESSIVE_WBT_FRAME_BEGIN:
2303 rc = progressive_wb_frame_begin(progressive, &sub, blockType, blockLen);
2306 case PROGRESSIVE_WBT_FRAME_END:
2307 rc = progressive_wb_frame_end(progressive, &sub, blockType, blockLen);
2310 case PROGRESSIVE_WBT_CONTEXT:
2311 rc = progressive_wb_context(progressive, &sub, blockType, blockLen);
2314 case PROGRESSIVE_WBT_REGION:
2315 rc = progressive_wb_region(progressive, &sub, blockType, blockLen, surface, region);
2319 WLog_Print(progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16, blockType);
2326 if (Stream_GetRemainingLength(&sub) > 0)
2328 WLog_Print(progressive->log, WLOG_ERROR,
2329 "block len %" PRIu32
" does not match read data %" PRIuz, blockLen,
2330 blockLen - Stream_GetRemainingLength(&sub));
2337static inline BOOL update_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2339 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2340 UINT32 nXDst, UINT32 nYDst,
2341 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
2342 REGION16* WINPR_RESTRICT invalidRegion)
2345 REGION16 clippingRects = WINPR_C_ARRAY_INIT;
2346 region16_init(&clippingRects);
2348 for (UINT32 i = 0; i < region->numRects; i++)
2351 const RFX_RECT* rect = &(region->rects[i]);
2353 clippingRect.left = (UINT16)nXDst + rect->x;
2354 clippingRect.top = (UINT16)nYDst + rect->y;
2355 clippingRect.right = clippingRect.left + rect->width;
2356 clippingRect.bottom = clippingRect.top + rect->height;
2357 if (!region16_union_rect(&clippingRects, &clippingRects, &clippingRect))
2359 region16_uninit(&clippingRects);
2364 for (UINT32 i = 0; i < surface->numUpdatedTiles; i++)
2366 UINT32 nbUpdateRects = 0;
2370 WINPR_ASSERT(surface->updatedTileIndices);
2371 const UINT32 index = surface->updatedTileIndices[i];
2373 WINPR_ASSERT(index < surface->tilesSize);
2377 const UINT32 dl = nXDst + tile->x;
2378 updateRect.left = WINPR_ASSERTING_INT_CAST(UINT16, dl);
2380 const UINT32 dt = nYDst + tile->y;
2381 updateRect.top = WINPR_ASSERTING_INT_CAST(UINT16, dt);
2382 updateRect.right = updateRect.left + 64;
2383 updateRect.bottom = updateRect.top + 64;
2385 REGION16 updateRegion = WINPR_C_ARRAY_INIT;
2386 region16_init(&updateRegion);
2387 if (!region16_intersect_rect(&updateRegion, &clippingRects, &updateRect))
2389 region16_uninit(&updateRegion);
2392 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
2394 for (UINT32 j = 0; j < nbUpdateRects; j++)
2398 if (rect->left < updateRect.left)
2400 const UINT32 nXSrc = rect->left - updateRect.left;
2401 const UINT32 nYSrc = rect->top - updateRect.top;
2402 const UINT32 width = rect->right - rect->left;
2403 const UINT32 height = rect->bottom - rect->top;
2405 if (rect->left + width > surface->width)
2407 if (rect->top + height > surface->height)
2409 rc = freerdp_image_copy_no_overlap(
2410 pDstData, DstFormat, nDstStep, rect->left, rect->top, width, height, tile->data,
2411 progressive->format, tile->stride, nXSrc, nYSrc,
nullptr, FREERDP_KEEP_DST_ALPHA);
2417 if (!region16_union_rect(invalidRegion, invalidRegion, rect))
2419 region16_uninit(&updateRegion);
2425 region16_uninit(&updateRegion);
2428 tile->dirty = FALSE;
2432 region16_uninit(&clippingRects);
2436INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2437 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
2438 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2439 UINT32 nXDst, UINT32 nYDst,
REGION16* WINPR_RESTRICT invalidRegion,
2440 UINT16 surfaceId, UINT32 frameId)
2444 WINPR_ASSERT(progressive);
2449 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion no surface for %" PRIu16,
2454 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2455 WINPR_ASSERT(region);
2457 if (surface->frameId != frameId)
2459 surface->frameId = frameId;
2460 surface->numUpdatedTiles = 0;
2463 wStream ss = WINPR_C_ARRAY_INIT;
2464 wStream* s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
2469 case PIXEL_FORMAT_RGBA32:
2470 case PIXEL_FORMAT_RGBX32:
2471 case PIXEL_FORMAT_BGRA32:
2472 case PIXEL_FORMAT_BGRX32:
2473 progressive->format = DstFormat;
2476 progressive->format = PIXEL_FORMAT_XRGB32;
2480 const size_t start = Stream_GetPosition(s);
2481 progressive->state = 0;
2482 while (Stream_GetRemainingLength(s) > 0)
2484 if (progressive_parse_block(progressive, s, surface, region) < 0)
2489 const size_t end = Stream_GetPosition(s);
2490 if ((end - start) != SrcSize)
2492 WLog_Print(progressive->log, WLOG_ERROR,
2493 "total block len %" PRIuz
" does not match read data %" PRIu32, end - start,
2500 if (!update_tiles(progressive, surface, pDstData, DstFormat, nDstStep, nXDst, nYDst, region,
2507BOOL progressive_rfx_write_message_progressive_simple(
2508 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s,
2509 const RFX_MESSAGE* WINPR_RESTRICT msg)
2511 RFX_CONTEXT* context =
nullptr;
2513 WINPR_ASSERT(progressive);
2516 context = progressive->rfx_context;
2517 return rfx_write_message_progressive_simple(context, s, msg);
2520int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2521 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 SrcFormat,
2522 UINT32 Width, UINT32 Height, UINT32 ScanLine,
2523 const REGION16* WINPR_RESTRICT invalidRegion,
2524 BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize)
2529 UINT32 numRects = 0;
2531 RFX_MESSAGE* message =
nullptr;
2533 if (!progressive || !pSrcData || !ppDstData || !pDstSize)
2542 case PIXEL_FORMAT_ABGR32:
2543 case PIXEL_FORMAT_ARGB32:
2544 case PIXEL_FORMAT_XBGR32:
2545 case PIXEL_FORMAT_XRGB32:
2546 case PIXEL_FORMAT_BGRA32:
2547 case PIXEL_FORMAT_BGRX32:
2548 case PIXEL_FORMAT_RGBA32:
2549 case PIXEL_FORMAT_RGBX32:
2550 ScanLine = Width * 4;
2557 if (SrcSize < Height * ScanLine)
2562 numRects = (Width + 63) / 64;
2563 numRects *= (Height + 63) / 64;
2567 const int nr = region16_n_rects(invalidRegion);
2568 numRects = WINPR_ASSERTING_INT_CAST(uint32_t, nr);
2574 if (!Stream_EnsureRemainingCapacity(progressive->rects, numRects *
sizeof(
RFX_RECT)))
2576 rects = Stream_BufferAs(progressive->rects,
RFX_RECT);
2579 const RECTANGLE_16* region_rects = region16_rects(invalidRegion,
nullptr);
2580 for (UINT32 idx = 0; idx < numRects; idx++)
2587 rect->width = r->right - r->left;
2588 rect->height = r->bottom - r->top;
2596 for (UINT32 i = 0; i < numRects; i++)
2602 WINPR_ASSERT(Width >= x);
2603 WINPR_ASSERT(Height >= y);
2604 r->width = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Width - x));
2605 r->height = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Height - y));
2607 if (x + 64UL >= Width)
2615 WINPR_ASSERT(r->x % 64 == 0);
2616 WINPR_ASSERT(r->y % 64 == 0);
2617 WINPR_ASSERT(r->width <= 64);
2618 WINPR_ASSERT(r->height <= 64);
2621 s = progressive->buffer;
2622 Stream_ResetPosition(s);
2624 progressive->rfx_context->mode = RLGR1;
2626 progressive->rfx_context->width = WINPR_ASSERTING_INT_CAST(UINT16, Width);
2627 progressive->rfx_context->height = WINPR_ASSERTING_INT_CAST(UINT16, Height);
2628 rfx_context_set_pixel_format(progressive->rfx_context, SrcFormat);
2629 message = rfx_encode_message(progressive->rfx_context, rects, numRects, pSrcData, Width, Height,
2633 WLog_ERR(TAG,
"failed to encode rfx message");
2637 rc = progressive_rfx_write_message_progressive_simple(progressive, s, message);
2638 rfx_message_free(progressive->rfx_context, message);
2643 const size_t pos = Stream_GetPosition(s);
2644 WINPR_ASSERT(pos <= UINT32_MAX);
2645 *pDstSize = (UINT32)pos;
2647 *ppDstData = Stream_Buffer(s);
2653BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive)
2655 return (progressive !=
nullptr);
2658PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
2660 return progressive_context_new_ex(Compressor, 0);
2663PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, UINT32 ThreadingFlags)
2665 PROGRESSIVE_CONTEXT* progressive =
2666 (PROGRESSIVE_CONTEXT*)winpr_aligned_calloc(1,
sizeof(PROGRESSIVE_CONTEXT), 32);
2671 progressive->Compressor = Compressor;
2672 progressive->quantProgValFull.quality = 100;
2673 progressive->log = WLog_Get(TAG);
2674 if (!progressive->log)
2676 progressive->rfx_context = rfx_context_new_ex(Compressor, ThreadingFlags);
2677 if (!progressive->rfx_context)
2679 progressive->buffer = Stream_New(
nullptr, 1024);
2680 if (!progressive->buffer)
2682 progressive->rects = Stream_New(
nullptr, 1024);
2683 if (!progressive->rects)
2685 progressive->bufferPool = BufferPool_New(TRUE, (8192LL + 32LL) * 3LL, 16);
2686 if (!progressive->bufferPool)
2688 progressive->SurfaceContexts = HashTable_New(TRUE);
2689 if (!progressive->SurfaceContexts)
2693 wObject* obj = HashTable_ValueObject(progressive->SurfaceContexts);
2699 WINPR_PRAGMA_DIAG_PUSH
2700 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2701 progressive_context_free(progressive);
2702 WINPR_PRAGMA_DIAG_POP
2706void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
2711 Stream_Free(progressive->buffer, TRUE);
2712 Stream_Free(progressive->rects, TRUE);
2713 rfx_context_free(progressive->rfx_context);
2715 BufferPool_Free(progressive->bufferPool);
2716 HashTable_Free(progressive->SurfaceContexts);
2718 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