Clamps a pixel to the valid range of values for the pixel format.
pixel
@override int clamp(int pixel) => pixel.clamp(0, length - 1);