2013-11-26 03:58:01 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* RDP6 Planar Codec
|
|
|
|
*
|
|
|
|
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-11-26 07:26:08 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
|
|
|
|
#include <freerdp/codec/bitmap.h>
|
|
|
|
|
2013-11-26 03:58:01 +04:00
|
|
|
#include "planar.h"
|
|
|
|
|
2013-11-29 13:12:59 +04:00
|
|
|
static int freerdp_bitmap_planar_decompress_plane_rle(BYTE* inPlane, int width, int height, BYTE* outPlane, int srcSize)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 13:12:59 +04:00
|
|
|
int k;
|
2013-11-29 12:06:39 +04:00
|
|
|
int x, y;
|
|
|
|
BYTE* srcp;
|
|
|
|
BYTE* dstp;
|
|
|
|
UINT32 pixel;
|
|
|
|
int scanline;
|
|
|
|
int cRawBytes;
|
|
|
|
int nRunLength;
|
|
|
|
int deltaValue;
|
|
|
|
BYTE controlByte;
|
|
|
|
BYTE* currentScanline;
|
|
|
|
BYTE* previousScanline;
|
|
|
|
|
2013-11-29 13:12:59 +04:00
|
|
|
k = 0;
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
srcp = inPlane;
|
|
|
|
dstp = outPlane;
|
|
|
|
scanline = width * 4;
|
|
|
|
previousScanline = NULL;
|
|
|
|
|
|
|
|
y = 0;
|
|
|
|
|
|
|
|
while (y < height)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
pixel = 0;
|
|
|
|
dstp = (outPlane + height * scanline) - ((y + 1) * scanline);
|
|
|
|
currentScanline = dstp;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
x = 0;
|
|
|
|
|
|
|
|
while (x < width)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
controlByte = *srcp;
|
|
|
|
srcp++;
|
|
|
|
|
2013-11-29 13:12:59 +04:00
|
|
|
if ((srcp - inPlane) > srcSize)
|
|
|
|
{
|
|
|
|
printf("freerdp_bitmap_planar_decompress_plane_rle: error reading input buffer\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte);
|
|
|
|
cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte);
|
|
|
|
|
2013-11-29 13:12:59 +04:00
|
|
|
//printf("CONTROL(%d, %d)\n", cRawBytes, nRunLength);
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
if (nRunLength == 1)
|
|
|
|
{
|
|
|
|
nRunLength = cRawBytes + 16;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
else if (nRunLength == 2)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
nRunLength = cRawBytes + 32;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-11-29 13:12:59 +04:00
|
|
|
#if 0
|
|
|
|
printf("y: %d cRawBytes: %d nRunLength: %d\n", y, cRawBytes, nRunLength);
|
|
|
|
|
|
|
|
printf("RAW[");
|
|
|
|
|
|
|
|
for (k = 0; k < cRawBytes; k++)
|
|
|
|
{
|
|
|
|
printf("0x%02X%s", srcp[k],
|
|
|
|
((k + 1) == cRawBytes) ? "" : ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("] RUN[%d]\n", nRunLength);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (((dstp + (cRawBytes + nRunLength)) - currentScanline) > width * 4)
|
|
|
|
{
|
|
|
|
printf("freerdp_bitmap_planar_decompress_plane_rle: too many pixels in scanline\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
if (!previousScanline)
|
|
|
|
{
|
|
|
|
/* first scanline, absolute values */
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
while (cRawBytes > 0)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
pixel = *srcp;
|
|
|
|
srcp++;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
*dstp = pixel;
|
|
|
|
dstp += 4;
|
|
|
|
x++;
|
|
|
|
cRawBytes--;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
while (nRunLength > 0)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
*dstp = pixel;
|
|
|
|
dstp += 4;
|
|
|
|
x++;
|
|
|
|
nRunLength--;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
}
|
2013-11-29 12:06:39 +04:00
|
|
|
else
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
/* delta values relative to previous scanline */
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
while (cRawBytes > 0)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
deltaValue = *srcp;
|
|
|
|
srcp++;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
if (deltaValue & 1)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
deltaValue = deltaValue >> 1;
|
|
|
|
deltaValue = deltaValue + 1;
|
|
|
|
pixel = -deltaValue;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
deltaValue = deltaValue >> 1;
|
|
|
|
pixel = deltaValue;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
deltaValue = previousScanline[x * 4] + pixel;
|
|
|
|
*dstp = deltaValue;
|
|
|
|
dstp += 4;
|
|
|
|
x++;
|
|
|
|
cRawBytes--;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
while (nRunLength > 0)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
deltaValue = previousScanline[x * 4] + pixel;
|
|
|
|
*dstp = deltaValue;
|
|
|
|
dstp += 4;
|
|
|
|
x++;
|
|
|
|
nRunLength--;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
previousScanline = currentScanline;
|
|
|
|
y++;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
return (int) (srcp - inPlane);
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int freerdp_bitmap_planar_decompress_plane_raw(BYTE* srcData, int width, int height, BYTE* dstData, int size)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
dstData[(((height - y - 1) * width) + x) * 4] = srcData[((y * width) + x)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (width * height);
|
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_bitmap_planar_decompress(BYTE* srcData, BYTE* dstData, int width, int height, int size)
|
|
|
|
{
|
|
|
|
BYTE* srcp;
|
2013-11-29 12:06:39 +04:00
|
|
|
int dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
BYTE FormatHeader;
|
|
|
|
|
|
|
|
srcp = srcData;
|
|
|
|
|
|
|
|
FormatHeader = *srcp;
|
|
|
|
srcp++;
|
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
/* AlphaPlane */
|
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
|
|
|
|
{
|
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
dstSize = freerdp_bitmap_planar_decompress_plane_rle(srcp, width, height, dstData + 3, size - (srcp - srcData));
|
2013-11-29 13:12:59 +04:00
|
|
|
|
|
|
|
if (dstSize < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
srcp += dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
dstSize = freerdp_bitmap_planar_decompress_plane_raw(srcp, width, height, dstData + 3, size - (srcp - srcData));
|
|
|
|
srcp += dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
/* LumaOrRedPlane */
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
dstSize = freerdp_bitmap_planar_decompress_plane_rle(srcp, width, height, dstData + 2, size - (srcp - srcData));
|
2013-11-29 13:12:59 +04:00
|
|
|
|
|
|
|
if (dstSize < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
srcp += dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
/* OrangeChromaOrGreenPlane */
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
dstSize = freerdp_bitmap_planar_decompress_plane_rle(srcp, width, height, dstData + 1, size - (srcp - srcData));
|
2013-11-29 13:12:59 +04:00
|
|
|
|
|
|
|
if (dstSize < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
srcp += dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
/* GreenChromeOrBluePlane */
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
dstSize = freerdp_bitmap_planar_decompress_plane_rle(srcp, width, height, dstData + 0, size - (srcp - srcData));
|
2013-11-29 13:12:59 +04:00
|
|
|
|
|
|
|
if (dstSize < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
srcp += dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
/* LumaOrRedPlane */
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
dstSize = freerdp_bitmap_planar_decompress_plane_raw(srcp, width, height, dstData + 2, size - (srcp - srcData));
|
|
|
|
srcp += dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
/* OrangeChromaOrGreenPlane */
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
dstSize = freerdp_bitmap_planar_decompress_plane_raw(srcp, width, height, dstData + 1, size - (srcp - srcData));
|
|
|
|
srcp += dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
/* GreenChromeOrBluePlane */
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
dstSize = freerdp_bitmap_planar_decompress_plane_raw(srcp, width, height, dstData + 0, size - (srcp - srcData));
|
|
|
|
srcp += dstSize;
|
|
|
|
srcp++;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 13:12:59 +04:00
|
|
|
return (size == (srcp - srcData)) ? 0 : -1;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
int freerdp_split_color_planes(BYTE* data, UINT32 format, int width, int height, int scanline, BYTE* planes[4])
|
2013-11-26 03:58:01 +04:00
|
|
|
{
|
2013-11-26 07:26:08 +04:00
|
|
|
int bpp;
|
2013-11-26 03:58:01 +04:00
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
k = 0;
|
2013-11-26 07:26:08 +04:00
|
|
|
bpp = FREERDP_PIXEL_FORMAT_BPP(format);
|
|
|
|
|
|
|
|
if (bpp == 32)
|
2013-11-26 03:58:01 +04:00
|
|
|
{
|
2013-11-26 08:29:20 +04:00
|
|
|
UINT32* pixel;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2013-11-26 08:29:20 +04:00
|
|
|
for (i = height - 1; i >= 0; i--)
|
2013-11-26 03:58:01 +04:00
|
|
|
{
|
2013-11-26 08:29:20 +04:00
|
|
|
pixel = (UINT32*) &data[scanline * i];
|
|
|
|
|
2013-11-26 07:26:08 +04:00
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
2013-11-29 04:51:29 +04:00
|
|
|
GetARGB32(planes[0][k], planes[1][k], planes[2][k], planes[3][k], *pixel);
|
2013-11-26 08:29:20 +04:00
|
|
|
pixel++;
|
2013-11-26 07:26:08 +04:00
|
|
|
k++;
|
|
|
|
}
|
2013-11-26 03:58:01 +04:00
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
}
|
|
|
|
else if (bpp == 24)
|
|
|
|
{
|
2013-11-26 08:29:20 +04:00
|
|
|
UINT32* pixel;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2013-11-26 08:29:20 +04:00
|
|
|
for (i = height - 1; i >= 0; i--)
|
2013-11-26 07:26:08 +04:00
|
|
|
{
|
2013-11-26 08:29:20 +04:00
|
|
|
pixel = (UINT32*) &data[scanline * i];
|
|
|
|
|
2013-11-26 07:26:08 +04:00
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
2013-11-26 08:29:20 +04:00
|
|
|
GetRGB32(planes[1][k], planes[2][k], planes[3][k], *pixel);
|
|
|
|
planes[0][k] = 0xFF; /* A */
|
|
|
|
pixel++;
|
2013-11-26 07:26:08 +04:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2013-11-26 03:58:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
int freerdp_bitmap_planar_write_rle_bytes(BYTE* pInBuffer, int cRawBytes, int nRunLength, BYTE* pOutBuffer, int outBufferSize)
|
2013-11-27 00:16:40 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
BYTE* pInput;
|
|
|
|
BYTE* pOutput;
|
|
|
|
BYTE controlByte;
|
|
|
|
int nBytesToWrite;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
pInput = pInBuffer;
|
|
|
|
pOutput = pOutBuffer;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (!cRawBytes && !nRunLength)
|
|
|
|
return 0;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (nRunLength < 3)
|
|
|
|
{
|
|
|
|
cRawBytes += nRunLength;
|
|
|
|
nRunLength = 0;
|
2013-12-04 03:50:22 +04:00
|
|
|
}
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
while (cRawBytes)
|
2013-11-27 00:16:40 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
if (cRawBytes < 16)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
if (nRunLength > 15)
|
|
|
|
{
|
|
|
|
if (nRunLength < 18)
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(13, cRawBytes);
|
|
|
|
nRunLength -= 13;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(15, cRawBytes);
|
|
|
|
nRunLength -= 15;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(nRunLength, cRawBytes);
|
|
|
|
nRunLength = 0;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
2014-01-14 07:16:10 +04:00
|
|
|
else
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
controlByte = PLANAR_CONTROL_BYTE(0, 15);
|
|
|
|
cRawBytes -= 15;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (outBufferSize < 1)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
outBufferSize--;
|
2013-11-28 01:23:20 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
*pOutput = controlByte;
|
|
|
|
pOutput++;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nBytesToWrite = (int) (controlByte >> 4);
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (nBytesToWrite)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
if (outBufferSize < nBytesToWrite)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
outBufferSize -= nBytesToWrite;
|
|
|
|
CopyMemory(pOutput, pInput, nBytesToWrite);
|
|
|
|
pOutput += nBytesToWrite;
|
|
|
|
pInput += nBytesToWrite;
|
|
|
|
}
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
while (nRunLength)
|
|
|
|
{
|
|
|
|
if (nRunLength > 47)
|
|
|
|
{
|
|
|
|
if (nRunLength < 50)
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(2, 13);
|
|
|
|
nRunLength -= 45;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
2014-01-14 07:16:10 +04:00
|
|
|
else
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
controlByte = PLANAR_CONTROL_BYTE(2, 15);
|
|
|
|
nRunLength -= 47;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nRunLength > 31)
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(2, (nRunLength - 32));
|
|
|
|
nRunLength = 0;
|
|
|
|
}
|
|
|
|
else if (nRunLength > 15)
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(1, (nRunLength - 16));
|
|
|
|
nRunLength = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(nRunLength, 0);
|
|
|
|
nRunLength = 0;
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (outBufferSize < 1)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
--outBufferSize;
|
|
|
|
*pOutput = controlByte;
|
|
|
|
pOutput++;
|
|
|
|
}
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
return (pOutput - pOutBuffer);
|
|
|
|
}
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
int freerdp_bitmap_planar_encode_rle_bytes(BYTE* pInBuffer, int inBufferSize, BYTE* pOutBuffer, int outBufferSize)
|
|
|
|
{
|
|
|
|
BYTE symbol;
|
|
|
|
BYTE* pInput;
|
|
|
|
BYTE* pOutput;
|
|
|
|
BYTE* pBytes;
|
|
|
|
int cRawBytes;
|
|
|
|
int nRunLength;
|
|
|
|
int bSymbolMatch;
|
|
|
|
int nBytesWritten;
|
|
|
|
int nTotalBytesWritten;
|
2013-11-29 04:51:29 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
symbol = 0;
|
|
|
|
cRawBytes = 0;
|
|
|
|
nRunLength = 0;
|
|
|
|
pInput = pInBuffer;
|
|
|
|
pOutput = pOutBuffer;
|
|
|
|
nTotalBytesWritten = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (!outBufferSize)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!inBufferSize)
|
|
|
|
break;
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
bSymbolMatch = (symbol == *pInput) ? TRUE : FALSE;
|
|
|
|
symbol = *pInput;
|
|
|
|
pInput++;
|
|
|
|
inBufferSize--;
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (nRunLength && !bSymbolMatch)
|
|
|
|
{
|
|
|
|
if (nRunLength < 3)
|
|
|
|
{
|
|
|
|
cRawBytes += nRunLength;
|
|
|
|
nRunLength = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
else
|
2013-11-29 04:51:29 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
pBytes = pInput - (cRawBytes + nRunLength + 1);
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes,
|
|
|
|
cRawBytes, nRunLength, pOutput, outBufferSize);
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nRunLength = 0;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (!nBytesWritten || (nBytesWritten > outBufferSize))
|
|
|
|
return nRunLength;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nTotalBytesWritten += nBytesWritten;
|
|
|
|
outBufferSize -= nBytesWritten;
|
|
|
|
pOutput += nBytesWritten;
|
|
|
|
cRawBytes = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
}
|
2014-01-13 01:28:06 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nRunLength += bSymbolMatch;
|
|
|
|
cRawBytes += (!bSymbolMatch) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
while (outBufferSize);
|
2013-11-27 01:07:55 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (cRawBytes || nRunLength)
|
|
|
|
{
|
|
|
|
pBytes = pInput - (cRawBytes + nRunLength);
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes,
|
|
|
|
cRawBytes, nRunLength, pOutput, outBufferSize);
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (!nBytesWritten)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nTotalBytesWritten += nBytesWritten;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (inBufferSize)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return nTotalBytesWritten;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* inPlane, int width, int height, BYTE* outPlane, int* dstSize)
|
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
int index;
|
|
|
|
BYTE* pInput;
|
|
|
|
BYTE* pOutput;
|
|
|
|
int outBufferSize;
|
|
|
|
int nBytesWritten;
|
|
|
|
int nTotalBytesWritten;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
if (!outPlane)
|
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
outBufferSize = width * height;
|
|
|
|
outPlane = malloc(outBufferSize);
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
outBufferSize = *dstSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
index = 0;
|
|
|
|
pInput = inPlane;
|
|
|
|
pOutput = outPlane;
|
|
|
|
nTotalBytesWritten = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
while (outBufferSize)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
nBytesWritten = freerdp_bitmap_planar_encode_rle_bytes(pInput, width, pOutput, outBufferSize);
|
2013-12-04 03:50:22 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if ((!nBytesWritten) || (nBytesWritten > outBufferSize))
|
|
|
|
return NULL;
|
2013-11-29 13:12:59 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
outBufferSize -= nBytesWritten;
|
|
|
|
nTotalBytesWritten += nBytesWritten;
|
|
|
|
pOutput += nBytesWritten;
|
|
|
|
pInput += width;
|
|
|
|
index++;
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (index >= height)
|
|
|
|
break;
|
2013-11-27 01:07:55 +04:00
|
|
|
}
|
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
*dstSize = nTotalBytesWritten;
|
2013-11-27 01:07:55 +04:00
|
|
|
|
2013-11-27 03:04:29 +04:00
|
|
|
return outPlane;
|
|
|
|
}
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
int freerdp_bitmap_planar_compress_planes_rle(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes, int* dstSizes, BOOL skipAlpha)
|
2013-11-27 03:04:29 +04:00
|
|
|
{
|
2013-11-28 03:21:05 +04:00
|
|
|
int outPlanesSize = width * height * 4;
|
2013-11-28 01:23:20 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
/* AlphaPlane */
|
2013-11-28 01:23:20 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
if (skipAlpha)
|
|
|
|
{
|
|
|
|
dstSizes[0] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dstSizes[0] = outPlanesSize;
|
|
|
|
|
|
|
|
if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[0], width, height, outPlanes, &dstSizes[0]))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
outPlanes += dstSizes[0];
|
|
|
|
outPlanesSize -= dstSizes[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LumaOrRedPlane */
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2013-11-28 01:23:20 +04:00
|
|
|
dstSizes[1] = outPlanesSize;
|
|
|
|
|
|
|
|
if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[1], width, height, outPlanes, &dstSizes[1]))
|
2013-11-27 07:16:31 +04:00
|
|
|
return 0;
|
|
|
|
|
2013-11-28 01:23:20 +04:00
|
|
|
outPlanes += dstSizes[1];
|
|
|
|
outPlanesSize -= dstSizes[1];
|
2013-12-09 21:02:05 +04:00
|
|
|
|
|
|
|
/* OrangeChromaOrGreenPlane */
|
|
|
|
|
2013-11-28 01:23:20 +04:00
|
|
|
dstSizes[2] = outPlanesSize;
|
|
|
|
|
|
|
|
if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[2], width, height, outPlanes, &dstSizes[2]))
|
2013-11-27 07:16:31 +04:00
|
|
|
return 0;
|
|
|
|
|
2013-11-28 01:23:20 +04:00
|
|
|
outPlanes += dstSizes[2];
|
|
|
|
outPlanesSize -= dstSizes[2];
|
2013-12-09 21:02:05 +04:00
|
|
|
|
|
|
|
/* GreenChromeOrBluePlane */
|
|
|
|
|
2013-11-28 01:23:20 +04:00
|
|
|
dstSizes[3] = outPlanesSize;
|
|
|
|
|
|
|
|
if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[3], width, height, outPlanes, &dstSizes[3]))
|
2013-11-27 07:16:31 +04:00
|
|
|
return 0;
|
|
|
|
|
2013-11-28 01:23:20 +04:00
|
|
|
outPlanes += dstSizes[3];
|
|
|
|
outPlanesSize -= dstSizes[3];
|
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
return 1;
|
2013-11-27 03:04:29 +04:00
|
|
|
}
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int height, BYTE* outPlane)
|
2013-11-27 03:04:29 +04:00
|
|
|
{
|
|
|
|
char s2c;
|
|
|
|
int delta;
|
2014-01-14 12:44:38 +04:00
|
|
|
int y, x;
|
|
|
|
BYTE *outPtr, *srcPtr, *prevLinePtr;
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2013-11-27 03:04:29 +04:00
|
|
|
if (!outPlane)
|
|
|
|
outPlane = (BYTE*) malloc(width * height);
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2014-01-14 12:44:38 +04:00
|
|
|
// first line is copied as is
|
|
|
|
CopyMemory(outPlane, inPlane, width);
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2014-01-14 12:44:38 +04:00
|
|
|
outPtr = outPlane + width;
|
|
|
|
srcPtr = inPlane + width;
|
|
|
|
prevLinePtr = inPlane;
|
|
|
|
|
|
|
|
for (y = 1; y < height; y++)
|
2013-11-27 01:30:43 +04:00
|
|
|
{
|
2014-01-14 12:44:38 +04:00
|
|
|
for (x = 0; x < width; x++, outPtr++, srcPtr++, prevLinePtr++)
|
2013-11-27 01:30:43 +04:00
|
|
|
{
|
2014-01-14 12:44:38 +04:00
|
|
|
delta = *srcPtr - *prevLinePtr;
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2014-01-14 12:44:38 +04:00
|
|
|
s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (-delta)) + 1);
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2014-01-14 12:44:38 +04:00
|
|
|
s2c = (s2c >= 0) ? (s2c << 1) : (char) (((~((BYTE) s2c) + 1) << 1) - 1);
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2014-01-14 12:44:38 +04:00
|
|
|
*outPtr = (BYTE)s2c;
|
2013-11-27 01:30:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 03:04:29 +04:00
|
|
|
return outPlane;
|
|
|
|
}
|
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
int freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes[4])
|
2013-11-27 03:04:29 +04:00
|
|
|
{
|
2013-11-27 07:16:31 +04:00
|
|
|
freerdp_bitmap_planar_delta_encode_plane(inPlanes[0], width, height, outPlanes[0]);
|
|
|
|
freerdp_bitmap_planar_delta_encode_plane(inPlanes[1], width, height, outPlanes[1]);
|
|
|
|
freerdp_bitmap_planar_delta_encode_plane(inPlanes[2], width, height, outPlanes[2]);
|
|
|
|
freerdp_bitmap_planar_delta_encode_plane(inPlanes[3], width, height, outPlanes[3]);
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2013-11-27 01:07:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, UINT32 format,
|
|
|
|
int width, int height, int scanline, BYTE* dstData, int* dstSize)
|
2013-11-26 07:26:08 +04:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
BYTE* dstp;
|
|
|
|
int planeSize;
|
2013-11-28 01:23:20 +04:00
|
|
|
int dstSizes[4];
|
2013-11-27 03:04:29 +04:00
|
|
|
BYTE FormatHeader = 0;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
if (context->AllowSkipAlpha)
|
|
|
|
FormatHeader |= PLANAR_FORMAT_HEADER_NA;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2013-11-26 08:29:20 +04:00
|
|
|
planeSize = width * height;
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
freerdp_split_color_planes(data, format, width, height, scanline, context->planes);
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
if (context->AllowRunLengthEncoding)
|
2013-12-04 05:14:07 +04:00
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
freerdp_bitmap_planar_delta_encode_planes(context->planes, width, height, context->deltaPlanes);
|
2013-12-04 05:14:07 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
if (freerdp_bitmap_planar_compress_planes_rle(context->deltaPlanes, width, height,
|
|
|
|
context->rlePlanesBuffer, (int*) &dstSizes, context->AllowSkipAlpha) > 0)
|
2013-12-09 02:06:59 +04:00
|
|
|
{
|
|
|
|
int offset = 0;
|
2013-11-28 03:21:05 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
FormatHeader |= PLANAR_FORMAT_HEADER_RLE;
|
2013-11-27 07:16:31 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
context->rlePlanes[0] = &context->rlePlanesBuffer[offset];
|
|
|
|
offset += dstSizes[0];
|
2013-11-28 03:21:05 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
context->rlePlanes[1] = &context->rlePlanesBuffer[offset];
|
|
|
|
offset += dstSizes[1];
|
2013-11-28 03:21:05 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
context->rlePlanes[2] = &context->rlePlanesBuffer[offset];
|
|
|
|
offset += dstSizes[2];
|
2013-11-28 03:21:05 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
context->rlePlanes[3] = &context->rlePlanesBuffer[offset];
|
|
|
|
offset += dstSizes[3];
|
2013-11-28 01:23:20 +04:00
|
|
|
|
2013-12-20 11:41:25 +04:00
|
|
|
//printf("R: [%d/%d] G: [%d/%d] B: [%d/%d]\n",
|
|
|
|
// dstSizes[1], planeSize, dstSizes[2], planeSize, dstSizes[3], planeSize);
|
2013-12-09 02:06:59 +04:00
|
|
|
}
|
2013-11-27 07:16:31 +04:00
|
|
|
}
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2013-11-26 07:26:08 +04:00
|
|
|
if (!dstData)
|
|
|
|
{
|
2013-11-27 07:16:31 +04:00
|
|
|
size = 1;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
|
2013-11-27 07:16:31 +04:00
|
|
|
{
|
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
size += dstSizes[0];
|
|
|
|
else
|
|
|
|
size += planeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
size += (dstSizes[1] + dstSizes[2] + dstSizes[3]);
|
|
|
|
else
|
|
|
|
size += (planeSize * 3);
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_RLE))
|
|
|
|
size++;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
dstData = malloc(size);
|
|
|
|
*dstSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
dstp = dstData;
|
|
|
|
|
|
|
|
*dstp = FormatHeader; /* FormatHeader */
|
|
|
|
dstp++;
|
|
|
|
|
|
|
|
/* AlphaPlane */
|
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
|
|
|
|
{
|
2013-11-27 07:16:31 +04:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->rlePlanes[0], dstSizes[0]); /* Alpha */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += dstSizes[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->planes[0], planeSize); /* Alpha */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += planeSize;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* LumaOrRedPlane */
|
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->rlePlanes[1], dstSizes[1]); /* Red */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += dstSizes[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->planes[1], planeSize); /* Red */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += planeSize;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
/* OrangeChromaOrGreenPlane */
|
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->rlePlanes[2], dstSizes[2]); /* Green */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += dstSizes[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->planes[2], planeSize); /* Green */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += planeSize;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
/* GreenChromeOrBluePlane */
|
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->rlePlanes[3], dstSizes[3]); /* Blue */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += dstSizes[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->planes[3], planeSize); /* Blue */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += planeSize;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
/* Pad1 (1 byte) */
|
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_RLE))
|
|
|
|
{
|
|
|
|
*dstp = 0;
|
|
|
|
dstp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = (dstp - dstData);
|
|
|
|
*dstSize = size;
|
|
|
|
|
|
|
|
return dstData;
|
|
|
|
}
|
2013-12-09 02:06:59 +04:00
|
|
|
|
|
|
|
BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, int maxWidth, int maxHeight)
|
|
|
|
{
|
|
|
|
BITMAP_PLANAR_CONTEXT* context;
|
|
|
|
|
|
|
|
context = (BITMAP_PLANAR_CONTEXT*) malloc(sizeof(BITMAP_PLANAR_CONTEXT));
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ZeroMemory(context, sizeof(BITMAP_PLANAR_CONTEXT));
|
|
|
|
|
|
|
|
if (flags & PLANAR_FORMAT_HEADER_NA)
|
|
|
|
context->AllowSkipAlpha = TRUE;
|
|
|
|
|
|
|
|
if (flags & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
context->AllowRunLengthEncoding = TRUE;
|
|
|
|
|
|
|
|
if (flags & PLANAR_FORMAT_HEADER_CS)
|
|
|
|
context->AllowColorSubsampling = TRUE;
|
|
|
|
|
|
|
|
context->ColorLossLevel = flags & PLANAR_FORMAT_HEADER_CLL_MASK;
|
|
|
|
|
|
|
|
if (context->ColorLossLevel)
|
|
|
|
context->AllowDynamicColorFidelity = TRUE;
|
|
|
|
|
|
|
|
context->maxWidth = maxWidth;
|
|
|
|
context->maxHeight = maxHeight;
|
|
|
|
context->maxPlaneSize = context->maxWidth * context->maxHeight;
|
|
|
|
|
|
|
|
context->planesBuffer = malloc(context->maxPlaneSize * 4);
|
|
|
|
context->planes[0] = &context->planesBuffer[context->maxPlaneSize * 0];
|
|
|
|
context->planes[1] = &context->planesBuffer[context->maxPlaneSize * 1];
|
|
|
|
context->planes[2] = &context->planesBuffer[context->maxPlaneSize * 2];
|
|
|
|
context->planes[3] = &context->planesBuffer[context->maxPlaneSize * 3];
|
|
|
|
|
|
|
|
context->deltaPlanesBuffer = malloc(context->maxPlaneSize * 4);
|
|
|
|
context->deltaPlanes[0] = &context->deltaPlanesBuffer[context->maxPlaneSize * 0];
|
|
|
|
context->deltaPlanes[1] = &context->deltaPlanesBuffer[context->maxPlaneSize * 1];
|
|
|
|
context->deltaPlanes[2] = &context->deltaPlanesBuffer[context->maxPlaneSize * 2];
|
|
|
|
context->deltaPlanes[3] = &context->deltaPlanesBuffer[context->maxPlaneSize * 3];
|
|
|
|
|
|
|
|
context->rlePlanesBuffer = malloc(context->maxPlaneSize * 4);
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context)
|
|
|
|
{
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free(context->planesBuffer);
|
|
|
|
free(context->deltaPlanesBuffer);
|
|
|
|
free(context->rlePlanesBuffer);
|
|
|
|
|
|
|
|
free(context);
|
|
|
|
}
|