📄 skl_yuv_c.cpp
字号:
/******************************************************** * Some code. Copyright (C) 2003 by Pascal Massimino. * * All Rights Reserved. (http://skal.planet-d.net) * * For Educational/Academic use ONLY. See 'LICENSE.TXT'.* ********************************************************//* * skl_yuv_c.cpp * * YUV <-> RGB * ********************************************************/#include "skl.h"#include "skl_syst/skl_dsp.h"#include "skl_2d/skl_btm_cvrt.h"extern "C" {extern SKL_YUV_DSP Skl_YUV_DSP_C;extern SKL_YUV_DSP Skl_YUV_DSP_Ref;#define RGB_TO_YUV_FUNC_DCL(Name) \void Name(SKL_BYTE *Y, SKL_BYTE *U, SKL_BYTE *V, \ const int Dst_BpS, \ const SKL_BYTE *RGB, const int Src_BpS, \ const int Width, const int Height)#define YUV_TO_RGB_FUNC_DCL(Name) \void Name(SKL_BYTE *RGB, const int Dst_BpS, \ const SKL_BYTE *Y, const SKL_BYTE *U, const SKL_BYTE *V, \ const int Src_BpS, \ const int Width, const int Height)extern "C" RGB_TO_YUV_FUNC_DCL(Skl_RGB32_To_YUV_C);extern "C" RGB_TO_YUV_FUNC_DCL(Skl_RGB24_To_YUV_C);extern "C" RGB_TO_YUV_FUNC_DCL(Skl_RGB565_To_YUV_C);//////////////////////////////////////////////////////////// Ref-impl//////////////////////////////////////////////////////////#define RGB32_TO_RGB(V) r=((V)>>16)&0xff; g=((V)>>8)&0xff; b=((V)>>0)&0xff; #define RGB24_TO_RGB(V) r=(V)[0]; g=(V)[1]; b=(V)[2]#define RGB565_TO_RGB(V) r=((V)>>8)&0xf8; g=((V)>>3)&0xfc; b=((V)<<3)&0xf8#define RGB_TO_Y(r,g,b) ( 66*(r)+129*(g) + 25*(b) + (128+ 16*256))#define RGB_TO_U(r,g,b) (-38*(r)- 74*(g) +112*(b) + (128+128*256))#define RGB_TO_V(r,g,b) (112*(r)- 94*(g) - 18*(b) + (128+128*256))#define SAT(x) ( (x)<0 ? 0 : (x)>255 ? 255 : (x) )#define TO_RGB32(Y) ((SAT(Y+Bo)<<16)&0xff0000) | ((SAT(Y-Go)<<8)&0x00ff00) | (SAT(Y+Ro)&0x0000ff)#define TO_RGB24(D,Y) \ D[0] = SAT(Y[0]+Bo); D[1] = SAT(Y[0]-Go); D[2] = SAT(Y[0]+Ro); \ D[3] = SAT(Y[1]+Bo); D[4] = SAT(Y[1]-Go); D[5] = SAT(Y[1]+Ro); \#define TO_RGB565(Y) ((SAT(Y+Bo)<<8)&0xf800) | ((SAT(Y-Go)<<3)&0x07e0) | ((SAT(Y+Ro)>>3))RGB_TO_YUV_FUNC_DCL(Skl_RGB32_To_YUV_Ref){ for(int y=0; y<Height/2; y++) { SKL_BYTE *pDst1 = Y; SKL_BYTE *pDst2 = Y+Dst_BpS; const SKL_UINT32 *pSrc1 = (SKL_UINT32*)RGB; const SKL_UINT32 *pSrc2 = (SKL_UINT32*)(RGB + Src_BpS); for(int x=0; x<Width/2; x++) { int r,g,b, u,v; RGB32_TO_RGB(pSrc1[2*x+0]); pDst1[2*x+0] = RGB_TO_Y(r,g,b) >> 8; u = RGB_TO_U(r,g,b); v = RGB_TO_V(r,g,b); RGB32_TO_RGB(pSrc1[2*x+1]); pDst1[2*x+1] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); RGB32_TO_RGB(pSrc2[2*x+0]); pDst2[2*x+0] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); RGB32_TO_RGB(pSrc2[2*x+1]); pDst2[2*x+1] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); U[x] = u>>10; V[x] = v>>10; } RGB += 2*Src_BpS; Y += 2*Dst_BpS; U += Dst_BpS; V += Dst_BpS; }}static YUV_TO_RGB_FUNC_DCL(YUV_To_RGB32_Ref){ for(int y=0; y<Height/2; y++) { SKL_UINT32 *pDst1 = (SKL_UINT32*)RGB; SKL_UINT32 *pDst2 = (SKL_UINT32*)(RGB+Dst_BpS); const SKL_BYTE *pYSrc1 = Y; const SKL_BYTE *pYSrc2 = Y + Src_BpS; for(int x=0; x<Width/2; x++) { const int Uo = U[x]-128; const int Vo = V[x]-128; const int Ro = (91181*Uo)>>16; const int Go = (22553*Vo + 46801*Uo)>>16; const int Bo = (116129*Vo)>>16; pDst1[0] = TO_RGB32(pYSrc1[0]); pDst1[1] = TO_RGB32(pYSrc1[1]); pDst1+=2; pYSrc1+=2; pDst2[0] = TO_RGB32(pYSrc2[0]); pDst2[1] = TO_RGB32(pYSrc2[1]); pDst2+=2; pYSrc2+=2; } RGB += 2*Dst_BpS; Y += 2*Src_BpS; U += Src_BpS; V += Src_BpS; }}RGB_TO_YUV_FUNC_DCL(Skl_RGB24_To_YUV_Ref){ for(int y=0; y<Height/2; y++) { SKL_BYTE *pDst1 = Y; SKL_BYTE *pDst2 = Y+Dst_BpS; const SKL_BYTE *pSrc1 = RGB; const SKL_BYTE *pSrc2 = RGB + Src_BpS; for(int x=0; x<Width/2; x++) { int r,g,b, u,v; RGB24_TO_RGB(&pSrc1[6*x+0]); pDst1[2*x+0] = RGB_TO_Y(r,g,b) >> 8; u = RGB_TO_U(r,g,b); v = RGB_TO_V(r,g,b); RGB24_TO_RGB(&pSrc1[6*x+3]); pDst1[2*x+1] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); RGB24_TO_RGB(&pSrc2[6*x+0]); pDst2[2*x+0] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); RGB24_TO_RGB(&pSrc2[6*x+3]); pDst2[2*x+1] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); U[x] = u>>10; V[x] = v>>10; } RGB += 2*Src_BpS; Y += 2*Dst_BpS; U += Dst_BpS; V += Dst_BpS; }}static YUV_TO_RGB_FUNC_DCL(YUV_To_RGB24_Ref){ for(int y=0; y<Height/2; y++) { SKL_BYTE *pDst1 = RGB; SKL_BYTE *pDst2 = RGB+Dst_BpS; const SKL_BYTE *pYSrc1 = Y; const SKL_BYTE *pYSrc2 = Y + Src_BpS; for(int x=0; x<Width/2; x++) { const int Uo = U[x]-128; const int Vo = V[x]-128; const int Ro = (91181*Uo)>>16; const int Go = (22553*Vo + 46801*Uo)>>16; const int Bo = (116129*Vo)>>16; TO_RGB24(pDst1, pYSrc1) pDst1 +=6; pYSrc1+=2; TO_RGB24(pDst2, pYSrc2) pDst2 +=6; pYSrc2+=2; } RGB += 2*Dst_BpS; Y += 2*Src_BpS; U += Src_BpS; V += Src_BpS; }}RGB_TO_YUV_FUNC_DCL(Skl_RGB565_To_YUV_Ref){ for(int y=0; y<Height/2; y++) { SKL_BYTE *pDst1 = Y; SKL_BYTE *pDst2 = Y+Dst_BpS; const SKL_UINT16 *pSrc1 = (SKL_UINT16*)RGB; const SKL_UINT16 *pSrc2 = (SKL_UINT16*)(RGB + Src_BpS); for(int x=0; x<Width/2; x++) { int r,g,b, u,v; RGB565_TO_RGB(pSrc1[2*x+0]); pDst1[2*x+0] = RGB_TO_Y(r,g,b) >> 8; u = RGB_TO_U(r,g,b); v = RGB_TO_V(r,g,b); RGB565_TO_RGB(pSrc1[2*x+1]); pDst1[2*x+1] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); RGB565_TO_RGB(pSrc2[2*x+0]); pDst2[2*x+0] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); RGB565_TO_RGB(pSrc2[2*x+1]); pDst2[2*x+1] = RGB_TO_Y(r,g,b) >> 8; u += RGB_TO_U(r,g,b); v += RGB_TO_V(r,g,b); U[x] = u>>10; V[x] = v>>10; } RGB += 2*Src_BpS; Y += 2*Dst_BpS; U += Dst_BpS; V += Dst_BpS; }}static YUV_TO_RGB_FUNC_DCL(YUV_To_RGB565_Ref){ for(int y=0; y<Height/2; y++) { SKL_UINT16 *pDst1 = (SKL_UINT16*)RGB; SKL_UINT16 *pDst2 = (SKL_UINT16*)(RGB+Dst_BpS); const SKL_BYTE *pYSrc1 = Y; const SKL_BYTE *pYSrc2 = Y + Src_BpS; for(int x=0; x<Width/2; x++) { const int Uo = U[x]-128; const int Vo = V[x]-128; const int Ro = (91181*Uo)>>16; const int Go = (22553*Vo + 46801*Uo)>>16; const int Bo = (116129*Vo)>>16; pDst1[0] = TO_RGB565(pYSrc1[0]); pDst1[1] = TO_RGB565(pYSrc1[1]); pDst1+=2; pYSrc1+=2; pDst2[0] = TO_RGB565(pYSrc2[0]); pDst2[1] = TO_RGB565(pYSrc2[1]); pDst2+=2; pYSrc2+=2; } RGB += 2*Dst_BpS; Y += 2*Src_BpS; U += Src_BpS; V += Src_BpS; }}static int Init_YUV_RGB_Ref(int Transfer_Type) { if (Transfer_Type<0 || Transfer_Type>=8) return 0; return 1;}//////////////////////////////////////////////////////////SKL_YUV_DSP Skl_YUV_DSP_Ref = { "YUV-Ref", Skl_Switch_None, Init_YUV_RGB_Ref, Skl_RGB565_To_YUV_Ref, YUV_To_RGB565_Ref, Skl_RGB24_To_YUV_Ref, YUV_To_RGB24_Ref, Skl_RGB32_To_YUV_Ref, YUV_To_RGB32_Ref,};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -