Fast clamp
Sometimes one needs to bound a value between two limits, min and max. This operation is called clamp. Let’s consider the clamp of an integer to the interval [0, 255]. int clamp(int x) { return x 255 ? 255 : x; } JPEG decoding requires three such clamp operations per decoded pixel, so we’d like [...]