fix jpeg reading regression after #1805 - closes #2123 (patch from @clundgren)