Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- server/dcc-encoders.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++ server/dcc-encoders.h | 4 ++ server/dcc.c | 127 -------------------------------------------------- 3 files changed, 131 insertions(+), 127 deletions(-) diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c index 279c134..0b8ef46 100644 --- a/server/dcc-encoders.c +++ b/server/dcc-encoders.c @@ -862,4 +862,131 @@ int image_encoders_compress_lz(ImageEncoders *enc, return TRUE; } +int image_encoders_compress_jpeg(ImageEncoders *enc, SpiceImage *dest, + SpiceBitmap *src, compress_send_data_t* o_comp_data, + stat_info_t *jpeg_stats, // FIXME put all stats in a structure + stat_info_t *jpeg_alpha_stats) +{ + JpegData *jpeg_data = &enc->jpeg_data; + LzData *lz_data = &enc->lz_data; + JpegEncoderContext *jpeg = enc->jpeg; + LzContext *lz = enc->lz; + volatile JpegEncoderImageType jpeg_in_type; + int jpeg_size = 0; + volatile int has_alpha = FALSE; + int alpha_lz_size = 0; + int comp_head_filled; + int comp_head_left; + int stride; + uint8_t *lz_out_start_byte; + stat_start_time_t start_time; + stat_start_time_init(&start_time, jpeg_alpha_stats); + +#ifdef COMPRESS_DEBUG + spice_info("JPEG compress"); +#endif + + switch (src->format) { + case SPICE_BITMAP_FMT_16BIT: + jpeg_in_type = JPEG_IMAGE_TYPE_RGB16; + break; + case SPICE_BITMAP_FMT_24BIT: + jpeg_in_type = JPEG_IMAGE_TYPE_BGR24; + break; + case SPICE_BITMAP_FMT_32BIT: + jpeg_in_type = JPEG_IMAGE_TYPE_BGRX32; + break; + case SPICE_BITMAP_FMT_RGBA: + jpeg_in_type = JPEG_IMAGE_TYPE_BGRX32; + has_alpha = TRUE; + break; + default: + return FALSE; + } + + encoder_data_init(&jpeg_data->data); + + if (setjmp(jpeg_data->data.jmp_env)) { + encoder_data_reset(&jpeg_data->data); + return FALSE; + } + + if (src->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE) { + spice_chunks_linearize(src->data); + } + + jpeg_data->data.u.lines_data.chunks = src->data; + jpeg_data->data.u.lines_data.stride = src->stride; + if ((src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN)) { + jpeg_data->data.u.lines_data.next = 0; + jpeg_data->data.u.lines_data.reverse = 0; + stride = src->stride; + } else { + jpeg_data->data.u.lines_data.next = src->data->num_chunks - 1; + jpeg_data->data.u.lines_data.reverse = 1; + stride = -src->stride; + } + jpeg_size = jpeg_encode(jpeg, enc->jpeg_quality, jpeg_in_type, + src->x, src->y, NULL, + 0, stride, jpeg_data->data.bufs_head->buf.bytes, + sizeof(jpeg_data->data.bufs_head->buf)); + + // the compressed buffer is bigger than the original data + if (jpeg_size > (src->y * src->stride)) { + longjmp(jpeg_data->data.jmp_env, 1); + } + + if (!has_alpha) { + dest->descriptor.type = SPICE_IMAGE_TYPE_JPEG; + dest->u.jpeg.data_size = jpeg_size; + + o_comp_data->comp_buf = jpeg_data->data.bufs_head; + o_comp_data->comp_buf_size = jpeg_size; + o_comp_data->is_lossy = TRUE; + + stat_compress_add(jpeg_stats, start_time, src->stride * src->y, + o_comp_data->comp_buf_size); + return TRUE; + } + + lz_data->data.bufs_head = jpeg_data->data.bufs_tail; + lz_data->data.bufs_tail = lz_data->data.bufs_head; + + comp_head_filled = jpeg_size % sizeof(lz_data->data.bufs_head->buf); + comp_head_left = sizeof(lz_data->data.bufs_head->buf) - comp_head_filled; + lz_out_start_byte = lz_data->data.bufs_head->buf.bytes + comp_head_filled; + + 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; + + alpha_lz_size = lz_encode(lz, LZ_IMAGE_TYPE_XXXA, src->x, src->y, + !!(src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN), + NULL, 0, src->stride, + lz_out_start_byte, + comp_head_left); + + // the compressed buffer is bigger than the original data + if ((jpeg_size + alpha_lz_size) > (src->y * src->stride)) { + longjmp(jpeg_data->data.jmp_env, 1); + } + + dest->descriptor.type = SPICE_IMAGE_TYPE_JPEG_ALPHA; + dest->u.jpeg_alpha.flags = 0; + if (src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN) { + dest->u.jpeg_alpha.flags |= SPICE_JPEG_ALPHA_FLAGS_TOP_DOWN; + } + + dest->u.jpeg_alpha.jpeg_size = jpeg_size; + dest->u.jpeg_alpha.data_size = jpeg_size + alpha_lz_size; + + o_comp_data->comp_buf = jpeg_data->data.bufs_head; + o_comp_data->comp_buf_size = jpeg_size + alpha_lz_size; + o_comp_data->is_lossy = TRUE; + stat_compress_add(jpeg_alpha_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 5bb0208..939221f 100644 --- a/server/dcc-encoders.h +++ b/server/dcc-encoders.h @@ -188,6 +188,10 @@ int image_encoders_compress_lz(ImageEncoders *enc, SpiceImage *dest, SpiceBitmap *src, compress_send_data_t* o_comp_data, stat_info_t *stats); +int image_encoders_compress_jpeg(ImageEncoders *enc, SpiceImage *dest, + SpiceBitmap *src, compress_send_data_t* o_comp_data, + stat_info_t *jpeg_stats, + stat_info_t *jpeg_alpha_stats); #define RED_RELEASE_BUNCH_SIZE 64 diff --git a/server/dcc.c b/server/dcc.c index ca6f5b5..218baad 100644 --- a/server/dcc.c +++ b/server/dcc.c @@ -784,133 +784,6 @@ glz: return TRUE; } -static int image_encoders_compress_jpeg(ImageEncoders *enc, SpiceImage *dest, - SpiceBitmap *src, compress_send_data_t* o_comp_data, - stat_info_t *jpeg_stats, // FIXME put all stats in a structure - stat_info_t *jpeg_alpha_stats) -{ - JpegData *jpeg_data = &enc->jpeg_data; - LzData *lz_data = &enc->lz_data; - JpegEncoderContext *jpeg = enc->jpeg; - LzContext *lz = enc->lz; - volatile JpegEncoderImageType jpeg_in_type; - int jpeg_size = 0; - volatile int has_alpha = FALSE; - int alpha_lz_size = 0; - int comp_head_filled; - int comp_head_left; - int stride; - uint8_t *lz_out_start_byte; - stat_start_time_t start_time; - stat_start_time_init(&start_time, jpeg_alpha_stats); - -#ifdef COMPRESS_DEBUG - spice_info("JPEG compress"); -#endif - - switch (src->format) { - case SPICE_BITMAP_FMT_16BIT: - jpeg_in_type = JPEG_IMAGE_TYPE_RGB16; - break; - case SPICE_BITMAP_FMT_24BIT: - jpeg_in_type = JPEG_IMAGE_TYPE_BGR24; - break; - case SPICE_BITMAP_FMT_32BIT: - jpeg_in_type = JPEG_IMAGE_TYPE_BGRX32; - break; - case SPICE_BITMAP_FMT_RGBA: - jpeg_in_type = JPEG_IMAGE_TYPE_BGRX32; - has_alpha = TRUE; - break; - default: - return FALSE; - } - - encoder_data_init(&jpeg_data->data); - - if (setjmp(jpeg_data->data.jmp_env)) { - encoder_data_reset(&jpeg_data->data); - return FALSE; - } - - if (src->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE) { - spice_chunks_linearize(src->data); - } - - jpeg_data->data.u.lines_data.chunks = src->data; - jpeg_data->data.u.lines_data.stride = src->stride; - if ((src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN)) { - jpeg_data->data.u.lines_data.next = 0; - jpeg_data->data.u.lines_data.reverse = 0; - stride = src->stride; - } else { - jpeg_data->data.u.lines_data.next = src->data->num_chunks - 1; - jpeg_data->data.u.lines_data.reverse = 1; - stride = -src->stride; - } - jpeg_size = jpeg_encode(jpeg, enc->jpeg_quality, jpeg_in_type, - src->x, src->y, NULL, - 0, stride, jpeg_data->data.bufs_head->buf.bytes, - sizeof(jpeg_data->data.bufs_head->buf)); - - // the compressed buffer is bigger than the original data - if (jpeg_size > (src->y * src->stride)) { - longjmp(jpeg_data->data.jmp_env, 1); - } - - if (!has_alpha) { - dest->descriptor.type = SPICE_IMAGE_TYPE_JPEG; - dest->u.jpeg.data_size = jpeg_size; - - o_comp_data->comp_buf = jpeg_data->data.bufs_head; - o_comp_data->comp_buf_size = jpeg_size; - o_comp_data->is_lossy = TRUE; - - stat_compress_add(jpeg_stats, start_time, src->stride * src->y, - o_comp_data->comp_buf_size); - return TRUE; - } - - lz_data->data.bufs_head = jpeg_data->data.bufs_tail; - lz_data->data.bufs_tail = lz_data->data.bufs_head; - - comp_head_filled = jpeg_size % sizeof(lz_data->data.bufs_head->buf); - comp_head_left = sizeof(lz_data->data.bufs_head->buf) - comp_head_filled; - lz_out_start_byte = lz_data->data.bufs_head->buf.bytes + comp_head_filled; - - 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; - - alpha_lz_size = lz_encode(lz, LZ_IMAGE_TYPE_XXXA, src->x, src->y, - !!(src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN), - NULL, 0, src->stride, - lz_out_start_byte, - comp_head_left); - - // the compressed buffer is bigger than the original data - if ((jpeg_size + alpha_lz_size) > (src->y * src->stride)) { - longjmp(jpeg_data->data.jmp_env, 1); - } - - dest->descriptor.type = SPICE_IMAGE_TYPE_JPEG_ALPHA; - dest->u.jpeg_alpha.flags = 0; - if (src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN) { - dest->u.jpeg_alpha.flags |= SPICE_JPEG_ALPHA_FLAGS_TOP_DOWN; - } - - dest->u.jpeg_alpha.jpeg_size = jpeg_size; - dest->u.jpeg_alpha.data_size = jpeg_size + alpha_lz_size; - - o_comp_data->comp_buf = jpeg_data->data.bufs_head; - o_comp_data->comp_buf_size = jpeg_size + alpha_lz_size; - o_comp_data->is_lossy = TRUE; - stat_compress_add(jpeg_alpha_stats, start_time, src->stride * src->y, - o_comp_data->comp_buf_size); - return TRUE; -} - #ifdef USE_LZ4 static int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest, SpiceBitmap *src, compress_send_data_t* o_comp_data) -- 2.7.4 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel