⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scan.c

📁 从FFMPEG转换而来的H264解码程序,VC下编译..
💻 C
📖 第 1 页 / 共 5 页
字号:
    FDiffPixels ++;

    /* If we have a lot of changed pixels for this fragment on this
       row then the fragment is almost sure to be picked
       (e.g. through the line search) so we can mark it as selected
       and then ignore it. */
    if (FragChangedPixels >= 7){
      *DispFragPtr = BLOCK_CODED_LOW;
    }
    DispFragPtr++;
    /*************************************************************/
    /* Fragment in between!! */

    for ( i = HFRAGPIXELS ; i < ppi->PlaneWidth-HFRAGPIXELS;
	  i += HFRAGPIXELS ){
      /* Reset count of pixels changed for the current fragment. */
      FragChangedPixels = 0;

      /* Test for break out conditions to save time. */
      if (*DispFragPtr == CANDIDATE_BLOCK){
	/* Clear down entries in changed locals array */
        SET8_0(ChLocalsPtr);
	for ( j = 0; j < HFRAGPIXELS; j++ ){
	  /* Take a local copy of the measured difference. */
	  Diff = (int)YuvPtr1[j] - (int)YuvPtr2[j];

	  /* Store the actual difference value */
	  YUVDiffsPtr[j] = Diff;

	  /* Test against the Level thresholds and record the results */
	  SgcPtr[0] += ppi->SgcThreshTable[Diff+255];

	  if (ppi->SrfPakThreshTable[Diff+255] )
	    Diff = (int)ApplyPakLowPass( ppi, &YuvPtr1[j] ) -
	      (int)ApplyPakLowPass( ppi, &YuvPtr2[j] );


	  /* Test against the SRF thresholds */
	  bits_map_ptr[j] = ppi->SrfThreshTable[Diff+255];
	  FragChangedPixels += ppi->SrfThreshTable[Diff+255];
	}
      }else{
	/* If we are breaking out here mark all pixels as changed. */
	if ( *DispFragPtr > BLOCK_NOT_CODED ){
          SET8_1(bits_map_ptr);
          SET8_8(ChLocalsPtr);
	}else{
          SET8_0(ChLocalsPtr);
	}
      }

      *RowDiffsPtr += FragChangedPixels;
      *FDiffPixels += (unsigned char)FragChangedPixels;

      YuvPtr1 += HFRAGPIXELS;
      YuvPtr2 += HFRAGPIXELS;
      bits_map_ptr += HFRAGPIXELS;
      ChLocalsPtr += HFRAGPIXELS;
      YUVDiffsPtr += HFRAGPIXELS;
      SgcPtr ++;
      FDiffPixels ++;

      /* If we have a lot of changed pixels for this fragment on this
	 row then the fragment is almost sure to be picked
	 (e.g. through the line search) so we can mark it as selected
	 and then ignore it. */
      if (FragChangedPixels >= 7){
	*DispFragPtr = BLOCK_CODED_LOW;
      }
      DispFragPtr++;
    }
    /*************************************************************/
    /* Last fragment of row !! */

    /* Reset count of pixels changed for the current fragment. */
    FragChangedPixels = 0;

    /* Test for break out conditions to save time. */
    if (*DispFragPtr == CANDIDATE_BLOCK){
      /* Clear down entries in changed locals array */
      SET8_0(ChLocalsPtr);

      for ( j = 0; j < HFRAGPIXELS; j++ ){
	/* Take a local copy of the measured difference. */
	Diff = (int)YuvPtr1[j] - (int)YuvPtr2[j];

	/* Store the actual difference value */
	YUVDiffsPtr[j] = Diff;

	/* Test against the Level thresholds and record the results */
	SgcPtr[0] += ppi->SgcThreshTable[Diff+255];

	if (j<7 && ppi->SrfPakThreshTable[Diff+255] )
	  Diff = (int)ApplyPakLowPass( ppi, &YuvPtr1[j] ) -
	    (int)ApplyPakLowPass( ppi, &YuvPtr2[j] );


	/* Test against the SRF thresholds */
	bits_map_ptr[j] = ppi->SrfThreshTable[Diff+255];
	FragChangedPixels += ppi->SrfThreshTable[Diff+255];
      }
    }else{
      /* If we are breaking out here mark all pixels as changed.*/
      if ( *DispFragPtr > BLOCK_NOT_CODED ) {
          SET8_1(bits_map_ptr);
          SET8_8(ChLocalsPtr);
	}else{
          SET8_0(ChLocalsPtr);
	}
    }
    /* If we have a lot of changed pixels for this fragment on this
       row then the fragment is almost sure to be picked (e.g. through
       the line search) so we can mark it as selected and then ignore
       it. */
    *RowDiffsPtr += FragChangedPixels;
    *FDiffPixels += (unsigned char)FragChangedPixels;

    /* If we have a lot of changed pixels for this fragment on this
       row then the fragment is almost sure to be picked (e.g. through
       the line search) so we can mark it as selected and then ignore
       it. */
    if (FragChangedPixels >= 7){
      *DispFragPtr = BLOCK_CODED_LOW;
    }
    DispFragPtr++;

  }
}

static void ConsolidateDiffScanResults( PP_INSTANCE *ppi,
					unsigned char * FDiffPixels,
					signed char * SgcScoresPtr,
					signed char * DispFragPtr ){
  ogg_int32_t i;

  for ( i = 0; i < ppi->PlaneHFragments; i ++ ){
    /* Consider only those blocks that were candidates in the
       difference scan. Ignore definite YES and NO cases. */
    if ( DispFragPtr[i] == CANDIDATE_BLOCK ){
      if ( ((ogg_uint32_t)abs(SgcScoresPtr[i]) > ppi->BlockSgcThresh) ){
	/* Block marked for update due to Sgc change */
	DispFragPtr[i] = BLOCK_CODED_SGC;
      }else if ( FDiffPixels[i] == 0 ){
	/* Block is no longer a candidate for the main tests but will
	   still be considered a candidate in RowBarEnhBlockMap() */
	DispFragPtr[i] = CANDIDATE_BLOCK_LOW;
      }
    }
  }
}

static void RowChangedLocalsScan( PP_INSTANCE *ppi,
				  unsigned char * PixelMapPtr,
				  unsigned char * ChLocalsPtr,
				  signed char  * DispFragPtr,
				  unsigned char   RowType ){

  unsigned char changed_locals = 0;
  unsigned char * PixelsChangedPtr0;
  unsigned char * PixelsChangedPtr1;
  unsigned char * PixelsChangedPtr2;
  ogg_int32_t i, j;
  ogg_int32_t LastRowIndex = ppi->PlaneWidth - 1;

  /* Set up the line based pointers into the bits changed map. */
  PixelsChangedPtr0 = PixelMapPtr - ppi->PlaneWidth;
  if ( PixelsChangedPtr0 < ppi->PixelChangedMap )
    PixelsChangedPtr0 += ppi->PixelMapCircularBufferSize;
  PixelsChangedPtr0 -= 1;

  PixelsChangedPtr1 = PixelMapPtr - 1;

  PixelsChangedPtr2 = PixelMapPtr + ppi->PlaneWidth;
  if ( PixelsChangedPtr2 >=
       (ppi->PixelChangedMap + ppi->PixelMapCircularBufferSize) )
    PixelsChangedPtr2 -= ppi->PixelMapCircularBufferSize;
  PixelsChangedPtr2 -= 1;

  if ( RowType == NOT_EDGE_ROW ){
    /* Scan through the row of pixels and calculate changed locals. */
    for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
      /* Skip a group of 8 pixels if the assosciated fragment has no
         pixels of interest. */
      if ( *DispFragPtr == CANDIDATE_BLOCK ){
	for ( j = 0; j < HFRAGPIXELS; j++ ){
	  changed_locals = 0;

	  /* If the pixel itself has changed */
	  if ( PixelsChangedPtr1[1] ){
	    if ( (i > 0) || (j > 0) ){
	      changed_locals += PixelsChangedPtr0[0];
	      changed_locals += PixelsChangedPtr1[0];
	      changed_locals += PixelsChangedPtr2[0];
	    }

	    changed_locals += PixelsChangedPtr0[1];
	    changed_locals += PixelsChangedPtr2[1];

	    if ( (i + j) < LastRowIndex ){
	      changed_locals += PixelsChangedPtr0[2];
	      changed_locals += PixelsChangedPtr1[2];
	      changed_locals += PixelsChangedPtr2[2];
	    }

	    /* Store the number of changed locals */
	    *ChLocalsPtr |= changed_locals;
	  }

	  /* Increment to next pixel in the row */
	  ChLocalsPtr++;
	  PixelsChangedPtr0++;
	  PixelsChangedPtr1++;
	  PixelsChangedPtr2++;
	}
      }else{
	if ( *DispFragPtr > BLOCK_NOT_CODED )
          SET8_0(ChLocalsPtr);

	/* Step pointers */
	ChLocalsPtr += HFRAGPIXELS;
	PixelsChangedPtr0 += HFRAGPIXELS;
	PixelsChangedPtr1 += HFRAGPIXELS;
	PixelsChangedPtr2 += HFRAGPIXELS;
      }

      /* Move on to next fragment. */
      DispFragPtr++;

    }
  }else{
    /* Scan through the row of pixels and calculate changed locals. */
    for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
      /* Skip a group of 8 pixels if the assosciated fragment has no
         pixels of interest */
      if ( *DispFragPtr == CANDIDATE_BLOCK ){
	for ( j = 0; j < HFRAGPIXELS; j++ ){
	  changed_locals = 0;

	  /* If the pixel itself has changed */
	  if ( PixelsChangedPtr1[1] ){
	    if ( RowType == FIRST_ROW ){
	      if ( (i > 0) || (j > 0) ){
		changed_locals += PixelsChangedPtr1[0];
		changed_locals += PixelsChangedPtr2[0];
	      }

	      changed_locals += PixelsChangedPtr2[1];

	      if ( (i + j) < LastRowIndex ){
		changed_locals += PixelsChangedPtr1[2];
		changed_locals += PixelsChangedPtr2[2];
	      }
	    }else{
	      if ( (i > 0) || (j > 0 ) ){
		changed_locals += PixelsChangedPtr0[0];
		changed_locals += PixelsChangedPtr1[0];
	      }

	      changed_locals += PixelsChangedPtr0[1];

	      if ( (i + j) < LastRowIndex ){
		changed_locals += PixelsChangedPtr0[2];
		changed_locals += PixelsChangedPtr1[2];
	      }
	    }

	    /* Store the number of changed locals */
	    *ChLocalsPtr |= changed_locals;
	  }

	  /* Increment to next pixel in the row */
	  ChLocalsPtr++;
	  PixelsChangedPtr0++;
	  PixelsChangedPtr1++;
	  PixelsChangedPtr2++;
	}
      }else{
	if ( *DispFragPtr > BLOCK_NOT_CODED )
          SET8_0(ChLocalsPtr);

	/* Step pointers */
	ChLocalsPtr += HFRAGPIXELS;
	PixelsChangedPtr0 += HFRAGPIXELS;
	PixelsChangedPtr1 += HFRAGPIXELS;
	PixelsChangedPtr2 += HFRAGPIXELS;
      }

      /* Move on to next fragment. */
      DispFragPtr++;
    }
  }
}

static void NoiseScoreRow( PP_INSTANCE *ppi,
			   unsigned char * PixelMapPtr,
			   unsigned char * ChLocalsPtr,
			   ogg_int16_t   * YUVDiffsPtr,
			   unsigned char * PixelNoiseScorePtr,
			   ogg_uint32_t  * FragScorePtr,
			   signed char   * DispFragPtr,
			   ogg_int32_t   * RowDiffsPtr ){
  ogg_int32_t i,j;
  unsigned char  changed_locals = 0;
  ogg_int32_t  Score;
  ogg_uint32_t FragScore;
  ogg_int32_t  AbsDiff;

  /* For each pixel in the row */
  for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
    /* Skip a group of 8 pixels if the assosciated fragment has no
       pixels of interest. */
    if ( *DispFragPtr == CANDIDATE_BLOCK ){
      /* Reset the cumulative fragment score. */
      FragScore = 0;

      /* Pixels grouped along the row into fragments */
      for ( j = 0; j < HFRAGPIXELS; j++ ){
	if ( PixelMapPtr[j] ){
	  AbsDiff = (ogg_int32_t)( abs(YUVDiffsPtr[j]) );
	  changed_locals = ChLocalsPtr[j];

	  /* Give this pixel a score based on changed locals and level
             of its own change. */
	  Score = (1 + ((ogg_int32_t)(changed_locals +
				      ppi->NoiseScoreBoostTable[AbsDiff]) -
			ppi->NoiseSupLevel));

	  /* For no zero scores adjust by a level based score multiplier. */
	  if ( Score > 0 ){
	    Score = ((double)Score *
		     ppi->AbsDiff_ScoreMultiplierTable[AbsDiff] );
	    if ( Score < 1 )
	      Score = 1;
	  }else{
	    /* Set -ve values to 0 */
	    Score = 0;

	    /* If there are no changed locals then clear the pixel
	       changed flag and decrement the pixels changed in
	       fragment count to speed later stages. */
	    if ( changed_locals == 0 ){
	      PixelMapPtr[j] = 0;
	      *RowDiffsPtr -= 1;
	    }
	  }

	  /* Update the pixel scores etc. */
	  PixelNoiseScorePtr[j] = (unsigned char)Score;
	  FragScore += (ogg_uint32_t)Score;
	}
      }

      /* Add fragment score (with plane correction factor) into main
         data structure */
      *FragScorePtr += (ogg_int32_t)(FragScore *
				     ppi->YUVPlaneCorrectionFactor);

      /* If score is greater than trip threshold then mark blcok for update. */
      if ( *FragScorePtr > ppi->BlockThreshold ){
	*DispFragPtr = BLOCK_CODED_LOW;
      }
    }

    /* Increment the various pointers */
    FragScorePtr++;
    DispFragPtr++;
    PixelNoiseScorePtr += HFRAGPIXELS;
    PixelMapPtr += HFRAGPIXELS;
    ChLocalsPtr += HFRAGPIXELS;
    YUVDiffsPtr += HFRAGPIXELS;
  }
}

static void PrimaryEdgeScoreRow( PP_INSTANCE *ppi,
				 unsigned char * ChangedLocalsPtr,
				 ogg_int16_t   * YUVDiffsPtr,
				 unsigned char * PixelNoiseScorePtr,
				 ogg_uint32_t  * FragScorePtr,
				 signed char   * DispFragPtr,
				 unsigned char   RowType ){
  ogg_uint32_t     BodyNeighbours;
  ogg_uint32_t     AbsDiff;
  unsigned char    changed_locals = 0;
  ogg_int32_t      Score;
  ogg_uint32_t     FragScore;
  unsigned char  * CHLocalsPtr0;
  unsigned char  * CHLocalsPtr1;
  unsigned char  * CHLocalsPtr2;
  ogg_int32_t      i,j;
  ogg_int32_t      LastRowIndex = ppi->PlaneWidth - 1;

  /* Set up pointers into the current previous and next row of the
     changed locals data structure. */
  CHLocalsPtr0 = ChangedLocalsPtr - ppi->PlaneWidth;
  if ( CHLocalsPtr0 < ppi->ChLocals )
    CHLocalsPtr0 += ppi->ChLocalsCircularBufferSize;
  CHLocalsPtr0 -= 1;

  CHLocalsPtr1 = ChangedLocalsPtr - 1;

  CHLocalsPtr2 = ChangedLocalsPtr + ppi->PlaneWidth;
  if ( CHLocalsPtr2 >= (ppi->ChLocals + ppi->ChLocalsCircularBufferSize) )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -