-
-
Notifications
You must be signed in to change notification settings - Fork 717
ImageIO: Add member functions to get pixel component type traits, remove MapPixelType specializations #5421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thewtex
merged 2 commits into
InsightSoftwareConsortium:master
from
N-Dekker:ComponentTypeTraits
Jun 23, 2025
Merged
ImageIO: Add member functions to get pixel component type traits, remove MapPixelType specializations #5421
thewtex
merged 2 commits into
InsightSoftwareConsortium:master
from
N-Dekker:ComponentTypeTraits
Jun 23, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Directly initialized `MapPixelType::CType` to its intended value in the primary template definition of `MapPixelType`, and removed its specializations. Removed `IMAGEIOBASE_TYPEMAP`, following C++ Core Guidelines, May 8, 2025, "Don’t use macros for program text manipulation", https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es30-dont-use-macros-for-program-text-manipulation
0f52915 to
e498641
Compare
e498641 to
9401fba
Compare
Added three static member functions to ImageIOBase:
IsComponentTypeFloatingPoint(IOComponentEnum)
IsComponentTypeUnsigned(IOComponentEnum)
GetNumberOfBitsOfComponentType(IOComponentEnum)
Eases estimating whether a component type is floating point, whether the type
is unsigned, and estimating its number of bits, respectively.
9401fba to
3604e0c
Compare
thewtex
approved these changes
Jun 23, 2025
Member
thewtex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
N-Dekker
added a commit
to N-Dekker/ITK
that referenced
this pull request
Jun 27, 2025
Follow-up to pull request InsightSoftwareConsortium#5421 commit b209c1a "STYLE: Remove template specializations of `ImageIOBase::MapPixelType`" Note that `MeshIOBase::MapComponentType` supports `long double` as pixel component type, whereas `ImageIOBase::MapPixelType` does not. Moreover, `MeshIOBase::MapComponentType` unconditionally maps `char` to `CHAR`, whereas `ImageIOBase::MapPixelType` maps `char` to either `CHAR` or `UCHAR`, depending on the signedness of `char`.
N-Dekker
added a commit
to N-Dekker/ITK
that referenced
this pull request
Jul 10, 2025
`ImageIOBase::GetComponentTypeTraits` incorrectly assumed that the plain `char` type is always mapped to `IOComponentEnum::CHAR`. However, that isn't the case when the default `char` type is an unsigned type (as can be specified by GCC option `-funsigned-char` and MSVC option `/J`). This bug was introduced with pull request InsightSoftwareConsortium#5421 commit 3604e0c "ENH: Ease getting type traits of pixel components from ImageIO" (merged to the master branch on June 23, 2025). The bug caused incorrect return values from the following function calls: ImageIOBase::GetNumberOfBitsOfComponentType(IOComponentEnum::INT8); ImageIOBase::GetNumberOfBitsOfComponentType(IOComponentEnum::CHAR); ImageIOBase::GetComponentTypeFromTypeTraits(false, false, 0); ImageIOBase::GetComponentTypeFromTypeTraits(false, false, 8); As was observed from the static_assert failures in "itkImageIOBaseTest.cxx", when using the compiler option that makes the default `char` unsigned.
hjmjohnson
pushed a commit
that referenced
this pull request
Jul 11, 2025
`ImageIOBase::GetComponentTypeTraits` incorrectly assumed that the plain `char` type is always mapped to `IOComponentEnum::CHAR`. However, that isn't the case when the default `char` type is an unsigned type (as can be specified by GCC option `-funsigned-char` and MSVC option `/J`). This bug was introduced with pull request #5421 commit 3604e0c "ENH: Ease getting type traits of pixel components from ImageIO" (merged to the master branch on June 23, 2025). The bug caused incorrect return values from the following function calls: ImageIOBase::GetNumberOfBitsOfComponentType(IOComponentEnum::INT8); ImageIOBase::GetNumberOfBitsOfComponentType(IOComponentEnum::CHAR); ImageIOBase::GetComponentTypeFromTypeTraits(false, false, 0); ImageIOBase::GetComponentTypeFromTypeTraits(false, false, 8); As was observed from the static_assert failures in "itkImageIOBaseTest.cxx", when using the compiler option that makes the default `char` unsigned.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area:IO
Issues affecting the IO module
type:Testing
Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added three static member functions to ImageIOBase:
Eases estimating whether a component type is floating point, whether the type is unsigned, and estimating its number of bits, respectively.
Removed the template specializations of
MapPixelType<TPixel>, to avoid GCC compile errors sayingerror: specialization of 'itk::ImageIOBase::MapPixelType' after instantiation. Presented as "STYLE" commit, as it would originally just be a nicety 😃