Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cinder/ip/Resize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ void resample( const vector<const ChannelT<T>*> &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<T,typename SCALETRAIT<T>::SUMT>( MAP(dstY, m.sy, m.uy), filter, &filterParamsY, srcHeight, false, &yWeights );
Expand Down
1 change: 1 addition & 0 deletions test/unit/proj/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions test/unit/src/ResizeTest.cpp
Original file line number Diff line number Diff line change
@@ -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 ) );
}
}
}
1 change: 1 addition & 0 deletions test/unit/vc2022/unit.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ xcopy /y "..\..\..\lib\msw\x86\d3dcompiler_46.dll" "$(OutDir)"</Command>
<ClCompile Include="..\src\MediaTime.cpp" />
<ClCompile Include="..\src\ObjLoaderTest.cpp" />
<ClCompile Include="..\src\RandTest.cpp" />
<ClCompile Include="..\src\ResizeTest.cpp" />
<ClCompile Include="..\src\ShaderPreprocessorTest.cpp" />
<ClCompile Include="..\src\signals\SignalsTest.cpp" />
<ClCompile Include="..\src\SystemTest.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions test/unit/vc2022/unit.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<ClCompile Include="..\src\RandTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\ResizeTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SystemTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
4 changes: 4 additions & 0 deletions test/unit/xcode/UnitTests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
000703211DEB7DE00086D6CA /* Path2dTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Path2dTest.cpp; sourceTree = "<group>"; };
AABB00001234567800CCDDEE /* CinderMathTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CinderMathTest.cpp; sourceTree = "<group>"; };
006D720219952D00008149E2 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down