static int column_all_dark( hb_buffer_t* buf, int top, int bottom, int col ) { int stride = buf->plane[0].stride; int height = buf->plane[0].height - top - bottom; uint8_t *luma = buf->plane[0].data + stride * top + col; // compute the average value of the column int i = height, avg = 0, row = 0; for ( ; --i >= 0; row += stride ) { avg += clampBlack( luma[row] ); } avg /= height; if ( avg >= DARK ) return 0; // since we're trying to detect smooth borders, only take the column if // all pixels are within +-16 of the average. i = height, row = 0; for ( ; --i >= 0; row += stride ) { if ( absdiff( avg, clampBlack( luma[row] ) ) > 16 ) return 0; } return 1; }
static int column_all_dark( hb_title_t *title, uint8_t* luma, int top, int bottom, int col ) { int stride = title->width; int height = title->height - top - bottom; luma += stride * top + col; // compute the average value of the column int i = height, avg = 0, row = 0; for ( ; --i >= 0; row += stride ) { avg += clampBlack( luma[row] ); } avg /= height; if ( avg >= DARK ) return 0; // since we're trying to detect smooth borders, only take the column if // all pixels are within +-16 of the average. i = height, row = 0; for ( ; --i >= 0; row += stride ) { if ( absdiff( avg, clampBlack( luma[row] ) ) > 16 ) return 0; } return 1; }
static int row_all_dark( hb_buffer_t* buf, int row ) { int width = buf->plane[0].width; int stride = buf->plane[0].stride; uint8_t *luma = buf->plane[0].data + stride * row; // compute the average luma value of the row int i, avg = 0; for ( i = 0; i < width; ++i ) { avg += clampBlack( luma[i] ); } avg /= width; if ( avg >= DARK ) return 0; // since we're trying to detect smooth borders, only take the row if // all pixels are within +-16 of the average (this range is fairly coarse // but there's a lot of quantization noise for luma values near black // so anything less will fail to crop because of the noise). for ( i = 0; i < width; ++i ) { if ( absdiff( avg, clampBlack( luma[i] ) ) > 16 ) return 0; } return 1; }
static int row_all_dark( hb_title_t *title, uint8_t* luma, int row ) { luma += title->width * row; // compute the average luma value of the row int i, avg = 0; for ( i = 0; i < title->width; ++i ) { avg += clampBlack( luma[i] ); } avg /= title->width; if ( avg >= DARK ) return 0; // since we're trying to detect smooth borders, only take the row if // all pixels are within +-16 of the average (this range is fairly coarse // but there's a lot of quantization noise for luma values near black // so anything less will fail to crop because of the noise). for ( i = 0; i < title->width; ++i ) { if ( absdiff( avg, clampBlack( luma[i] ) ) > 16 ) return 0; } return 1; }