Skip to content

Commit

Permalink
BUG: Fix ColorTableTestSpecialConditionChecker component/pixel mix-up
Browse files Browse the repository at this point in the history
It appears that `ColorTableTestSpecialConditionChecker<TComponent>()`
mixed up color component and pixel types, when it assigned the result of
two `GetColorComponent` calls to a `pixel` variable. `GetColorComponent`
returns a component value, rather than a pixel value.

This bug was found by declaring the `RGBPixel(const ComponentType &)`
constructor `explicit` (locally, temporarily), to detect accidental
implicit conversions from a component value to an `RGBPixel` value.

Follow-up to:
pull request InsightSoftwareConsortium#3221
commit 9cfaf8f
"STYLE: Rename `ColorTable` template parameter `TPixel` to `TComponent`"
  • Loading branch information
N-Dekker authored and hjmjohnson committed Feb 24, 2022
1 parent 0eac15b commit 490ef8c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Modules/Core/Common/test/itkColorTableTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,23 @@ ColorTableTestSpecialConditionChecker(typename itk::ColorTable<TComponent>::Poin

char rgb = 'r';
TComponent zeroComponent(0);
pixel = colors->GetColorComponent(numberOfColors, rgb);
if (pixel != zeroComponent)
TComponent colorComponent = colors->GetColorComponent(numberOfColors, rgb);
if (colorComponent != zeroComponent)
{
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error in itk::ColorTable::GetColorComponent" << std::endl;
std::cerr << "Expected: 0 "
<< ", but got: " << pixel << std::endl;
<< ", but got: " << colorComponent << std::endl;
return EXIT_FAILURE;
}
rgb = 'a';
pixel = colors->GetColorComponent(numberOfColors - 1, rgb);
if (pixel != zeroComponent)
colorComponent = colors->GetColorComponent(numberOfColors - 1, rgb);
if (colorComponent != zeroComponent)
{
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error in itk::ColorTable::GetColorComponent" << std::endl;
std::cerr << "Expected: 0 "
<< ", but got: " << pixel << std::endl;
<< ", but got: " << colorComponent << std::endl;
return EXIT_FAILURE;
}

Expand Down

0 comments on commit 490ef8c

Please sign in to comment.