[Spice-devel] [PATCH v2 06/30] Move image_encoders_compress_lz to dcc-encoders.c
Jonathon Jongsma
jjongsma at redhat.com
Thu Jun 9 20:42:38 UTC 2016
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
On Thu, 2016-06-09 at 13:31 +0100, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> server/dcc-encoders.c | 80
> +++++++++++++++++++++++++++++++++++++++++++++++++++
> server/dcc-encoders.h | 5 ++++
> server/dcc.c | 66 ------------------------------------------
> 3 files changed, 85 insertions(+), 66 deletions(-)
>
> diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
> index 2ccbb66..e795065 100644
> --- a/server/dcc-encoders.c
> +++ b/server/dcc-encoders.c
> @@ -782,4 +782,84 @@ int image_encoders_compress_quic(ImageEncoders *enc,
> SpiceImage *dest,
> return TRUE;
> }
>
> +static const LzImageType bitmap_fmt_to_lz_image_type[] = {
> + LZ_IMAGE_TYPE_INVALID,
> + LZ_IMAGE_TYPE_PLT1_LE,
> + LZ_IMAGE_TYPE_PLT1_BE,
> + LZ_IMAGE_TYPE_PLT4_LE,
> + LZ_IMAGE_TYPE_PLT4_BE,
> + LZ_IMAGE_TYPE_PLT8,
> + LZ_IMAGE_TYPE_RGB16,
> + LZ_IMAGE_TYPE_RGB24,
> + LZ_IMAGE_TYPE_RGB32,
> + LZ_IMAGE_TYPE_RGBA,
> + LZ_IMAGE_TYPE_A8
> +};
> +
> +int image_encoders_compress_lz(ImageEncoders *enc,
> + SpiceImage *dest, SpiceBitmap *src,
> + compress_send_data_t* o_comp_data,
> + stat_info_t *stats)
> +{
> + LzData *lz_data = &enc->lz_data;
> + LzContext *lz = enc->lz;
> + LzImageType type = bitmap_fmt_to_lz_image_type[src->format];
> + int size; // size of the compressed data
> +
> + stat_start_time_t start_time;
> + stat_start_time_init(&start_time, stats);
> +
> +#ifdef COMPRESS_DEBUG
> + spice_info("LZ LOCAL compress");
> +#endif
> +
> + encoder_data_init(&lz_data->data);
> +
> + if (setjmp(lz_data->data.jmp_env)) {
> + encoder_data_reset(&lz_data->data);
> + return FALSE;
> + }
> +
> + lz_data->data.u.lines_data.chunks = src->data;
> + lz_data->data.u.lines_data.stride = src->stride;
> + lz_data->data.u.lines_data.next = 0;
> + lz_data->data.u.lines_data.reverse = 0;
> +
> + size = lz_encode(lz, type, src->x, src->y,
> + !!(src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN),
> + NULL, 0, src->stride,
> + lz_data->data.bufs_head->buf.bytes,
> + sizeof(lz_data->data.bufs_head->buf));
> +
> + // the compressed buffer is bigger than the original data
> + if (size > (src->y * src->stride)) {
> + longjmp(lz_data->data.jmp_env, 1);
> + }
> +
> + if (bitmap_fmt_is_rgb(src->format)) {
> + dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_RGB;
> + dest->u.lz_rgb.data_size = size;
> +
> + o_comp_data->comp_buf = lz_data->data.bufs_head;
> + o_comp_data->comp_buf_size = size;
> + } else {
> + /* masks are 1BIT bitmaps without palettes, but they are not
> compressed
> + * (see fill_mask) */
> + spice_assert(src->palette);
> + dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_PLT;
> + dest->u.lz_plt.data_size = size;
> + dest->u.lz_plt.flags = src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN;
> + dest->u.lz_plt.palette = src->palette;
> + dest->u.lz_plt.palette_id = src->palette->unique;
> + o_comp_data->comp_buf = lz_data->data.bufs_head;
> + o_comp_data->comp_buf_size = size;
> +
> + o_comp_data->lzplt_palette = dest->u.lz_plt.palette;
> + }
> +
> + stat_compress_add(stats, start_time, src->stride * src->y,
> + o_comp_data->comp_buf_size);
> + return TRUE;
> +}
> +
>
> diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
> index 03d5ee7..21e2fa4 100644
> --- a/server/dcc-encoders.h
> +++ b/server/dcc-encoders.h
> @@ -179,6 +179,11 @@ typedef struct compress_send_data_t {
> int image_encoders_compress_quic(ImageEncoders *enc, SpiceImage *dest,
> SpiceBitmap *src, compress_send_data_t*
> o_comp_data,
> stat_info_t *stats);
> +int image_encoders_compress_lz(ImageEncoders *enc,
> + SpiceImage *dest, SpiceBitmap *src,
> + compress_send_data_t* o_comp_data,
> + stat_info_t *stats);
> +
> #define RED_RELEASE_BUNCH_SIZE 64
>
> #endif /* DCC_ENCODERS_H_ */
> diff --git a/server/dcc.c b/server/dcc.c
> index d5e6c6b..2d715d9 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -784,72 +784,6 @@ glz:
> return TRUE;
> }
>
> -static int image_encoders_compress_lz(ImageEncoders *enc,
> - SpiceImage *dest, SpiceBitmap *src,
> - compress_send_data_t* o_comp_data,
> - stat_info_t *stats)
> -{
> - LzData *lz_data = &enc->lz_data;
> - LzContext *lz = enc->lz;
> - LzImageType type = bitmap_fmt_to_lz_image_type[src->format];
> - int size; // size of the compressed data
> -
> - stat_start_time_t start_time;
> - stat_start_time_init(&start_time, stats);
> -
> -#ifdef COMPRESS_DEBUG
> - spice_info("LZ LOCAL compress");
> -#endif
> -
> - encoder_data_init(&lz_data->data);
> -
> - if (setjmp(lz_data->data.jmp_env)) {
> - encoder_data_reset(&lz_data->data);
> - return FALSE;
> - }
> -
> - lz_data->data.u.lines_data.chunks = src->data;
> - lz_data->data.u.lines_data.stride = src->stride;
> - lz_data->data.u.lines_data.next = 0;
> - lz_data->data.u.lines_data.reverse = 0;
> -
> - size = lz_encode(lz, type, src->x, src->y,
> - !!(src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN),
> - NULL, 0, src->stride,
> - lz_data->data.bufs_head->buf.bytes,
> - sizeof(lz_data->data.bufs_head->buf));
> -
> - // the compressed buffer is bigger than the original data
> - if (size > (src->y * src->stride)) {
> - longjmp(lz_data->data.jmp_env, 1);
> - }
> -
> - if (bitmap_fmt_is_rgb(src->format)) {
> - dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_RGB;
> - dest->u.lz_rgb.data_size = size;
> -
> - o_comp_data->comp_buf = lz_data->data.bufs_head;
> - o_comp_data->comp_buf_size = size;
> - } else {
> - /* masks are 1BIT bitmaps without palettes, but they are not
> compressed
> - * (see fill_mask) */
> - spice_assert(src->palette);
> - dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_PLT;
> - dest->u.lz_plt.data_size = size;
> - dest->u.lz_plt.flags = src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN;
> - dest->u.lz_plt.palette = src->palette;
> - dest->u.lz_plt.palette_id = src->palette->unique;
> - o_comp_data->comp_buf = lz_data->data.bufs_head;
> - o_comp_data->comp_buf_size = size;
> -
> - o_comp_data->lzplt_palette = dest->u.lz_plt.palette;
> - }
> -
> - stat_compress_add(stats, start_time, src->stride * src->y,
> - o_comp_data->comp_buf_size);
> - return TRUE;
> -}
> -
> static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage
> *dest,
> SpiceBitmap *src, compress_send_data_t*
> o_comp_data)
> {
More information about the Spice-devel
mailing list