mesa/main: rewrite mipmap generation code
This MR rewrites the mipmap generation code quite a bit, to use the format conversion instead of open-coding it. This solves a few issues with the code in one swoop.
In addition, there's a trivial typo-fixup in here.
Edited by Erik Faye-Lund