From c1a6eda7405e1533ab7bba2fabf00b277ae7013c Mon Sep 17 00:00:00 2001 From: Hardening Date: Tue, 14 Jan 2014 09:44:38 +0100 Subject: [PATCH] Improve performance for delta_encoder This patch inline the case of the first line to drop the if() that was done at each loop. Some variable have been renamed for code clarity. --- libfreerdp/codec/planar.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c index bc0b71118..a320da5a3 100644 --- a/libfreerdp/codec/planar.c +++ b/libfreerdp/codec/planar.c @@ -618,41 +618,31 @@ int freerdp_bitmap_planar_compress_planes_rle(BYTE* inPlanes[4], int width, int BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int height, BYTE* outPlane) { char s2c; - BYTE u2c; int delta; - int i, j, k; + int y, x; + BYTE *outPtr, *srcPtr, *prevLinePtr; if (!outPlane) - { outPlane = (BYTE*) malloc(width * height); - } - k = 0; + // first line is copied as is + CopyMemory(outPlane, inPlane, width); - for (i = 0; i < height; i++) + outPtr = outPlane + width; + srcPtr = inPlane + width; + prevLinePtr = inPlane; + + for (y = 1; y < height; y++) { - for (j = 0; j < width; j++) + for (x = 0; x < width; x++, outPtr++, srcPtr++, prevLinePtr++) { - if (i < 1) - { - delta = inPlane[j]; + delta = *srcPtr - *prevLinePtr; - s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (delta * -1)) + 1); - } - else - { - delta = inPlane[(i * width) + j] - inPlane[((i - 1) * width) + j]; + s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (-delta)) + 1); - s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (delta * -1)) + 1); + s2c = (s2c >= 0) ? (s2c << 1) : (char) (((~((BYTE) s2c) + 1) << 1) - 1); - s2c = (s2c >= 0) ? (s2c << 1) : (char) (((~((BYTE) s2c) + 1) << 1) - 1); - } - - u2c = (BYTE) s2c; - - outPlane[(i * width) + j] = u2c; - - k++; + *outPtr = (BYTE)s2c; } }