22#include <freerdp/config.h>
25#include <winpr/wtypes.h>
26#include <winpr/assert.h>
27#include <winpr/cast.h>
28#include <winpr/print.h>
30#include <freerdp/primitives.h>
31#include <freerdp/log.h>
32#include <freerdp/codec/bitmap.h>
33#include <freerdp/codec/planar.h>
35#define TAG FREERDP_TAG("codec")
37#define PLANAR_ALIGN(val, align) \
38 ((val) % (align) == 0) ? (val) : ((val) + (align) - (val) % (align))
54 RDP6_RLE_SEGMENT* segments;
70struct S_BITMAP_PLANAR_CONTEXT
77 BOOL AllowRunLengthEncoding;
78 BOOL AllowColorSubsampling;
79 BOOL AllowDynamicColorFidelity;
81 UINT32 ColorLossLevel;
87 BYTE* deltaPlanesBuffer;
90 BYTE* rlePlanesBuffer;
99static inline BYTE PLANAR_CONTROL_BYTE(UINT32 nRunLength, UINT32 cRawBytes)
101 return WINPR_ASSERTING_INT_CAST(UINT8, ((nRunLength & 0x0F) | ((cRawBytes & 0x0F) << 4)));
104static inline BYTE PLANAR_CONTROL_BYTE_RUN_LENGTH(UINT32 controlByte)
106 return (controlByte & 0x0F);
108static inline BYTE PLANAR_CONTROL_BYTE_RAW_BYTES(UINT32 controlByte)
110 return ((controlByte >> 4) & 0x0F);
113static inline UINT32 planar_invert_format(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, BOOL alpha,
116 WINPR_ASSERT(planar);
117 if (planar->bgr && alpha)
121 case PIXEL_FORMAT_ARGB32:
122 DstFormat = PIXEL_FORMAT_ABGR32;
124 case PIXEL_FORMAT_XRGB32:
125 DstFormat = PIXEL_FORMAT_XBGR32;
127 case PIXEL_FORMAT_ABGR32:
128 DstFormat = PIXEL_FORMAT_ARGB32;
130 case PIXEL_FORMAT_XBGR32:
131 DstFormat = PIXEL_FORMAT_XRGB32;
133 case PIXEL_FORMAT_BGRA32:
134 DstFormat = PIXEL_FORMAT_RGBA32;
136 case PIXEL_FORMAT_BGRX32:
137 DstFormat = PIXEL_FORMAT_RGBX32;
139 case PIXEL_FORMAT_RGBA32:
140 DstFormat = PIXEL_FORMAT_BGRA32;
142 case PIXEL_FORMAT_RGBX32:
143 DstFormat = PIXEL_FORMAT_BGRX32;
145 case PIXEL_FORMAT_RGB24:
146 DstFormat = PIXEL_FORMAT_BGR24;
148 case PIXEL_FORMAT_BGR24:
149 DstFormat = PIXEL_FORMAT_RGB24;
151 case PIXEL_FORMAT_RGB16:
152 DstFormat = PIXEL_FORMAT_BGR16;
154 case PIXEL_FORMAT_BGR16:
155 DstFormat = PIXEL_FORMAT_RGB16;
157 case PIXEL_FORMAT_ARGB15:
158 DstFormat = PIXEL_FORMAT_ABGR15;
160 case PIXEL_FORMAT_RGB15:
161 DstFormat = PIXEL_FORMAT_BGR15;
163 case PIXEL_FORMAT_ABGR15:
164 DstFormat = PIXEL_FORMAT_ARGB15;
166 case PIXEL_FORMAT_BGR15:
167 DstFormat = PIXEL_FORMAT_RGB15;
176static inline BOOL freerdp_bitmap_planar_compress_plane_rle(
const BYTE* WINPR_RESTRICT inPlane,
177 UINT32 width, UINT32 height,
178 BYTE* WINPR_RESTRICT outPlane,
179 UINT32* WINPR_RESTRICT dstSize);
180static inline BYTE* freerdp_bitmap_planar_delta_encode_plane(
const BYTE* WINPR_RESTRICT inPlane,
181 UINT32 width, UINT32 height,
182 BYTE* WINPR_RESTRICT outPlane);
184static inline INT32 planar_skip_plane_rle(
const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
185 UINT32 nWidth, UINT32 nHeight)
189 WINPR_ASSERT(pSrcData);
191 for (UINT32 y = 0; y < nHeight; y++)
193 for (UINT32 x = 0; x < nWidth;)
197 WLog_ERR(TAG,
"planar plane used %" PRIu32
" exceeds SrcSize %" PRIu32, used,
202 const uint8_t controlByte = pSrcData[used++];
203 uint32_t nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte);
204 uint32_t cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte);
208 nRunLength = cRawBytes + 16;
211 else if (nRunLength == 2)
213 nRunLength = cRawBytes + 32;
223 WLog_ERR(TAG,
"planar plane x %" PRIu32
" exceeds width %" PRIu32, x, nWidth);
229 WLog_ERR(TAG,
"planar plane used %" PRIu32
" exceeds SrcSize %" PRId32, used,
236 if (used > INT32_MAX)
238 WLog_ERR(TAG,
"planar plane used %" PRIu32
" exceeds SrcSize %" PRIu32, used, SrcSize);
244static inline UINT8 clamp(INT16 val)
249static inline INT32 planar_decompress_plane_rle_only(
const BYTE* WINPR_RESTRICT pSrcData,
250 UINT32 SrcSize, BYTE* WINPR_RESTRICT pDstData,
251 UINT32 nWidth, UINT32 nHeight)
253 BYTE* previousScanline =
nullptr;
254 const BYTE* srcp = pSrcData;
256 WINPR_ASSERT(nHeight <= INT32_MAX);
257 WINPR_ASSERT(nWidth <= INT32_MAX);
259 for (UINT32 y = 0; y < nHeight; y++)
261 BYTE* dstp = &pDstData[1ULL * (y)*nWidth];
263 BYTE* currentScanline = dstp;
265 for (UINT32 x = 0; x < nWidth;)
267 const size_t cur = WINPR_ASSERTING_INT_CAST(
size_t, (srcp - pSrcData));
268 if (cur + 1 > SrcSize * 1ll)
270 WLog_ERR(TAG,
"error reading input buffer");
274 BYTE controlByte = *srcp;
277 UINT32 nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte);
278 UINT32 cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte);
282 nRunLength = cRawBytes + 16;
285 else if (nRunLength == 2)
287 nRunLength = cRawBytes + 32;
291 if (((dstp + (cRawBytes + nRunLength)) - currentScanline) > nWidth * 1ll)
293 WLog_ERR(TAG,
"too many pixels in scanline");
297 if (!previousScanline)
300 while (cRawBytes > 0)
304 *dstp = clamp(pixel);
310 while (nRunLength > 0)
312 *dstp = clamp(pixel);
321 while (cRawBytes > 0)
323 UINT8 deltaValue = *srcp;
328 deltaValue = deltaValue >> 1;
329 deltaValue = deltaValue + 1;
330 pixel = WINPR_ASSERTING_INT_CAST(int16_t, -1 * (int16_t)deltaValue);
334 deltaValue = deltaValue >> 1;
335 pixel = WINPR_ASSERTING_INT_CAST(INT16, deltaValue);
339 WINPR_ASSERTING_INT_CAST(int16_t, previousScanline[x] + pixel);
340 *dstp = clamp(delta);
346 while (nRunLength > 0)
348 const INT16 deltaValue =
349 WINPR_ASSERTING_INT_CAST(int16_t, previousScanline[x] + pixel);
350 *dstp = clamp(deltaValue);
358 previousScanline = currentScanline;
361 return (INT32)(srcp - pSrcData);
364static inline INT32 planar_decompress_plane_rle(
const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
365 BYTE* WINPR_RESTRICT pDstData, UINT32 nDstStep,
366 UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
367 UINT32 nHeight, UINT32 nChannel, BOOL vFlip)
372 BYTE* previousScanline =
nullptr;
373 const BYTE* srcp = pSrcData;
375 WINPR_ASSERT(nHeight <= INT32_MAX);
376 WINPR_ASSERT(nWidth <= INT32_MAX);
377 WINPR_ASSERT(nDstStep <= INT32_MAX);
381 beg = (INT32)nHeight - 1;
388 end = (INT32)nHeight;
392 for (INT32 y = beg; y != end; y += inc)
394 const intptr_t off = ((1LL * nYDst + y) * nDstStep) + (4LL * nXDst) + nChannel * 1LL;
395 BYTE* dstp = &pDstData[off];
396 BYTE* currentScanline = dstp;
399 for (INT32 x = 0; x < (INT32)nWidth;)
401 const size_t cur = WINPR_ASSERTING_INT_CAST(
size_t, (srcp - pSrcData));
402 if (cur + 1 > SrcSize * 1ll)
404 WLog_ERR(TAG,
"error reading input buffer");
408 const BYTE controlByte = *srcp;
411 UINT32 nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte);
412 UINT32 cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte);
416 nRunLength = cRawBytes + 16;
419 else if (nRunLength == 2)
421 nRunLength = cRawBytes + 32;
425 if (((dstp + (cRawBytes + nRunLength)) - currentScanline) > nWidth * 4ll)
427 WLog_ERR(TAG,
"too many pixels in scanline");
431 if (!previousScanline)
434 while (cRawBytes > 0)
438 *dstp = WINPR_ASSERTING_INT_CAST(BYTE, pixel);
444 while (nRunLength > 0)
446 *dstp = WINPR_ASSERTING_INT_CAST(BYTE, pixel);
455 while (cRawBytes > 0)
457 BYTE deltaValue = *srcp;
462 deltaValue = deltaValue >> 1;
463 deltaValue = deltaValue + 1;
464 pixel = WINPR_ASSERTING_INT_CAST(int16_t, -deltaValue);
468 deltaValue = deltaValue >> 1;
473 WINPR_ASSERTING_INT_CAST(int16_t, previousScanline[4LL * x] + pixel);
474 *dstp = clamp(delta);
480 while (nRunLength > 0)
482 const INT16 deltaValue =
483 WINPR_ASSERTING_INT_CAST(int16_t, pixel + previousScanline[4LL * x]);
484 *dstp = clamp(deltaValue);
492 previousScanline = currentScanline;
495 return (INT32)(srcp - pSrcData);
498static inline INT32 planar_set_plane(BYTE bValue, BYTE* pDstData, UINT32 nDstStep, UINT32 nXDst,
499 UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, UINT32 nChannel,
503 INT32 end = (INT32)nHeight;
506 WINPR_ASSERT(nHeight <= INT32_MAX);
507 WINPR_ASSERT(nWidth <= INT32_MAX);
508 WINPR_ASSERT(nDstStep <= INT32_MAX);
512 beg = (INT32)nHeight - 1;
517 for (INT32 y = beg; y != end; y += inc)
519 const intptr_t off = ((1LL * nYDst + y) * nDstStep) + (4LL * nXDst) + nChannel * 1LL;
520 BYTE* dstp = &pDstData[off];
522 for (INT32 x = 0; x < (INT32)nWidth; ++x)
532static inline BOOL writeLine(BYTE** WINPR_RESTRICT ppRgba, UINT32 DstFormat, UINT32 width,
533 const BYTE** WINPR_RESTRICT ppR,
const BYTE** WINPR_RESTRICT ppG,
534 const BYTE** WINPR_RESTRICT ppB,
const BYTE** WINPR_RESTRICT ppA)
536 WINPR_ASSERT(ppRgba);
543 case PIXEL_FORMAT_BGRA32:
544 for (UINT32 x = 0; x < width; x++)
546 *(*ppRgba)++ = *(*ppB)++;
547 *(*ppRgba)++ = *(*ppG)++;
548 *(*ppRgba)++ = *(*ppR)++;
549 *(*ppRgba)++ = *(*ppA)++;
554 case PIXEL_FORMAT_BGRX32:
555 for (UINT32 x = 0; x < width; x++)
557 *(*ppRgba)++ = *(*ppB)++;
558 *(*ppRgba)++ = *(*ppG)++;
559 *(*ppRgba)++ = *(*ppR)++;
568 for (UINT32 x = 0; x < width; x++)
570 BYTE alpha = *(*ppA)++;
572 FreeRDPGetColor(DstFormat, *(*ppR)++, *(*ppG)++, *(*ppB)++, alpha);
573 FreeRDPWriteColor(*ppRgba, DstFormat, color);
574 *ppRgba += FreeRDPGetBytesPerPixel(DstFormat);
579 const BYTE alpha = 0xFF;
581 for (UINT32 x = 0; x < width; x++)
584 FreeRDPGetColor(DstFormat, *(*ppR)++, *(*ppG)++, *(*ppB)++, alpha);
585 FreeRDPWriteColor(*ppRgba, DstFormat, color);
586 *ppRgba += FreeRDPGetBytesPerPixel(DstFormat);
594static inline BOOL planar_decompress_planes_raw(
const BYTE* WINPR_RESTRICT pSrcData[4],
595 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat,
596 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
597 UINT32 nWidth, UINT32 nHeight, BOOL vFlip,
603 const BYTE* pR = pSrcData[0];
604 const BYTE* pG = pSrcData[1];
605 const BYTE* pB = pSrcData[2];
606 const BYTE* pA = pSrcData[3];
607 const UINT32 bpp = FreeRDPGetBytesPerPixel(DstFormat);
611 beg = WINPR_ASSERTING_INT_CAST(int32_t, nHeight - 1);
618 end = WINPR_ASSERTING_INT_CAST(int32_t, nHeight);
622 if (nYDst + nHeight > totalHeight)
625 "planar plane destination Y %" PRIu32
" + height %" PRIu32
626 " exceeds totalHeight %" PRIu32,
627 nYDst, nHeight, totalHeight);
631 if ((nXDst + nWidth) * bpp > nDstStep)
634 "planar plane destination (X %" PRIu32
" + width %" PRIu32
") * bpp %" PRIu32
635 " exceeds stride %" PRIu32,
636 nXDst, nWidth, bpp, nDstStep);
640 for (INT32 y = beg; y != end; y += inc)
642 BYTE* pRGB =
nullptr;
644 if (y > WINPR_ASSERTING_INT_CAST(INT64, nHeight))
646 WLog_ERR(TAG,
"planar plane destination Y %" PRId32
" exceeds height %" PRIu32, y,
651 const intptr_t off = ((1LL * nYDst + y) * nDstStep) + (1LL * nXDst * bpp);
652 pRGB = &pDstData[off];
654 if (!writeLine(&pRGB, DstFormat, nWidth, &pR, &pG, &pB, &pA))
661static BOOL planar_subsample_expand(
const BYTE* WINPR_RESTRICT plane,
size_t planeLength,
662 UINT32 nWidth, UINT32 nHeight, UINT32 nPlaneWidth,
663 UINT32 nPlaneHeight, BYTE* WINPR_RESTRICT deltaPlane)
666 WINPR_UNUSED(planeLength);
669 WINPR_ASSERT(deltaPlane);
671 if (nWidth > nPlaneWidth * 2)
673 WLog_ERR(TAG,
"planar subsample width %" PRIu32
" > PlaneWidth %" PRIu32
" * 2", nWidth,
678 if (nHeight > nPlaneHeight * 2)
680 WLog_ERR(TAG,
"planar subsample height %" PRIu32
" > PlaneHeight %" PRIu32
" * 2", nHeight,
685 for (
size_t y = 0; y < nHeight; y++)
687 const BYTE* src = plane + y / 2 * nPlaneWidth;
689 for (UINT32 x = 0; x < nWidth; x++)
691 deltaPlane[pos++] = src[x / 2];
698#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
699BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar,
700 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 nSrcWidth,
701 UINT32 nSrcHeight, BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat,
702 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth,
703 UINT32 nDstHeight, BOOL vFlip)
705 return freerdp_bitmap_decompress_planar(planar, pSrcData, SrcSize, nSrcWidth, nSrcHeight,
706 pDstData, DstFormat, nDstStep, nXDst, nYDst, nDstWidth,
711BOOL freerdp_bitmap_decompress_planar(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar,
712 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
713 UINT32 nSrcWidth, UINT32 nSrcHeight,
714 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat,
715 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth,
716 UINT32 nDstHeight, BOOL vFlip)
718 BOOL useAlpha = FALSE;
720 INT32 rleSizes[4] = { 0, 0, 0, 0 };
721 UINT32 rawSizes[4] = WINPR_C_ARRAY_INIT;
722 UINT32 rawWidths[4] = WINPR_C_ARRAY_INIT;
723 UINT32 rawHeights[4] = WINPR_C_ARRAY_INIT;
724 const BYTE* planes[4] = WINPR_C_ARRAY_INIT;
725 const UINT32 w = MIN(nSrcWidth, nDstWidth);
726 const UINT32 h = MIN(nSrcHeight, nDstHeight);
729 WINPR_ASSERT(planar);
732 if (planar->maxWidth < nSrcWidth)
734 if (planar->maxHeight < nSrcHeight)
737 const UINT32 bpp = FreeRDPGetBytesPerPixel(DstFormat);
739 nDstStep = nDstWidth * bpp;
741 const BYTE* srcp = pSrcData;
743 if (!pSrcData || (SrcSize < 1))
745 WLog_ERR(TAG,
"Invalid argument pSrcData=%p [size=%" PRIu32
"]",
746 WINPR_CXX_COMPAT_CAST(
const void*, pSrcData), SrcSize);
752 WLog_ERR(TAG,
"Invalid argument pDstData=nullptr");
756 const BYTE FormatHeader = *srcp++;
757 const BYTE cll = (FormatHeader & PLANAR_FORMAT_HEADER_CLL_MASK);
758 const BYTE cs = (FormatHeader & PLANAR_FORMAT_HEADER_CS) != 0;
759 const BYTE rle = (FormatHeader & PLANAR_FORMAT_HEADER_RLE) != 0;
760 const BYTE alpha = !(FormatHeader & PLANAR_FORMAT_HEADER_NA);
762 DstFormat = planar_invert_format(planar, alpha, DstFormat);
765 useAlpha = FreeRDPColorHasAlpha(DstFormat);
772 WLog_ERR(TAG,
"Chroma subsampling requires YCoCg and does not work with RGB data");
776 const UINT32 subWidth = (nSrcWidth / 2) + (nSrcWidth % 2);
777 const UINT32 subHeight = (nSrcHeight / 2) + (nSrcHeight % 2);
778 const UINT32 planeSize = nSrcWidth * nSrcHeight;
779 const UINT32 subSize = subWidth * subHeight;
783 rawSizes[0] = planeSize;
784 rawWidths[0] = nSrcWidth;
785 rawHeights[0] = nSrcHeight;
786 rawSizes[1] = planeSize;
787 rawWidths[1] = nSrcWidth;
788 rawHeights[1] = nSrcHeight;
789 rawSizes[2] = planeSize;
790 rawWidths[2] = nSrcWidth;
791 rawHeights[2] = nSrcHeight;
792 rawSizes[3] = planeSize;
793 rawWidths[3] = nSrcWidth;
794 rawHeights[3] = nSrcHeight;
798 rawSizes[0] = planeSize;
799 rawWidths[0] = nSrcWidth;
800 rawHeights[0] = nSrcHeight;
801 rawSizes[1] = subSize;
802 rawWidths[1] = subWidth;
803 rawHeights[1] = subHeight;
804 rawSizes[2] = subSize;
805 rawWidths[2] = subWidth;
806 rawHeights[2] = subHeight;
807 rawSizes[3] = planeSize;
808 rawWidths[3] = nSrcWidth;
809 rawHeights[3] = nSrcHeight;
812 const size_t diff = WINPR_ASSERTING_INT_CAST(
size_t, (intptr_t)(srcp - pSrcData));
815 WLog_ERR(TAG,
"Size mismatch %" PRIu32
" < %" PRIuz, SrcSize, diff);
822 UINT32 base = planeSize * 3;
824 base = planeSize + planeSize / 2;
828 if ((SrcSize - diff) < (planeSize + base))
830 WLog_ERR(TAG,
"Alpha plane size mismatch %" PRIuz
" < %" PRIu32, SrcSize - diff,
836 planes[0] = planes[3] + rawSizes[3];
837 planes[1] = planes[0] + rawSizes[0];
838 planes[2] = planes[1] + rawSizes[1];
840 if ((planes[2] + rawSizes[2]) > &pSrcData[SrcSize])
842 WLog_ERR(TAG,
"plane size mismatch %p + %" PRIu32
" > %p",
843 WINPR_CXX_COMPAT_CAST(
const void*, planes[2]), rawSizes[2],
844 WINPR_CXX_COMPAT_CAST(
const void*, &pSrcData[SrcSize]));
850 if ((SrcSize - diff) < base)
852 WLog_ERR(TAG,
"plane size mismatch %" PRIuz
" < %" PRIu32, SrcSize - diff, base);
857 planes[1] = planes[0] + rawSizes[0];
858 planes[2] = planes[1] + rawSizes[1];
860 if ((planes[2] + rawSizes[2]) > &pSrcData[SrcSize])
862 WLog_ERR(TAG,
"plane size mismatch %p + %" PRIu32
" > %p",
863 WINPR_CXX_COMPAT_CAST(
const void*, planes[2]), rawSizes[2],
864 WINPR_CXX_COMPAT_CAST(
const void*, &pSrcData[SrcSize]));
874 rleSizes[3] = planar_skip_plane_rle(planes[3], (UINT32)(SrcSize - diff), rawWidths[3],
880 planes[0] = planes[3] + rleSizes[3];
885 const size_t diff0 = WINPR_ASSERTING_INT_CAST(
size_t, (intptr_t)(planes[0] - pSrcData));
888 WLog_ERR(TAG,
"Size mismatch %" PRIu32
" < %" PRIuz, SrcSize, diff0);
891 rleSizes[0] = planar_skip_plane_rle(planes[0], (UINT32)(SrcSize - diff0), rawWidths[0],
897 planes[1] = planes[0] + rleSizes[0];
899 const size_t diff1 = WINPR_ASSERTING_INT_CAST(
size_t, (intptr_t)(planes[1] - pSrcData));
902 WLog_ERR(TAG,
"Size mismatch %" PRIu32
" < %" PRIuz, SrcSize, diff1);
905 rleSizes[1] = planar_skip_plane_rle(planes[1], (UINT32)(SrcSize - diff1), rawWidths[1],
911 planes[2] = planes[1] + rleSizes[1];
912 const size_t diff2 = WINPR_ASSERTING_INT_CAST(
size_t, (intptr_t)(planes[2] - pSrcData));
915 WLog_ERR(TAG,
"Size mismatch %" PRIu32
" < %" PRIuz, SrcSize, diff);
918 rleSizes[2] = planar_skip_plane_rle(planes[2], (UINT32)(SrcSize - diff2), rawWidths[2],
927 UINT32 TempFormat = 0;
928 BYTE* pTempData = pDstData;
929 UINT32 nTempStep = nDstStep;
930 UINT32 nTotalHeight = nYDst + nDstHeight;
933 TempFormat = PIXEL_FORMAT_BGRA32;
935 TempFormat = PIXEL_FORMAT_BGRX32;
937 TempFormat = planar_invert_format(planar, alpha, TempFormat);
939 if ((TempFormat != DstFormat) || (nSrcWidth != nDstWidth) || (nSrcHeight != nDstHeight))
941 pTempData = planar->pTempData;
942 nTempStep = planar->nTempStep;
943 nTotalHeight = planar->maxHeight;
948 if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, nXDst,
949 nYDst, nSrcWidth, nSrcHeight, vFlip, nTotalHeight))
953 srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3];
955 srcp += rawSizes[0] + rawSizes[1] + rawSizes[2];
957 if ((SrcSize - (srcp - pSrcData)) == 1)
962 if (nYDst + nSrcHeight > nTotalHeight)
965 "planar plane destination Y %" PRIu32
" + height %" PRIu32
966 " exceeds totalHeight %" PRIu32,
967 nYDst, nSrcHeight, nTotalHeight);
971 if ((nXDst + nSrcWidth) * bpp > nTempStep)
974 "planar plane destination (X %" PRIu32
" + width %" PRIu32
975 ") * bpp %" PRIu32
" exceeds stride %" PRIu32,
976 nXDst, nSrcWidth, bpp, nTempStep);
980 status = planar_decompress_plane_rle(
981 planes[0], WINPR_ASSERTING_INT_CAST(uint32_t, rleSizes[0]), pTempData, nTempStep,
982 nXDst, nYDst, nSrcWidth, nSrcHeight, 2, vFlip);
987 status = planar_decompress_plane_rle(
988 planes[1], WINPR_ASSERTING_INT_CAST(uint32_t, rleSizes[1]), pTempData, nTempStep,
989 nXDst, nYDst, nSrcWidth, nSrcHeight, 1, vFlip);
994 status = planar_decompress_plane_rle(
995 planes[2], WINPR_ASSERTING_INT_CAST(uint32_t, rleSizes[2]), pTempData, nTempStep,
996 nXDst, nYDst, nSrcWidth, nSrcHeight, 0, vFlip);
1001 srcp += rleSizes[0] + rleSizes[1] + rleSizes[2];
1005 status = planar_decompress_plane_rle(
1006 planes[3], WINPR_ASSERTING_INT_CAST(uint32_t, rleSizes[3]), pTempData,
1007 nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 3, vFlip);
1010 status = planar_set_plane(0xFF, pTempData, nTempStep, nXDst, nYDst, nSrcWidth,
1011 nSrcHeight, 3, vFlip);
1017 srcp += rleSizes[3];
1020 if (pTempData != pDstData)
1022 if (!freerdp_image_copy_no_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, w, h,
1023 pTempData, TempFormat, nTempStep, nXDst, nYDst,
1024 nullptr, FREERDP_FLIP_NONE))
1026 WLog_ERR(TAG,
"planar image copy failed");
1033 UINT32 TempFormat = 0;
1034 BYTE* pTempData = planar->pTempData;
1035 UINT32 nTempStep = planar->nTempStep;
1036 UINT32 nTotalHeight = planar->maxHeight;
1037 BYTE* dst = &pDstData[nXDst * FreeRDPGetBytesPerPixel(DstFormat) + nYDst * nDstStep];
1040 TempFormat = PIXEL_FORMAT_BGRA32;
1042 TempFormat = PIXEL_FORMAT_BGRX32;
1049 BYTE* rleBuffer[4] = WINPR_C_ARRAY_INIT;
1051 if (!planar->rlePlanesBuffer)
1054 rleBuffer[3] = planar->rlePlanesBuffer;
1055 rleBuffer[0] = rleBuffer[3] + planeSize;
1056 rleBuffer[1] = rleBuffer[0] + planeSize;
1057 rleBuffer[2] = rleBuffer[1] + planeSize;
1060 status = planar_decompress_plane_rle_only(
1061 planes[3], WINPR_ASSERTING_INT_CAST(uint32_t, rleSizes[3]), rleBuffer[3],
1062 rawWidths[3], rawHeights[3]);
1069 srcp += rleSizes[3];
1071 status = planar_decompress_plane_rle_only(
1072 planes[0], WINPR_ASSERTING_INT_CAST(uint32_t, rleSizes[0]), rleBuffer[0],
1073 rawWidths[0], rawHeights[0]);
1078 status = planar_decompress_plane_rle_only(
1079 planes[1], WINPR_ASSERTING_INT_CAST(uint32_t, rleSizes[1]), rleBuffer[1],
1080 rawWidths[1], rawHeights[1]);
1085 status = planar_decompress_plane_rle_only(
1086 planes[2], WINPR_ASSERTING_INT_CAST(uint32_t, rleSizes[2]), rleBuffer[2],
1087 rawWidths[2], rawHeights[2]);
1092 planes[0] = rleBuffer[0];
1093 planes[1] = rleBuffer[1];
1094 planes[2] = rleBuffer[2];
1095 planes[3] = rleBuffer[3];
1104 if (!planar_subsample_expand(planes[1], rawSizes[1], nSrcWidth, nSrcHeight,
1105 rawWidths[1], rawHeights[1], planar->deltaPlanes[0]))
1108 planes[1] = planar->deltaPlanes[0];
1109 rawSizes[1] = planeSize;
1110 rawWidths[1] = nSrcWidth;
1111 rawHeights[1] = nSrcHeight;
1113 if (!planar_subsample_expand(planes[2], rawSizes[2], nSrcWidth, nSrcHeight,
1114 rawWidths[2], rawHeights[2], planar->deltaPlanes[1]))
1117 planes[2] = planar->deltaPlanes[1];
1118 rawSizes[2] = planeSize;
1119 rawWidths[2] = nSrcWidth;
1120 rawHeights[2] = nSrcHeight;
1123 if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, nXDst,
1124 nYDst, nSrcWidth, nSrcHeight, vFlip, nTotalHeight))
1128 srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3];
1130 srcp += rawSizes[0] + rawSizes[1] + rawSizes[2];
1132 if ((SrcSize - (srcp - pSrcData)) == 1)
1136 WINPR_ASSERT(prims->YCoCgToRGB_8u_AC4R);
1137 int rc = prims->YCoCgToRGB_8u_AC4R(
1138 pTempData, WINPR_ASSERTING_INT_CAST(int32_t, nTempStep), dst, DstFormat,
1139 WINPR_ASSERTING_INT_CAST(int32_t, nDstStep), w, h, cll, useAlpha);
1140 if (rc != PRIMITIVES_SUCCESS)
1142 WLog_ERR(TAG,
"YCoCgToRGB_8u_AC4R failed with %d", rc);
1151static inline BOOL freerdp_split_color_planes(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar,
1152 const BYTE* WINPR_RESTRICT data, UINT32 format,
1153 UINT32 width, UINT32 height, UINT32 scanline,
1154 BYTE* WINPR_RESTRICT planes[4])
1156 WINPR_ASSERT(planar);
1158 if ((width > INT32_MAX) || (height > INT32_MAX) || (scanline > INT32_MAX))
1162 scanline = width * FreeRDPGetBytesPerPixel(format);
1164 if (planar->topdown)
1167 for (UINT32 i = 0; i < height; i++)
1169 const BYTE* pixel = &data[1ULL * scanline * i];
1171 for (UINT32 j = 0; j < width; j++)
1173 const UINT32 color = FreeRDPReadColor(pixel, format);
1174 pixel += FreeRDPGetBytesPerPixel(format);
1175 FreeRDPSplitColor(color, format, &planes[1][k], &planes[2][k], &planes[3][k],
1176 &planes[0][k],
nullptr);
1185 for (INT64 i = (INT64)height - 1; i >= 0; i--)
1187 const BYTE* pixel = &data[1ULL * scanline * (UINT32)i];
1189 for (UINT32 j = 0; j < width; j++)
1191 const UINT32 color = FreeRDPReadColor(pixel, format);
1192 pixel += FreeRDPGetBytesPerPixel(format);
1193 FreeRDPSplitColor(color, format, &planes[1][k], &planes[2][k], &planes[3][k],
1194 &planes[0][k],
nullptr);
1202static inline UINT32 freerdp_bitmap_planar_write_rle_bytes(
const BYTE* WINPR_RESTRICT pInBuffer,
1203 UINT32 cRawBytes, UINT32 nRunLength,
1204 BYTE* WINPR_RESTRICT pOutBuffer,
1205 UINT32 outBufferSize)
1207 const BYTE* pInput = pInBuffer;
1208 BYTE* pOutput = pOutBuffer;
1209 BYTE controlByte = 0;
1210 UINT32 nBytesToWrite = 0;
1212 if (!cRawBytes && !nRunLength)
1217 cRawBytes += nRunLength;
1225 if (nRunLength > 15)
1227 if (nRunLength < 18)
1229 controlByte = PLANAR_CONTROL_BYTE(13, cRawBytes);
1235 controlByte = PLANAR_CONTROL_BYTE(15, cRawBytes);
1242 controlByte = PLANAR_CONTROL_BYTE(nRunLength, cRawBytes);
1249 controlByte = PLANAR_CONTROL_BYTE(0, 15);
1253 if (outBufferSize < 1)
1257 *pOutput = controlByte;
1259 nBytesToWrite = (controlByte >> 4);
1263 if (outBufferSize < nBytesToWrite)
1266 outBufferSize -= nBytesToWrite;
1267 CopyMemory(pOutput, pInput, nBytesToWrite);
1268 pOutput += nBytesToWrite;
1269 pInput += nBytesToWrite;
1275 if (nRunLength > 47)
1277 if (nRunLength < 50)
1279 controlByte = PLANAR_CONTROL_BYTE(2, 13);
1284 controlByte = PLANAR_CONTROL_BYTE(2, 15);
1288 else if (nRunLength > 31)
1290 controlByte = PLANAR_CONTROL_BYTE(2, (nRunLength - 32));
1293 else if (nRunLength > 15)
1295 controlByte = PLANAR_CONTROL_BYTE(1, (nRunLength - 16));
1300 controlByte = PLANAR_CONTROL_BYTE(nRunLength, 0);
1304 if (outBufferSize < 1)
1308 *pOutput = controlByte;
1312 const intptr_t diff = (pOutput - pOutBuffer);
1313 if ((diff < 0) || (diff > UINT32_MAX))
1315 return (UINT32)diff;
1318static inline UINT32 freerdp_bitmap_planar_encode_rle_bytes(
const BYTE* WINPR_RESTRICT pInBuffer,
1319 UINT32 inBufferSize,
1320 BYTE* WINPR_RESTRICT pOutBuffer,
1321 UINT32 outBufferSize)
1324 const BYTE* pInput = pInBuffer;
1325 BYTE* pOutput = pOutBuffer;
1326 const BYTE* pBytes =
nullptr;
1327 UINT32 cRawBytes = 0;
1328 UINT32 nRunLength = 0;
1329 UINT32 nBytesWritten = 0;
1330 UINT32 nTotalBytesWritten = 0;
1340 const UINT32 bSymbolMatch = (symbol == *pInput) != 0;
1345 if (nRunLength && !bSymbolMatch)
1349 cRawBytes += nRunLength;
1354 pBytes = pInput - (cRawBytes + nRunLength + 1);
1355 nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes, cRawBytes, nRunLength,
1356 pOutput, outBufferSize);
1359 if (!nBytesWritten || (nBytesWritten > outBufferSize))
1362 nTotalBytesWritten += nBytesWritten;
1363 outBufferSize -= nBytesWritten;
1364 pOutput += nBytesWritten;
1369 nRunLength += bSymbolMatch;
1370 cRawBytes += (!bSymbolMatch) != 0;
1371 }
while (outBufferSize);
1373 if (cRawBytes || nRunLength)
1375 pBytes = pInput - (cRawBytes + nRunLength);
1376 nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes, cRawBytes, nRunLength,
1377 pOutput, outBufferSize);
1382 nTotalBytesWritten += nBytesWritten;
1388 return nTotalBytesWritten;
1391BOOL freerdp_bitmap_planar_compress_plane_rle(
const BYTE* WINPR_RESTRICT inPlane, UINT32 width,
1392 UINT32 height, BYTE* WINPR_RESTRICT outPlane,
1393 UINT32* WINPR_RESTRICT dstSize)
1399 const BYTE* pInput = inPlane;
1400 BYTE* pOutput = outPlane;
1401 UINT32 outBufferSize = *dstSize;
1402 UINT32 nTotalBytesWritten = 0;
1404 while (outBufferSize > 0)
1406 const UINT32 nBytesWritten =
1407 freerdp_bitmap_planar_encode_rle_bytes(pInput, width, pOutput, outBufferSize);
1409 if ((!nBytesWritten) || (nBytesWritten > outBufferSize))
1412 outBufferSize -= nBytesWritten;
1413 nTotalBytesWritten += nBytesWritten;
1414 pOutput += nBytesWritten;
1418 if (index >= height)
1422 *dstSize = nTotalBytesWritten;
1426static inline BOOL freerdp_bitmap_planar_compress_planes_rle(BYTE* WINPR_RESTRICT inPlanes[4],
1427 UINT32 width, UINT32 height,
1428 BYTE* WINPR_RESTRICT outPlanes,
1429 UINT32* WINPR_RESTRICT dstSizes,
1432 UINT32 outPlanesSize = width * height * 4;
1441 dstSizes[0] = outPlanesSize;
1443 if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[0], width, height, outPlanes,
1447 outPlanes += dstSizes[0];
1448 outPlanesSize -= dstSizes[0];
1452 dstSizes[1] = outPlanesSize;
1454 if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[1], width, height, outPlanes,
1458 outPlanes += dstSizes[1];
1459 outPlanesSize -= dstSizes[1];
1461 dstSizes[2] = outPlanesSize;
1463 if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[2], width, height, outPlanes,
1467 outPlanes += dstSizes[2];
1468 outPlanesSize -= dstSizes[2];
1470 dstSizes[3] = outPlanesSize;
1472 return (freerdp_bitmap_planar_compress_plane_rle(inPlanes[3], width, height, outPlanes,
1476BYTE* freerdp_bitmap_planar_delta_encode_plane(
const BYTE* WINPR_RESTRICT inPlane, UINT32 width,
1477 UINT32 height, BYTE* WINPR_RESTRICT outPlane)
1481 if (width * height == 0)
1484 outPlane = (BYTE*)calloc(height, width);
1490 CopyMemory(outPlane, inPlane, width);
1492 for (UINT32 y = 1; y < height; y++)
1494 const size_t off = 1ull * width * y;
1495 BYTE* outPtr = &outPlane[off];
1496 const BYTE* srcPtr = &inPlane[off];
1497 const BYTE* prevLinePtr = &inPlane[off - width];
1498 for (UINT32 x = 0; x < width; x++)
1500 const int delta = (int)srcPtr[x] - (
int)prevLinePtr[x];
1501 const int s2c1i = (delta >= 0) ? delta : (INT_MAX + delta) + 1;
1502 const int8_t s2c1 = WINPR_CXX_COMPAT_CAST(int8_t, s2c1i);
1503 const uint32_t s2c =
1504 (s2c1 >= 0) ? ((UINT32)s2c1 << 1) : (((UINT32)(~(s2c1) + 1) << 1) - 1);
1505 outPtr[x] = (BYTE)s2c;
1512static inline BOOL freerdp_bitmap_planar_delta_encode_planes(BYTE* WINPR_RESTRICT inPlanes[4],
1513 UINT32 width, UINT32 height,
1514 BYTE* WINPR_RESTRICT outPlanes[4])
1516 for (UINT32 i = 0; i < 4; i++)
1519 freerdp_bitmap_planar_delta_encode_plane(inPlanes[i], width, height, outPlanes[i]);
1528BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT context,
1529 const BYTE* WINPR_RESTRICT data, UINT32 format, UINT32 width,
1530 UINT32 height, UINT32 scanline, BYTE* WINPR_RESTRICT dstData,
1531 UINT32* WINPR_RESTRICT pDstSize)
1534 BYTE* dstp =
nullptr;
1535 UINT32 dstSizes[4] = WINPR_C_ARRAY_INIT;
1536 BYTE FormatHeader = 0;
1538 if (!context || !context->rlePlanesBuffer)
1541 if (context->AllowSkipAlpha)
1542 FormatHeader |= PLANAR_FORMAT_HEADER_NA;
1544 const UINT32 planeSize = width * height;
1546 if (!context->AllowSkipAlpha)
1547 format = planar_invert_format(context, TRUE, format);
1549 if (!freerdp_split_color_planes(context, data, format, width, height, scanline,
1553 if (context->AllowRunLengthEncoding)
1555 if (!freerdp_bitmap_planar_delta_encode_planes(context->planes, width, height,
1556 context->deltaPlanes))
1559 if (!freerdp_bitmap_planar_compress_planes_rle(context->deltaPlanes, width, height,
1560 context->rlePlanesBuffer, dstSizes,
1561 context->AllowSkipAlpha))
1565 uint32_t offset = 0;
1566 FormatHeader |= PLANAR_FORMAT_HEADER_RLE;
1567 context->rlePlanes[0] = &context->rlePlanesBuffer[offset];
1568 offset += dstSizes[0];
1569 context->rlePlanes[1] = &context->rlePlanesBuffer[offset];
1570 offset += dstSizes[1];
1571 context->rlePlanes[2] = &context->rlePlanesBuffer[offset];
1572 offset += dstSizes[2];
1573 context->rlePlanes[3] = &context->rlePlanesBuffer[offset];
1575#if defined(WITH_DEBUG_CODECS)
1577 "R: [%" PRIu32
"/%" PRIu32
"] G: [%" PRIu32
"/%" PRIu32
"] B: [%" PRIu32
1579 dstSizes[1], planeSize, dstSizes[2], planeSize, dstSizes[3], planeSize);
1584 if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
1586 if (!context->AllowRunLengthEncoding)
1589 if (context->rlePlanes[0] ==
nullptr)
1592 if (context->rlePlanes[1] ==
nullptr)
1595 if (context->rlePlanes[2] ==
nullptr)
1598 if (context->rlePlanes[3] ==
nullptr)
1606 if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
1608 if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
1609 size += dstSizes[0];
1614 if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
1615 size += (dstSizes[1] + dstSizes[2] + dstSizes[3]);
1617 size += (planeSize * 3);
1619 if (!(FormatHeader & PLANAR_FORMAT_HEADER_RLE))
1622 dstData = malloc(size);
1631 *dstp = FormatHeader;
1636 if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
1638 if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
1640 CopyMemory(dstp, context->rlePlanes[0], dstSizes[0]);
1641 dstp += dstSizes[0];
1645 CopyMemory(dstp, context->planes[0], planeSize);
1652 if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
1654 CopyMemory(dstp, context->rlePlanes[1], dstSizes[1]);
1655 dstp += dstSizes[1];
1659 CopyMemory(dstp, context->planes[1], planeSize);
1665 if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
1667 CopyMemory(dstp, context->rlePlanes[2], dstSizes[2]);
1668 dstp += dstSizes[2];
1672 CopyMemory(dstp, context->planes[2], planeSize);
1678 if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
1680 CopyMemory(dstp, context->rlePlanes[3], dstSizes[3]);
1681 dstp += dstSizes[3];
1685 CopyMemory(dstp, context->planes[3], planeSize);
1691 if (!(FormatHeader & PLANAR_FORMAT_HEADER_RLE))
1697 const intptr_t diff = (dstp - dstData);
1698 if ((diff < 0) || (diff > UINT32_MAX))
1703 size = (UINT32)diff;
1708BOOL freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT context,
1709 UINT32 width, UINT32 height)
1714 context->bgr = FALSE;
1715 context->maxWidth = PLANAR_ALIGN(width, 4);
1716 context->maxHeight = PLANAR_ALIGN(height, 4);
1718 const UINT64 tmp = (UINT64)context->maxWidth * context->maxHeight;
1719 if (tmp > UINT32_MAX)
1721 context->maxPlaneSize = (UINT32)tmp;
1724 if (context->maxWidth > UINT32_MAX / 4)
1726 context->nTempStep = context->maxWidth * 4;
1728 memset((
void*)context->planes, 0,
sizeof(context->planes));
1729 memset((
void*)context->rlePlanes, 0,
sizeof(context->rlePlanes));
1730 memset((
void*)context->deltaPlanes, 0,
sizeof(context->deltaPlanes));
1732 if (context->maxPlaneSize > 0)
1734 void* tmp = winpr_aligned_recalloc(context->planesBuffer, context->maxPlaneSize, 4, 32);
1737 context->planesBuffer = tmp;
1739 tmp = winpr_aligned_recalloc(context->pTempData, context->maxPlaneSize, 6, 32);
1742 context->pTempData = tmp;
1744 tmp = winpr_aligned_recalloc(context->deltaPlanesBuffer, context->maxPlaneSize, 4, 32);
1747 context->deltaPlanesBuffer = tmp;
1749 tmp = winpr_aligned_recalloc(context->rlePlanesBuffer, context->maxPlaneSize, 4, 32);
1752 context->rlePlanesBuffer = tmp;
1754 context->planes[0] = &context->planesBuffer[0ULL * context->maxPlaneSize];
1755 context->planes[1] = &context->planesBuffer[1ULL * context->maxPlaneSize];
1756 context->planes[2] = &context->planesBuffer[2ULL * context->maxPlaneSize];
1757 context->planes[3] = &context->planesBuffer[3ULL * context->maxPlaneSize];
1758 context->deltaPlanes[0] = &context->deltaPlanesBuffer[0ULL * context->maxPlaneSize];
1759 context->deltaPlanes[1] = &context->deltaPlanesBuffer[1ULL * context->maxPlaneSize];
1760 context->deltaPlanes[2] = &context->deltaPlanesBuffer[2ULL * context->maxPlaneSize];
1761 context->deltaPlanes[3] = &context->deltaPlanesBuffer[3ULL * context->maxPlaneSize];
1766BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, UINT32 maxWidth,
1769 BITMAP_PLANAR_CONTEXT* context =
1770 (BITMAP_PLANAR_CONTEXT*)winpr_aligned_calloc(1,
sizeof(BITMAP_PLANAR_CONTEXT), 32);
1775 if (flags & PLANAR_FORMAT_HEADER_NA)
1776 context->AllowSkipAlpha = TRUE;
1778 if (flags & PLANAR_FORMAT_HEADER_RLE)
1779 context->AllowRunLengthEncoding = TRUE;
1781 if (flags & PLANAR_FORMAT_HEADER_CS)
1782 context->AllowColorSubsampling = TRUE;
1784 context->ColorLossLevel = flags & PLANAR_FORMAT_HEADER_CLL_MASK;
1786 if (context->ColorLossLevel)
1787 context->AllowDynamicColorFidelity = TRUE;
1789 if (!freerdp_bitmap_planar_context_reset(context, maxWidth, maxHeight))
1791 WINPR_PRAGMA_DIAG_PUSH
1792 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
1793 freerdp_bitmap_planar_context_free(context);
1794 WINPR_PRAGMA_DIAG_POP
1801void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context)
1806 winpr_aligned_free(context->pTempData);
1807 winpr_aligned_free(context->planesBuffer);
1808 winpr_aligned_free(context->deltaPlanesBuffer);
1809 winpr_aligned_free(context->rlePlanesBuffer);
1810 winpr_aligned_free(context);
1813void freerdp_planar_switch_bgr(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, BOOL bgr)
1815 WINPR_ASSERT(planar);
1819void freerdp_planar_topdown_image(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, BOOL topdown)
1821 WINPR_ASSERT(planar);
1822 planar->topdown = topdown;