static int send_palette_rect(VncState *vs, int w, int h, struct QDict *palette)

{

    int stream = 2;

    int level = tight_conf[vs->tight_compression].idx_zlib_level;

    int colors;

    size_t bytes;



    colors = qdict_size(palette);



    vnc_write_u8(vs, (stream | VNC_TIGHT_EXPLICIT_FILTER) << 4);

    vnc_write_u8(vs, VNC_TIGHT_FILTER_PALETTE);

    vnc_write_u8(vs, colors - 1);



    switch(vs->clientds.pf.bytes_per_pixel) {

    case 4:

    {

        size_t old_offset, offset;

        uint32_t header[qdict_size(palette)];

        struct palette_cb_priv priv = { vs, (uint8_t *)header };



        old_offset = vs->output.offset;

        qdict_iter(palette, write_palette, &priv);

        vnc_write(vs, header, sizeof(header));



        if (vs->tight_pixel24) {

            tight_pack24(vs, vs->output.buffer + old_offset, colors, &offset);

            vs->output.offset = old_offset + offset;

        }



        tight_encode_indexed_rect32(vs->tight.buffer, w * h, palette);

        break;

    }

    case 2:

    {

        uint16_t header[qdict_size(palette)];

        struct palette_cb_priv priv = { vs, (uint8_t *)header };



        qdict_iter(palette, write_palette, &priv);

        vnc_write(vs, header, sizeof(header));

        tight_encode_indexed_rect16(vs->tight.buffer, w * h, palette);

        break;

    }

    default:

        return -1; /* No palette for 8bits colors */

        break;

    }

    bytes = w * h;

    vs->tight.offset = bytes;



    bytes = tight_compress_data(vs, stream, bytes,

                                level, Z_DEFAULT_STRATEGY);

    return (bytes >= 0);

}

static int send_palette_rect(VncState *vs, int w, int h, struct QDict *palette)

{

    int stream = 2;

    int level = tight_conf[vs->tight_compression].idx_zlib_level;

    int colors;

    size_t bytes;



    colors = qdict_size(palette);



    vnc_write_u8(vs, (stream | VNC_TIGHT_EXPLICIT_FILTER) << 4);

    vnc_write_u8(vs, VNC_TIGHT_FILTER_PALETTE);

    vnc_write_u8(vs, colors - 1);



    switch(vs->clientds.pf.bytes_per_pixel) {

    case 4:

    {

        size_t old_offset, offset;

        uint32_t header[qdict_size(palette)];

        struct palette_cb_priv priv = { vs, (uint8_t *)header };



        old_offset = vs->output.offset;

        qdict_iter(palette, write_palette, &priv);

        vnc_write(vs, header, sizeof(header));



        if (vs->tight_pixel24) {

            tight_pack24(vs, vs->output.buffer + old_offset, colors, &offset);

            vs->output.offset = old_offset + offset;

        }



        tight_encode_indexed_rect32(vs->tight.buffer, w * h, palette);

        break;

    }

    case 2:

    {

        uint16_t header[qdict_size(palette)];

        struct palette_cb_priv priv = { vs, (uint8_t *)header };



        qdict_iter(palette, write_palette, &priv);

        vnc_write(vs, header, sizeof(header));

        tight_encode_indexed_rect16(vs->tight.buffer, w * h, palette);

        break;

    }

    default:

        return -1; 

        break;

    }

    bytes = w * h;

    vs->tight.offset = bytes;



    bytes = tight_compress_data(vs, stream, bytes,

                                level, Z_DEFAULT_STRATEGY);

    return (bytes >= 0);

}

static int FUNC_0(VncState *VAR_0, int VAR_1, int VAR_2, struct QDict *VAR_3)

{

    int VAR_4 = 2;

    int VAR_5 = tight_conf[VAR_0->tight_compression].idx_zlib_level;

    int VAR_6;

    size_t bytes;



    VAR_6 = qdict_size(VAR_3);



    vnc_write_u8(VAR_0, (VAR_4 | VNC_TIGHT_EXPLICIT_FILTER) << 4);

    vnc_write_u8(VAR_0, VNC_TIGHT_FILTER_PALETTE);

    vnc_write_u8(VAR_0, VAR_6 - 1);



    switch(VAR_0->clientds.pf.bytes_per_pixel) {

    case 4:

    {

        size_t old_offset, offset;

        uint32_t header[qdict_size(VAR_3)];

        struct palette_cb_priv VAR_8 = { VAR_0, (uint8_t *)header };



        old_offset = VAR_0->output.offset;

        qdict_iter(VAR_3, write_palette, &VAR_8);

        vnc_write(VAR_0, header, sizeof(header));



        if (VAR_0->tight_pixel24) {

            tight_pack24(VAR_0, VAR_0->output.buffer + old_offset, VAR_6, &offset);

            VAR_0->output.offset = old_offset + offset;

        }



        tight_encode_indexed_rect32(VAR_0->tight.buffer, VAR_1 * VAR_2, VAR_3);

        break;

    }

    case 2:

    {

        uint16_t header[qdict_size(VAR_3)];

        struct palette_cb_priv VAR_8 = { VAR_0, (uint8_t *)header };



        qdict_iter(VAR_3, write_palette, &VAR_8);

        vnc_write(VAR_0, header, sizeof(header));

        tight_encode_indexed_rect16(VAR_0->tight.buffer, VAR_1 * VAR_2, VAR_3);

        break;

    }

    default:

        return -1; 

        break;

    }

    bytes = VAR_1 * VAR_2;

    VAR_0->tight.offset = bytes;



    bytes = tight_compress_data(VAR_0, VAR_4, bytes,

                                VAR_5, Z_DEFAULT_STRATEGY);

    return (bytes >= 0);

}

static int FUNC_0(VncState *VAR_0, int VAR_1, int VAR_2, struct QDict *VAR_3)
{ int VAR_4 = 2; int VAR_5 = tight_conf[VAR_0->tight_compression].idx_zlib_level; int VAR_6; size_t bytes; VAR_6 = qdict_size(VAR_3); vnc_write_u8(VAR_0, (VAR_4 | VNC_TIGHT_EXPLICIT_FILTER) << 4); vnc_write_u8(VAR_0, VNC_TIGHT_FILTER_PALETTE); vnc_write_u8(VAR_0, VAR_6 - 1); switch(VAR_0->clientds.pf.bytes_per_pixel) { case 4:
{ size_t old_offset, offset; uint32_t header[qdict_size(VAR_3)]; struct palette_cb_priv VAR_8 = { VAR_0, (uint8_t *)header }; old_offset = VAR_0->output.offset; qdict_iter(VAR_3, write_palette, &VAR_8); vnc_write(VAR_0, header, sizeof(header)); if (VAR_0->tight_pixel24) { tight_pack24(VAR_0, VAR_0->output.buffer + old_offset, VAR_6, &offset); VAR_0->output.offset = old_offset + offset; } tight_encode_indexed_rect32(VAR_0->tight.buffer, VAR_1 * VAR_2, VAR_3); break; } case 2:
{ uint16_t header[qdict_size(VAR_3)]; struct palette_cb_priv VAR_8 = { VAR_0, (uint8_t *)header }; qdict_iter(VAR_3, write_palette, &VAR_8); vnc_write(VAR_0, header, sizeof(header)); tight_encode_indexed_rect16(VAR_0->tight.buffer, VAR_1 * VAR_2, VAR_3); break; } default:
return -1; break; } bytes = VAR_1 * VAR_2; VAR_0->tight.offset = bytes; bytes = tight_compress_data(VAR_0, VAR_4, bytes,
VAR_5, Z_DEFAULT_STRATEGY); return (bytes >= 0); }