I'm trying to understand someone else's code for raw image management.
Here's what I'm looking at:
// Resolution has to be a power of 2.
// This code finds the lowest RxR resolution which has equal or more pixel than requested
uint32_t higher = std::max(resolutionX, resolutionY);
higher--;
higher |= higher >> 1;
higher |= higher >> 2;
higher |= higher >> 4;
higher |= higher >> 8;
higher |= higher >> 16;
higher++;
internResolution = higher;
I understand that |= is the Bitwise Or operator and that >> is the Shift Bits Right operator. What I'm not getting is why the original code was designed this way. I think this pushes Resolution to be a perfect factor of 2, and I'm assuming that is to maintain Pixel perfect integer ratio logic, but this code seems an odd way to get there.
Can someone explain what is going on here, and perhaps why this is designed this way? Is this just an abstruse way to get to "Smallest power of 2 greater than or equal to n"