Skip to content

Commit

Permalink
Simplificiations
Browse files Browse the repository at this point in the history
  • Loading branch information
Nexarian committed Mar 27, 2023
1 parent 2076183 commit 72143c3
Showing 1 changed file with 53 additions and 67 deletions.
120 changes: 53 additions & 67 deletions module/rdpCapture.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ capture
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

/* this should be before all X11 .h files */
#include <xorg-server.h>
Expand Down Expand Up @@ -58,6 +59,11 @@ capture
#define LLOGLN(_level, _args) \
do { if (_level < LOG_LEVEL) { ErrorF _args ; ErrorF("\n"); } } while (0)

#define RGB_SPLIT(R, G, B, pixel) \
R = (pixel >> 16) & UCHAR_MAX; \
G = (pixel >> 8) & UCHAR_MAX; \
B = (pixel >> 0) & UCHAR_MAX;

/******************************************************************************/
/* copy rects with no error checking */
static int
Expand Down Expand Up @@ -166,18 +172,18 @@ rdpCopyBox_a8r8g8b8_to_yuvalp(int ax, int ay,
while (kndex < width)
{
pixel = *(s32++);
a = (pixel >> 24) & 0xff;
r = (pixel >> 16) & 0xff;
g = (pixel >> 8) & 0xff;
b = (pixel >> 0) & 0xff;
a = (pixel >> 24) & UCHAR_MAX;
r = (pixel >> 16) & UCHAR_MAX;
g = (pixel >> 8) & UCHAR_MAX;
b = (pixel >> 0) & UCHAR_MAX;
y = (r * 19595 + g * 38470 + b * 7471) >> 16;
u = (r * -11071 + g * -21736 + b * 32807) >> 16;
v = (r * 32756 + g * -27429 + b * -5327) >> 16;
u = u + 128;
v = v + 128;
y = RDPCLAMP(y, 0, 255);
u = RDPCLAMP(u, 0, 255);
v = RDPCLAMP(v, 0, 255);
y = RDPCLAMP(y, 0, UCHAR_MAX);
u = RDPCLAMP(u, 0, UCHAR_MAX);
v = RDPCLAMP(v, 0, UCHAR_MAX);
*(yptr++) = y;
*(uptr++) = u;
*(vptr++) = v;
Expand Down Expand Up @@ -477,55 +483,47 @@ a8r8g8b8_to_nv12_box(const uint8_t *s8, int src_stride,

pixel = s32a[0];
s32a++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = (( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
d8ya[0] = RDPCLAMP(Y, 0, 255);
d8ya[0] = RDPCLAMP(Y, 0, UCHAR_MAX);
d8ya++;
U_sum += RDPCLAMP(U, 0, 255);
V_sum += RDPCLAMP(V, 0, 255);
U_sum += RDPCLAMP(U, 0, UCHAR_MAX);
V_sum += RDPCLAMP(V, 0, UCHAR_MAX);

pixel = s32a[0];
s32a++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = (( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
d8ya[0] = RDPCLAMP(Y, 0, 255);
d8ya[0] = RDPCLAMP(Y, 0, UCHAR_MAX);
d8ya++;
U_sum += RDPCLAMP(U, 0, 255);
V_sum += RDPCLAMP(V, 0, 255);
U_sum += RDPCLAMP(U, 0, UCHAR_MAX);
V_sum += RDPCLAMP(V, 0, UCHAR_MAX);

pixel = s32b[0];
s32b++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = (( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
d8yb[0] = RDPCLAMP(Y, 0, 255);
d8yb[0] = RDPCLAMP(Y, 0, UCHAR_MAX);
d8yb++;
U_sum += RDPCLAMP(U, 0, 255);
V_sum += RDPCLAMP(V, 0, 255);
U_sum += RDPCLAMP(U, 0, UCHAR_MAX);
V_sum += RDPCLAMP(V, 0, UCHAR_MAX);

pixel = s32b[0];
s32b++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = (( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
d8yb[0] = RDPCLAMP(Y, 0, 255);
d8yb[0] = RDPCLAMP(Y, 0, UCHAR_MAX);
d8yb++;
U_sum += RDPCLAMP(U, 0, 255);
V_sum += RDPCLAMP(V, 0, 255);
U_sum += RDPCLAMP(U, 0, UCHAR_MAX);
V_sum += RDPCLAMP(V, 0, UCHAR_MAX);

d8uv[0] = (U_sum + 2) / 4;
d8uv++;
Expand Down Expand Up @@ -574,55 +572,47 @@ a8r8g8b8_to_nv12_709fr_box(const uint8_t *s8, int src_stride,

pixel = s32a[0];
s32a++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = ( 54 * R + 183 * G + 18 * B) >> 8;
U = ((-29 * R - 99 * G + 128 * B) >> 8) + 128;
V = ((128 * R - 116 * G - 12 * B) >> 8) + 128;
d8ya[0] = RDPCLAMP(Y, 0, 255);
d8ya[0] = RDPCLAMP(Y, 0, UCHAR_MAX);
d8ya++;
U_sum += RDPCLAMP(U, 0, 255);
V_sum += RDPCLAMP(V, 0, 255);
U_sum += RDPCLAMP(U, 0, UCHAR_MAX);
V_sum += RDPCLAMP(V, 0, UCHAR_MAX);

pixel = s32a[0];
s32a++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = ( 54 * R + 183 * G + 18 * B) >> 8;
U = ((-29 * R - 99 * G + 128 * B) >> 8) + 128;
V = ((128 * R - 116 * G - 12 * B) >> 8) + 128;
d8ya[0] = RDPCLAMP(Y, 0, 255);
d8ya[0] = RDPCLAMP(Y, 0, UCHAR_MAX);
d8ya++;
U_sum += RDPCLAMP(U, 0, 255);
V_sum += RDPCLAMP(V, 0, 255);
U_sum += RDPCLAMP(U, 0, UCHAR_MAX);
V_sum += RDPCLAMP(V, 0, UCHAR_MAX);

pixel = s32b[0];
s32b++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = ( 54 * R + 183 * G + 18 * B) >> 8;
U = ((-29 * R - 99 * G + 128 * B) >> 8) + 128;
V = ((128 * R - 116 * G - 12 * B) >> 8) + 128;
d8yb[0] = RDPCLAMP(Y, 0, 255);
d8yb[0] = RDPCLAMP(Y, 0, UCHAR_MAX);
d8yb++;
U_sum += RDPCLAMP(U, 0, 255);
V_sum += RDPCLAMP(V, 0, 255);
U_sum += RDPCLAMP(U, 0, UCHAR_MAX);
V_sum += RDPCLAMP(V, 0, UCHAR_MAX);

pixel = s32b[0];
s32b++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = ( 54 * R + 183 * G + 18 * B) >> 8;
U = ((-29 * R - 99 * G + 128 * B) >> 8) + 128;
V = ((128 * R - 116 * G - 12 * B) >> 8) + 128;
d8yb[0] = RDPCLAMP(Y, 0, 255);
d8yb[0] = RDPCLAMP(Y, 0, UCHAR_MAX);
d8yb++;
U_sum += RDPCLAMP(U, 0, 255);
V_sum += RDPCLAMP(V, 0, 255);
U_sum += RDPCLAMP(U, 0, UCHAR_MAX);
V_sum += RDPCLAMP(V, 0, UCHAR_MAX);

d8uv[0] = (U_sum + 2) / 4;
d8uv++;
Expand All @@ -641,12 +631,9 @@ a8r8g8b8_to_yuv444_709fr_box(const uint8_t *s8, int src_stride,
{
int index;
int jndex;
int R;
int G;
int B;
int Y;
int U;
int V;
int R, G, B;
int Y, U, V;
int cY, cU, cV;
int pixel;
const uint32_t *s32;
uint32_t *d32;
Expand All @@ -659,15 +646,14 @@ a8r8g8b8_to_yuv444_709fr_box(const uint8_t *s8, int src_stride,
{
pixel = s32[0];
s32++;
R = (pixel >> 16) & 0xff;
G = (pixel >> 8) & 0xff;
B = (pixel >> 0) & 0xff;
RGB_SPLIT(R, G, B, pixel);
Y = ( 54 * R + 183 * G + 18 * B) >> 8;
U = ((-29 * R - 99 * G + 128 * B) >> 8) + 128;
V = ((128 * R - 116 * G - 12 * B) >> 8) + 128;
d32[0] = (RDPCLAMP(Y, 0, 255) << 16) |
(RDPCLAMP(U, 0, 255) << 8) |
RDPCLAMP(V, 0, 255);
cY = RDPCLAMP(Y, 0, UCHAR_MAX) << 16;
cU = RDPCLAMP(U, 0, UCHAR_MAX) << 8;
cV = RDPCLAMP(V, 0, UCHAR_MAX);
d32[0] = cY | cU | cV;
d32++;
}
}
Expand Down

0 comments on commit 72143c3

Please sign in to comment.