# \`long double\` support for ImageIO, MeshIO pixels?

**URL:** https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570
**Category:** Engineering
**Created:** [June 24, 2025, 4:49pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570 "2025-06-24T16:49:00Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [June 24, 2025, 4:49pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/1 "2025-06-24T16:49:00Z")

</div>

Should ITK’s ImageIO and MeshIO both support `long double` as a possible type for pixel components? The `IOComponent` enum class has an enumerator for `long double`, named `LDOUBLE`, at [ITK/Modules/Core/Common/include/itkCommonEnums.h at 45b4e6cfb8cda8f156ed9c67a38b7a3a71dae8ee · InsightSoftwareConsortium/ITK · GitHub](https://github.com/InsightSoftwareConsortium/ITK/blob/45b4e6cfb8cda8f156ed9c67a38b7a3a71dae8ee/Modules/Core/Common/include/itkCommonEnums.h#L92)

It appears that `long double` is now only supported by MeshIO, not by ImageIO. Honestly I don’t really have a use case for `long double`, and I realize that its size is very platform dependent: typically either 64 bits, 80 bits, or 128 bits. Is `long double` still important to other users?

I’m asking, just because I’m considering some refactoring, to share code between ImageIO and MeshIO. Specifically, `MeshIOBase::MapComponentType` and `ImageIOBase::MapPixelType` are very similar, but the first one supports `long double`, and the second one does not!

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 24, 2025, 6:06pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/2 "2025-06-24T18:06:01Z")

</div>

`long double` was interesting with IA32 and older architectures in x64 series, because 80-bit float was a (the?) native type. With AMD64 that disappeared, which has 64-bit native float.

As removals are easier, I have a mild preference for adding `LDOUBLE` to `ImageIO`.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 24, 2025, 6:23pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/3 "2025-06-24T18:23:07Z")

</div>

The concept of having the ImageIO express pixel component types as non-portable types is problematic. Files are potable between systems, these descriptive types are not. IMHO describing the component type as “long double” is not descriptive and will not be well defined.

For comparison of a portable specification, consider the ZARR dtype spec:

> **[Zarr Storage Specification Version 2 — Zarr specs documentation](https://zarr-specs.readthedocs.io/en/latest/v2/v2.0.html#data-type-encoding)**

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [June 26, 2025, 10:16am UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/4 "2025-06-26T10:16:06Z")

</div>

Thanks to you both @dzenanz and @blowekamp So basically, there are three possible options:

- Let ImageIO and MeshIO both support `long double`
- Drop `long double` for both ImageIO and MeshIO
- Let MeshIO support `long double`, while ImageIO does not (current situation)

Could it be that `long double` is more relevant for MeshIO than it is for ImageIO, for fundamental reasons? 🤷

By the way, we could of course also add fixed width floating point types, `FLOAT80` and `FLOAT128` to the enum class `IOComponent`, but then they should be processed in a platform/compiler dependent way. (Possibly throw an exception when the platform does not have a floating point type of that size.)

* * *

For the record

It looks like ImageIO never supported LDOUBLE, looking at revision [COMP: Restore GetComponentTypeInfo Method to itk::ImageIOBase · InsightSoftwareConsortium/ITK@aa87186 · GitHub](https://github.com/InsightSoftwareConsortium/ITK/commit/aa87186ca0efdc580b0e989cfcfd0a7304b344a3) (Feb 2011):

> <https://github.com/InsightSoftwareConsortium/ITK/blob/aa87186ca0efdc580b0e989cfcfd0a7304b344a3/Code/IO/itkImageIOBase.h#L640-L650>

On the other hand, it looks like MeshIO _always_ supported LDOUBLE, looking at revision [ENH: Add mesh IO · InsightSoftwareConsortium/ITK@9403e3b · GitHub](https://github.com/InsightSoftwareConsortium/ITK/commit/9403e3b37a2250fe6fa2ef61de7c19cf014689ba) (Aug 2011):

> <https://github.com/InsightSoftwareConsortium/ITK/blob/9403e3b37a2250fe6fa2ef61de7c19cf014689ba/Modules/IO/Mesh/include/itkMeshIOBase.h#L762-L775>

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 26, 2025, 12:04pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/5 "2025-06-26T12:04:28Z")

</div>

Does “long double” for ImageIO provide anything meaningful? Does any Image file format support “long double”?

Also how would FLOAT80 be stores as in a buffer? 3-bytes with poor alignment? 4-bytes?

I don’t see a need to for this and you state that you don’t have a use case either. There are details here that could be done incorrectly that would cause more problems if an implementation with a well defined use case was required.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 26, 2025, 1:56pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/6 "2025-06-26T13:56:11Z")

</div>

Brad, do you prefer leaving things as is, or removing LDOUBLE from MeshIO?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 26, 2025, 2:14pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/7 "2025-06-26T14:14:18Z")

</div>

I do not know if the MeshIO is usable or functional with long double. A quick grep though the IO code seems to indicate that there are a large number of occurrences of LDOUBLE in many of the MeshIO implementation so this would indicate good support for it at one point.

The ImageIOBase::IOComponentEnum is already itk::IOComponentEnum which contains LDOUBLE in the enum. So it looks like this enum is already valid if ImageIO classes.

In that context, defining the behavior or LDOUBLE for imageIO seems more reasonable. I hope that all the ImageIO implementations have correct handling of the “default” case for this enum.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [June 26, 2025, 3:13pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/8 "2025-06-26T15:13:51Z")

</div>

Ideally I would like to move the enum class `{ UCHAR, CHAR, ..., LDOUBLE }`, as well as the type-to-enum-value map (`Map...Type<T>`) to “Core/Common”, so that they can be shared between the ImageIO and MeshIO. What do you think?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 26, 2025, 3:26pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/9 "2025-06-26T15:26:25Z")

</div>

Isn’t the `IOComponent` already in Core/Common/itkCommonEnums.h? What change are you proposing?

Have a common ctype-to-enum-value map seems to be a good idea to me.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [June 26, 2025, 6:03pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/10 "2025-06-26T18:03:57Z")

</div>

Yes indeed, `IOComponent` is already in [Core/Common/itkCommonEnums.h](https://github.com/InsightSoftwareConsortium/ITK/blob/ac62746139aee8bd6222db385b2394238bb592bb/Modules/Core/Common/include/itkCommonEnums.h#L77). (Sorry I was mistaken!)

So I would then just propose a common ctype-to-enum-value map.

Note that there appears another difference between `MeshIOBase` and `ImageIOBase`. `MeshIOBase::MapComponentType` unconditionally maps `char` to `CHAR`, whereas `ImageIOBase::MapPixelType` maps `char` to either `CHAR` or `UCHAR`, depending on the signedness of `char`: if `char` is signed, it is mapped to `CHAR`, otherwise to `UCHAR`. This difference should also be resolved, when introducing a common ctype-to-enum-value map.

Currently `IOComponent` has distinct enum values for two char types: CHAR and UCHAR. I think it would be easier if we would have an extra enum value for SIGNED\_CHAR, because in C++ `char` and `signed char` are distinct type. And then unconditionally map `char` to CHAR, and `signed char` to SIGNED\_CHAR, right? Or would that break too much legacy code?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 26, 2025, 6:38pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/11 "2025-06-26T18:38:07Z")

</div>

> [@Niels\_Dekker](#):
>
> Currently `IOComponent` has distinct enum values for two char types: CHAR and UCHAR. I think it would be easier if we would have an extra enum value for SIGNED\_CHAR, because in C++ `char` and `signed char` are distinct type. And then unconditionally map `char` to CHAR, and `signed char` to SIGNED\_CHAR, right? Or would that break too much legacy code?

It sounds like you are thinking the CHAR enum is describing the `char` C type ( which is incorrect). The actual usage of it is to describe a signed char/8-bit type. Changing the definition of the CHAR enum would not be good. Perhaps adding an alias of “SIGNED\_CHAR == CHAR” would be descriptive and useful.

Also 8-bit integers are only signed or unsigned. The three states of C’s “char” types is an artifact of C and not data. The ImageIO interface really should be describing what is stored on the disk and not the state of types and sizes at programming language level, IMHO. That is to say I have a long term frustration with this interface not providing fixed width integer types.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [June 26, 2025, 6:50pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/12 "2025-06-26T18:50:35Z")

</div>

> It sounds like you are thinking the CHAR enum is describing the `char` C type

Thanks, but I guess most users would think so as well. 🤷 And so does `MeshIOBase`. (Assuming that `MeshIOBase` can actually _think_ 😉.)

> [@blowekamp](#):
>
> That is to say I have a long term frustration with this interface not providing fixed width integer types.

_That_ frustration is over now, right? 😃

[ENH: Fixed width type enums (INT8, UINT64, FLOAT64, ...) for IOComponent by N-Dekker · Pull Request #5410 · InsightSoftwareConsortium/ITK · GitHub](https://github.com/InsightSoftwareConsortium/ITK/pull/5410)

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 26, 2025, 7:11pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/13 "2025-06-26T19:11:09Z")

</div>

But the CHAR enum type ( for ImageIO ) currently must represents signed 8-bit data. There is not other way to represent as a component type, so it much be signed:

> <https://github.com/SimpleITK/SimpleITK/blob/master/Code/IO/src/sitkImageReaderBase.cxx#L266-L267>

(Those later cases look like they can be conveniently updated with the new fixed types. )

And yes, 8-bit signed data is real and common with certain file formats. Java does not have an 8-bit unsigned data type. So for Java developer signed 8-bit data/images are very natural.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [June 30, 2025, 11:18am UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/14 "2025-06-30T11:18:31Z")

</div>

FYI, This pull request of mine is somewhat related:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/5445>
>
> Follow-up to pull request https://github.com/InsightSoftwareConsortium/ITK/pull/…5421 commit b209c1a00f2cc042172996631d8cf5a06658fd1a
> "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\`.

Please note this pull request in it current state is only a _style_ PR. It does not address the different behavior between MeshIO and ImageIO regarding the type mapping of CHAR and LDOUBLE (long double). So it may be processed independently.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [July 1, 2025, 11:23am UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/15 "2025-07-01T11:23:21Z")

</div>

I see, SimpleITK’s `sitkImageReaderBase` maps `IOComponentEnum::CHAR` to `int8_t` (which is a signed integer type, by definition), whereas ITK’s `itk::ImageFileReader` maps `IOComponentEnum::CHAR` to `char` (which _might_ be an unsigned integer type):

> <https://github.com/InsightSoftwareConsortium/ITK/blob/0b79fd0c2815197a2c8c4b0bbc8af8013a86d47c/Modules/IO/ImageBase/include/itkImageFileReader.hxx#L485>

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [July 2, 2025, 1:52pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/16 "2025-07-02T13:52:41Z")

</div>

Interesting, thanks of sharing.

For the imageIOs which support signed 8-bit data, they are most likely reporting their data as ENUM::CHAR. Perhaps, “CHAR” should be changed to “signed char”? I think there are some portability issue with the current definitions, but I think it was “working” in practice so it was left alone.

A couple examples:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/09305ce7c3509139ab0ca12047f8e6793b01db74/Modules/IO/MRC/src/itkMRCImageIO.cxx#L138-L148>

> <https://github.com/InsightSoftwareConsortium/ITKIOOMEZarrNGFF/blob/4bd6557d26b00e74f4a23ad657835388ef00a330/src/itkOMEZarrNGFFImageIO.cxx#L63-L65>

Also note I am actively using sighed 8-bit images, for the MRC image file format.

The argument for just the “char” type for being useful would be to represent text. Which I don’t think make sense for the ImageIO class. I don’t believe that this enum is used to represent any meta-data? If you did want to represent text where is a whole other set of text encoding that would be relevant, and that is not something that should opened up.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [July 2, 2025, 4:17pm UTC](https://discourse.itk.org/t/long-double-support-for-imageio-meshio-pixels/7570/17 "2025-07-02T16:17:49Z")

</div>

Thanks @blowekamp

Honestly I don’t know if it’s useful to have a pixel type `char` to represent text. If we agree to only support `signed char` and `unsigned char` (but not plain `char`), I would suggest renaming the enum `CHAR` to `SIGNED_CHAR`.

On the other hand, if there is a use case for plain `char` pixels, let it map unconditionally to the enum `CHAR`, and add a `SIGNED_CHAR` enum, unconditionally mapping `signed char` (not plain `char`).

But honestly I don’t know what to choose 🤷
