[FEATURE REQUEST] - float_half maketx/make_texture conversion
Can the maketx argument --attrib half be applied ONLY when the source texture is float? I am trying to switch our own customized version of OpenImageIO to the mainline version and one of the last major differences is how texture conversion is handled. In our custom system, integer textures are converted "as-is", but floating-point textures are always deliberately converted to half-float for performance reasons (less data off disc = faster load time, and half-float = less memory in the texture cache and for us, half-float is plenty of precision at render-time).
If I call maketx like so (assuming the input file is a 32bit float texture):
maketx --filter lanczos3 --fixnan box3 --oiio --wrap periodic --attrib tiff:half 1 --d half --threads 4 -o /path/to/outputfile.tx /path/to/inputfile.tif
then the result will be half-float, which is fine, but so will all integer input textures (i.e. 8-bit integer textures will be up-converted to half-float which I don't want, as that will lower performance).
I would instead like an option that ONLY applies to floating-point input textures, and allows them to be generated as half-float
Would is make sense to half a new option called --attribute tiff:float_half or, alternatively, --d float_half which can specifically target floating-point input textures?
Custom hacking is all I've considered
Alternatively, writing code to open the file, and check the input before calling OIIO::ImageBufAlgo::make_texture is another option, but that feels "dirty" since I'd need to access the file-handle twice, one in my code to check it, then again in OIIO to do the conversion. I'd like it to be handled all in one place.
Without this feature OpenImageIO is 30% slower than our existing system I expect that halving the data bandwidth will lower this difference in performance to 15%, which is MUCH closer to where I want to be.
Coincidentally, #3243 gives you exactly the tools you need (if you use oiiotool rather than maketx, and after that patch is merged) via the new control flow operators. I think this would work:
oiiotool /path/to/inputfile.tif -if "{eq(TOP.file_extension, '.tif') && (eq(TOP.format, 'float') || eq(TOP.format, 'half'))}" --attrib tiff:half 1 -d half --endif -otex /path/to/outputfile.tx /path/to/inputfile.tif
Do you really have full float source images that you want to convert to half? Or do you just have half that you want to keep half?
If that whole "if" business is just too verbose, we can make a direct option like the "tif:float_half" as you suggest.