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-26 07:26:08 +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-26 08:29:20 +04:00
|
|
|
GetARGB32(planes[0][k], planes[0][k], planes[2][k], planes[3][k], *pixel);
|
|
|
|
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-27 00:16:40 +04:00
|
|
|
int freerdp_bitmap_compress_planar_rle_plane_scanline(BYTE* plane, int size)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
BYTE symbol;
|
|
|
|
int nRunLength;
|
|
|
|
int cRawBytes;
|
|
|
|
BYTE* rawValues;
|
|
|
|
int nSequenceLength;
|
|
|
|
|
|
|
|
cRawBytes = 0;
|
|
|
|
nRunLength = 0;
|
|
|
|
rawValues = plane;
|
|
|
|
|
|
|
|
nSequenceLength = 0;
|
|
|
|
|
|
|
|
for (i = 0; i <= size; i++)
|
|
|
|
{
|
|
|
|
if ((!nSequenceLength) && (i != size))
|
|
|
|
{
|
|
|
|
symbol = plane[i];
|
|
|
|
nSequenceLength = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((i != size) && (plane[i] == symbol))
|
|
|
|
{
|
|
|
|
nSequenceLength++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nSequenceLength > 3)
|
|
|
|
{
|
|
|
|
cRawBytes += 1;
|
|
|
|
nRunLength = nSequenceLength - 1;
|
|
|
|
|
|
|
|
printf("RAW[");
|
|
|
|
|
|
|
|
for (j = 0; j < cRawBytes; j++)
|
|
|
|
printf("%c", rawValues[j]);
|
|
|
|
|
|
|
|
printf("] RUN[%d]\n", nRunLength);
|
|
|
|
|
|
|
|
rawValues = &plane[i];
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cRawBytes += nSequenceLength;
|
|
|
|
|
|
|
|
if (i == size)
|
|
|
|
{
|
|
|
|
nRunLength = 0;
|
|
|
|
|
|
|
|
printf("RAW[");
|
|
|
|
|
|
|
|
for (j = 0; j < cRawBytes; j++)
|
|
|
|
printf("%c", rawValues[j]);
|
|
|
|
|
|
|
|
printf("] RUN[%d]\n", nRunLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != size)
|
|
|
|
{
|
|
|
|
symbol = plane[i];
|
|
|
|
nSequenceLength = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-27 01:07:55 +04:00
|
|
|
int freerdp_bitmap_planar_delta_encode_scanlines(BYTE* plane, int width, int height)
|
|
|
|
{
|
|
|
|
char s2c;
|
|
|
|
int delta;
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
printf("{ ");
|
|
|
|
|
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
|
|
|
printf("%4d%s", plane[k],
|
|
|
|
(j + 1 == width) ? " }\n" : ", ");
|
|
|
|
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
printf("{ ");
|
|
|
|
|
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
|
|
|
if (i < 1)
|
|
|
|
{
|
|
|
|
delta = plane[j];
|
|
|
|
|
|
|
|
printf("%4d%s", delta,
|
|
|
|
(j + 1 == width) ? " }\n" : ", ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delta = plane[(i * width) + j] - plane[((i - 1) * width) + j];
|
|
|
|
|
|
|
|
printf("%4d%s", (int) delta,
|
|
|
|
(j + 1 == width) ? " }\n" : ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
printf("{ ");
|
|
|
|
|
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
|
|
|
if (i < 1)
|
|
|
|
{
|
|
|
|
delta = plane[j];
|
|
|
|
|
|
|
|
s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (delta * -1)) + 1);
|
|
|
|
|
|
|
|
printf("%4d%s", s2c,
|
|
|
|
(j + 1 == width) ? " }\n" : ", ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delta = plane[(i * width) + j] - plane[((i - 1) * width) + j];
|
|
|
|
|
|
|
|
s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (delta * -1)) + 1);
|
|
|
|
|
|
|
|
printf("%4d%s", s2c,
|
|
|
|
(j + 1 == width) ? " }\n" : ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-26 07:26:08 +04:00
|
|
|
BYTE* freerdp_bitmap_compress_planar(BYTE* data, UINT32 format, int width, int height, int scanline, BYTE* dstData, int* dstSize)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
BYTE* dstp;
|
|
|
|
int planeSize;
|
|
|
|
BYTE* planes[4];
|
|
|
|
BYTE FormatHeader;
|
|
|
|
BYTE* planesBuffer;
|
|
|
|
|
|
|
|
FormatHeader = 0;
|
|
|
|
FormatHeader |= PLANAR_FORMAT_HEADER_NA;
|
|
|
|
|
2013-11-26 08:29:20 +04:00
|
|
|
planeSize = width * height;
|
2013-11-26 07:26:08 +04:00
|
|
|
planesBuffer = malloc(planeSize * 4);
|
|
|
|
planes[0] = &planesBuffer[planeSize * 0];
|
|
|
|
planes[1] = &planesBuffer[planeSize * 1];
|
|
|
|
planes[2] = &planesBuffer[planeSize * 2];
|
|
|
|
planes[3] = &planesBuffer[planeSize * 3];
|
|
|
|
|
|
|
|
freerdp_split_color_planes(data, format, width, height, scanline, planes);
|
|
|
|
|
|
|
|
if (!dstData)
|
|
|
|
{
|
|
|
|
size = 2;
|
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
|
|
|
|
size += planeSize;
|
|
|
|
|
|
|
|
size += (planeSize * 3);
|
|
|
|
|
|
|
|
dstData = malloc(size);
|
|
|
|
*dstSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
dstp = dstData;
|
|
|
|
|
|
|
|
*dstp = FormatHeader; /* FormatHeader */
|
|
|
|
dstp++;
|
|
|
|
|
|
|
|
/* AlphaPlane */
|
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
|
|
|
|
{
|
|
|
|
CopyMemory(dstp, planes[0], planeSize); /* Alpha */
|
|
|
|
dstp += planeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LumaOrRedPlane */
|
|
|
|
|
|
|
|
CopyMemory(dstp, planes[1], planeSize); /* Red */
|
|
|
|
dstp += planeSize;
|
|
|
|
|
|
|
|
/* OrangeChromaOrGreenPlane */
|
|
|
|
|
|
|
|
CopyMemory(dstp, planes[2], planeSize); /* Green */
|
|
|
|
dstp += planeSize;
|
|
|
|
|
|
|
|
/* GreenChromeOrBluePlane */
|
|
|
|
|
|
|
|
CopyMemory(dstp, planes[3], planeSize); /* Blue */
|
|
|
|
dstp += planeSize;
|
|
|
|
|
|
|
|
/* Pad1 (1 byte) */
|
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_RLE))
|
|
|
|
{
|
|
|
|
*dstp = 0;
|
|
|
|
dstp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = (dstp - dstData);
|
|
|
|
*dstSize = size;
|
|
|
|
|
|
|
|
free(planesBuffer);
|
|
|
|
|
|
|
|
return dstData;
|
|
|
|
}
|