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_calloc(tile->stride, tile->height, 16);
371 memset(tile->data, 0xFF, dataLen);
375 const size_t signLen = (8192ULL + 32ULL);
376 tile->sign = (BYTE*)winpr_aligned_calloc(3, signLen, 16);
383 const size_t currentLen = (8192ULL + 32ULL);
384 tile->current = (BYTE*)winpr_aligned_calloc(3, 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 if (!rfx_differential_decode(buffer + 4032, 64))
881 if (!progressive_rfx_decode_block(prims, &buffer[0], 1024, shift->HL1))
883 if (!progressive_rfx_decode_block(prims, &buffer[1024], 1024, shift->LH1))
885 if (!progressive_rfx_decode_block(prims, &buffer[2048], 1024, shift->HH1))
887 if (!progressive_rfx_decode_block(prims, &buffer[3072], 256, shift->HL2))
889 if (!progressive_rfx_decode_block(prims, &buffer[3328], 256, shift->LH2))
891 if (!progressive_rfx_decode_block(prims, &buffer[3584], 256, shift->HH2))
893 if (!progressive_rfx_decode_block(prims, &buffer[3840], 64, shift->HL3))
895 if (!progressive_rfx_decode_block(prims, &buffer[3904], 64, shift->LH3))
897 if (!progressive_rfx_decode_block(prims, &buffer[3968], 64, shift->HH3))
899 if (!progressive_rfx_decode_block(prims, &buffer[4032], 64, shift->LL3))
904 if (!progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1))
906 if (!progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1))
908 if (!progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1))
910 if (!progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2))
912 if (!progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2))
914 if (!progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2))
916 if (!progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3))
918 if (!progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3))
920 if (!progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3))
922 if (!rfx_differential_decode(&buffer[4015], 81))
924 if (!progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3))
927 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
932progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
934 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
940 BOOL extrapolate = 0;
941 BYTE* pBuffer =
nullptr;
959 diff = tile->flags & RFX_TILE_DIFFERENCE;
960 sub = context->flags & RFX_SUBBAND_DIFFING;
961 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
963#if defined(WITH_DEBUG_CODECS)
964 WLog_Print(progressive->log, WLOG_DEBUG,
965 "ProgressiveTile%s: quantIdx Y: %" PRIu8
" Cb: %" PRIu8
" Cr: %" PRIu8
966 " xIdx: %" PRIu16
" yIdx: %" PRIu16
" flags: 0x%02" PRIX8
" quality: %" PRIu8
967 " yLen: %" PRIu16
" cbLen: %" PRIu16
" crLen: %" PRIu16
" tailLen: %" PRIu16
"",
968 (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ?
"First" :
"Simple",
969 tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx,
970 tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
973 if (tile->quantIdxY >= region->numQuant)
975 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
979 quantY = &(region->quantVals[tile->quantIdxY]);
981 if (tile->quantIdxCb >= region->numQuant)
983 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
988 quantCb = &(region->quantVals[tile->quantIdxCb]);
990 if (tile->quantIdxCr >= region->numQuant)
992 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
997 quantCr = &(region->quantVals[tile->quantIdxCr]);
999 if (tile->quality == 0xFF)
1001 quantProgVal = &(progressive->quantProgValFull);
1005 if (tile->quality >= region->numProgQuant)
1007 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1008 region->numProgQuant);
1012 quantProgVal = &(region->quantProgVals[tile->quality]);
1015 quantProgY = &(quantProgVal->yQuantValues);
1016 quantProgCb = &(quantProgVal->cbQuantValues);
1017 quantProgCr = &(quantProgVal->crQuantValues);
1019 tile->yQuant = *quantY;
1020 tile->cbQuant = *quantCb;
1021 tile->crQuant = *quantCr;
1022 tile->yProgQuant = *quantProgY;
1023 tile->cbProgQuant = *quantProgCb;
1024 tile->crProgQuant = *quantProgCr;
1026 progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
1027 progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
1028 progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
1029 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1030 if (!progressive_rfx_quant_lsub(&shiftY, 1))
1032 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1033 if (!progressive_rfx_quant_lsub(&shiftCb, 1))
1035 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1036 if (!progressive_rfx_quant_lsub(&shiftCr, 1))
1040 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 0) + 16]));
1042 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 1) + 16]));
1044 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 2) + 16]));
1047 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 0) + 16]));
1049 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 1) + 16]));
1051 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 2) + 16]));
1053 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1055 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 0) + 16]));
1057 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 1) + 16]));
1059 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 2) + 16]));
1061 rc = progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0],
1062 pCurrent[0], pSign[0], diff, sub, extrapolate);
1065 rc = progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen,
1066 pSrcDst[1], pCurrent[1], pSign[1], diff, sub,
1070 rc = progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen,
1071 pSrcDst[2], pCurrent[2], pSign[2], diff, sub,
1077 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1078 rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1079 progressive->format, &roi_64x64);
1082 BufferPool_Return(progressive->bufferPool, pBuffer);
1086static inline INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1089 WINPR_ASSERT(state);
1100 const UINT32 k = state->kp / 8;
1105 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1106 BitStream_Shift(bs, 1);
1111 state->nz = (1 << k);
1128 bs->mask = ((1u << k) - 1);
1130 WINPR_ASSERTING_INT_CAST(int16_t, ((bs->accumulator >> (32u - k)) & bs->mask));
1131 BitStream_Shift(bs, k);
1145 const UINT32 sign = (bs->accumulator & 0x80000000) ? 1 : 0;
1146 BitStream_Shift(bs, 1);
1154 return sign ? -1 : 1;
1157 const UINT32 max = (1u << numBits) - 1;
1161 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1162 BitStream_Shift(bs, 1);
1170 if (mag > INT16_MAX)
1172 return (INT16)(sign ? -1 * (int)mag : (INT16)mag);
1176progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state)
1187 pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
1190 BitStream_Shift(raw, pad);
1192 pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
1195 BitStream_Shift(srl, pad);
1197 if (BitStream_GetRemainingLength(srl) == 8)
1198 BitStream_Shift(srl, 8);
1203static inline int16_t rawShift(
wBitStream* raw, UINT32 numBits)
1206 WINPR_ASSERT(numBits > 0);
1208 raw->mask = ((1u << numBits) - 1);
1209 const int16_t input = (int16_t)((raw->accumulator >> (32 - numBits)) & raw->mask);
1210 BitStream_Shift(raw, numBits);
1214static inline int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1215 INT16* WINPR_RESTRICT buffer,
1216 INT16* WINPR_RESTRICT sign, UINT32 length,
1217 UINT32 shift, WINPR_ATTR_UNUSED UINT32 bitPos,
1228 for (UINT32 index = 0; index < length; index++)
1230 input = rawShift(raw, numBits);
1232 const int32_t shifted = input << shift;
1233 const int32_t val = buffer[index] + shifted;
1234 const int16_t ival = WINPR_ASSERTING_INT_CAST(int16_t, val);
1235 buffer[index] = ival;
1241 for (UINT32 index = 0; index < length; index++)
1243 if (sign[index] > 0)
1246 input = rawShift(raw, numBits);
1248 else if (sign[index] < 0)
1251 input = rawShift(raw, numBits);
1257 input = progressive_rfx_srl_read(state, numBits);
1258 sign[index] = WINPR_ASSERTING_INT_CAST(int16_t, input);
1261 const int32_t val = input << shift;
1262 const int32_t ival = buffer[index] + val;
1263 buffer[index] = WINPR_ASSERTING_INT_CAST(INT16, ival);
1269static inline int progressive_rfx_upgrade_component(
1270 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1274 INT16* WINPR_RESTRICT current, INT16* WINPR_RESTRICT sign,
const BYTE* WINPR_RESTRICT srlData,
1275 UINT32 srlLen,
const BYTE* WINPR_RESTRICT rawData, UINT32 rawLen, BOOL coeffDiff,
1276 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
1281 RFX_PROGRESSIVE_UPGRADE_STATE state = WINPR_C_ARRAY_INIT;
1287 BitStream_Attach(state.srl, srlData, srlLen);
1288 BitStream_Fetch(state.srl);
1289 BitStream_Attach(state.raw, rawData, rawLen);
1290 BitStream_Fetch(state.raw);
1293 rc = progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1,
1297 rc = progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1,
1298 bitPos->LH1, numBits->LH1);
1301 rc = progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1,
1302 bitPos->HH1, numBits->HH1);
1305 rc = progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2,
1306 bitPos->HL2, numBits->HL2);
1309 rc = progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2,
1310 bitPos->LH2, numBits->LH2);
1313 rc = progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2,
1314 bitPos->HH2, numBits->HH2);
1317 rc = progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3,
1318 bitPos->HL3, numBits->HL3);
1321 rc = progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3,
1322 bitPos->LH3, numBits->LH3);
1325 rc = progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3,
1326 bitPos->HH3, numBits->HH3);
1330 state.nonLL = FALSE;
1331 rc = progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3,
1332 bitPos->LL3, numBits->LL3);
1335 rc = progressive_rfx_upgrade_state_finish(&state);
1338 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
1343progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1345 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1351 BOOL extrapolate = 0;
1352 BYTE* pBuffer =
nullptr;
1353 INT16* pSign[3] = WINPR_C_ARRAY_INIT;
1354 INT16* pSrcDst[3] = WINPR_C_ARRAY_INIT;
1355 INT16* pCurrent[3] = WINPR_C_ARRAY_INIT;
1375 coeffDiff = tile->flags & RFX_TILE_DIFFERENCE;
1376 sub = context->flags & RFX_SUBBAND_DIFFING;
1377 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
1381#if defined(WITH_DEBUG_CODECS)
1382 WLog_Print(progressive->log, WLOG_DEBUG,
1383 "ProgressiveTileUpgrade: pass: %" PRIu16
" quantIdx Y: %" PRIu8
" Cb: %" PRIu8
1384 " Cr: %" PRIu8
" xIdx: %" PRIu16
" yIdx: %" PRIu16
" quality: %" PRIu8
1385 " ySrlLen: %" PRIu16
" yRawLen: %" PRIu16
" cbSrlLen: %" PRIu16
" cbRawLen: %" PRIu16
1386 " crSrlLen: %" PRIu16
" crRawLen: %" PRIu16
"",
1387 tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx,
1388 tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen,
1389 tile->cbRawLen, tile->crSrlLen, tile->crRawLen);
1392 if (tile->quantIdxY >= region->numQuant)
1394 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
1398 quantY = &(region->quantVals[tile->quantIdxY]);
1400 if (tile->quantIdxCb >= region->numQuant)
1402 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
1407 quantCb = &(region->quantVals[tile->quantIdxCb]);
1409 if (tile->quantIdxCr >= region->numQuant)
1411 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1416 quantCr = &(region->quantVals[tile->quantIdxCr]);
1418 if (tile->quality == 0xFF)
1420 quantProg = &(progressive->quantProgValFull);
1424 if (tile->quality >= region->numProgQuant)
1426 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1427 region->numProgQuant);
1431 quantProg = &(region->quantProgVals[tile->quality]);
1434 quantProgY = &(quantProg->yQuantValues);
1435 quantProgCb = &(quantProg->cbQuantValues);
1436 quantProgCr = &(quantProg->crQuantValues);
1438 if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
1439 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantY has changed!");
1441 if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
1442 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCb has changed!");
1444 if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
1445 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCr has changed!");
1447 if (!(context->flags & RFX_SUBBAND_DIFFING))
1448 WLog_WARN(TAG,
"PROGRESSIVE_BLOCK_CONTEXT::flags & RFX_SUBBAND_DIFFING not set");
1450 progressive_rfx_quant_add(quantY, quantProgY, &yBitPos);
1451 progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos);
1452 progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos);
1453 if (!progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits))
1455 if (!progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits))
1457 if (!progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits))
1459 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1460 if (!progressive_rfx_quant_lsub(&shiftY, 1))
1462 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1463 if (!progressive_rfx_quant_lsub(&shiftCb, 1))
1465 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1466 if (!progressive_rfx_quant_lsub(&shiftCr, 1))
1469 tile->yBitPos = yBitPos;
1470 tile->cbBitPos = cbBitPos;
1471 tile->crBitPos = crBitPos;
1472 tile->yQuant = *quantY;
1473 tile->cbQuant = *quantCb;
1474 tile->crQuant = *quantCr;
1475 tile->yProgQuant = *quantProgY;
1476 tile->cbProgQuant = *quantProgCb;
1477 tile->crProgQuant = *quantProgCr;
1480 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 0) + 16]));
1482 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 1) + 16]));
1484 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 2) + 16]));
1487 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 0) + 16]));
1489 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 1) + 16]));
1491 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 2) + 16]));
1493 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1495 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 0) + 16]));
1497 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 1) + 16]));
1499 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 2) + 16]));
1501 status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
1502 pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData,
1503 tile->ySrlLen, tile->yRawData, tile->yRawLen,
1504 coeffDiff, sub, extrapolate);
1509 status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
1510 pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData,
1511 tile->cbSrlLen, tile->cbRawData, tile->cbRawLen,
1512 coeffDiff, sub, extrapolate);
1517 status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
1518 pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData,
1519 tile->crSrlLen, tile->crRawData, tile->crRawLen,
1520 coeffDiff, sub, extrapolate);
1526 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1527 status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1528 progressive->format, &roi_64x64);
1531 BufferPool_Return(progressive->bufferPool, pBuffer);
1535static inline BOOL progressive_tile_read_upgrade(
1536 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1538 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1542 const size_t expect = 20;
1544 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1547 tile.blockType = blockType;
1548 tile.blockLen = blockLen;
1551 Stream_Read_UINT8(s, tile.quantIdxY);
1552 Stream_Read_UINT8(s, tile.quantIdxCb);
1553 Stream_Read_UINT8(s, tile.quantIdxCr);
1554 Stream_Read_UINT16(s, tile.xIdx);
1555 Stream_Read_UINT16(s, tile.yIdx);
1556 Stream_Read_UINT8(s, tile.quality);
1557 Stream_Read_UINT16(s, tile.ySrlLen);
1558 Stream_Read_UINT16(s, tile.yRawLen);
1559 Stream_Read_UINT16(s, tile.cbSrlLen);
1560 Stream_Read_UINT16(s, tile.cbRawLen);
1561 Stream_Read_UINT16(s, tile.crSrlLen);
1562 Stream_Read_UINT16(s, tile.crRawLen);
1564 tile.ySrlData = Stream_Pointer(s);
1565 if (!Stream_SafeSeek(s, tile.ySrlLen))
1567 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.ySrlLen);
1571 tile.yRawData = Stream_Pointer(s);
1572 if (!Stream_SafeSeek(s, tile.yRawLen))
1574 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yRawLen);
1578 tile.cbSrlData = Stream_Pointer(s);
1579 if (!Stream_SafeSeek(s, tile.cbSrlLen))
1581 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1586 tile.cbRawData = Stream_Pointer(s);
1587 if (!Stream_SafeSeek(s, tile.cbRawLen))
1589 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1594 tile.crSrlData = Stream_Pointer(s);
1595 if (!Stream_SafeSeek(s, tile.crSrlLen))
1597 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1602 tile.crRawData = Stream_Pointer(s);
1603 if (!Stream_SafeSeek(s, tile.crRawLen))
1605 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1610 return progressive_surface_tile_replace(surface, region, &tile, TRUE);
1614progressive_tile_read(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, BOOL simple,
1615 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
1617 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1621 size_t expect = simple ? 16 : 17;
1623 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1626 tile.blockType = blockType;
1627 tile.blockLen = blockLen;
1629 Stream_Read_UINT8(s, tile.quantIdxY);
1630 Stream_Read_UINT8(s, tile.quantIdxCb);
1631 Stream_Read_UINT8(s, tile.quantIdxCr);
1632 Stream_Read_UINT16(s, tile.xIdx);
1633 Stream_Read_UINT16(s, tile.yIdx);
1634 Stream_Read_UINT8(s, tile.flags);
1637 Stream_Read_UINT8(s, tile.quality);
1639 tile.quality = 0xFF;
1640 Stream_Read_UINT16(s, tile.yLen);
1641 Stream_Read_UINT16(s, tile.cbLen);
1642 Stream_Read_UINT16(s, tile.crLen);
1643 Stream_Read_UINT16(s, tile.tailLen);
1645 tile.yData = Stream_Pointer(s);
1646 if (!Stream_SafeSeek(s, tile.yLen))
1648 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yLen);
1652 tile.cbData = Stream_Pointer(s);
1653 if (!Stream_SafeSeek(s, tile.cbLen))
1655 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.cbLen);
1659 tile.crData = Stream_Pointer(s);
1660 if (!Stream_SafeSeek(s, tile.crLen))
1662 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.crLen);
1666 tile.tailData = Stream_Pointer(s);
1667 if (!Stream_SafeSeek(s, tile.tailLen))
1669 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.tailLen);
1673 return progressive_surface_tile_replace(surface, region, &tile, FALSE);
1676static void CALLBACK progressive_process_tiles_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1677 void* context, PTP_WORK work)
1681 WINPR_UNUSED(instance);
1684 switch (param->tile->blockType)
1686 case PROGRESSIVE_WBT_TILE_SIMPLE:
1687 case PROGRESSIVE_WBT_TILE_FIRST:
1688 progressive_decompress_tile_first(param->progressive, param->tile, param->region,
1692 case PROGRESSIVE_WBT_TILE_UPGRADE:
1693 progressive_decompress_tile_upgrade(param->progressive, param->tile, param->region,
1697 WLog_Print(param->progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16
" (%s)",
1698 param->tile->blockType,
1699 rfx_get_progressive_block_type_string(param->tile->blockType));
1704static inline SSIZE_T
1705progressive_process_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1707 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1713 const size_t start = Stream_GetPosition(s);
1714 UINT16 blockType = 0;
1715 UINT32 blockLen = 0;
1717 UINT16 close_cnt = 0;
1719 WINPR_ASSERT(progressive);
1720 WINPR_ASSERT(region);
1722 if (!Stream_CheckAndLogRequiredLength(TAG, s, region->tileDataSize))
1725 while ((Stream_GetRemainingLength(s) >= 6) &&
1726 (region->tileDataSize > (Stream_GetPosition(s) - start)))
1728 const size_t pos = Stream_GetPosition(s);
1730 Stream_Read_UINT16(s, blockType);
1731 Stream_Read_UINT32(s, blockLen);
1733#if defined(WITH_DEBUG_CODECS)
1734 WLog_Print(progressive->log, WLOG_DEBUG,
"%s",
1735 rfx_get_progressive_block_type_string(blockType));
1740 WLog_Print(progressive->log, WLOG_ERROR,
"Expected >= %" PRIu32
" remaining %" PRIu32,
1744 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
1749 case PROGRESSIVE_WBT_TILE_SIMPLE:
1750 if (!progressive_tile_read(progressive, TRUE, s, blockType, blockLen, surface,
1755 case PROGRESSIVE_WBT_TILE_FIRST:
1756 if (!progressive_tile_read(progressive, FALSE, s, blockType, blockLen, surface,
1761 case PROGRESSIVE_WBT_TILE_UPGRADE:
1762 if (!progressive_tile_read_upgrade(progressive, s, blockType, blockLen, surface,
1767 WLog_ERR(TAG,
"Invalid block type %04" PRIx16
" (%s)", blockType,
1768 rfx_get_progressive_block_type_string(blockType));
1772 size_t rem = Stream_GetPosition(s);
1773 if ((rem - pos) != blockLen)
1775 WLog_Print(progressive->log, WLOG_ERROR,
1776 "Actual block read %" PRIuz
" but expected %" PRIu32, rem - pos, blockLen);
1782 end = Stream_GetPosition(s);
1783 if ((end - start) != region->tileDataSize)
1785 WLog_Print(progressive->log, WLOG_ERROR,
1786 "Actual total blocks read %" PRIuz
" but expected %" PRIu32, end - start,
1787 region->tileDataSize);
1791 if (count != region->numTiles)
1793 WLog_Print(progressive->log, WLOG_WARN,
1794 "numTiles inconsistency: actual: %" PRIu32
", expected: %" PRIu16
"\n", count,
1799 for (UINT32 idx = 0; idx < region->numTiles; idx++)
1803 param->progressive = progressive;
1804 param->region = region;
1805 param->context = context;
1808 if (progressive->rfx_context->priv->UseThreads)
1810 progressive->work_objects[idx] = CreateThreadpoolWork(
1811 progressive_process_tiles_tile_work_callback, (
void*)param,
nullptr);
1812 if (!progressive->work_objects[idx])
1814 WLog_Print(progressive->log, WLOG_ERROR,
1815 "Failed to create ThreadpoolWork for tile %" PRIu32, idx);
1820 SubmitThreadpoolWork(progressive->work_objects[idx]);
1822 close_cnt = WINPR_ASSERTING_INT_CAST(UINT16, idx + 1);
1826 progressive_process_tiles_tile_work_callback(
nullptr, param,
nullptr);
1831 WLog_Print(progressive->log, WLOG_ERROR,
"Failed to decompress %s at %" PRIu16,
1832 rfx_get_progressive_block_type_string(tile->blockType), idx);
1837 if (progressive->rfx_context->priv->UseThreads)
1839 for (UINT32 idx = 0; idx < close_cnt; idx++)
1841 WaitForThreadpoolWorkCallbacks(progressive->work_objects[idx], FALSE);
1842 CloseThreadpoolWork(progressive->work_objects[idx]);
1851 return (SSIZE_T)(end - start);
1854static inline SSIZE_T progressive_wb_sync(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1855 wStream* WINPR_RESTRICT s, UINT16 blockType,
1858 const UINT32 magic = 0xCACCACCA;
1859 const UINT16 version = 0x0100;
1862 sync.blockType = blockType;
1863 sync.blockLen = blockLen;
1865 if (sync.blockLen != 12)
1867 WLog_Print(progressive->log, WLOG_ERROR,
1868 "PROGRESSIVE_BLOCK_SYNC::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1869 sync.blockLen, 12u);
1873 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1876#if defined(WITH_DEBUG_CODECS)
1877 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveSync");
1880 Stream_Read_UINT32(s, sync.magic);
1881 Stream_Read_UINT16(s, sync.version);
1883 if (sync.magic != magic)
1885 WLog_Print(progressive->log, WLOG_ERROR,
1886 "PROGRESSIVE_BLOCK_SYNC::magic = 0x%08" PRIx32
" != 0x%08" PRIx32, sync.magic,
1891 if (sync.version != 0x0100)
1893 WLog_Print(progressive->log, WLOG_ERROR,
1894 "PROGRESSIVE_BLOCK_SYNC::version = 0x%04" PRIx16
" != 0x%04" PRIu16,
1895 sync.version, version);
1899 if ((progressive->state & FLAG_WBT_SYNC) != 0)
1900 WLog_WARN(TAG,
"Duplicate PROGRESSIVE_BLOCK_SYNC, ignoring");
1902 progressive->state |= FLAG_WBT_SYNC;
1906static inline SSIZE_T progressive_wb_frame_begin(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1907 wStream* WINPR_RESTRICT s, UINT16 blockType,
1912 frameBegin.blockType = blockType;
1913 frameBegin.blockLen = blockLen;
1915 if (frameBegin.blockLen != 12)
1917 WLog_Print(progressive->log, WLOG_ERROR,
1918 " RFX_PROGRESSIVE_FRAME_BEGIN::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1919 frameBegin.blockLen, 12u);
1923 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1926 Stream_Read_UINT32(s, frameBegin.frameIndex);
1927 Stream_Read_UINT16(s, frameBegin.regionCount);
1929#if defined(WITH_DEBUG_CODECS)
1930 WLog_Print(progressive->log, WLOG_DEBUG,
1931 "ProgressiveFrameBegin: frameIndex: %" PRIu32
" regionCount: %" PRIu16
"",
1932 frameBegin.frameIndex, frameBegin.regionCount);
1941 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1943 WLog_ERR(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_BEGIN in stream, this is not allowed!");
1947 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1949 WLog_ERR(TAG,
"RFX_PROGRESSIVE_FRAME_BEGIN after RFX_PROGRESSIVE_FRAME_END in stream, this "
1954 progressive->state |= FLAG_WBT_FRAME_BEGIN;
1958static inline SSIZE_T progressive_wb_frame_end(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1959 wStream* WINPR_RESTRICT s, UINT16 blockType,
1964 frameEnd.blockType = blockType;
1965 frameEnd.blockLen = blockLen;
1967 if (frameEnd.blockLen != 6)
1969 WLog_Print(progressive->log, WLOG_ERROR,
1970 " RFX_PROGRESSIVE_FRAME_END::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1971 frameEnd.blockLen, 6u);
1975 if (Stream_GetRemainingLength(s) != 0)
1977 WLog_Print(progressive->log, WLOG_ERROR,
1978 "ProgressiveFrameEnd short %" PRIuz
", expected %u",
1979 Stream_GetRemainingLength(s), 0U);
1983#if defined(WITH_DEBUG_CODECS)
1984 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveFrameEnd");
1987 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
1988 WLog_WARN(TAG,
"RFX_PROGRESSIVE_FRAME_END before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
1989 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1990 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_END, ignoring");
1992 progressive->state |= FLAG_WBT_FRAME_END;
1996static inline SSIZE_T progressive_wb_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1997 wStream* WINPR_RESTRICT s, UINT16 blockType,
2001 context->blockType = blockType;
2002 context->blockLen = blockLen;
2004 if (context->blockLen != 10)
2006 WLog_Print(progressive->log, WLOG_ERROR,
2007 "RFX_PROGRESSIVE_CONTEXT::blockLen = 0x%08" PRIx32
" != 0x%08x",
2008 context->blockLen, 10u);
2012 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2015 Stream_Read_UINT8(s, context->ctxId);
2016 Stream_Read_UINT16(s, context->tileSize);
2017 Stream_Read_UINT8(s, context->flags);
2019 if (context->ctxId != 0x00)
2020 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT::ctxId != 0x00: %" PRIu8, context->ctxId);
2022 if (context->tileSize != 64)
2024 WLog_ERR(TAG,
"RFX_PROGRESSIVE_CONTEXT::tileSize != 0x40: %" PRIu16, context->tileSize);
2028 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
2029 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_BEGIN");
2030 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2031 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_END");
2032 if ((progressive->state & FLAG_WBT_CONTEXT) != 0)
2033 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_CONTEXT received, ignoring.");
2035#if defined(WITH_DEBUG_CODECS)
2036 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveContext: flags: 0x%02" PRIX8
"",
2040 progressive->state |= FLAG_WBT_CONTEXT;
2044static inline SSIZE_T
2045progressive_wb_read_region_header(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2046 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
2047 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2049 region->usedTiles = 0;
2051 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2054 region->blockType = blockType;
2055 region->blockLen = blockLen;
2056 Stream_Read_UINT8(s, region->tileSize);
2057 Stream_Read_UINT16(s, region->numRects);
2058 Stream_Read_UINT8(s, region->numQuant);
2059 Stream_Read_UINT8(s, region->numProgQuant);
2060 Stream_Read_UINT8(s, region->flags);
2061 Stream_Read_UINT16(s, region->numTiles);
2062 Stream_Read_UINT32(s, region->tileDataSize);
2064 if (region->tileSize != 64)
2066 WLog_Print(progressive->log, WLOG_ERROR,
2067 "ProgressiveRegion tile size %" PRIu8
", expected %u", region->tileSize, 64U);
2071 if (region->numRects < 1)
2073 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion missing rect count %" PRIu16,
2078 if (region->numQuant > 7)
2080 WLog_Print(progressive->log, WLOG_ERROR,
2081 "ProgressiveRegion quant count too high %" PRIu8
", expected < %u",
2082 region->numQuant, 7U);
2086 const SSIZE_T rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, Stream_GetRemainingLength(s));
2087 const SSIZE_T expect = region->numRects * 8ll + region->numQuant * 5ll +
2088 region->numProgQuant * 16ll + region->tileDataSize;
2092 if (len / 8LL < region->numRects)
2094 WLog_Print(progressive->log, WLOG_ERROR,
2095 "ProgressiveRegion data short for region->rects");
2098 len -= region->numRects * 8LL;
2100 if (len / 5LL < region->numQuant)
2102 WLog_Print(progressive->log, WLOG_ERROR,
2103 "ProgressiveRegion data short for region->cQuant");
2106 len -= region->numQuant * 5LL;
2108 if (len / 16LL < region->numProgQuant)
2110 WLog_Print(progressive->log, WLOG_ERROR,
2111 "ProgressiveRegion data short for region->cProgQuant");
2114 len -= region->numProgQuant * 16LL;
2116 if (len < region->tileDataSize * 1ll)
2118 WLog_Print(progressive->log, WLOG_ERROR,
2119 "ProgressiveRegion data short for region->tiles");
2122 len -= region->tileDataSize;
2125 WLog_Print(progressive->log, WLOG_WARN,
2126 "Unused bytes detected, %" PRIdz
" bytes not processed", len);
2132static inline SSIZE_T progressive_wb_skip_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2133 wStream* WINPR_RESTRICT s, UINT16 blockType,
2136 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2139 progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2143 if (!Stream_SafeSeek(s, WINPR_ASSERTING_INT_CAST(
size_t, rc)))
2149static inline SSIZE_T progressive_wb_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2150 wStream* WINPR_RESTRICT s, UINT16 blockType,
2153 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2158 UINT16 boxRight = 0;
2159 UINT16 boxBottom = 0;
2162 UINT16 idxRight = 0;
2163 UINT16 idxBottom = 0;
2166 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
2168 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
2169 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2171 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2173 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION after RFX_PROGRESSIVE_FRAME_END, ignoring");
2174 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2177 progressive->state |= FLAG_WBT_REGION;
2179 rc = progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2183 for (UINT16 index = 0; index < region->numRects; index++)
2185 RFX_RECT* rect = &(region->rects[index]);
2186 Stream_Read_UINT16(s, rect->x);
2187 Stream_Read_UINT16(s, rect->y);
2188 Stream_Read_UINT16(s, rect->width);
2189 Stream_Read_UINT16(s, rect->height);
2192 for (BYTE index = 0; index < region->numQuant; index++)
2195 progressive_component_codec_quant_read(s, quantVal);
2197 if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
2199 WLog_Print(progressive->log, WLOG_ERROR,
2200 "ProgressiveRegion region->cQuant[%" PRIu32
"] < 6", index);
2204 if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
2206 WLog_Print(progressive->log, WLOG_ERROR,
2207 "ProgressiveRegion region->cQuant[%" PRIu32
"] > 15", index);
2212 for (BYTE index = 0; index < region->numProgQuant; index++)
2216 Stream_Read_UINT8(s, quantProgVal->quality);
2218 progressive_component_codec_quant_read(s, &(quantProgVal->yQuantValues));
2219 progressive_component_codec_quant_read(s, &(quantProgVal->cbQuantValues));
2220 progressive_component_codec_quant_read(s, &(quantProgVal->crQuantValues));
2223#if defined(WITH_DEBUG_CODECS)
2224 WLog_Print(progressive->log, WLOG_DEBUG,
2225 "ProgressiveRegion: numRects: %" PRIu16
" numTiles: %" PRIu16
2226 " tileDataSize: %" PRIu32
" flags: 0x%02" PRIX8
" numQuant: %" PRIu8
2227 " numProgQuant: %" PRIu8
"",
2228 region->numRects, region->numTiles, region->tileDataSize, region->flags,
2229 region->numQuant, region->numProgQuant);
2232 boxLeft = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridWidth);
2233 boxTop = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridHeight);
2237 for (UINT16 index = 0; index < region->numRects; index++)
2239 RFX_RECT* rect = &(region->rects[index]);
2240 idxLeft = rect->x / 64;
2241 idxTop = rect->y / 64;
2242 idxRight = (rect->x + rect->width + 63) / 64;
2243 idxBottom = (rect->y + rect->height + 63) / 64;
2245 if (idxLeft < boxLeft)
2248 if (idxTop < boxTop)
2251 if (idxRight > boxRight)
2252 boxRight = idxRight;
2254 if (idxBottom > boxBottom)
2255 boxBottom = idxBottom;
2257#if defined(WITH_DEBUG_CODECS)
2258 WLog_Print(progressive->log, WLOG_DEBUG,
2259 "rect[%" PRIu16
"]: x: %" PRIu16
" y: %" PRIu16
" w: %" PRIu16
" h: %" PRIu16
"",
2260 index, rect->x, rect->y, rect->width, rect->height);
2264 const SSIZE_T res = progressive_process_tiles(progressive, s, region, surface, context);
2270static inline SSIZE_T progressive_parse_block(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2273 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2275 UINT16 blockType = 0;
2276 UINT32 blockLen = 0;
2278 wStream sub = WINPR_C_ARRAY_INIT;
2280 WINPR_ASSERT(progressive);
2282 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
2285 Stream_Read_UINT16(s, blockType);
2286 Stream_Read_UINT32(s, blockLen);
2290 WLog_WARN(TAG,
"Invalid blockLen %" PRIu32
", expected >= 6", blockLen);
2293 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
2295 Stream_StaticConstInit(&sub, Stream_Pointer(s), blockLen - 6);
2296 Stream_Seek(s, blockLen - 6);
2300 case PROGRESSIVE_WBT_SYNC:
2301 rc = progressive_wb_sync(progressive, &sub, blockType, blockLen);
2304 case PROGRESSIVE_WBT_FRAME_BEGIN:
2305 rc = progressive_wb_frame_begin(progressive, &sub, blockType, blockLen);
2308 case PROGRESSIVE_WBT_FRAME_END:
2309 rc = progressive_wb_frame_end(progressive, &sub, blockType, blockLen);
2312 case PROGRESSIVE_WBT_CONTEXT:
2313 rc = progressive_wb_context(progressive, &sub, blockType, blockLen);
2316 case PROGRESSIVE_WBT_REGION:
2317 rc = progressive_wb_region(progressive, &sub, blockType, blockLen, surface, region);
2321 WLog_Print(progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16, blockType);
2328 if (Stream_GetRemainingLength(&sub) > 0)
2330 WLog_Print(progressive->log, WLOG_ERROR,
2331 "block len %" PRIu32
" does not match read data %" PRIuz, blockLen,
2332 blockLen - Stream_GetRemainingLength(&sub));
2339static inline BOOL update_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2341 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2342 UINT32 nXDst, UINT32 nYDst,
2343 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
2344 REGION16* WINPR_RESTRICT invalidRegion)
2347 REGION16 clippingRects = WINPR_C_ARRAY_INIT;
2348 region16_init(&clippingRects);
2350 for (UINT32 i = 0; i < region->numRects; i++)
2353 const RFX_RECT* rect = &(region->rects[i]);
2355 clippingRect.left = (UINT16)nXDst + rect->x;
2356 clippingRect.top = (UINT16)nYDst + rect->y;
2357 clippingRect.right = clippingRect.left + rect->width;
2358 clippingRect.bottom = clippingRect.top + rect->height;
2359 if (!region16_union_rect(&clippingRects, &clippingRects, &clippingRect))
2361 region16_uninit(&clippingRects);
2366 for (UINT32 i = 0; i < surface->numUpdatedTiles; i++)
2368 UINT32 nbUpdateRects = 0;
2372 WINPR_ASSERT(surface->updatedTileIndices);
2373 const UINT32 index = surface->updatedTileIndices[i];
2375 WINPR_ASSERT(index < surface->tilesSize);
2379 const UINT32 dl = nXDst + tile->x;
2380 updateRect.left = WINPR_ASSERTING_INT_CAST(UINT16, dl);
2382 const UINT32 dt = nYDst + tile->y;
2383 updateRect.top = WINPR_ASSERTING_INT_CAST(UINT16, dt);
2384 updateRect.right = updateRect.left + 64;
2385 updateRect.bottom = updateRect.top + 64;
2387 REGION16 updateRegion = WINPR_C_ARRAY_INIT;
2388 region16_init(&updateRegion);
2389 if (!region16_intersect_rect(&updateRegion, &clippingRects, &updateRect))
2391 region16_uninit(&updateRegion);
2394 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
2396 for (UINT32 j = 0; j < nbUpdateRects; j++)
2400 if (rect->left < updateRect.left)
2402 const UINT32 nXSrc = rect->left - updateRect.left;
2403 const UINT32 nYSrc = rect->top - updateRect.top;
2404 const UINT32 width = rect->right - rect->left;
2405 const UINT32 height = rect->bottom - rect->top;
2407 if (rect->left + width > surface->width)
2409 if (rect->top + height > surface->height)
2411 rc = freerdp_image_copy_no_overlap(
2412 pDstData, DstFormat, nDstStep, rect->left, rect->top, width, height, tile->data,
2413 progressive->format, tile->stride, nXSrc, nYSrc,
nullptr, FREERDP_KEEP_DST_ALPHA);
2419 if (!region16_union_rect(invalidRegion, invalidRegion, rect))
2421 region16_uninit(&updateRegion);
2427 region16_uninit(&updateRegion);
2430 tile->dirty = FALSE;
2434 region16_uninit(&clippingRects);
2438INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2439 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
2440 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2441 UINT32 nXDst, UINT32 nYDst,
REGION16* WINPR_RESTRICT invalidRegion,
2442 UINT16 surfaceId, UINT32 frameId)
2446 WINPR_ASSERT(progressive);
2451 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion no surface for %" PRIu16,
2456 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2457 WINPR_ASSERT(region);
2459 if (surface->frameId != frameId)
2461 surface->frameId = frameId;
2462 surface->numUpdatedTiles = 0;
2465 wStream ss = WINPR_C_ARRAY_INIT;
2466 wStream* s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
2471 case PIXEL_FORMAT_RGBA32:
2472 case PIXEL_FORMAT_RGBX32:
2473 case PIXEL_FORMAT_BGRA32:
2474 case PIXEL_FORMAT_BGRX32:
2475 progressive->format = DstFormat;
2478 progressive->format = PIXEL_FORMAT_XRGB32;
2482 const size_t start = Stream_GetPosition(s);
2483 progressive->state = 0;
2484 while (Stream_GetRemainingLength(s) > 0)
2486 if (progressive_parse_block(progressive, s, surface, region) < 0)
2491 const size_t end = Stream_GetPosition(s);
2492 if ((end - start) != SrcSize)
2494 WLog_Print(progressive->log, WLOG_ERROR,
2495 "total block len %" PRIuz
" does not match read data %" PRIu32, end - start,
2502 if (!update_tiles(progressive, surface, pDstData, DstFormat, nDstStep, nXDst, nYDst, region,
2509BOOL progressive_rfx_write_message_progressive_simple(
2510 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s,
2511 const RFX_MESSAGE* WINPR_RESTRICT msg)
2513 RFX_CONTEXT* context =
nullptr;
2515 WINPR_ASSERT(progressive);
2518 context = progressive->rfx_context;
2519 return rfx_write_message_progressive_simple(context, s, msg);
2522int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2523 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 SrcFormat,
2524 UINT32 Width, UINT32 Height, UINT32 ScanLine,
2525 const REGION16* WINPR_RESTRICT invalidRegion,
2526 BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize)
2531 UINT32 numRects = 0;
2533 RFX_MESSAGE* message =
nullptr;
2535 if (!progressive || !pSrcData || !ppDstData || !pDstSize)
2544 case PIXEL_FORMAT_ABGR32:
2545 case PIXEL_FORMAT_ARGB32:
2546 case PIXEL_FORMAT_XBGR32:
2547 case PIXEL_FORMAT_XRGB32:
2548 case PIXEL_FORMAT_BGRA32:
2549 case PIXEL_FORMAT_BGRX32:
2550 case PIXEL_FORMAT_RGBA32:
2551 case PIXEL_FORMAT_RGBX32:
2552 ScanLine = Width * 4;
2559 if (SrcSize < Height * ScanLine)
2564 numRects = (Width + 63) / 64;
2565 numRects *= (Height + 63) / 64;
2569 const int nr = region16_n_rects(invalidRegion);
2570 numRects = WINPR_ASSERTING_INT_CAST(uint32_t, nr);
2576 if (!Stream_EnsureRemainingCapacity(progressive->rects, numRects *
sizeof(
RFX_RECT)))
2578 rects = Stream_BufferAs(progressive->rects,
RFX_RECT);
2581 const RECTANGLE_16* region_rects = region16_rects(invalidRegion,
nullptr);
2582 for (UINT32 idx = 0; idx < numRects; idx++)
2589 rect->width = r->right - r->left;
2590 rect->height = r->bottom - r->top;
2598 for (UINT32 i = 0; i < numRects; i++)
2604 WINPR_ASSERT(Width >= x);
2605 WINPR_ASSERT(Height >= y);
2606 r->width = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Width - x));
2607 r->height = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Height - y));
2609 if (x + 64UL >= Width)
2617 WINPR_ASSERT(r->x % 64 == 0);
2618 WINPR_ASSERT(r->y % 64 == 0);
2619 WINPR_ASSERT(r->width <= 64);
2620 WINPR_ASSERT(r->height <= 64);
2623 s = progressive->buffer;
2624 Stream_ResetPosition(s);
2626 progressive->rfx_context->mode = RLGR1;
2628 progressive->rfx_context->width = WINPR_ASSERTING_INT_CAST(UINT16, Width);
2629 progressive->rfx_context->height = WINPR_ASSERTING_INT_CAST(UINT16, Height);
2630 rfx_context_set_pixel_format(progressive->rfx_context, SrcFormat);
2631 message = rfx_encode_message(progressive->rfx_context, rects, numRects, pSrcData, Width, Height,
2635 WLog_ERR(TAG,
"failed to encode rfx message");
2639 rc = progressive_rfx_write_message_progressive_simple(progressive, s, message);
2640 rfx_message_free(progressive->rfx_context, message);
2645 const size_t pos = Stream_GetPosition(s);
2646 WINPR_ASSERT(pos <= UINT32_MAX);
2647 *pDstSize = (UINT32)pos;
2649 *ppDstData = Stream_Buffer(s);
2655BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive)
2657 return (progressive !=
nullptr);
2660PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
2662 return progressive_context_new_ex(Compressor, 0);
2665PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, UINT32 ThreadingFlags)
2667 PROGRESSIVE_CONTEXT* progressive =
2668 (PROGRESSIVE_CONTEXT*)winpr_aligned_calloc(1,
sizeof(PROGRESSIVE_CONTEXT), 32);
2673 progressive->Compressor = Compressor;
2674 progressive->quantProgValFull.quality = 100;
2675 progressive->log = WLog_Get(TAG);
2676 if (!progressive->log)
2678 progressive->rfx_context = rfx_context_new_ex(Compressor, ThreadingFlags);
2679 if (!progressive->rfx_context)
2681 progressive->buffer = Stream_New(
nullptr, 1024);
2682 if (!progressive->buffer)
2684 progressive->rects = Stream_New(
nullptr, 1024);
2685 if (!progressive->rects)
2687 progressive->bufferPool = BufferPool_New(TRUE, (8192LL + 32LL) * 3LL, 16);
2688 if (!progressive->bufferPool)
2690 progressive->SurfaceContexts = HashTable_New(TRUE);
2691 if (!progressive->SurfaceContexts)
2695 wObject* obj = HashTable_ValueObject(progressive->SurfaceContexts);
2701 WINPR_PRAGMA_DIAG_PUSH
2702 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2703 progressive_context_free(progressive);
2704 WINPR_PRAGMA_DIAG_POP
2708void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
2713 Stream_Free(progressive->buffer, TRUE);
2714 Stream_Free(progressive->rects, TRUE);
2715 rfx_context_free(progressive->rfx_context);
2717 BufferPool_Free(progressive->bufferPool);
2718 HashTable_Free(progressive->SurfaceContexts);
2720 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