static int send_jpeg_rect(VncState *vs, int x, int y, int w, int h, int quality)

{

    struct jpeg_compress_struct cinfo;

    struct jpeg_error_mgr jerr;

    struct jpeg_destination_mgr manager;

    JSAMPROW row[1];

    uint8_t *buf;

    int dy;



    if (ds_get_bytes_per_pixel(vs->ds) == 1)

        return send_full_color_rect(vs, w, h);



    buf = qemu_malloc(w * 3);

    row[0] = buf;

    buffer_reserve(&vs->tight_jpeg, 2048);



    cinfo.err = jpeg_std_error(&jerr);

    jpeg_create_compress(&cinfo);



    cinfo.client_data = vs;

    cinfo.image_width = w;

    cinfo.image_height = h;

    cinfo.input_components = 3;

    cinfo.in_color_space = JCS_RGB;



    jpeg_set_defaults(&cinfo);

    jpeg_set_quality(&cinfo, quality, true);



    manager.init_destination = jpeg_init_destination;

    manager.empty_output_buffer = jpeg_empty_output_buffer;

    manager.term_destination = jpeg_term_destination;

    cinfo.dest = &manager;



    jpeg_start_compress(&cinfo, true);



    for (dy = 0; dy < h; dy++) {

        jpeg_prepare_row(vs, buf, x, y + dy, w);

        jpeg_write_scanlines(&cinfo, row, 1);

    }



    jpeg_finish_compress(&cinfo);

    jpeg_destroy_compress(&cinfo);



    vnc_write_u8(vs, VNC_TIGHT_JPEG << 4);



    tight_send_compact_size(vs, vs->tight_jpeg.offset);

    vnc_write(vs, vs->tight_jpeg.buffer, vs->tight_jpeg.offset);

    buffer_reset(&vs->tight_jpeg);



    return 1;

}

static int send_jpeg_rect(VncState *vs, int x, int y, int w, int h, int quality)

{

    struct jpeg_compress_struct cinfo;

    struct jpeg_error_mgr jerr;

    struct jpeg_destination_mgr manager;

    JSAMPROW row[1];

    uint8_t *buf;

    int dy;



    if (ds_get_bytes_per_pixel(vs->ds) == 1)

        return send_full_color_rect(vs, w, h);



    buf = qemu_malloc(w * 3);

    row[0] = buf;

    buffer_reserve(&vs->tight_jpeg, 2048);



    cinfo.err = jpeg_std_error(&jerr);

    jpeg_create_compress(&cinfo);



    cinfo.client_data = vs;

    cinfo.image_width = w;

    cinfo.image_height = h;

    cinfo.input_components = 3;

    cinfo.in_color_space = JCS_RGB;



    jpeg_set_defaults(&cinfo);

    jpeg_set_quality(&cinfo, quality, true);



    manager.init_destination = jpeg_init_destination;

    manager.empty_output_buffer = jpeg_empty_output_buffer;

    manager.term_destination = jpeg_term_destination;

    cinfo.dest = &manager;



    jpeg_start_compress(&cinfo, true);



    for (dy = 0; dy < h; dy++) {

        jpeg_prepare_row(vs, buf, x, y + dy, w);

        jpeg_write_scanlines(&cinfo, row, 1);

    }



    jpeg_finish_compress(&cinfo);

    jpeg_destroy_compress(&cinfo);



    vnc_write_u8(vs, VNC_TIGHT_JPEG << 4);



    tight_send_compact_size(vs, vs->tight_jpeg.offset);

    vnc_write(vs, vs->tight_jpeg.buffer, vs->tight_jpeg.offset);

    buffer_reset(&vs->tight_jpeg);



    return 1;

}

static int FUNC_0(VncState *VAR_0, int VAR_1, int VAR_2, int VAR_3, int VAR_4, int VAR_5)

{

    struct jpeg_compress_struct VAR_6;

    struct jpeg_error_mgr VAR_7;

    struct jpeg_destination_mgr VAR_8;

    JSAMPROW row[1];

    uint8_t *buf;

    int VAR_9;



    if (ds_get_bytes_per_pixel(VAR_0->ds) == 1)

        return send_full_color_rect(VAR_0, VAR_3, VAR_4);



    buf = qemu_malloc(VAR_3 * 3);

    row[0] = buf;

    buffer_reserve(&VAR_0->tight_jpeg, 2048);



    VAR_6.err = jpeg_std_error(&VAR_7);

    jpeg_create_compress(&VAR_6);



    VAR_6.client_data = VAR_0;

    VAR_6.image_width = VAR_3;

    VAR_6.image_height = VAR_4;

    VAR_6.input_components = 3;

    VAR_6.in_color_space = JCS_RGB;



    jpeg_set_defaults(&VAR_6);

    jpeg_set_quality(&VAR_6, VAR_5, true);



    VAR_8.init_destination = jpeg_init_destination;

    VAR_8.empty_output_buffer = jpeg_empty_output_buffer;

    VAR_8.term_destination = jpeg_term_destination;

    VAR_6.dest = &VAR_8;



    jpeg_start_compress(&VAR_6, true);



    for (VAR_9 = 0; VAR_9 < VAR_4; VAR_9++) {

        jpeg_prepare_row(VAR_0, buf, VAR_1, VAR_2 + VAR_9, VAR_3);

        jpeg_write_scanlines(&VAR_6, row, 1);

    }



    jpeg_finish_compress(&VAR_6);

    jpeg_destroy_compress(&VAR_6);



    vnc_write_u8(VAR_0, VNC_TIGHT_JPEG << 4);



    tight_send_compact_size(VAR_0, VAR_0->tight_jpeg.offset);

    vnc_write(VAR_0, VAR_0->tight_jpeg.buffer, VAR_0->tight_jpeg.offset);

    buffer_reset(&VAR_0->tight_jpeg);



    return 1;

}

static int FUNC_0(VncState *VAR_0, int VAR_1, int VAR_2, int VAR_3, int VAR_4, int VAR_5)
{ struct jpeg_compress_struct VAR_6; struct jpeg_error_mgr VAR_7; struct jpeg_destination_mgr VAR_8; JSAMPROW row[1]; uint8_t *buf; int VAR_9; if (ds_get_bytes_per_pixel(VAR_0->ds) == 1)
return send_full_color_rect(VAR_0, VAR_3, VAR_4); buf = qemu_malloc(VAR_3 * 3); row[0] = buf; buffer_reserve(&VAR_0->tight_jpeg, 2048); VAR_6.err = jpeg_std_error(&VAR_7); jpeg_create_compress(&VAR_6); VAR_6.client_data = VAR_0; VAR_6.image_width = VAR_3; VAR_6.image_height = VAR_4; VAR_6.input_components = 3; VAR_6.in_color_space = JCS_RGB; jpeg_set_defaults(&VAR_6); jpeg_set_quality(&VAR_6, VAR_5, true); VAR_8.init_destination = jpeg_init_destination; VAR_8.empty_output_buffer = jpeg_empty_output_buffer; VAR_8.term_destination = jpeg_term_destination; VAR_6.dest = &VAR_8; jpeg_start_compress(&VAR_6, true); for (VAR_9 = 0; VAR_9 < VAR_4; VAR_9++) { jpeg_prepare_row(VAR_0, buf, VAR_1, VAR_2 + VAR_9, VAR_3); jpeg_write_scanlines(&VAR_6, row, 1); } jpeg_finish_compress(&VAR_6); jpeg_destroy_compress(&VAR_6); vnc_write_u8(VAR_0, VNC_TIGHT_JPEG << 4); tight_send_compact_size(VAR_0, VAR_0->tight_jpeg.offset); vnc_write(VAR_0, VAR_0->tight_jpeg.buffer, VAR_0->tight_jpeg.offset); buffer_reset(&VAR_0->tight_jpeg); return 1; }