Can one create an NSBitmapImageRep from floating-point data?

In the documentation of -[NSBitmapImageRep initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:], it says that the bitmap format mask can include NSBitmapFormatFloatingPointSamples, which suggests that the answer is yes, but it also says that the number of bits per component can be at most 16, which suggests that the answer is no.

Answered by DTS Engineer in 919978022

Yes. NSBitmapImageRep supports floating-point samples with 32 bits per sample, which is what your experiment found. The Mac OS X 10.4 notes in AppKit Release Notes for macOS 10.12 and Earlier introduced the floating-point format. Their NSBitmapImageRep section says "setting a floating point format requires bits/sample to be 32."

I tested this in macOS 27.2.1. An NSBitmapImageRep with 32 bits per sample and floatingPointSamples initialized, drew through an NSGraphicsContext, and read back the values I drew. With 32-bit integer samples, the initializer returned nil.

The reference page for initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel: doesn't list 32. It says bps "should be one of these values: 1, 2, 4, 8, 12, or 16." That's the problem your report describes. Thanks for posting your result and for filing FB9972520. It remains open and under investigation.

Experimentally, using 32-bit floating-point samples works, so I have filed a bug report on the documentation: FB9972520

Yes. NSBitmapImageRep supports floating-point samples with 32 bits per sample, which is what your experiment found. The Mac OS X 10.4 notes in AppKit Release Notes for macOS 10.12 and Earlier introduced the floating-point format. Their NSBitmapImageRep section says "setting a floating point format requires bits/sample to be 32."

I tested this in macOS 27.2.1. An NSBitmapImageRep with 32 bits per sample and floatingPointSamples initialized, drew through an NSGraphicsContext, and read back the values I drew. With 32-bit integer samples, the initializer returned nil.

The reference page for initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel: doesn't list 32. It says bps "should be one of these values: 1, 2, 4, 8, 12, or 16." That's the problem your report describes. Thanks for posting your result and for filing FB9972520. It remains open and under investigation.