Jpeg: Fixing encoder memory issue
Review URL: http://webrtc-codereview.appspot.com/93001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@246 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
da03e21908
commit
069e63085e
@ -143,6 +143,19 @@ JpegEncoder::Encode(const RawImage& inputImage)
|
|||||||
_cinfo->comp_info[2].v_samp_factor = 1;
|
_cinfo->comp_info[2].v_samp_factor = 1;
|
||||||
_cinfo->raw_data_in = TRUE;
|
_cinfo->raw_data_in = TRUE;
|
||||||
|
|
||||||
|
WebRtc_UWord32 height16 = (height + 15) & ~15;
|
||||||
|
WebRtc_UWord8* imgPtr = inputImage._buffer;
|
||||||
|
WebRtc_UWord8* origImagePtr = NULL;
|
||||||
|
if (height16 != height)
|
||||||
|
{
|
||||||
|
// Copy image to an adequate size buffer
|
||||||
|
WebRtc_UWord32 requiredSize = height16 * width * 3 >> 1;
|
||||||
|
origImagePtr = new WebRtc_UWord8[requiredSize];
|
||||||
|
memset(origImagePtr, 0, requiredSize);
|
||||||
|
memcpy(origImagePtr, inputImage._buffer, inputImage._length);
|
||||||
|
imgPtr = origImagePtr;
|
||||||
|
}
|
||||||
|
|
||||||
jpeg_start_compress(_cinfo, TRUE);
|
jpeg_start_compress(_cinfo, TRUE);
|
||||||
|
|
||||||
JSAMPROW y[16],u[8],v[8];
|
JSAMPROW y[16],u[8],v[8];
|
||||||
@ -158,13 +171,13 @@ JpegEncoder::Encode(const RawImage& inputImage)
|
|||||||
{
|
{
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
y[i] = (JSAMPLE*) inputImage._buffer + width * (i + j);
|
y[i] = (JSAMPLE*)imgPtr + width * (i + j);
|
||||||
|
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0)
|
||||||
{
|
{
|
||||||
u[i / 2] = (JSAMPLE*) inputImage._buffer + width * height +
|
u[i / 2] = (JSAMPLE*) imgPtr + width * height +
|
||||||
width / 2 * ((i + j) / 2);
|
width / 2 * ((i + j) / 2);
|
||||||
v[i / 2] = (JSAMPLE*) inputImage._buffer + width * height +
|
v[i / 2] = (JSAMPLE*) imgPtr + width * height +
|
||||||
width * height / 4 + width / 2 * ((i + j) / 2);
|
width * height / 4 + width / 2 * ((i + j) / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,6 +189,11 @@ JpegEncoder::Encode(const RawImage& inputImage)
|
|||||||
|
|
||||||
fclose(outFile);
|
fclose(outFile);
|
||||||
|
|
||||||
|
if (origImagePtr != NULL)
|
||||||
|
{
|
||||||
|
delete [] origImagePtr;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user