-
-
Notifications
You must be signed in to change notification settings - Fork 715
BUG: MINCImageIO should use signed char for CHAR and MI_TYPE_BYTE
#5470
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
BUG: MINCImageIO should use signed char for CHAR and MI_TYPE_BYTE
#5470
Conversation
`MINCImageIO::Write` should use `signed char` for the estimation of the min and the max pixel value, when the pixel component type is `IOComponentEnum::CHAR`. Both `IOComponentEnum::CHAR` and `MI_TYPE_BYTE` specify a _signed_ type, whereas the default `char` might be unsigned (for example, when using GCC compiler option `-funsigned-char`). Obviously the estimation of min and max pixel value may go wrong when the pixels are incorrectly assumed to be unsigned.
|
Glad to hear that compiler flag has been useful to track down issues! |
|
@gdevenyi may interest you |
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.
Pull Request Overview
This PR fixes a bug in MINCImageIO where the wrong char type was used for min/max pixel value calculations. The issue occurs when IOComponentEnum::CHAR and MI_TYPE_BYTE are used with compilers that default to unsigned char (e.g., GCC with -funsigned-char), leading to incorrect pixel value range estimation.
- Changes
chartosigned charin the template parameter forget_buffer_min_maxfunction call - Ensures consistent handling of signed byte data regardless of compiler char signedness defaults
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.
💯
87a4fff
into
InsightSoftwareConsortium:main
Both `VTKPolyDataMeshIO::WritePoints` and `VTKPolyDataMeshIO::WritePointData` originally casted the `buffer` to plain `char *` for component type `CHAR` (using `CASE_INVOKE_WITH_COMPONENT_TYPE`). However, `CHAR` indicates that the component type is _signed_ char, whereas the default `char` might be unsigned. Follow-up to pull request InsightSoftwareConsortium#5470 commit 70fbb2b "BUG: MINCImageIO should use `signed char` for `CHAR` and `MI_TYPE_BYTE`"
`VTKPolyDataMeshIO` originally casted the `buffer` to plain `char *` for component type `CHAR`. However, `CHAR` indicates that the component type is _signed_ char, whereas the default `char` might be unsigned. Follow-up to pull request InsightSoftwareConsortium#5470 commit 70fbb2b "BUG: MINCImageIO should use `signed char` for `CHAR` and `MI_TYPE_BYTE`"
`VTKPolyDataMeshIO` originally casted the `buffer` to plain `char *` for component type `CHAR`. However, `CHAR` indicates that the component type is _signed_ char, whereas the default `char` might be unsigned. Follow-up to pull request InsightSoftwareConsortium#5470 commit 70fbb2b "BUG: MINCImageIO should use `signed char` for `CHAR` and `MI_TYPE_BYTE`"
`VTKPolyDataMeshIO` originally casted the `buffer` to plain `char *` for component type `CHAR`. However, `CHAR` indicates that the component type is _signed_ char, whereas the default `char` might be unsigned. Follow-up to pull request InsightSoftwareConsortium#5470 commit 70fbb2b "BUG: MINCImageIO should use `signed char` for `CHAR` and `MI_TYPE_BYTE`"
`VTKPolyDataMeshIO` originally casted the `buffer` to plain `char *` for component type `CHAR`. However, `CHAR` indicates that the component type is _signed_ char, whereas the default `char` might be unsigned. Follow-up to pull request InsightSoftwareConsortium#5470 commit 70fbb2b "BUG: MINCImageIO should use `signed char` for `CHAR` and `MI_TYPE_BYTE`"
`VTKPolyDataMeshIO` originally casted the `buffer` to plain `char *` for component type `SCHAR`. However, `SCHAR` indicates that the component type is _signed_ char. Follow-up to pull request InsightSoftwareConsortium#5470 commit 70fbb2b "BUG: MINCImageIO should use `signed char` for `CHAR` and `MI_TYPE_BYTE`"
MINCImageIO::Writeshould usesigned charfor the estimation of the min and the max pixel value, when the pixel component type isIOComponentEnum::CHAR. BothIOComponentEnum::CHARandMI_TYPE_BYTEspecify a signed type, whereas the defaultcharmight be unsigned (for example, when using GCC compiler option-funsigned-char).Obviously the estimation of min and max pixel value may go wrong when the pixels are incorrectly assumed to be unsigned.
@blowekamp This little bug fix is still a spinoff from your suggestion to try to build ITK using
-funsigned-char😃