📄 scan.c
字号:
TmpLineLength = *line_length; PixelLineSearch( ppi, ChangedLocalsPtr - 1, RowNumber, ColNumber - 1, direction, &TmpLineLength ); if ( TmpLineLength > BestLineLength ) BestLineLength = TmpLineLength; } /* right */ if ( (BestLineLength < ppi->MaxLineSearchLen) && ( direction == RIGHT ) ){ TmpLineLength = *line_length; PixelLineSearch( ppi, ChangedLocalsPtr + 1, RowNumber, ColNumber + 1, direction, &TmpLineLength ); if ( TmpLineLength > BestLineLength ) BestLineLength = TmpLineLength; } /* Down */ if ( BestLineLength < ppi->MaxLineSearchLen ){ TmpLineLength = *line_length; if ( direction == DOWN ){ search_ptr = ChangedLocalsPtr + ppi->PlaneWidth; if ( search_ptr >= (ppi->ChLocals + ppi->ChLocalsCircularBufferSize) ) search_ptr -= ppi->ChLocalsCircularBufferSize; PixelLineSearch( ppi, search_ptr, RowNumber + 1, ColNumber, direction, &TmpLineLength ); if ( TmpLineLength > BestLineLength ) BestLineLength = TmpLineLength; } /* down and left */ if ( (BestLineLength < ppi->MaxLineSearchLen) && ((direction == DOWN) || (direction == LEFT)) ){ TmpLineLength = *line_length; search_ptr = ChangedLocalsPtr + ppi->PlaneWidth; if ( search_ptr >= (ppi->ChLocals + ppi->ChLocalsCircularBufferSize) ) search_ptr -= ppi->ChLocalsCircularBufferSize; search_ptr -= 1; PixelLineSearch( ppi, search_ptr, RowNumber + 1, ColNumber - 1, direction, &TmpLineLength ); if ( TmpLineLength > BestLineLength ) BestLineLength = TmpLineLength; } /* down and right */ if ( (BestLineLength < ppi->MaxLineSearchLen) && ((direction == DOWN) || (direction == RIGHT)) ){ TmpLineLength = *line_length; search_ptr = ChangedLocalsPtr + ppi->PlaneWidth; if ( search_ptr >= (ppi->ChLocals + ppi->ChLocalsCircularBufferSize) ) search_ptr -= ppi->ChLocalsCircularBufferSize; search_ptr += 1; PixelLineSearch( ppi, search_ptr, RowNumber + 1, ColNumber + 1, direction, &TmpLineLength ); if ( TmpLineLength > BestLineLength ) BestLineLength = TmpLineLength; } } /* Note the search value for this pixel. */ *line_length = BestLineLength; }}static unsigned char LineSearchScorePixel( PP_INSTANCE *ppi, unsigned char * ChangedLocalsPtr, ogg_int32_t RowNumber, ogg_int32_t ColNumber ){ ogg_uint32_t line_length = 0; ogg_uint32_t line_length2 = 0; ogg_uint32_t line_length_score = 0; ogg_uint32_t tmp_line_length = 0; ogg_uint32_t tmp_line_length2 = 0; /* Look UP and Down */ PixelLineSearch( ppi, ChangedLocalsPtr, RowNumber, ColNumber, UP, &tmp_line_length ); if (tmp_line_length < ppi->MaxLineSearchLen) { /* Look DOWN */ PixelLineSearch( ppi, ChangedLocalsPtr, RowNumber, ColNumber, DOWN, &tmp_line_length2 ); line_length = tmp_line_length + tmp_line_length2 - 1; if ( line_length > ppi->MaxLineSearchLen ) line_length = ppi->MaxLineSearchLen; }else line_length = tmp_line_length; /* If no max length line found then look left and right */ if ( line_length < ppi->MaxLineSearchLen ){ tmp_line_length = 0; tmp_line_length2 = 0; PixelLineSearch( ppi, ChangedLocalsPtr, RowNumber, ColNumber, LEFT, &tmp_line_length ); if (tmp_line_length < ppi->MaxLineSearchLen){ PixelLineSearch( ppi, ChangedLocalsPtr, RowNumber, ColNumber, RIGHT, &tmp_line_length2 ); line_length2 = tmp_line_length + tmp_line_length2 - 1; if ( line_length2 > ppi->MaxLineSearchLen ) line_length2 = ppi->MaxLineSearchLen; }else line_length2 = tmp_line_length; } /* Take the largest line length */ if ( line_length2 > line_length ) line_length = line_length2; /* Create line length score */ line_length_score = LineLengthScores[line_length]; return (unsigned char)line_length_score;}static void LineSearchScoreRow( PP_INSTANCE *ppi, unsigned char * ChangedLocalsPtr, ogg_int16_t * YUVDiffsPtr, unsigned char * PixelNoiseScorePtr, ogg_uint32_t * FragScorePtr, signed char * DispFragPtr, ogg_int32_t RowNumber ){ ogg_uint32_t AbsDiff; unsigned char changed_locals = 0; ogg_int32_t Score; ogg_uint32_t FragScore; ogg_int32_t i,j; /* The defining rule used here is as follows. */ /* An edge pixels has 2-5 changed locals. */ /* And one or more of these changed locals has itself got 7-8 changed locals. */ /* 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 for edge enhancement */ if ( (changed_locals > 1) && (changed_locals < 6) && (PixelNoiseScorePtr[j] < ppi->LineSearchTripTresh) ) { Score = (ogg_int32_t) LineSearchScorePixel( ppi, &ChangedLocalsPtr[j], RowNumber, i+j ); if ( Score ){ AbsDiff = abs( YUVDiffsPtr[j] ); Score = (ogg_int32_t) ( (double)Score * ppi->AbsDiff_ScoreMultiplierTable[AbsDiff] ); if ( Score < 1 ) Score = 1; 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; ChangedLocalsPtr += HFRAGPIXELS; YUVDiffsPtr += HFRAGPIXELS; }}static void RowCopy( PP_INSTANCE *ppi, ogg_uint32_t BlockMapIndex ){ ogg_uint32_t i,j; ogg_uint32_t PixelIndex = ppi->ScanPixelIndexTable[BlockMapIndex]; signed char * BlockMapPtr = &ppi->ScanDisplayFragments[BlockMapIndex]; signed char * PrevFragmentsPtr = &ppi->PrevFragments[0][BlockMapIndex]; unsigned char * SourcePtr; unsigned char * DestPtr; /* Copy pixels from changed blocks back to reference frame. */ for ( i = 0; i < (ogg_uint32_t)ppi->PlaneHFragments; i ++ ){ /* If the fragement is marked for update or was recently marked for update (PrevFragmentsPtr[i]) */ if ( (BlockMapPtr[i] > BLOCK_NOT_CODED) || (PrevFragmentsPtr[i] == BLOCK_CODED) ){ /* Set up the various pointers required. */ SourcePtr = &ppi->ScanConfig.Yuv1ptr[PixelIndex]; DestPtr = &ppi->ScanConfig.SrfWorkSpcPtr[PixelIndex]; /* For each row of the block */ for ( j = 0; j < VFRAGPIXELS; j++ ){ /* Copy the data unaltered from source to destination */ memcpy(DestPtr,SourcePtr,8); /* Increment pointers for next line in the block */ SourcePtr += ppi->PlaneWidth; DestPtr += ppi->PlaneWidth; } } /* Increment pixel index for next block. */ PixelIndex += HFRAGPIXELS; }}static void RowBarEnhBlockMap( PP_INSTANCE *ppi, signed char * UpdatedBlockMapPtr, signed char * BarBlockMapPtr, ogg_uint32_t RowNumber ){ int i; /* Start by blanking the row in the bar block map structure. */ memset( BarBlockMapPtr, BLOCK_NOT_CODED, ppi->PlaneHFragments ); /* First row */ if ( RowNumber == 0 ){ /* For each fragment in the row. */ for ( i = 0; i < ppi->PlaneHFragments; i ++ ){ /* Test for CANDIDATE_BLOCK or CANDIDATE_BLOCK_LOW. Uncoded or coded blocks will be ignored. */ if ( UpdatedBlockMapPtr[i] <= CANDIDATE_BLOCK ){ /* Is one of the immediate neighbours updated in the main map. */ /* Note special cases for blocks at the start and end of rows. */ if ( i == 0 ){ if ((UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments]>BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments+1]>BLOCK_NOT_CODED ) ) BarBlockMapPtr[i] = BLOCK_CODED_BAR; }else if ( i == (ppi->PlaneHFragments - 1) ){ if ((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments-1]>BLOCK_NOT_CODED) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments]>BLOCK_NOT_CODED) ) BarBlockMapPtr[i] = BLOCK_CODED_BAR; }else{ if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i+ppi->PlaneHFragments] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments+1] > BLOCK_NOT_CODED) ) BarBlockMapPtr[i] = BLOCK_CODED_BAR; } } } } else if ( RowNumber == (ogg_uint32_t)(ppi->PlaneVFragments-1)) { /* Last row */ /* Used to read PlaneHFragments */ /* For each fragment in the row. */ for ( i = 0; i < ppi->PlaneHFragments; i ++ ){ /* Test for CANDIDATE_BLOCK or CANDIDATE_BLOCK_LOW Uncoded or coded blocks will be ignored. */ if ( UpdatedBlockMapPtr[i] <= CANDIDATE_BLOCK ){ /* Is one of the immediate neighbours updated in the main map. */ /* Note special cases for blocks at the start and end of rows. */ if ( i == 0 ){ if((UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments+1] > BLOCK_NOT_CODED )) BarBlockMapPtr[i] = BLOCK_CODED_BAR; }else if ( i == (ppi->PlaneHFragments - 1) ){ if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ) BarBlockMapPtr[i] = BLOCK_CODED_BAR; }else{ if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments+1] > BLOCK_NOT_CODED) ) BarBlockMapPtr[i] = BLOCK_CODED_BAR; } } } }else{ /* All other rows */ /* For each fragment in the row. */ for ( i = 0; i < ppi->PlaneHFragments; i ++ ){ /* Test for CANDIDATE_BLOCK or CANDIDATE_BLOCK_LOW */ /* Uncoded or coded blocks will be ignored. */ if ( UpdatedBlockMapPtr[i] <= CANDIDATE_BLOCK ){ /* Is one of the immediate neighbours updated in the main map. */ /* Note special cases for blocks at the start and end of rows. */ if ( i == 0 ){ if((UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments+1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i+ppi->PlaneHFragments] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments+1] > BLOCK_NOT_CODED) ) BarBlockMapPtr[i] = BLOCK_CODED_BAR; }else if ( i == (ppi->PlaneHFragments - 1) ){ if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i+ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ) BarBlockMapPtr[i] = BLOCK_CODED_BAR; }else{ if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i-ppi->PlaneHFragments+1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i+ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)|| (UpdatedBlockMapPtr[i+ppi->PlaneHFragments] > BLOCK_NOT_CODED ) || (UpdatedBlockMapPtr[i+ppi->PlaneHFragments+1] > BLOCK_NOT_CODED )) BarBlockMapPtr[i] = BLOCK_CODED_BAR; } } } }}static void BarCopyBack( PP_INSTANCE *ppi, signed char * UpdatedBlockMapPtr, signed char * BarBlockMapPtr ){ ogg_int32_t i; /* For each fragment in the row. */ for ( i = 0; i < ppi->PlaneHFragments; i ++ ){ if ( BarBlockMapPtr[i] > BLOCK_NOT_CODED ){ UpdatedBlockMapPtr[i] = BarBlockMapPtr[i]; } }}static void AnalysePlane( PP_INSTANCE *ppi, unsigned char * PlanePtr0, unsigned char * PlanePtr1,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -