22 #include <freerdp/config.h>
24 #include <winpr/assert.h>
25 #include <winpr/crt.h>
26 #include <winpr/print.h>
27 #include <winpr/bitstream.h>
29 #include <freerdp/primitives.h>
30 #include <freerdp/codec/color.h>
31 #include <freerdp/codec/progressive.h>
32 #include <freerdp/codec/region.h>
33 #include <freerdp/log.h>
35 #include "rfx_differential.h"
36 #include "rfx_quantization.h"
39 #include "rfx_constants.h"
40 #include "rfx_types.h"
41 #include "progressive.h"
43 #define TAG FREERDP_TAG("codec.progressive")
56 } RFX_PROGRESSIVE_UPGRADE_STATE;
59 progressive_component_codec_quant_read(
wStream* WINPR_RESTRICT s,
63 Stream_Read_UINT8(s, b);
64 quantVal->LL3 = b & 0x0F;
65 quantVal->HL3 = b >> 4;
66 Stream_Read_UINT8(s, b);
67 quantVal->LH3 = b & 0x0F;
68 quantVal->HH3 = b >> 4;
69 Stream_Read_UINT8(s, b);
70 quantVal->HL2 = b & 0x0F;
71 quantVal->LH2 = b >> 4;
72 Stream_Read_UINT8(s, b);
73 quantVal->HH2 = b & 0x0F;
74 quantVal->HL1 = b >> 4;
75 Stream_Read_UINT8(s, b);
76 quantVal->LH1 = b & 0x0F;
77 quantVal->HH1 = b >> 4;
98 dst->HL1 = q1->HL1 + q2->HL1;
99 dst->LH1 = q1->LH1 + q2->LH1;
100 dst->HH1 = q1->HH1 + q2->HH1;
101 dst->HL2 = q1->HL2 + q2->HL2;
102 dst->LH2 = q1->LH2 + q2->LH2;
103 dst->HH2 = q1->HH2 + q2->HH2;
104 dst->HL3 = q1->HL3 + q2->HL3;
105 dst->LH3 = q1->LH3 + q2->LH3;
106 dst->HH3 = q1->HH3 + q2->HH3;
107 dst->LL3 = q1->LL3 + q2->LL3;
128 dst->HL1 = q1->HL1 - q2->HL1;
129 dst->LH1 = q1->LH1 - q2->LH1;
130 dst->HH1 = q1->HH1 - q2->HH1;
131 dst->HL2 = q1->HL2 - q2->HL2;
132 dst->LH2 = q1->LH2 - q2->LH2;
133 dst->HH2 = q1->HH2 - q2->HH2;
134 dst->HL3 = q1->HL3 - q2->HL3;
135 dst->LH3 = q1->LH3 - q2->LH3;
136 dst->HH3 = q1->HH3 - q2->HH3;
137 dst->LL3 = q1->LL3 - q2->LL3;
180 if (q1->HL1 > q2->HL1)
183 if (q1->LH1 > q2->LH1)
186 if (q1->HH1 > q2->HH1)
189 if (q1->HL2 > q2->HL2)
192 if (q1->LH2 > q2->LH2)
195 if (q1->HH2 > q2->HH2)
198 if (q1->HL3 > q2->HL3)
201 if (q1->LH3 > q2->LH3)
204 if (q1->HH3 > q2->HH3)
207 if (q1->LL3 > q2->LL3)
253 if (q1->HL1 < q2->HL1)
256 if (q1->LH1 < q2->LH1)
259 if (q1->HH1 < q2->HH1)
262 if (q1->HL2 < q2->HL2)
265 if (q1->LH2 < q2->LH2)
268 if (q1->HH2 < q2->HH2)
271 if (q1->HL3 < q2->HL3)
274 if (q1->LH3 < q2->LH3)
277 if (q1->HH3 < q2->HH3)
280 if (q1->LL3 < q2->LL3)
290 if (q1->HL1 != q2->HL1)
293 if (q1->LH1 != q2->LH1)
296 if (q1->HH1 != q2->HH1)
299 if (q1->HL2 != q2->HL2)
302 if (q1->LH2 != q2->LH2)
305 if (q1->HH2 != q2->HH2)
308 if (q1->HL3 != q2->HL3)
311 if (q1->LH3 != q2->LH3)
314 if (q1->HH3 != q2->HH3)
317 if (q1->LL3 != q2->LL3)
323 static INLINE BOOL progressive_set_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
328 key = ((ULONG_PTR)surfaceId) + 1;
331 return HashTable_Insert(progressive->SurfaceContexts, (
void*)key, pData);
333 HashTable_Remove(progressive->SurfaceContexts, (
void*)key);
338 progressive_get_surface_data(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, UINT16 surfaceId)
340 void* key = (
void*)(((ULONG_PTR)surfaceId) + 1);
345 return HashTable_GetItemValue(progressive->SurfaceContexts, key);
352 winpr_aligned_free(tile->sign);
353 winpr_aligned_free(tile->current);
354 winpr_aligned_free(tile->data);
355 winpr_aligned_free(tile);
359 static void progressive_surface_context_free(
void* ptr)
368 for (
size_t index = 0; index < surface->tilesSize; index++)
371 progressive_tile_free(tile);
375 winpr_aligned_free(surface->tiles);
376 winpr_aligned_free(surface->updatedTileIndices);
377 winpr_aligned_free(surface);
388 tile->stride = 4 * tile->width;
390 size_t dataLen = 1ull * tile->stride * tile->height;
391 tile->data = (BYTE*)winpr_aligned_malloc(dataLen, 16);
394 memset(tile->data, 0xFF, dataLen);
396 size_t signLen = (8192ULL + 32ULL) * 3ULL;
397 tile->sign = (BYTE*)winpr_aligned_malloc(signLen, 16);
401 size_t currentLen = (8192ULL + 32ULL) * 3ULL;
402 tile->current = (BYTE*)winpr_aligned_malloc(currentLen, 16);
409 progressive_tile_free(tile);
418 WINPR_ASSERT(surface);
419 WINPR_ASSERT(surface->gridSize > 0);
423 oldIndex = surface->gridSize;
424 while (surface->gridSize < min)
425 surface->gridSize += 1024;
428 void* tmp = winpr_aligned_recalloc(surface->tiles, surface->gridSize,
432 surface->tilesSize = surface->gridSize;
433 surface->tiles = tmp;
435 for (
size_t x = oldIndex; x < surface->tilesSize; x++)
437 surface->tiles[x] = progressive_tile_new();
438 if (!surface->tiles[x])
443 winpr_aligned_recalloc(surface->updatedTileIndices, surface->gridSize,
sizeof(UINT32), 32);
447 surface->updatedTileIndices = tmp;
461 surface->id = surfaceId;
462 surface->width = width;
463 surface->height = height;
464 surface->gridWidth = (width + (64 - width % 64)) / 64;
465 surface->gridHeight = (height + (64 - height % 64)) / 64;
466 surface->gridSize = surface->gridWidth * surface->gridHeight;
468 if (!progressive_allocate_tile_cache(surface, surface->gridSize))
470 progressive_surface_context_free(surface);
479 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
485 if (!surface || !tile)
488 zIdx = (tile->yIdx * surface->gridWidth) + tile->xIdx;
490 if (zIdx >= surface->tilesSize)
492 WLog_ERR(TAG,
"Invalid zIndex %" PRIuz, zIdx);
496 t = surface->tiles[zIdx];
498 t->blockType = tile->blockType;
499 t->blockLen = tile->blockLen;
500 t->quantIdxY = tile->quantIdxY;
501 t->quantIdxCb = tile->quantIdxCb;
502 t->quantIdxCr = tile->quantIdxCr;
503 t->xIdx = tile->xIdx;
504 t->yIdx = tile->yIdx;
505 t->flags = tile->flags;
506 t->quality = tile->quality;
507 t->x = tile->xIdx * t->width;
508 t->y = tile->yIdx * t->height;
512 t->ySrlLen = tile->ySrlLen;
513 t->yRawLen = tile->yRawLen;
514 t->cbSrlLen = tile->cbSrlLen;
515 t->cbRawLen = tile->cbRawLen;
516 t->crSrlLen = tile->crSrlLen;
517 t->crRawLen = tile->crRawLen;
518 t->ySrlData = tile->ySrlData;
519 t->yRawData = tile->yRawData;
520 t->cbSrlData = tile->cbSrlData;
521 t->cbRawData = tile->cbRawData;
522 t->crSrlData = tile->crSrlData;
523 t->crRawData = tile->crRawData;
527 t->yLen = tile->yLen;
528 t->cbLen = tile->cbLen;
529 t->crLen = tile->crLen;
530 t->tailLen = tile->tailLen;
531 t->yData = tile->yData;
532 t->cbData = tile->cbData;
533 t->crData = tile->crData;
534 t->tailData = tile->tailData;
537 if (region->usedTiles >= region->numTiles)
539 WLog_ERR(TAG,
"Invalid tile count, only expected %" PRIu16
", got %" PRIu16,
540 region->numTiles, region->usedTiles);
544 region->tiles[region->usedTiles++] = t;
547 if (surface->numUpdatedTiles >= surface->gridSize)
549 if (!progressive_allocate_tile_cache(surface, surface->numUpdatedTiles + 1))
553 surface->updatedTileIndices[surface->numUpdatedTiles++] = (UINT32)zIdx;
560 INT32 progressive_create_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
561 UINT16 surfaceId, UINT32 width, UINT32 height)
567 surface = progressive_surface_context_new(surfaceId, width, height);
572 if (!progressive_set_surface_data(progressive, surfaceId, (
void*)surface))
574 progressive_surface_context_free(surface);
582 int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
585 progressive_set_surface_data(progressive, surfaceId, NULL);
608 static INLINE
void progressive_rfx_idwt_x(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
609 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
610 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
611 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
620 for (
size_t i = 0; i < nDstCount; i++)
622 const INT16* pL = pLowBand;
623 const INT16* pH = pHighBand;
624 INT16* pX = pDstBand;
630 for (
size_t j = 0; j < (nHighCount - 1); j++)
636 X2 = L0 - ((H0 + H1) / 2);
637 X1 = ((X0 + X2) / 2) + (2 * H0);
645 if (nLowCount <= (nHighCount + 1))
647 if (nLowCount <= nHighCount)
650 pX[1] = X2 + (2 * H0);
658 pX[1] = ((X0 + X2) / 2) + (2 * H0);
668 pX[1] = ((X0 + X2) / 2) + (2 * H0);
672 pX[3] = (X0 + L0) / 2;
675 pLowBand += nLowStep;
676 pHighBand += nHighStep;
677 pDstBand += nDstStep;
681 static INLINE
void progressive_rfx_idwt_y(
const INT16* WINPR_RESTRICT pLowBand,
size_t nLowStep,
682 const INT16* WINPR_RESTRICT pHighBand,
size_t nHighStep,
683 INT16* WINPR_RESTRICT pDstBand,
size_t nDstStep,
684 size_t nLowCount,
size_t nHighCount,
size_t nDstCount)
693 for (
size_t i = 0; i < nDstCount; i++)
695 const INT16* pL = pLowBand;
696 const INT16* pH = pHighBand;
697 INT16* pX = pDstBand;
705 for (
size_t j = 0; j < (nHighCount - 1); j++)
711 X2 = L0 - ((H0 + H1) / 2);
712 X1 = ((X0 + X2) / 2) + (2 * H0);
721 if (nLowCount <= (nHighCount + 1))
723 if (nLowCount <= nHighCount)
735 *pX = ((X0 + X2) / 2) + (2 * H0);
747 *pX = ((X0 + X2) / 2) + (2 * H0);
761 static INLINE
size_t progressive_rfx_get_band_l_count(
size_t level)
763 return (64 >> level) + 1;
766 static INLINE
size_t progressive_rfx_get_band_h_count(
size_t level)
769 return (64 >> 1) - 1;
771 return (64 + (1 << (level - 1))) >> level;
774 static INLINE
void progressive_rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer,
775 INT16* WINPR_RESTRICT temp,
size_t level)
777 size_t nDstStepX = 0;
778 size_t nDstStepY = 0;
779 const INT16* WINPR_RESTRICT HL = NULL;
780 const INT16* WINPR_RESTRICT LH = NULL;
781 const INT16* WINPR_RESTRICT HH = NULL;
782 INT16* WINPR_RESTRICT LL = NULL;
783 INT16* WINPR_RESTRICT L = NULL;
784 INT16* WINPR_RESTRICT H = NULL;
785 INT16* WINPR_RESTRICT LLx = NULL;
787 const size_t nBandL = progressive_rfx_get_band_l_count(level);
788 const size_t nBandH = progressive_rfx_get_band_h_count(level);
791 HL = &buffer[offset];
792 offset += (nBandH * nBandL);
793 LH = &buffer[offset];
794 offset += (nBandL * nBandH);
795 HH = &buffer[offset];
796 offset += (nBandH * nBandH);
797 LL = &buffer[offset];
798 nDstStepX = (nBandL + nBandH);
799 nDstStepY = (nBandL + nBandH);
802 offset += (nBandL * nDstStepX);
807 progressive_rfx_idwt_x(LL, nBandL, HL, nBandH, L, nDstStepX, nBandL, nBandH, nBandL);
810 progressive_rfx_idwt_x(LH, nBandL, HH, nBandH, H, nDstStepX, nBandL, nBandH, nBandH);
813 progressive_rfx_idwt_y(L, nDstStepX, H, nDstStepX, LLx, nDstStepY, nBandL, nBandH,
817 void rfx_dwt_2d_extrapolate_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT temp)
819 WINPR_ASSERT(buffer);
821 progressive_rfx_dwt_2d_decode_block(&buffer[3807], temp, 3);
822 progressive_rfx_dwt_2d_decode_block(&buffer[3007], temp, 2);
823 progressive_rfx_dwt_2d_decode_block(&buffer[0], temp, 1);
826 static INLINE
int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
827 INT16* WINPR_RESTRICT buffer,
828 INT16* WINPR_RESTRICT current, BOOL coeffDiff,
829 BOOL extrapolate, BOOL reverse)
833 if (!progressive || !buffer || !current)
836 const size_t belements = 4096;
837 const size_t bsize = belements *
sizeof(INT16);
839 memcpy(buffer, current, bsize);
841 memcpy(current, buffer, bsize);
845 INT16* temp = (INT16*)BufferPool_Take(progressive->bufferPool, -1);
852 progressive->rfx_context->dwt_2d_decode(buffer, temp);
856 WINPR_ASSERT(progressive->rfx_context->dwt_2d_extrapolate_decode);
857 progressive->rfx_context->dwt_2d_extrapolate_decode(buffer, temp);
859 BufferPool_Return(progressive->bufferPool, temp);
863 static INLINE
void progressive_rfx_decode_block(
const primitives_t* prims,
864 INT16* WINPR_RESTRICT buffer, UINT32 length,
873 static INLINE
int progressive_rfx_decode_component(
874 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
876 UINT32 length, INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
877 INT16* WINPR_RESTRICT sign, BOOL coeffDiff, BOOL subbandDiff, BOOL extrapolate)
882 status = progressive->rfx_context->rlgr_decode(RLGR1, data, length, buffer, 4096);
887 CopyMemory(sign, buffer, 4096ULL * 2ULL);
890 rfx_differential_decode(buffer + 4032, 64);
891 progressive_rfx_decode_block(prims, &buffer[0], 1024, shift->HL1);
892 progressive_rfx_decode_block(prims, &buffer[1024], 1024, shift->LH1);
893 progressive_rfx_decode_block(prims, &buffer[2048], 1024, shift->HH1);
894 progressive_rfx_decode_block(prims, &buffer[3072], 256, shift->HL2);
895 progressive_rfx_decode_block(prims, &buffer[3328], 256, shift->LH2);
896 progressive_rfx_decode_block(prims, &buffer[3584], 256, shift->HH2);
897 progressive_rfx_decode_block(prims, &buffer[3840], 64, shift->HL3);
898 progressive_rfx_decode_block(prims, &buffer[3904], 64, shift->LH3);
899 progressive_rfx_decode_block(prims, &buffer[3968], 64, shift->HH3);
900 progressive_rfx_decode_block(prims, &buffer[4032], 64, shift->LL3);
904 progressive_rfx_decode_block(prims, &buffer[0], 1023, shift->HL1);
905 progressive_rfx_decode_block(prims, &buffer[1023], 1023, shift->LH1);
906 progressive_rfx_decode_block(prims, &buffer[2046], 961, shift->HH1);
907 progressive_rfx_decode_block(prims, &buffer[3007], 272, shift->HL2);
908 progressive_rfx_decode_block(prims, &buffer[3279], 272, shift->LH2);
909 progressive_rfx_decode_block(prims, &buffer[3551], 256, shift->HH2);
910 progressive_rfx_decode_block(prims, &buffer[3807], 72, shift->HL3);
911 progressive_rfx_decode_block(prims, &buffer[3879], 72, shift->LH3);
912 progressive_rfx_decode_block(prims, &buffer[3951], 64, shift->HH3);
913 rfx_differential_decode(&buffer[4015], 81);
914 progressive_rfx_decode_block(prims, &buffer[4015], 81, shift->LL3);
916 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
921 progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
923 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
929 BOOL extrapolate = 0;
930 BYTE* pBuffer = NULL;
948 diff = tile->flags & RFX_TILE_DIFFERENCE;
949 sub = context->flags & RFX_SUBBAND_DIFFING;
950 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
952 #if defined(WITH_DEBUG_CODECS)
953 WLog_Print(progressive->log, WLOG_DEBUG,
954 "ProgressiveTile%s: quantIdx Y: %" PRIu8
" Cb: %" PRIu8
" Cr: %" PRIu8
955 " xIdx: %" PRIu16
" yIdx: %" PRIu16
" flags: 0x%02" PRIX8
" quality: %" PRIu8
956 " yLen: %" PRIu16
" cbLen: %" PRIu16
" crLen: %" PRIu16
" tailLen: %" PRIu16
"",
957 (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ?
"First" :
"Simple",
958 tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx,
959 tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen);
962 if (tile->quantIdxY >= region->numQuant)
964 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
968 quantY = &(region->quantVals[tile->quantIdxY]);
970 if (tile->quantIdxCb >= region->numQuant)
972 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
977 quantCb = &(region->quantVals[tile->quantIdxCb]);
979 if (tile->quantIdxCr >= region->numQuant)
981 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
986 quantCr = &(region->quantVals[tile->quantIdxCr]);
988 if (tile->quality == 0xFF)
990 quantProgVal = &(progressive->quantProgValFull);
994 if (tile->quality >= region->numProgQuant)
996 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
997 region->numProgQuant);
1001 quantProgVal = &(region->quantProgVals[tile->quality]);
1004 quantProgY = &(quantProgVal->yQuantValues);
1005 quantProgCb = &(quantProgVal->cbQuantValues);
1006 quantProgCr = &(quantProgVal->crQuantValues);
1008 tile->yQuant = *quantY;
1009 tile->cbQuant = *quantCb;
1010 tile->crQuant = *quantCr;
1011 tile->yProgQuant = *quantProgY;
1012 tile->cbProgQuant = *quantProgCb;
1013 tile->crProgQuant = *quantProgCr;
1015 progressive_rfx_quant_add(quantY, quantProgY, &(tile->yBitPos));
1016 progressive_rfx_quant_add(quantCb, quantProgCb, &(tile->cbBitPos));
1017 progressive_rfx_quant_add(quantCr, quantProgCr, &(tile->crBitPos));
1018 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1019 progressive_rfx_quant_lsub(&shiftY, 1);
1020 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1021 progressive_rfx_quant_lsub(&shiftCb, 1);
1022 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1023 progressive_rfx_quant_lsub(&shiftCr, 1);
1025 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
1026 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
1027 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
1029 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
1030 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
1031 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
1033 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1034 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
1035 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
1036 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
1038 rc = progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0],
1039 pCurrent[0], pSign[0], diff, sub, extrapolate);
1042 rc = progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen,
1043 pSrcDst[1], pCurrent[1], pSign[1], diff, sub,
1047 rc = progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen,
1048 pSrcDst[2], pCurrent[2], pSign[2], diff, sub,
1053 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1054 rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride, progressive->format,
1057 BufferPool_Return(progressive->bufferPool, pBuffer);
1061 static INLINE INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1064 WINPR_ASSERT(state);
1075 const UINT32 k = state->kp / 8;
1080 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1081 BitStream_Shift(bs, 1);
1086 state->nz = (1 << k);
1103 bs->mask = ((1 << k) - 1);
1104 state->nz = ((bs->accumulator >> (32u - k)) & bs->mask);
1105 BitStream_Shift(bs, k);
1119 const UINT32 sign = (bs->accumulator & 0x80000000) ? 1 : 0;
1120 BitStream_Shift(bs, 1);
1128 return sign ? -1 : 1;
1131 const UINT32 max = (1 << numBits) - 1;
1135 const UINT32 bit = (bs->accumulator & 0x80000000) ? 1 : 0;
1136 BitStream_Shift(bs, 1);
1144 if (mag > INT16_MAX)
1146 return (INT16)(sign ? -1 * (int)mag : (INT16)mag);
1150 progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state)
1161 pad = (raw->position % 8) ? (8 - (raw->position % 8)) : 0;
1164 BitStream_Shift(raw, pad);
1166 pad = (srl->position % 8) ? (8 - (srl->position % 8)) : 0;
1169 BitStream_Shift(srl, pad);
1171 if (BitStream_GetRemainingLength(srl) == 8)
1172 BitStream_Shift(srl, 8);
1177 static INLINE
int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* WINPR_RESTRICT state,
1178 INT16* WINPR_RESTRICT buffer,
1179 INT16* WINPR_RESTRICT sign, UINT32 length,
1180 UINT32 shift, UINT32 bitPos, UINT32 numBits)
1192 for (UINT32 index = 0; index < length; index++)
1194 raw->mask = ((1 << numBits) - 1);
1195 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1196 BitStream_Shift(raw, numBits);
1197 buffer[index] += (input << shift);
1203 for (UINT32 index = 0; index < length; index++)
1205 if (sign[index] > 0)
1208 raw->mask = ((1 << numBits) - 1);
1209 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1210 BitStream_Shift(raw, numBits);
1212 else if (sign[index] < 0)
1215 raw->mask = ((1 << numBits) - 1);
1216 input = (INT16)((raw->accumulator >> (32 - numBits)) & raw->mask);
1217 BitStream_Shift(raw, numBits);
1223 input = progressive_rfx_srl_read(state, numBits);
1224 sign[index] = input;
1227 buffer[index] += (INT16)((UINT32)input << shift);
1234 progressive_rfx_upgrade_component(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1238 INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT current,
1239 INT16* WINPR_RESTRICT sign,
const BYTE* WINPR_RESTRICT srlData,
1240 UINT32 srlLen,
const BYTE* WINPR_RESTRICT rawData, UINT32 rawLen,
1241 BOOL coeffDiff, BOOL subbandDiff, BOOL extrapolate)
1248 RFX_PROGRESSIVE_UPGRADE_STATE state = { 0 };
1254 BitStream_Attach(state.srl, srlData, srlLen);
1255 BitStream_Fetch(state.srl);
1256 BitStream_Attach(state.raw, rawData, rawLen);
1257 BitStream_Fetch(state.raw);
1260 rc = progressive_rfx_upgrade_block(&state, ¤t[0], &sign[0], 1023, shift->HL1, bitPos->HL1,
1264 rc = progressive_rfx_upgrade_block(&state, ¤t[1023], &sign[1023], 1023, shift->LH1,
1265 bitPos->LH1, numBits->LH1);
1268 rc = progressive_rfx_upgrade_block(&state, ¤t[2046], &sign[2046], 961, shift->HH1,
1269 bitPos->HH1, numBits->HH1);
1272 rc = progressive_rfx_upgrade_block(&state, ¤t[3007], &sign[3007], 272, shift->HL2,
1273 bitPos->HL2, numBits->HL2);
1276 rc = progressive_rfx_upgrade_block(&state, ¤t[3279], &sign[3279], 272, shift->LH2,
1277 bitPos->LH2, numBits->LH2);
1280 rc = progressive_rfx_upgrade_block(&state, ¤t[3551], &sign[3551], 256, shift->HH2,
1281 bitPos->HH2, numBits->HH2);
1284 rc = progressive_rfx_upgrade_block(&state, ¤t[3807], &sign[3807], 72, shift->HL3,
1285 bitPos->HL3, numBits->HL3);
1288 rc = progressive_rfx_upgrade_block(&state, ¤t[3879], &sign[3879], 72, shift->LH3,
1289 bitPos->LH3, numBits->LH3);
1292 rc = progressive_rfx_upgrade_block(&state, ¤t[3951], &sign[3951], 64, shift->HH3,
1293 bitPos->HH3, numBits->HH3);
1297 state.nonLL = FALSE;
1298 rc = progressive_rfx_upgrade_block(&state, ¤t[4015], &sign[4015], 81, shift->LL3,
1299 bitPos->LL3, numBits->LL3);
1302 rc = progressive_rfx_upgrade_state_finish(&state);
1305 aRawLen = (state.raw->position + 7) / 8;
1306 aSrlLen = (state.srl->position + 7) / 8;
1308 if ((aRawLen != rawLen) || (aSrlLen != srlLen))
1314 pRawLen = (int)((((
float)aRawLen) / ((
float)rawLen)) * 100.0f);
1317 pSrlLen = (int)((((
float)aSrlLen) / ((
float)srlLen)) * 100.0f);
1319 WLog_Print(progressive->log, WLOG_WARN,
1320 "RAW: %" PRIu32
"/%" PRIu32
" %d%% (%" PRIu32
"/%" PRIu32
":%" PRIu32
1321 ")\tSRL: %" PRIu32
"/%" PRIu32
" %d%% (%" PRIu32
"/%" PRIu32
":%" PRIu32
")",
1322 aRawLen, rawLen, pRawLen, state.raw->position, rawLen * 8,
1323 (rawLen * 8) - state.raw->position, aSrlLen, srlLen, pSrlLen,
1324 state.srl->position, srlLen * 8, (srlLen * 8) - state.srl->position);
1328 return progressive_rfx_dwt_2d_decode(progressive, buffer, current, coeffDiff, extrapolate,
1333 progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1335 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1341 BOOL extrapolate = 0;
1342 BYTE* pBuffer = NULL;
1343 INT16* pSign[3] = { 0 };
1344 INT16* pSrcDst[3] = { 0 };
1345 INT16* pCurrent[3] = { 0 };
1365 coeffDiff = tile->flags & RFX_TILE_DIFFERENCE;
1366 sub = context->flags & RFX_SUBBAND_DIFFING;
1367 extrapolate = region->flags & RFX_DWT_REDUCE_EXTRAPOLATE;
1371 #if defined(WITH_DEBUG_CODECS)
1372 WLog_Print(progressive->log, WLOG_DEBUG,
1373 "ProgressiveTileUpgrade: pass: %" PRIu16
" quantIdx Y: %" PRIu8
" Cb: %" PRIu8
1374 " Cr: %" PRIu8
" xIdx: %" PRIu16
" yIdx: %" PRIu16
" quality: %" PRIu8
1375 " ySrlLen: %" PRIu16
" yRawLen: %" PRIu16
" cbSrlLen: %" PRIu16
" cbRawLen: %" PRIu16
1376 " crSrlLen: %" PRIu16
" crRawLen: %" PRIu16
"",
1377 tile->pass, tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx,
1378 tile->yIdx, tile->quality, tile->ySrlLen, tile->yRawLen, tile->cbSrlLen,
1379 tile->cbRawLen, tile->crSrlLen, tile->crRawLen);
1382 if (tile->quantIdxY >= region->numQuant)
1384 WLog_ERR(TAG,
"quantIdxY %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxY, region->numQuant);
1388 quantY = &(region->quantVals[tile->quantIdxY]);
1390 if (tile->quantIdxCb >= region->numQuant)
1392 WLog_ERR(TAG,
"quantIdxCb %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCb,
1397 quantCb = &(region->quantVals[tile->quantIdxCb]);
1399 if (tile->quantIdxCr >= region->numQuant)
1401 WLog_ERR(TAG,
"quantIdxCr %" PRIu8
" > numQuant %" PRIu8, tile->quantIdxCr,
1406 quantCr = &(region->quantVals[tile->quantIdxCr]);
1408 if (tile->quality == 0xFF)
1410 quantProg = &(progressive->quantProgValFull);
1414 if (tile->quality >= region->numProgQuant)
1416 WLog_ERR(TAG,
"quality %" PRIu8
" > numProgQuant %" PRIu8, tile->quality,
1417 region->numProgQuant);
1421 quantProg = &(region->quantProgVals[tile->quality]);
1424 quantProgY = &(quantProg->yQuantValues);
1425 quantProgCb = &(quantProg->cbQuantValues);
1426 quantProgCr = &(quantProg->crQuantValues);
1428 if (!progressive_rfx_quant_cmp_equal(quantY, &(tile->yQuant)))
1429 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantY has changed!");
1431 if (!progressive_rfx_quant_cmp_equal(quantCb, &(tile->cbQuant)))
1432 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCb has changed!");
1434 if (!progressive_rfx_quant_cmp_equal(quantCr, &(tile->crQuant)))
1435 WLog_Print(progressive->log, WLOG_WARN,
"non-progressive quantCr has changed!");
1437 if (!(context->flags & RFX_SUBBAND_DIFFING))
1438 WLog_WARN(TAG,
"PROGRESSIVE_BLOCK_CONTEXT::flags & RFX_SUBBAND_DIFFING not set");
1440 progressive_rfx_quant_add(quantY, quantProgY, &yBitPos);
1441 progressive_rfx_quant_add(quantCb, quantProgCb, &cbBitPos);
1442 progressive_rfx_quant_add(quantCr, quantProgCr, &crBitPos);
1443 progressive_rfx_quant_sub(&(tile->yBitPos), &yBitPos, &yNumBits);
1444 progressive_rfx_quant_sub(&(tile->cbBitPos), &cbBitPos, &cbNumBits);
1445 progressive_rfx_quant_sub(&(tile->crBitPos), &crBitPos, &crNumBits);
1446 progressive_rfx_quant_add(quantY, quantProgY, &shiftY);
1447 progressive_rfx_quant_lsub(&shiftY, 1);
1448 progressive_rfx_quant_add(quantCb, quantProgCb, &shiftCb);
1449 progressive_rfx_quant_lsub(&shiftCb, 1);
1450 progressive_rfx_quant_add(quantCr, quantProgCr, &shiftCr);
1451 progressive_rfx_quant_lsub(&shiftCr, 1);
1453 tile->yBitPos = yBitPos;
1454 tile->cbBitPos = cbBitPos;
1455 tile->crBitPos = crBitPos;
1456 tile->yQuant = *quantY;
1457 tile->cbQuant = *quantCb;
1458 tile->crQuant = *quantCr;
1459 tile->yProgQuant = *quantProgY;
1460 tile->cbProgQuant = *quantProgCb;
1461 tile->crProgQuant = *quantProgCr;
1463 pSign[0] = (INT16*)((&tile->sign[((8192 + 32) * 0) + 16]));
1464 pSign[1] = (INT16*)((&tile->sign[((8192 + 32) * 1) + 16]));
1465 pSign[2] = (INT16*)((&tile->sign[((8192 + 32) * 2) + 16]));
1467 pCurrent[0] = (INT16*)((&tile->current[((8192 + 32) * 0) + 16]));
1468 pCurrent[1] = (INT16*)((&tile->current[((8192 + 32) * 1) + 16]));
1469 pCurrent[2] = (INT16*)((&tile->current[((8192 + 32) * 2) + 16]));
1471 pBuffer = (BYTE*)BufferPool_Take(progressive->bufferPool, -1);
1472 pSrcDst[0] = (INT16*)((&pBuffer[((8192 + 32) * 0) + 16]));
1473 pSrcDst[1] = (INT16*)((&pBuffer[((8192 + 32) * 1) + 16]));
1474 pSrcDst[2] = (INT16*)((&pBuffer[((8192 + 32) * 2) + 16]));
1476 status = progressive_rfx_upgrade_component(progressive, &shiftY, quantProgY, &yNumBits,
1477 pSrcDst[0], pCurrent[0], pSign[0], tile->ySrlData,
1478 tile->ySrlLen, tile->yRawData, tile->yRawLen,
1479 coeffDiff, sub, extrapolate);
1484 status = progressive_rfx_upgrade_component(progressive, &shiftCb, quantProgCb, &cbNumBits,
1485 pSrcDst[1], pCurrent[1], pSign[1], tile->cbSrlData,
1486 tile->cbSrlLen, tile->cbRawData, tile->cbRawLen,
1487 coeffDiff, sub, extrapolate);
1492 status = progressive_rfx_upgrade_component(progressive, &shiftCr, quantProgCr, &crNumBits,
1493 pSrcDst[2], pCurrent[2], pSign[2], tile->crSrlData,
1494 tile->crSrlLen, tile->crRawData, tile->crRawLen,
1495 coeffDiff, sub, extrapolate);
1500 const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**,
const INT16**);
1501 status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
1502 progressive->format, &roi_64x64);
1504 BufferPool_Return(progressive->bufferPool, pBuffer);
1508 static INLINE BOOL progressive_tile_read_upgrade(
1509 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1511 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1515 const size_t expect = 20;
1517 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1520 tile.blockType = blockType;
1521 tile.blockLen = blockLen;
1524 Stream_Read_UINT8(s, tile.quantIdxY);
1525 Stream_Read_UINT8(s, tile.quantIdxCb);
1526 Stream_Read_UINT8(s, tile.quantIdxCr);
1527 Stream_Read_UINT16(s, tile.xIdx);
1528 Stream_Read_UINT16(s, tile.yIdx);
1529 Stream_Read_UINT8(s, tile.quality);
1530 Stream_Read_UINT16(s, tile.ySrlLen);
1531 Stream_Read_UINT16(s, tile.yRawLen);
1532 Stream_Read_UINT16(s, tile.cbSrlLen);
1533 Stream_Read_UINT16(s, tile.cbRawLen);
1534 Stream_Read_UINT16(s, tile.crSrlLen);
1535 Stream_Read_UINT16(s, tile.crRawLen);
1537 tile.ySrlData = Stream_Pointer(s);
1538 if (!Stream_SafeSeek(s, tile.ySrlLen))
1540 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.ySrlLen);
1544 tile.yRawData = Stream_Pointer(s);
1545 if (!Stream_SafeSeek(s, tile.yRawLen))
1547 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yRawLen);
1551 tile.cbSrlData = Stream_Pointer(s);
1552 if (!Stream_SafeSeek(s, tile.cbSrlLen))
1554 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1559 tile.cbRawData = Stream_Pointer(s);
1560 if (!Stream_SafeSeek(s, tile.cbRawLen))
1562 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1567 tile.crSrlData = Stream_Pointer(s);
1568 if (!Stream_SafeSeek(s, tile.crSrlLen))
1570 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1575 tile.crRawData = Stream_Pointer(s);
1576 if (!Stream_SafeSeek(s, tile.crRawLen))
1578 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes",
1583 return progressive_surface_tile_replace(surface, region, &tile, TRUE);
1586 static INLINE BOOL progressive_tile_read(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1587 BOOL simple,
wStream* WINPR_RESTRICT s, UINT16 blockType,
1590 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1594 size_t expect = simple ? 16 : 17;
1596 if (!Stream_CheckAndLogRequiredLength(TAG, s, expect))
1599 tile.blockType = blockType;
1600 tile.blockLen = blockLen;
1602 Stream_Read_UINT8(s, tile.quantIdxY);
1603 Stream_Read_UINT8(s, tile.quantIdxCb);
1604 Stream_Read_UINT8(s, tile.quantIdxCr);
1605 Stream_Read_UINT16(s, tile.xIdx);
1606 Stream_Read_UINT16(s, tile.yIdx);
1607 Stream_Read_UINT8(s, tile.flags);
1610 Stream_Read_UINT8(s, tile.quality);
1612 tile.quality = 0xFF;
1613 Stream_Read_UINT16(s, tile.yLen);
1614 Stream_Read_UINT16(s, tile.cbLen);
1615 Stream_Read_UINT16(s, tile.crLen);
1616 Stream_Read_UINT16(s, tile.tailLen);
1618 tile.yData = Stream_Pointer(s);
1619 if (!Stream_SafeSeek(s, tile.yLen))
1621 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.yLen);
1625 tile.cbData = Stream_Pointer(s);
1626 if (!Stream_SafeSeek(s, tile.cbLen))
1628 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.cbLen);
1632 tile.crData = Stream_Pointer(s);
1633 if (!Stream_SafeSeek(s, tile.crLen))
1635 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.crLen);
1639 tile.tailData = Stream_Pointer(s);
1640 if (!Stream_SafeSeek(s, tile.tailLen))
1642 WLog_Print(progressive->log, WLOG_ERROR,
" Failed to seek %" PRIu32
" bytes", tile.tailLen);
1646 return progressive_surface_tile_replace(surface, region, &tile, FALSE);
1649 static void CALLBACK progressive_process_tiles_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1650 void* context, PTP_WORK work)
1654 WINPR_UNUSED(instance);
1657 switch (param->tile->blockType)
1659 case PROGRESSIVE_WBT_TILE_SIMPLE:
1660 case PROGRESSIVE_WBT_TILE_FIRST:
1661 progressive_decompress_tile_first(param->progressive, param->tile, param->region,
1665 case PROGRESSIVE_WBT_TILE_UPGRADE:
1666 progressive_decompress_tile_upgrade(param->progressive, param->tile, param->region,
1670 WLog_Print(param->progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16
" (%s)",
1671 param->tile->blockType,
1672 rfx_get_progressive_block_type_string(param->tile->blockType));
1677 static INLINE SSIZE_T progressive_process_tiles(
1678 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s,
1679 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
1685 const size_t start = Stream_GetPosition(s);
1686 UINT16 blockType = 0;
1687 UINT32 blockLen = 0;
1689 UINT16 close_cnt = 0;
1691 WINPR_ASSERT(progressive);
1692 WINPR_ASSERT(region);
1694 if (!Stream_CheckAndLogRequiredLength(TAG, s, region->tileDataSize))
1697 while ((Stream_GetRemainingLength(s) >= 6) &&
1698 (region->tileDataSize > (Stream_GetPosition(s) - start)))
1700 const size_t pos = Stream_GetPosition(s);
1702 Stream_Read_UINT16(s, blockType);
1703 Stream_Read_UINT32(s, blockLen);
1705 #if defined(WITH_DEBUG_CODECS)
1706 WLog_Print(progressive->log, WLOG_DEBUG,
"%s",
1707 rfx_get_progressive_block_type_string(blockType));
1712 WLog_Print(progressive->log, WLOG_ERROR,
"Expected >= %" PRIu32
" remaining %" PRIuz, 6,
1716 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
1721 case PROGRESSIVE_WBT_TILE_SIMPLE:
1722 if (!progressive_tile_read(progressive, TRUE, s, blockType, blockLen, surface,
1727 case PROGRESSIVE_WBT_TILE_FIRST:
1728 if (!progressive_tile_read(progressive, FALSE, s, blockType, blockLen, surface,
1733 case PROGRESSIVE_WBT_TILE_UPGRADE:
1734 if (!progressive_tile_read_upgrade(progressive, s, blockType, blockLen, surface,
1739 WLog_ERR(TAG,
"Invalid block type %04" PRIx16
" (%s)", blockType,
1740 rfx_get_progressive_block_type_string(blockType));
1744 size_t rem = Stream_GetPosition(s);
1745 if ((rem - pos) != blockLen)
1747 WLog_Print(progressive->log, WLOG_ERROR,
1748 "Actual block read %" PRIuz
" but expected %" PRIu32, rem - pos, blockLen);
1754 end = Stream_GetPosition(s);
1755 if ((end - start) != region->tileDataSize)
1757 WLog_Print(progressive->log, WLOG_ERROR,
1758 "Actual total blocks read %" PRIuz
" but expected %" PRIu32, end - start,
1759 region->tileDataSize);
1763 if (count != region->numTiles)
1765 WLog_Print(progressive->log, WLOG_WARN,
1766 "numTiles inconsistency: actual: %" PRIu32
", expected: %" PRIu16
"\n", count,
1771 for (UINT32 idx = 0; idx < region->numTiles; idx++)
1775 param->progressive = progressive;
1776 param->region = region;
1777 param->context = context;
1780 if (progressive->rfx_context->priv->UseThreads)
1782 progressive->work_objects[idx] =
1783 CreateThreadpoolWork(progressive_process_tiles_tile_work_callback, (
void*)param,
1784 &progressive->rfx_context->priv->ThreadPoolEnv);
1785 if (!progressive->work_objects[idx])
1787 WLog_Print(progressive->log, WLOG_ERROR,
1788 "Failed to create ThreadpoolWork for tile %" PRIu32, idx);
1793 SubmitThreadpoolWork(progressive->work_objects[idx]);
1794 close_cnt = idx + 1;
1798 progressive_process_tiles_tile_work_callback(0, param, 0);
1803 WLog_Print(progressive->log, WLOG_ERROR,
"Failed to decompress %s at %" PRIu16,
1804 rfx_get_progressive_block_type_string(tile->blockType), idx);
1809 if (progressive->rfx_context->priv->UseThreads)
1811 for (UINT32 idx = 0; idx < close_cnt; idx++)
1813 WaitForThreadpoolWorkCallbacks(progressive->work_objects[idx], FALSE);
1814 CloseThreadpoolWork(progressive->work_objects[idx]);
1823 return (SSIZE_T)(end - start);
1826 static INLINE SSIZE_T progressive_wb_sync(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1827 wStream* WINPR_RESTRICT s, UINT16 blockType,
1830 const UINT32 magic = 0xCACCACCA;
1831 const UINT16 version = 0x0100;
1834 sync.blockType = blockType;
1835 sync.blockLen = blockLen;
1837 if (sync.blockLen != 12)
1839 WLog_Print(progressive->log, WLOG_ERROR,
1840 "PROGRESSIVE_BLOCK_SYNC::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1845 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1848 #if defined(WITH_DEBUG_CODECS)
1849 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveSync");
1852 Stream_Read_UINT32(s, sync.magic);
1853 Stream_Read_UINT16(s, sync.version);
1855 if (sync.magic != magic)
1857 WLog_Print(progressive->log, WLOG_ERROR,
1858 "PROGRESSIVE_BLOCK_SYNC::magic = 0x%08" PRIx32
" != 0x%08" PRIx32, sync.magic,
1863 if (sync.version != 0x0100)
1865 WLog_Print(progressive->log, WLOG_ERROR,
1866 "PROGRESSIVE_BLOCK_SYNC::version = 0x%04" PRIx16
" != 0x%04" PRIu16,
1867 sync.version, version);
1871 if ((progressive->state & FLAG_WBT_SYNC) != 0)
1872 WLog_WARN(TAG,
"Duplicate PROGRESSIVE_BLOCK_SYNC, ignoring");
1874 progressive->state |= FLAG_WBT_SYNC;
1878 static INLINE SSIZE_T progressive_wb_frame_begin(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1879 wStream* WINPR_RESTRICT s, UINT16 blockType,
1884 frameBegin.blockType = blockType;
1885 frameBegin.blockLen = blockLen;
1887 if (frameBegin.blockLen != 12)
1889 WLog_Print(progressive->log, WLOG_ERROR,
1890 " RFX_PROGRESSIVE_FRAME_BEGIN::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1891 frameBegin.blockLen, 12);
1895 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1898 Stream_Read_UINT32(s, frameBegin.frameIndex);
1899 Stream_Read_UINT16(s, frameBegin.regionCount);
1901 #if defined(WITH_DEBUG_CODECS)
1902 WLog_Print(progressive->log, WLOG_DEBUG,
1903 "ProgressiveFrameBegin: frameIndex: %" PRIu32
" regionCount: %" PRIu16
"",
1904 frameBegin.frameIndex, frameBegin.regionCount);
1913 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
1915 WLog_ERR(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_BEGIN in stream, this is not allowed!");
1919 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1921 WLog_ERR(TAG,
"RFX_PROGRESSIVE_FRAME_BEGIN after RFX_PROGRESSIVE_FRAME_END in stream, this "
1926 progressive->state |= FLAG_WBT_FRAME_BEGIN;
1930 static INLINE SSIZE_T progressive_wb_frame_end(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1931 wStream* WINPR_RESTRICT s, UINT16 blockType,
1936 frameEnd.blockType = blockType;
1937 frameEnd.blockLen = blockLen;
1939 if (frameEnd.blockLen != 6)
1941 WLog_Print(progressive->log, WLOG_ERROR,
1942 " RFX_PROGRESSIVE_FRAME_END::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1943 frameEnd.blockLen, 6);
1947 if (Stream_GetRemainingLength(s) != 0)
1949 WLog_Print(progressive->log, WLOG_ERROR,
1950 "ProgressiveFrameEnd short %" PRIuz
", expected %" PRIuz,
1951 Stream_GetRemainingLength(s), 0);
1955 #if defined(WITH_DEBUG_CODECS)
1956 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveFrameEnd");
1959 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
1960 WLog_WARN(TAG,
"RFX_PROGRESSIVE_FRAME_END before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
1961 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
1962 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_FRAME_END, ignoring");
1964 progressive->state |= FLAG_WBT_FRAME_END;
1968 static INLINE SSIZE_T progressive_wb_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
1969 wStream* WINPR_RESTRICT s, UINT16 blockType,
1973 context->blockType = blockType;
1974 context->blockLen = blockLen;
1976 if (context->blockLen != 10)
1978 WLog_Print(progressive->log, WLOG_ERROR,
1979 "RFX_PROGRESSIVE_CONTEXT::blockLen = 0x%08" PRIx32
" != 0x%08" PRIx32,
1980 context->blockLen, 10);
1984 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1987 Stream_Read_UINT8(s, context->ctxId);
1988 Stream_Read_UINT16(s, context->tileSize);
1989 Stream_Read_UINT8(s, context->flags);
1991 if (context->ctxId != 0x00)
1992 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT::ctxId != 0x00: %" PRIu8, context->ctxId);
1994 if (context->tileSize != 64)
1996 WLog_ERR(TAG,
"RFX_PROGRESSIVE_CONTEXT::tileSize != 0x40: %" PRIu16, context->tileSize);
2000 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) != 0)
2001 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_BEGIN");
2002 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2003 WLog_WARN(TAG,
"RFX_PROGRESSIVE_CONTEXT received after RFX_PROGRESSIVE_FRAME_END");
2004 if ((progressive->state & FLAG_WBT_CONTEXT) != 0)
2005 WLog_WARN(TAG,
"Duplicate RFX_PROGRESSIVE_CONTEXT received, ignoring.");
2007 #if defined(WITH_DEBUG_CODECS)
2008 WLog_Print(progressive->log, WLOG_DEBUG,
"ProgressiveContext: flags: 0x%02" PRIX8
"",
2012 progressive->state |= FLAG_WBT_CONTEXT;
2016 static INLINE SSIZE_T progressive_wb_read_region_header(
2017 PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
wStream* WINPR_RESTRICT s, UINT16 blockType,
2018 UINT32 blockLen, PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2020 region->usedTiles = 0;
2022 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2025 region->blockType = blockType;
2026 region->blockLen = blockLen;
2027 Stream_Read_UINT8(s, region->tileSize);
2028 Stream_Read_UINT16(s, region->numRects);
2029 Stream_Read_UINT8(s, region->numQuant);
2030 Stream_Read_UINT8(s, region->numProgQuant);
2031 Stream_Read_UINT8(s, region->flags);
2032 Stream_Read_UINT16(s, region->numTiles);
2033 Stream_Read_UINT32(s, region->tileDataSize);
2035 if (region->tileSize != 64)
2037 WLog_Print(progressive->log, WLOG_ERROR,
2038 "ProgressiveRegion tile size %" PRIu8
", expected %" PRIuz, region->tileSize,
2043 if (region->numRects < 1)
2045 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion missing rect count %" PRIu16,
2050 if (region->numQuant > 7)
2052 WLog_Print(progressive->log, WLOG_ERROR,
2053 "ProgressiveRegion quant count too high %" PRIu8
", expected < %" PRIuz,
2054 region->numQuant, 7);
2058 const SSIZE_T rc = Stream_GetRemainingLength(s);
2059 const SSIZE_T expect = region->numRects * 8ll + region->numQuant * 5ll +
2060 region->numProgQuant * 16ll + region->tileDataSize;
2064 if (len / 8LL < region->numRects)
2066 WLog_Print(progressive->log, WLOG_ERROR,
2067 "ProgressiveRegion data short for region->rects");
2070 len -= region->numRects * 8LL;
2072 if (len / 5LL < region->numQuant)
2074 WLog_Print(progressive->log, WLOG_ERROR,
2075 "ProgressiveRegion data short for region->cQuant");
2078 len -= region->numQuant * 5LL;
2080 if (len / 16LL < region->numProgQuant)
2082 WLog_Print(progressive->log, WLOG_ERROR,
2083 "ProgressiveRegion data short for region->cProgQuant");
2086 len -= region->numProgQuant * 16LL;
2088 if (len < region->tileDataSize * 1ll)
2090 WLog_Print(progressive->log, WLOG_ERROR,
2091 "ProgressiveRegion data short for region->tiles");
2094 len -= region->tileDataSize;
2097 WLog_Print(progressive->log, WLOG_WARN,
2098 "Unused bytes detected, %" PRIdz
" bytes not processed", len);
2104 static INLINE SSIZE_T progressive_wb_skip_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2105 wStream* WINPR_RESTRICT s, UINT16 blockType,
2108 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2111 progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2115 if (!Stream_SafeSeek(s, rc))
2121 static INLINE SSIZE_T progressive_wb_region(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2122 wStream* WINPR_RESTRICT s, UINT16 blockType,
2125 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2130 UINT16 boxRight = 0;
2131 UINT16 boxBottom = 0;
2134 UINT16 idxRight = 0;
2135 UINT16 idxBottom = 0;
2138 if ((progressive->state & FLAG_WBT_FRAME_BEGIN) == 0)
2140 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION before RFX_PROGRESSIVE_FRAME_BEGIN, ignoring");
2141 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2143 if ((progressive->state & FLAG_WBT_FRAME_END) != 0)
2145 WLog_WARN(TAG,
"RFX_PROGRESSIVE_REGION after RFX_PROGRESSIVE_FRAME_END, ignoring");
2146 return progressive_wb_skip_region(progressive, s, blockType, blockLen);
2149 progressive->state |= FLAG_WBT_REGION;
2151 rc = progressive_wb_read_region_header(progressive, s, blockType, blockLen, region);
2155 for (UINT16 index = 0; index < region->numRects; index++)
2157 RFX_RECT* rect = &(region->rects[index]);
2158 Stream_Read_UINT16(s, rect->x);
2159 Stream_Read_UINT16(s, rect->y);
2160 Stream_Read_UINT16(s, rect->width);
2161 Stream_Read_UINT16(s, rect->height);
2164 for (BYTE index = 0; index < region->numQuant; index++)
2167 progressive_component_codec_quant_read(s, quantVal);
2169 if (!progressive_rfx_quant_lcmp_greater_equal(quantVal, 6))
2171 WLog_Print(progressive->log, WLOG_ERROR,
2172 "ProgressiveRegion region->cQuant[%" PRIu32
"] < 6", index);
2176 if (!progressive_rfx_quant_lcmp_less_equal(quantVal, 15))
2178 WLog_Print(progressive->log, WLOG_ERROR,
2179 "ProgressiveRegion region->cQuant[%" PRIu32
"] > 15", index);
2184 for (BYTE index = 0; index < region->numProgQuant; index++)
2188 Stream_Read_UINT8(s, quantProgVal->quality);
2190 progressive_component_codec_quant_read(s, &(quantProgVal->yQuantValues));
2191 progressive_component_codec_quant_read(s, &(quantProgVal->cbQuantValues));
2192 progressive_component_codec_quant_read(s, &(quantProgVal->crQuantValues));
2195 #if defined(WITH_DEBUG_CODECS)
2196 WLog_Print(progressive->log, WLOG_DEBUG,
2197 "ProgressiveRegion: numRects: %" PRIu16
" numTiles: %" PRIu16
2198 " tileDataSize: %" PRIu32
" flags: 0x%02" PRIX8
" numQuant: %" PRIu8
2199 " numProgQuant: %" PRIu8
"",
2200 region->numRects, region->numTiles, region->tileDataSize, region->flags,
2201 region->numQuant, region->numProgQuant);
2204 boxLeft = surface->gridWidth;
2205 boxTop = surface->gridHeight;
2209 for (UINT16 index = 0; index < region->numRects; index++)
2211 RFX_RECT* rect = &(region->rects[index]);
2212 idxLeft = rect->x / 64;
2213 idxTop = rect->y / 64;
2214 idxRight = (rect->x + rect->width + 63) / 64;
2215 idxBottom = (rect->y + rect->height + 63) / 64;
2217 if (idxLeft < boxLeft)
2220 if (idxTop < boxTop)
2223 if (idxRight > boxRight)
2224 boxRight = idxRight;
2226 if (idxBottom > boxBottom)
2227 boxBottom = idxBottom;
2229 #if defined(WITH_DEBUG_CODECS)
2230 WLog_Print(progressive->log, WLOG_DEBUG,
2231 "rect[%" PRIu16
"]: x: %" PRIu16
" y: %" PRIu16
" w: %" PRIu16
" h: %" PRIu16
"",
2232 index, rect->x, rect->y, rect->width, rect->height);
2236 const SSIZE_T res = progressive_process_tiles(progressive, s, region, surface, context);
2242 static INLINE SSIZE_T progressive_parse_block(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2245 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region)
2247 UINT16 blockType = 0;
2248 UINT32 blockLen = 0;
2252 WINPR_ASSERT(progressive);
2254 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
2257 Stream_Read_UINT16(s, blockType);
2258 Stream_Read_UINT32(s, blockLen);
2262 WLog_WARN(TAG,
"Invalid blockLen %" PRIu32
", expected >= 6", blockLen);
2265 if (!Stream_CheckAndLogRequiredLength(TAG, s, blockLen - 6))
2267 Stream_StaticConstInit(&sub, Stream_Pointer(s), blockLen - 6);
2268 Stream_Seek(s, blockLen - 6);
2272 case PROGRESSIVE_WBT_SYNC:
2273 rc = progressive_wb_sync(progressive, &sub, blockType, blockLen);
2276 case PROGRESSIVE_WBT_FRAME_BEGIN:
2277 rc = progressive_wb_frame_begin(progressive, &sub, blockType, blockLen);
2280 case PROGRESSIVE_WBT_FRAME_END:
2281 rc = progressive_wb_frame_end(progressive, &sub, blockType, blockLen);
2284 case PROGRESSIVE_WBT_CONTEXT:
2285 rc = progressive_wb_context(progressive, &sub, blockType, blockLen);
2288 case PROGRESSIVE_WBT_REGION:
2289 rc = progressive_wb_region(progressive, &sub, blockType, blockLen, surface, region);
2293 WLog_Print(progressive->log, WLOG_ERROR,
"Invalid block type %04" PRIx16, blockType);
2300 if (Stream_GetRemainingLength(&sub) > 0)
2302 WLog_Print(progressive->log, WLOG_ERROR,
2303 "block len %" PRIu32
" does not match read data %" PRIuz, blockLen,
2304 blockLen - Stream_GetRemainingLength(&sub));
2311 static INLINE BOOL update_tiles(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2313 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2314 UINT32 nXDst, UINT32 nYDst,
2315 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region,
2316 REGION16* WINPR_RESTRICT invalidRegion)
2320 region16_init(&clippingRects);
2322 for (UINT32 i = 0; i < region->numRects; i++)
2325 const RFX_RECT* rect = &(region->rects[i]);
2327 clippingRect.left = (UINT16)nXDst + rect->x;
2328 clippingRect.top = (UINT16)nYDst + rect->y;
2329 clippingRect.right = clippingRect.left + rect->width;
2330 clippingRect.bottom = clippingRect.top + rect->height;
2331 region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
2334 for (UINT32 i = 0; i < surface->numUpdatedTiles; i++)
2336 UINT32 nbUpdateRects = 0;
2340 WINPR_ASSERT(surface->updatedTileIndices);
2341 const UINT32 index = surface->updatedTileIndices[i];
2343 WINPR_ASSERT(index < surface->tilesSize);
2347 updateRect.left = nXDst + tile->x;
2348 updateRect.top = nYDst + tile->y;
2349 updateRect.right = updateRect.left + 64;
2350 updateRect.bottom = updateRect.top + 64;
2353 region16_init(&updateRegion);
2354 region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
2355 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
2357 for (UINT32 j = 0; j < nbUpdateRects; j++)
2360 if (rect->left < updateRect.left)
2362 const UINT32 nXSrc = rect->left - updateRect.left;
2363 const UINT32 nYSrc = rect->top - updateRect.top;
2364 const UINT32 width = rect->right - rect->left;
2365 const UINT32 height = rect->bottom - rect->top;
2367 if (rect->left + width > surface->width)
2369 if (rect->top + height > surface->height)
2371 rc = freerdp_image_copy_no_overlap(
2372 pDstData, DstFormat, nDstStep, rect->left, rect->top, width, height, tile->data,
2373 progressive->format, tile->stride, nXSrc, nYSrc, NULL, FREERDP_KEEP_DST_ALPHA);
2378 region16_union_rect(invalidRegion, invalidRegion, rect);
2381 region16_uninit(&updateRegion);
2382 tile->dirty = FALSE;
2386 region16_uninit(&clippingRects);
2390 INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2391 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
2392 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep,
2393 UINT32 nXDst, UINT32 nYDst,
REGION16* WINPR_RESTRICT invalidRegion,
2394 UINT16 surfaceId, UINT32 frameId)
2398 WINPR_ASSERT(progressive);
2403 WLog_Print(progressive->log, WLOG_ERROR,
"ProgressiveRegion no surface for %" PRIu16,
2408 PROGRESSIVE_BLOCK_REGION* WINPR_RESTRICT region = &progressive->region;
2409 WINPR_ASSERT(region);
2411 if (surface->frameId != frameId)
2413 surface->frameId = frameId;
2414 surface->numUpdatedTiles = 0;
2418 wStream* s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
2423 case PIXEL_FORMAT_RGBA32:
2424 case PIXEL_FORMAT_RGBX32:
2425 case PIXEL_FORMAT_BGRA32:
2426 case PIXEL_FORMAT_BGRX32:
2427 progressive->format = DstFormat;
2430 progressive->format = PIXEL_FORMAT_XRGB32;
2434 const size_t start = Stream_GetPosition(s);
2435 progressive->state = 0;
2436 while (Stream_GetRemainingLength(s) > 0)
2438 if (progressive_parse_block(progressive, s, surface, region) < 0)
2442 const size_t end = Stream_GetPosition(s);
2443 if ((end - start) != SrcSize)
2445 WLog_Print(progressive->log, WLOG_ERROR,
2446 "total block len %" PRIuz
" does not match read data %" PRIu32, end - start,
2452 if (!update_tiles(progressive, surface, pDstData, DstFormat, nDstStep, nXDst, nYDst, region,
2459 BOOL progressive_rfx_write_message_progressive_simple(PROGRESSIVE_CONTEXT* progressive,
wStream* s,
2460 const RFX_MESSAGE* msg)
2462 RFX_CONTEXT* context = NULL;
2464 WINPR_ASSERT(progressive);
2467 context = progressive->rfx_context;
2468 return rfx_write_message_progressive_simple(context, s, msg);
2471 int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive,
2472 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 SrcFormat,
2473 UINT32 Width, UINT32 Height, UINT32 ScanLine,
2474 const REGION16* WINPR_RESTRICT invalidRegion,
2475 BYTE** WINPR_RESTRICT ppDstData, UINT32* WINPR_RESTRICT pDstSize)
2480 UINT32 numRects = 0;
2484 RFX_MESSAGE* message = NULL;
2486 if (!progressive || !pSrcData || !ppDstData || !pDstSize)
2495 case PIXEL_FORMAT_ABGR32:
2496 case PIXEL_FORMAT_ARGB32:
2497 case PIXEL_FORMAT_XBGR32:
2498 case PIXEL_FORMAT_XRGB32:
2499 case PIXEL_FORMAT_BGRA32:
2500 case PIXEL_FORMAT_BGRX32:
2501 case PIXEL_FORMAT_RGBA32:
2502 case PIXEL_FORMAT_RGBX32:
2503 ScanLine = Width * 4;
2510 if (SrcSize < Height * ScanLine)
2515 numRects = (Width + 63) / 64;
2516 numRects *= (Height + 63) / 64;
2519 numRects = region16_n_rects(invalidRegion);
2524 if (!Stream_EnsureCapacity(progressive->rects, numRects *
sizeof(
RFX_RECT)))
2526 rects = Stream_BufferAs(progressive->rects,
RFX_RECT);
2529 const RECTANGLE_16* region_rects = region16_rects(invalidRegion, NULL);
2530 for (UINT32 idx = 0; idx < numRects; idx++)
2537 rect->width = r->right - r->left;
2538 rect->height = r->bottom - r->top;
2545 for (UINT32 i = 0; i < numRects; i++)
2550 r->width = MIN(64, Width - x);
2551 r->height = MIN(64, Height - y);
2553 if (x + 64 >= Width)
2561 WINPR_ASSERT(r->x % 64 == 0);
2562 WINPR_ASSERT(r->y % 64 == 0);
2563 WINPR_ASSERT(r->width <= 64);
2564 WINPR_ASSERT(r->height <= 64);
2567 s = progressive->buffer;
2568 Stream_SetPosition(s, 0);
2570 progressive->rfx_context->mode = RLGR1;
2571 progressive->rfx_context->width = Width;
2572 progressive->rfx_context->height = Height;
2573 rfx_context_set_pixel_format(progressive->rfx_context, SrcFormat);
2574 message = rfx_encode_message(progressive->rfx_context, rects, numRects, pSrcData, Width, Height,
2578 WLog_ERR(TAG,
"failed to encode rfx message");
2582 rc = progressive_rfx_write_message_progressive_simple(progressive, s, message);
2583 rfx_message_free(progressive->rfx_context, message);
2587 const size_t pos = Stream_GetPosition(s);
2588 WINPR_ASSERT(pos <= UINT32_MAX);
2589 *pDstSize = (UINT32)pos;
2590 *ppDstData = Stream_Buffer(s);
2596 BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive)
2604 PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
2606 return progressive_context_new_ex(Compressor, 0);
2609 PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, UINT32 ThreadingFlags)
2611 PROGRESSIVE_CONTEXT* progressive =
2612 (PROGRESSIVE_CONTEXT*)winpr_aligned_calloc(1,
sizeof(PROGRESSIVE_CONTEXT), 32);
2617 progressive->Compressor = Compressor;
2618 progressive->quantProgValFull.quality = 100;
2619 progressive->log = WLog_Get(TAG);
2620 if (!progressive->log)
2622 progressive->rfx_context = rfx_context_new_ex(Compressor, ThreadingFlags);
2623 if (!progressive->rfx_context)
2625 progressive->buffer = Stream_New(NULL, 1024);
2626 if (!progressive->buffer)
2628 progressive->rects = Stream_New(NULL, 1024);
2629 if (!progressive->rects)
2631 progressive->bufferPool = BufferPool_New(TRUE, (8192LL + 32LL) * 3LL, 16);
2632 if (!progressive->bufferPool)
2634 progressive->SurfaceContexts = HashTable_New(TRUE);
2635 if (!progressive->SurfaceContexts)
2639 wObject* obj = HashTable_ValueObject(progressive->SurfaceContexts);
2641 obj->fnObjectFree = progressive_surface_context_free;
2645 WINPR_PRAGMA_DIAG_PUSH
2646 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2647 progressive_context_free(progressive);
2648 WINPR_PRAGMA_DIAG_POP
2652 void progressive_context_free(PROGRESSIVE_CONTEXT* progressive)
2657 Stream_Free(progressive->buffer, TRUE);
2658 Stream_Free(progressive->rects, TRUE);
2659 rfx_context_free(progressive->rfx_context);
2661 BufferPool_Free(progressive->bufferPool);
2662 HashTable_Free(progressive->SurfaceContexts);
2664 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.