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);
404 UINT32 gridSize = surface->gridSize;
408 while (gridSize < min)
410 if (gridSize > UINT32_MAX - 1024)
420 surface->tilesSize = gridSize;
423 for (
size_t x = oldIndex; x < surface->tilesSize; x++)
425 surface->tiles[x] = progressive_tile_new();
426 if (!surface->tiles[x])
430 tmp = winpr_aligned_recalloc(surface->updatedTileIndices, gridSize,
sizeof(UINT32), 32);
434 surface->gridSize = gridSize;
435 surface->updatedTileIndices = tmp;
449 surface->id = surfaceId;
450 surface->width = width;
451 surface->height = height;
452 surface->gridWidth = (width + (64 - width % 64)) / 64;
453 surface->gridHeight = (height + (64 - height % 64)) / 64;
454 surface->gridSize = surface->gridWidth * surface->gridHeight;
456 if (!progressive_allocate_tile_cache(surface, surface->gridSize))
458 progressive_surface_context_free(surface);
467 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
473 if (!surface || !tile)
476 zIdx = (tile->yIdx * surface->gridWidth) + tile->xIdx;
478 if (zIdx >= surface->tilesSize)
480 WLog_ERR(TAG,
"Invalid zIndex %" PRIuz, zIdx);
484 t = surface->tiles[zIdx];
486 t->blockType = tile->blockType;
487 t->blockLen = tile->blockLen;
488 t->quantIdxY = tile->quantIdxY;
489 t->quantIdxCb = tile->quantIdxCb;
490 t->quantIdxCr = tile->quantIdxCr;
491 t->xIdx = tile->xIdx;
492 t->yIdx = tile->yIdx;
493 t->flags = tile->flags;
494 t->quality = tile->quality;
495 t->x = tile->xIdx * t->width;
496 t->y = tile->yIdx * t->height;
500 t->ySrlLen = tile->ySrlLen;
501 t->yRawLen = tile->yRawLen;
502 t->cbSrlLen = tile->cbSrlLen;
503 t->cbRawLen = tile->cbRawLen;
504 t->crSrlLen = tile->crSrlLen;
505 t->crRawLen = tile->crRawLen;
506 t->ySrlData = tile->ySrlData;
507 t->yRawData = tile->yRawData;
508 t->cbSrlData = tile->cbSrlData;
509 t->cbRawData = tile->cbRawData;
510 t->crSrlData = tile->crSrlData;
511 t->crRawData = tile->crRawData;
515 t->yLen = tile->yLen;
516 t->cbLen = tile->cbLen;
517 t->crLen = tile->crLen;
518 t->tailLen = tile->tailLen;
519 t->yData = tile->yData;
520 t->cbData = tile->cbData;
521 t->crData = tile->crData;
522 t->tailData = tile->tailData;
525 if (region->usedTiles >= region->numTiles)
527 WLog_ERR(TAG,
"Invalid tile count, only expected %" PRIu16
", got %" PRIu16,
528 region->numTiles, region->usedTiles);
532 region->tiles[region->usedTiles++] = t;
535 if (surface->numUpdatedTiles >= surface->gridSize)
537 if (!progressive_allocate_tile_cache(surface, surface->numUpdatedTiles + 1))
541 surface->updatedTileIndices[surface->numUpdatedTiles++] = (UINT32)zIdx;
548INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
549 UINT16 surfaceId, UINT32 width, UINT32 height)
555 surface = progressive_surface_context_new(surfaceId, width, height);
560 if (!progressive_set_surface_data(progressive, surfaceId, (
void*)surface))
562 progressive_surface_context_free(surface);
570int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
573 progressive_set_surface_data(progressive, surfaceId,
nullptr);
596static int16_t clampi16(
int val)
605static inline void progressive_rfx_idwt_x(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
606 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
607 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
608 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
613 for (
size_t i = 0; i < nDstCount; i++)
615 const INT16* pL = pLowBand;
616 const INT16* pH = pHighBand;
617 INT16* pX = pDstBand;
620 INT16 X0 = clampi16((int32_t)L0 - H0);
621 INT16 X2 = clampi16((int32_t)L0 - H0);
623 for (
size_t j = 0; j < (nHighCount - 1); j++)
629 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
630 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
638 if (nLowCount <= (nHighCount + 1))
640 if (nLowCount <= nHighCount)
643 pX[1] = clampi16((int32_t)X2 + (2 * H0));
649 X0 = clampi16((int32_t)L0 - H0);
651 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
659 X0 = clampi16((int32_t)L0 - (H0 / 2));
661 pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
665 pX[3] = clampi16((int32_t)(X0 + L0) / 2);
668 pLowBand += nLowStep;
669 pHighBand += nHighStep;
670 pDstBand += nDstStep;
674static inline void progressive_rfx_idwt_y(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
675 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
676 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
677 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
679 for (
size_t i = 0; i < nDstCount; i++)
683 const INT16* pL = pLowBand;
684 const INT16* pH = pHighBand;
685 INT16* pX = pDstBand;
690 int16_t X0 = clampi16((int32_t)L0 - H0);
691 int16_t X2 = clampi16((int32_t)L0 - H0);
693 for (
size_t j = 0; j < (nHighCount - 1); j++)
699 X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
700 X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
709 if (nLowCount <= (nHighCount + 1))
711 if (nLowCount <= nHighCount)
715 *pX = clampi16((int32_t)X2 + (2 * H0));
720 X0 = clampi16((int32_t)L0 - H0);
723 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
732 X0 = clampi16((int32_t)L0 - (H0 / 2));
735 *pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
740 *pX = clampi16((int32_t)(X0 + L0) / 2);
749static inline size_t progressive_rfx_get_band_l_count(
size_t level)
751 return (64 >> level) + 1;
754static inline size_t progressive_rfx_get_band_h_count(
size_t level)
757 return (64 >> 1) - 1;
759 return (64 + (1u << (level - 1))) >> level;
762static inline void progressive_rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer,
763 INT16* WINPR_RESTRICT temp,
size_t level)
765 size_t nDstStepX = 0;
766 size_t nDstStepY = 0;
767 const INT16* WINPR_RESTRICT HL =
nullptr;
768 const INT16* WINPR_RESTRICT LH =
nullptr;
769 const INT16* WINPR_RESTRICT HH =
nullptr;
770 INT16* WINPR_RESTRICT LL =
nullptr;
771 INT16* WINPR_RESTRICT L =
nullptr;
772 INT16* WINPR_RESTRICT H =
nullptr;
773 INT16* WINPR_RESTRICT LLx =
nullptr;
775 const size_t nBandL = progressive_rfx_get_band_l_count(level);
776 const size_t nBandH = progressive_rfx_get_band_h_count(level);
779 HL = &buffer[offset];
780 offset += (nBandH * nBandL);
781 LH = &buffer[offset];
782 offset += (nBandL * nBandH);
783 HH = &buffer[offset];
784 offset += (nBandH * nBandH);
785 LL = &buffer[offset];
786 nDstStepX = (nBandL + nBandH);
787 nDstStepY = (nBandL + nBandH);
790 offset += (nBandL * nDstStepX);
795 progressive_rfx_idwt_x(LL, nBandL, HL, nBandH, L, nDstStepX, nBandL, nBandH, nBandL);
798 progressive_rfx_idwt_x(LH, nBandL, HH, nBandH, H, nDstStepX, nBandL, nBandH, nBandH);
801 progressive_rfx_idwt_y(L, nDstStepX, H, nDstStepX, LLx, nDstStepY, nBandL, nBandH,
805void rfx_dwt_2d_extrapolate_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
807 WINPR_ASSERT(buffer);
808 WINPR_ASSERT(dwt_buffer);
809 progressive_rfx_dwt_2d_decode_block(&buffer[3807], dwt_buffer, 3);
810 progressive_rfx_dwt_2d_decode_block(&buffer[3007], dwt_buffer, 2);
811 progressive_rfx_dwt_2d_decode_block(&buffer[0], dwt_buffer, 1);
814static inline int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
815 INT16* WINPR_RESTRICT buffer,
816 INT16* WINPR_RESTRICT current, BOOL coeffDiff,
817 BOOL extrapolate, BOOL reverse)
821 if (!progressive || !buffer || !current)
824 const uint32_t belements = 4096;
825 const uint32_t bsize = belements *
sizeof(INT16);
827 memcpy(buffer, current, bsize);
829 memcpy(current, buffer, bsize);
832 const pstatus_t rc = prims->
add_16s_inplace(buffer, current, belements);
833 if (rc != PRIMITIVES_SUCCESS)
837 INT16* temp = (INT16*)BufferPool_Take(progressive->bufferPool, -1);
844 progressive->rfx_context->dwt_2d_decode(buffer, temp);
848 WINPR_ASSERT(progressive->rfx_context->dwt_2d_extrapolate_decode);
849 progressive->rfx_context->dwt_2d_extrapolate_decode(buffer, temp);
851 BufferPool_Return(progressive->bufferPool, temp);
855static inline BOOL progressive_rfx_decode_block(
const primitives_t* prims,
856 INT16* WINPR_RESTRICT buffer, UINT32 length,
866progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
868 const BYTE* WINPR_RESTRICT data, UINT32 length,
869 INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
870 INT16* WINPR_RESTRICT sign, BOOL coeffDiff,
871 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
876 status = progressive->rfx_context->rlgr_decode(RLGR1, data, length, buffer, 4096);
881 CopyMemory(sign, buffer, 4096ULL * 2ULL);
884 if (!rfx_differential_decode(buffer + 4032, 64))
886 if (!progressive_rfx_decode_block(prims, &buffer[0], 1024, shift->HL1))
888 if (!progressive_rfx_decode_block(prims, &buffer[1024], 1024, shift->LH1))
890 if (!progressive_rfx_decode_block(prims, &buffer[2048], 1024, shift->HH1))
892 if (!progressive_rfx_decode_block(prims, &buffer[3072], 256, shift->HL2))
894 if (!progressive_rfx_decode_block(prims, &buffer[3328], 256, shift->LH2))
896 if (!progressive_rfx_decode_block(prims, &buffer[3584], 256, shift->HH2))
898 if (!progressive_rfx_decode_block(prims, &buffer[3840], 64, shift->HL3))
900 if (!progressive_rfx_decode_block(prims, &buffer[3904], 64, shift->LH3))
902 if (!progressive_rfx_decode_block(prims, &buffer[3968], 64, shift->HH3))
904 if (!progressive_rfx_decode_block(prims, &buffer[4032], 64, shift->LL3))
909 if (!progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1))
911 if (!progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1))
913 if (!progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1))
915 if (!progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2))
917 if (!progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2))
919 if (!progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2))
921 if (!progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3))
923 if (!progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3))
925 if (!progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3))
927 if (!rfx_differential_decode(&buffer[4015], 81))
929 if (!progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3))
932 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
937progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
939 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
945 BOOL extrapolate = 0;
946 BYTE* pBuffer =
nullptr;
964 diff = tile->flags & RFX_TILE_DIFFERENCE;
965 sub = context->flags & RFX_SUBBAND_DIFFING;
966 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
968#if defined(WITH_DEBUG_CODECS)
969 WLog_Print(progressive->log, WLOG_DEBUG,
970 "ProgressiveTile%s: quantIdx Y: %" PRIu8
" Cb: %" PRIu8
" Cr: %" PRIu8
971 " xIdx: %" PRIu16
" yIdx: %" PRIu16
" flags: 0x%02" PRIX8
" quality: %" PRIu8
972 " yLen: %" PRIu16
" cbLen: %" PRIu16
" crLen: %" PRIu16
" tailLen: %" PRIu16
"",
973 (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ?
"First" :
"Simple",
974 tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx,
975 tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
978 if (tile->quantIdxY >= region->numQuant)
980 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
984 quantY = &(region->quantVals[tile->quantIdxY]);
986 if (tile->quantIdxCb >= region->numQuant)
988 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
993 quantCb = &(region->quantVals[tile->quantIdxCb]);
995 if (tile->quantIdxCr >= region->numQuant)
997 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1002 quantCr = &(region->quantVals[tile->quantIdxCr]);
1004 if (tile->quality == 0xFF)
1006 quantProgVal = &(progressive->quantProgValFull);
1010 if (tile->quality >= region->numProgQuant)
1012 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1013 region->numProgQuant);
1017 quantProgVal = &(region->quantProgVals[tile->quality]);
1020 quantProgY = &(quantProgVal->yQuantValues);
1021 quantProgCb = &(quantProgVal->cbQuantValues);
1022 quantProgCr = &(quantProgVal->crQuantValues);
1024 tile->yQuant = *quantY;
1025 tile->cbQuant = *quantCb;
1026 tile->crQuant = *quantCr;
1027 tile->yProgQuant = *quantProgY;
1028 tile->cbProgQuant = *quantProgCb;
1029 tile->crProgQuant = *quantProgCr;
1031 progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
1032 progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
1033 progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
1034 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1035 if (!progressive_rfx_quant_lsub(&shiftY, 1))
1037 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1038 if (!progressive_rfx_quant_lsub(&shiftCb, 1))
1040 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1041 if (!progressive_rfx_quant_lsub(&shiftCr, 1))
1045 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 0) + 16]));
1047 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 1) + 16]));
1049 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 2) + 16]));
1052 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 0) + 16]));
1054 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 1) + 16]));
1056 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 2) + 16]));
1058 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1060 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 0) + 16]));
1062 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 1) + 16]));
1064 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 2) + 16]));
1066 rc = progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0],
1067 pCurrent[0], pSign[0], diff, sub, extrapolate);
1070 rc = progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen,
1071 pSrcDst[1], pCurrent[1], pSign[1], diff, sub,
1075 rc = progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen,
1076 pSrcDst[2], pCurrent[2], pSign[2], diff, sub,
1082 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1083 rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1084 progressive->format, &roi_64x64);
1087 BufferPool_Return(progressive->bufferPool, pBuffer);
1091static inline INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1094 WINPR_ASSERT(state);
1105 const UINT32 k = state->kp / 8;
1110 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1111 BitStream_Shift(bs, 1);
1116 state->nz = (1 << k);
1133 bs->mask = ((1u << k) - 1);
1135 WINPR_ASSERTING_INT_CAST(int16_t, ((bs->accumulator >> (32u - k)) & bs->mask));
1136 BitStream_Shift(bs, k);
1150 const UINT32 sign = (bs->accumulator & 0x80000000) ? 1 : 0;
1151 BitStream_Shift(bs, 1);
1159 return sign ? -1 : 1;
1162 const UINT32 max = (1u << numBits) - 1;
1166 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1167 BitStream_Shift(bs, 1);
1175 if (mag > INT16_MAX)
1177 return (INT16)(sign ? -1 * (int)mag : (INT16)mag);
1181progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state)
1192 pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
1195 BitStream_Shift(raw, pad);
1197 pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
1200 BitStream_Shift(srl, pad);
1202 if (BitStream_GetRemainingLength(srl) == 8)
1203 BitStream_Shift(srl, 8);
1208static inline int16_t rawShift(
wBitStream* raw, UINT32 numBits)
1211 WINPR_ASSERT(numBits > 0);
1213 raw->mask = ((1u << numBits) - 1);
1214 const int16_t input = (int16_t)((raw->accumulator >> (32 - numBits)) & raw->mask);
1215 BitStream_Shift(raw, numBits);
1219static inline int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1220 INT16* WINPR_RESTRICT buffer,
1221 INT16* WINPR_RESTRICT sign, UINT32 length,
1222 UINT32 shift, WINPR_ATTR_UNUSED UINT32 bitPos,
1233 for (UINT32 index = 0; index < length; index++)
1235 input = rawShift(raw, numBits);
1237 const int32_t shifted = input << shift;
1238 const int32_t val = buffer[index] + shifted;
1239 const int16_t ival = WINPR_ASSERTING_INT_CAST(int16_t, val);
1240 buffer[index] = ival;
1246 for (UINT32 index = 0; index < length; index++)
1248 if (sign[index] > 0)
1251 input = rawShift(raw, numBits);
1253 else if (sign[index] < 0)
1256 input = rawShift(raw, numBits);
1262 input = progressive_rfx_srl_read(state, numBits);
1263 sign[index] = WINPR_ASSERTING_INT_CAST(int16_t, input);
1266 const int32_t val = input << shift;
1267 const int32_t ival = buffer[index] + val;
1268 buffer[index] = WINPR_ASSERTING_INT_CAST(INT16, ival);
1274static inline int progressive_rfx_upgrade_component(
1275 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1279 INT16* WINPR_RESTRICT current, INT16* WINPR_RESTRICT sign,
const BYTE* WINPR_RESTRICT srlData,
1280 UINT32 srlLen,
const BYTE* WINPR_RESTRICT rawData, UINT32 rawLen, BOOL coeffDiff,
1281 WINPR_ATTR_UNUSED BOOL subbandDiff, BOOL extrapolate)
1286 RFX_PROGRESSIVE_UPGRADE_STATE state = WINPR_C_ARRAY_INIT;
1292 BitStream_Attach(state.srl, srlData, srlLen);
1293 BitStream_Fetch(state.srl);
1294 BitStream_Attach(state.raw, rawData, rawLen);
1295 BitStream_Fetch(state.raw);
1298 rc = progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1,
1302 rc = progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1,
1303 bitPos->LH1, numBits->LH1);
1306 rc = progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1,
1307 bitPos->HH1, numBits->HH1);
1310 rc = progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2,
1311 bitPos->HL2, numBits->HL2);
1314 rc = progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2,
1315 bitPos->LH2, numBits->LH2);
1318 rc = progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2,
1319 bitPos->HH2, numBits->HH2);
1322 rc = progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3,
1323 bitPos->HL3, numBits->HL3);
1326 rc = progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3,
1327 bitPos->LH3, numBits->LH3);
1330 rc = progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3,
1331 bitPos->HH3, numBits->HH3);
1335 state.nonLL = FALSE;
1336 rc = progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3,
1337 bitPos->LL3, numBits->LL3);
1340 rc = progressive_rfx_upgrade_state_finish(&state);
1343 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
1348progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1350 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1356 BOOL extrapolate = 0;
1357 BYTE* pBuffer =
nullptr;
1358 INT16* pSign[3] = WINPR_C_ARRAY_INIT;
1359 INT16* pSrcDst[3] = WINPR_C_ARRAY_INIT;
1360 INT16* pCurrent[3] = WINPR_C_ARRAY_INIT;
1380 coeffDiff = tile->flags & RFX_TILE_DIFFERENCE;
1381 sub = context->flags & RFX_SUBBAND_DIFFING;
1382 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
1386#if defined(WITH_DEBUG_CODECS)
1387 WLog_Print(progressive->log, WLOG_DEBUG,
1388 "ProgressiveTileUpgrade: pass: %" PRIu16
" quantIdx Y: %" PRIu8
" Cb: %" PRIu8
1389 " Cr: %" PRIu8
" xIdx: %" PRIu16
" yIdx: %" PRIu16
" quality: %" PRIu8
1390 " ySrlLen: %" PRIu16
" yRawLen: %" PRIu16
" cbSrlLen: %" PRIu16
" cbRawLen: %" PRIu16
1391 " crSrlLen: %" PRIu16
" crRawLen: %" PRIu16
"",
1392 tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx,
1393 tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen,
1394 tile->cbRawLen, tile->crSrlLen, tile->crRawLen);
1397 if (tile->quantIdxY >= region->numQuant)
1399 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
1403 quantY = &(region->quantVals[tile->quantIdxY]);
1405 if (tile->quantIdxCb >= region->numQuant)
1407 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
1412 quantCb = &(region->quantVals[tile->quantIdxCb]);
1414 if (tile->quantIdxCr >= region->numQuant)
1416 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1421 quantCr = &(region->quantVals[tile->quantIdxCr]);
1423 if (tile->quality == 0xFF)
1425 quantProg = &(progressive->quantProgValFull);
1429 if (tile->quality >= region->numProgQuant)
1431 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1432 region->numProgQuant);
1436 quantProg = &(region->quantProgVals[tile->quality]);
1439 quantProgY = &(quantProg->yQuantValues);
1440 quantProgCb = &(quantProg->cbQuantValues);
1441 quantProgCr = &(quantProg->crQuantValues);
1443 if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
1444 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantY has changed!");
1446 if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
1447 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCb has changed!");
1449 if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
1450 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCr has changed!");
1452 if (!(context->flags & RFX_SUBBAND_DIFFING))
1453 WLog_WARN(TAG,
"PROGRESSIVE_BLOCK_CONTEXT::flags & RFX_SUBBAND_DIFFING not set");
1455 progressive_rfx_quant_add(quantY, quantProgY, &yBitPos);
1456 progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos);
1457 progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos);
1458 if (!progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits))
1460 if (!progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits))
1462 if (!progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits))
1464 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1465 if (!progressive_rfx_quant_lsub(&shiftY, 1))
1467 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1468 if (!progressive_rfx_quant_lsub(&shiftCb, 1))
1470 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1471 if (!progressive_rfx_quant_lsub(&shiftCr, 1))
1474 tile->yBitPos = yBitPos;
1475 tile->cbBitPos = cbBitPos;
1476 tile->crBitPos = crBitPos;
1477 tile->yQuant = *quantY;
1478 tile->cbQuant = *quantCb;
1479 tile->crQuant = *quantCr;
1480 tile->yProgQuant = *quantProgY;
1481 tile->cbProgQuant = *quantProgCb;
1482 tile->crProgQuant = *quantProgCr;
1485 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 0) + 16]));
1487 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 1) + 16]));
1489 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->sign[((8192 + 32) * 2) + 16]));
1492 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 0) + 16]));
1494 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 1) + 16]));
1496 WINPR_PACKED_ALIGN_CAST(INT16*, (&tile->current[((8192 + 32) * 2) + 16]));
1498 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1500 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 0) + 16]));
1502 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 1) + 16]));
1504 WINPR_PACKED_ALIGN_CAST(INT16*, (&pBuffer[((8192 + 32) * 2) + 16]));
1506 status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
1507 pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData,
1508 tile->ySrlLen, tile->yRawData, tile->yRawLen,
1509 coeffDiff, sub, extrapolate);
1514 status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
1515 pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData,
1516 tile->cbSrlLen, tile->cbRawData, tile->cbRawLen,
1517 coeffDiff, sub, extrapolate);
1522 status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
1523 pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData,
1524 tile->crSrlLen, tile->crRawData, tile->crRawLen,
1525 coeffDiff, sub, extrapolate);
1531 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1532 status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1533 progressive->format, &roi_64x64);
1536 BufferPool_Return(progressive->bufferPool, pBuffer);
1540static inline BOOL progressive_tile_read_upgrade(
1541 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1543 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1547 const size_t expect = 20;
1549 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1552 tile.blockType = blockType;
1553 tile.blockLen = blockLen;
1556 Stream_Read_UINT8(s, tile.quantIdxY);
1557 Stream_Read_UINT8(s, tile.quantIdxCb);
1558 Stream_Read_UINT8(s, tile.quantIdxCr);
1559 Stream_Read_UINT16(s, tile.xIdx);
1560 Stream_Read_UINT16(s, tile.yIdx);
1561 Stream_Read_UINT8(s, tile.quality);
1562 Stream_Read_UINT16(s, tile.ySrlLen);
1563 Stream_Read_UINT16(s, tile.yRawLen);
1564 Stream_Read_UINT16(s, tile.cbSrlLen);
1565 Stream_Read_UINT16(s, tile.cbRawLen);
1566 Stream_Read_UINT16(s, tile.crSrlLen);
1567 Stream_Read_UINT16(s, tile.crRawLen);
1569 tile.ySrlData = Stream_Pointer(s);
1570 if (!Stream_SafeSeek(s, tile.ySrlLen))
1572 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.ySrlLen);
1576 tile.yRawData = Stream_Pointer(s);
1577 if (!Stream_SafeSeek(s, tile.yRawLen))
1579 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yRawLen);
1583 tile.cbSrlData = Stream_Pointer(s);
1584 if (!Stream_SafeSeek(s, tile.cbSrlLen))
1586 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1591 tile.cbRawData = Stream_Pointer(s);
1592 if (!Stream_SafeSeek(s, tile.cbRawLen))
1594 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1599 tile.crSrlData = Stream_Pointer(s);
1600 if (!Stream_SafeSeek(s, tile.crSrlLen))
1602 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1607 tile.crRawData = Stream_Pointer(s);
1608 if (!Stream_SafeSeek(s, tile.crRawLen))
1610 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1615 return progressive_surface_tile_replace(surface, region, &tile, TRUE);
1619progressive_tile_read(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, BOOL simple,
1620 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
1622 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1626 size_t expect = simple ? 16 : 17;
1628 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1631 tile.blockType = blockType;
1632 tile.blockLen = blockLen;
1634 Stream_Read_UINT8(s, tile.quantIdxY);
1635 Stream_Read_UINT8(s, tile.quantIdxCb);
1636 Stream_Read_UINT8(s, tile.quantIdxCr);
1637 Stream_Read_UINT16(s, tile.xIdx);
1638 Stream_Read_UINT16(s, tile.yIdx);
1639 Stream_Read_UINT8(s, tile.flags);
1642 Stream_Read_UINT8(s, tile.quality);
1644 tile.quality = 0xFF;
1645 Stream_Read_UINT16(s, tile.yLen);
1646 Stream_Read_UINT16(s, tile.cbLen);
1647 Stream_Read_UINT16(s, tile.crLen);
1648 Stream_Read_UINT16(s, tile.tailLen);
1650 tile.yData = Stream_Pointer(s);
1651 if (!Stream_SafeSeek(s, tile.yLen))
1653 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yLen);
1657 tile.cbData = Stream_Pointer(s);
1658 if (!Stream_SafeSeek(s, tile.cbLen))
1660 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.cbLen);
1664 tile.crData = Stream_Pointer(s);
1665 if (!Stream_SafeSeek(s, tile.crLen))
1667 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.crLen);
1671 tile.tailData = Stream_Pointer(s);
1672 if (!Stream_SafeSeek(s, tile.tailLen))
1674 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.tailLen);
1678 return progressive_surface_tile_replace(surface, region, &tile, FALSE);
1681static void CALLBACK progressive_process_tiles_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1682 void* context, PTP_WORK work)
1686 WINPR_UNUSED(instance);
1689 switch (param->tile->blockType)
1691 case PROGRESSIVE_WBT_TILE_SIMPLE:
1692 case PROGRESSIVE_WBT_TILE_FIRST:
1693 progressive_decompress_tile_first(param->progressive, param->tile, param->region,
1697 case PROGRESSIVE_WBT_TILE_UPGRADE:
1698 progressive_decompress_tile_upgrade(param->progressive, param->tile, param->region,
1702 WLog_Print(param->progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16
" (%s)",
1703 param->tile->blockType,
1704 rfx_get_progressive_block_type_string(param->tile->blockType));
1709static inline SSIZE_T
1710progressive_process_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1712 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1718 const size_t start = Stream_GetPosition(s);
1719 UINT16 blockType = 0;
1720 UINT32 blockLen = 0;
1722 UINT16 close_cnt = 0;
1724 WINPR_ASSERT(progressive);
1725 WINPR_ASSERT(region);
1727 if (!Stream_CheckAndLogRequiredLength(TAG, s, region->tileDataSize))
1730 while ((Stream_GetRemainingLength(s) >= 6) &&
1731 (region->tileDataSize > (Stream_GetPosition(s) - start)))
1733 const size_t pos = Stream_GetPosition(s);
1735 Stream_Read_UINT16(s, blockType);
1736 Stream_Read_UINT32(s, blockLen);
1738#if defined(WITH_DEBUG_CODECS)
1739 WLog_Print(progressive->log, WLOG_DEBUG,
"%s",
1740 rfx_get_progressive_block_type_string(blockType));
1745 WLog_Print(progressive->log, WLOG_ERROR,
"Expected >= %" PRIu32
" remaining %" PRIu32,
1749 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
1754 case PROGRESSIVE_WBT_TILE_SIMPLE:
1755 if (!progressive_tile_read(progressive, TRUE, s, blockType, blockLen, surface,
1760 case PROGRESSIVE_WBT_TILE_FIRST:
1761 if (!progressive_tile_read(progressive, FALSE, s, blockType, blockLen, surface,
1766 case PROGRESSIVE_WBT_TILE_UPGRADE:
1767 if (!progressive_tile_read_upgrade(progressive, s, blockType, blockLen, surface,
1772 WLog_ERR(TAG,
"Invalid block type %04" PRIx16
" (%s)", blockType,
1773 rfx_get_progressive_block_type_string(blockType));
1777 size_t rem = Stream_GetPosition(s);
1778 if ((rem - pos) != blockLen)
1780 WLog_Print(progressive->log, WLOG_ERROR,
1781 "Actual block read %" PRIuz
" but expected %" PRIu32, rem - pos, blockLen);
1787 end = Stream_GetPosition(s);
1788 if ((end - start) != region->tileDataSize)
1790 WLog_Print(progressive->log, WLOG_ERROR,
1791 "Actual total blocks read %" PRIuz
" but expected %" PRIu32, end - start,
1792 region->tileDataSize);
1796 if (count != region->numTiles)
1798 WLog_Print(progressive->log, WLOG_WARN,
1799 "numTiles inconsistency: actual: %" PRIu32
", expected: %" PRIu16
"\n", count,
1804 for (UINT32 idx = 0; idx < region->numTiles; idx++)
1808 param->progressive = progressive;
1809 param->region = region;
1810 param->context = context;
1813 if (progressive->rfx_context->priv->UseThreads)
1815 progressive->work_objects[idx] = CreateThreadpoolWork(
1816 progressive_process_tiles_tile_work_callback, (
void*)param,
nullptr);
1817 if (!progressive->work_objects[idx])
1819 WLog_Print(progressive->log, WLOG_ERROR,
1820 "Failed to create ThreadpoolWork for tile %" PRIu32, idx);
1825 SubmitThreadpoolWork(progressive->work_objects[idx]);
1827 close_cnt = WINPR_ASSERTING_INT_CAST(UINT16, idx + 1);
1831 progressive_process_tiles_tile_work_callback(
nullptr, param,
nullptr);
1836 WLog_Print(progressive->log, WLOG_ERROR,
"Failed to decompress %s at %" PRIu16,
1837 rfx_get_progressive_block_type_string(tile->blockType), idx);
1842 if (progressive->rfx_context->priv->UseThreads)
1844 for (UINT32 idx = 0; idx < close_cnt; idx++)
1846 WaitForThreadpoolWorkCallbacks(progressive->work_objects[idx], FALSE);
1847 CloseThreadpoolWork(progressive->work_objects[idx]);
1856 return (SSIZE_T)(end - start);
1859static inline SSIZE_T progressive_wb_sync(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1860 wStream* WINPR_RESTRICT s, UINT16 blockType,
1863 const UINT32 magic = 0xCACCACCA;
1864 const UINT16 version = 0x0100;
1867 sync.blockType = blockType;
1868 sync.blockLen = blockLen;
1870 if (sync.blockLen != 12)
1872 WLog_Print(progressive->log, WLOG_ERROR,
1873 "PROGRESSIVE_BLOCK_SYNC::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1874 sync.blockLen, 12u);
1878 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1881#if defined(WITH_DEBUG_CODECS)
1882 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveSync");
1885 Stream_Read_UINT32(s, sync.magic);
1886 Stream_Read_UINT16(s, sync.version);
1888 if (sync.magic != magic)
1890 WLog_Print(progressive->log, WLOG_ERROR,
1891 "PROGRESSIVE_BLOCK_SYNC::magic = 0x%08" PRIx32
" != 0x%08" PRIx32, sync.magic,
1896 if (sync.version != 0x0100)
1898 WLog_Print(progressive->log, WLOG_ERROR,
1899 "PROGRESSIVE_BLOCK_SYNC::version = 0x%04" PRIx16
" != 0x%04" PRIu16,
1900 sync.version, version);
1904 if ((progressive->state & FLAG_WBT_SYNC) != 0)
1905 WLog_WARN(TAG,
"Duplicate PROGRESSIVE_BLOCK_SYNC, ignoring");
1907 progressive->state |= FLAG_WBT_SYNC;
1911static inline SSIZE_T progressive_wb_frame_begin(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1912 wStream* WINPR_RESTRICT s, UINT16 blockType,
1917 frameBegin.blockType = blockType;
1918 frameBegin.blockLen = blockLen;
1920 if (frameBegin.blockLen != 12)
1922 WLog_Print(progressive->log, WLOG_ERROR,
1923 " RFX_PROGRESSIVE_FRAME_BEGIN::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1924 frameBegin.blockLen, 12u);
1928 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1931 Stream_Read_UINT32(s, frameBegin.frameIndex);
1932 Stream_Read_UINT16(s, frameBegin.regionCount);
1934#if defined(WITH_DEBUG_CODECS)
1935 WLog_Print(progressive->log, WLOG_DEBUG,
1936 "ProgressiveFrameBegin: frameIndex: %" PRIu32
" regionCount: %" PRIu16
"",
1937 frameBegin.frameIndex, frameBegin.regionCount);
1946 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1948 WLog_ERR(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_BEGIN in stream, this is not allowed!");
1952 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1954 WLog_ERR(TAG,
"RFX_PROGRESSIVE_FRAME_BEGIN after RFX_PROGRESSIVE_FRAME_END in stream, this "
1959 progressive->state |= FLAG_WBT_FRAME_BEGIN;
1963static inline SSIZE_T progressive_wb_frame_end(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1964 wStream* WINPR_RESTRICT s, UINT16 blockType,
1969 frameEnd.blockType = blockType;
1970 frameEnd.blockLen = blockLen;
1972 if (frameEnd.blockLen != 6)
1974 WLog_Print(progressive->log, WLOG_ERROR,
1975 " RFX_PROGRESSIVE_FRAME_END::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1976 frameEnd.blockLen, 6u);
1980 if (Stream_GetRemainingLength(s) != 0)
1982 WLog_Print(progressive->log, WLOG_ERROR,
1983 "ProgressiveFrameEnd short %" PRIuz
", expected %u",
1984 Stream_GetRemainingLength(s), 0U);
1988#if defined(WITH_DEBUG_CODECS)
1989 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveFrameEnd");
1992 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
1993 WLog_WARN(TAG,
"RFX_PROGRESSIVE_FRAME_END before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
1994 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1995 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_END, ignoring");
1997 progressive->state |= FLAG_WBT_FRAME_END;
2001static inline SSIZE_T progressive_wb_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2002 wStream* WINPR_RESTRICT s, UINT16 blockType,
2006 context->blockType = blockType;
2007 context->blockLen = blockLen;
2009 if (context->blockLen != 10)
2011 WLog_Print(progressive->log, WLOG_ERROR,
2012 "RFX_PROGRESSIVE_CONTEXT::blockLen = 0x%08" PRIx32
" != 0x%08x",
2013 context->blockLen, 10u);
2017 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2020 Stream_Read_UINT8(s, context->ctxId);
2021 Stream_Read_UINT16(s, context->tileSize);
2022 Stream_Read_UINT8(s, context->flags);
2024 if (context->ctxId != 0x00)
2025 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT::ctxId != 0x00: %" PRIu8, context->ctxId);
2027 if (context->tileSize != 64)
2029 WLog_ERR(TAG,
"RFX_PROGRESSIVE_CONTEXT::tileSize != 0x40: %" PRIu16, context->tileSize);
2033 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
2034 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_BEGIN");
2035 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2036 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_END");
2037 if ((progressive->state & FLAG_WBT_CONTEXT) != 0)
2038 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_CONTEXT received, ignoring.");
2040#if defined(WITH_DEBUG_CODECS)
2041 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveContext: flags: 0x%02" PRIX8
"",
2045 progressive->state |= FLAG_WBT_CONTEXT;
2049static inline SSIZE_T
2050progressive_wb_read_region_header(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2051 wStream* WINPR_RESTRICT s, UINT16 blockType, UINT32 blockLen,
2052 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2054 region->usedTiles = 0;
2056 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2059 region->blockType = blockType;
2060 region->blockLen = blockLen;
2061 Stream_Read_UINT8(s, region->tileSize);
2062 Stream_Read_UINT16(s, region->numRects);
2063 Stream_Read_UINT8(s, region->numQuant);
2064 Stream_Read_UINT8(s, region->numProgQuant);
2065 Stream_Read_UINT8(s, region->flags);
2066 Stream_Read_UINT16(s, region->numTiles);
2067 Stream_Read_UINT32(s, region->tileDataSize);
2069 if (region->tileSize != 64)
2071 WLog_Print(progressive->log, WLOG_ERROR,
2072 "ProgressiveRegion tile size %" PRIu8
", expected %u", region->tileSize, 64U);
2076 if (region->numRects < 1)
2078 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion missing rect count %" PRIu16,
2083 if (region->numQuant > 7)
2085 WLog_Print(progressive->log, WLOG_ERROR,
2086 "ProgressiveRegion quant count too high %" PRIu8
", expected < %u",
2087 region->numQuant, 7U);
2091 const SSIZE_T rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, Stream_GetRemainingLength(s));
2092 const SSIZE_T expect = region->numRects * 8ll + region->numQuant * 5ll +
2093 region->numProgQuant * 16ll + region->tileDataSize;
2097 if (len / 8LL < region->numRects)
2099 WLog_Print(progressive->log, WLOG_ERROR,
2100 "ProgressiveRegion data short for region->rects");
2103 len -= region->numRects * 8LL;
2105 if (len / 5LL < region->numQuant)
2107 WLog_Print(progressive->log, WLOG_ERROR,
2108 "ProgressiveRegion data short for region->cQuant");
2111 len -= region->numQuant * 5LL;
2113 if (len / 16LL < region->numProgQuant)
2115 WLog_Print(progressive->log, WLOG_ERROR,
2116 "ProgressiveRegion data short for region->cProgQuant");
2119 len -= region->numProgQuant * 16LL;
2121 if (len < region->tileDataSize * 1ll)
2123 WLog_Print(progressive->log, WLOG_ERROR,
2124 "ProgressiveRegion data short for region->tiles");
2127 len -= region->tileDataSize;
2130 WLog_Print(progressive->log, WLOG_WARN,
2131 "Unused bytes detected, %" PRIdz
" bytes not processed", len);
2137static inline SSIZE_T progressive_wb_skip_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2138 wStream* WINPR_RESTRICT s, UINT16 blockType,
2141 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2144 progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2148 if (!Stream_SafeSeek(s, WINPR_ASSERTING_INT_CAST(
size_t, rc)))
2154static inline SSIZE_T progressive_wb_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2155 wStream* WINPR_RESTRICT s, UINT16 blockType,
2158 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2163 UINT16 boxRight = 0;
2164 UINT16 boxBottom = 0;
2167 UINT16 idxRight = 0;
2168 UINT16 idxBottom = 0;
2171 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
2173 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
2174 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2176 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2178 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION after RFX_PROGRESSIVE_FRAME_END, ignoring");
2179 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2182 progressive->state |= FLAG_WBT_REGION;
2184 rc = progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2188 for (UINT16 index = 0; index < region->numRects; index++)
2190 RFX_RECT* rect = &(region->rects[index]);
2191 Stream_Read_UINT16(s, rect->x);
2192 Stream_Read_UINT16(s, rect->y);
2193 Stream_Read_UINT16(s, rect->width);
2194 Stream_Read_UINT16(s, rect->height);
2197 for (BYTE index = 0; index < region->numQuant; index++)
2200 progressive_component_codec_quant_read(s, quantVal);
2202 if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
2204 WLog_Print(progressive->log, WLOG_ERROR,
2205 "ProgressiveRegion region->cQuant[%" PRIu32
"] < 6", index);
2209 if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
2211 WLog_Print(progressive->log, WLOG_ERROR,
2212 "ProgressiveRegion region->cQuant[%" PRIu32
"] > 15", index);
2217 for (BYTE index = 0; index < region->numProgQuant; index++)
2221 Stream_Read_UINT8(s, quantProgVal->quality);
2223 progressive_component_codec_quant_read(s, &(quantProgVal->yQuantValues));
2224 progressive_component_codec_quant_read(s, &(quantProgVal->cbQuantValues));
2225 progressive_component_codec_quant_read(s, &(quantProgVal->crQuantValues));
2228#if defined(WITH_DEBUG_CODECS)
2229 WLog_Print(progressive->log, WLOG_DEBUG,
2230 "ProgressiveRegion: numRects: %" PRIu16
" numTiles: %" PRIu16
2231 " tileDataSize: %" PRIu32
" flags: 0x%02" PRIX8
" numQuant: %" PRIu8
2232 " numProgQuant: %" PRIu8
"",
2233 region->numRects, region->numTiles, region->tileDataSize, region->flags,
2234 region->numQuant, region->numProgQuant);
2237 boxLeft = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridWidth);
2238 boxTop = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridHeight);
2242 for (UINT16 index = 0; index < region->numRects; index++)
2244 RFX_RECT* rect = &(region->rects[index]);
2245 idxLeft = rect->x / 64;
2246 idxTop = rect->y / 64;
2247 idxRight = (rect->x + rect->width + 63) / 64;
2248 idxBottom = (rect->y + rect->height + 63) / 64;
2250 if (idxLeft < boxLeft)
2253 if (idxTop < boxTop)
2256 if (idxRight > boxRight)
2257 boxRight = idxRight;
2259 if (idxBottom > boxBottom)
2260 boxBottom = idxBottom;
2262#if defined(WITH_DEBUG_CODECS)
2263 WLog_Print(progressive->log, WLOG_DEBUG,
2264 "rect[%" PRIu16
"]: x: %" PRIu16
" y: %" PRIu16
" w: %" PRIu16
" h: %" PRIu16
"",
2265 index, rect->x, rect->y, rect->width, rect->height);
2269 const SSIZE_T res = progressive_process_tiles(progressive, s, region, surface, context);
2275static inline SSIZE_T progressive_parse_block(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2278 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2280 UINT16 blockType = 0;
2281 UINT32 blockLen = 0;
2283 wStream sub = WINPR_C_ARRAY_INIT;
2285 WINPR_ASSERT(progressive);
2287 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
2290 Stream_Read_UINT16(s, blockType);
2291 Stream_Read_UINT32(s, blockLen);
2295 WLog_WARN(TAG,
"Invalid blockLen %" PRIu32
", expected >= 6", blockLen);
2298 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
2300 Stream_StaticConstInit(&sub, Stream_Pointer(s), blockLen - 6);
2301 Stream_Seek(s, blockLen - 6);
2305 case PROGRESSIVE_WBT_SYNC:
2306 rc = progressive_wb_sync(progressive, &sub, blockType, blockLen);
2309 case PROGRESSIVE_WBT_FRAME_BEGIN:
2310 rc = progressive_wb_frame_begin(progressive, &sub, blockType, blockLen);
2313 case PROGRESSIVE_WBT_FRAME_END:
2314 rc = progressive_wb_frame_end(progressive, &sub, blockType, blockLen);
2317 case PROGRESSIVE_WBT_CONTEXT:
2318 rc = progressive_wb_context(progressive, &sub, blockType, blockLen);
2321 case PROGRESSIVE_WBT_REGION:
2322 rc = progressive_wb_region(progressive, &sub, blockType, blockLen, surface, region);
2326 WLog_Print(progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16, blockType);
2333 if (Stream_GetRemainingLength(&sub) > 0)
2335 WLog_Print(progressive->log, WLOG_ERROR,
2336 "block len %" PRIu32
" does not match read data %" PRIuz, blockLen,
2337 blockLen - Stream_GetRemainingLength(&sub));
2344static inline BOOL update_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2346 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2347 UINT32 nXDst, UINT32 nYDst,
2348 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
2349 REGION16* WINPR_RESTRICT invalidRegion)
2352 REGION16 clippingRects = WINPR_C_ARRAY_INIT;
2353 region16_init(&clippingRects);
2355 for (UINT32 i = 0; i < region->numRects; i++)
2358 const RFX_RECT* rect = &(region->rects[i]);
2360 clippingRect.left = (UINT16)nXDst + rect->x;
2361 clippingRect.top = (UINT16)nYDst + rect->y;
2362 clippingRect.right = clippingRect.left + rect->width;
2363 clippingRect.bottom = clippingRect.top + rect->height;
2364 if (!region16_union_rect(&clippingRects, &clippingRects, &clippingRect))
2366 region16_uninit(&clippingRects);
2371 for (UINT32 i = 0; i < surface->numUpdatedTiles; i++)
2373 UINT32 nbUpdateRects = 0;
2377 WINPR_ASSERT(surface->updatedTileIndices);
2378 const UINT32 index = surface->updatedTileIndices[i];
2380 WINPR_ASSERT(index < surface->tilesSize);
2384 const UINT32 dl = nXDst + tile->x;
2385 updateRect.left = WINPR_ASSERTING_INT_CAST(UINT16, dl);
2387 const UINT32 dt = nYDst + tile->y;
2388 updateRect.top = WINPR_ASSERTING_INT_CAST(UINT16, dt);
2389 updateRect.right = updateRect.left + 64;
2390 updateRect.bottom = updateRect.top + 64;
2392 REGION16 updateRegion = WINPR_C_ARRAY_INIT;
2393 region16_init(&updateRegion);
2394 if (!region16_intersect_rect(&updateRegion, &clippingRects, &updateRect))
2396 region16_uninit(&updateRegion);
2399 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
2401 for (UINT32 j = 0; j < nbUpdateRects; j++)
2404 if (rect->left < updateRect.left)
2406 const UINT32 nXSrc = rect->left - updateRect.left;
2407 const UINT32 nYSrc = rect->top - updateRect.top;
2408 const UINT32 width = rect->right - rect->left;
2409 const UINT32 height = rect->bottom - rect->top;
2411 if (rect->left + width > surface->width)
2413 if (rect->top + height > surface->height)
2415 const BOOL res = freerdp_image_copy_no_overlap(
2416 pDstData, DstFormat, nDstStep, rect->left, rect->top, width, height, tile->data,
2417 progressive->format, tile->stride, nXSrc, nYSrc,
nullptr, FREERDP_KEEP_DST_ALPHA);
2423 if (!region16_union_rect(invalidRegion, invalidRegion, rect))
2425 region16_uninit(&updateRegion);
2431 region16_uninit(&updateRegion);
2432 tile->dirty = FALSE;
2438 region16_uninit(&clippingRects);
2442INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2443 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
2444 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2445 UINT32 nXDst, UINT32 nYDst,
REGION16* WINPR_RESTRICT invalidRegion,
2446 UINT16 surfaceId, UINT32 frameId)
2450 WINPR_ASSERT(progressive);
2455 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion no surface for %" PRIu16,
2460 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2461 WINPR_ASSERT(region);
2463 if (surface->frameId != frameId)
2465 surface->frameId = frameId;
2466 surface->numUpdatedTiles = 0;
2469 wStream ss = WINPR_C_ARRAY_INIT;
2470 wStream* s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
2475 case PIXEL_FORMAT_RGBA32:
2476 case PIXEL_FORMAT_RGBX32:
2477 case PIXEL_FORMAT_BGRA32:
2478 case PIXEL_FORMAT_BGRX32:
2479 progressive->format = DstFormat;
2482 progressive->format = PIXEL_FORMAT_XRGB32;
2486 const size_t start = Stream_GetPosition(s);
2487 progressive->state = 0;
2488 while (Stream_GetRemainingLength(s) > 0)
2490 if (progressive_parse_block(progressive, s, surface, region) < 0)
2495 const size_t end = Stream_GetPosition(s);
2496 if ((end - start) != SrcSize)
2498 WLog_Print(progressive->log, WLOG_ERROR,
2499 "total block len %" PRIuz
" does not match read data %" PRIu32, end - start,
2506 if (!update_tiles(progressive, surface, pDstData, DstFormat, nDstStep, nXDst, nYDst, region,
2515BOOL progressive_rfx_write_message_progressive_simple(
2516 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s,
2517 const RFX_MESSAGE* WINPR_RESTRICT msg)
2519 RFX_CONTEXT* context =
nullptr;
2521 WINPR_ASSERT(progressive);
2524 context = progressive->rfx_context;
2525 return rfx_write_message_progressive_simple(context, s, msg);
2528int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2529 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 SrcFormat,
2530 UINT32 Width, UINT32 Height, UINT32 ScanLine,
2531 const REGION16* WINPR_RESTRICT invalidRegion,
2532 BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize)
2537 UINT32 numRects = 0;
2539 RFX_MESSAGE* message =
nullptr;
2541 if (!progressive || !pSrcData || !ppDstData || !pDstSize)
2550 case PIXEL_FORMAT_ABGR32:
2551 case PIXEL_FORMAT_ARGB32:
2552 case PIXEL_FORMAT_XBGR32:
2553 case PIXEL_FORMAT_XRGB32:
2554 case PIXEL_FORMAT_BGRA32:
2555 case PIXEL_FORMAT_BGRX32:
2556 case PIXEL_FORMAT_RGBA32:
2557 case PIXEL_FORMAT_RGBX32:
2558 ScanLine = Width * 4;
2565 if (SrcSize < Height * ScanLine)
2570 numRects = (Width + 63) / 64;
2571 numRects *= (Height + 63) / 64;
2575 const int nr = region16_n_rects(invalidRegion);
2576 numRects = WINPR_ASSERTING_INT_CAST(uint32_t, nr);
2582 if (!Stream_EnsureRemainingCapacity(progressive->rects, numRects *
sizeof(
RFX_RECT)))
2584 rects = Stream_BufferAs(progressive->rects,
RFX_RECT);
2587 const RECTANGLE_16* region_rects = region16_rects(invalidRegion,
nullptr);
2588 for (UINT32 idx = 0; idx < numRects; idx++)
2595 rect->width = r->right - r->left;
2596 rect->height = r->bottom - r->top;
2604 for (UINT32 i = 0; i < numRects; i++)
2610 WINPR_ASSERT(Width >= x);
2611 WINPR_ASSERT(Height >= y);
2612 r->width = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Width - x));
2613 r->height = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Height - y));
2615 if (x + 64UL >= Width)
2623 WINPR_ASSERT(r->x % 64 == 0);
2624 WINPR_ASSERT(r->y % 64 == 0);
2625 WINPR_ASSERT(r->width <= 64);
2626 WINPR_ASSERT(r->height <= 64);
2629 s = progressive->buffer;
2630 Stream_ResetPosition(s);
2632 progressive->rfx_context->mode = RLGR1;
2634 progressive->rfx_context->width = WINPR_ASSERTING_INT_CAST(UINT16, Width);
2635 progressive->rfx_context->height = WINPR_ASSERTING_INT_CAST(UINT16, Height);
2636 rfx_context_set_pixel_format(progressive->rfx_context, SrcFormat);
2637 message = rfx_encode_message(progressive->rfx_context, rects, numRects, pSrcData, Width, Height,
2641 WLog_ERR(TAG,
"failed to encode rfx message");
2645 rc = progressive_rfx_write_message_progressive_simple(progressive, s, message);
2646 rfx_message_free(progressive->rfx_context, message);
2651 const size_t pos = Stream_GetPosition(s);
2652 WINPR_ASSERT(pos <= UINT32_MAX);
2653 *pDstSize = (UINT32)pos;
2655 *ppDstData = Stream_Buffer(s);
2661BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive)
2663 return (progressive !=
nullptr);
2666PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
2668 return progressive_context_new_ex(Compressor, 0);
2671PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, UINT32 ThreadingFlags)
2673 PROGRESSIVE_CONTEXT* progressive =
2674 (PROGRESSIVE_CONTEXT*)winpr_aligned_calloc(1,
sizeof(PROGRESSIVE_CONTEXT), 32);
2679 progressive->Compressor = Compressor;
2680 progressive->quantProgValFull.quality = 100;
2681 progressive->log = WLog_Get(TAG);
2682 if (!progressive->log)
2684 progressive->rfx_context = rfx_context_new_ex(Compressor, ThreadingFlags);
2685 if (!progressive->rfx_context)
2687 progressive->buffer = Stream_New(
nullptr, 1024);
2688 if (!progressive->buffer)
2690 progressive->rects = Stream_New(
nullptr, 1024);
2691 if (!progressive->rects)
2693 progressive->bufferPool = BufferPool_New(TRUE, (8192LL + 32LL) * 3LL, 16);
2694 if (!progressive->bufferPool)
2696 progressive->SurfaceContexts = HashTable_New(TRUE);
2697 if (!progressive->SurfaceContexts)
2701 wObject* obj = HashTable_ValueObject(progressive->SurfaceContexts);
2707 WINPR_PRAGMA_DIAG_PUSH
2708 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2709 progressive_context_free(progressive);
2710 WINPR_PRAGMA_DIAG_POP
2714void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
2719 Stream_Free(progressive->buffer, TRUE);
2720 Stream_Free(progressive->rects, TRUE);
2721 rfx_context_free(progressive->rfx_context);
2723 BufferPool_Free(progressive->bufferPool);
2724 HashTable_Free(progressive->SurfaceContexts);
2726 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