/* Note: we warn about excess calls to jpeg_read_scanlines() since this likely signals an application programmer error. However, an oversize buffer (max_lines > scanlines remaining) is not an error.  */
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
/* Note: we warn about excess calls to jpeg_read_scanlines() since this likely signals an application programmer error. However, an oversize buffer (max_lines > scanlines remaining) is not an error.  */
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
{
    JDIMENSION row_ctr;
    if (cinfo->global_state != DSTATE_SCANNING)
        ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
    if (cinfo->output_scanline >= cinfo->output_height) {
        WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
        return 0;
    }
    if (cinfo->progress != NULL) {
        cinfo->progress->pass_counter = (long)cinfo->output_scanline;
        cinfo->progress->pass_limit = (long)cinfo->output_height;
        (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
    }
    row_ctr = 0;
    (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
    cinfo->output_scanline += row_ctr;
    return row_ctr;
}