plug-ins: bmp-load - 64bpp BMP: error in s2.13 conversion
Environment/Versions
- GIMP version: 2.99.19
- Package: current git (849de6c8)
- Operating System: All
Description of the bug
The new code (db0f6859) for importing 64bpp BMPs has some issues in the value conversion from s2.13 fixed-point format to u16 values.
- The divisor to shift the decimal point is 0x1fff when it should be 0x2000 (more obvious when you think base-10: you divide by 100, not by 99, to shift the decimal point)
- That division isn't needed at all, neither are the other floating point calculations. All that is needed is a multiplication by 0xffff (scaling for u16) and a right shift by 13 bits (shifting of decimal point).
- The s2.13 format has a range of -4.0 to 3.999... Should be clipped to 0.0 to 1.0 in order to avoid integer overflow in the resulting u16 value.
Attached is a patch '0001-plug-ins-64bpp-BMP-s2.13-to-u16-conversion-fix.patch' which fixes these issues 1. to 3.
0001-plug-ins-64bpp-BMP-s2.13-to-u16-conversion-fix.patch
- This one I am not sure about: Are 64bpp BMPs always linear light? The current code assumes non-linear. The only sample I have is from Jason Summers' BMPSuite, and that one is in linear light. (change would be easy in lines 692,693 of bmp-load.c)
- As the value range in 64bpp BMPs is -4.0 to 3.999..., would it make sense to load the BMP as float, in case that range is actually used?
Rupert