ref: 58fad377cbf35e5a03d4a5953d5dfabcb75ca3a8
parent: 71e5eaf30c76e8bbd82fe4c9592d4406d7fa1c08
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Jul 13 09:07:29 EDT 2021
make rgb→yuv more readable
--- a/hj264.c
+++ b/hj264.c
@@ -45,18 +45,17 @@
};
static void
-xrgb2yuv(u8int *src, int stride, int h, H264E_io_yuv_t *io)
+xrgb2yuv(u8int *bgrx, int w, int h, H264E_io_yuv_t *io)
{
+ u8int *py, *pu, *pv;
int x, y, r, g, b;
- u8int *bgrx, *yuv[3];
- yuv[0] = io->yuv[0];
- yuv[1] = io->yuv[1];
- yuv[2] = io->yuv[2];
+ py = io->yuv[0];
+ pu = io->yuv[1];
+ pv = io->yuv[2];
- for(y = 0; y < h;){
- bgrx = &src[y * stride];
- for(x = 0; x < stride/4;){
+ for(y = 0; y < h; bgrx += w*4){
+ for(x = 0; x < w;){
b = bgrx[0];
g = bgrx[1];
r = bgrx[2];
@@ -65,9 +64,9 @@
#define YY ((( 66*r + 129*g + 25*b + 128) >> 8) + 16)
#define UU (((-38*r - 74*g + 112*b + 128) >> 8) + 128)
#define VV (((112*r - 94*g - 18*b + 128) >> 8) + 128)
- yuv[0][x] = YY;
- yuv[1][x/2] = UU;
- yuv[2][x/2] = VV;
+ py[x] = YY;
+ pu[x/2] = UU;
+ pv[x/2] = VV;
x++;
b = bgrx[0];
@@ -74,26 +73,26 @@
g = bgrx[1];
r = bgrx[2];
bgrx += 4;
- yuv[0][x] = YY;
+ py[x] = YY;
x++;
}
- yuv[0] += io->stride[0];
+ py += io->stride[0];
y++;
- for(x = 0; x < stride/4;){
+ for(x = 0; x < w;){
b = bgrx[0];
g = bgrx[1];
r = bgrx[2];
bgrx += 4;
- yuv[0][x] = YY;
+ py[x] = YY;
x++;
#undef YY
#undef UU
#undef VV
}
- yuv[0] += io->stride[0];
- yuv[1] += io->stride[1];
- yuv[2] += io->stride[1];
+ py += io->stride[0];
+ pu += io->stride[1];
+ pv += io->stride[1];
y++;
}
}
@@ -198,7 +197,10 @@
cp.token = h;
cp.run_func_in_thread = hjobsrun;
- H264E_init(h->persist, &cp);
+ if((e = H264E_init(h->persist, &cp)) != 0){
+ werrstr("H264E_init: error %d", e);
+ return nil;
+ }
h->nthreads = nthreads;
for(i = 0; i < nthreads; i++){
@@ -349,7 +351,7 @@
}
unloadmemimage(im, im->r, src, srcsz);
- xrgb2yuv(src, bytesperline(im->r, im->depth), Dy(im->r), &h->yuv);
+ xrgb2yuv(src, Dx(im->r), Dy(im->r), &h->yuv);
freememimage(im);
if(hj264_encode(h, &data, &sz) != 0)
--- a/mkfile
+++ b/mkfile
@@ -15,3 +15,4 @@
default:V: all
</sys/src/cmd/mkone
+#LDFLAGS=-p