📄 scan.c
字号:
/* 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) ) CHLocalsPtr2 -= ppi->ChLocalsCircularBufferSize; CHLocalsPtr2 -= 1; /* The defining rule used here is as follows. */ /* An edge pixels has 3-5 changed locals. */ /* And one or more of these changed locals has itself got 7-8 changed locals. */ if ( RowType == NOT_EDGE_ROW ){ /* Loop for all pixels in the row. */ for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){ /* Does the fragment contain anything interesting to work with. */ if ( *DispFragPtr == CANDIDATE_BLOCK ){ /* Reset the cumulative fragment score. */ FragScore = 0; /* Pixels grouped along the row into fragments */ for ( j = 0; j < HFRAGPIXELS; j++ ){ /* How many changed locals has the current pixel got. */ changed_locals = ChangedLocalsPtr[j]; /* Is the pixel a suitable candidate */ if ( (changed_locals > 2) && (changed_locals < 6) ){ /* The pixel may qualify... have a closer look. */ BodyNeighbours = 0; /* Count the number of "BodyNeighbours" .. Pixels that have 7 or more changed neighbours. */ if ( (i > 0) || (j > 0 ) ){ if ( CHLocalsPtr0[0] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr1[0] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr2[0] >= 7 ) BodyNeighbours++; } if ( CHLocalsPtr0[1] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr2[1] >= 7 ) BodyNeighbours++; if ( (i + j) < LastRowIndex ){ if ( CHLocalsPtr0[2] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr1[2] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr2[2] >= 7 ) BodyNeighbours++; } if ( BodyNeighbours > 0 ){ AbsDiff = abs( YUVDiffsPtr[j] ); Score = (ogg_int32_t) ( (double)(BodyNeighbours * BodyNeighbourScore) * ppi->AbsDiff_ScoreMultiplierTable[AbsDiff] ); if ( Score < 1 ) Score = 1; /* Increment the score by a value determined by the number of body neighbours. */ PixelNoiseScorePtr[j] += (unsigned char)Score; FragScore += (ogg_uint32_t)Score; } } /* Increment pointers into changed locals buffer */ CHLocalsPtr0 ++; CHLocalsPtr1 ++; CHLocalsPtr2 ++; } /* 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; } }else{ /* Nothing to do for this fragment group */ /* Advance pointers into changed locals buffer */ CHLocalsPtr0 += HFRAGPIXELS; CHLocalsPtr1 += HFRAGPIXELS; CHLocalsPtr2 += HFRAGPIXELS; } /* Increment the various pointers */ FragScorePtr++; DispFragPtr++; PixelNoiseScorePtr += HFRAGPIXELS; ChangedLocalsPtr += HFRAGPIXELS; YUVDiffsPtr += HFRAGPIXELS; } }else{ /* This is either the top or bottom row of pixels in a plane. */ /* Loop for all pixels in the row. */ for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){ /* Does the fragment contain anything interesting to work with. */ if ( *DispFragPtr == CANDIDATE_BLOCK ){ /* Reset the cumulative fragment score. */ FragScore = 0; /* Pixels grouped along the row into fragments */ for ( j = 0; j < HFRAGPIXELS; j++ ){ /* How many changed locals has the current pixel got. */ changed_locals = ChangedLocalsPtr[j]; /* Is the pixel a suitable candidate */ if ( (changed_locals > 2) && (changed_locals < 6) ){ /* The pixel may qualify... have a closer look. */ BodyNeighbours = 0; /* Count the number of "BodyNeighbours" .. Pixels that have 7 or more changed neighbours. */ if ( RowType == LAST_ROW ){ /* Test for cases where it could be the first pixel on the line */ if ( (i > 0) || (j > 0) ){ if ( CHLocalsPtr0[0] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr1[0] >= 7 ) BodyNeighbours++; } if ( CHLocalsPtr0[1] >= 7 ) BodyNeighbours++; /* Test for the end of line case */ if ( (i + j) < LastRowIndex ){ if ( CHLocalsPtr0[2] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr1[2] >= 7 ) BodyNeighbours++; } }else{ /* First Row */ /* Test for cases where it could be the first pixel on the line */ if ( (i > 0) || (j > 0) ){ if ( CHLocalsPtr1[0] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr2[0] >= 7 ) BodyNeighbours++; } /* Test for the end of line case */ if ( CHLocalsPtr2[1] >= 7 ) BodyNeighbours++; if ( (i + j) < LastRowIndex ){ if ( CHLocalsPtr1[2] >= 7 ) BodyNeighbours++; if ( CHLocalsPtr2[2] >= 7 ) BodyNeighbours++; } } /* Allocate a score according to the number of Body neighbours. */ if ( BodyNeighbours > 0 ){ AbsDiff = abs( YUVDiffsPtr[j] ); Score = (ogg_int32_t) ( (double)(BodyNeighbours * BodyNeighbourScore) * ppi->AbsDiff_ScoreMultiplierTable[AbsDiff] ); if ( Score < 1 ) Score = 1; PixelNoiseScorePtr[j] += (unsigned char)Score; FragScore += (ogg_uint32_t)Score; } } /* Increment pointers into changed locals buffer */ CHLocalsPtr0 ++; CHLocalsPtr1 ++; CHLocalsPtr2 ++; } /* 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; } }else{ /* Nothing to do for this fragment group */ /* Advance pointers into changed locals buffer */ CHLocalsPtr0 += HFRAGPIXELS; CHLocalsPtr1 += HFRAGPIXELS; CHLocalsPtr2 += HFRAGPIXELS; } /* Increment the various pointers */ FragScorePtr++; DispFragPtr++; PixelNoiseScorePtr += HFRAGPIXELS; ChangedLocalsPtr += HFRAGPIXELS; YUVDiffsPtr += HFRAGPIXELS; } }}static void PixelLineSearch( PP_INSTANCE *ppi, unsigned char * ChangedLocalsPtr, ogg_int32_t RowNumber, ogg_int32_t ColNumber, unsigned char direction, ogg_uint32_t * line_length ){ /* Exit if the pixel does not qualify or we have fallen off the edge of either the image plane or the row. */ if ( (RowNumber < 0) || (RowNumber >= ppi->PlaneHeight) || (ColNumber < 0) || (ColNumber >= ppi->PlaneWidth) || ((*ChangedLocalsPtr) <= 1) || ((*ChangedLocalsPtr) >= 6) ){ /* If not then it isn't part of any line. */ return; } if (*line_length < ppi->MaxLineSearchLen){ ogg_uint32_t TmpLineLength; ogg_uint32_t BestLineLength; unsigned char * search_ptr; /* Increment the line length to include this pixel. */ *line_length += 1; BestLineLength = *line_length; /* Continue search */ /* up */ if ( direction == UP ){ TmpLineLength = *line_length; search_ptr = ChangedLocalsPtr - ppi->PlaneWidth; if ( search_ptr < ppi->ChLocals ) search_ptr += ppi->ChLocalsCircularBufferSize; PixelLineSearch( ppi, search_ptr, RowNumber - 1, ColNumber, direction, &TmpLineLength ); if ( TmpLineLength > BestLineLength ) BestLineLength = TmpLineLength; } /* up and left */ if ( (BestLineLength < ppi->MaxLineSearchLen) && ((direction == UP) || (direction == LEFT)) ){ TmpLineLength = *line_length; search_ptr = ChangedLocalsPtr - ppi->PlaneWidth; if ( search_ptr < ppi->ChLocals ) search_ptr += ppi->ChLocalsCircularBufferSize; search_ptr -= 1; PixelLineSearch( ppi, search_ptr, RowNumber - 1, ColNumber - 1, direction, &TmpLineLength ); if ( TmpLineLength > BestLineLength ) BestLineLength = TmpLineLength; } /* up and right */ if ( (BestLineLength < ppi->MaxLineSearchLen) && ((direction == UP) || (direction == RIGHT)) ){ TmpLineLength = *line_length; search_ptr = ChangedLocalsPtr - ppi->PlaneWidth; if ( search_ptr < ppi->ChLocals ) search_ptr += ppi->ChLocalsCircularBufferSize; search_ptr += 1; PixelLineSearch( ppi, search_ptr, RowNumber - 1, ColNumber + 1, direction, &TmpLineLength ); if ( TmpLineLength > BestLineLength ) BestLineLength = TmpLineLength; } /* left */ if ( (BestLineLength < ppi->MaxLineSearchLen) && ( direction == LEFT ) ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -