ref: 6cdf4cb5e83da3d89367cd2e2d8b1813b573146d
dir: /yuv.c/
#include <u.h> #include <libc.h> #include "yuv.h" #define Y ((( 77*r + 150*g + 29*b + 128) >> 8) + 0) #define U (((-43*r - 84*g + 127*b + 128) >> 8) + 128) #define V (((127*r - 106*g - 21*b + 128) >> 8) + 128) void xrgb2yuv420(u8int *bgrx, int w, int h, YUV *yuv) { u8int *py, *pu, *pv; int x, y, r, g, b; py = yuv->y; pu = yuv->u; pv = yuv->v; for(y = 0; y < h;){ for(x = 0; x < w;){ b = bgrx[0]; g = bgrx[1]; r = bgrx[2]; bgrx += 4; py[x] = Y; pu[x/2] = U; pv[x/2] = V; x++; b = bgrx[0]; g = bgrx[1]; r = bgrx[2]; bgrx += 4; py[x] = Y; x++; } py += yuv->ys; y++; for(x = 0; x < w;){ b = bgrx[0]; g = bgrx[1]; r = bgrx[2]; bgrx += 4; py[x] = Y; x++; } py += yuv->ys; pu += yuv->us; pv += yuv->vs; y++; } }