diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bfa4a4b..294fa50 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,3 +35,28 @@ jobs: # Build your program with the given configuration run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run-tests: + needs: build + runs-on: ubuntu-latest + steps: + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install gcc-10 g++-10 cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev + + - uses: actions/checkout@v2 + + - name: Check out tests data + uses: actions/checkout@master + with: + path: tests_data + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DBUILD_TESTS=ON -DCALYP_TEST_DATA_DIR=${{github.workspace}}/tests_data + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t test + + - name: CalypLib tests + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t test \ No newline at end of file diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index 931164e..cdda0ce 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -141,6 +141,10 @@ public: CalypPixel operator-( const CalypPixel& ) const; CalypPixel operator*( const double& ) const; + auto operator==( const CalypPixel& other ) const -> bool; + + friend std::ostream& operator<<( std::ostream& os, const CalypPixel& p ); + /** * Convert a Pixel to a new color space * @param inputPixel input pixel (CalypPixel) @@ -150,6 +154,8 @@ public: CalypPixel convertPixel( CalypColorSpace eOutputSpace ) const; }; +std::ostream& operator<<( std::ostream& os, const CalypPixel& p ); + /** * \class CalypPlane * \ingroup CalypLibGrp CalypPlaneGrp diff --git a/lib/CalypPixel.cpp b/lib/CalypPixel.cpp index 20cfa0b..87d74f7 100644 --- a/lib/CalypPixel.cpp +++ b/lib/CalypPixel.cpp @@ -141,6 +141,25 @@ CalypPixel CalypPixel::operator*( const double& op ) const return result; } +auto CalypPixel::operator==( const CalypPixel& other ) const -> bool +{ + return colorSpace() == other.colorSpace() && + std::equal( m_pelComp.begin(), m_pelComp.end(), other.components().begin() ); +} + +std::ostream& operator<<( std::ostream& os, const CalypPixel& p ) +{ + if( p.colorSpace() == CLP_COLOR_RGB || p.colorSpace() == CLP_COLOR_YUV ) + { + os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ")"; + } + else + { + os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ", " << p[3] << ")"; + } + return os; +} + CalypPixel CalypPixel::convertPixel( CalypColorSpace eOutputSpace ) const { if( m_colorSpace == eOutputSpace ) diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index 1579749..b44200c 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -235,7 +235,7 @@ public: handler->m_uiHeight = height; handler->m_iPixelFormat = input_format; handler->m_uiBitsPerPixel = bitsPel; - handler->m_iEndianness = endianness; + handler->m_iEndianness = bitsPel > 8 ? endianness : CLP_BIG_ENDIAN; handler->m_dFrameRate = frame_rate; if( !handler->openHandler( cFilename, isInput ) ) diff --git a/lib/catch2/CMakeLists.txt b/lib/catch2/CMakeLists.txt index 8bae1ea..6216870 100644 --- a/lib/catch2/CMakeLists.txt +++ b/lib/catch2/CMakeLists.txt @@ -2,9 +2,13 @@ # CMakeLists for Calyp lis tests using catch2 # -# ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\") +SET(Calyp_Lib_Catch2_Tests_SRCS + CalypLibTests.cpp + CalypStreamTests.cpp + CalypFrameTests.cpp +) -SET(Calyp_Lib_Catch2_Tests_SRCS CalypFrameTests.cpp) +ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\") ADD_EXECUTABLE(CalypLibCatch2Tests ${Calyp_Lib_Catch2_Tests_SRCS}) TARGET_LINK_LIBRARIES(CalypLibCatch2Tests ${PROJECT_LIBRARY} Catch2::Catch2) diff --git a/lib/catch2/CalypFrameTests.cpp b/lib/catch2/CalypFrameTests.cpp index a45fe6e..dbb7643 100644 --- a/lib/catch2/CalypFrameTests.cpp +++ b/lib/catch2/CalypFrameTests.cpp @@ -22,7 +22,6 @@ * \brief CalypFrame general tests */ -#define CATCH_CONFIG_MAIN #include #include "CalypFrame.h" @@ -32,10 +31,10 @@ TEST_CASE( "create a 256x128 frame with 8 bits in YUV420 format", "CalypFrame" ) // Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 ); CalypFrame testFrame( 256, 128, CLP_YUV420P, 8 ); - REQUIRE( testFrame.getWidth() == 256 ); - REQUIRE( testFrame.getHeight() == 128 ); - REQUIRE( testFrame.getPelFormat() == CLP_YUV420P ); - REQUIRE( testFrame.getBitsPel() == 8 ); + CHECK( testFrame.getWidth() == 256 ); + CHECK( testFrame.getHeight() == 128 ); + CHECK( testFrame.getPelFormat() == CLP_YUV420P ); + CHECK( testFrame.getBitsPel() == 8 ); } TEST_CASE( "create a 256x128 frame with 10 bits in YUV420 format", "CalypFrame" ) @@ -43,10 +42,10 @@ TEST_CASE( "create a 256x128 frame with 10 bits in YUV420 format", "CalypFrame" // Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 ); CalypFrame testFrame( 256, 128, CLP_YUV420P, 10 ); - REQUIRE( testFrame.getWidth() == 256 ); - REQUIRE( testFrame.getHeight() == 128 ); - REQUIRE( testFrame.getPelFormat() == CLP_YUV420P ); - REQUIRE( testFrame.getBitsPel() == 10 ); + CHECK( testFrame.getWidth() == 256 ); + CHECK( testFrame.getHeight() == 128 ); + CHECK( testFrame.getPelFormat() == CLP_YUV420P ); + CHECK( testFrame.getBitsPel() == 10 ); } TEST_CASE( "create a 256x128 frame with 16 bits in YUV420 format", "CalypFrame" ) @@ -54,8 +53,8 @@ TEST_CASE( "create a 256x128 frame with 16 bits in YUV420 format", "CalypFrame" // Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 ); CalypFrame testFrame( 256, 128, CLP_YUV420P, 16 ); - REQUIRE( testFrame.getWidth() == 256 ); - REQUIRE( testFrame.getHeight() == 128 ); - REQUIRE( testFrame.getPelFormat() == CLP_YUV420P ); - REQUIRE( testFrame.getBitsPel() == 16 ); + CHECK( testFrame.getWidth() == 256 ); + CHECK( testFrame.getHeight() == 128 ); + CHECK( testFrame.getPelFormat() == CLP_YUV420P ); + CHECK( testFrame.getBitsPel() == 16 ); } diff --git a/lib/catch2/CalypLibTests.cpp b/lib/catch2/CalypLibTests.cpp new file mode 100644 index 0000000..7bff40f --- /dev/null +++ b/lib/catch2/CalypLibTests.cpp @@ -0,0 +1,26 @@ +/* This file is a part of plaYUVer 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 CalypLibTests.cpp + * \brief CalypLib main test file + */ + +#define CATCH_CONFIG_MAIN +#include diff --git a/lib/catch2/CalypStreamTests.cpp b/lib/catch2/CalypStreamTests.cpp new file mode 100644 index 0000000..0029dab --- /dev/null +++ b/lib/catch2/CalypStreamTests.cpp @@ -0,0 +1,112 @@ +/* This file is a part of plaYUVer 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 CalypStreamTests.cpp + * \brief CalypStream general tests + */ + +#include +#include + +#include "CalypFrame.h" +#include "CalypStream.h" + +constexpr int kFrameRate{ 30 }; +constexpr bool kIsInput{ true }; + +auto getFileTestFilename( const char* test_sequence ) -> std::string +{ + return std::string( CALYP_TEST_DATA_DIR ) + std::string( "/" ) + std::string( test_sequence ); +} + +TEST_CASE( "Can open a YUV 420p file", "CalypStream" ) +{ + constexpr int kWidth{ 352 }; + constexpr int kHeight{ 288 }; + constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV420P }; + constexpr int kBitsPel{ 8 }; + constexpr auto KEndianness{ CLP_INVALID_ENDIANESS }; + + CalypStream test_stream; + auto result = test_stream.open( getFileTestFilename( "Foreman.yuv" ), kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, true ); + + REQUIRE( result ); + + CHECK( test_stream.getWidth() == kWidth ); + CHECK( test_stream.getHeight() == kHeight ); + CHECK( test_stream.getBitsPerPixel() == kBitsPel ); + CHECK( test_stream.getFormatName() == "YUV" ); + CHECK( test_stream.getCodecName() == "Raw Video" ); + CHECK( test_stream.getEndianess() == CLP_BIG_ENDIAN ); + + const auto* frame = test_stream.getCurrFrame(); + + CHECK( frame->getPixel( 2, 0 ) == CalypPixel{ CLP_COLOR_YUV, 201, 129, 125 } ); + CHECK( frame->getPixel( 336, 278 ) == CalypPixel{ CLP_COLOR_YUV, 99, 111, 142 } ); +} + +TEST_CASE( "Can open .batatas file as RAW video", "CalypStream" ) +{ + constexpr int kWidth{ 352 }; + constexpr int kHeight{ 288 }; + constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV420P }; + constexpr int kBitsPel{ 8 }; + constexpr auto KEndianness{ CLP_INVALID_ENDIANESS }; + + bool force_raw{ false }; + + SECTION( "Without forcing raw video" ) + { + CalypStream test_stream; + bool result{ false }; + try + { + result = test_stream.open( getFileTestFilename( "Foreman.batatas" ), kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kIsInput, force_raw ); + } + catch( ... ) + { + // NOLINT + } + + CHECK( !result ); + } + + SECTION( "Forcing raw video" ) + { + force_raw = true; + + CalypStream test_stream; + auto result = test_stream.open( getFileTestFilename( "Foreman.batatas" ), kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kIsInput, force_raw ); + + REQUIRE( result ); + + CHECK( test_stream.getWidth() == kWidth ); + CHECK( test_stream.getHeight() == kHeight ); + CHECK( test_stream.getBitsPerPixel() == kBitsPel ); + CHECK( test_stream.getFormatName() == "YUV" ); + CHECK( test_stream.getCodecName() == "Raw Video" ); + CHECK( test_stream.getEndianess() == CLP_BIG_ENDIAN ); + + const auto* frame = test_stream.getCurrFrame(); + + CHECK( frame->getPixel( 2, 0 ) == CalypPixel{ CLP_COLOR_YUV, 201, 129, 125 } ); + CHECK( frame->getPixel( 336, 278 ) == CalypPixel{ CLP_COLOR_YUV, 99, 111, 142 } ); + } +} \ No newline at end of file diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 1851162..9fe2bf1 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -85,15 +85,15 @@ ADD_MODULE_USE_OPENCV( imgproc photo ) -ADD_MODULE_USE_OPENCV( - ThreeSixtyDynamicDownsampling - "ThreeSixtyDynamicDownsampling" - VERSION - 3.1.0 - MODULES - core - imgproc -) +# ADD_MODULE_USE_OPENCV( +# ThreeSixtyDynamicDownsampling +# "ThreeSixtyDynamicDownsampling" +# VERSION +# 3.1.0 +# MODULES +# core +# imgproc +# ) ADD_MODULE_USE_OPENCV( ThreeSixtyNxN "ThreeSixtyNxN" diff --git a/modules/SaliencyBasedFiltering.cpp b/modules/SaliencyBasedFiltering.cpp index 26dc989..8678a98 100644 --- a/modules/SaliencyBasedFiltering.cpp +++ b/modules/SaliencyBasedFiltering.cpp @@ -53,10 +53,6 @@ bool SaliencyBasedFiltering::create( std::vector apcFrameList ) if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_RESOLUTION ) ) return false; } - if( apcFrameList[1]->getNumberChannels() != 1 ) - { - return false; - } m_pcProcessedFrame = std::make_unique( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(),