0

When you use Image I/O on macOS, there's an option kCGImageSourceShouldAllowFloat which is documented as follows:

Whether the image should be returned as a CGImage object that uses floating-point values, if supported by the file format. CGImage objects that use extended-range floating-point values may require additional processing to render in a pleasing manner.

But it doesn’t say what file formats support it or what the benefits are, just that it might be slower.

Does anyone know what file formats support this and what the benefits would be?

Sindre Sorhus
  • 62,972
  • 39
  • 168
  • 232

1 Answers1

2

TIFF files support floating point values. For example, the 128 bits per pixel format accepts 32-bit float components. See About Bitmap Images and Image Masks. Also see Supported Pixel Formats for table of supported pixel formats for graphics contexts.

In terms of the benefits of floating point, 32 bits per channel, it just means that you have more possible gradations of colors per channel. In general you can’t see this with the naked eye (over 16 bits per channel), but if you start applying adjustments (traditionally, multiple curves or levels adjustments) it means that you’re less likely to experience posterization of the images. So, if (a) the image already has this level of information; and (b) you’re might need to perform these sorts of adjustments to images, then the added data of 32-bits per component might have benefits. Otherwise the benefits of this amount of information is somewhat limited.

Bottom line, use floating point if you are possibly editing assets that might already have floating point components. But often we don’t need or use this level of information. Most of the JPG and PNG assets we deal with are 8 bits per component, anyway.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Thanks for a great explanation. Are there any other image formats supported by macOS other than TIFF that supports floating-point values? – Sindre Sorhus Jan 29 '21 at 06:14
  • I bet there are. I wouldn’t assume that TIFF is the only one. – Rob Jan 29 '21 at 14:51
  • Not that you're likely to encounter them, but candidates include DNG files (which is based upon TIFF format) and FITS (captured by some astrophotography cameras, which supports floating point types). I wouldn't be surprised if there are other, more common formats, that also support floating point types. – Rob Jan 30 '21 at 13:36