static inline pixman_image_t *__surface_create_stride(pixman_format_code_t format, int width, int height, int stride) { uint8_t *data; uint8_t *stride_data; pixman_image_t *surface; PixmanData *pixman_data; data = (uint8_t *)spice_malloc_n(abs(stride), height); if (stride < 0) { stride_data = data + (-stride) * (height - 1); } else { stride_data = data; } surface = pixman_image_create_bits(format, width, height, (uint32_t *)stride_data, stride); if (surface == NULL) { free(data); spice_error("create surface failed, out of memory"); } pixman_data = pixman_image_add_data(surface); pixman_data->data = data; pixman_data->format = format; return surface; }
MJpegEncoder *mjpeg_encoder_new(int width, int height) { MJpegEncoder *enc; enc = spice_new0(MJpegEncoder, 1); enc->first_frame = TRUE; enc->width = width; enc->height = height; enc->stride = width * 3; enc->quality = 70; if (enc->stride < width) { abort(); } enc->frame = spice_malloc_n(enc->stride, height); enc->cinfo.err = jpeg_std_error(&enc->jerr); jpeg_create_compress(&enc->cinfo); return enc; }