Commit f2b7da41 authored by AlexandrX Konovalov's avatar AlexandrX Konovalov Committed by Dmitry Ermilov

JPEGe/JPEGd code cleanup

1) Explicitly delete unused ctors/assignment operators.
2) Check for NULL before dereference of pointers.
3) Remove redundant conditions.
4) In CJPEGEncoder::ColorConvert() rule out unsupported cases.

    Issue: MDP-52543

(cherry picked from commit 25bdde0d)
parent efa2d960
......@@ -1936,11 +1936,11 @@ mfxStatus MFXVideoENCODEMJPEG::EncodeFrameCheck(mfxEncodeCtrl *ctrl, mfxFrameSur
if (MFX_ERR_NONE == sts || MFX_WRN_INCOMPATIBLE_VIDEO_PARAM == sts || MFX_ERR_MORE_BITSTREAM == sts)
{
// EncodeFrameCheck(ctrl, surface, bs, reordered_surface, pInternalParams) processes
// !surface case, so here we must have valid pOriginalSurface.
// lock surface. If input surface is opaque core will lock both opaque and associated realSurface
if (pOriginalSurface)
{
m_core->IncreaseReference(&(pOriginalSurface->Data));
}
m_core->IncreaseReference(&(pOriginalSurface->Data));
MJPEGEncodeTask *pTask = NULL;
{
......
......@@ -36,6 +36,11 @@ public:
// Destructor
~CJpegTaskBuffer(void);
CJpegTaskBuffer(const CJpegTaskBuffer&) = delete;
CJpegTaskBuffer(CJpegTaskBuffer&&) = delete;
CJpegTaskBuffer& operator=(const CJpegTaskBuffer&) = delete;
CJpegTaskBuffer& operator=(CJpegTaskBuffer&&) = delete;
// Allocate the buffer
mfxStatus Allocate(const size_t size);
......
......@@ -23,6 +23,7 @@
#include "ippi.h"
#include "ipps.h"
#include <memory>
#include <stdio.h>
#include <string.h>
#include "jpegbase.h"
......@@ -1913,7 +1914,6 @@ JERRCODE CJPEGDecoder::UpSampling(uint32_t rowMCU, uint32_t colMCU, uint32_t max
int srcStep;
int dstStep;
uint8_t* pSrc;
uint8_t* pTmp;
uint8_t* pDst;
uint32_t srcWidth, intervalSize, tileSize, pixelToProcess;
......@@ -1926,7 +1926,7 @@ JERRCODE CJPEGDecoder::UpSampling(uint32_t rowMCU, uint32_t colMCU, uint32_t max
// set the pointer to source buffer
pSrc = curr_comp->GetSSBufferPtr<uint8_t> (0) + 8 * colMCU * curr_comp->m_scan_hsampling;
// set the pointer to temporary buffer
pTmp = (uint8_t*)malloc(2 * srcWidth / m_dd_factor);
std::unique_ptr<uint8_t> pTmp( new uint8_t[2 * srcWidth / m_dd_factor] );
// set the pointer to destination buffer
pDst = curr_comp->GetCCBufferPtr<uint8_t> (0) + 8 * colMCU * curr_comp->m_h_factor;
......@@ -1944,10 +1944,9 @@ JERRCODE CJPEGDecoder::UpSampling(uint32_t rowMCU, uint32_t colMCU, uint32_t max
pixelToProcess = MFX_MIN(tileSize, srcWidth / m_dd_factor);
while(j < (int) srcWidth / m_dd_factor)
{
status = mfxiSampleUpRowH2V1_Triangle_JPEG_8u_C1(pSrc + j, pixelToProcess, pTmp + j * 2);
status = mfxiSampleUpRowH2V1_Triangle_JPEG_8u_C1(pSrc + j, pixelToProcess, pTmp.get() + j * 2);
if(ippStsNoErr != status)
{
free(pTmp);
LOG0("Error: mfxiSampleUpRowH2V1_Triangle_JPEG_8u_C1() failed!");
return JPEG_ERR_INTERNAL;
}
......@@ -1959,10 +1958,9 @@ JERRCODE CJPEGDecoder::UpSampling(uint32_t rowMCU, uint32_t colMCU, uint32_t max
pixelToProcess = MFX_MIN(2 * tileSize, 2 * srcWidth / m_dd_factor);
while(j < 2 * (int) srcWidth / m_dd_factor)
{
status = mfxiSampleUpRowH2V1_Triangle_JPEG_8u_C1(pTmp + j, pixelToProcess, pDst + j * 2);
status = mfxiSampleUpRowH2V1_Triangle_JPEG_8u_C1(pTmp.get() + j, pixelToProcess, pDst + j * 2);
if(ippStsNoErr != status)
{
free(pTmp);
LOG0("Error: mfxiSampleUpRowH2V1_Triangle_JPEG_8u_C1() failed!");
return JPEG_ERR_INTERNAL;
}
......@@ -1973,7 +1971,6 @@ JERRCODE CJPEGDecoder::UpSampling(uint32_t rowMCU, uint32_t colMCU, uint32_t max
pSrc += srcStep;
pDst += dstStep;
}
free(pTmp);
} // 411
......@@ -2046,7 +2043,6 @@ JERRCODE CJPEGDecoder::UpSampling(uint32_t rowMCU, uint32_t colMCU, uint32_t max
int srcStep;
int tmpStep;
uint8_t* pSrc;
uint8_t* pTmp;
uint8_t* pDst;
mfxSize srcRoiSize;
mfxSize tmpRoiSize;
......@@ -2057,7 +2053,7 @@ JERRCODE CJPEGDecoder::UpSampling(uint32_t rowMCU, uint32_t colMCU, uint32_t max
// set the pointer to source buffer
pSrc = curr_comp->GetCCBufferPtr<uint8_t> (0) + 8 * colMCU;
// set the pointer to temporary buffer
pTmp = (uint8_t*)malloc(tmpStep * m_curr_scan->mcuHeight / 2);
std::unique_ptr<uint8_t> pTmp( new uint8_t[tmpStep * m_curr_scan->mcuHeight / 2] );
// set the pointer to destination buffer
pDst = curr_comp->GetCCBufferPtr<uint8_t> (0) + 8 * colMCU / 2;
......@@ -2069,23 +2065,19 @@ JERRCODE CJPEGDecoder::UpSampling(uint32_t rowMCU, uint32_t colMCU, uint32_t max
tmpRoiSize.width = (maxMCU - colMCU) * 8 / 2;
tmpRoiSize.height = m_curr_scan->mcuHeight / 2;
status = mfxiSampleDownH2V2_JPEG_8u_C1R(pSrc, srcStep, srcRoiSize, pTmp, tmpStep, tmpRoiSize);
status = mfxiSampleDownH2V2_JPEG_8u_C1R(pSrc, srcStep, srcRoiSize, pTmp.get(), tmpStep, tmpRoiSize);
if(ippStsNoErr != status)
{
free(pTmp);
LOG0("Error: mfxiSampleDownH2V2_JPEG_8u_C1R() failed!");
return JPEG_ERR_INTERNAL;
}
status = mfxsCopy_8u(pTmp, pDst, tmpStep * m_curr_scan->mcuHeight / 2);
status = mfxsCopy_8u(pTmp.get(), pDst, tmpStep * m_curr_scan->mcuHeight / 2);
if(ippStsNoErr != status)
{
free(pTmp);
LOG0("Error: mfxs_Copy_8u() failed!");
return JPEG_ERR_INTERNAL;
}
free(pTmp);
}
// vertical downsampling
......@@ -2524,7 +2516,6 @@ JERRCODE CJPEGDecoder::ReconstructMCURowBL8x8_NxN(int16_t* pMCUBuf,
uint8_t* lnz = 0;
uint8_t* dst = 0;
int dstStep = m_ccWidth;
uint16_t* qtbl;
int status;
CJPEGColorComponent* curr_comp;
const int thread_id = 0;
......@@ -2537,12 +2528,12 @@ JERRCODE CJPEGDecoder::ReconstructMCURowBL8x8_NxN(int16_t* pMCUBuf,
lnz = m_ccomp[c].GetLNZBufferPtr(thread_id);
curr_lnz = mcu_col * curr_comp->m_lnz_ds;
qtbl = m_qntbl[curr_comp->m_q_selector];
uint16_t* qtbl = m_qntbl[curr_comp->m_q_selector];
if(!qtbl)
{
LOG1("Error: in CJPEGDecoder::ReconstructMCURowBL8x8_NxN() m_qntbl[] is empty for ",
curr_comp->m_q_selector);
return JPEG_ERR_INTERNAL;
LOG1("Error: in CJPEGDecoder::ReconstructMCURowBL8x8_NxN() m_qntbl[] is empty for ",
curr_comp->m_q_selector);
return JPEG_ERR_INTERNAL;
}
for(k = 0; k < curr_comp->m_vsampling; k++)
......
......@@ -98,8 +98,6 @@ CJpegTask::~CJpegTask(void)
void CJpegTask::Close(void)
{
size_t i;
// delete all buffers allocated
for (auto& pic: m_pics)
{
......
......@@ -2023,21 +2023,6 @@ JERRCODE CJPEGEncoder::Init(void)
curr_comp->m_cc_step = m_curr_scan.numxMCU * m_curr_scan.mcuWidth;
break;
//case JPEG_EXTENDED:
// curr_comp->m_cc_height = m_mcuHeight;
// curr_comp->m_cc_step = m_numxMCU * m_mcuWidth * ((m_jpeg_precision <= 8) ? sizeof(uint8_t) : sizeof(int16_t));
// break;
//case JPEG_PROGRESSIVE:
// curr_comp->m_cc_height = m_mcuHeight;
// curr_comp->m_cc_step = m_numxMCU * m_mcuWidth;
// break;
//case JPEG_LOSSLESS:
// curr_comp->m_cc_height = m_mcuHeight;
// curr_comp->m_cc_step = m_numxMCU * m_mcuWidth * sizeof(int16_t);
// break;
default:
return JPEG_ERR_PARAMS;
}
......@@ -2055,13 +2040,6 @@ JERRCODE CJPEGEncoder::Init(void)
if(JPEG_OK != jerr)
return jerr;
if(JPEG_LOSSLESS == m_jpeg_mode)
{
curr_comp->m_row1.Allocate(curr_comp->m_cc_step);
curr_comp->m_row2.Allocate(curr_comp->m_cc_step);
curr_comp->m_curr_row = (int16_t*)curr_comp->m_row1.m_buffer;
curr_comp->m_prev_row = (int16_t*)curr_comp->m_row2.m_buffer;
}
} // for m_jpeg_ncomp
if(JPEG_PROGRESSIVE == m_jpeg_mode)
......@@ -2082,24 +2060,6 @@ JERRCODE CJPEGEncoder::Init(void)
tr_buf_size = m_curr_scan.numxMCU * m_curr_scan.numyMCU * m_nblock * DCTSIZE2 * sizeof(int16_t) * m_num_threads;
break;
//case JPEG_EXTENDED:
// if(!m_optimal_htbl)
// tr_buf_size = m_numxMCU * m_nblock * DCTSIZE2 * sizeof(int16_t) * m_num_threads;
// else
// tr_buf_size = m_numxMCU * m_numyMCU * m_nblock * DCTSIZE2 * sizeof(int16_t) * m_num_threads;
// break;
//case JPEG_PROGRESSIVE:
// tr_buf_size = m_numxMCU * m_numyMCU * m_nblock * DCTSIZE2 * sizeof(int16_t) * m_num_threads;
// break;
//case JPEG_LOSSLESS:
// if(!m_optimal_htbl)
// tr_buf_size = m_numxMCU * m_nblock * sizeof(int16_t) * m_num_threads;
// else
// tr_buf_size = m_numxMCU * m_numyMCU * m_nblock * sizeof(int16_t) * m_num_threads;
// break;
default:
return JPEG_ERR_PARAMS;
}
......@@ -2320,6 +2280,11 @@ JERRCODE CJPEGEncoder::ColorConvert(uint32_t rowMCU, uint32_t colMCU, uint32_t m
int dstStep;
uint8_t* pDst8u;
if(m_src.precision > 8)
{
return JPEG_ERR_INTERNAL;
}
dstStep = m_ccomp[0].m_cc_step;
convert = 1;
......@@ -2456,6 +2421,10 @@ JERRCODE CJPEGEncoder::ColorConvert(uint32_t rowMCU, uint32_t colMCU, uint32_t m
if(JD_PIXEL == m_src.order)
{
if(m_src.precision > 8)
{
return JPEG_ERR_INTERNAL;
}
status = mfxiRGBToYCbCr_JPEG_8u_C3P3R(pSrc8u,srcStep,pDst8u,dstStep,roi);
}
else
......@@ -2482,6 +2451,11 @@ JERRCODE CJPEGEncoder::ColorConvert(uint32_t rowMCU, uint32_t colMCU, uint32_t m
int dstStep;
uint8_t* pDst8u[3];
if(m_src.precision > 8)
{
return JPEG_ERR_INTERNAL;
}
dstStep = m_ccomp[0].m_cc_step;
convert = 1;
......@@ -2504,6 +2478,11 @@ JERRCODE CJPEGEncoder::ColorConvert(uint32_t rowMCU, uint32_t colMCU, uint32_t m
int dstStep;
uint8_t* pDst8u[3];
if(m_src.precision > 8)
{
return JPEG_ERR_INTERNAL;
}
dstStep = m_ccomp[0].m_cc_step;
convert = 1;
......@@ -2527,6 +2506,11 @@ JERRCODE CJPEGEncoder::ColorConvert(uint32_t rowMCU, uint32_t colMCU, uint32_t m
int dstStep[3];
uint8_t* pDst8u[3];
if(m_src.precision > 8)
{
return JPEG_ERR_INTERNAL;
}
convert = 1;
dstStep[0] = m_ccomp[0].m_cc_step;
......@@ -2552,6 +2536,11 @@ JERRCODE CJPEGEncoder::ColorConvert(uint32_t rowMCU, uint32_t colMCU, uint32_t m
int dstStep;
uint8_t* pDst8u[4];
if(m_src.precision > 8)
{
return JPEG_ERR_INTERNAL;
}
dstStep = m_ccomp[0].m_cc_step;
convert = 1;
......@@ -2575,6 +2564,11 @@ JERRCODE CJPEGEncoder::ColorConvert(uint32_t rowMCU, uint32_t colMCU, uint32_t m
int dstStep;
uint8_t* pDst8u[4];
if(m_src.precision > 8)
{
return JPEG_ERR_INTERNAL;
}
dstStep = m_ccomp[0].m_cc_step;
convert = 1;
......@@ -4555,70 +4549,10 @@ JERRCODE CJPEGEncoder::WriteHeader(void)
}
break;
case JPEG_EXTENDED:
if(!m_optimal_htbl)
{
jerr = WriteDHT(&m_dctbl[0]);
if(JPEG_OK != jerr)
{
LOG0("Error: WriteDHT() failed");
return jerr;
}
jerr = WriteDHT(&m_actbl[0]);
if(JPEG_OK != jerr)
{
LOG0("Error: WriteDHT() failed");
return jerr;
}
if(m_jpeg_ncomp != 1 && (m_jpeg_color == JC_YCBCR || m_jpeg_color == JC_YCCK || m_jpeg_color == JC_NV12))
{
jerr = WriteDHT(&m_dctbl[1]);
if(JPEG_OK != jerr)
{
LOG0("Error: WriteDHT() failed");
return jerr;
}
jerr = WriteDHT(&m_actbl[1]);
if(JPEG_OK != jerr)
{
LOG0("Error: WriteDHT() failed");
return jerr;
}
}
}
else
{
GenerateHuffmanTablesEX();
}
break;
case JPEG_PROGRESSIVE:
// always generated tables
break;
case JPEG_LOSSLESS:
if(!m_optimal_htbl)
{
jerr = WriteDHT(&m_dctbl[0]);
if(JPEG_OK != jerr)
{
LOG0("Error: WriteDHT() failed");
return jerr;
}
}
else
{
jerr = GenerateHuffmanTables();
if(JPEG_OK != jerr)
{
LOG0("Error: GenerateHuffmanTables() failed");
return jerr;
}
}
break;
default:
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment