/* This routine is now just a front end to jpeg_consume_input, with some extra error checking.  */
jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
/* This routine is now just a front end to jpeg_consume_input, with some extra error checking.  */
jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
{
    int retcode;
    if (cinfo->global_state != DSTATE_START &&
        cinfo->global_state != DSTATE_INHEADER)
        ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
    retcode = jpeg_consume_input(cinfo);
    switch (retcode) {
    case JPEG_REACHED_SOS:
        retcode = JPEG_HEADER_OK;
        break;
    case JPEG_REACHED_EOI:
        if (require_image)
            ERREXIT(cinfo, JERR_NO_IMAGE);
        jpeg_abort((j_common_ptr)cinfo);
        retcode = JPEG_HEADER_TABLES_ONLY;
        break;
    case JPEG_SUSPENDED:
        break;
    }
    return retcode;
}