Improve time critical functions in CalypFrame

This commit is contained in:
2021-06-07 00:05:45 +01:00
parent f2a636baa1
commit d330ecfd0d
6 changed files with 103 additions and 30 deletions
+2 -2
View File
@@ -228,7 +228,7 @@ IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -funroll-loops -ftree-vectorizer-verbose")
ADD_DEFINITIONS(
-DQT_NO_CAST_TO_ASCII
@@ -252,7 +252,7 @@ IF(USE_WERROR)
ENDIF()
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
# SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
# ####################################################################################################################################################
# Configure targets
+1
View File
@@ -3,3 +3,4 @@
#
ADD_SUBDIRECTORY(modules)
ADD_SUBDIRECTORY(stream)
+3 -3
View File
@@ -2,7 +2,7 @@
# CMakeLists for modules_example
#
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.0)
PROJECT("modules_example")
@@ -10,7 +10,7 @@ PROJECT("modules_example")
INCLUDE_DIRECTORIES(../../lib)
ADD_LIBRARY(FrameBinarization SHARED FrameBinarization_APIv1.cpp)
TARGET_LINK_LIBRARIES(FrameBinarization ${CALYP_LINKER_LIBS})
TARGET_LINK_LIBRARIES(FrameBinarization ${PROJECT_LIBRARY})
ADD_LIBRARY(AbsoluteFrameDifferenceExample SHARED AbsoluteFrameDifferenceExample.cpp)
TARGET_LINK_LIBRARIES(AbsoluteFrameDifferenceExample ${PROJECT_LIBRARY} ${CALYP_LINKER_LIBS})
TARGET_LINK_LIBRARIES(AbsoluteFrameDifferenceExample ${PROJECT_LIBRARY})
+9
View File
@@ -0,0 +1,9 @@
#
# CMakeLists for modules_example
#
INCLUDE_DIRECTORIES(../../lib)
ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\")
ADD_EXECUTABLE(testStreamReading testStreamReading.cpp)
TARGET_LINK_LIBRARIES(testStreamReading ${PROJECT_LIBRARY})
+69
View File
@@ -0,0 +1,69 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
*
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file testStreamReading.cpp
* \brief Example of open and reading from a stream
*/
#include <chrono>
#include <iostream>
#include "CalypFrame.h"
#include "CalypStream.h"
int main( int argc, char* argv[] )
{
// Use auto keyword to avoid typing long
// type definitions to get the timepoint
// at this instant use function now()
auto start = std::chrono::high_resolution_clock::now();
double n = 0;
CalypStream stream;
//stream.open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/Kendo_c4_1024x768_yuv420p.yuv" ), 1024, 768, 0, 8, CLP_BIG_ENDIAN, 1, true );
stream.open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/SteamLocomotiveTrain_2560x1600_60_10bit_crop.yuv" ), 2560, 1600, 0, 10, CLP_LITTLE_ENDIAN, 1, true );
while( 1 )
{
CalypFrame* frame = stream.getCurrFrame();
frame->fillRGBBuffer();
n++;
if( stream.setNextFrame() )
break;
stream.readNextFrame();
}
// After function call
auto stop = std::chrono::high_resolution_clock::now();
// Subtract stop and start timepoints and
// cast it to required unit. Predefined units
// are nanoseconds, microseconds, milliseconds,
// seconds, minutes, hours. Use duration_cast()
// function.
auto duration = std::chrono::duration_cast<std::chrono::microseconds>( stop - start );
// To get the value of duration use the count()
// member function on the duration object
std::cout << duration.count() / 1000.0 / n << std::endl;
return 0;
}
+19 -25
View File
@@ -674,16 +674,11 @@ void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness, unsigned long
void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness )
{
ClpByte* ppBuff[MAX_NUMBER_PLANES];
ClpByte* pTmpBuff;
ClpPel* pPel;
unsigned int bytesPixel = ( d->m_uiBitsPel - 1 ) / 8 + 1;
int ratioH, ratioW, step;
unsigned int i, ch;
int startByte = 0;
int endByte = bytesPixel;
int incByte = 1;
int b;
int maxval = pow( 2, d->m_uiBitsPel ) - 1;
int maxval = ( 1 << d->m_uiBitsPel ) - 1;
if( iEndianness == CLP_BIG_ENDIAN )
{
@@ -693,36 +688,35 @@ void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness )
}
ppBuff[0] = Buff;
for( i = 1; i < MAX_NUMBER_PLANES; i++ )
for( unsigned i = 1; i < MAX_NUMBER_PLANES; i++ )
{
ratioW = i > 1 ? d->m_pcPelFormat->log2ChromaWidth : 0;
ratioH = i > 1 ? d->m_pcPelFormat->log2ChromaHeight : 0;
int ratioW = i > 1 ? d->m_pcPelFormat->log2ChromaWidth : 0;
int ratioH = i > 1 ? d->m_pcPelFormat->log2ChromaHeight : 0;
ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ) * bytesPixel;
}
for( ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ )
xMemSet( ClpPel, getTotalNumberOfPixels(), d->m_pppcInputPel[0][0] );
for( unsigned ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ )
{
ratioW = ch > 0 ? d->m_pcPelFormat->log2ChromaWidth : 0;
ratioH = ch > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0;
step = ( d->m_pcPelFormat->comp[ch].step_minus1 ) * bytesPixel;
int ratioW = ch > 0 ? d->m_pcPelFormat->log2ChromaWidth : 0;
int ratioH = ch > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0;
int step = ( d->m_pcPelFormat->comp[ch].step_minus1 ) * bytesPixel;
pPel = d->m_pppcInputPel[ch][0];
pTmpBuff = ppBuff[d->m_pcPelFormat->comp[ch].plane] + ( d->m_pcPelFormat->comp[ch].offset_plus1 - 1 ) * bytesPixel;
ClpPel* pPel = d->m_pppcInputPel[ch][0];
ClpByte* pTmpBuff = ppBuff[d->m_pcPelFormat->comp[ch].plane] + ( d->m_pcPelFormat->comp[ch].offset_plus1 - 1 ) * bytesPixel;
for( i = 0; i < CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ); i++ )
for( unsigned p = 0; p < CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ); p++ )
{
*pPel = 0;
for( b = startByte; b != endByte; b += incByte )
for( int b = startByte; b != endByte; b += incByte )
{
*pPel += *pTmpBuff << ( b * 8 );
pPel[p] += *pTmpBuff << ( b * 8 );
pTmpBuff++;
// Check max value and bound it to "maxval" to prevent segfault when
// calculating histogram
if( *pPel > maxval )
*pPel = 0;
// -----
}
pPel++;
// Check max value and bound it to "maxval" to prevent segfault when
// calculating histogram
if( pPel[p] > maxval )
pPel[p] = 0;
pTmpBuff += step;
}
}