[Spice-devel] [PATCH 12/30] Move dcc_compress_image_lz4 to dcc-encoders.c

Frediano Ziglio fziglio at redhat.com
Tue Jun 7 10:17:50 UTC 2016


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/dcc-encoders.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 server/dcc-encoders.h |  3 +++
 server/dcc.c          | 52 ---------------------------------------------------
 3 files changed, 53 insertions(+), 52 deletions(-)

diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index dadcb07..c4b85d3 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -988,4 +988,54 @@ int dcc_compress_image_jpeg(EncodersData *enc, SpiceImage *dest,
     return TRUE;
 }
 
+#ifdef USE_LZ4
+int dcc_compress_image_lz4(EncodersData *enc, SpiceImage *dest,
+                           SpiceBitmap *src, compress_send_data_t* o_comp_data,
+                           stat_info_t *stats)
+{
+    Lz4Data *lz4_data = &enc->lz4_data;
+    Lz4EncoderContext *lz4 = enc->lz4;
+    int lz4_size = 0;
+    stat_start_time_t start_time;
+    stat_start_time_init(&start_time, stats);
+
+#ifdef COMPRESS_DEBUG
+    spice_info("LZ4 compress");
+#endif
 
+    encoder_data_init(&lz4_data->data);
+
+    if (setjmp(lz4_data->data.jmp_env)) {
+        encoder_data_reset(&lz4_data->data);
+        return FALSE;
+    }
+
+    if (src->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE) {
+        spice_chunks_linearize(src->data);
+    }
+
+    lz4_data->data.u.lines_data.chunks = src->data;
+    lz4_data->data.u.lines_data.stride = src->stride;
+    lz4_data->data.u.lines_data.next = 0;
+    lz4_data->data.u.lines_data.reverse = 0;
+
+    lz4_size = lz4_encode(lz4, src->y, src->stride, lz4_data->data.bufs_head->buf.bytes,
+                          sizeof(lz4_data->data.bufs_head->buf),
+                          src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN, src->format);
+
+    // the compressed buffer is bigger than the original data
+    if (lz4_size > (src->y * src->stride)) {
+        longjmp(lz4_data->data.jmp_env, 1);
+    }
+
+    dest->descriptor.type = SPICE_IMAGE_TYPE_LZ4;
+    dest->u.lz4.data_size = lz4_size;
+
+    o_comp_data->comp_buf = lz4_data->data.bufs_head;
+    o_comp_data->comp_buf_size = lz4_size;
+
+    stat_compress_add(stats, start_time, src->stride * src->y,
+                      o_comp_data->comp_buf_size);
+    return TRUE;
+}
+#endif
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index eb34785..e682b05 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -198,6 +198,9 @@ int dcc_compress_image_jpeg(EncodersData *enc, SpiceImage *dest,
                             SpiceBitmap *src, compress_send_data_t* o_comp_data,
                             stat_info_t *jpeg_stats,
                             stat_info_t *jpeg_alpha_stats);
+int dcc_compress_image_lz4(EncodersData *enc, SpiceImage *dest,
+                           SpiceBitmap *src, compress_send_data_t* o_comp_data,
+                           stat_info_t *stats);
 
 #define RED_RELEASE_BUNCH_SIZE 64
 
diff --git a/server/dcc.c b/server/dcc.c
index aeaa2eb..c59858c 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -784,58 +784,6 @@ glz:
     return TRUE;
 }
 
-#ifdef USE_LZ4
-static int dcc_compress_image_lz4(EncodersData *enc, SpiceImage *dest,
-                                  SpiceBitmap *src, compress_send_data_t* o_comp_data,
-                                  stat_info_t *stats)
-{
-    Lz4Data *lz4_data = &enc->lz4_data;
-    Lz4EncoderContext *lz4 = enc->lz4;
-    int lz4_size = 0;
-    stat_start_time_t start_time;
-    stat_start_time_init(&start_time, stats);
-
-#ifdef COMPRESS_DEBUG
-    spice_info("LZ4 compress");
-#endif
-
-    encoder_data_init(&lz4_data->data);
-
-    if (setjmp(lz4_data->data.jmp_env)) {
-        encoder_data_reset(&lz4_data->data);
-        return FALSE;
-    }
-
-    if (src->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE) {
-        spice_chunks_linearize(src->data);
-    }
-
-    lz4_data->data.u.lines_data.chunks = src->data;
-    lz4_data->data.u.lines_data.stride = src->stride;
-    lz4_data->data.u.lines_data.next = 0;
-    lz4_data->data.u.lines_data.reverse = 0;
-
-    lz4_size = lz4_encode(lz4, src->y, src->stride, lz4_data->data.bufs_head->buf.bytes,
-                          sizeof(lz4_data->data.bufs_head->buf),
-                          src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN, src->format);
-
-    // the compressed buffer is bigger than the original data
-    if (lz4_size > (src->y * src->stride)) {
-        longjmp(lz4_data->data.jmp_env, 1);
-    }
-
-    dest->descriptor.type = SPICE_IMAGE_TYPE_LZ4;
-    dest->u.lz4.data_size = lz4_size;
-
-    o_comp_data->comp_buf = lz4_data->data.bufs_head;
-    o_comp_data->comp_buf_size = lz4_size;
-
-    stat_compress_add(stats, start_time, src->stride * src->y,
-                      o_comp_data->comp_buf_size);
-    return TRUE;
-}
-#endif
-
 #define MIN_DIMENSION_TO_QUIC 3
 /**
  * quic doesn't handle:
-- 
2.7.4



More information about the Spice-devel mailing list