zynq_7010/zynq_7010_code/Jpegcompress.cpp

43 lines
1.1 KiB
C++
Raw Permalink Normal View History

2023-07-20 03:48:38 +00:00
#include "Jpegcompress.h"
#include <string>
2023-07-17 03:29:37 +00:00
2023-07-20 03:48:38 +00:00
JpegCompress::JpegCompress(int quality):tjInstance(NULL)
,m_quality(quality)
{
}
2023-07-17 03:29:37 +00:00
2023-07-20 03:48:38 +00:00
JpegCompress::~JpegCompress()
{
tjDestroy(tjInstance);
}
2023-07-17 03:29:37 +00:00
2023-07-20 03:48:38 +00:00
HG_JpegCompressInfo JpegCompress::GetCompressedImg(cv::Mat& mat)
{
HG_JpegCompressInfo info={0};
if(mat.empty())
{
LOG("JpegCompress Empty Mat! warnning !!!!\n");
return info;
}
tjInstance = tjInitCompress();
int outSubsamp;
int flags = 0;
int pixelFormat;
if (mat.channels() == 1)
{
outSubsamp = TJSAMP_GRAY;
pixelFormat = TJPF_GRAY;
}
else
{
pixelFormat = TJPF_RGB;
outSubsamp = TJSAMP_444;
}
//std::chrono::steady_clock::time_point _start = std::chrono::steady_clock::now();
2023-08-09 07:31:27 +00:00
//LOG("image rows= %d cols= %d pixelFormat= %d \n",mat.rows,mat.cols,pixelFormat);
2023-07-20 03:48:38 +00:00
tjCompress2(tjInstance, mat.data, mat.cols, 0, mat.rows, pixelFormat,
&info.pJpegData, (long unsigned int*)&info.DataLength, outSubsamp, m_quality, flags);
2023-07-17 03:29:37 +00:00
2023-07-20 03:48:38 +00:00
//LOG("jpeg compress done \n");
return info;
}