/* Convert some rows of samples to the JPEG colorspace. This version handles grayscale output with no conversion. The source can be either plain grayscale or YCbCr (since Y == gray).  */
grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
/* Convert some rows of samples to the JPEG colorspace. This version handles grayscale output with no conversion. The source can be either plain grayscale or YCbCr (since Y == gray).  */
grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
{
    register JSAMPROW inptr;
    register JSAMPROW outptr;
    register JDIMENSION col;
    JDIMENSION num_cols = cinfo->image_width;
    int instride = cinfo->input_components;
    while (--num_rows >= 0) {
        inptr = *input_buf++;
        outptr = output_buf[0][output_row];
        output_row++;
        for (col = 0; col < num_cols; col++) {
            outptr[col] = inptr[0];
            inptr += instride;
        }
    }
}