It's always the same code, so there's no need for switch statements.
The code accesses pixels in a chunks of 4 bytes, so we must only support formats where the size of a single pixel is 4 bytes. Fix RGB24 to be 4 bytes (the alpha channel is ignored) and disallow A8.
It's only ever used like that