📄 decoder.cpp
字号:
(int*)&m_marker, dctbl, m_state); if(ippStsNoErr > status) { LOG0("Error: ippiDecodeHuffmanOne_JPEG_1u16s_C1() failed!"); return JPEG_INTERNAL_ERROR; } pMCUBuf++; } // for m_hsampling } // for m_vsampling } // for m_jpeg_ncomp m_restarts_to_go --; } // for m_numxMCU return JPEG_OK;} // CJPEGDecoder::DecodeHuffmanMCURowLS()JERRCODE CJPEGDecoder::ReconstructMCURowBL(Ipp16s* pMCUBuf,int nMCURow,int idThread){ int mcu_col, n, k, l; int threadOffsetCC; int threadOffsetSS; Ipp8u* dst = 0; int dst_step = m_ccWidth; Ipp8u* ss_buf; Ipp8u* cc_buf; Ipp16u* qtbl; IppStatus status;#ifdef __TIMING__ Ipp64u c0; Ipp64u c1;#endif threadOffsetCC = m_numxMCU * m_mcuWidth * m_mcuHeight * idThread; switch(m_jpeg_sampling) { default: case JS_444: threadOffsetSS = 0; break; case JS_422: threadOffsetSS = m_numxMCU * (m_mcuWidth>>1) * m_mcuHeight * idThread; break; case JS_244: threadOffsetSS = m_numxMCU * m_mcuWidth * (m_mcuHeight>>1) * idThread; break; case JS_411: threadOffsetSS = m_numxMCU * (m_mcuWidth>>1) * ((m_mcuHeight>>1)+2) * idThread; break; } for(mcu_col = 0; mcu_col < m_numxMCU; mcu_col++) { for(n = 0; n < m_jpeg_ncomp; n++) { ss_buf = m_ccomp[n].m_ss_buffer + threadOffsetSS; cc_buf = m_ccomp[n].m_cc_buffer + threadOffsetCC; qtbl = m_qntbl[m_ccomp[n].m_q_selector]; for(k = 0; k < m_ccomp[n].m_vsampling; k++) { if(m_ccomp[n].m_hsampling == m_max_hsampling && m_ccomp[n].m_vsampling == m_max_vsampling) { dst_step = m_ccWidth; dst = cc_buf + mcu_col*8*m_ccomp[n].m_hsampling + k*8*dst_step; } else { dst_step = m_ccWidth / m_ccomp[n].m_h_factor; dst = ss_buf + mcu_col*8*m_ccomp[n].m_hsampling + k*8*dst_step; } // skip border row (when 244 or 411 sampling) if(m_ccomp[n].m_v_factor == 2) { dst += dst_step; } for(l = 0; l < m_ccomp[n].m_hsampling; l++) { dst += l*8;#ifdef __TIMING__ c0 = ippCoreGetCpuClocks();#endif status = ippiDCTQuantInv8x8LS_JPEG_16s8u_C1R( pMCUBuf, dst, dst_step, qtbl); if(ippStsNoErr > status) { LOG0("Error: ippiDCTQuantInv8x8LS_JPEG_16s8u_C1R() failed!"); return JPEG_INTERNAL_ERROR; }#ifdef __TIMING__ c1 = ippCoreGetCpuClocks(); m_clk_dct += c1 - c0;#endif pMCUBuf += DCTSIZE2; } // for m_hsampling } // for m_vsampling } // for m_jpeg_ncomp } // for m_numxMCU return JPEG_OK;} // CJPEGDecoder::ReconstructMCURowBL()JERRCODE CJPEGDecoder::ReconstructMCURowLS(Ipp16s* pMCUBuf,int nMCURow,int idThread){ Ipp16s* pCurrRow; Ipp16s* pPrevRow; Ipp8u* pDst8u = 0; Ipp16s* pDst16s = 0; IppiSize roi; IppStatus status; pCurrRow = m_ccomp[0].m_curr_row; pPrevRow = m_ccomp[0].m_prev_row; roi.width = m_dst.width; roi.height = 1; if(m_dst.precision == 8) pDst8u = (Ipp8u*)m_dst.p.Data8u + nMCURow*m_dst.width; else pDst16s = m_dst.p.Data16s + nMCURow*m_dst.width; if(0 != nMCURow) { status = ippiReconstructPredRow_JPEG_16s_C1( pMCUBuf,pPrevRow,pCurrRow,m_dst.width,m_ss); } else { status = ippiReconstructPredFirstRow_JPEG_16s_C1( pMCUBuf,pCurrRow,m_dst.width,m_jpeg_precision,m_al); } if(ippStsNoErr != status) { return JPEG_INTERNAL_ERROR; } if(m_al) { status = ippsLShiftC_16s_I(m_al,pCurrRow,m_dst.width); if(ippStsNoErr != status) { return JPEG_INTERNAL_ERROR; } } if(m_dst.precision == 8) status = ippiConvert_16s8u_C1R(pCurrRow,m_dst.width*sizeof(Ipp16s),pDst8u,m_dst.width,roi); else status = ippsCopy_16s(pCurrRow,pDst16s,m_dst.width); if(ippStsNoErr != status) { return JPEG_INTERNAL_ERROR; } m_ccomp[0].m_curr_row = pPrevRow; m_ccomp[0].m_prev_row = pCurrRow; return JPEG_OK;} // CJPEGDecoder::ReconstructMCURowLS()JERRCODE CJPEGDecoder::DecodeScanBaseline(void){ int scount = 0; IppStatus status;#ifdef __TIMING__ Ipp64u c0; Ipp64u c1;#endif status = ippiDecodeHuffmanStateInit_JPEG_8u(m_state); if(ippStsNoErr != status) { return JPEG_INTERNAL_ERROR; } m_marker = JM_NONE; if(m_dctbl[0].IsEmpty()) { m_dctbl[0].Create(); m_dctbl[0].Init(0,0,(Ipp8u*)&DefaultLuminanceDCBits[0],(Ipp8u*)&DefaultLuminanceDCValues[0]); } if(m_dctbl[1].IsEmpty()) { m_dctbl[1].Create(); m_dctbl[1].Init(1,0,(Ipp8u*)&DefaultChrominanceDCBits[0],(Ipp8u*)&DefaultChrominanceDCValues[0]); } if(m_actbl[0].IsEmpty()) { m_actbl[0].Create(); m_actbl[0].Init(0,1,(Ipp8u*)&DefaultLuminanceACBits[0],(Ipp8u*)&DefaultLuminanceACValues[0]); } if(m_actbl[1].IsEmpty()) { m_actbl[1].Create(); m_actbl[1].Init(1,1,(Ipp8u*)&DefaultChrominanceACBits[0],(Ipp8u*)&DefaultChrominanceACValues[0]); }#ifdef _OPENMP#pragma omp parallel default(shared) if(m_jpeg_sampling != JS_411)#endif { int i; int idThread = 0; Ipp16s* pMCUBuf; // the pointer to Buffer for a current thread.#ifdef _OPENMP idThread = omp_get_thread_num(); // the thread id of the calling thread.#endif pMCUBuf = m_block_buffer + idThread * m_numxMCU * m_nblock * DCTSIZE2; i = 0; while(i < m_numyMCU) {#ifdef _OPENMP#pragma omp critical (IPP_JPEG_OMP)#endif { i = scount; scount++; if(i < m_numyMCU) {#ifdef __TIMING__ c0 = ippGetCpuClocks();#endif DecodeHuffmanMCURowBL(pMCUBuf);#ifdef __TIMING__ c1 = ippGetCpuClocks(); m_clk_huff += (c1 - c0);#endif } } if(i < m_numyMCU) {#ifdef __TIMING__ c0 = ippGetCpuClocks();#endif ReconstructMCURowBL(pMCUBuf, i, idThread);#ifdef __TIMING__ c1 = ippGetCpuClocks(); m_clk_dct += c1 - c0;#endif#ifdef __TIMING__ c0 = ippGetCpuClocks();#endif UpSampling(i,idThread);#ifdef __TIMING__ c1 = ippGetCpuClocks(); m_clk_ss += c1 - c0;#endif#ifdef __TIMING__ c0 = ippGetCpuClocks();#endif ColorConvert(i,idThread);#ifdef __TIMING__ c1 = ippGetCpuClocks(); m_clk_cc += c1 - c0;#endif } i++; } // for m_numyMCU } // OMP return JPEG_OK;} // CJPEGDecoder::DecodeScanBaseline()JERRCODE CJPEGDecoder::DecodeScanProgressive(void){ int i, j, k, n, l, c; int size; Ipp8u* src; int srcLen; JERRCODE jerr; IppStatus status; m_scan_count++; status = ippiDecodeHuffmanStateInit_JPEG_8u(m_state); if(ippStsNoErr != status) { return JPEG_INTERNAL_ERROR; } m_marker = JM_NONE; src = m_src.pData; srcLen = m_src.DataLen; for(size = 0, k = 0; k < m_jpeg_ncomp; k++) { size += (m_ccomp[k].m_hsampling * m_ccomp[k].m_vsampling); } Ipp16s* block; if(m_ss != 0 && m_se != 0) { // AC scan for(i = 0; i < m_numyMCU; i++) { for(k = 0; k < m_ccomp[m_curr_comp_no].m_vsampling; k++) { if(i*m_ccomp[m_curr_comp_no].m_vsampling*8 + k*8 >= m_jpeg_height) break; for(j = 0; j < m_numxMCU; j++) { block = m_block_buffer + (DCTSIZE2*size*(j+(i*m_numxMCU))); // skip any relevant components for(c = 0; c < m_ccomp[m_curr_comp_no].m_comp_no; c++) { block += (DCTSIZE2*m_ccomp[c].m_hsampling* m_ccomp[c].m_vsampling); } // Skip over relevant 8x8 blocks from this component. block += (k * DCTSIZE2 * m_ccomp[m_curr_comp_no].m_hsampling); for(l = 0; l < m_ccomp[m_curr_comp_no].m_hsampling; l++) { // Ignore the last column(s) of the image. if(((j*m_ccomp[m_curr_comp_no].m_hsampling*8) + (l*8)) >= m_jpeg_width) break; if(m_jpeg_restart_interval) { if(m_restarts_to_go == 0) { jerr = ProcessRestart(); if(JPEG_OK != jerr) { LOG0("Error: ProcessRestart() failed!"); return jerr; } } } IppiDecodeHuffmanSpec* actbl = m_actbl[m_ccomp[m_curr_comp_no].m_ac_selector]; if(m_ah == 0) { status = ippiDecodeHuffman8x8_ACFirst_JPEG_1u16s_C1( src, srcLen, &m_src.currPos, block, (int*)&m_marker, m_ss, m_se, m_al, actbl, m_state); if(ippStsNoErr > status) { LOG0("Error: ippiDecodeHuffman8x8_ACFirst_JPEG_1u16s_C1() failed!"); return JPEG_INTERNAL_ERROR; } } else { status = ippiDecodeHuffman8x8_ACRefine_JPEG_1u16s_C1( src, srcLen, &m_src.currPos, block, (int*)&m_marker, m_ss, m_se, m_al, actbl, m_state); if(ippStsNoErr > status) { LOG0("Error: ippiDecodeHuffman8x8_ACRefine_JPEG_1u16s_C1() failed!"); return JPEG_INTERNAL_ERROR; } } block += DCTSIZE2; m_restarts_to_go --; } // for m_hsampling } // for m_numxMCU } // for m_vsampling } // for m_numyMCU if(m_al == 0) { m_ccomp[m_curr_comp_no].m_ac_scan_completed = 1; } } else { // DC scan for(i = 0; i < m_numyMCU; i++) { for(j = 0; j < m_numxMCU; j++) { if(m_jpeg_restart_interval) { if(m_restarts_to_go == 0) { jerr = ProcessRestart(); if(JPEG_OK != jerr) { LOG0("Error: ProcessRestart() failed!"); return jerr; } } } block = m_block_buffer + (DCTSIZE2*size*(j+(i*m_numxMCU))); if(m_ah == 0) { // first DC scan for(n = 0; n < m_jpeg_ncomp; n++) { Ipp16s* lastDC = &m_ccomp[n].m_lastDC; IppiDecodeHuffmanSpec* dctbl = m_dctbl[m_ccomp[n].m_dc_selector]; for(k = 0; k < m_ccomp[n].m_vsampling; k++) { for(l = 0; l < m_ccomp[n].m_hsampling; l++) { status = ippiDecodeHuffman8x8_DCFirst_JPEG_1u16s_C1( src, srcLen, &m_src.currPos, block, lastDC, (int*)&m_marker, m_al, dctbl, m_state); if(ippStsNoErr > status) { LOG0("Error: ippiDecodeHuffman8x8_DCFirst_JPEG_1u16s_C1() failed!"); return JPEG_INTERNAL_ERROR; } block += DCTSIZE2; } // for m_hsampling } // for m_vsampling } // for m_jpeg_ncomp } else { // refine DC scan for(n = 0; n < m_jpeg_ncomp; n++) { for(k = 0; k < m_ccomp[n].m_vsampling; k++) { for(l = 0; l < m_ccomp[n].m_hsampling; l++) { status = ippiDecodeHuffman8x8_DCRefine_JPEG_1u16s_C1( src, srcLen, &m_src.currPos, block, (int*)&m_marker, m_al, m_state); if(ippStsNoErr > status) { LOG0("Error: ippiDecodeHuffman8x8_DCRefine_JPEG_1u16s_C1() failed!"); return JPEG_INTERNAL_ERROR; } block += DCTSIZE2; } // for m_hsampling } // for m_vsampling } // for m_jpeg_ncomp } m_restarts_to_go --; } // for m_numxMCU } // for m_numyMCU if(m_al == 0) { m_dc_scan_completed = 1; } } return JPEG_OK;} // CJPEGDecoder::DecodeScanProgressive()JERRCODE CJPEGDecoder::DecodeScanLossless(void){ JERRCODE jerr; IppStatus status;#ifdef __TIMING__ Ipp64u c0; Ipp64u c1;#endif status = ippiDecodeHuffmanStateInit_JPEG_8u(m_state); if(ippStsNoErr != status) { return JPEG_INTERNAL_ERROR; } m_marker = JM_NONE; int i; int idThread = 0; Ipp16s* pMCUBuf; pMCUBuf = m_block_buffer; i = 0; while(i < m_numyMCU) { { if(i < m_numyMCU) {#ifdef __TIMING__ c0 = ippGetCpuClocks();#endif jerr = DecodeHuffmanMCURowLS(pMCUBuf); if(JPEG_OK != jerr) { return jerr; }#ifdef __TIMING__ c1 = ippGetCpuClocks(); m_clk_huff += c1 - c0;#endif } i++; // advance counter to the next mcu row } if((i-1) < m_numyMCU) {#ifdef __TIMING__ c0 = ippGetCpuClocks();#endif jerr = ReconstructMCURowLS(pMCUBuf, i-1, idThread); if(JPEG_OK != jerr) { return jerr; }#ifdef __TIMING__ c1 = ippGetCpuClocks(); m_clk_diff += c1 - c0;#endif } } // for m_numyMCU return JPEG_OK;} // CJPEGDecoder::DecodeScanLossless()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -