static int find_large_solid_color_rect(VncState *vs, int x, int y,

                                       int w, int h, int max_rows)

{

    int dx, dy, dw, dh;

    int n = 0;



    /* Try to find large solid-color areas and send them separately. */



    for (dy = y; dy < y + h; dy += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) {



        /* If a rectangle becomes too large, send its upper part now. */



        if (dy - y >= max_rows) {

            n += send_rect_simple(vs, x, y, w, max_rows);

            y += max_rows;

            h -= max_rows;

        }



        dh = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (y + h - dy));



        for (dx = x; dx < x + w; dx += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) {

            uint32_t color_value;

            int x_best, y_best, w_best, h_best;



            dw = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (x + w - dx));



            if (!check_solid_tile(vs, dx, dy, dw, dh, &color_value, false)) {

                continue ;

            }



            /* Get dimensions of solid-color area. */



            find_best_solid_area(vs, dx, dy, w - (dx - x), h - (dy - y),

                                 color_value, &w_best, &h_best);



            /* Make sure a solid rectangle is large enough

               (or the whole rectangle is of the same color). */



            if (w_best * h_best != w * h &&

                w_best * h_best < VNC_TIGHT_MIN_SOLID_SUBRECT_SIZE) {

                continue;

            }



            /* Try to extend solid rectangle to maximum size. */



            x_best = dx; y_best = dy;

            extend_solid_area(vs, x, y, w, h, color_value,

                              &x_best, &y_best, &w_best, &h_best);



            /* Send rectangles at top and left to solid-color area. */



            if (y_best != y) {

                n += send_rect_simple(vs, x, y, w, y_best-y);

            }

            if (x_best != x) {

                n += vnc_tight_send_framebuffer_update(vs, x, y_best,

                                                       x_best-x, h_best);

            }



            /* Send solid-color rectangle. */

            n += send_sub_rect_solid(vs, x_best, y_best, w_best, h_best);



            /* Send remaining rectangles (at right and bottom). */



            if (x_best + w_best != x + w) {

                n += vnc_tight_send_framebuffer_update(vs, x_best+w_best,

                                                       y_best,

                                                       w-(x_best-x)-w_best,

                                                       h_best);

            }

            if (y_best + h_best != y + h) {

                n += vnc_tight_send_framebuffer_update(vs, x, y_best+h_best,

                                                       w, h-(y_best-y)-h_best);

            }



            /* Return after all recursive calls are done. */

            return n;

        }

    }

    return n + send_rect_simple(vs, x, y, w, h);

}

static int find_large_solid_color_rect(VncState *vs, int x, int y,

                                       int w, int h, int max_rows)

{

    int dx, dy, dw, dh;

    int n = 0;



    



    for (dy = y; dy < y + h; dy += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) {



        



        if (dy - y >= max_rows) {

            n += send_rect_simple(vs, x, y, w, max_rows);

            y += max_rows;

            h -= max_rows;

        }



        dh = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (y + h - dy));



        for (dx = x; dx < x + w; dx += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) {

            uint32_t color_value;

            int x_best, y_best, w_best, h_best;



            dw = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (x + w - dx));



            if (!check_solid_tile(vs, dx, dy, dw, dh, &color_value, false)) {

                continue ;

            }



            



            find_best_solid_area(vs, dx, dy, w - (dx - x), h - (dy - y),

                                 color_value, &w_best, &h_best);



            





            if (w_best * h_best != w * h &&

                w_best * h_best < VNC_TIGHT_MIN_SOLID_SUBRECT_SIZE) {

                continue;

            }



            



            x_best = dx; y_best = dy;

            extend_solid_area(vs, x, y, w, h, color_value,

                              &x_best, &y_best, &w_best, &h_best);



            



            if (y_best != y) {

                n += send_rect_simple(vs, x, y, w, y_best-y);

            }

            if (x_best != x) {

                n += vnc_tight_send_framebuffer_update(vs, x, y_best,

                                                       x_best-x, h_best);

            }



            

            n += send_sub_rect_solid(vs, x_best, y_best, w_best, h_best);



            



            if (x_best + w_best != x + w) {

                n += vnc_tight_send_framebuffer_update(vs, x_best+w_best,

                                                       y_best,

                                                       w-(x_best-x)-w_best,

                                                       h_best);

            }

            if (y_best + h_best != y + h) {

                n += vnc_tight_send_framebuffer_update(vs, x, y_best+h_best,

                                                       w, h-(y_best-y)-h_best);

            }



            

            return n;

        }

    }

    return n + send_rect_simple(vs, x, y, w, h);

}

static int FUNC_0(VncState *VAR_0, int VAR_1, int VAR_2,

                                       int VAR_3, int VAR_4, int VAR_5)

{

    int VAR_6, VAR_7, VAR_8, VAR_9;

    int VAR_10 = 0;



    



    for (VAR_7 = VAR_2; VAR_7 < VAR_2 + VAR_4; VAR_7 += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) {



        



        if (VAR_7 - VAR_2 >= VAR_5) {

            VAR_10 += send_rect_simple(VAR_0, VAR_1, VAR_2, VAR_3, VAR_5);

            VAR_2 += VAR_5;

            VAR_4 -= VAR_5;

        }



        VAR_9 = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (VAR_2 + VAR_4 - VAR_7));



        for (VAR_6 = VAR_1; VAR_6 < VAR_1 + VAR_3; VAR_6 += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) {

            uint32_t color_value;

            int VAR_11, VAR_12, VAR_13, VAR_14;



            VAR_8 = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (VAR_1 + VAR_3 - VAR_6));



            if (!check_solid_tile(VAR_0, VAR_6, VAR_7, VAR_8, VAR_9, &color_value, false)) {

                continue ;

            }



            



            find_best_solid_area(VAR_0, VAR_6, VAR_7, VAR_3 - (VAR_6 - VAR_1), VAR_4 - (VAR_7 - VAR_2),

                                 color_value, &VAR_13, &VAR_14);



            





            if (VAR_13 * VAR_14 != VAR_3 * VAR_4 &&

                VAR_13 * VAR_14 < VNC_TIGHT_MIN_SOLID_SUBRECT_SIZE) {

                continue;

            }



            



            VAR_11 = VAR_6; VAR_12 = VAR_7;

            extend_solid_area(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, color_value,

                              &VAR_11, &VAR_12, &VAR_13, &VAR_14);



            



            if (VAR_12 != VAR_2) {

                VAR_10 += send_rect_simple(VAR_0, VAR_1, VAR_2, VAR_3, VAR_12-VAR_2);

            }

            if (VAR_11 != VAR_1) {

                VAR_10 += vnc_tight_send_framebuffer_update(VAR_0, VAR_1, VAR_12,

                                                       VAR_11-VAR_1, VAR_14);

            }



            

            VAR_10 += send_sub_rect_solid(VAR_0, VAR_11, VAR_12, VAR_13, VAR_14);



            



            if (VAR_11 + VAR_13 != VAR_1 + VAR_3) {

                VAR_10 += vnc_tight_send_framebuffer_update(VAR_0, VAR_11+VAR_13,

                                                       VAR_12,

                                                       VAR_3-(VAR_11-VAR_1)-VAR_13,

                                                       VAR_14);

            }

            if (VAR_12 + VAR_14 != VAR_2 + VAR_4) {

                VAR_10 += vnc_tight_send_framebuffer_update(VAR_0, VAR_1, VAR_12+VAR_14,

                                                       VAR_3, VAR_4-(VAR_12-VAR_2)-VAR_14);

            }



            

            return VAR_10;

        }

    }

    return VAR_10 + send_rect_simple(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4);

}

static int FUNC_0(VncState *VAR_0, int VAR_1, int VAR_2,
int VAR_3, int VAR_4, int VAR_5)
{ int VAR_6, VAR_7, VAR_8, VAR_9; int VAR_10 = 0; for (VAR_7 = VAR_2; VAR_7 < VAR_2 + VAR_4; VAR_7 += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) { if (VAR_7 - VAR_2 >= VAR_5) { VAR_10 += send_rect_simple(VAR_0, VAR_1, VAR_2, VAR_3, VAR_5); VAR_2 += VAR_5; VAR_4 -= VAR_5; } VAR_9 = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (VAR_2 + VAR_4 - VAR_7)); for (VAR_6 = VAR_1; VAR_6 < VAR_1 + VAR_3; VAR_6 += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) { uint32_t color_value; int VAR_11, VAR_12, VAR_13, VAR_14; VAR_8 = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (VAR_1 + VAR_3 - VAR_6)); if (!check_solid_tile(VAR_0, VAR_6, VAR_7, VAR_8, VAR_9, &color_value, false)) { continue ; } find_best_solid_area(VAR_0, VAR_6, VAR_7, VAR_3 - (VAR_6 - VAR_1), VAR_4 - (VAR_7 - VAR_2),
color_value, &VAR_13, &VAR_14); if (VAR_13 * VAR_14 != VAR_3 * VAR_4 &&
VAR_13 * VAR_14 < VNC_TIGHT_MIN_SOLID_SUBRECT_SIZE) { continue; } VAR_11 = VAR_6; VAR_12 = VAR_7; extend_solid_area(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, color_value,
&VAR_11, &VAR_12, &VAR_13, &VAR_14); if (VAR_12 != VAR_2) { VAR_10 += send_rect_simple(VAR_0, VAR_1, VAR_2, VAR_3, VAR_12-VAR_2); } if (VAR_11 != VAR_1) { VAR_10 += vnc_tight_send_framebuffer_update(VAR_0, VAR_1, VAR_12,
VAR_11-VAR_1, VAR_14); } VAR_10 += send_sub_rect_solid(VAR_0, VAR_11, VAR_12, VAR_13, VAR_14); if (VAR_11 + VAR_13 != VAR_1 + VAR_3) { VAR_10 += vnc_tight_send_framebuffer_update(VAR_0, VAR_11+VAR_13,
VAR_12,
VAR_3-(VAR_11-VAR_1)-VAR_13,
VAR_14); } if (VAR_12 + VAR_14 != VAR_2 + VAR_4) { VAR_10 += vnc_tight_send_framebuffer_update(VAR_0, VAR_1, VAR_12+VAR_14,
VAR_3, VAR_4-(VAR_12-VAR_2)-VAR_14); } return VAR_10; } } return VAR_10 + send_rect_simple(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4); }