22 #include <freerdp/config.h>
24 #include <winpr/assert.h>
25 #include <winpr/cast.h>
26 #include <winpr/crt.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"
41 #include "rfx_types.h"
42 #include "progressive.h"
44 #define TAG FREERDP_TAG("codec.progressive")
57 } RFX_PROGRESSIVE_UPGRADE_STATE;
60 progressive_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;
99 dst->HL1 = q1->HL1 + q2->HL1;
100 dst->LH1 = q1->LH1 + q2->LH1;
101 dst->HH1 = q1->HH1 + q2->HH1;
102 dst->HL2 = q1->HL2 + q2->HL2;
103 dst->LH2 = q1->LH2 + q2->LH2;
104 dst->HH2 = q1->HH2 + q2->HH2;
105 dst->HL3 = q1->HL3 + q2->HL3;
106 dst->LH3 = q1->LH3 + q2->LH3;
107 dst->HH3 = q1->HH3 + q2->HH3;
108 dst->LL3 = q1->LL3 + q2->LL3;
129 dst->HL1 = q1->HL1 - q2->HL1;
130 dst->LH1 = q1->LH1 - q2->LH1;
131 dst->HH1 = q1->HH1 - q2->HH1;
132 dst->HL2 = q1->HL2 - q2->HL2;
133 dst->LH2 = q1->LH2 - q2->LH2;
134 dst->HH2 = q1->HH2 - q2->HH2;
135 dst->HL3 = q1->HL3 - q2->HL3;
136 dst->LH3 = q1->LH3 - q2->LH3;
137 dst->HH3 = q1->HH3 - q2->HH3;
138 dst->LL3 = q1->LL3 - q2->LL3;
181 if (q1->HL1 > q2->HL1)
184 if (q1->LH1 > q2->LH1)
187 if (q1->HH1 > q2->HH1)
190 if (q1->HL2 > q2->HL2)
193 if (q1->LH2 > q2->LH2)
196 if (q1->HH2 > q2->HH2)
199 if (q1->HL3 > q2->HL3)
202 if (q1->LH3 > q2->LH3)
205 if (q1->HH3 > q2->HH3)
208 if (q1->LL3 > q2->LL3)
254 if (q1->HL1 < q2->HL1)
257 if (q1->LH1 < q2->LH1)
260 if (q1->HH1 < q2->HH1)
263 if (q1->HL2 < q2->HL2)
266 if (q1->LH2 < q2->LH2)
269 if (q1->HH2 < q2->HH2)
272 if (q1->HL3 < q2->HL3)
275 if (q1->LH3 < q2->LH3)
278 if (q1->HH3 < q2->HH3)
281 if (q1->LL3 < q2->LL3)
291 if (q1->HL1 != q2->HL1)
294 if (q1->LH1 != q2->LH1)
297 if (q1->HH1 != q2->HH1)
300 if (q1->HL2 != q2->HL2)
303 if (q1->LH2 != q2->LH2)
306 if (q1->HH2 != q2->HH2)
309 if (q1->HL3 != q2->HL3)
312 if (q1->LH3 != q2->LH3)
315 if (q1->HH3 != q2->HH3)
318 if (q1->LL3 != q2->LL3)
324 static INLINE BOOL progressive_set_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
329 key = ((ULONG_PTR)surfaceId) + 1;
332 return HashTable_Insert(progressive->SurfaceContexts, (
void*)key, pData);
334 HashTable_Remove(progressive->SurfaceContexts, (
void*)key);
339 progressive_get_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, UINT16 surfaceId)
341 void* key = (
void*)(((ULONG_PTR)surfaceId) + 1);
346 return HashTable_GetItemValue(progressive->SurfaceContexts, key);
353 winpr_aligned_free(tile->sign);
354 winpr_aligned_free(tile->current);
355 winpr_aligned_free(tile->data);
356 winpr_aligned_free(tile);
360 static void progressive_surface_context_free(
void* ptr)
369 for (
size_t index = 0; index < surface->tilesSize; index++)
372 progressive_tile_free(tile);
376 winpr_aligned_free((
void*)surface->tiles);
377 winpr_aligned_free(surface->updatedTileIndices);
378 winpr_aligned_free(surface);
389 tile->stride = 4 * tile->width;
391 size_t dataLen = 1ull * tile->stride * tile->height;
392 tile->data = (BYTE*)winpr_aligned_malloc(dataLen, 16);
395 memset(tile->data, 0xFF, dataLen);
397 size_t signLen = (8192ULL + 32ULL) * 3ULL;
398 tile->sign = (BYTE*)winpr_aligned_malloc(signLen, 16);
402 size_t currentLen = (8192ULL + 32ULL) * 3ULL;
403 tile->current = (BYTE*)winpr_aligned_malloc(currentLen, 16);
410 progressive_tile_free(tile);
419 WINPR_ASSERT(surface);
420 WINPR_ASSERT(surface->gridSize > 0);
424 oldIndex = surface->gridSize;
425 while (surface->gridSize < min)
426 surface->gridSize += 1024;
429 void* tmp = winpr_aligned_recalloc((
void*)surface->tiles, surface->gridSize,
433 surface->tilesSize = surface->gridSize;
436 for (
size_t x = oldIndex; x < surface->tilesSize; x++)
438 surface->tiles[x] = progressive_tile_new();
439 if (!surface->tiles[x])
444 winpr_aligned_recalloc(surface->updatedTileIndices, surface->gridSize,
sizeof(UINT32), 32);
448 surface->updatedTileIndices = tmp;
462 surface->id = surfaceId;
463 surface->width = width;
464 surface->height = height;
465 surface->gridWidth = (width + (64 - width % 64)) / 64;
466 surface->gridHeight = (height + (64 - height % 64)) / 64;
467 surface->gridSize = surface->gridWidth * surface->gridHeight;
469 if (!progressive_allocate_tile_cache(surface, surface->gridSize))
471 progressive_surface_context_free(surface);
480 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
486 if (!surface || !tile)
489 zIdx = (tile->yIdx * surface->gridWidth) + tile->xIdx;
491 if (zIdx >= surface->tilesSize)
493 WLog_ERR(TAG,
"Invalid zIndex %" PRIuz, zIdx);
497 t = surface->tiles[zIdx];
499 t->blockType = tile->blockType;
500 t->blockLen = tile->blockLen;
501 t->quantIdxY = tile->quantIdxY;
502 t->quantIdxCb = tile->quantIdxCb;
503 t->quantIdxCr = tile->quantIdxCr;
504 t->xIdx = tile->xIdx;
505 t->yIdx = tile->yIdx;
506 t->flags = tile->flags;
507 t->quality = tile->quality;
508 t->x = tile->xIdx * t->width;
509 t->y = tile->yIdx * t->height;
513 t->ySrlLen = tile->ySrlLen;
514 t->yRawLen = tile->yRawLen;
515 t->cbSrlLen = tile->cbSrlLen;
516 t->cbRawLen = tile->cbRawLen;
517 t->crSrlLen = tile->crSrlLen;
518 t->crRawLen = tile->crRawLen;
519 t->ySrlData = tile->ySrlData;
520 t->yRawData = tile->yRawData;
521 t->cbSrlData = tile->cbSrlData;
522 t->cbRawData = tile->cbRawData;
523 t->crSrlData = tile->crSrlData;
524 t->crRawData = tile->crRawData;
528 t->yLen = tile->yLen;
529 t->cbLen = tile->cbLen;
530 t->crLen = tile->crLen;
531 t->tailLen = tile->tailLen;
532 t->yData = tile->yData;
533 t->cbData = tile->cbData;
534 t->crData = tile->crData;
535 t->tailData = tile->tailData;
538 if (region->usedTiles >= region->numTiles)
540 WLog_ERR(TAG,
"Invalid tile count, only expected %" PRIu16
", got %" PRIu16,
541 region->numTiles, region->usedTiles);
545 region->tiles[region->usedTiles++] = t;
548 if (surface->numUpdatedTiles >= surface->gridSize)
550 if (!progressive_allocate_tile_cache(surface, surface->numUpdatedTiles + 1))
554 surface->updatedTileIndices[surface->numUpdatedTiles++] = (UINT32)zIdx;
561 INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
562 UINT16 surfaceId, UINT32 width, UINT32 height)
568 surface = progressive_surface_context_new(surfaceId, width, height);
573 if (!progressive_set_surface_data(progressive, surfaceId, (
void*)surface))
575 progressive_surface_context_free(surface);
583 int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
586 progressive_set_surface_data(progressive, surfaceId, NULL);
609 static INLINE
void progressive_rfx_idwt_x(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
610 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
611 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
612 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
621 for (
size_t i = 0; i < nDstCount; i++)
623 const INT16* pL = pLowBand;
624 const INT16* pH = pHighBand;
625 INT16* pX = pDstBand;
628 X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
629 X2 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
631 for (
size_t j = 0; j < (nHighCount - 1); j++)
637 X2 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - ((H0 + H1) / 2));
638 X1 = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
646 if (nLowCount <= (nHighCount + 1))
648 if (nLowCount <= nHighCount)
651 pX[1] = WINPR_ASSERTING_INT_CAST(int16_t, X2 + (2 * H0));
657 X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
659 pX[1] = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
667 X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - (H0 / 2));
669 pX[1] = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
673 pX[3] = WINPR_ASSERTING_INT_CAST(int16_t, (X0 + L0) / 2);
676 pLowBand += nLowStep;
677 pHighBand += nHighStep;
678 pDstBand += nDstStep;
682 static INLINE
void progressive_rfx_idwt_y(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
683 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
684 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
685 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
694 for (
size_t i = 0; i < nDstCount; i++)
696 const INT16* pL = pLowBand;
697 const INT16* pH = pHighBand;
698 INT16* pX = pDstBand;
703 X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
704 X2 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
706 for (
size_t j = 0; j < (nHighCount - 1); j++)
712 X2 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - ((H0 + H1) / 2));
713 X1 = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
722 if (nLowCount <= (nHighCount + 1))
724 if (nLowCount <= nHighCount)
728 *pX = WINPR_ASSERTING_INT_CAST(int16_t, X2 + (2 * H0));
733 X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
736 *pX = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
745 X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - (H0 / 2));
748 *pX = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
753 *pX = WINPR_ASSERTING_INT_CAST(int16_t, (X0 + L0) / 2);
762 static INLINE
size_t progressive_rfx_get_band_l_count(
size_t level)
764 return (64 >> level) + 1;
767 static INLINE
size_t progressive_rfx_get_band_h_count(
size_t level)
770 return (64 >> 1) - 1;
772 return (64 + (1 << (level - 1))) >> level;
775 static INLINE
void progressive_rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer,
776 INT16* WINPR_RESTRICT temp,
size_t level)
778 size_t nDstStepX = 0;
779 size_t nDstStepY = 0;
780 const INT16* WINPR_RESTRICT HL = NULL;
781 const INT16* WINPR_RESTRICT LH = NULL;
782 const INT16* WINPR_RESTRICT HH = NULL;
783 INT16* WINPR_RESTRICT LL = NULL;
784 INT16* WINPR_RESTRICT L = NULL;
785 INT16* WINPR_RESTRICT H = NULL;
786 INT16* WINPR_RESTRICT LLx = NULL;
788 const size_t nBandL = progressive_rfx_get_band_l_count(level);
789 const size_t nBandH = progressive_rfx_get_band_h_count(level);
792 HL = &buffer[offset];
793 offset += (nBandH * nBandL);
794 LH = &buffer[offset];
795 offset += (nBandL * nBandH);
796 HH = &buffer[offset];
797 offset += (nBandH * nBandH);
798 LL = &buffer[offset];
799 nDstStepX = (nBandL + nBandH);
800 nDstStepY = (nBandL + nBandH);
803 offset += (nBandL * nDstStepX);
808 progressive_rfx_idwt_x(LL, nBandL, HL, nBandH, L, nDstStepX, nBandL, nBandH, nBandL);
811 progressive_rfx_idwt_x(LH, nBandL, HH, nBandH, H, nDstStepX, nBandL, nBandH, nBandH);
814 progressive_rfx_idwt_y(L, nDstStepX, H, nDstStepX, LLx, nDstStepY, nBandL, nBandH,
818 void rfx_dwt_2d_extrapolate_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT temp)
820 WINPR_ASSERT(buffer);
822 progressive_rfx_dwt_2d_decode_block(&buffer[3807], temp, 3);
823 progressive_rfx_dwt_2d_decode_block(&buffer[3007], temp, 2);
824 progressive_rfx_dwt_2d_decode_block(&buffer[0], temp, 1);
827 static INLINE
int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
828 INT16* WINPR_RESTRICT buffer,
829 INT16* WINPR_RESTRICT current, BOOL coeffDiff,
830 BOOL extrapolate, BOOL reverse)
834 if (!progressive || !buffer || !current)
837 const size_t belements = 4096;
838 const size_t bsize = belements *
sizeof(INT16);
840 memcpy(buffer, current, bsize);
842 memcpy(current, buffer, bsize);
846 INT16* temp = (INT16*)BufferPool_Take(progressive->bufferPool, -1);
853 progressive->rfx_context->dwt_2d_decode(buffer, temp);
857 WINPR_ASSERT(progressive->rfx_context->dwt_2d_extrapolate_decode);
858 progressive->rfx_context->dwt_2d_extrapolate_decode(buffer, temp);
860 BufferPool_Return(progressive->bufferPool, temp);
864 static INLINE
void progressive_rfx_decode_block(
const primitives_t* prims,
865 INT16* WINPR_RESTRICT buffer, UINT32 length,
874 static INLINE
int progressive_rfx_decode_component(
875 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
877 UINT32 length, INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
878 INT16* WINPR_RESTRICT sign, BOOL coeffDiff, BOOL subbandDiff, BOOL extrapolate)
883 status = progressive->rfx_context->rlgr_decode(RLGR1, data, length, buffer, 4096);
888 CopyMemory(sign, buffer, 4096ULL * 2ULL);
891 rfx_differential_decode(buffer + 4032, 64);
892 progressive_rfx_decode_block(prims, &buffer[0], 1024, shift->HL1);
893 progressive_rfx_decode_block(prims, &buffer[1024], 1024, shift->LH1);
894 progressive_rfx_decode_block(prims, &buffer[2048], 1024, shift->HH1);
895 progressive_rfx_decode_block(prims, &buffer[3072], 256, shift->HL2);
896 progressive_rfx_decode_block(prims, &buffer[3328], 256, shift->LH2);
897 progressive_rfx_decode_block(prims, &buffer[3584], 256, shift->HH2);
898 progressive_rfx_decode_block(prims, &buffer[3840], 64, shift->HL3);
899 progressive_rfx_decode_block(prims, &buffer[3904], 64, shift->LH3);
900 progressive_rfx_decode_block(prims, &buffer[3968], 64, shift->HH3);
901 progressive_rfx_decode_block(prims, &buffer[4032], 64, shift->LL3);
905 progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1);
906 progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1);
907 progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1);
908 progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2);
909 progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2);
910 progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2);
911 progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3);
912 progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3);
913 progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3);
914 rfx_differential_decode(&buffer[4015], 81);
915 progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3);
917 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
922 progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
924 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
930 BOOL extrapolate = 0;
931 BYTE* pBuffer = NULL;
949 diff = tile->flags & RFX_TILE_DIFFERENCE;
950 sub = context->flags & RFX_SUBBAND_DIFFING;
951 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
953 #if defined(WITH_DEBUG_CODECS)
954 WLog_Print(progressive->log, WLOG_DEBUG,
955 "ProgressiveTile%s: quantIdx Y: %" PRIu8
" Cb: %" PRIu8
" Cr: %" PRIu8
956 " xIdx: %" PRIu16
" yIdx: %" PRIu16
" flags: 0x%02" PRIX8
" quality: %" PRIu8
957 " yLen: %" PRIu16
" cbLen: %" PRIu16
" crLen: %" PRIu16
" tailLen: %" PRIu16
"",
958 (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ?
"First" :
"Simple",
959 tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx,
960 tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
963 if (tile->quantIdxY >= region->numQuant)
965 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
969 quantY = &(region->quantVals[tile->quantIdxY]);
971 if (tile->quantIdxCb >= region->numQuant)
973 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
978 quantCb = &(region->quantVals[tile->quantIdxCb]);
980 if (tile->quantIdxCr >= region->numQuant)
982 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
987 quantCr = &(region->quantVals[tile->quantIdxCr]);
989 if (tile->quality == 0xFF)
991 quantProgVal = &(progressive->quantProgValFull);
995 if (tile->quality >= region->numProgQuant)
997 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
998 region->numProgQuant);
1002 quantProgVal = &(region->quantProgVals[tile->quality]);
1005 quantProgY = &(quantProgVal->yQuantValues);
1006 quantProgCb = &(quantProgVal->cbQuantValues);
1007 quantProgCr = &(quantProgVal->crQuantValues);
1009 tile->yQuant = *quantY;
1010 tile->cbQuant = *quantCb;
1011 tile->crQuant = *quantCr;
1012 tile->yProgQuant = *quantProgY;
1013 tile->cbProgQuant = *quantProgCb;
1014 tile->crProgQuant = *quantProgCr;
1016 progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
1017 progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
1018 progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
1019 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1020 progressive_rfx_quant_lsub(&shiftY, 1);
1021 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1022 progressive_rfx_quant_lsub(&shiftCb, 1);
1023 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1024 progressive_rfx_quant_lsub(&shiftCr, 1);
1026 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
1027 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
1028 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
1030 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
1031 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
1032 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
1034 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1035 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
1036 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
1037 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
1039 rc = progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0],
1040 pCurrent[0], pSign[0], diff, sub, extrapolate);
1043 rc = progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen,
1044 pSrcDst[1], pCurrent[1], pSign[1], diff, sub,
1048 rc = progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen,
1049 pSrcDst[2], pCurrent[2], pSign[2], diff, sub,
1054 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1055 rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride, progressive->format,
1058 BufferPool_Return(progressive->bufferPool, pBuffer);
1062 static INLINE INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1065 WINPR_ASSERT(state);
1076 const UINT32 k = state->kp / 8;
1081 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1082 BitStream_Shift(bs, 1);
1087 state->nz = (1 << k);
1104 bs->mask = ((1 << k) - 1);
1106 WINPR_ASSERTING_INT_CAST(int16_t, ((bs->accumulator >> (32u - k)) & bs->mask));
1107 BitStream_Shift(bs, k);
1121 const UINT32 sign = (bs->accumulator & 0x80000000) ? 1 : 0;
1122 BitStream_Shift(bs, 1);
1130 return sign ? -1 : 1;
1133 const UINT32 max = (1 << numBits) - 1;
1137 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1138 BitStream_Shift(bs, 1);
1146 if (mag > INT16_MAX)
1148 return (INT16)(sign ? -1 * (int)mag : (INT16)mag);
1152 progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state)
1163 pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
1166 BitStream_Shift(raw, pad);
1168 pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
1171 BitStream_Shift(srl, pad);
1173 if (BitStream_GetRemainingLength(srl) == 8)
1174 BitStream_Shift(srl, 8);
1179 static INLINE
int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1180 INT16* WINPR_RESTRICT buffer,
1181 INT16* WINPR_RESTRICT sign, UINT32 length,
1182 UINT32 shift, UINT32 bitPos, UINT32 numBits)
1194 for (UINT32 index = 0; index < length; index++)
1196 raw->mask = ((1 << numBits) - 1);
1197 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1198 BitStream_Shift(raw, numBits);
1200 WINPR_ASSERTING_INT_CAST(INT16, (INT16)(((UINT32)input << shift) & 0xFFFF));
1206 for (UINT32 index = 0; index < length; index++)
1208 if (sign[index] > 0)
1211 raw->mask = ((1 << numBits) - 1);
1212 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1213 BitStream_Shift(raw, numBits);
1215 else if (sign[index] < 0)
1218 raw->mask = ((1 << numBits) - 1);
1219 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1220 BitStream_Shift(raw, numBits);
1226 input = progressive_rfx_srl_read(state, numBits);
1227 sign[index] = input;
1230 const int32_t val = input << shift;
1231 buffer[index] += WINPR_ASSERTING_INT_CAST(INT16, val);
1238 progressive_rfx_upgrade_component(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1242 INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
1243 INT16* WINPR_RESTRICT sign,
const BYTE* WINPR_RESTRICT srlData,
1244 UINT32 srlLen,
const BYTE* WINPR_RESTRICT rawData, UINT32 rawLen,
1245 BOOL coeffDiff, BOOL subbandDiff, BOOL extrapolate)
1252 RFX_PROGRESSIVE_UPGRADE_STATE state = { 0 };
1258 BitStream_Attach(state.srl, srlData, srlLen);
1259 BitStream_Fetch(state.srl);
1260 BitStream_Attach(state.raw, rawData, rawLen);
1261 BitStream_Fetch(state.raw);
1264 rc = progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1,
1268 rc = progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1,
1269 bitPos->LH1, numBits->LH1);
1272 rc = progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1,
1273 bitPos->HH1, numBits->HH1);
1276 rc = progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2,
1277 bitPos->HL2, numBits->HL2);
1280 rc = progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2,
1281 bitPos->LH2, numBits->LH2);
1284 rc = progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2,
1285 bitPos->HH2, numBits->HH2);
1288 rc = progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3,
1289 bitPos->HL3, numBits->HL3);
1292 rc = progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3,
1293 bitPos->LH3, numBits->LH3);
1296 rc = progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3,
1297 bitPos->HH3, numBits->HH3);
1301 state.nonLL = FALSE;
1302 rc = progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3,
1303 bitPos->LL3, numBits->LL3);
1306 rc = progressive_rfx_upgrade_state_finish(&state);
1309 aRawLen = (state.raw->position + 7) / 8;
1310 aSrlLen = (state.srl->position + 7) / 8;
1312 if ((aRawLen != rawLen) || (aSrlLen != srlLen))
1318 pRawLen = (int)((((
float)aRawLen) / ((
float)rawLen)) * 100.0f);
1321 pSrlLen = (int)((((
float)aSrlLen) / ((
float)srlLen)) * 100.0f);
1323 WLog_Print(progressive->log, WLOG_WARN,
1324 "RAW: %" PRIu32
"/%" PRIu32
" %d%% (%" PRIu32
"/%" PRIu32
":%" PRIu32
1325 ")\tSRL: %" PRIu32
"/%" PRIu32
" %d%% (%" PRIu32
"/%" PRIu32
":%" PRIu32
")",
1326 aRawLen, rawLen, pRawLen, state.raw->position, rawLen * 8,
1327 (rawLen * 8) - state.raw->position, aSrlLen, srlLen, pSrlLen,
1328 state.srl->position, srlLen * 8, (srlLen * 8) - state.srl->position);
1332 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
1337 progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1339 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1345 BOOL extrapolate = 0;
1346 BYTE* pBuffer = NULL;
1347 INT16* pSign[3] = { 0 };
1348 INT16* pSrcDst[3] = { 0 };
1349 INT16* pCurrent[3] = { 0 };
1369 coeffDiff = tile->flags & RFX_TILE_DIFFERENCE;
1370 sub = context->flags & RFX_SUBBAND_DIFFING;
1371 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
1375 #if defined(WITH_DEBUG_CODECS)
1376 WLog_Print(progressive->log, WLOG_DEBUG,
1377 "ProgressiveTileUpgrade: pass: %" PRIu16
" quantIdx Y: %" PRIu8
" Cb: %" PRIu8
1378 " Cr: %" PRIu8
" xIdx: %" PRIu16
" yIdx: %" PRIu16
" quality: %" PRIu8
1379 " ySrlLen: %" PRIu16
" yRawLen: %" PRIu16
" cbSrlLen: %" PRIu16
" cbRawLen: %" PRIu16
1380 " crSrlLen: %" PRIu16
" crRawLen: %" PRIu16
"",
1381 tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx,
1382 tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen,
1383 tile->cbRawLen, tile->crSrlLen, tile->crRawLen);
1386 if (tile->quantIdxY >= region->numQuant)
1388 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
1392 quantY = &(region->quantVals[tile->quantIdxY]);
1394 if (tile->quantIdxCb >= region->numQuant)
1396 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
1401 quantCb = &(region->quantVals[tile->quantIdxCb]);
1403 if (tile->quantIdxCr >= region->numQuant)
1405 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1410 quantCr = &(region->quantVals[tile->quantIdxCr]);
1412 if (tile->quality == 0xFF)
1414 quantProg = &(progressive->quantProgValFull);
1418 if (tile->quality >= region->numProgQuant)
1420 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1421 region->numProgQuant);
1425 quantProg = &(region->quantProgVals[tile->quality]);
1428 quantProgY = &(quantProg->yQuantValues);
1429 quantProgCb = &(quantProg->cbQuantValues);
1430 quantProgCr = &(quantProg->crQuantValues);
1432 if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
1433 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantY has changed!");
1435 if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
1436 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCb has changed!");
1438 if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
1439 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCr has changed!");
1441 if (!(context->flags & RFX_SUBBAND_DIFFING))
1442 WLog_WARN(TAG,
"PROGRESSIVE_BLOCK_CONTEXT::flags & RFX_SUBBAND_DIFFING not set");
1444 progressive_rfx_quant_add(quantY, quantProgY, &yBitPos);
1445 progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos);
1446 progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos);
1447 progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits);
1448 progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits);
1449 progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits);
1450 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1451 progressive_rfx_quant_lsub(&shiftY, 1);
1452 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1453 progressive_rfx_quant_lsub(&shiftCb, 1);
1454 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1455 progressive_rfx_quant_lsub(&shiftCr, 1);
1457 tile->yBitPos = yBitPos;
1458 tile->cbBitPos = cbBitPos;
1459 tile->crBitPos = crBitPos;
1460 tile->yQuant = *quantY;
1461 tile->cbQuant = *quantCb;
1462 tile->crQuant = *quantCr;
1463 tile->yProgQuant = *quantProgY;
1464 tile->cbProgQuant = *quantProgCb;
1465 tile->crProgQuant = *quantProgCr;
1467 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
1468 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
1469 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
1471 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
1472 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
1473 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
1475 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1476 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
1477 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
1478 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
1480 status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
1481 pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData,
1482 tile->ySrlLen, tile->yRawData, tile->yRawLen,
1483 coeffDiff, sub, extrapolate);
1488 status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
1489 pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData,
1490 tile->cbSrlLen, tile->cbRawData, tile->cbRawLen,
1491 coeffDiff, sub, extrapolate);
1496 status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
1497 pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData,
1498 tile->crSrlLen, tile->crRawData, tile->crRawLen,
1499 coeffDiff, sub, extrapolate);
1504 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1505 status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1506 progressive->format, &roi_64x64);
1508 BufferPool_Return(progressive->bufferPool, pBuffer);
1512 static INLINE BOOL progressive_tile_read_upgrade(
1513 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1515 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1519 const size_t expect = 20;
1521 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1524 tile.blockType = blockType;
1525 tile.blockLen = blockLen;
1528 Stream_Read_UINT8(s, tile.quantIdxY);
1529 Stream_Read_UINT8(s, tile.quantIdxCb);
1530 Stream_Read_UINT8(s, tile.quantIdxCr);
1531 Stream_Read_UINT16(s, tile.xIdx);
1532 Stream_Read_UINT16(s, tile.yIdx);
1533 Stream_Read_UINT8(s, tile.quality);
1534 Stream_Read_UINT16(s, tile.ySrlLen);
1535 Stream_Read_UINT16(s, tile.yRawLen);
1536 Stream_Read_UINT16(s, tile.cbSrlLen);
1537 Stream_Read_UINT16(s, tile.cbRawLen);
1538 Stream_Read_UINT16(s, tile.crSrlLen);
1539 Stream_Read_UINT16(s, tile.crRawLen);
1541 tile.ySrlData = Stream_Pointer(s);
1542 if (!Stream_SafeSeek(s, tile.ySrlLen))
1544 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.ySrlLen);
1548 tile.yRawData = Stream_Pointer(s);
1549 if (!Stream_SafeSeek(s, tile.yRawLen))
1551 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yRawLen);
1555 tile.cbSrlData = Stream_Pointer(s);
1556 if (!Stream_SafeSeek(s, tile.cbSrlLen))
1558 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1563 tile.cbRawData = Stream_Pointer(s);
1564 if (!Stream_SafeSeek(s, tile.cbRawLen))
1566 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1571 tile.crSrlData = Stream_Pointer(s);
1572 if (!Stream_SafeSeek(s, tile.crSrlLen))
1574 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1579 tile.crRawData = Stream_Pointer(s);
1580 if (!Stream_SafeSeek(s, tile.crRawLen))
1582 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1587 return progressive_surface_tile_replace(surface, region, &tile, TRUE);
1590 static INLINE BOOL progressive_tile_read(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1591 BOOL simple,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1594 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1598 size_t expect = simple ? 16 : 17;
1600 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1603 tile.blockType = blockType;
1604 tile.blockLen = blockLen;
1606 Stream_Read_UINT8(s, tile.quantIdxY);
1607 Stream_Read_UINT8(s, tile.quantIdxCb);
1608 Stream_Read_UINT8(s, tile.quantIdxCr);
1609 Stream_Read_UINT16(s, tile.xIdx);
1610 Stream_Read_UINT16(s, tile.yIdx);
1611 Stream_Read_UINT8(s, tile.flags);
1614 Stream_Read_UINT8(s, tile.quality);
1616 tile.quality = 0xFF;
1617 Stream_Read_UINT16(s, tile.yLen);
1618 Stream_Read_UINT16(s, tile.cbLen);
1619 Stream_Read_UINT16(s, tile.crLen);
1620 Stream_Read_UINT16(s, tile.tailLen);
1622 tile.yData = Stream_Pointer(s);
1623 if (!Stream_SafeSeek(s, tile.yLen))
1625 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yLen);
1629 tile.cbData = Stream_Pointer(s);
1630 if (!Stream_SafeSeek(s, tile.cbLen))
1632 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.cbLen);
1636 tile.crData = Stream_Pointer(s);
1637 if (!Stream_SafeSeek(s, tile.crLen))
1639 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.crLen);
1643 tile.tailData = Stream_Pointer(s);
1644 if (!Stream_SafeSeek(s, tile.tailLen))
1646 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.tailLen);
1650 return progressive_surface_tile_replace(surface, region, &tile, FALSE);
1653 static void CALLBACK progressive_process_tiles_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1654 void* context, PTP_WORK work)
1658 WINPR_UNUSED(instance);
1661 switch (param->tile->blockType)
1663 case PROGRESSIVE_WBT_TILE_SIMPLE:
1664 case PROGRESSIVE_WBT_TILE_FIRST:
1665 progressive_decompress_tile_first(param->progressive, param->tile, param->region,
1669 case PROGRESSIVE_WBT_TILE_UPGRADE:
1670 progressive_decompress_tile_upgrade(param->progressive, param->tile, param->region,
1674 WLog_Print(param->progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16
" (%s)",
1675 param->tile->blockType,
1676 rfx_get_progressive_block_type_string(param->tile->blockType));
1681 static INLINE SSIZE_T progressive_process_tiles(
1682 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s,
1683 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1689 const size_t start = Stream_GetPosition(s);
1690 UINT16 blockType = 0;
1691 UINT32 blockLen = 0;
1693 UINT16 close_cnt = 0;
1695 WINPR_ASSERT(progressive);
1696 WINPR_ASSERT(region);
1698 if (!Stream_CheckAndLogRequiredLength(TAG, s, region->tileDataSize))
1701 while ((Stream_GetRemainingLength(s) >= 6) &&
1702 (region->tileDataSize > (Stream_GetPosition(s) - start)))
1704 const size_t pos = Stream_GetPosition(s);
1706 Stream_Read_UINT16(s, blockType);
1707 Stream_Read_UINT32(s, blockLen);
1709 #if defined(WITH_DEBUG_CODECS)
1710 WLog_Print(progressive->log, WLOG_DEBUG,
"%s",
1711 rfx_get_progressive_block_type_string(blockType));
1716 WLog_Print(progressive->log, WLOG_ERROR,
"Expected >= %" PRIu32
" remaining %" PRIuz, 6,
1720 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
1725 case PROGRESSIVE_WBT_TILE_SIMPLE:
1726 if (!progressive_tile_read(progressive, TRUE, s, blockType, blockLen, surface,
1731 case PROGRESSIVE_WBT_TILE_FIRST:
1732 if (!progressive_tile_read(progressive, FALSE, s, blockType, blockLen, surface,
1737 case PROGRESSIVE_WBT_TILE_UPGRADE:
1738 if (!progressive_tile_read_upgrade(progressive, s, blockType, blockLen, surface,
1743 WLog_ERR(TAG,
"Invalid block type %04" PRIx16
" (%s)", blockType,
1744 rfx_get_progressive_block_type_string(blockType));
1748 size_t rem = Stream_GetPosition(s);
1749 if ((rem - pos) != blockLen)
1751 WLog_Print(progressive->log, WLOG_ERROR,
1752 "Actual block read %" PRIuz
" but expected %" PRIu32, rem - pos, blockLen);
1758 end = Stream_GetPosition(s);
1759 if ((end - start) != region->tileDataSize)
1761 WLog_Print(progressive->log, WLOG_ERROR,
1762 "Actual total blocks read %" PRIuz
" but expected %" PRIu32, end - start,
1763 region->tileDataSize);
1767 if (count != region->numTiles)
1769 WLog_Print(progressive->log, WLOG_WARN,
1770 "numTiles inconsistency: actual: %" PRIu32
", expected: %" PRIu16
"\n", count,
1775 for (UINT32 idx = 0; idx < region->numTiles; idx++)
1779 param->progressive = progressive;
1780 param->region = region;
1781 param->context = context;
1784 if (progressive->rfx_context->priv->UseThreads)
1786 progressive->work_objects[idx] =
1787 CreateThreadpoolWork(progressive_process_tiles_tile_work_callback, (
void*)param,
1788 &progressive->rfx_context->priv->ThreadPoolEnv);
1789 if (!progressive->work_objects[idx])
1791 WLog_Print(progressive->log, WLOG_ERROR,
1792 "Failed to create ThreadpoolWork for tile %" PRIu32, idx);
1797 SubmitThreadpoolWork(progressive->work_objects[idx]);
1799 close_cnt = WINPR_ASSERTING_INT_CAST(UINT16, idx + 1);
1803 progressive_process_tiles_tile_work_callback(0, param, 0);
1808 WLog_Print(progressive->log, WLOG_ERROR,
"Failed to decompress %s at %" PRIu16,
1809 rfx_get_progressive_block_type_string(tile->blockType), idx);
1814 if (progressive->rfx_context->priv->UseThreads)
1816 for (UINT32 idx = 0; idx < close_cnt; idx++)
1818 WaitForThreadpoolWorkCallbacks(progressive->work_objects[idx], FALSE);
1819 CloseThreadpoolWork(progressive->work_objects[idx]);
1828 return (SSIZE_T)(end - start);
1831 static INLINE SSIZE_T progressive_wb_sync(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1832 wStream* WINPR_RESTRICT s, UINT16 blockType,
1835 const UINT32 magic = 0xCACCACCA;
1836 const UINT16 version = 0x0100;
1839 sync.blockType = blockType;
1840 sync.blockLen = blockLen;
1842 if (sync.blockLen != 12)
1844 WLog_Print(progressive->log, WLOG_ERROR,
1845 "PROGRESSIVE_BLOCK_SYNC::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1850 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1853 #if defined(WITH_DEBUG_CODECS)
1854 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveSync");
1857 Stream_Read_UINT32(s, sync.magic);
1858 Stream_Read_UINT16(s, sync.version);
1860 if (sync.magic != magic)
1862 WLog_Print(progressive->log, WLOG_ERROR,
1863 "PROGRESSIVE_BLOCK_SYNC::magic = 0x%08" PRIx32
" != 0x%08" PRIx32, sync.magic,
1868 if (sync.version != 0x0100)
1870 WLog_Print(progressive->log, WLOG_ERROR,
1871 "PROGRESSIVE_BLOCK_SYNC::version = 0x%04" PRIx16
" != 0x%04" PRIu16,
1872 sync.version, version);
1876 if ((progressive->state & FLAG_WBT_SYNC) != 0)
1877 WLog_WARN(TAG,
"Duplicate PROGRESSIVE_BLOCK_SYNC, ignoring");
1879 progressive->state |= FLAG_WBT_SYNC;
1883 static INLINE SSIZE_T progressive_wb_frame_begin(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1884 wStream* WINPR_RESTRICT s, UINT16 blockType,
1889 frameBegin.blockType = blockType;
1890 frameBegin.blockLen = blockLen;
1892 if (frameBegin.blockLen != 12)
1894 WLog_Print(progressive->log, WLOG_ERROR,
1895 " RFX_PROGRESSIVE_FRAME_BEGIN::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1896 frameBegin.blockLen, 12);
1900 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1903 Stream_Read_UINT32(s, frameBegin.frameIndex);
1904 Stream_Read_UINT16(s, frameBegin.regionCount);
1906 #if defined(WITH_DEBUG_CODECS)
1907 WLog_Print(progressive->log, WLOG_DEBUG,
1908 "ProgressiveFrameBegin: frameIndex: %" PRIu32
" regionCount: %" PRIu16
"",
1909 frameBegin.frameIndex, frameBegin.regionCount);
1918 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1920 WLog_ERR(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_BEGIN in stream, this is not allowed!");
1924 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1926 WLog_ERR(TAG,
"RFX_PROGRESSIVE_FRAME_BEGIN after RFX_PROGRESSIVE_FRAME_END in stream, this "
1931 progressive->state |= FLAG_WBT_FRAME_BEGIN;
1935 static INLINE SSIZE_T progressive_wb_frame_end(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1936 wStream* WINPR_RESTRICT s, UINT16 blockType,
1941 frameEnd.blockType = blockType;
1942 frameEnd.blockLen = blockLen;
1944 if (frameEnd.blockLen != 6)
1946 WLog_Print(progressive->log, WLOG_ERROR,
1947 " RFX_PROGRESSIVE_FRAME_END::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1948 frameEnd.blockLen, 6);
1952 if (Stream_GetRemainingLength(s) != 0)
1954 WLog_Print(progressive->log, WLOG_ERROR,
1955 "ProgressiveFrameEnd short %" PRIuz
", expected %" PRIuz,
1956 Stream_GetRemainingLength(s), 0);
1960 #if defined(WITH_DEBUG_CODECS)
1961 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveFrameEnd");
1964 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
1965 WLog_WARN(TAG,
"RFX_PROGRESSIVE_FRAME_END before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
1966 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1967 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_END, ignoring");
1969 progressive->state |= FLAG_WBT_FRAME_END;
1973 static INLINE SSIZE_T progressive_wb_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1974 wStream* WINPR_RESTRICT s, UINT16 blockType,
1978 context->blockType = blockType;
1979 context->blockLen = blockLen;
1981 if (context->blockLen != 10)
1983 WLog_Print(progressive->log, WLOG_ERROR,
1984 "RFX_PROGRESSIVE_CONTEXT::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1985 context->blockLen, 10);
1989 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1992 Stream_Read_UINT8(s, context->ctxId);
1993 Stream_Read_UINT16(s, context->tileSize);
1994 Stream_Read_UINT8(s, context->flags);
1996 if (context->ctxId != 0x00)
1997 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT::ctxId != 0x00: %" PRIu8, context->ctxId);
1999 if (context->tileSize != 64)
2001 WLog_ERR(TAG,
"RFX_PROGRESSIVE_CONTEXT::tileSize != 0x40: %" PRIu16, context->tileSize);
2005 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
2006 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_BEGIN");
2007 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2008 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_END");
2009 if ((progressive->state & FLAG_WBT_CONTEXT) != 0)
2010 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_CONTEXT received, ignoring.");
2012 #if defined(WITH_DEBUG_CODECS)
2013 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveContext: flags: 0x%02" PRIX8
"",
2017 progressive->state |= FLAG_WBT_CONTEXT;
2021 static INLINE SSIZE_T progressive_wb_read_region_header(
2022 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
2023 UINT32 blockLen, PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2025 region->usedTiles = 0;
2027 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2030 region->blockType = blockType;
2031 region->blockLen = blockLen;
2032 Stream_Read_UINT8(s, region->tileSize);
2033 Stream_Read_UINT16(s, region->numRects);
2034 Stream_Read_UINT8(s, region->numQuant);
2035 Stream_Read_UINT8(s, region->numProgQuant);
2036 Stream_Read_UINT8(s, region->flags);
2037 Stream_Read_UINT16(s, region->numTiles);
2038 Stream_Read_UINT32(s, region->tileDataSize);
2040 if (region->tileSize != 64)
2042 WLog_Print(progressive->log, WLOG_ERROR,
2043 "ProgressiveRegion tile size %" PRIu8
", expected %" PRIuz, region->tileSize,
2048 if (region->numRects < 1)
2050 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion missing rect count %" PRIu16,
2055 if (region->numQuant > 7)
2057 WLog_Print(progressive->log, WLOG_ERROR,
2058 "ProgressiveRegion quant count too high %" PRIu8
", expected < %" PRIuz,
2059 region->numQuant, 7);
2063 const SSIZE_T rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, Stream_GetRemainingLength(s));
2064 const SSIZE_T expect = region->numRects * 8ll + region->numQuant * 5ll +
2065 region->numProgQuant * 16ll + region->tileDataSize;
2069 if (len / 8LL < region->numRects)
2071 WLog_Print(progressive->log, WLOG_ERROR,
2072 "ProgressiveRegion data short for region->rects");
2075 len -= region->numRects * 8LL;
2077 if (len / 5LL < region->numQuant)
2079 WLog_Print(progressive->log, WLOG_ERROR,
2080 "ProgressiveRegion data short for region->cQuant");
2083 len -= region->numQuant * 5LL;
2085 if (len / 16LL < region->numProgQuant)
2087 WLog_Print(progressive->log, WLOG_ERROR,
2088 "ProgressiveRegion data short for region->cProgQuant");
2091 len -= region->numProgQuant * 16LL;
2093 if (len < region->tileDataSize * 1ll)
2095 WLog_Print(progressive->log, WLOG_ERROR,
2096 "ProgressiveRegion data short for region->tiles");
2099 len -= region->tileDataSize;
2102 WLog_Print(progressive->log, WLOG_WARN,
2103 "Unused bytes detected, %" PRIdz
" bytes not processed", len);
2109 static INLINE SSIZE_T progressive_wb_skip_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2110 wStream* WINPR_RESTRICT s, UINT16 blockType,
2113 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2116 progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2120 if (!Stream_SafeSeek(s, WINPR_ASSERTING_INT_CAST(
size_t, rc)))
2126 static INLINE SSIZE_T progressive_wb_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2127 wStream* WINPR_RESTRICT s, UINT16 blockType,
2130 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2135 UINT16 boxRight = 0;
2136 UINT16 boxBottom = 0;
2139 UINT16 idxRight = 0;
2140 UINT16 idxBottom = 0;
2143 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
2145 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
2146 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2148 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2150 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION after RFX_PROGRESSIVE_FRAME_END, ignoring");
2151 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2154 progressive->state |= FLAG_WBT_REGION;
2156 rc = progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2160 for (UINT16 index = 0; index < region->numRects; index++)
2162 RFX_RECT* rect = &(region->rects[index]);
2163 Stream_Read_UINT16(s, rect->x);
2164 Stream_Read_UINT16(s, rect->y);
2165 Stream_Read_UINT16(s, rect->width);
2166 Stream_Read_UINT16(s, rect->height);
2169 for (BYTE index = 0; index < region->numQuant; index++)
2172 progressive_component_codec_quant_read(s, quantVal);
2174 if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
2176 WLog_Print(progressive->log, WLOG_ERROR,
2177 "ProgressiveRegion region->cQuant[%" PRIu32
"] < 6", index);
2181 if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
2183 WLog_Print(progressive->log, WLOG_ERROR,
2184 "ProgressiveRegion region->cQuant[%" PRIu32
"] > 15", index);
2189 for (BYTE index = 0; index < region->numProgQuant; index++)
2193 Stream_Read_UINT8(s, quantProgVal->quality);
2195 progressive_component_codec_quant_read(s, &(quantProgVal->yQuantValues));
2196 progressive_component_codec_quant_read(s, &(quantProgVal->cbQuantValues));
2197 progressive_component_codec_quant_read(s, &(quantProgVal->crQuantValues));
2200 #if defined(WITH_DEBUG_CODECS)
2201 WLog_Print(progressive->log, WLOG_DEBUG,
2202 "ProgressiveRegion: numRects: %" PRIu16
" numTiles: %" PRIu16
2203 " tileDataSize: %" PRIu32
" flags: 0x%02" PRIX8
" numQuant: %" PRIu8
2204 " numProgQuant: %" PRIu8
"",
2205 region->numRects, region->numTiles, region->tileDataSize, region->flags,
2206 region->numQuant, region->numProgQuant);
2209 boxLeft = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridWidth);
2210 boxTop = WINPR_ASSERTING_INT_CAST(UINT16, surface->gridHeight);
2214 for (UINT16 index = 0; index < region->numRects; index++)
2216 RFX_RECT* rect = &(region->rects[index]);
2217 idxLeft = rect->x / 64;
2218 idxTop = rect->y / 64;
2219 idxRight = (rect->x + rect->width + 63) / 64;
2220 idxBottom = (rect->y + rect->height + 63) / 64;
2222 if (idxLeft < boxLeft)
2225 if (idxTop < boxTop)
2228 if (idxRight > boxRight)
2229 boxRight = idxRight;
2231 if (idxBottom > boxBottom)
2232 boxBottom = idxBottom;
2234 #if defined(WITH_DEBUG_CODECS)
2235 WLog_Print(progressive->log, WLOG_DEBUG,
2236 "rect[%" PRIu16
"]: x: %" PRIu16
" y: %" PRIu16
" w: %" PRIu16
" h: %" PRIu16
"",
2237 index, rect->x, rect->y, rect->width, rect->height);
2241 const SSIZE_T res = progressive_process_tiles(progressive, s, region, surface, context);
2247 static INLINE SSIZE_T progressive_parse_block(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2250 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2252 UINT16 blockType = 0;
2253 UINT32 blockLen = 0;
2257 WINPR_ASSERT(progressive);
2259 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
2262 Stream_Read_UINT16(s, blockType);
2263 Stream_Read_UINT32(s, blockLen);
2267 WLog_WARN(TAG,
"Invalid blockLen %" PRIu32
", expected >= 6", blockLen);
2270 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
2272 Stream_StaticConstInit(&sub, Stream_Pointer(s), blockLen - 6);
2273 Stream_Seek(s, blockLen - 6);
2277 case PROGRESSIVE_WBT_SYNC:
2278 rc = progressive_wb_sync(progressive, &sub, blockType, blockLen);
2281 case PROGRESSIVE_WBT_FRAME_BEGIN:
2282 rc = progressive_wb_frame_begin(progressive, &sub, blockType, blockLen);
2285 case PROGRESSIVE_WBT_FRAME_END:
2286 rc = progressive_wb_frame_end(progressive, &sub, blockType, blockLen);
2289 case PROGRESSIVE_WBT_CONTEXT:
2290 rc = progressive_wb_context(progressive, &sub, blockType, blockLen);
2293 case PROGRESSIVE_WBT_REGION:
2294 rc = progressive_wb_region(progressive, &sub, blockType, blockLen, surface, region);
2298 WLog_Print(progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16, blockType);
2305 if (Stream_GetRemainingLength(&sub) > 0)
2307 WLog_Print(progressive->log, WLOG_ERROR,
2308 "block len %" PRIu32
" does not match read data %" PRIuz, blockLen,
2309 blockLen - Stream_GetRemainingLength(&sub));
2316 static INLINE BOOL update_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2318 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2319 UINT32 nXDst, UINT32 nYDst,
2320 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
2321 REGION16* WINPR_RESTRICT invalidRegion)
2325 region16_init(&clippingRects);
2327 for (UINT32 i = 0; i < region->numRects; i++)
2330 const RFX_RECT* rect = &(region->rects[i]);
2332 clippingRect.left = (UINT16)nXDst + rect->x;
2333 clippingRect.top = (UINT16)nYDst + rect->y;
2334 clippingRect.right = clippingRect.left + rect->width;
2335 clippingRect.bottom = clippingRect.top + rect->height;
2336 region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
2339 for (UINT32 i = 0; i < surface->numUpdatedTiles; i++)
2341 UINT32 nbUpdateRects = 0;
2345 WINPR_ASSERT(surface->updatedTileIndices);
2346 const UINT32 index = surface->updatedTileIndices[i];
2348 WINPR_ASSERT(index < surface->tilesSize);
2352 const UINT32 dl = nXDst + tile->x;
2353 updateRect.left = WINPR_ASSERTING_INT_CAST(UINT16, dl);
2355 const UINT32 dt = nYDst + tile->y;
2356 updateRect.top = WINPR_ASSERTING_INT_CAST(UINT16, dt);
2357 updateRect.right = updateRect.left + 64;
2358 updateRect.bottom = updateRect.top + 64;
2361 region16_init(&updateRegion);
2362 region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
2363 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
2365 for (UINT32 j = 0; j < nbUpdateRects; j++)
2368 if (rect->left < updateRect.left)
2370 const UINT32 nXSrc = rect->left - updateRect.left;
2371 const UINT32 nYSrc = rect->top - updateRect.top;
2372 const UINT32 width = rect->right - rect->left;
2373 const UINT32 height = rect->bottom - rect->top;
2375 if (rect->left + width > surface->width)
2377 if (rect->top + height > surface->height)
2379 rc = freerdp_image_copy_no_overlap(
2380 pDstData, DstFormat, nDstStep, rect->left, rect->top, width, height, tile->data,
2381 progressive->format, tile->stride, nXSrc, nYSrc, NULL, FREERDP_KEEP_DST_ALPHA);
2386 region16_union_rect(invalidRegion, invalidRegion, rect);
2389 region16_uninit(&updateRegion);
2390 tile->dirty = FALSE;
2394 region16_uninit(&clippingRects);
2398 INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2399 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
2400 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2401 UINT32 nXDst, UINT32 nYDst,
REGION16* WINPR_RESTRICT invalidRegion,
2402 UINT16 surfaceId, UINT32 frameId)
2406 WINPR_ASSERT(progressive);
2411 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion no surface for %" PRIu16,
2416 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2417 WINPR_ASSERT(region);
2419 if (surface->frameId != frameId)
2421 surface->frameId = frameId;
2422 surface->numUpdatedTiles = 0;
2426 wStream* s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
2431 case PIXEL_FORMAT_RGBA32:
2432 case PIXEL_FORMAT_RGBX32:
2433 case PIXEL_FORMAT_BGRA32:
2434 case PIXEL_FORMAT_BGRX32:
2435 progressive->format = DstFormat;
2438 progressive->format = PIXEL_FORMAT_XRGB32;
2442 const size_t start = Stream_GetPosition(s);
2443 progressive->state = 0;
2444 while (Stream_GetRemainingLength(s) > 0)
2446 if (progressive_parse_block(progressive, s, surface, region) < 0)
2450 const size_t end = Stream_GetPosition(s);
2451 if ((end - start) != SrcSize)
2453 WLog_Print(progressive->log, WLOG_ERROR,
2454 "total block len %" PRIuz
" does not match read data %" PRIu32, end - start,
2460 if (!update_tiles(progressive, surface, pDstData, DstFormat, nDstStep, nXDst, nYDst, region,
2467 BOOL progressive_rfx_write_message_progressive_simple(PROGRESSIVE_CONTEXT* progressive,
wStream* s,
2468 const RFX_MESSAGE* msg)
2470 RFX_CONTEXT* context = NULL;
2472 WINPR_ASSERT(progressive);
2475 context = progressive->rfx_context;
2476 return rfx_write_message_progressive_simple(context, s, msg);
2479 int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2480 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 SrcFormat,
2481 UINT32 Width, UINT32 Height, UINT32 ScanLine,
2482 const REGION16* WINPR_RESTRICT invalidRegion,
2483 BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize)
2488 UINT32 numRects = 0;
2490 RFX_MESSAGE* message = NULL;
2492 if (!progressive || !pSrcData || !ppDstData || !pDstSize)
2501 case PIXEL_FORMAT_ABGR32:
2502 case PIXEL_FORMAT_ARGB32:
2503 case PIXEL_FORMAT_XBGR32:
2504 case PIXEL_FORMAT_XRGB32:
2505 case PIXEL_FORMAT_BGRA32:
2506 case PIXEL_FORMAT_BGRX32:
2507 case PIXEL_FORMAT_RGBA32:
2508 case PIXEL_FORMAT_RGBX32:
2509 ScanLine = Width * 4;
2516 if (SrcSize < Height * ScanLine)
2521 numRects = (Width + 63) / 64;
2522 numRects *= (Height + 63) / 64;
2526 const int nr = region16_n_rects(invalidRegion);
2527 numRects = WINPR_ASSERTING_INT_CAST(uint32_t, nr);
2533 if (!Stream_EnsureCapacity(progressive->rects, numRects *
sizeof(
RFX_RECT)))
2535 rects = Stream_BufferAs(progressive->rects,
RFX_RECT);
2538 const RECTANGLE_16* region_rects = region16_rects(invalidRegion, NULL);
2539 for (UINT32 idx = 0; idx < numRects; idx++)
2546 rect->width = r->right - r->left;
2547 rect->height = r->bottom - r->top;
2555 for (UINT32 i = 0; i < numRects; i++)
2561 WINPR_ASSERT(Width >= x);
2562 WINPR_ASSERT(Height >= y);
2563 r->width = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Width - x));
2564 r->height = MIN(64, WINPR_ASSERTING_INT_CAST(UINT16, Height - y));
2566 if (x + 64 >= Width)
2574 WINPR_ASSERT(r->x % 64 == 0);
2575 WINPR_ASSERT(r->y % 64 == 0);
2576 WINPR_ASSERT(r->width <= 64);
2577 WINPR_ASSERT(r->height <= 64);
2580 s = progressive->buffer;
2581 Stream_SetPosition(s, 0);
2583 progressive->rfx_context->mode = RLGR1;
2585 progressive->rfx_context->width = WINPR_ASSERTING_INT_CAST(UINT16, Width);
2586 progressive->rfx_context->height = WINPR_ASSERTING_INT_CAST(UINT16, Height);
2587 rfx_context_set_pixel_format(progressive->rfx_context, SrcFormat);
2588 message = rfx_encode_message(progressive->rfx_context, rects, numRects, pSrcData, Width, Height,
2592 WLog_ERR(TAG,
"failed to encode rfx message");
2596 rc = progressive_rfx_write_message_progressive_simple(progressive, s, message);
2597 rfx_message_free(progressive->rfx_context, message);
2601 const size_t pos = Stream_GetPosition(s);
2602 WINPR_ASSERT(pos <= UINT32_MAX);
2603 *pDstSize = (UINT32)pos;
2604 *ppDstData = Stream_Buffer(s);
2610 BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive)
2618 PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
2620 return progressive_context_new_ex(Compressor, 0);
2623 PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, UINT32 ThreadingFlags)
2625 PROGRESSIVE_CONTEXT* progressive =
2626 (PROGRESSIVE_CONTEXT*)winpr_aligned_calloc(1,
sizeof(PROGRESSIVE_CONTEXT), 32);
2631 progressive->Compressor = Compressor;
2632 progressive->quantProgValFull.quality = 100;
2633 progressive->log = WLog_Get(TAG);
2634 if (!progressive->log)
2636 progressive->rfx_context = rfx_context_new_ex(Compressor, ThreadingFlags);
2637 if (!progressive->rfx_context)
2639 progressive->buffer = Stream_New(NULL, 1024);
2640 if (!progressive->buffer)
2642 progressive->rects = Stream_New(NULL, 1024);
2643 if (!progressive->rects)
2645 progressive->bufferPool = BufferPool_New(TRUE, (8192LL + 32LL) * 3LL, 16);
2646 if (!progressive->bufferPool)
2648 progressive->SurfaceContexts = HashTable_New(TRUE);
2649 if (!progressive->SurfaceContexts)
2653 wObject* obj = HashTable_ValueObject(progressive->SurfaceContexts);
2655 obj->fnObjectFree = progressive_surface_context_free;
2659 WINPR_PRAGMA_DIAG_PUSH
2660 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2661 progressive_context_free(progressive);
2662 WINPR_PRAGMA_DIAG_POP
2666 void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
2671 Stream_Free(progressive->buffer, TRUE);
2672 Stream_Free(progressive->rects, TRUE);
2673 rfx_context_free(progressive->rfx_context);
2675 BufferPool_Free(progressive->bufferPool);
2676 HashTable_Free(progressive->SurfaceContexts);
2678 winpr_aligned_free(progressive);
__lShiftC_16s_inplace_t lShiftC_16s_inplace
__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.