間違いがありました。615行の jpeg_calc_output_dimensions(&cinfo); をif文の外に出せばcinfo.output_width と cinfo.output_height はそのまま使えました。失礼しました。