Skip to content

Instantly share code, notes, and snippets.

@scottellis
Created December 10, 2011 23:05
Show Gist options
  • Save scottellis/1456937 to your computer and use it in GitHub Desktop.
Save scottellis/1456937 to your computer and use it in GitHub Desktop.
SpacesRecordDecompress alternative
bool SpacesRecordDecompress(SYNTRO_RECORD_HEADER *pSRH, unsigned char **pBuff, int bufLen, bool bRight)
{
SYNTRO_RECORD_VIDEO *pSRV;
Mat mJpeg;
int size_required;
bool result = false;
switch (pSRH->nType)
{
case SYNTRO_RECORD_TYPE_VIDEO:
pSRV = (SYNTRO_RECORD_VIDEO *)(pSRH);
switch (pSRH->nSubType)
{
case SYNTRO_RECORD_TYPE_VIDEO_MJPEG:
if (bRight)
{
Mat mImage(ConvertUC4ToInt(pSRV->nRightSize), 1, CV_8UC1,
(unsigned char *)(pSRV+1) + ConvertUC4ToInt(pSRV->nLeftSize));
mJpeg = imdecode(mImage, 1);
}
else
{
Mat mImage(ConvertUC4ToInt(pSRV->nLeftSize), 1, CV_8UC1,
(unsigned char *)(pSRV+1));
mJpeg = imdecode(mImage, 1);
}
size_required = mJpeg.rows * mJpeg.cols * 3;
if (*pBuff)
{
if (bufLen < size_required)
{
free(*pBuff);
*pBuff = NULL;
}
}
if (!*pBuff)
{
*pBuff = (unsigned char *)malloc(size_required);
if (!*pBuff)
break;
}
memcpy(*pBuff, mJpeg.data, mJpeg.rows * mJpeg.cols * 3);
result = true;
break;
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment