Fixed JPEG problem

I have no idea why the switch does not work.
So I decided to convert it into a cascade of if.
I know it sucks, but I have not found another solution.