ref: 14e6292060224eaab98ecd331b7ac3c309beb2e2
parent: 2320b8e811830601ad68e6c84ab138a20b5e4d79
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Feb 8 16:15:31 EST 2021
use yuv to xrgb32 conversion instead of rgb24
--- a/main.c
+++ b/main.c
@@ -94,11 +94,11 @@
loadimage(curim, r, curpx, f->w*f->h);
}else{
if(curim == nil)
- curim = allocimage(display, r, RGB24, 0, DNofill);
+ curim = allocimage(display, r, XRGB32, 0, DNofill);
if(curpx == nil)
- curpx = malloc(f->w*f->h*3);
- yuv420_rgb24(f->w, f->h, f->yuv[0], f->yuv[1], f->yuv[2], f->ystride, f->uvstride, curpx, f->w*3);
- loadimage(curim, r, curpx, f->w*f->h*3);
+ curpx = malloc(f->w*f->h*4);
+ yuv420_xrgb32(f->w, f->h, f->yuv[0], f->yuv[1], f->yuv[2], f->ystride, f->uvstride, curpx, f->w*4);
+ loadimage(curim, r, curpx, f->w*f->h*4);
}
dispdelay = nanosec() - x;
--- a/misc.h
+++ b/misc.h
@@ -4,7 +4,7 @@
int str2fmt(char *s);
char *fmt2str(int fmt);
uvlong nanosec(void);
-void yuv420_rgb24(int width, int height, u8int *y, u8int *u, u8int *v, u32int ystride, u32int uvstride, u8int *rgb, u32int rgbstride);
+void yuv420_xrgb32(int width, int height, u8int *y, u8int *u, u8int *v, u32int ystride, u32int uvstride, u8int *rgb, u32int rgbstride);
extern int nproc;
extern int debug;
--- a/yuv.c
+++ b/yuv.c
@@ -3,7 +3,7 @@
uvlong yuv→rgb;
-void yuv420_rgb24(
+void yuv420_xrgb32(
int width, int height,
u8int *y, u8int *u, u8int *v,
u32int ystride, u32int uvstride,
@@ -21,20 +21,23 @@
cr = *v - 0x80;
go = 22554*cb + 46802*cr;
+ cb *= 116130;
+ cr *= 91881;
+
#define ONE do{ \
yy = *y * 0x10101; \
- b = yy + 116130*cb; \
+ b = yy + cb; \
rgb[0] = (b >> 24) ? ~(b >> 31) : (b>>16); \
g = yy - go; \
rgb[1] = (g >> 24) ? ~(g >> 31) : (g>>16); \
- r = yy + 91881*cr; \
+ r = yy + cr; \
rgb[2] = (r >> 24) ? ~(r >> 31) : (r>>16); \
}while(0)
-
- ONE; y += 1; rgb += 3;
+ ONE; y += 1; rgb += 4;
ONE; y += ystride; rgb += rgbstride;
- ONE; y -= 1; rgb -= 3;
- ONE; y -= ystride; rgb -= rgbstride - 6;
+ ONE; y -= 1; rgb -= 4;
+ ONE; y -= ystride; rgb -= rgbstride - 8;
+#undef ONE
y += 2;
u += 1;
@@ -44,7 +47,7 @@
y += ystride*2 - w;
u += uvstride - w/2;
v += uvstride - w/2;
- rgb += rgbstride*2 - 3*w;
+ rgb += rgbstride*2 - 4*w;
}
yuv→rgb = nanosec() - start;
}