* @brief mPSNR tone-mapping operator for HDR images. * * @param val The color value to tone map * @param fstop The exposure fstop; should be in range [-125, 125] * * @return The mapped color value in [0.0f, 255.0f] range */
| 65 | * @return The mapped color value in [0.0f, 255.0f] range |
| 66 | */ |
| 67 | static float mpsnr_operator( |
| 68 | float val, |
| 69 | int fstop |
| 70 | ) { |
| 71 | // Fast implementation of pow(2.0, fstop), assuming IEEE float layout |
| 72 | // Memcpy to uint avoids ubsan complaints shift of negative int |
| 73 | unsigned int uscale = 0x3f800000u + (astc::int_as_uint(fstop) << 23); |
| 74 | float scale = astc::uint_as_float(uscale); |
| 75 | |
| 76 | val = powf(val * scale, (1.0f / 2.2f)); |
| 77 | return astc::clamp(val * 255.0f, 0.0f, 255.0f); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @brief mPSNR difference between two values. |
no test coverage detected