Fix all warnings in TurboJPEG code

Actually use the error code from tjCompress() by logging the errors.

Make sure width is more than zero before filling the pad with the last
pixel data.
This commit is contained in:
Pavel Roskin 2016-12-24 19:39:17 -08:00
parent 15a24ff1c4
commit bcaa1709e0

View File

@ -28,6 +28,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <turbojpeg.h> #include <turbojpeg.h>
#include "log.h"
/*****************************************************************************/ /*****************************************************************************/
int APP_CC int APP_CC
@ -81,18 +82,28 @@ xrdp_jpeg_compress(void *handle, char *in_data, int width, int height,
*dst32 = pixel; *dst32 = pixel;
dst32++; dst32++;
} }
if (width > 0)
{
for (i = 0; i < e; i++) for (i = 0; i < e; i++)
{ {
*dst32 = pixel; *dst32 = pixel;
dst32++; dst32++;
} }
} }
}
src_buf = (unsigned char *) temp_buf; src_buf = (unsigned char *) temp_buf;
} }
dst_buf = (unsigned char*)(s->p); dst_buf = (unsigned char*)(s->p);
error = tjCompress(tj_han, src_buf, width + e, (width + e) * 4, height, error = tjCompress(tj_han, src_buf, width + e, (width + e) * 4, height,
TJPF_XBGR, dst_buf, &cdata_bytes, TJPF_XBGR, dst_buf, &cdata_bytes,
TJSAMP_420, quality, 0); TJSAMP_420, quality, 0);
if (error != 0)
{
log_message(LOG_LEVEL_ERROR,
"xrdp_jpeg_compress: tjCompress error: %s",
tjGetErrorStr());
}
s->p += cdata_bytes; s->p += cdata_bytes;
g_free(temp_buf); g_free(temp_buf);
return height; return height;
@ -171,6 +182,13 @@ xrdp_codec_jpeg_compress(void *handle,
quality, /* jpeg quality */ quality, /* jpeg quality */
0 /* flags */ 0 /* flags */
); );
if (error != 0)
{
log_message(LOG_LEVEL_ERROR,
"xrdp_codec_jpeg_compress: tjCompress error: %s",
tjGetErrorStr());
}
*io_len = lio_len; *io_len = lio_len;
return height; return height;
} }