Spice image compression algorithm related code logic flow

Source: Internet
Author: User
Tags quic

The following is reproduced http://blog.csdn.net/zhoujiaxq/article/details/11201893 content, is a simple introduction to the image algorithm process

The current spice image compression is mainly based on QUIC,GLZ and JPEG. Quic and Glz are lossless compression algorithms, Quic mainly used for photographs, Glz for artificial images, JPEG is mainly used for photo compression but is lossy. JPEG can save 50% of the bandwidth, Glz can only save 20%, but JPEG brings more overhead, so you cannot use JPEG for compression.

Spice website for WAN Support introduction: Http://spice-space.org/page/Features/WanSupport

The process of spice image compression:

QXL first gets the image of the area to refresh through the GDI interface, and then passes it to the spice-server,spice-server after acquiring the image through

static inline void marshall_qxl_drawable (redchannelclient *rcc,spicemarshaller *m, Drawablepipeitem *dpi)

[CPP]View Plaincopy
  1. static inline void  marshall_ Qxl_drawable (redchannelclient *rcc,spicemarshaller *m, drawablepipeitem *dpi)   
The function first determines whether the image should be treated as a video or an image, and if it is a video call Red_marshall_stream_data (RCC, M, item)

[CPP]View Plaincopy
    1. Red_marshall_stream_data (RCC, M, item)
If the image first determines whether JPEG compression is used, whether JPEG compression is static void Red_init (Redworker *worker, Workerinitdata *init_data) [CPP]View Plaincopy
  1. static void
setting, Worker->jpeg_state = init_data->jpeg_state;

If you want to use JPEG compression can be changed directly to Worker->jpeg_state =spice_wan_compression_always; or in REDS.C

spice_wan_compression_t jpeg_state = Spice_wan_compression_auto; Change to

spice_wan_compression_t jpeg_state = spice_wan_compression_always;

The final compression of images in Spice-server is

static inline int red_compress_image (displaychannelclient *dcc,spiceimage *dest, Spicebitmap *src, drawable *drawa Ble,int can_lossy,compress_send_data_t* O_comp_data)

[CPP]View Plaincopy
  1. Static inline intred_compress_image (displaychannelclient *dcc,spiceimage *dest, Spicebitmap *src, drawable *drawable,intcan_lossy,compress_send_data_t* O_comp_data)
in this function, according to the image_compression, the image size, the image format to select the corresponding compression algorithm.

Spice-server through TCP transmission to the SPICE-GTK client, the client will use the data flow to determine what compression algorithm is adopted and the corresponding algorithm to decode.

Ornate Split Line ********************************************* *******************

A path that triggers Quic decoding, and the server sends a SPICE_MSG_DISPLAY_DRAW_COPY message
Display_handle_draw_copy for processing
->surface->canvas->ops->draw_copy
->canvas_draw_copy
->canvas_get_image
->canvas_get_image_internal
->canvas_get_quic

1. Function entry of Quic algorithm
Canvas_get_quic This function eventually returns a surface, the original bitmap is written to
Dest = (uint8_t *) pixman_image_get_data (surface);

typedef struct DISPLAY_SURFACE {
Guint32 surface_id;
BOOL Primary;
Enum SPICESURFACEFMT format;
int width, height, stride, size;
int shmid;
uint8_t *data;
Spicecanvas *canvas;
Spiceglzdecoder *glz_decoder;
Spicezlibdecoder *zlib_decoder;
Spicejpegdecoder *jpeg_decoder;
} display_surface;


struct _spicecanvas {
Spicecanvasops *ops; Encapsulation of function pointers for all operation functions
};


Client Add PRINT Statement
In the canvas_base.c file function canvas_draw_copy Add the following output:
pixman_image_t *canvas_image = Spice_canvas->ops->get_image (Spice_canvas, FALSE);
int width = pixman_image_get_width (canvas_image);
int height = pixman_image_get_height (canvas_image);


Spice_debug ("Canvas_draw_copy:%x:%d:%d, [bbox]:%d,%d,%d,%d, [type]%d, [src_area]:%d,%d,%d,%d],
Canvas_image, width, height, bbox->left, Bbox->top,
Bbox->right-bbox->left, Bbox->bottom-bbox->top,
Copy->src_bitmap->descriptor.type,
Copy->src_area.left, Copy->src_area.top,
Copy->src_area.right-copy->src_area.left, Copy->src_area.bottom-
Copy->src_area.top
);


Server-side image capture and compression:
The following functions are in the Red_worker.c file.
The Display_channel_send_item function reads an update from the QXL driver to the current image and then sends it to the client
->marshall_qxl_drawable judge the current image when the video or the image of the refresh, if the video is flushed back to exit, then determine whether lossless or lossy compression, call the relevant
function interface. JPEG is lossy compression, which uses lossless compression according to the settings here.
->red_marshall_qxl_drawable
->red_marshall_qxl_draw_copy
->fill_bits,fill_mask
->red_compress_image into the selection of image compression algorithm, currently between the Quic and Glz LZ algorithm, the default is Glz, according to the image source X, Y, and Stripe and so on, whether
Using the QUIC algorithm
->red_quic_compress_image Quic algorithm:

Spice image compression algorithm related code logic flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.