diff --git a/src/cinder/ip/Resize.cpp b/src/cinder/ip/Resize.cpp index fd94349dd9..1c29f7c5c4 100644 --- a/src/cinder/ip/Resize.cpp +++ b/src/cinder/ip/Resize.cpp @@ -192,6 +192,8 @@ void resample( const vector*> &srcChannels, const FilterBase & } for( size_t chan = 0; chan < srcChannels.size(); ++chan ) { + for( auto &line : linesBuffer ) + line.first = -1; for ( int32_t dstY = 0; dstY < dstHeight; ++dstY ) { // loop over dest scanlines // prepare a weight table for dest y position by makeWeightTable::SUMT>( MAP(dstY, m.sy, m.uy), filter, &filterParamsY, srcHeight, false, &yWeights ); diff --git a/test/unit/proj/cmake/CMakeLists.txt b/test/unit/proj/cmake/CMakeLists.txt index 89c4a39a0f..c2ae6cfc02 100644 --- a/test/unit/proj/cmake/CMakeLists.txt +++ b/test/unit/proj/cmake/CMakeLists.txt @@ -14,6 +14,7 @@ set( SOURCES ${UNIT_DIR}/src/JsonTest.cpp ${UNIT_DIR}/src/ObjLoaderTest.cpp ${UNIT_DIR}/src/RandTest.cpp + ${UNIT_DIR}/src/ResizeTest.cpp ${UNIT_DIR}/src/SystemTest.cpp ${UNIT_DIR}/src/ShaderPreprocessorTest.cpp ${UNIT_DIR}/src/TestMain.cpp diff --git a/test/unit/src/ResizeTest.cpp b/test/unit/src/ResizeTest.cpp new file mode 100644 index 0000000000..8201ebe979 --- /dev/null +++ b/test/unit/src/ResizeTest.cpp @@ -0,0 +1,49 @@ +#include "catch.hpp" +#include "cinder/Surface.h" +#include "cinder/ip/Resize.h" + +using namespace cinder; + +TEST_CASE( "Resize preserves independent color channels", "[ip]" ) +{ + for( int height : { 1, 2, 7 } ) { + for( bool alpha : { false, true } ) { + CAPTURE( height ); + CAPTURE( alpha ); + Surface8u source( 2, height, alpha ); + for( int y = 0; y < height; ++y ) + for( int x = 0; x < 2; ++x ) + source.setPixel( ivec2( x, y ), ColorA8u( 20, 80, 160, 200 ) ); + + auto result = ip::resizeCopy( source, source.getBounds(), ivec2( 4, height * 2 ) ); + for( int y = 0; y < result.getHeight(); ++y ) { + for( int x = 0; x < result.getWidth(); ++x ) { + auto pixel = result.getPixel( ivec2( x, y ) ); + REQUIRE( pixel.r == 20 ); + REQUIRE( pixel.g == 80 ); + REQUIRE( pixel.b == 160 ); + if( alpha ) + REQUIRE( pixel.a == 200 ); + } + } + } + } +} + +TEST_CASE( "Resize preserves floating point color channels", "[ip]" ) +{ + Surface32f source( 2, 1, true ); + for( int x = 0; x < 2; ++x ) + source.setPixel( ivec2( x, 0 ), ColorA( 0.125f, 0.25f, 0.5f, 0.75f ) ); + + auto result = ip::resizeCopy( source, source.getBounds(), ivec2( 4, 2 ) ); + for( int y = 0; y < result.getHeight(); ++y ) { + for( int x = 0; x < result.getWidth(); ++x ) { + auto pixel = result.getPixel( ivec2( x, y ) ); + REQUIRE( pixel.r == Approx( 0.125f ) ); + REQUIRE( pixel.g == Approx( 0.25f ) ); + REQUIRE( pixel.b == Approx( 0.5f ) ); + REQUIRE( pixel.a == Approx( 0.75f ) ); + } + } +} diff --git a/test/unit/vc2022/unit.vcxproj b/test/unit/vc2022/unit.vcxproj index 6f93de3bb0..494a1335b2 100644 --- a/test/unit/vc2022/unit.vcxproj +++ b/test/unit/vc2022/unit.vcxproj @@ -522,6 +522,7 @@ xcopy /y "..\..\..\lib\msw\x86\d3dcompiler_46.dll" "$(OutDir)" + diff --git a/test/unit/vc2022/unit.vcxproj.filters b/test/unit/vc2022/unit.vcxproj.filters index 871e388d35..da8237bed8 100644 --- a/test/unit/vc2022/unit.vcxproj.filters +++ b/test/unit/vc2022/unit.vcxproj.filters @@ -33,6 +33,9 @@ Source Files + + Source Files + Source Files diff --git a/test/unit/xcode/UnitTests.xcodeproj/project.pbxproj b/test/unit/xcode/UnitTests.xcodeproj/project.pbxproj index 999ab5fb7a..52df9220b3 100644 --- a/test/unit/xcode/UnitTests.xcodeproj/project.pbxproj +++ b/test/unit/xcode/UnitTests.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + C41D3E002026091100000001 /* ResizeTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C41D3E002026091100000002 /* ResizeTest.cpp */; }; 000703221DEB7DE00086D6CA /* Path2dTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 000703211DEB7DE00086D6CA /* Path2dTest.cpp */; }; AABB00011234567800CCDDEE /* CinderMathTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AABB00001234567800CCDDEE /* CinderMathTest.cpp */; }; 00C7BBC024120160001D5238 /* MediaTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00C7BBBF24120160001D5238 /* MediaTime.cpp */; }; @@ -51,6 +52,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + C41D3E002026091100000002 /* ResizeTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeTest.cpp; sourceTree = ""; }; 000703211DEB7DE00086D6CA /* Path2dTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Path2dTest.cpp; sourceTree = ""; }; AABB00001234567800CCDDEE /* CinderMathTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CinderMathTest.cpp; sourceTree = ""; }; 006D720219952D00008149E2 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; @@ -217,6 +219,7 @@ 00C7BBBF24120160001D5238 /* MediaTime.cpp */, 4989E06B1DB6889500503C9A /* PolyLineTest.cpp */, 9CA851BA1C1F74000049358B /* RandTest.cpp */, + C41D3E002026091100000002 /* ResizeTest.cpp */, 114CE0E71E2F03930002A384 /* ShaderPreprocessorTest.cpp */, 9CA851BD1C1F74000049358B /* SystemTest.cpp */, 9CA851BF1C1F74000049358B /* UnicodeTest.cpp */, @@ -298,6 +301,7 @@ 117BC7781E836FDF003D8F25 /* FileWatcherTest.cpp in Sources */, 9CA851C01C1F74000049358B /* Base64Test.cpp in Sources */, 9CA851C31C1F74000049358B /* RandTest.cpp in Sources */, + C41D3E002026091100000001 /* ResizeTest.cpp in Sources */, 00C7BBC024120160001D5238 /* MediaTime.cpp in Sources */, 11E4FC4D1C267DB70082A67E /* FftUnit.cpp in Sources */, 4989E06C1DB6889500503C9A /* PolyLineTest.cpp in Sources */,