diff --git a/CMakeLists.txt b/CMakeLists.txt index 189844e..af63b0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 03cedf0..05978b4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,3 +3,4 @@ # ADD_SUBDIRECTORY(modules) +ADD_SUBDIRECTORY(stream) diff --git a/examples/modules/CMakeLists.txt b/examples/modules/CMakeLists.txt index e6903c7..9b35f35 100644 --- a/examples/modules/CMakeLists.txt +++ b/examples/modules/CMakeLists.txt @@ -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}) diff --git a/examples/stream/CMakeLists.txt b/examples/stream/CMakeLists.txt new file mode 100644 index 0000000..46c2ebf --- /dev/null +++ b/examples/stream/CMakeLists.txt @@ -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}) diff --git a/examples/stream/testStreamReading.cpp b/examples/stream/testStreamReading.cpp new file mode 100644 index 0000000..d578098 --- /dev/null +++ b/examples/stream/testStreamReading.cpp @@ -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 +#include + +#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( 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; +} diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index fdc8c50..c827e74 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -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; } }