void CSampleView::DrawBack(CDC* pDC)
{
   POINT     points[6];
   int width  = GetWidth();
   int height = GetHeight();
   CRect     rect;

   GetClientRect(&rect);
   if (rect.right <= width && rect.bottom <= height) return;
   if (rect.right <= width) {
       width = rect.right;
       rect.top = IPP_MIN(height,rect.bottom);
   }
   if (rect.bottom <= height) {
       height = rect.bottom;
       rect.left = width;
   }
   points[0].x = width;       points[0].y = height;
   points[1].x = width;       points[1].y = rect.top;
   points[2].x = rect.right;  points[2].y = rect.top;
   points[3].x = rect.right;  points[3].y = rect.bottom;
   points[4].x = rect.left;   points[4].y = rect.bottom;
   points[5].x = rect.left;   points[5].y = height;

   CPen pen(PS_NULL, 0, RGB(0,0,0));
   CBrush brush(m_pSignalDC->GetColorAxisBack());
   pDC->SelectObject(&pen);
   pDC->SelectObject(&brush);
   pDC->Polygon(points,6);
}
示例#2
0
int FileSaveDialog::imageComment(char* comment, int len)
{
  int         comment_size;
  QByteArray  arr;

  if(len <= 0)
    return 0;

  arr = m_imageCommentEdit.text().toAscii();

  comment_size = IPP_MIN(len,m_imageCommentEdit.text().length());

  ippsCopy_8u((Ipp8u*)arr.data(), (Ipp8u*)comment, comment_size);

  return comment_size;
} // FileSaveDialog::imageComment()
示例#3
0
static inline int ippiSuggestThreadsNum(size_t width, size_t height, size_t elemSize, double multiplier)
{
    int threads = cv::getNumThreads();
    if(threads > 1 && height >= 64)
    {
        size_t opMemory = (int)(width*height*elemSize*multiplier);
        int l2cache = 0;
#if IPP_VERSION_X100 >= 201700
        ippGetL2CacheSize(&l2cache);
#endif
        if(!l2cache)
            l2cache = 1 << 18;

        return IPP_MAX(1, (IPP_MIN((int)(opMemory/l2cache), threads)));
    }
    return 1;
}
示例#4
0
Status CMemBuffInput::Read(void* buf,TSize len,TSize& cnt)
{
  TSize rb;

  rb = (TSize)IPP_MIN(len, (TSize)(m_buflen - m_currpos));

  ippsCopy_8u(m_buf + m_currpos,(Ipp8u*)buf,(int)rb);

  m_currpos += (int)rb;

  cnt = rb;

  if(len != rb)
    return StatusFail;

  return StatusOk;
} // CMemBuffInput::Read()
static Ipp32s
sbrencCalcCompensation(Ipp32f bufT[][64],
                       Ipp32f bufDiff[][64],
                       Ipp32s* pFreqTab,
                       Ipp32s nBand,
                       Ipp32s* bs_add_harmonic,
                       Ipp32s* bufComp,
                       Ipp32s totNoEst)

{
  Ipp32f maxVal;
  Ipp32f curThres;

  Ipp32s band, j, i, iStart, iEnd;
  Ipp32s maxPosF,maxPosT;
  Ipp32s compValue;


  ippsZero_32s(bufComp, nBand);

  for(band=0 ; band < nBand; band++){

    if(0 == bs_add_harmonic[band]) continue;

    /* miss sine has been detected */

    iStart = pFreqTab[band];
    iEnd = pFreqTab[band+1];

    maxPosF = 0;
    maxPosT = 0;
    maxVal  = 0;

    for(j=0;j<totNoEst;j++){

      for(i=iStart; i<iEnd; i++){

        if(bufT[j][i] > maxVal) {

          maxVal = bufT[j][i];
          maxPosF = i;
          maxPosT = j;
        }
      }
    }

    if(maxPosF == iStart && band){

      compValue = (Ipp32s) (fabs(ILOG2*log(bufDiff[maxPosT][band - 1]+EPS)) + 0.5f);

      compValue = IPP_MIN( compValue, MAX_COMP );

      if((!bs_add_harmonic[band-1]) && (maxPosF >= 1) ) {

        if(bufT[maxPosT][maxPosF -1] > TONALITY_QUOTA*bufT[maxPosT][maxPosF]){

          bufComp[band-1] = -1*compValue;
        }
      }
    }

    /* STEP2 [+1] */
    if(maxPosF == iEnd-1 && band+1 < nBand){

      compValue = (Ipp32s) (fabs(ILOG2*log(bufDiff[maxPosT][band + 1]+EPS)) + 0.5f);

      compValue = IPP_MIN( compValue, MAX_COMP );

      if(!bs_add_harmonic[band+1]) {

        if(bufT[maxPosT][maxPosF+1] > TONALITY_QUOTA*bufT[maxPosT][maxPosF]){

          bufComp[band+1] = compValue;
        }
      }
    }

    /* intermediate band: (0, nBand)  */
    if(band && band < nBand - 1){

      /* [-1] */
      compValue = (Ipp32s) (fabs(ILOG2*log(bufDiff[maxPosT][band -1]+EPS)) + 0.5f);

      compValue = IPP_MIN( compValue, MAX_COMP );

      curThres = bufDiff[maxPosT][band]*bufDiff[maxPosT][band-1];
      curThres *= DIFF_QUOTA;

      if(1.0f > curThres){
        bufComp[band-1] = -1*compValue;
      }

      /* [+1] */
      compValue = (Ipp32s) (fabs(ILOG2*log(bufDiff[maxPosT][band + 1]+EPS)) + 0.5f);

      compValue = IPP_MIN( compValue, MAX_COMP );

      curThres = bufDiff[maxPosT][band]*bufDiff[maxPosT][band+1];
      curThres *= DIFF_QUOTA;

      if(1.0f > curThres ){
        bufComp[band+1] = compValue;
      }
    }
  }

  return 0; //OK
}
static Ipp32s
sbrencDetectionSinEst(Ipp32f* bufT,
                      Ipp32f* bufDiff,
                      Ipp32s* detVec,
                      Ipp32s* pFreqTab,
                      Ipp32s  nBand,
                      Ipp32f* bufSfmOrig,
                      Ipp32f* bufSfmSBR,

                      sSBRGuideData guideState,
                      sSBRGuideData guideNewState)
{
  Ipp32f tmpThres = 0.f, origThres = 0.f;
  Ipp32s criterion1 = 0, criterion2 = 0, criterion3 = 0;
  Ipp32s iStart = 0, iEnd = 0;

  Ipp32s band = 0;
  Ipp32s i = 0;

  /* ******************************
   * detection algorithm: step 1
   * ****************************** */
  for(band = 0; band < nBand; band++){
    if (guideState.bufGuideDiff[band]) {

      tmpThres = IPP_MAX(DECAY_GUIDE_DIFF*guideState.bufGuideDiff[band],THR_DIFF_GUIDE);
    } else {

      tmpThres = THR_DIFF;
    }

    tmpThres = IPP_MIN(tmpThres, THR_DIFF);

    if(bufDiff[band] > tmpThres){

      detVec[band] = 1;
      guideNewState.bufGuideDiff[band] = bufDiff[band];
    } else {

      if(guideState.bufGuideDiff[band]){

        guideState.bufGuideOrig[band] = THR_TONE_GUIDE;
      }
    }
  }

  /* ******************************
  * detection algorithm: step 2
  * ****************************** */
  for(band = 0; band < nBand; band++){

    iStart = pFreqTab[band];
    iEnd = pFreqTab[band+1];

    origThres   = IPP_MAX(guideState.bufGuideOrig[band] * DECAY_GUIDE_ORIG, THR_TONE_GUIDE );

    origThres   = IPP_MIN(origThres, THR_TONE);

    if(guideState.bufGuideOrig[band]){

      for(i = iStart; i < iEnd; i++){

        if(bufT[i] > origThres){

          detVec[band] = 1;
          guideNewState.bufGuideOrig[band] = bufT[i];
        }
      }
    }
  }

  /* ******************************
   * detection algorithm: step 3
   * ****************************** */
  origThres   = THR_TONE;

  for(band = 0; band < nBand; band++){

    iStart = pFreqTab[band];
    iEnd = pFreqTab[band+1];

    if(iEnd -iStart > 1){

      for(i = iStart; i < iEnd; i++){

        /* get criterion */
        criterion1 = (bufT[i]       > origThres)      ? 1 : 0;
        criterion2 = (bufSfmSBR[band]  > THR_SFM_SBR ) ? 1 : 0;
        criterion3 = (bufSfmOrig[band] < THR_SFM_ORIG) ? 1 : 0;

        if(criterion1 && criterion2 && criterion3){

          detVec[band] = 1;
          guideNewState.bufGuideOrig[band] = bufT[i];
        }
      }
    } else {

      if(band < nBand -1){

        //iStart = pFreqTab[band];

        criterion1 = (bufT[iStart]     > THR_TONE )     ? 1 : 0;

        if(band){

          criterion2 = (bufDiff[+1]  < INV_THR_TONE ) ? 1 : 0;
          criterion3 = (bufDiff[band-1] < INV_THR_TONE ) ? 1 : 0;

          if(criterion1 && ( criterion2 || criterion3) ){

              detVec[band] = 1;
              guideNewState.bufGuideOrig[band] = bufT[iStart];
          }
        } else {

          criterion2 = (bufDiff[band+1] < INV_THR_TONE) ? 1 : 0;

          if(criterion1 && criterion2){

              detVec[band] = 1;
              guideNewState.bufGuideOrig[band] = bufT[iStart];
          }
        }
      }
    }
  }

  return 0;//OK

}
示例#7
0
JERRCODE CJPEGDecoder::DecodeScanBaselineIN_RSTI(void)
{
  int rcount = 0;
  IppStatus status;
  JERRCODE  jerr;
#ifdef __TIMING__
  Ipp64u   c0;
  Ipp64u   c1;
#endif

#ifdef _OPENMP
  int j;
  for(j = 0; j < m_num_threads; j++)
    status = ippiDecodeHuffmanStateInit_JPEG_8u(m_state_t[j]);
#endif
  status = ippiDecodeHuffmanStateInit_JPEG_8u(m_state);

  if(ippStsNoErr != status)
  {
    return JPEG_ERR_INTERNAL;
  }

  m_marker = JM_NONE;

  // workaround for 8-bit qnt tables in 12-bit scans
  if(m_qntbl[0].m_initialized && m_qntbl[0].m_precision == 0 && m_jpeg_precision == 12)
    m_qntbl[0].ConvertToHighPrecision();

  if(m_qntbl[1].m_initialized && m_qntbl[1].m_precision == 0 && m_jpeg_precision == 12)
    m_qntbl[1].ConvertToHighPrecision();

  if(m_qntbl[2].m_initialized && m_qntbl[2].m_precision == 0 && m_jpeg_precision == 12)
    m_qntbl[2].ConvertToHighPrecision();

  if(m_qntbl[3].m_initialized && m_qntbl[3].m_precision == 0 && m_jpeg_precision == 12)
    m_qntbl[3].ConvertToHighPrecision();

  // workaround for 16-bit qnt tables in 8-bit scans
  if(m_qntbl[0].m_initialized && m_qntbl[0].m_precision == 1 && m_jpeg_precision == 8)
    m_qntbl[0].ConvertToLowPrecision();

  if(m_qntbl[1].m_initialized && m_qntbl[1].m_precision == 1 && m_jpeg_precision == 8)
    m_qntbl[1].ConvertToLowPrecision();

  if(m_qntbl[2].m_initialized && m_qntbl[2].m_precision == 1 && m_jpeg_precision == 8)
    m_qntbl[2].ConvertToLowPrecision();

  if(m_qntbl[3].m_initialized && m_qntbl[3].m_precision == 1 && m_jpeg_precision == 8)
    m_qntbl[3].ConvertToLowPrecision();

  if(m_dctbl[0].IsEmpty())
  {
    jerr = m_dctbl[0].Create();
    if(JPEG_OK != jerr)
      return jerr;

    jerr = m_dctbl[0].Init(0,0,(Ipp8u*)&DefaultLuminanceDCBits[0],(Ipp8u*)&DefaultLuminanceDCValues[0]);
    if(JPEG_OK != jerr)
      return jerr;
  }

  if(m_dctbl[1].IsEmpty())
  {
    jerr = m_dctbl[1].Create();
    if(JPEG_OK != jerr)
      return jerr;

    jerr = m_dctbl[1].Init(1,0,(Ipp8u*)&DefaultChrominanceDCBits[0],(Ipp8u*)&DefaultChrominanceDCValues[0]);
    if(JPEG_OK != jerr)
      return jerr;
  }

  if(m_actbl[0].IsEmpty())
  {
    jerr = m_actbl[0].Create();
    if(JPEG_OK != jerr)
      return jerr;

    jerr = m_actbl[0].Init(0,1,(Ipp8u*)&DefaultLuminanceACBits[0],(Ipp8u*)&DefaultLuminanceACValues[0]);
    if(JPEG_OK != jerr)
      return jerr;
  }

  if(m_actbl[1].IsEmpty())
  {
    jerr = m_actbl[1].Create();
    if(JPEG_OK != jerr)
      return jerr;

    jerr = m_actbl[1].Init(1,1,(Ipp8u*)&DefaultChrominanceACBits[0],(Ipp8u*)&DefaultChrominanceACValues[0]);
    if(JPEG_OK != jerr)
      return jerr;
  }

  m_rsti_offset[0] = m_BitStreamIn.GetStreamPos();

#ifdef _OPENMP
#pragma omp parallel shared(rcount) if(m_jpeg_sampling != JS_411)
#endif
  {
    int     i          = 0;
    int     rh         = 1;
    int     r          = 0;
    int     currMCURow = 0;
    int     idThread   = 0;
    Ipp16s* pMCUBuf    = 0;  // 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;

    while(i < m_num_rsti)
    {
#ifdef _OPENMP
#pragma omp critical
      {
#endif

        i = rcount;
        rcount++;

        if(i < m_num_rsti)
        {
          ParseNextRSTI(idThread,i+1);
        }

#ifdef _OPENMP
      }
#endif

      if(i < m_num_rsti)
      {
#ifdef _OPENMP

        currMCURow = m_rsti_height*i;

        m_BitStreamInT[idThread].SetDataLen(m_rsti_offset[i+1] - m_rsti_offset[i]);
        m_BitStreamInT[idThread].SetCurrPos(0);
#endif
        rh = IPP_MIN(m_rsti_height, m_numyMCU - currMCURow);

        for(r = 0; r < rh; r++)
        {
          ippsZero_16s(pMCUBuf,m_numxMCU * m_nblock * DCTSIZE2);

          jerr = DecodeHuffmanMCURowBL_RSTI(pMCUBuf, idThread);
          if(JPEG_OK != jerr)
            continue;

          jerr = ReconstructMCURowBL8x8(pMCUBuf, idThread);
          if(JPEG_OK != jerr)
            continue;

          jerr = UpSampling(currMCURow + r,idThread);
          if(JPEG_OK != jerr)
            continue;

          jerr = ColorConvert(currMCURow + r,idThread);
          if(JPEG_OK != jerr)
            continue;
        }

        if(m_jpeg_restart_interval)
        {
          jerr = ProcessRestart(idThread);
          if(JPEG_OK != jerr)
          {
            LOG0("Error: ProcessRestart() failed!");
          }
        }
      } // if
#ifndef _OPENMP
        i++;
#endif
    } // for m_numyMCU
  } // OMP

#ifdef _OPENMP
  /*for(j = 0; j < m_num_rsti; j++)
  {
    omp_destroy_lock(&locks[j]);
  }

  ippFree(locks);
  locks = 0;*/
#endif

  return JPEG_OK;
} // CJPEGDecoder::DecodeScanBaselineIN_RSTI()
IppStatus ownPredictCoef_SBR_R_32f_D2L(Ipp32f **pSrc, Ipp32f *pAlpha0,
                                       Ipp32f *pAlpha1, Ipp32f *pReflectCoef,
                                       Ipp32s k0, Ipp32s len) {
  Ipp32f  fi[3][3];
  const Ipp32s TIME_HF_ADJ = 2;
  Ipp32s  i, j, k, n;
  const Ipp32f rel = 1.f / (1.f + 1e-6f);
  Ipp32f  d;
  Ipp32f** ppX = pSrc + TIME_HF_ADJ;

  for (k = 0; k < k0; k++) {
    fi[0][0] = fi[0][1] = fi[0][2] = fi[1][0] = fi[1][1] = fi[1][2] = fi[2][0] =
      fi[2][1] = fi[2][2] = 0.f;
/*
 * auto correlation
 */
    for (n = 0; n < len; n++) {
      i = 0;
      j = 1;
      fi[0][1] += ppX[n - i][k] * ppX[n - j][k];

      i = 0;
      j = 2;
      fi[0][2] += ppX[n - i][k] * ppX[n - j][k];

      i = 1;
      j = 1;
      fi[1][1] += ppX[n - i][k] * ppX[n - j][k];

      i = 1;
      j = 2;
      fi[1][2] += ppX[n - i][k] * ppX[n - j][k];

      i = 2;
      j = 2;
      fi[2][2] += ppX[n - i][k] * ppX[n - j][k];
    }

    d = fi[1][1] * fi[2][2] - rel * fi[1][2] * fi[1][2];
/*
 * pAlpha1
 */
    if ((Ipp64f)d * d > 0.f) {  /* if (d != 0) */
      pAlpha1[k] = (fi[0][1] * fi[1][2] - fi[0][2] * fi[1][1]) * (1.f / d);
    } else {
      pAlpha1[k] = 0.f;
    }
/*
 * pAlpha0
 */
    if (fi[1][1] > 0.f) {       /* if (fi[1][1] != 0) */
      pAlpha0[k] = -(fi[0][1] + pAlpha1[k] * fi[1][2]) * (1.f / fi[1][1]);
    } else {
      pAlpha0[k] = 0.f;
    }

    if (((pAlpha1[k] * pAlpha1[k]) >= 16.f) ||
        ((pAlpha0[k] * pAlpha0[k]) >= 16.f)) {
      pAlpha1[k] = pAlpha0[k] = 0.f;
    }

    if (fi[1][1] == 0.0f) {
      pReflectCoef[k] = 0.0f;
    } else {
      pReflectCoef[k] = IPP_MIN(IPP_MAX(-fi[0][1] / fi[1][1], -1), 1);
    }
  }

  return ippStsNoErr;
}
bool H264Slice::Reset(void *pSource, size_t nSourceSize, Ipp32s iConsumerNumber)
{
    Ipp32s iMBInFrame;
    Ipp32s iFieldIndex;

    m_BitStream.Reset((Ipp8u *) pSource, (Ipp32u) nSourceSize);

    // decode slice header
    if (nSourceSize && false == DecodeSliceHeader())
        return false;

    m_iMBWidth  = GetSeqParam()->frame_width_in_mbs;
    m_iMBHeight = GetSeqParam()->frame_height_in_mbs;

    iMBInFrame = (m_iMBWidth * m_iMBHeight) / ((m_SliceHeader.field_pic_flag) ? (2) : (1));
    iFieldIndex = (m_SliceHeader.field_pic_flag && m_SliceHeader.bottom_field_flag) ? (1) : (0);

    // set slice variables
    m_iFirstMB = m_SliceHeader.first_mb_in_slice;
    m_iMaxMB = iMBInFrame;

    m_iFirstMBFld = m_SliceHeader.first_mb_in_slice + iMBInFrame * iFieldIndex;

    m_iAvailableMB = iMBInFrame;

    if (m_iFirstMB >= m_iAvailableMB)
        return false;

    // reset all internal variables
    m_iCurMBToDec = m_iFirstMB;
    m_iCurMBToRec = m_iFirstMB;
    m_iCurMBToDeb = m_iFirstMB;

    m_bInProcess = false;
    m_bDecVacant = 1;
    m_bRecVacant = 1;
    m_bDebVacant = 1;
    m_bFirstDebThreadedCall = true;
    m_bError = false;

    m_MVsDistortion = 0;

    // reallocate internal buffer
    if (false == IsSliceGroups() && iConsumerNumber > 1)
    {
        Ipp32s iMBRowSize = GetMBRowWidth();
        Ipp32s iMBRowBuffers;
        Ipp32s bit_depth_luma, bit_depth_chroma;
        if (m_SliceHeader.is_auxiliary)
        {
            bit_depth_luma = GetSeqParamEx()->bit_depth_aux;
            bit_depth_chroma = 8;
        } else {
            bit_depth_luma = GetSeqParam()->bit_depth_luma;
            bit_depth_chroma = GetSeqParam()->bit_depth_chroma;
        }

        Ipp32s isU16Mode = (bit_depth_luma > 8 || bit_depth_chroma > 8) ? 2 : 1;

        // decide number of buffers
        iMBRowBuffers = IPP_MAX(MINIMUM_NUMBER_OF_ROWS, MB_BUFFER_SIZE / iMBRowSize);
        iMBRowBuffers = IPP_MIN(MAXIMUM_NUMBER_OF_ROWS, iMBRowBuffers);

        m_CoeffsBuffers.Init(iMBRowBuffers, (Ipp32s)sizeof(Ipp16s) * isU16Mode * (iMBRowSize * COEFFICIENTS_BUFFER_SIZE + DEFAULT_ALIGN_VALUE));
    }

    m_CoeffsBuffers.Reset();

    // reset through-decoding variables
    m_nMBSkipCount = 0;
    m_nQuantPrev = m_pPicParamSet->pic_init_qp +
                   m_SliceHeader.slice_qp_delta;
    m_prev_dquant = 0;
    m_field_index = iFieldIndex;

    if (IsSliceGroups())
        m_bNeedToCheckMBSliceEdges = true;
    else
        m_bNeedToCheckMBSliceEdges = (0 == m_SliceHeader.first_mb_in_slice) ? (false) : (true);

    // set conditional flags
    m_bDecoded = false;
    m_bPrevDeblocked = false;
    m_bDeblocked = (m_SliceHeader.disable_deblocking_filter_idc == DEBLOCK_FILTER_OFF);

    if (m_bDeblocked)
    {
        m_bDebVacant = 0;
        m_iCurMBToDeb = m_iMaxMB;
    }

    // frame is not associated yet
    m_pCurrentFrame = NULL;

    return true;

} // bool H264Slice::Reset(void *pSource, size_t nSourceSize, Ipp32s iNumber)