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
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
struct _PLANAR_RLE_CONTEXT
|
2013-11-27 00:16:40 +04:00
|
|
|
{
|
2013-11-29 11:16:16 +04:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
BYTE* output;
|
2013-11-27 00:16:40 +04:00
|
|
|
int nRunLength;
|
|
|
|
int cRawBytes;
|
|
|
|
BYTE* rawValues;
|
2013-11-29 00:49:22 +04:00
|
|
|
BYTE* rawScanline;
|
2013-11-29 11:16:16 +04:00
|
|
|
BYTE* outPlane;
|
2013-11-27 03:04:29 +04:00
|
|
|
int outPlaneSize;
|
2013-11-27 07:16:31 +04:00
|
|
|
int outSegmentSize;
|
2013-11-29 11:16:16 +04:00
|
|
|
};
|
|
|
|
typedef struct _PLANAR_RLE_CONTEXT PLANAR_RLE_CONTEXT;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2013-12-04 03:50:22 +04:00
|
|
|
int freerdp_bitmap_planar_compress_plane_rle_segment(PLANAR_RLE_CONTEXT* rle)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-12-04 03:50:22 +04:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
int k;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-04 03:50:22 +04:00
|
|
|
printf("RAW[");
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-04 03:50:22 +04:00
|
|
|
for (k = 0; k < rle->cRawBytes; k++)
|
|
|
|
{
|
|
|
|
printf("0x%02X%s", rle->rawValues[k],
|
|
|
|
((k + 1) == rle->cRawBytes) ? "" : ", ");
|
|
|
|
}
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2013-12-04 03:50:22 +04:00
|
|
|
printf("] RUN[%d]\n", rle->nRunLength);
|
|
|
|
}
|
|
|
|
#endif
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
while ((rle->cRawBytes != 0) || (rle->nRunLength != 0))
|
2013-11-27 00:16:40 +04:00
|
|
|
{
|
2013-12-04 03:50:22 +04:00
|
|
|
//printf("|| cRawBytes: %d nRunLength: %d\n", rle->cRawBytes, rle->nRunLength);
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
if (rle->nRunLength < 3)
|
|
|
|
{
|
|
|
|
rle->cRawBytes += rle->nRunLength;
|
|
|
|
rle->nRunLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rle->rawValues - rle->rawScanline) > rle->width)
|
|
|
|
{
|
|
|
|
printf("rawValues overflow! %d\n", rle->rawValues - rle->rawScanline);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
if (rle->cRawBytes > 15)
|
2013-11-27 00:16:40 +04:00
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
rle->outSegmentSize = 1 + 15;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
if (((rle->output - rle->outPlane) + rle->outSegmentSize) > rle->outPlaneSize)
|
2013-11-27 23:46:38 +04:00
|
|
|
{
|
2013-11-29 11:16:16 +04:00
|
|
|
printf("overflow: %d > %d\n", ((rle->output - rle->outPlane) + rle->outSegmentSize), rle->outPlaneSize);
|
|
|
|
return -1;
|
2013-11-27 00:16:40 +04:00
|
|
|
}
|
2013-11-28 01:23:20 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
*rle->output = PLANAR_CONTROL_BYTE(0, 15);
|
|
|
|
rle->output++;
|
|
|
|
|
|
|
|
CopyMemory(rle->output, rle->rawValues, 15);
|
|
|
|
rle->cRawBytes -= 15;
|
|
|
|
rle->rawValues += 15;
|
|
|
|
rle->output += 15;
|
|
|
|
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
else if (rle->cRawBytes == 0)
|
|
|
|
{
|
|
|
|
if (rle->nRunLength > 47)
|
2013-11-27 00:16:40 +04:00
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
rle->outSegmentSize = 1;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
if (((rle->output - rle->outPlane) + rle->outSegmentSize) > rle->outPlaneSize)
|
2013-11-29 04:51:29 +04:00
|
|
|
{
|
2013-11-29 11:16:16 +04:00
|
|
|
printf("overflow: %d > %d\n", ((rle->output - rle->outPlane) + rle->outSegmentSize), rle->outPlaneSize);
|
|
|
|
return -1;
|
2013-11-29 04:51:29 +04:00
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
*rle->output = PLANAR_CONTROL_BYTE(2, 15);
|
|
|
|
rle->nRunLength -= 47;
|
|
|
|
rle->output++;
|
|
|
|
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
else if (rle->nRunLength > 31)
|
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
rle->outSegmentSize = 1;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
if (((rle->output - rle->outPlane) + rle->outSegmentSize) > rle->outPlaneSize)
|
2013-11-29 04:51:29 +04:00
|
|
|
{
|
2013-11-29 11:16:16 +04:00
|
|
|
printf("overflow: %d > %d\n", ((rle->output - rle->outPlane) + rle->outSegmentSize), rle->outPlaneSize);
|
|
|
|
return -1;
|
2013-11-29 04:51:29 +04:00
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
*rle->output = PLANAR_CONTROL_BYTE(2, (rle->nRunLength - 32));
|
|
|
|
rle->nRunLength -= 32;
|
|
|
|
rle->output++;
|
|
|
|
|
|
|
|
return 0; /* finish */
|
2013-11-29 04:51:29 +04:00
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
else if (rle->nRunLength > 15)
|
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
rle->outSegmentSize = 1;
|
2013-11-29 04:51:29 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
if (((rle->output - rle->outPlane) + rle->outSegmentSize) > rle->outPlaneSize)
|
|
|
|
{
|
|
|
|
printf("overflow: %d > %d\n", ((rle->output - rle->outPlane) + rle->outSegmentSize), rle->outPlaneSize);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rle->output = PLANAR_CONTROL_BYTE(1, (rle->nRunLength - 16));
|
|
|
|
rle->nRunLength -= 16;
|
|
|
|
rle->output++;
|
|
|
|
|
|
|
|
return 0; /* finish */
|
|
|
|
}
|
|
|
|
else
|
2013-11-29 04:51:29 +04:00
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
rle->outSegmentSize = 1 + rle->cRawBytes;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
if (((rle->output - rle->outPlane) + rle->outSegmentSize) > rle->outPlaneSize)
|
|
|
|
{
|
|
|
|
printf("overflow: %d > %d\n", ((rle->output - rle->outPlane) + rle->outSegmentSize), rle->outPlaneSize);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
*rle->output = PLANAR_CONTROL_BYTE(rle->nRunLength, rle->cRawBytes);
|
|
|
|
rle->output++;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2013-12-09 08:17:24 +04:00
|
|
|
CopyMemory(rle->output, rle->rawValues, rle->cRawBytes);
|
|
|
|
rle->rawValues += (rle->cRawBytes + rle->nRunLength);
|
|
|
|
rle->output += rle->cRawBytes;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
rle->cRawBytes = 0;
|
|
|
|
rle->nRunLength = 0;
|
|
|
|
|
|
|
|
return 0; /* finish */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rle->cRawBytes < 16)
|
|
|
|
{
|
|
|
|
if (rle->nRunLength > 15)
|
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
rle->outSegmentSize = 1 + rle->cRawBytes;
|
2013-11-27 01:07:55 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
if (((rle->output - rle->outPlane) + rle->outSegmentSize) > rle->outPlaneSize)
|
2013-11-29 04:51:29 +04:00
|
|
|
{
|
2013-11-29 11:16:16 +04:00
|
|
|
printf("overflow: %d > %d\n", ((rle->output - rle->outPlane) + rle->outSegmentSize), rle->outPlaneSize);
|
|
|
|
return -1;
|
2013-11-29 04:51:29 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
*rle->output = PLANAR_CONTROL_BYTE(15, rle->cRawBytes);
|
|
|
|
rle->output++;
|
|
|
|
|
2013-12-09 08:17:24 +04:00
|
|
|
CopyMemory(rle->output, rle->rawValues, rle->cRawBytes);
|
|
|
|
rle->rawValues += (rle->cRawBytes + 15);
|
|
|
|
rle->output += rle->cRawBytes;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
rle->nRunLength -= 15;
|
|
|
|
rle->cRawBytes = 0;
|
2013-11-27 01:07:55 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 21:02:05 +04:00
|
|
|
rle->outSegmentSize = 1 + rle->cRawBytes;
|
2013-11-27 23:46:38 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
if (((rle->output - rle->outPlane) + rle->outSegmentSize) > rle->outPlaneSize)
|
|
|
|
{
|
|
|
|
printf("overflow: %d > %d\n", ((rle->output - rle->outPlane) + rle->outSegmentSize), rle->outPlaneSize);
|
|
|
|
return -1;
|
2013-11-28 01:23:20 +04:00
|
|
|
}
|
2013-11-27 01:07:55 +04:00
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
*rle->output = PLANAR_CONTROL_BYTE(rle->nRunLength, rle->cRawBytes);
|
|
|
|
rle->output++;
|
|
|
|
|
2013-12-09 08:17:24 +04:00
|
|
|
CopyMemory(rle->output, rle->rawValues, rle->cRawBytes);
|
|
|
|
rle->rawValues += (rle->cRawBytes + rle->nRunLength);
|
|
|
|
rle->output += rle->cRawBytes;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
rle->cRawBytes = 0;
|
|
|
|
rle->nRunLength = 0;
|
|
|
|
|
|
|
|
return 0; /* finish */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* inPlane, int width, int height, BYTE* outPlane, int* dstSize)
|
|
|
|
{
|
|
|
|
int i, j;
|
2013-12-04 03:50:22 +04:00
|
|
|
int bSymbolMatch;
|
|
|
|
int bSequenceEnd;
|
2013-11-29 11:16:16 +04:00
|
|
|
PLANAR_RLE_CONTEXT rle_s;
|
|
|
|
PLANAR_RLE_CONTEXT* rle = &rle_s;
|
|
|
|
|
|
|
|
if (!outPlane)
|
|
|
|
{
|
|
|
|
rle->outPlaneSize = width * height * 2;
|
|
|
|
outPlane = malloc(rle->outPlaneSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rle->outPlaneSize = *dstSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
rle->output = outPlane;
|
|
|
|
rle->outPlane = outPlane;
|
|
|
|
rle->width = width;
|
|
|
|
rle->height = height;
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
rle->nRunLength = 0;
|
2013-12-04 03:50:22 +04:00
|
|
|
rle->cRawBytes = 1;
|
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
rle->rawScanline = &inPlane[i * width];
|
|
|
|
rle->rawValues = rle->rawScanline;
|
|
|
|
|
2013-12-09 08:17:24 +04:00
|
|
|
//winpr_HexDump(rle->rawScanline, width);
|
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
for (j = 1; j < width; j++)
|
|
|
|
{
|
2013-12-04 03:50:22 +04:00
|
|
|
bSymbolMatch = FALSE;
|
|
|
|
bSequenceEnd = ((j + 1) == width) ? TRUE : FALSE;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
if (rle->rawScanline[j] == rle->rawValues[rle->cRawBytes - 1])
|
2013-12-04 03:50:22 +04:00
|
|
|
{
|
|
|
|
bSymbolMatch = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//printf("mismatch: nRunLength: %d cRawBytes: %d\n", rle->nRunLength, rle->cRawBytes);
|
|
|
|
|
|
|
|
if (bSequenceEnd)
|
|
|
|
rle->cRawBytes++;
|
|
|
|
|
|
|
|
if (rle->nRunLength < 3)
|
|
|
|
{
|
|
|
|
rle->cRawBytes += rle->nRunLength;
|
|
|
|
rle->nRunLength = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bSequenceEnd = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bSymbolMatch)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
|
|
|
rle->nRunLength++;
|
2013-11-28 01:23:20 +04:00
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-04 03:50:22 +04:00
|
|
|
//printf("j: %d [0x%02X] cRawBytes: %d nRunLength: %d bSymbolMatch: %d bSequenceEnd: %d\n",
|
|
|
|
// j, rle->rawScanline[j], rle->cRawBytes, rle->nRunLength, bSymbolMatch, bSequenceEnd);
|
2013-11-29 13:12:59 +04:00
|
|
|
|
2013-12-04 03:50:22 +04:00
|
|
|
if (bSequenceEnd)
|
|
|
|
{
|
|
|
|
if (rle->nRunLength < 3)
|
|
|
|
{
|
|
|
|
rle->cRawBytes += rle->nRunLength;
|
|
|
|
rle->nRunLength = 0;
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-04 03:50:22 +04:00
|
|
|
if (freerdp_bitmap_planar_compress_plane_rle_segment(rle) < 0)
|
|
|
|
return NULL;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-12-04 03:50:22 +04:00
|
|
|
rle->nRunLength = 0;
|
|
|
|
rle->cRawBytes = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!bSymbolMatch)
|
|
|
|
{
|
|
|
|
rle->cRawBytes++;
|
|
|
|
}
|
|
|
|
}
|
2013-11-27 01:07:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-29 11:16:16 +04:00
|
|
|
*dstSize = (rle->output - outPlane);
|
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;
|
|
|
|
BYTE u2c;
|
|
|
|
int delta;
|
|
|
|
int i, j, k;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
|
|
|
if (i < 1)
|
|
|
|
{
|
2013-11-27 03:04:29 +04:00
|
|
|
delta = inPlane[j];
|
2013-11-27 01:30:43 +04:00
|
|
|
|
|
|
|
s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (delta * -1)) + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-27 03:04:29 +04:00
|
|
|
delta = inPlane[(i * width) + j] - inPlane[((i - 1) * width) + j];
|
2013-11-27 01:30:43 +04:00
|
|
|
|
|
|
|
s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (delta * -1)) + 1);
|
|
|
|
|
|
|
|
s2c = (s2c >= 0) ? (s2c << 1) : (char) (((~((BYTE) s2c) + 1) << 1) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
u2c = (BYTE) s2c;
|
|
|
|
|
2013-11-27 03:04:29 +04:00
|
|
|
outPlane[(i * width) + j] = u2c;
|
2013-11-27 01:30:43 +04:00
|
|
|
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09 02:06:59 +04:00
|
|
|
printf("R: [%d/%d] G: [%d/%d] B: [%d/%d]\n",
|
|
|
|
dstSizes[1], planeSize, dstSizes[2], planeSize, dstSizes[3], planeSize);
|
|
|
|
}
|
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);
|
|
|
|
}
|