Shift and round for B44 pack (matches OpenEXR's shiftAndRound)
| 4335 | |
| 4336 | // Shift and round for B44 pack (matches OpenEXR's shiftAndRound) |
| 4337 | static inline int B44ShiftAndRound(int x, int shift) { |
| 4338 | // Compute y = x * pow(2, -shift), rounded to nearest integer |
| 4339 | // In case of a tie, round to the even one |
| 4340 | x <<= 1; |
| 4341 | int a = (1 << shift) - 1; |
| 4342 | shift += 1; |
| 4343 | int b = (x >> shift) & 1; |
| 4344 | return (x + a + b) >> shift; |
| 4345 | } |
| 4346 | |
| 4347 | // Pack a 4x4 block of HALF values into 14 bytes (matches OpenEXR's pack()) |
| 4348 | // Returns the number of bytes written (14 for normal, 3 for flat if flatfields=true) |