Skip to content

ImageIOBase: Simplify GetComponentSize(), deprecate SetTypeInfo, rename TPixel to TComponent#5438

Merged
thewtex merged 3 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:ImageIOBase-GetComponentSize-style
Jun 24, 2025
Merged

ImageIOBase: Simplify GetComponentSize(), deprecate SetTypeInfo, rename TPixel to TComponent#5438
thewtex merged 3 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:ImageIOBase-GetComponentSize-style

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker commented Jun 24, 2025

Three style commits:

  • Let GetComponentSize() call GetComponentTypeTraits, instead of having a boilerplate switch
  • Deprecated SetTypeInfo(const TPixel *), which was introduced by commit 383216f (11 Nov 2010), and appears unimplemented and unused
  • Renamed template parameters from TPixel to TComponent, just like itk::RGBPixel<TComponent>:
    template <typename TComponent = unsigned short>
    class ITK_TEMPLATE_EXPORT RGBPixel : public FixedArray<TComponent, 3>

N-Dekker added 3 commits June 24, 2025 11:59
Replaced an exhaustive (boilerplate) `switch` statement.

Made `ComponentTypeTraits::sizeOfComponent` an `unsigned int`, as that is also
the return type of GetComponentSize().
`SetTypeInfo(const TPixel *)` was introduced with commit 383216f,
11 Nov 2010, but it was never implemented and it was not specialized.
When a template parameter specifies a pixel _component_ type, rather than a
pixel type, it appears clearer to name it `TComponent` (similar to
`itk::RGBPixel<TComponent>` in "itkRGBPixel.h").

Adjusted the documentation of `MapPixelType` accordingly.
@github-actions github-actions bot added the area:IO Issues affecting the IO module label Jun 24, 2025
@N-Dekker N-Dekker marked this pull request as ready for review June 24, 2025 13:58
@hjmjohnson hjmjohnson requested a review from Copilot June 24, 2025 17:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR streamlines component size retrieval, removes an unused legacy method, and aligns template parameter naming with upstream conventions.

  • Simplify GetComponentSize() by delegating to GetComponentTypeTraits
  • Deprecate unimplemented SetTypeInfo(const TPixel*) via itkLegacyMacro
  • Rename template parameter TPixel to TComponent and adjust trait member type

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Modules/IO/ImageBase/src/itkImageIOBase.cxx Simplified GetComponentSize() implementation using type traits
Modules/IO/ImageBase/include/itkImageIOBase.h Deprecated legacy SetTypeInfo, updated GetNumberOfBitsOfComponentType, renamed TPixel to TComponent, and changed sizeOfComponent to unsigned int
Comments suppressed due to low confidence (3)

Modules/IO/ImageBase/src/itkImageIOBase.cxx:357

  • Add unit tests for each IOComponentEnum value—especially UNKNOWNCOMPONENTTYPE—to verify that GetComponentSize returns correct sizes and throws on unknown types.
ImageIOBase::GetComponentSize() const

Modules/IO/ImageBase/src/itkImageIOBase.cxx:359

  • [nitpick] Use auto for sizeOfComponent to decouple from unsigned int, e.g., if (const auto sizeOfComponent = ... so that changes in GetComponentTypeTraits don't require updating this type.
  if (const unsigned int sizeOfComponent = GetComponentTypeTraits(m_ComponentType).sizeOfComponent; sizeOfComponent > 0)

Modules/IO/ImageBase/include/itkImageIOBase.h:967

  • [nitpick] Consider using size_t for sizeOfComponent to match platform-dependent sizes and avoid potential narrowing if component sizes ever exceed UINT_MAX.
    unsigned int sizeOfComponent;

Copy link
Copy Markdown
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks, Niels!

@thewtex thewtex merged commit ac62746 into InsightSoftwareConsortium:main Jun 24, 2025
16 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants