+#define YUV_rgb_to_yuv_8(r,g,b, y,u,v) \
+ y = (rtoy8[r] + gtoy8[g] + btoy8[b] + yzero) >> 16; \
+ u = (rtou8[r] + gtou8[g] + btou8[b] + uvzero) >> 16; \
+ v = (rtov8[r] + gtov8[g] + btov8[b] + uvzero) >> 16
+
+ bc_always_inline void rgb_to_yuv_8(int r, int g, int b, int &y, int &u, int &v) {
+ YUV_rgb_to_yuv_8(r,g,b, y,u,v);
+ }
+ bc_always_inline void rgb_to_yuv_8(int r, int g, int b, uint8_t &y, uint8_t &u, uint8_t &v) {
+ YUV_rgb_to_yuv_8(r,g,b, y,u,v);
+ }
+ bc_always_inline void rgb_to_yuv_8(int &y, int &u, int &v) {
+ int r = y, g = u, b = v; YUV_rgb_to_yuv_8(r, g, b, y, u, v);
+ }
+
+#define YUV_rgb_to_yuv_16(r,g,b, y,u,v) \
+ y = (rtoy16[r] + gtoy16[g] + btoy16[b] + yzero) >> 8; \
+ u = (rtou16[r] + gtou16[g] + btou16[b] + uvzero) >> 8; \
+ v = (rtov16[r] + gtov16[g] + btov16[b] + uvzero) >> 8
+
+ bc_always_inline void rgb_to_yuv_16(int r, int g, int b, int &y, int &u, int &v) {
+ YUV_rgb_to_yuv_16(r,g,b, y,u,v);
+ }
+ bc_always_inline void rgb_to_yuv_16(int r, int g, int b, uint16_t &y, uint16_t &u, uint16_t &v) {
+ YUV_rgb_to_yuv_16(r,g,b, y,u,v);
+ }
+ bc_always_inline void rgb_to_yuv_16(int &y, int &u, int &v) {
+ int r = y, g = u, b = v;
+ YUV_rgb_to_yuv_16(r, g, b, y, u, v);
+ }
+
+ bc_always_inline void rgb_to_yuv_f(float r, float g, float b, float &y, float &u, float &v) {
+ y = r * r_to_y + g * g_to_y + b * b_to_y + yminf;
+ u = r * r_to_u + g * g_to_u + b * b_to_u + uvminf;
+ v = r * r_to_v + g * g_to_v + b * b_to_v + uvminf;
+ }
+ bc_always_inline void rgb_to_yuv_8(float r, float g, float b, int &y, int &u, int &v) {
+ float fy, fu, fv; rgb_to_yuv_f(r, g, b, fy, fu, fv);
+ int iy = fy * 0x100, iu = fu * 0x100, iv = fv * 0x100;
+ CLAMP(iy, ymin8, ymax8);
+ CLAMP(iu, uvmin8, uvmax8); CLAMP(iv, uvmin8, uvmax8);
+ y = iy; u = iu; v = iv;
+ }
+ bc_always_inline void rgb_to_yuv_16(float r, float g, float b,
+ int &y, int &u, int &v) {
+ float fy, fu, fv; rgb_to_yuv_f(r, g, b, fy, fu, fv);
+ int iy = fy * 0x10000, iu = fu * 0x10000, iv = fv * 0x10000;
+ CLAMP(iy, ymin16, ymax16);
+ CLAMP(iu, uvmin16, uvmax16); CLAMP(iv, uvmin16, uvmax16);
+ y = iy; u = iu; v = iv;
+ }
+
+#define YUV_yuv_to_rgb_8(r,g,b, y,u,v) \
+ r = (ytab8[y] + vtor8[v]) >> 16; \
+ g = (ytab8[y] + utog8[u] + vtog8[v]) >> 16; \
+ b = (ytab8[y] + utob8[u]) >> 16
+
+ bc_always_inline void yuv_to_rgb_8(int &r, int &g, int &b, int y, int u, int v) {
+ YUV_yuv_to_rgb_8(r,g,b, y,u,v);
+ CLAMP(r, 0, 0xff); CLAMP(g, 0, 0xff); CLAMP(b, 0, 0xff);
+ }
+ bc_always_inline void yuv_to_rgb_8(uint8_t &r, uint8_t &g, uint8_t &b, int y, int u, int v) {
+ YUV_yuv_to_rgb_8(r,g,b, y,u,v);
+ }
+ bc_always_inline void yuv_to_rgb_8(int &r, int &g, int &b) {
+ int y = r, u = g, v = b; YUV_yuv_to_rgb_8(r,g,b, y,u,v);
+ CLAMP(r, 0, 0xff); CLAMP(g, 0, 0xff); CLAMP(b, 0, 0xff);
+ }
+ bc_always_inline void yuv_to_rgb_8(float &r, float &g, float &b, int y, int u, int v) {
+ int ir, ig, ib; YUV_yuv_to_rgb_8(ir,ig,ib, y,u,v);
+ float s = 1/255.f; r = s*ir; g = s*ig; b = s*ib;
+ }
+
+#define YUV_yuv_to_rgb_16(r,g,b, y,u,v) \
+ r = (ytab16[y] + vtor16[v]) >> 8; \
+ g = (ytab16[y] + utog16[u] + vtog16[v]) >> 8; \
+ b = (ytab16[y] + utob16[u]) >> 8
+
+ bc_always_inline void yuv_to_rgb_16(int &r, int &g, int &b, int y, int u, int v) {
+ YUV_yuv_to_rgb_16(r,g,b, y,u,v);
+ CLAMP(r, 0, 0xffff); CLAMP(g, 0, 0xffff); CLAMP(b, 0, 0xffff);
+ }
+ bc_always_inline void yuv_to_rgb_16(uint16_t &r, uint16_t &g, uint16_t &b, int y, int u, int v) {
+ YUV_yuv_to_rgb_16(r,g,b, y,u,v);
+ }
+ bc_always_inline void yuv_to_rgb_16(int &r, int &g, int &b) {
+ int y = r, u = g, v = b; YUV_yuv_to_rgb_16(r,g,b, y,u,v);
+ CLAMP(r, 0, 0xffff); CLAMP(g, 0, 0xffff); CLAMP(b, 0, 0xffff);
+ }
+ bc_always_inline void yuv_to_rgb_16(float &r, float &g, float &b, int y, int u, int v) {
+ int ir, ig, ib; YUV_yuv_to_rgb_16(ir,ig,ib, y,u,v);
+ float s = 1/65535.f; r = s*ir; g = s*ig; b = s*ib;
+ }
+
+ bc_always_inline void yuv_to_rgb_f(float &r, float &g, float &b, float y, float u, float v) {
+ y = (y-yminf) / yrangef;
+ u = u-uvminf; v = v-uvminf;
+ r = y + v_to_r * v;
+ g = u + u_to_g * u + v_to_g * v;
+ b = y + u_to_b * u;
+ }