Clean up the TextureDecoder and some related things

Just trying to remove code duplication here.