?? skl_gmc_dsp.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_gmc_dsp.cpp * * level Sprite (MPEG4's GMC) processing ********************************************************/#include "skl.h"#include "skl_syst/skl_dsp.h"#include "skl_syst/skl_bits.h"extern "C" {//////////////////////////////////////////////////////////// Raw-C version#define RDIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))#define RSHIFT(a,b) ( (a)>0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))#define MLT(i) (((16-(i))<<16) + (i))static const SKL_UINT32 MTab[16] = { MLT( 0), MLT( 1), MLT( 2), MLT( 3), MLT( 4), MLT( 5), MLT( 6), MLT( 7), MLT( 8), MLT( 9), MLT(10), MLT(11), MLT(12), MLT(13), MLT(14), MLT(15)};#undef MLT//////////////////////////////////////////////////////////// Pts = 2 or 3staticvoid Predict_16x16_C(const SKL_GMC_DSP * const This, SKL_BYTE *Dst, const SKL_BYTE *Src, int BpS, int x, int y, int Rounding){ const int W = This->Width; const int H = This->Height; const int Rho = 3-This->Accuracy; const SKL_INT32 Rounder = ( 128 - (Rounding<<(2*Rho)) ) << 16; const SKL_UINT32 W2 = W<<(16-Rho); const SKL_UINT32 H2 = H<<(16-Rho); Dst += 16; const SKL_INT32 dUx = This->dU[0]; const SKL_INT32 dVx = This->dV[0]; const SKL_INT32 dUy = This->dU[1]; const SKL_INT32 dVy = This->dV[1]; SKL_INT32 Uo = This->Uo + 16*(dUy*y + dUx*x); SKL_INT32 Vo = This->Vo + 16*(dVy*y + dVx*x); for(int j=16; j>0; --j) {#ifdef USE_ASM// __asm__ __volatile__ ("prefetcht0 (%0)\n\t" : : "r" (Dst-16));#endif SKL_INT32 U = Uo, V = Vo; Uo += dUy; Vo += dVy; if ( (SKL_UINT32)U<W2 && (SKL_UINT32)(U+15*dUx)<W2 && (SKL_UINT32)V<H2 && (SKL_UINT32)(V+15*dVx)<H2 ) { for(int i=-16; i<0; ++i) { SKL_INT32 u = ( U >> 16 ) << Rho; SKL_INT32 v = ( V >> 16 ) << Rho; U += dUx; V += dVx; int Offset = (u>>4) + (v>>4)*BpS; const SKL_UINT32 ri = MTab[u&15]; const SKL_UINT32 rj = MTab[v&15]; SKL_UINT32 f0, f1; f0 = Src[ Offset +0 ]; f0 |= Src[ Offset +1 ] << 16; f1 = Src[ Offset+BpS +0 ]; f1 |= Src[ Offset+BpS +1 ] << 16; f0 = (ri*f0)>>16; f1 = (ri*f1) & 0x0fff0000; f0 |= f1; f0 = ( rj*f0 + Rounder ) >> 24; Dst[i] = (SKL_BYTE)f0; } } else { for(int i=-16; i<0; ++i) { int Offset; SKL_INT32 u = ( U >> 16 ) << Rho; SKL_INT32 v = ( V >> 16 ) << Rho; U += dUx; V += dVx; if ((SKL_UINT32)u<(SKL_UINT32)W) Offset = u>>4; else { if (u>=W) Offset = W>>4; else Offset = 0; u = 0; } if ((SKL_UINT32)v<(SKL_UINT32)H) Offset += (v>>4)*BpS; else { if (v>=H) Offset += (H>>4)*BpS; v = 0; } if (u&15) { const SKL_UINT32 ri = MTab[u&15]; if (v&15) { const SKL_UINT32 rj = MTab[v&15]; SKL_UINT32 f0, f1; f0 = Src[ Offset +0 ]; f0 |= Src[ Offset +1 ] << 16; f1 = Src[ Offset+BpS +0 ]; f1 |= Src[ Offset+BpS +1 ] << 16; f0 = (ri*f0)>>16; f1 = (ri*f1) & 0x0fff0000; f0 |= f1; f0 = ( rj*f0 + Rounder ) >> 24; Dst[i] = (SKL_BYTE)f0; } else { SKL_UINT32 f0; f0 = Src[ Offset ]; f0 |= Src[ Offset+1 ] << 16; f0 = (ri*f0 + (Rounder>>4))>>20; Dst[i] = (SKL_BYTE)f0; } } else { if (v&15) { const SKL_UINT32 rj = MTab[v&15]; SKL_UINT32 f0; f0 = Src[ Offset ]; f0 |= Src[ Offset +BpS ] << 16; f0 = (rj*f0 + (Rounder>>4))>>20; Dst[i] = (SKL_BYTE)f0; } else { Dst[i] = Src[Offset]; } } } } Dst += BpS; }}staticvoid Predict_8x8_C(const SKL_GMC_DSP * const This, SKL_BYTE *uDst, const SKL_BYTE *uSrc, SKL_SAFE_INT uv_Coloc, int BpS, int x, int y, int Rounding){ const int W = This->Width >> 1; const int H = This->Height>> 1; const int Rho = 3-This->Accuracy; const SKL_INT32 Rounder = ( 128 - (Rounding<<(2*Rho)) ) << 16; const SKL_UINT32 W2 = W<<(16-Rho); const SKL_UINT32 H2 = H<<(16-Rho); uDst += 8; SKL_BYTE *vDst = uDst + uv_Coloc; const SKL_BYTE *vSrc = uSrc + uv_Coloc; const SKL_INT32 dUx = This->dU[0]; const SKL_INT32 dVx = This->dV[0]; const SKL_INT32 dUy = This->dU[1]; const SKL_INT32 dVy = This->dV[1]; SKL_INT32 Uo = This->Uco + 8*(dUy*y + dUx*x); SKL_INT32 Vo = This->Vco + 8*(dVy*y + dVx*x); for(int j=8; j>0; --j) {#ifdef USE_ASM// __asm__ __volatile__ ("prefetcht0 (%0)\n\t" : : "r" (uDst-8));// __asm__ __volatile__ ("prefetcht0 (%0)\n\t" : : "r" (vDst-8));#endif SKL_INT32 U = Uo, V = Vo; Uo += dUy; Vo += dVy; if ( (SKL_UINT32)U<W2 && (SKL_UINT32)(U+15*dUx)<W2 && (SKL_UINT32)V<H2 && (SKL_UINT32)(V+15*dVx)<H2 ) { for(int i=-8; i<0; ++i) { SKL_INT32 u = ( U >> 16 ) << Rho; SKL_INT32 v = ( V >> 16 ) << Rho; U += dUx; V += dVx; const int Offset = (u>>4) + (v>>4)*BpS; const SKL_UINT32 ri = MTab[u&15]; const SKL_UINT32 rj = MTab[v&15]; SKL_UINT32 f0, f1; f0 = uSrc[ Offset +0 ]; f0 |= uSrc[ Offset +1 ] << 16; f1 = uSrc[ Offset+BpS +0 ]; f1 |= uSrc[ Offset+BpS +1 ] << 16; f0 = (ri*f0)>>16; f1 = (ri*f1) & 0x0fff0000; f0 |= f1; f0 = ( rj*f0 + Rounder ) >> 24; uDst[i] = (SKL_BYTE)f0; f0 = vSrc[ Offset +0 ]; f0 |= vSrc[ Offset +1 ] << 16; f1 = vSrc[ Offset+BpS +0 ]; f1 |= vSrc[ Offset+BpS +1 ] << 16; f0 = (ri*f0)>>16; f1 = (ri*f1) & 0x0fff0000; f0 |= f1; f0 = ( rj*f0 + Rounder ) >> 24; vDst[i] = (SKL_BYTE)f0; } } else { for(int i=-8; i<0; ++i) { SKL_INT32 u = ( U >> 16 ) << Rho; SKL_INT32 v = ( V >> 16 ) << Rho; U += dUx; V += dVx; int Offset; if ((SKL_UINT32)u<(SKL_UINT32)W) Offset = u>>4; else { if (u>=W) Offset = W>>4; else Offset = 0; u = 0; } if ((SKL_UINT32)v<(SKL_UINT32)H) Offset += (v>>4)*BpS; else { if (v>=H) Offset += (H>>4)*BpS; v = 0; } if (u&15) { const SKL_UINT32 ri = MTab[u&15]; if (v&15) { SKL_UINT32 f0, f1; const SKL_UINT32 rj = MTab[v&15]; f0 = uSrc[ Offset +0 ]; f0 |= uSrc[ Offset +1 ] << 16; f1 = uSrc[ Offset+BpS +0 ]; f1 |= uSrc[ Offset+BpS +1 ] << 16; f0 = (ri*f0)>>16; f1 = (ri*f1) & 0x0fff0000; f0 |= f1; f0 = ( rj*f0 + Rounder ) >> 24; uDst[i] = (SKL_BYTE)f0; f0 = vSrc[ Offset +0 ]; f0 |= vSrc[ Offset +1 ] << 16; f1 = vSrc[ Offset+BpS +0 ]; f1 |= vSrc[ Offset+BpS +1 ] << 16; f0 = (ri*f0)>>16; f1 = (ri*f1) & 0x0fff0000; f0 |= f1; f0 = ( rj*f0 + Rounder ) >> 24; vDst[i] = (SKL_BYTE)f0; } else { SKL_UINT32 f0; f0 = uSrc[ Offset ]; f0 |= uSrc[ Offset+1 ] << 16; f0 = (ri*f0 + (Rounder>>4))>>20; uDst[i] = (SKL_BYTE)f0; f0 = vSrc[ Offset ]; f0 |= vSrc[ Offset+1 ] << 16; f0 = (ri*f0 + (Rounder>>4))>>20; vDst[i] = (SKL_BYTE)f0; } } else { if (v&15) { const SKL_UINT32 rj = MTab[v&15]; SKL_UINT32 f0; f0 = uSrc[ Offset ]; f0 |= uSrc[ Offset +BpS ] << 16; f0 = (rj*f0 + (Rounder>>4))>>20; uDst[i] = (SKL_BYTE)f0; f0 = vSrc[ Offset ]; f0 |= vSrc[ Offset +BpS ] << 16; f0 = (rj*f0 + (Rounder>>4))>>20; vDst[i] = (SKL_BYTE)f0; } else { uDst[i] = uSrc[Offset]; vDst[i] = vSrc[Offset]; } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -