Пример #1
0
int APP_CC
xrdp_image_compress_rle(int width, int height, int bpp, unsigned char* data, char* dest)
{
   struct stream *s;
   struct stream *tmp_s;
   int e;
   int i;
   int bufsize;
   make_stream(s);
   init_stream(s, IMAGE_TILE_MAX_BUFFER_SIZE);
   make_stream(tmp_s);
   init_stream(tmp_s, IMAGE_TILE_MAX_BUFFER_SIZE);
   e = width % 4;

   if (e != 0)
       e = 4 - e;

   i = height;
   xrdp_bitmap_compress(data, width, height, s, bpp, IMAGE_TILE_MAX_BUFFER_SIZE, i - 1, tmp_s, e);
   bufsize = (int) (s->p - s->data);
   g_memcpy(dest, s->data, bufsize);
   free_stream(tmp_s);
   free_stream(s);
   return bufsize;
}
Пример #2
0
int EXPORT_CC
libxrdp_send_bitmap(struct xrdp_session *session, int width, int height,
                    int bpp, char *data, int x, int y, int cx, int cy)
{
    int line_size = 0;
    int i = 0;
    int j = 0;
    int total_lines = 0;
    int lines_sending = 0;
    int Bpp = 0;
    int e = 0;
    int bufsize = 0;
    int total_bufsize = 0;
    int num_updates = 0;
    char *p_num_updates = (char *)NULL;
    char *p = (char *)NULL;
    char *q = (char *)NULL;
    struct stream *s = (struct stream *)NULL;
    struct stream *temp_s = (struct stream *)NULL;

    DEBUG(("libxrdp_send_bitmap sending bitmap"));
    Bpp = (bpp + 7) / 8;
    e = width % 4;

    if (e != 0)
    {
        e = 4 - e;
    }

    line_size = width * Bpp;
    make_stream(s);
    init_stream(s, 8192);

    if (session->client_info->use_bitmap_comp)
    {
        make_stream(temp_s);
        init_stream(temp_s, 65536);
        i = 0;

        if (cy <= height)
        {
            i = cy;
        }

        while (i > 0)
        {
            total_bufsize = 0;
            num_updates = 0;
            xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s);
            out_uint16_le(s, RDP_UPDATE_BITMAP);
            p_num_updates = s->p;
            out_uint8s(s, 2); /* num_updates set later */

            do
            {
                if (session->client_info->op1)
                {
                    s_push_layer(s, channel_hdr, 18);
                }
                else
                {
                    s_push_layer(s, channel_hdr, 26);
                }

                p = s->p;
                lines_sending = xrdp_bitmap_compress(data, width, height,
                                                     s, bpp,
                                                     4096 - total_bufsize,
                                                     i - 1, temp_s, e);

                if (lines_sending == 0)
                {
                    break;
                }

                num_updates++;
                bufsize = s->p - p;
                total_bufsize += bufsize;
                i = i - lines_sending;
                s_mark_end(s);
                s_pop_layer(s, channel_hdr);
                out_uint16_le(s, x); /* left */
                out_uint16_le(s, y + i); /* top */
                out_uint16_le(s, (x + cx) - 1); /* right */
                out_uint16_le(s, (y + i + lines_sending) - 1); /* bottom */
                out_uint16_le(s, width + e); /* width */
                out_uint16_le(s, lines_sending); /* height */
                out_uint16_le(s, bpp); /* bpp */

                if (session->client_info->op1)
                {
                    out_uint16_le(s, 0x401); /* compress */
                    out_uint16_le(s, bufsize); /* compressed size */
                    j = (width + e) * Bpp;
                    j = j * lines_sending;
                }
                else
                {
                    out_uint16_le(s, 0x1); /* compress */
                    out_uint16_le(s, bufsize + 8);
                    out_uint8s(s, 2); /* pad */
                    out_uint16_le(s, bufsize); /* compressed size */
                    j = (width + e) * Bpp;
                    out_uint16_le(s, j); /* line size */
                    j = j * lines_sending;
                    out_uint16_le(s, j); /* final size */
                }

                if (j > 32768)
                {
                    g_writeln("error, decompressed size too big, its %d", j);
                }

                if (bufsize > 8192)
                {
                    g_writeln("error, compressed size too big, its %d", bufsize);
                }

                s->p = s->end;
            }
            while (total_bufsize < 4096 && i > 0);

            p_num_updates[0] = num_updates;
            p_num_updates[1] = num_updates >> 8;
            xrdp_rdp_send_data((struct xrdp_rdp *)session->rdp, s,
                               RDP_DATA_PDU_UPDATE);

            if (total_bufsize > 8192)
            {
                g_writeln("error, total compressed size too big, its %d",
                          total_bufsize);
            }
        }

        free_stream(temp_s);
    }
Пример #3
0
int EXPORT_CC
libxrdp_send_bitmap(struct xrdp_session *session, int width, int height,
                    int bpp, char *data, int x, int y, int cx, int cy)
{
    int line_bytes = 0;
    int i = 0;
    int j = 0;
    int k;
    int total_lines = 0;
    int lines_sending = 0;
    int Bpp = 0;
    int e = 0;
    int bufsize = 0;
    int total_bufsize = 0;
    int num_updates = 0;
    int line_pad_bytes;
    int server_line_bytes;
    char *p_num_updates = (char *)NULL;
    char *p = (char *)NULL;
    char *q = (char *)NULL;
    struct stream *s = (struct stream *)NULL;
    struct stream *temp_s = (struct stream *)NULL;
    tui32 pixel;

    LLOGLN(10, ("libxrdp_send_bitmap: sending bitmap"));
    Bpp = (bpp + 7) / 8;
    e = (4 - width) & 3;
    switch (bpp)
    {
        case 15:
        case 16:
            server_line_bytes = width * 2;
            break;
        case 24:
        case 32:
            server_line_bytes = width * 4;
            break;
        default: /* 8 bpp */
            server_line_bytes = width;
            break;
    }
    line_bytes = width * Bpp;
    line_pad_bytes = line_bytes + e * Bpp;

    LLOGLN(10, ("libxrdp_send_bitmap: bpp %d Bpp %d line_bytes %d "
           "server_line_bytes %d", bpp, Bpp, line_bytes, server_line_bytes));
    make_stream(s);
    init_stream(s, MAX_BITMAP_BUF_SIZE);

    if (session->client_info->use_bitmap_comp)
    {
        LLOGLN(10, ("libxrdp_send_bitmap: compression"));
        make_stream(temp_s);
        init_stream(temp_s, 65536);
        i = 0;

        if (cy <= height)
        {
            i = cy;
        }

        while (i > 0)
        {
            LLOGLN(10, ("libxrdp_send_bitmap: i %d", i));

            total_bufsize = 0;
            num_updates = 0;
            xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s);
            out_uint16_le(s, RDP_UPDATE_BITMAP);
            p_num_updates = s->p;
            out_uint8s(s, 2); /* num_updates set later */

            do
            {
                if (session->client_info->op1)
                {
                    s_push_layer(s, channel_hdr, 18);
                }
                else
                {
                    s_push_layer(s, channel_hdr, 26);
                }

                p = s->p;

                if (bpp > 24)
                {
                    LLOGLN(10, ("libxrdp_send_bitmap: 32 bpp"));
                    lines_sending = xrdp_bitmap32_compress(data, width, height,
                                                           s, 32,
                                   (MAX_BITMAP_BUF_SIZE - 100) - total_bufsize,
                                                           i - 1, temp_s, e, 0x10);
                    LLOGLN(10, ("libxrdp_send_bitmap: i %d lines_sending %d",
                           i, lines_sending));
                }
                else
                {
                    lines_sending = xrdp_bitmap_compress(data, width, height,
                                                         s, bpp,
                                 (MAX_BITMAP_BUF_SIZE - 100) - total_bufsize,
                                                         i - 1, temp_s, e);
                    LLOGLN(10, ("libxrdp_send_bitmap: i %d lines_sending %d",
                           i, lines_sending));
                }

                if (lines_sending == 0)
                {
                    break;
                }

                num_updates++;
                bufsize = s->p - p;
                total_bufsize += bufsize;
                i = i - lines_sending;
                s_mark_end(s);
                s_pop_layer(s, channel_hdr);
                out_uint16_le(s, x); /* left */
                out_uint16_le(s, y + i); /* top */
                out_uint16_le(s, (x + cx) - 1); /* right */
                out_uint16_le(s, (y + i + lines_sending) - 1); /* bottom */
                out_uint16_le(s, width + e); /* width */
                out_uint16_le(s, lines_sending); /* height */
                out_uint16_le(s, bpp); /* bpp */

                if (session->client_info->op1)
                {
                    out_uint16_le(s, 0x401); /* compress */
                    out_uint16_le(s, bufsize); /* compressed size */
                    j = (width + e) * Bpp;
                    j = j * lines_sending;
                    total_bufsize += 18; /* bytes since pop layer */
                }
                else
                {
                    out_uint16_le(s, 0x1); /* compress */
                    out_uint16_le(s, bufsize + 8);
                    out_uint8s(s, 2); /* pad */
                    out_uint16_le(s, bufsize); /* compressed size */
                    j = (width + e) * Bpp;
                    out_uint16_le(s, j); /* line size */
                    j = j * lines_sending;
                    out_uint16_le(s, j); /* final size */
                    total_bufsize += 26; /* bytes since pop layer */
                }

                LLOGLN(10, ("libxrdp_send_bitmap: decompressed pixels %d "
                       "decompressed bytes %d compressed bytes %d",
                       lines_sending * (width + e),
                       line_pad_bytes * lines_sending, bufsize));

                if (j > MAX_BITMAP_BUF_SIZE)
                {
                    LLOGLN(0, ("libxrdp_send_bitmap: error, decompressed "
                           "size too big: %d bytes", j));
                }

                if (bufsize > MAX_BITMAP_BUF_SIZE)
                {
                    LLOGLN(0, ("libxrdp_send_bitmap: error, compressed size "
                           "too big: %d bytes", bufsize));
                }

                s->p = s->end;
            }
            while (total_bufsize < MAX_BITMAP_BUF_SIZE && i > 0);

            LLOGLN(10, ("libxrdp_send_bitmap: num_updates %d total_bufsize %d",
                   num_updates, total_bufsize));

            p_num_updates[0] = num_updates;
            p_num_updates[1] = num_updates >> 8;
            xrdp_rdp_send_data((struct xrdp_rdp *)session->rdp, s,
                               RDP_DATA_PDU_UPDATE);

            if (total_bufsize > MAX_BITMAP_BUF_SIZE)
            {
                LLOGLN(0, ("libxrdp_send_bitmap: error, total compressed "
                       "size too big: %d bytes", total_bufsize));
            }
        }

        free_stream(temp_s);
    }