?? colorspace.c
字號:
#include <string.h> // memcpy#include "colorspace.h"#include "../divx4.h" // DEC_PICTURE// function pointers/* output */color_outputFuncPtr yv12_to_rgb555;color_outputFuncPtr yv12_to_yuv;#define MIN(A,B) ((A)<(B)?(A):(B))#define MAX(A,B) ((A)>(B)?(A):(B))#define SCALEBITS_IN 8#define FIX_IN(x) ((uint16_t) ((x) * (1L<<SCALEBITS_IN) + 0.5))int32_t RGB_Y_tab[256];int32_t B_U_tab[256];int32_t G_U_tab[256];int32_t G_V_tab[256];int32_t R_V_tab[256];/* yuv -> rgb def's */#define RGB_Y_OUT 1.164#define B_U_OUT 2.018#define Y_ADD_OUT 16#define G_U_OUT 0.391#define G_V_OUT 0.813#define U_ADD_OUT 128#define R_V_OUT 1.596#define V_ADD_OUT 128#define SCALEBITS_OUT 13#define FIX_OUT(x) ((uint16_t) ((x) * (1L<<SCALEBITS_OUT) + 0.5))/* initialize rgb lookup tables */voidcolorspace_init(void){ int32_t i; for (i = 0; i < 256; i++) { RGB_Y_tab[i] = FIX_OUT(RGB_Y_OUT) * (i - Y_ADD_OUT); B_U_tab[i] = FIX_OUT(B_U_OUT) * (i - U_ADD_OUT); G_U_tab[i] = FIX_OUT(G_U_OUT) * (i - U_ADD_OUT); G_V_tab[i] = FIX_OUT(G_V_OUT) * (i - V_ADD_OUT); R_V_tab[i] = FIX_OUT(R_V_OUT) * (i - V_ADD_OUT); }}/* yuv 4:2:0 planar -> rgb555 + very simple error diffusion*/#define MK_RGB555(R,G,B) ((MAX(0,MIN(255, R)) << 7) & 0x7c00) | \ ((MAX(0,MIN(255, G)) << 2) & 0x03e0) | \ ((MAX(0,MIN(255, B)) >> 3) & 0x001f) | 0x8000voidyv12_to_rgb555_c(uint8_t * dst, int dst_stride, uint8_t * y_src, uint8_t * u_src, uint8_t * v_src, int y_stride, int uv_stride, int width, int height){ const uint32_t dst_dif = 4 * dst_stride - 2 * width; int32_t y_dif = 2 * y_stride - width; uint8_t *dst2 = dst + 2 * dst_stride; uint8_t *y_src2 = y_src + y_stride; uint32_t x, y; if (height < 0) { height = -height; y_src += (height - 1) * y_stride; y_src2 = y_src - y_stride; u_src += (height / 2 - 1) * uv_stride; v_src += (height / 2 - 1) * uv_stride; y_dif = -width - 2 * y_stride; uv_stride = -uv_stride; } for (y = height / 2; y; y--) { int r, g, b; int r2, g2, b2; r = g = b = 0; r2 = g2 = b2 = 0; // process one 2x2 block per iteration for (x = 0; x < (uint32_t) width / 2; x++) { int u, v; int b_u, g_uv, r_v, rgb_y; u = u_src[x]; v = v_src[x]; b_u = B_U_tab[u]; g_uv = G_U_tab[u] + G_V_tab[v]; r_v = R_V_tab[v]; rgb_y = RGB_Y_tab[*y_src]; b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); *(uint16_t *) dst = MK_RGB555(r, g, b); y_src++; rgb_y = RGB_Y_tab[*y_src]; b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); *(uint16_t *) (dst + 2) = MK_RGB555(r, g, b); y_src++; rgb_y = RGB_Y_tab[*y_src2]; b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); *(uint16_t *) (dst2) = MK_RGB555(r2, g2, b2); y_src2++; rgb_y = RGB_Y_tab[*y_src2]; b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); *(uint16_t *) (dst2 + 2) = MK_RGB555(r2, g2, b2); y_src2++; dst += 4; dst2 += 4; } dst += dst_dif; dst2 += dst_dif; y_src += y_dif; y_src2 += y_dif; u_src += uv_stride; v_src += uv_stride; }}#ifdef not_complete_yetvoidyv12_to_rgb555_c(uint8_t * dst, int dst_stride, uint8_t * y_src, uint8_t * u_src, uint8_t * v_src, int y_stride, int uv_stride, int width, int height){ const uint32_t dst_dif = 4 * dst_stride - 2 * width; int32_t y_dif = 2 * y_stride - width; uint8_t *dst2 = dst + 2 * dst_stride; uint8_t *y_src2 = y_src + y_stride; uint32_t x, y; int uv_pos; int y_pos; if (height < 0) { height = -height; y_src += (height - 1) * y_stride; y_src2 = y_src - y_stride; u_src += (height / 2 - 1) * uv_stride; v_src += (height / 2 - 1) * uv_stride; y_dif = -width - 2 * y_stride; uv_stride = -uv_stride; } for (y = height / 2; y; y--) ///for (y=0; y<height/2; ++y) { int r, g, b; int r2, g2, b2; r = g = b = 0; r2 = g2 = b2 = 0; // process one 2x2 block per iteration for (x = 0; x < (uint32_t) width / 2; x++) { int u, v; int b_u, g_uv, r_v, rgb_y; uv_pos = (y/8) * (8*uv_stride) + (x/8) * 64 + ( (y - y/8*8) * 8 + (x - x/8*8) ); u = u_src[uv_pos]; ///u = u_src[x]; v = v_src[uv_pos]; ///v = v_src[x]; b_u = B_U_tab[u]; g_uv = G_U_tab[u] + G_V_tab[v]; r_v = R_V_tab[v]; y_pos = (y/8) * (16*y_stride) + (x/8) * 256 + ( (y - y/8*8) * 2 * 16 + (x - x/8*8)*2 ); rgb_y = RGB_Y_tab[y_pos]; /// rgb_y = RGB_Y_tab[*y_src]; b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); *(uint16_t *) dst = MK_RGB555(r, g, b); ++y_pos; /// y_src++; rgb_y = RGB_Y_tab[y_pos]; /// rgb_y = RGB_Y_tab[*y_src]; b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); *(uint16_t *) (dst + 2) = MK_RGB555(r, g, b); y_pos = y_pos + 15; /// ==> ( 16 - 1) rgb_y = RGB_Y_tab[y_pos]; /// rgb_y = RGB_Y_tab[*y_src2]; b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); *(uint16_t *) (dst2) = MK_RGB555(r2, g2, b2); ++y_pos; rgb_y = RGB_Y_tab[y_pos]; /// rgb_y = RGB_Y_tab[*y_src2]; b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); *(uint16_t *) (dst2 + 2) = MK_RGB555(r2, g2, b2); dst += 4; dst2 += 4; } dst += dst_dif; dst2 += dst_dif;/// y_src += y_dif;/// y_src2 += y_dif;/// u_src += uv_stride;/// v_src += uv_stride; }}#endif /* end_of_not *//* yuv 4:2:0 planar -> yuv planar */voidyv12_to_yuv_c(uint8_t * dst, int dst_stride, uint8_t * y_src, uint8_t * u_src, uint8_t * v_src, int y_stride, int uv_stride, int width, int height){ uint32_t dst_stride2 = dst_stride >> 1; uint32_t width2 = width >> 1; uint32_t y; if (height < 0) { height = -height; y_src += (height - 1) * y_stride; u_src += (height / 2 - 1) * uv_stride; v_src += (height / 2 - 1) * uv_stride; y_stride = -y_stride; uv_stride = -uv_stride; } for (y = height; y; y--) { memcpy(dst, y_src, width); dst += dst_stride; y_src += y_stride; } for (y = height >> 1; y; y--) { memcpy(dst, u_src, width2); dst += dst_stride2; u_src += uv_stride; } for (y = height >> 1; y; y--) { memcpy(dst, v_src, width2); dst += dst_stride2; v_src += uv_stride; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -