?? videomanrendererogl.cpp
字號:
int iniC = screenSize.right * despC;
int finC = screenSize.right * despCs;
int iniF = screenSize.top * despF;
int finF = screenSize.top * despFs;
float tamX = finC - iniC;
float tamY = finF - iniF;
float aspectX = (float)tamX / (float)inputList[v].width;
float aspectY = (float)tamY / (float)inputList[v].height;
if ( aspectX < aspectY )
{
inputList[v].screenCoords.left = iniC;
inputList[v].screenCoords.right = tamX;
inputList[v].screenCoords.top = (float)inputList[v].height * aspectX;
inputList[v].screenCoords.bottom = iniF;//+((float)tamY - (float)videoList[v].screenCoords.top)*0.5f;
}
else
{
inputList[v].screenCoords.bottom = iniF;
inputList[v].screenCoords.top = tamY;
inputList[v].screenCoords.right = (float)inputList[v].width * aspectY;
inputList[v].screenCoords.left = iniC + ( (float)tamX - (float)inputList[v].screenCoords.right ) * 0.5f;
}
inputList[v].activated = true;
v++;
}
}*/
}
void VideoManRendererOGL::activateVideoInput( size_t v )
{
assert( v >= 0 && v < inputList.size() && "activateVideoInput: Index out of range");
if ( inputList[v].activated || !inputList[v].supported )
return;
activatedInputs++;
inputList[v].activated = true;
changeScreenSize( screenSize.left,screenSize.bottom,screenSize.width,screenSize.height );
}
void VideoManRendererOGL::deactivateAllVideoInputs()
{
activatedInputs = 0;
for( size_t v = 0; v < inputList.size(); v++ )
{
inputList[v].activated = false;
}
changeScreenSize( screenSize.left,screenSize.bottom,screenSize.width,screenSize.height );
}
void VideoManRendererOGL::deactivateVideoInput( size_t v )
{
assert ( v >= 0 && v < inputList.size() && "deactivateVideoInput: Index out of range");
if ( !inputList[v].activated )
return;
activatedInputs--;
inputList[v].activated=false;
changeScreenSize( screenSize.left,screenSize.bottom,screenSize.width,screenSize.height );
}
bool VideoManRendererOGL::isActivated( size_t v )
{
assert ( v >= 0 && v < inputList.size() && "deactivateVideoInput: Index out of range");
return ( inputList[v].activated );
}
void VideoManRendererOGL::changeVisualizationMode( int vM )
{
visualizationMode = vM;
changeScreenSize( screenSize.left, screenSize.bottom, screenSize.width, screenSize.height );
}
void VideoManRendererOGL::changeMainVisualizationInput( const size_t &v )
{
assert ( v >= 0 && v < inputList.size() && "changeMainVisualizationInput: Index out of range");
if ( inputList[v].activated )
{
mainVisualizationInput = v;
changeScreenSize( screenSize.left, screenSize.bottom, screenSize.width, screenSize.height );
}
}
void VideoManRendererOGL::changeScreenSize( int left, int bottom, int width, int height )
{
screenSize.init( left, bottom, width, height );
if ( screenSize.height <= 0 || screenSize.width <= 0 )
return;
if ( inputList.size() == 0 || activatedInputs == 0 )
return;
switch ( visualizationMode )
{
case 0:
default:
{
changeScreenSizeV0( left, bottom, width, height );
break;
}
case 1:
{
if ( activatedInputs <= 1 )
changeScreenSizeV0( left, bottom, width, height );
else
changeScreenSizeV1( left, bottom, width, height );
break;
}
}
}
void VideoManRendererOGL::changeScreenSizeV0( int left, int bottom, int width, int height )
{
float numColsF = sqrt( ( (float)screenSize.width / (float)screenSize.height ) * 1.33333f * (float) activatedInputs );
int numCols = static_cast<int>( floor( numColsF ) );
if ( numCols == 0 ) numCols = 1;
if ( numCols > activatedInputs ) numCols = activatedInputs;
//if ((numColsF-numCols)>(numColsF-(numCols+1)))
// numCols=numCols+1;
int numFils = static_cast<int>( ceil( (float)activatedInputs / (float)numCols ) );
float despC = 0.0f;
float despF = 0.0f;
float despCs = 0.0f;
float despFs = 0.0f;
int actual = 0;
for ( int i = 0; i < (int)inputList.size(); i++ )
{
if ( inputList[i].activated )
{
//Calculate Which is its row
int row = static_cast<int>( floor( (float)actual / (float)numCols ) );
//Calculate Which is its column
int col = actual % numCols;
despC = (float)col / (float)numCols;
despF = (float)row / (float)numFils;
despCs = (float)(col+1) / (float)numCols;
despFs = (float)(row+1) / (float)numFils;
int iniC = static_cast<int>( screenSize.width * despC );
int finC = static_cast<int>( screenSize.width * despCs );
int iniF = static_cast<int>( screenSize.height - screenSize.height * despFs );
int finF = static_cast<int>( screenSize.height - screenSize.height * despF);
int tamX = finC - iniC;
int tamY = finF - iniF;
calculateAspectRatio( iniC, iniF, tamX, tamY, i );
actual++;
}
}
}
void VideoManRendererOGL::calculateAspectRatio( int left, int bottom, int width, int height, size_t index )
{
float aspectX = (float)width / (float)inputList[index].width;
float aspectY = (float)height / (float)inputList[index].height;
if ( aspectX < aspectY )
{
inputList[index].screenCoords.left = left;
inputList[index].screenCoords.width = static_cast<long>( width );
inputList[index].screenCoords.height = static_cast<long>( (float)inputList[index].height * aspectX );
//inputList[i].screenCoords.bottom = iniF;//+((float)tamY - (float)videoList[v].screenCoords.top)*0.5f;
inputList[index].screenCoords.bottom = static_cast<long>( bottom + (height - aspectX*inputList[index].height)*0.5f );
}
else
{
inputList[index].screenCoords.bottom = bottom;
inputList[index].screenCoords.height = static_cast<long>( height );
inputList[index].screenCoords.width = static_cast<long>( (float)inputList[index].width * aspectY );
inputList[index].screenCoords.left = static_cast<long>( left + ( (float)width - (float)inputList[index].screenCoords.width ) * 0.5f );
}
}
void VideoManRendererOGL::changeScreenSizeV1( int left, int bottom, int width, int height )
{
int despY = height / static_cast<int>( inputList.size() );
for ( int i = 0; i < (int)inputList.size(); i++ )
{
if ( inputList[i].activated )
{
if ( mainVisualizationInput == i )
{
calculateAspectRatio( left + width * 1 / 4, bottom, width * 3 / 4, height, i );
}
else
{
calculateAspectRatio( left, bottom + despY * i, width * 1 / 4, despY, i );
}
}
}
}
int VideoManRendererOGL::screenToImageCoords( float &x, float &y )
{
size_t i = 0;
int selected = -1;
y = screenSize.height - y;
while( selected == -1 && i<inputList.size() )
{
if ( inputList[i].activated )
{
float dY = y - inputList[i].screenCoords.bottom;
float dX = x - inputList[i].screenCoords.left;
if ( dX >= 0 && dX <= inputList[i].screenCoords.width &&
dY >= 0 && dY <= inputList[i].screenCoords.height )
{
selected = static_cast<int>( i );
}
}
i++;
}
if ( selected != -1 )
{
x = static_cast<float>( inputList[selected].width ) * ( x - static_cast<float>( inputList[selected].screenCoords.left ) ) / static_cast<float>( inputList[selected].screenCoords.width );
y = static_cast<float>( inputList[selected].height ) * ( y - static_cast<float>( inputList[selected].screenCoords.bottom ) ) / static_cast<float>( inputList[selected].screenCoords.height );
y = static_cast<float>( inputList[selected].height ) - y;
if ( x >= 0 && x < inputList[selected].width && y >= 0 && y < inputList[selected].height )
return selected;
else
return -1;
}
return selected;
}
bool VideoManRendererOGL::imageToScreenCoords( const size_t &v, float &x, float &y )
{
assert( v >= 0 && v < inputList.size() && "imageToScreenCoords: Index out of range");
//x = static_cast<float>( inputList[selected].width ) * ( x - static_cast<float>( inputList[selected].screenCoords.left ) ) / static_cast<float>( inputList[selected].screenCoords.right );
x = static_cast<float>( inputList[v].screenCoords.left ) + static_cast<float>( inputList[v].screenCoords.width ) * x / static_cast<float>( inputList[v].width );
//y = static_cast<float>( inputList[selected].height ) * ( y - static_cast<float>( inputList[selected].screenCoords.bottom ) ) / static_cast<float>( inputList[selected].screenCoords.top );
y = static_cast<float>( inputList[v].screenCoords.bottom ) + static_cast<float>( inputList[v].screenCoords.height ) * y / static_cast<float>( inputList[v].height );
return true;
}
bool VideoManRendererOGL::getScreenCoords( const size_t &v, int &left, int &bottom, int &width, int &height )
{
assert( v >= 0 && v < inputList.size() && "getScreenCoords: Index out of range");
if ( !inputList[v].activated )
return false;
left = inputList[v].screenCoords.left;
bottom = inputList[v].screenCoords.bottom;
width = inputList[v].screenCoords.width;
height = inputList[v].screenCoords.height;
return true;
}
void VideoManRendererOGL::getTextureCoords( const size_t &input, float &left, float &bottom, float &right, float &up )
{
assert( input >= 0 && input < inputList.size() && "getTextureCoords: Index out of range");
left = inputList[input].tu1;
right = inputList[input].tu2;
up = inputList[input].tv2;
bottom = inputList[input].tv1;
}
inline void VideoManRendererOGL::activateViewport( const size_t &v )
{
assert( v >= 0 && v < inputList.size() && "activateViewport: Index out of range");
glViewport( inputList[v].screenCoords.left, inputList[v].screenCoords.bottom, inputList[v].screenCoords.width, inputList[v].screenCoords.height);
}
inline void VideoManRendererOGL::activateTexture( const size_t &v )
{
assert( v >= 0 && v < inputList.size() && "activateTexture: Index out of range");
glBindTexture(GL_TEXTURE_2D, inputList[v].texture);
}
void VideoManRendererOGL::setVerticalFlip( const size_t &v, bool value )
{
assert( v >= 0 && v < inputList.size() && "setVerticalFlip: Index out of range");
if ( value != inputList[v].verticalFlip )
{
inputList[v].verticalFlip = value;
float aux = inputList[v].tv1;
inputList[v].tv1 = inputList[v].tv2;
inputList[v].tv2 = aux;
}
}
bool VideoManRendererOGL::getVerticalFlip( const size_t &v )
{
assert( v >= 0 && v < inputList.size() && "getVerticalFlip: Index out of range");
return inputList[v].verticalFlip;
}
void VideoManRendererOGL::setHorizontalFlip( const size_t &v, bool value )
{
assert( v >= 0 && v < inputList.size() && "setHorizontalFlip: Index out of range");
if ( value != inputList[v].horizontalFlip )
{
inputList[v].horizontalFlip = value;
float aux = inputList[v].tu1;
inputList[v].tu1 = inputList[v].tu2;
inputList[v].tu2 = aux;
}
}
bool VideoManRendererOGL::getHorizontalFlip( const size_t &v )
{
assert( v >= 0 && v < inputList.size() && "getHorizontalFlip: Index out of range");
return inputList[v].horizontalFlip;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -