mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-08-18 05:00:09 +00:00
mjpeg_encoder: allocate "row" on demand
It's not used when we use jpeg-turbo colorspaces, so it's better to allocate it when we know we'll need it rather than always allocating it even if it won't be used.
This commit is contained in:
parent
3a433912e9
commit
c12bafbc53
@ -27,7 +27,6 @@
|
||||
struct MJpegEncoder {
|
||||
int width;
|
||||
int height;
|
||||
int stride;
|
||||
uint8_t *row;
|
||||
int first_frame;
|
||||
int quality;
|
||||
@ -48,15 +47,8 @@ MJpegEncoder *mjpeg_encoder_new(int width, int height)
|
||||
enc->first_frame = TRUE;
|
||||
enc->width = width;
|
||||
enc->height = height;
|
||||
enc->stride = width * 3;
|
||||
enc->quality = 70;
|
||||
if (enc->stride < width) {
|
||||
abort();
|
||||
}
|
||||
enc->row = spice_malloc(enc->stride);
|
||||
|
||||
enc->cinfo.err = jpeg_std_error(&enc->jerr);
|
||||
|
||||
jpeg_create_compress(&enc->cinfo);
|
||||
|
||||
return enc;
|
||||
@ -240,6 +232,15 @@ int mjpeg_encoder_start_frame(MJpegEncoder *encoder, SpiceBitmapFmt format,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((encoder->pixel_converter != NULL) && (encoder->row == NULL)) {
|
||||
unsigned int stride = encoder->width * 3;
|
||||
/* check for integer overflow */
|
||||
if (stride < encoder->width) {
|
||||
return FALSE;
|
||||
}
|
||||
encoder->row = spice_malloc(stride);
|
||||
}
|
||||
|
||||
jpeg_mem_dest(&encoder->cinfo, dest, dest_len);
|
||||
|
||||
encoder->cinfo.image_width = encoder->width;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user