Commit 21a0c2c9 authored by clang-format's avatar clang-format Committed by James Zern

apply clang-format

after:
253c001f Port dering experiment from aom
72081457 Adding 8x16/16x8/32x16/16x32 transforms

Change-Id: Id93e0d7b72a128701d8dec35fc2fac473944d0c1
parent 0996fc6b
......@@ -34,8 +34,9 @@ using libvpx_test::ACMRandom;
TEST(Daala, TestDIVUuptoMAX) {
for (int d = 1; d <= OD_DIVU_DMAX; d++) {
for (uint32_t x = 1; x <= 1000000; x++) {
GTEST_ASSERT_EQ(x/d, OD_DIVU_SMALL(x, d)) << "x=" << x << " d=" << d <<
" x/d=" << (x/d) << " != " << OD_DIVU_SMALL(x, d);
GTEST_ASSERT_EQ(x / d, OD_DIVU_SMALL(x, d))
<< "x=" << x << " d=" << d << " x/d=" << (x / d)
<< " != " << OD_DIVU_SMALL(x, d);
}
}
}
......@@ -45,8 +46,9 @@ TEST(Daala, TestDIVUrandI31) {
for (int d = 1; d < OD_DIVU_DMAX; d++) {
for (int i = 0; i < 1000000; i++) {
uint32_t x = rnd.Rand31();
GTEST_ASSERT_EQ(x/d, OD_DIVU_SMALL(x, d)) << "x=" << x << " d=" << d <<
" x/d=" << (x/d) << " != " << OD_DIVU_SMALL(x, d);
GTEST_ASSERT_EQ(x / d, OD_DIVU_SMALL(x, d))
<< "x=" << x << " d=" << d << " x/d=" << (x / d)
<< " != " << OD_DIVU_SMALL(x, d);
}
}
}
......@@ -61,9 +61,9 @@ static const uint8_t num_16x16_blocks_high_lookup[BLOCK_SIZES] = {
};
static const uint8_t num_4x4_blocks_txsize_lookup[TX_SIZES_ALL] = {
1, 4, 16, 64,
1, 4, 16, 64,
#if CONFIG_EXT_TX
2, 2, 8, 8, 32, 32
2, 2, 8, 8, 32, 32
#endif // CONFIG_EXT_TX
};
static const uint8_t num_4x4_blocks_wide_txsize_lookup[TX_SIZES_ALL] = {
......@@ -380,7 +380,7 @@ static const BLOCK_SIZE txsize_to_bsize[TX_SIZES_ALL] = {
BLOCK_16X8, // TX_16X8
BLOCK_16X32, // TX_16X32
BLOCK_32X16, // TX_32X16
#endif // CONFIG_EXT_TX
#endif // CONFIG_EXT_TX
};
static const TX_SIZE txsize_sqr_map[TX_SIZES_ALL] = {
......@@ -395,7 +395,7 @@ static const TX_SIZE txsize_sqr_map[TX_SIZES_ALL] = {
TX_8X8, // TX_16X8
TX_16X16, // TX_16X32
TX_16X16, // TX_32X16
#endif // CONFIG_EXT_TX
#endif // CONFIG_EXT_TX
};
static const TX_SIZE txsize_sqr_up_map[TX_SIZES_ALL] = {
......@@ -410,7 +410,7 @@ static const TX_SIZE txsize_sqr_up_map[TX_SIZES_ALL] = {
TX_16X16, // TX_16X8
TX_32X32, // TX_16X32
TX_32X32, // TX_32X16
#endif // CONFIG_EXT_TX
#endif // CONFIG_EXT_TX
};
static const TX_SIZE tx_mode_to_biggest_tx_size[TX_MODES] = {
......
......@@ -18,13 +18,12 @@
#include "vp10/common/reconinter.h"
#include "vp10/common/od_dering.h"
int compute_level_from_index(int global_level, int gi) {
static const int dering_gains[DERING_REFINEMENT_LEVELS] = {0, 11, 16, 22};
static const int dering_gains[DERING_REFINEMENT_LEVELS] = { 0, 11, 16, 22 };
int level;
if (global_level == 0) return 0;
level = (global_level*dering_gains[gi] + 8) >> 4;
return clamp(level, gi, MAX_DERING_LEVEL-1);
level = (global_level * dering_gains[gi] + 8) >> 4;
return clamp(level, gi, MAX_DERING_LEVEL - 1);
}
int sb_all_skip(const VP10_COMMON *const cm, int mi_row, int mi_col) {
......@@ -38,8 +37,8 @@ int sb_all_skip(const VP10_COMMON *const cm, int mi_row, int mi_col) {
for (r = 0; r < maxr; r++) {
for (c = 0; c < maxc; c++) {
skip = skip &&
cm->mi_grid_visible[(mi_row + r)*cm->mi_stride + mi_col + c]->
mbmi.skip;
cm->mi_grid_visible[(mi_row + r) * cm->mi_stride + mi_col + c]
->mbmi.skip;
}
}
return skip;
......@@ -52,30 +51,29 @@ void vp10_dering_frame(YV12_BUFFER_CONFIG *frame, VP10_COMMON *cm,
int nhsb, nvsb;
od_dering_in *src[3];
unsigned char *bskip;
int dir[OD_DERING_NBLOCKS][OD_DERING_NBLOCKS] = {{0}};
int dir[OD_DERING_NBLOCKS][OD_DERING_NBLOCKS] = { { 0 } };
int stride;
int bsize[3];
int dec[3];
int pli;
int coeff_shift = VPXMAX(cm->bit_depth - 8, 0);
nvsb = (cm->mi_rows + MI_BLOCK_SIZE - 1)/MI_BLOCK_SIZE;
nhsb = (cm->mi_cols + MI_BLOCK_SIZE - 1)/MI_BLOCK_SIZE;
bskip = vpx_malloc(sizeof(*bskip)*cm->mi_rows*cm->mi_cols);
nvsb = (cm->mi_rows + MI_BLOCK_SIZE - 1) / MI_BLOCK_SIZE;
nhsb = (cm->mi_cols + MI_BLOCK_SIZE - 1) / MI_BLOCK_SIZE;
bskip = vpx_malloc(sizeof(*bskip) * cm->mi_rows * cm->mi_cols);
vp10_setup_dst_planes(xd->plane, frame, 0, 0);
for (pli = 0; pli < 3; pli++) {
dec[pli] = xd->plane[pli].subsampling_x;
bsize[pli] = 8 >> dec[pli];
}
stride = bsize[0]*cm->mi_cols;
stride = bsize[0] * cm->mi_cols;
for (pli = 0; pli < 3; pli++) {
src[pli] = vpx_malloc(sizeof(*src)*cm->mi_rows*cm->mi_cols*64);
for (r = 0; r < bsize[pli]*cm->mi_rows; ++r) {
for (c = 0; c < bsize[pli]*cm->mi_cols; ++c) {
src[pli] = vpx_malloc(sizeof(*src) * cm->mi_rows * cm->mi_cols * 64);
for (r = 0; r < bsize[pli] * cm->mi_rows; ++r) {
for (c = 0; c < bsize[pli] * cm->mi_cols; ++c) {
#if CONFIG_VPX_HIGHBITDEPTH
if (cm->use_highbitdepth) {
src[pli][r * stride + c] =
CONVERT_TO_SHORTPTR(xd->plane[pli].dst.buf)
[r * xd->plane[pli].dst.stride + c];
src[pli][r * stride + c] = CONVERT_TO_SHORTPTR(
xd->plane[pli].dst.buf)[r * xd->plane[pli].dst.stride + c];
} else {
#endif
src[pli][r * stride + c] =
......@@ -97,46 +95,48 @@ void vp10_dering_frame(YV12_BUFFER_CONFIG *frame, VP10_COMMON *cm,
for (sbc = 0; sbc < nhsb; sbc++) {
int level;
int nhb, nvb;
nhb = VPXMIN(MI_BLOCK_SIZE, cm->mi_cols - MI_BLOCK_SIZE*sbc);
nvb = VPXMIN(MI_BLOCK_SIZE, cm->mi_rows - MI_BLOCK_SIZE*sbr);
nhb = VPXMIN(MI_BLOCK_SIZE, cm->mi_cols - MI_BLOCK_SIZE * sbc);
nvb = VPXMIN(MI_BLOCK_SIZE, cm->mi_rows - MI_BLOCK_SIZE * sbr);
for (pli = 0; pli < 3; pli++) {
int16_t dst[MI_BLOCK_SIZE*MI_BLOCK_SIZE*8*8];
int16_t dst[MI_BLOCK_SIZE * MI_BLOCK_SIZE * 8 * 8];
int threshold;
#if DERING_REFINEMENT
level = compute_level_from_index(
global_level,
cm->mi_grid_visible[MI_BLOCK_SIZE*sbr*cm->mi_stride +
MI_BLOCK_SIZE*sbc]->mbmi.dering_gain);
cm->mi_grid_visible[MI_BLOCK_SIZE * sbr * cm->mi_stride +
MI_BLOCK_SIZE * sbc]
->mbmi.dering_gain);
#else
level = global_level;
level = global_level;
#endif
/* FIXME: This is a temporary hack that uses more conservative
deringing for chroma. */
if (pli) level = (level*5 + 4) >> 3;
if (sb_all_skip(cm, sbr*MI_BLOCK_SIZE, sbc*MI_BLOCK_SIZE)) level = 0;
if (pli) level = (level * 5 + 4) >> 3;
if (sb_all_skip(cm, sbr * MI_BLOCK_SIZE, sbc * MI_BLOCK_SIZE))
level = 0;
threshold = level << coeff_shift;
od_dering(
&OD_DERING_VTBL_C,
dst,
MI_BLOCK_SIZE*bsize[pli],
&src[pli][sbr*stride*bsize[pli]*MI_BLOCK_SIZE +
sbc*bsize[pli]*MI_BLOCK_SIZE],
&OD_DERING_VTBL_C, dst, MI_BLOCK_SIZE * bsize[pli],
&src[pli][sbr * stride * bsize[pli] * MI_BLOCK_SIZE +
sbc * bsize[pli] * MI_BLOCK_SIZE],
stride, nhb, nvb, sbc, sbr, nhsb, nvsb, dec[pli], dir, pli,
&bskip[MI_BLOCK_SIZE*sbr*cm->mi_cols + MI_BLOCK_SIZE*sbc],
&bskip[MI_BLOCK_SIZE * sbr * cm->mi_cols + MI_BLOCK_SIZE * sbc],
cm->mi_cols, threshold, OD_DERING_NO_CHECK_OVERLAP, coeff_shift);
for (r = 0; r < bsize[pli]*nvb; ++r) {
for (c = 0; c < bsize[pli]*nhb; ++c) {
for (r = 0; r < bsize[pli] * nvb; ++r) {
for (c = 0; c < bsize[pli] * nhb; ++c) {
#if CONFIG_VPX_HIGHBITDEPTH
if (cm->use_highbitdepth) {
CONVERT_TO_SHORTPTR(xd->plane[pli].dst.buf)
[xd->plane[pli].dst.stride*(bsize[pli]*MI_BLOCK_SIZE*sbr + r)
+ sbc*bsize[pli]*MI_BLOCK_SIZE + c] =
[xd->plane[pli].dst.stride *
(bsize[pli] * MI_BLOCK_SIZE * sbr + r) +
sbc * bsize[pli] * MI_BLOCK_SIZE + c] =
dst[r * MI_BLOCK_SIZE * bsize[pli] + c];
} else {
#endif
xd->plane[pli].dst.buf[xd->plane[pli].dst.stride*
(bsize[pli]*MI_BLOCK_SIZE*sbr + r) +
sbc*bsize[pli]*MI_BLOCK_SIZE + c] =
xd->plane[pli]
.dst.buf[xd->plane[pli].dst.stride *
(bsize[pli] * MI_BLOCK_SIZE * sbr + r) +
sbc * bsize[pli] * MI_BLOCK_SIZE + c] =
dst[r * MI_BLOCK_SIZE * bsize[pli] + c];
#if CONFIG_VPX_HIGHBITDEPTH
}
......
......@@ -24,8 +24,7 @@ void vp10_dering_frame(YV12_BUFFER_CONFIG *frame, VP10_COMMON *cm,
MACROBLOCKD *xd, int global_level);
int vp10_dering_search(YV12_BUFFER_CONFIG *frame, const YV12_BUFFER_CONFIG *ref,
VP10_COMMON *cm,
MACROBLOCKD *xd);
VP10_COMMON *cm, MACROBLOCKD *xd);
#ifdef __cplusplus
} // extern "C"
......
......@@ -59,12 +59,9 @@ const uint16_t band_count_table[TX_SIZES_ALL][8] = {
{ 1, 2, 3, 4, 3, 16 - 13, 0 }, { 1, 2, 3, 4, 11, 64 - 21, 0 },
{ 1, 2, 3, 4, 11, 256 - 21, 0 }, { 1, 2, 3, 4, 11, 1024 - 21, 0 },
#if CONFIG_EXT_TX
{ 1, 2, 3, 4, 8, 32 - 18, 0 },
{ 1, 2, 3, 4, 8, 32 - 18, 0 },
{ 1, 2, 3, 4, 11, 128 - 21, 0 },
{ 1, 2, 3, 4, 11, 128 - 21, 0 },
{ 1, 2, 3, 4, 11, 512 - 21, 0 },
{ 1, 2, 3, 4, 11, 512 - 21, 0 },
{ 1, 2, 3, 4, 8, 32 - 18, 0 }, { 1, 2, 3, 4, 8, 32 - 18, 0 },
{ 1, 2, 3, 4, 11, 128 - 21, 0 }, { 1, 2, 3, 4, 11, 128 - 21, 0 },
{ 1, 2, 3, 4, 11, 512 - 21, 0 }, { 1, 2, 3, 4, 11, 512 - 21, 0 },
#endif // CONFIG_EXT_TX
};
......@@ -72,12 +69,9 @@ const uint16_t band_cum_count_table[TX_SIZES_ALL][8] = {
{ 0, 1, 3, 6, 10, 13, 16, 0 }, { 0, 1, 3, 6, 10, 21, 64, 0 },
{ 0, 1, 3, 6, 10, 21, 256, 0 }, { 0, 1, 3, 6, 10, 21, 1024, 0 },
#if CONFIG_EXT_TX
{ 0, 1, 3, 6, 10, 18, 32, 0 },
{ 0, 1, 3, 6, 10, 18, 32, 0 },
{ 0, 1, 3, 6, 10, 21, 128, 0 },
{ 0, 1, 3, 6, 10, 21, 128, 0 },
{ 0, 1, 3, 6, 10, 21, 512, 0 },
{ 0, 1, 3, 6, 10, 21, 512, 0 },
{ 0, 1, 3, 6, 10, 18, 32, 0 }, { 0, 1, 3, 6, 10, 18, 32, 0 },
{ 0, 1, 3, 6, 10, 21, 128, 0 }, { 0, 1, 3, 6, 10, 21, 128, 0 },
{ 0, 1, 3, 6, 10, 21, 512, 0 }, { 0, 1, 3, 6, 10, 21, 512, 0 },
#endif // CONFIG_EXT_TX
};
......
......@@ -168,8 +168,7 @@ static INLINE const uint8_t *get_band_translate(TX_SIZE tx_size) {
switch (tx_size) {
case TX_4X4: return vp10_coefband_trans_4x4;
#if CONFIG_EXT_TX
case TX_4X8:
return vp10_coefband_trans_4x8_8x4;
case TX_4X8: return vp10_coefband_trans_4x8_8x4;
#endif // CONFIG_EXT_TX
default: return vp10_coefband_trans_8x8plus;
}
......@@ -230,19 +229,19 @@ static INLINE int get_entropy_context(TX_SIZE tx_size, const ENTROPY_CONTEXT *a,
break;
case TX_8X16:
above_ec = !!*(const uint16_t *)a;
left_ec = !!*(const uint32_t *)l;
left_ec = !!*(const uint32_t *)l;
break;
case TX_16X8:
above_ec = !!*(const uint32_t *)a;
left_ec = !!*(const uint16_t *)l;
left_ec = !!*(const uint16_t *)l;
break;
case TX_16X32:
above_ec = !!*(const uint32_t *)a;
left_ec = !!*(const uint64_t *)l;
left_ec = !!*(const uint64_t *)l;
break;
case TX_32X16:
above_ec = !!*(const uint64_t *)a;
left_ec = !!*(const uint32_t *)l;
left_ec = !!*(const uint32_t *)l;
break;
#endif // CONFIG_EXT_TX
case TX_8X8:
......
......@@ -138,12 +138,12 @@ typedef uint8_t TX_SIZE;
#define TX_SIZES ((TX_SIZE)4)
#if CONFIG_EXT_TX
#define TX_4X8 ((TX_SIZE)4) // 4x8 transform
#define TX_8X4 ((TX_SIZE)5) // 8x4 transform
#define TX_8X16 ((TX_SIZE)6) // 8x16 transform
#define TX_16X8 ((TX_SIZE)7) // 16x8 transform
#define TX_16X32 ((TX_SIZE)8) // 16x32 transform
#define TX_32X16 ((TX_SIZE)9) // 32x16 transform
#define TX_4X8 ((TX_SIZE)4) // 4x8 transform
#define TX_8X4 ((TX_SIZE)5) // 8x4 transform
#define TX_8X16 ((TX_SIZE)6) // 8x16 transform
#define TX_16X8 ((TX_SIZE)7) // 16x8 transform
#define TX_16X32 ((TX_SIZE)8) // 16x32 transform
#define TX_32X16 ((TX_SIZE)9) // 32x16 transform
#define TX_SIZES_ALL ((TX_SIZE)10) // Includes rectangular transforms
#else
#define TX_SIZES_ALL ((TX_SIZE)4)
......
This diff is collapsed.
......@@ -23,7 +23,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <stdlib.h>
......@@ -31,25 +31,26 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
#include "dering.h"
const od_dering_opt_vtbl OD_DERING_VTBL_C = {
{od_filter_dering_direction_4x4_c, od_filter_dering_direction_8x8_c},
{od_filter_dering_orthogonal_4x4_c, od_filter_dering_orthogonal_8x8_c}
{ od_filter_dering_direction_4x4_c, od_filter_dering_direction_8x8_c },
{ od_filter_dering_orthogonal_4x4_c, od_filter_dering_orthogonal_8x8_c }
};
/* Generated from gen_filter_tables.c. */
const int OD_DIRECTION_OFFSETS_TABLE[8][3] = {
{-1*OD_FILT_BSTRIDE + 1, -2*OD_FILT_BSTRIDE + 2, -3*OD_FILT_BSTRIDE + 3 },
{ 0*OD_FILT_BSTRIDE + 1, -1*OD_FILT_BSTRIDE + 2, -1*OD_FILT_BSTRIDE + 3 },
{ 0*OD_FILT_BSTRIDE + 1, 0*OD_FILT_BSTRIDE + 2, 0*OD_FILT_BSTRIDE + 3 },
{ 0*OD_FILT_BSTRIDE + 1, 1*OD_FILT_BSTRIDE + 2, 1*OD_FILT_BSTRIDE + 3 },
{ 1*OD_FILT_BSTRIDE + 1, 2*OD_FILT_BSTRIDE + 2, 3*OD_FILT_BSTRIDE + 3 },
{ 1*OD_FILT_BSTRIDE + 0, 2*OD_FILT_BSTRIDE + 1, 3*OD_FILT_BSTRIDE + 1 },
{ 1*OD_FILT_BSTRIDE + 0, 2*OD_FILT_BSTRIDE + 0, 3*OD_FILT_BSTRIDE + 0 },
{ 1*OD_FILT_BSTRIDE + 0, 2*OD_FILT_BSTRIDE - 1, 3*OD_FILT_BSTRIDE - 1 },
{ -1 * OD_FILT_BSTRIDE + 1, -2 * OD_FILT_BSTRIDE + 2,
-3 * OD_FILT_BSTRIDE + 3 },
{ 0 * OD_FILT_BSTRIDE + 1, -1 * OD_FILT_BSTRIDE + 2,
-1 * OD_FILT_BSTRIDE + 3 },
{ 0 * OD_FILT_BSTRIDE + 1, 0 * OD_FILT_BSTRIDE + 2, 0 * OD_FILT_BSTRIDE + 3 },
{ 0 * OD_FILT_BSTRIDE + 1, 1 * OD_FILT_BSTRIDE + 2, 1 * OD_FILT_BSTRIDE + 3 },
{ 1 * OD_FILT_BSTRIDE + 1, 2 * OD_FILT_BSTRIDE + 2, 3 * OD_FILT_BSTRIDE + 3 },
{ 1 * OD_FILT_BSTRIDE + 0, 2 * OD_FILT_BSTRIDE + 1, 3 * OD_FILT_BSTRIDE + 1 },
{ 1 * OD_FILT_BSTRIDE + 0, 2 * OD_FILT_BSTRIDE + 0, 3 * OD_FILT_BSTRIDE + 0 },
{ 1 * OD_FILT_BSTRIDE + 0, 2 * OD_FILT_BSTRIDE - 1, 3 * OD_FILT_BSTRIDE - 1 },
};
const double OD_DERING_GAIN_TABLE[OD_DERING_LEVELS] = {
0, 0.5, 0.707, 1, 1.41, 2
};
const double OD_DERING_GAIN_TABLE[OD_DERING_LEVELS] = { 0, 0.5, 0.707,
1, 1.41, 2 };
/* Detect direction. 0 means 45-degree up-right, 2 is horizontal, and so on.
The search minimizes the weighted variance along all the lines in a
......@@ -59,56 +60,59 @@ const double OD_DERING_GAIN_TABLE[OD_DERING_LEVELS] = {
that term is never computed. See Section 2, step 2, of:
http://jmvalin.ca/notes/intra_paint.pdf */
static int od_dir_find8(const od_dering_in *img, int stride, int32_t *var,
int coeff_shift) {
int coeff_shift) {
int i;
int32_t cost[8] = {0};
int partial[8][15] = {{0}};
int32_t cost[8] = { 0 };
int partial[8][15] = { { 0 } };
int32_t best_cost = 0;
int best_dir = 0;
/* Instead of dividing by n between 2 and 8, we multiply by 3*5*7*8/n.
The output is then 840 times larger, but we don't care for finding
the max. */
static const int div_table[] = {0, 840, 420, 280, 210, 168, 140, 120, 105};
static const int div_table[] = { 0, 840, 420, 280, 210, 168, 140, 120, 105 };
for (i = 0; i < 8; i++) {
int j;
for (j = 0; j < 8; j++) {
int x;
/* We subtract 128 here to reduce the maximum range of the squared
partial sums. */
x = (img[i*stride + j] >> coeff_shift) - 128;
x = (img[i * stride + j] >> coeff_shift) - 128;
partial[0][i + j] += x;
partial[1][i + j/2] += x;
partial[1][i + j / 2] += x;
partial[2][i] += x;
partial[3][3 + i - j/2] += x;
partial[3][3 + i - j / 2] += x;
partial[4][7 + i - j] += x;
partial[5][3 - i/2 + j] += x;
partial[5][3 - i / 2 + j] += x;
partial[6][j] += x;
partial[7][i/2 + j] += x;
partial[7][i / 2 + j] += x;
}
}
for (i = 0; i < 8; i++) {
cost[2] += partial[2][i]*partial[2][i];
cost[6] += partial[6][i]*partial[6][i];
cost[2] += partial[2][i] * partial[2][i];
cost[6] += partial[6][i] * partial[6][i];
}
cost[2] *= div_table[8];
cost[6] *= div_table[8];
for (i = 0; i < 7; i++) {
cost[0] += (partial[0][i]*partial[0][i]
+ partial[0][14 - i]*partial[0][14 - i])*div_table[i + 1];
cost[4] += (partial[4][i]*partial[4][i]
+ partial[4][14 - i]*partial[4][14 - i])*div_table[i + 1];
cost[0] += (partial[0][i] * partial[0][i] +
partial[0][14 - i] * partial[0][14 - i]) *
div_table[i + 1];
cost[4] += (partial[4][i] * partial[4][i] +
partial[4][14 - i] * partial[4][14 - i]) *
div_table[i + 1];
}
cost[0] += partial[0][7]*partial[0][7]*div_table[8];
cost[4] += partial[4][7]*partial[4][7]*div_table[8];
cost[0] += partial[0][7] * partial[0][7] * div_table[8];
cost[4] += partial[4][7] * partial[4][7] * div_table[8];
for (i = 1; i < 8; i += 2) {
int j;
for (j = 0; j < 4 + 1; j++) {
cost[i] += partial[i][3 + j]*partial[i][3 + j];
cost[i] += partial[i][3 + j] * partial[i][3 + j];
}
cost[i] *= div_table[8];
for (j = 0; j < 4 - 1; j++) {
cost[i] += (partial[i][j]*partial[i][j]
+ partial[i][10 - j]*partial[i][10 - j])*div_table[2*j + 2];
cost[i] += (partial[i][j] * partial[i][j] +
partial[i][10 - j] * partial[i][10 - j]) *
div_table[2 * j + 2];
}
}
for (i = 0; i < 8; i++) {
......@@ -127,57 +131,62 @@ static int od_dir_find8(const od_dering_in *img, int stride, int32_t *var,
}
#define OD_DERING_VERY_LARGE (30000)
#define OD_DERING_INBUF_SIZE ((OD_BSIZE_MAX + 2*OD_FILT_BORDER)*\
(OD_BSIZE_MAX + 2*OD_FILT_BORDER))
#define OD_DERING_INBUF_SIZE \
((OD_BSIZE_MAX + 2 * OD_FILT_BORDER) * (OD_BSIZE_MAX + 2 * OD_FILT_BORDER))
/* Smooth in the direction detected. */
void od_filter_dering_direction_c(int16_t *y, int ystride, const int16_t *in,
int ln, int threshold, int dir) {
int ln, int threshold, int dir) {
int i;
int j;
int k;
static const int taps[3] = {3, 2, 2};
static const int taps[3] = { 3, 2, 2 };
for (i = 0; i < 1 << ln; i++) {
for (j = 0; j < 1 << ln; j++) {
int16_t sum;
int16_t xx;
int16_t yy;
xx = in[i*OD_FILT_BSTRIDE + j];
sum= 0;
xx = in[i * OD_FILT_BSTRIDE + j];
sum = 0;
for (k = 0; k < 3; k++) {
int16_t p0;
int16_t p1;
p0 = in[i*OD_FILT_BSTRIDE + j + OD_DIRECTION_OFFSETS_TABLE[dir][k]]
- xx;
p1 = in[i*OD_FILT_BSTRIDE + j - OD_DIRECTION_OFFSETS_TABLE[dir][k]]
- xx;
if (abs(p0) < threshold) sum += taps[k]*p0;
if (abs(p1) < threshold) sum += taps[k]*p1;
p0 = in[i * OD_FILT_BSTRIDE + j + OD_DIRECTION_OFFSETS_TABLE[dir][k]] -
xx;
p1 = in[i * OD_FILT_BSTRIDE + j - OD_DIRECTION_OFFSETS_TABLE[dir][k]] -
xx;
if (abs(p0) < threshold) sum += taps[k] * p0;
if (abs(p1) < threshold) sum += taps[k] * p1;
}
yy = xx + ((sum + 8) >> 4);
y[i*ystride + j] = yy;
y[i * ystride + j] = yy;
}
}
}
void od_filter_dering_direction_4x4_c(int16_t *y, int ystride,
const int16_t *in, int threshold, int dir) {
const int16_t *in, int threshold,
int dir) {
od_filter_dering_direction_c(y, ystride, in, 2, threshold, dir);
}
void od_filter_dering_direction_8x8_c(int16_t *y, int ystride,
const int16_t *in, int threshold, int dir) {
const int16_t *in, int threshold,
int dir) {
od_filter_dering_direction_c(y, ystride, in, 3, threshold, dir);
}
/* Smooth in the direction orthogonal to what was detected. */
void od_filter_dering_orthogonal_c(int16_t *y, int ystride, const int16_t *in,
const od_dering_in *x, int xstride, int ln, int threshold, int dir) {
const od_dering_in *x, int xstride, int ln,
int threshold, int dir) {
int i;
int j;
int offset;
if (dir > 0 && dir < 4) offset = OD_FILT_BSTRIDE;
else offset = 1;
if (dir > 0 && dir < 4)
offset = OD_FILT_BSTRIDE;
else
offset = 1;
for (i = 0; i < 1 << ln; i++) {
for (j = 0; j < 1 << ln; j++) {
int16_t athresh;
......@@ -192,32 +201,33 @@ void od_filter_dering_orthogonal_c(int16_t *y, int ystride, const int16_t *in,
to be a little bit more aggressive on pure horizontal/vertical
since the ringing there tends to be directional, so it doesn't
get removed by the directional filtering. */
athresh = OD_MINI(threshold, threshold/3
+ abs(in[i*OD_FILT_BSTRIDE + j] - x[i*xstride + j]));
yy = in[i*OD_FILT_BSTRIDE + j];
athresh = OD_MINI(
threshold, threshold / 3 +
abs(in[i * OD_FILT_BSTRIDE + j] - x[i * xstride + j]));
yy = in[i * OD_FILT_BSTRIDE + j];
sum = 0;
p = in[i*OD_FILT_BSTRIDE + j + offset] - yy;
p = in[i * OD_FILT_BSTRIDE + j + offset] - yy;
if (abs(p) < athresh) sum += p;
p = in[i*OD_FILT_BSTRIDE + j - offset] - yy;
p = in[i * OD_FILT_BSTRIDE + j - offset] - yy;
if (abs(p) < athresh) sum += p;
p = in[i*OD_FILT_BSTRIDE + j + 2*offset] - yy;
p = in[i * OD_FILT_BSTRIDE + j + 2 * offset] - yy;
if (abs(p) < athresh) sum += p;
p = in[i*OD_FILT_BSTRIDE + j - 2*offset] - yy;
p = in[i * OD_FILT_BSTRIDE + j - 2 * offset] - yy;
if (abs(p) < athresh) sum += p;
y[i*ystride + j] = yy + ((3*sum + 8) >> 4);
y[i * ystride + j] = yy + ((3 * sum + 8) >> 4);
}
}
}
void od_filter_dering_orthogonal_4x4_c(int16_t *y, int ystride,
const int16_t *in, const od_dering_in *x, int xstride, int threshold,
int dir) {
const int16_t *in, const od_dering_in *x,
int xstride, int threshold, int dir) {
od_filter_dering_orthogonal_c(y, ystride, in, x, xstride, 2, threshold, dir);
}
void od_filter_dering_orthogonal_8x8_c(int16_t *y, int ystride,
const int16_t *in, const od_dering_in *x, int xstride, int threshold,
int dir) {
const int16_t *in, const od_dering_in *x,
int xstride, int threshold, int dir) {
od_filter_dering_orthogonal_c(y, ystride, in, x, xstride, 3, threshold, dir);
}
......@@ -225,9 +235,8 @@ void od_filter_dering_orthogonal_8x8_c(int16_t *y, int ystride,
to [-.5, 3]. The table is computed as:
round(256*min(3, max(.5, 1.08*(sqrt(2)*2.^([0:17]+8)/256/256).^.16))) */
static const int16_t OD_THRESH_TABLE_Q8[18] = {
128, 134, 150, 168, 188, 210, 234, 262,
292, 327, 365, 408, 455, 509, 569, 635,
710, 768,
128, 134, 150, 168, 188, 210, 234, 262, 292,
327, 365, 408, 455, 509, 569, 635, 710, 768,
};
/* Compute deringing filter threshold for each 8x8 block based on the
......@@ -237,8 +246,9 @@ static const int16_t OD_THRESH_TABLE_Q8[18] = {
contrast edge, or a non-directional texture, so we want to be careful not
to blur. */
static void od_compute_thresh(int thresh[OD_DERING_NBLOCKS][OD_DERING_NBLOCKS],
int threshold, int32_t var[OD_DERING_NBLOCKS][OD_DERING_NBLOCKS],
int nhb, int nvb) {
int threshold,
int32_t var[OD_DERING_NBLOCKS][OD_DERING_NBLOCKS],
int nhb, int nvb) {
int bx;
int by;
for (by = 0; by < nvb; by++) {
......@@ -246,16 +256,17 @@ static void od_compute_thresh(int thresh[OD_DERING_NBLOCKS][OD_DERING_NBLOCKS],
int v1;
/* We use the variance of 8x8 blocks to adjust the threshold. */
v1 = OD_MINI(32767, var[by][bx] >> 6);
thresh[by][bx] = (threshold*OD_THRESH_TABLE_Q8[OD_ILOG(v1)] + 128) >> 8;
thresh[by][bx] = (threshold * OD_THRESH_TABLE_Q8[OD_ILOG(v1)] + 128) >> 8;
}
}
}
void od_dering(const od_dering_opt_vtbl *vtbl, int16_t *y, int ystride,