Repository navigation
Description
As advised in the PR implementing this feature, #2934, I am moving the discussion to a this new issue thread. I have not found any existing issue that quite covers it.
I would like to add ColorType::L32F and ColorType::La32F entries to ColorType, and matching DynamicImage::Luma32F and DynamicImage::LumaA32F variants. I do not have a particularly strong need for either (yet), but think having them makes the library easier to use and the costs are not too steep.
-
The ImageDecoder trait only decodes to valid ColorTypes, although it also provides an ExtendedColorType that indicates roughly the original color type was. This can be somewhat inefficient (bitmaps get expanded to ColorType::L8 at minimum) but ensures users of ImageDecoder do not need to write much casework to handle the possible ColorTypes. (Although I suspect many either decode to DynamicImage, whose conversion functions solve the problem; or read a specific format for which the range of color types is limited.) The most general ColorType is Rgba32F, and almost all image format contents can be converted to it with negligible loss of information. (TIFF's 64F and multiband; and the many YCbCr color types are the main exception.)
There are a few formats that can contain single channel floating point data, most notably EXR, TIFF, DDS, and PHM/PFM, which can hold either f16 or f32. The nearest containing ColorType at the moment is Rgb32F, which requires 3x (or more, for f16) the memory. I expect it may also be briefly confusing if someone loads a depth or bump map and gets RGB data out of it. Encoding such a DynamicImage as grayscale into an image format is possible through the high level API since b773c9d (using DynamicImage::to_luma_32f() followed by ImageBuffer::write_to), but is not easy to find.
-
DynamicImage can contain image data whose specific color type is chosen at runtime. I consider its main uses to be to efficently convert images between color types (for example, given one process that naturally produces a range of color types, and one process that naturally accepts a different range, one can use DynamicImage as the interface between them.), and to perform operations (resizing, cropping) on images of uncertain color type. It provides some methods to convert between color types, like DynamicImage::grayscale, and the many "DynamicImage::to_" methods to pick a specific type.
However, it is missing (or has incomplete) methods that modify just one aspect of the current color type, like the grayscale/rgb distinction, the absence/presence of alpha, and the channel type. Similarly to the PNG transform flags, I think such methods would be useful for those who can afford to process some but not all of the full variability of the color types. Adding L32F and La32F variants makes the set of color types within DynamicImage complete, so that e.g. DynamicImage::grayscale always produces a Luma or LumaA image, that when passed to an external process (image encoder, etc.) will automatically be recognized as a Luma/LumaA image.
The main costs of adding L32F and La32F are, I think, the increases in API complexity (more named functions), in internal complexity (more casework), and in code generation (a proportional increase in monomorphized implementations for DynamicImage, with some central conversion logic growing quadratically. The quadratic growth could be avoided using two-step conversions, but that adds a bit more internal complexity.)
History and related:
-
DynamicImage dates back to 2014 (commit d0b2b7b)
-
The most recent redesign of ColorType, from 2019: Finalize ColorType enum #855 and associated PRs (865), one of which (995) also introduced ExtendedColorType
-
A issue about the Pixel type and how it interacts with F32, 2021-: Let's talk about
Pixel#1523 -
The Rgb32F and Rgba32F types were added in F32 dynamic image #1585 (and preceding work in 1515), both from 2021; closing issues like (795, 1360)
-
An attempt to add L32/La32 color types from 2023, feat: add PixelWithColorType for Luma<f32> and LumaA<f32> #1846
-
Discussion of ExtendedColorType from 2023, Better handling of ExtendColorType images #1849
-
A change to explicitly link DynamicImage and ColorType Exhaustively match in ColorType -> DynamicImage conversion #1848
-
A request to improve f32 grayscale support, since 2023: Support for single-channel f32 grayscale images? #1940
-
An attempt at adding Rgb64F and Rgba64F, from 2022-2024 Add Rgb64FImage and Rgba64FImage #1802
-
An attempt to add L32F to ColorType from 2025, Support single channel f32 tiff files #2536; the TIFF encoder/decoder gained f32 support with a different approach in 2534.
-
An PR to extract the alpha mask portion from 2025, Add alpha mask utilities to ImageBuffer #2544
Side note: Why keep updating the color types?
I think the set of color types supported by an image processing or rendering library should periodically be revisited.
As the years go by, compute and display hardware will continue to improve, and both drive changes in which formats are needed. Over the last forty years we have mostly seen fixed range images and rendering (with RGB values encoded as integers, mapping to [0,1]) with a transfer function applied in the display, but now people have more reasons to use high dynamic range images and floating point types. Specifically:
-
Computation is much less expensive, making it easier to apply physically based rendering methods, which tend to calculate directly with physical quantities (luminance) that have a high dynamic range. This mostly affects 3d rendering, but 3d rendering requires 2d textures for reflective color, emission, and other properties; and produces 2d intermediate images.
-
Improvements in display accuracy make the benefits of accurate color representation visible, so there is stronger interest in HDR and wide color gamut images. While the recent popularization of CICP makes it practical to compress HDR images into u8/u10/u12 color channels, accurate color blending and other computation involves conversion to a (linear, floating point) working space. Increases in display resolution and frame rate have also outpaced single threaded performance, which pushes applications to GPU rendering, where f16 and f32 are well supported color types.
Because hardware has improved, we no longer have a strong need for paletted images, interlaced images, sub-8 bpc formats, or (even) chroma subsampling. But I expect we will want image libraries that support a full set of operations on floating point color types; the only question is when.
Activity
RunDevelopment commentedon Jun 2, 2026
Resolved by #2934.