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:
Christophe Fergeau 2011-06-28 14:28:22 +02:00
parent 3a433912e9
commit c12bafbc53

View File

@ -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;