MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / hb_detect_comb

Function hb_detect_comb

libhb/hb.c:1087–1166  ·  view source on GitHub ↗

* Analyzes a frame to detect interlacing artifacts * and returns true if interlacing (combing) is found. * * Code taken from Thomas Oestreich's 32detect filter * in the Transcode project, with minor formatting changes. * * @param buf An hb_buffer structure holding valid frame data * @param width The frame's width in pixels * @param height The frame's height in pixels *

Source from the content-addressed store, hash-verified

1085 * @param prog_threshold Sensitivity for flagging progressive frames as combed
1086 */
1087int hb_detect_comb( hb_buffer_t * buf, int color_equal, int color_diff, int threshold, int prog_equal, int prog_diff, int prog_threshold )
1088{
1089 int j, k, n, off, cc_1, cc_2, cc[3] = {0};
1090 // int flag[3] ; // debugging flag
1091 uint16_t s1, s2, s3, s4;
1092 cc_1 = 0; cc_2 = 0;
1093
1094 if ( buf->s.flags & 16 )
1095 {
1096 /* Frame is progressive, be more discerning. */
1097 color_diff = prog_diff;
1098 color_equal = prog_equal;
1099 threshold = prog_threshold;
1100 }
1101
1102 /* One pas for Y, one pass for Cb, one pass for Cr */
1103 for( k = 0; k <= buf->f.max_plane; k++ )
1104 {
1105 uint8_t * data = buf->plane[k].data;
1106 int width = buf->plane[k].width;
1107 int stride = buf->plane[k].stride;
1108 int height = buf->plane[k].height;
1109
1110 for( j = 0; j < width; ++j )
1111 {
1112 off = 0;
1113
1114 for( n = 0; n < ( height - 4 ); n = n + 2 )
1115 {
1116 /* Look at groups of 4 sequential horizontal lines */
1117 s1 = ( ( data )[ off + j ] & 0xff );
1118 s2 = ( ( data )[ off + j + stride ] & 0xff );
1119 s3 = ( ( data )[ off + j + 2 * stride ] & 0xff );
1120 s4 = ( ( data )[ off + j + 3 * stride ] & 0xff );
1121
1122 /* Note if the 1st and 2nd lines are more different in
1123 color than the 1st and 3rd lines are similar in color.*/
1124 if ( ( abs( s1 - s3 ) < color_equal ) &&
1125 ( abs( s1 - s2 ) > color_diff ) )
1126 ++cc_1;
1127
1128 /* Note if the 2nd and 3rd lines are more different in
1129 color than the 2nd and 4th lines are similar in color.*/
1130 if ( ( abs( s2 - s4 ) < color_equal ) &&
1131 ( abs( s2 - s3 ) > color_diff) )
1132 ++cc_2;
1133
1134 /* Now move down 2 horizontal lines before starting over.*/
1135 off += 2 * stride;
1136 }
1137 }
1138
1139 // compare results
1140 /* The final cc score for a plane is the percentage of combed pixels it contains.
1141 Because sensitivity goes down to hundredths of a percent, multiply by 1000
1142 so it will be easy to compare against the threshold value which is an integer. */
1143 cc[k] = (int)( ( cc_1 + cc_2 ) * 1000.0 / ( width * height ) );
1144 }

Callers 1

DecodePreviewsFunction · 0.85

Calls 1

hb_logFunction · 0.85

Tested by

no test coverage detected