libfreerdp-codec: implement planar codec RLE scanline encoding
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Tue, 26 Nov 2013 20:16:40 +0000 (15:16 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Tue, 26 Nov 2013 20:16:40 +0000 (15:16 -0500)
libfreerdp/codec/planar.c
libfreerdp/codec/planar.h
libfreerdp/codec/test/TestFreeRDPCodecPlanar.c

index 1bf9f62..bf2985e 100644 (file)
@@ -73,6 +73,80 @@ int freerdp_split_color_planes(BYTE* data, UINT32 format, int width, int height,
        return 0;
 }
 
+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;
+}
+
 BYTE* freerdp_bitmap_compress_planar(BYTE* data, UINT32 format, int width, int height, int scanline, BYTE* dstData, int* dstSize)
 {
        int size;
index cc4a378..7d6f1bf 100644 (file)
@@ -62,5 +62,6 @@ struct _RDP6_BITMAP_STREAM
 typedef struct _RDP6_BITMAP_STREAM RDP6_BITMAP_STREAM;
 
 int freerdp_split_color_planes(BYTE* data, UINT32 format, int width, int height, int scanline, BYTE* planes[4]);
+int freerdp_bitmap_compress_planar_rle_plane_scanline(BYTE* plane, int size);
 
 #endif /* FREERDP_CODEC_PLANAR_PRIVATE_H */
index abda7e6..0e28b10 100644 (file)
@@ -157,6 +157,11 @@ const BYTE TEST_RLE_COMPRESSED_BITMAP[220] =
        "\xC3\x80\x61\x00\x00\x00\x00\x00\xCC\x89\x52\x03\x6E\xFF\xFF\x02"
        "\xCB\x18\xC6\x84\x08\x42\x08\x42\x08\x42\xFF\xFF";
 
+const BYTE TEST_RLE_SCANLINE_UNCOMPRESSED[12] =
+       "AAAABBCCCCCD";
+
+#include "../planar.h"
+
 int TestFreeRDPCodecPlanar(int argc, char* argv[])
 {
        int dstSize;
@@ -174,6 +179,8 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
 
        freerdp_bitmap_compress_planar(srcBitmap32, format, 32, 32, 32 * 4, NULL, &dstSize);
 
+       freerdp_bitmap_compress_planar_rle_plane_scanline((BYTE*) TEST_RLE_SCANLINE_UNCOMPRESSED, 12);
+
        freerdp_clrconv_free(clrconv);
        free(srcBitmap32);