Permalink
Browse files

Make CLPF 8 tap and add ramp-down constraint

  • Loading branch information...
Arild Fuldseth (arilfuld) Thomas Davies
Arild Fuldseth (arilfuld) authored and Thomas Davies committed Mar 2, 2017
1 parent 7e25377 commit 461fad8418d76daaf2650102c6deea90446b15e3
View
@@ -104,14 +104,24 @@ void TEMPLATE(find_block_contexts)(int ypos, int xpos, int height, int width, in
}
}
-int TEMPLATE(clpf_sample)(int X, int A, int B, int C, int D, int E, int F, int b) {
- int delta =
- 4*clip(A - X, -b, b) + clip(B - X, -b, b) + 3*clip(C - X, -b, b) +
- 3*clip(D - X, -b, b) + clip(E - X, -b, b) + 4*clip(F - X, -b, b);
+#ifndef HBD
+static int sign(int i) { return i < 0 ? -1 : 1; }
+
+static int constrain(int x, int s, unsigned int damping) {
+ return sign(x) * max(0, abs(x) - max(0, abs(x) - s +
+ (abs(x) >> (damping - log2i(s)))));
+}
+
+int clpf_sample(int X, int A, int B, int C, int D, int E, int F, int G, int H, int s, unsigned int dmp) {
+ int delta = 1 * constrain(A - X, s, dmp) + 3 * constrain(B - X, s, dmp) +
+ 1 * constrain(C - X, s, dmp) + 3 * constrain(D - X, s, dmp) +
+ 3 * constrain(E - X, s, dmp) + 1 * constrain(F - X, s, dmp) +
+ 3 * constrain(G - X, s, dmp) + 1 * constrain(H - X, s, dmp);
return (8 + delta - (delta < 0)) >> 4;
}
+#endif
-void TEMPLATE(clpf_block)(const SAMPLE *src, SAMPLE *dst, int sstride, int dstride, int x0, int y0, int sizex, int sizey, boundary_type bt, unsigned int strength) {
+void TEMPLATE(clpf_block)(const SAMPLE *src, SAMPLE *dst, int sstride, int dstride, int x0, int y0, int sizex, int sizey, boundary_type bt, unsigned int strength, unsigned int damping) {
const int xmin = x0 - !(bt & TILE_LEFT_BOUNDARY) * 2;
const int ymin = y0 - !(bt & TILE_ABOVE_BOUNDARY) * 2;
const int xmax = x0 + sizex + !(bt & TILE_RIGHT_BOUNDARY) * 2 - 1;
@@ -120,13 +130,15 @@ void TEMPLATE(clpf_block)(const SAMPLE *src, SAMPLE *dst, int sstride, int dstri
for (int y = y0; y < y0 + sizey; y++) {
for (int x = x0; x < x0 + sizex; x++) {
const int X = src[y * sstride + x];
- const int A = src[max(ymin, y - 1) * sstride + x];
- const int B = src[y * sstride + max(xmin, x - 2)];
- const int C = src[y * sstride + max(xmin, x - 1)];
- const int D = src[y * sstride + min(xmax, x + 1)];
- const int E = src[y * sstride + min(xmax, x + 2)];
- const int F = src[min(ymax, y + 1) * sstride + x];
- const int delta = TEMPLATE(clpf_sample)(X, A, B, C, D, E, F, strength);
+ const int A = src[max(ymin, y - 2) * sstride + x];
+ const int B = src[max(ymin, y - 1) * sstride + x];
+ const int C = src[y * sstride + max(xmin, x - 2)];
+ const int D = src[y * sstride + max(xmin, x - 1)];
+ const int E = src[y * sstride + min(xmax, x + 1)];
+ const int F = src[y * sstride + min(xmax, x + 2)];
+ const int G = src[min(ymax, y + 1) * sstride + x];
+ const int H = src[min(ymax, y + 2) * sstride + x];
+ const int delta = clpf_sample(X, A, B, C, D, E, F, G, H, strength, damping);
dst[y * dstride + x] = X + delta;
}
}
View
@@ -35,9 +35,9 @@ void TEMPLATE(reconstruct_block)(int16_t *block, SAMPLE *pblock, SAMPLE *rec, in
void TEMPLATE(find_block_contexts)(int ypos, int xpos, int height, int width, int size, deblock_data_t *deblock_data, block_context_t *block_context, int enable);
-void TEMPLATE(clpf_block)(const SAMPLE *src, SAMPLE *dst, int sstride, int dstride, int x0, int y0, int sizex, int sizey, boundary_type bt, unsigned int strength);
+void TEMPLATE(clpf_block)(const SAMPLE *src, SAMPLE *dst, int sstride, int dstride, int x0, int y0, int sizex, int sizey, boundary_type bt, unsigned int strength, unsigned int damping);
-int TEMPLATE(clpf_sample)(int X, int A, int B, int C, int D, int E, int F, int b);
+int clpf_sample(int X, int A, int B, int C, int D, int E, int F, int G, int H, int s, unsigned int dmp);
void TEMPLATE(improve_uv_prediction)(SAMPLE *y, SAMPLE *u, SAMPLE *v, SAMPLE *ry, int n, int cstride, int stride, int sub, int bitdepth);
View
@@ -761,8 +761,8 @@ void TEMPLATE(create_reference_frame)(yuv_frame_t *ref,yuv_frame_t *rec)
TEMPLATE(pad_yuv_frame)(ref);
}
-void TEMPLATE(clpf_frame)(const yuv_frame_t *frame, const yuv_frame_t *org, const deblock_data_t *deblock_data, void *stream, int enable_fb_flag, unsigned int strength, unsigned int fb_size_log2, int bitdepth, unsigned int plane,
- int(*decision)(int, int, const yuv_frame_t *, const yuv_frame_t *, const deblock_data_t *, int, int, int, void *, unsigned int, unsigned int, unsigned int, unsigned int)) {
+void TEMPLATE(clpf_frame)(const yuv_frame_t *frame, const yuv_frame_t *org, const deblock_data_t *deblock_data, void *stream, int enable_fb_flag, unsigned int strength, unsigned int fb_size_log2, int bitdepth, unsigned int plane, int qp,
+ int(*decision)(int, int, const yuv_frame_t *, const yuv_frame_t *, const deblock_data_t *, int, int, int, void *, unsigned int, unsigned int, unsigned int, unsigned int, int)) {
/* Constrained low-pass filter (CLPF) */
int c, k, l, m, n;
@@ -784,6 +784,7 @@ void TEMPLATE(clpf_frame)(const yuv_frame_t *frame, const yuv_frame_t *org, cons
const int cache_blocks = cache_size / (bs * bs);
SAMPLE *src_buffer = plane != PLANE_Y ? (plane == PLANE_U ? frame->u : frame->v) : frame->y;
SAMPLE *dst_buffer;
+ int damping = bitdepth - 4 - (plane != PLANE_Y) + (qp >> 4);
// Make buffer space for in-place filtering
cache = thor_alloc(cache_size * sizeof(SAMPLE), 32);
@@ -820,7 +821,7 @@ void TEMPLATE(clpf_frame)(const yuv_frame_t *frame, const yuv_frame_t *org, cons
(!enable_fb_flag ||
// Only called if fb_flag enabled (luma only)
decision(k, l, frame, org, deblock_data, bs, w / bs, h / bs, stream, strength,
- fb_size_log2, bitdepth-8, bs))) {
+ fb_size_log2, bitdepth-8, bs, qp))) {
// Iterate over all smaller blocks inside the filter block
for (m = 0; m < ((h + bs - 1) >> bslog); m++) {
for (n = 0; n < ((w + bs - 1) >> bslog); n++) {
@@ -880,7 +881,7 @@ void TEMPLATE(clpf_frame)(const yuv_frame_t *frame, const yuv_frame_t *org, cons
// Apply the filter
(use_simd ? TEMPLATE(clpf_block_simd) : TEMPLATE(clpf_block))
(src_buffer, dst_buffer, sstride, dstride, xpos,
- ypos, sizex, sizey, bt, strength);
+ ypos, sizex, sizey, bt, strength, damping);
}
}
}
View
@@ -43,8 +43,8 @@ void deblock_frame_uv_lbd(yuv_frame_t *rec, deblock_data_t *deblock_data, int w
void deblock_frame_uv_hbd(yuv_frame_t *rec, deblock_data_t *deblock_data, int width, int height, uint8_t qp, int bitdepth);
void create_reference_frame_lbd(yuv_frame_t *ref,yuv_frame_t *rec);
void create_reference_frame_hbd(yuv_frame_t *ref,yuv_frame_t *rec);
-void clpf_frame_lbd(yuv_frame_t *frame, yuv_frame_t *org, const deblock_data_t *deblock_data, void *stream,int enable_sb_flag, unsigned int strength, unsigned int fb_size_log2, int bitdepth, plane_t plane,
- int(*decision)(int, int, const yuv_frame_t *, const yuv_frame_t *, const deblock_data_t *, int, int, int, void *, unsigned int, unsigned int, unsigned int, unsigned int));
-void clpf_frame_hbd(yuv_frame_t *frame, yuv_frame_t *org, const deblock_data_t *deblock_data, void *stream,int enable_sb_flag, unsigned int strength, unsigned int fb_size_log2, int bitdepth, plane_t plane,
- int(*decision)(int, int, const yuv_frame_t *, const yuv_frame_t *, const deblock_data_t *, int, int, int, void *, unsigned int, unsigned int, unsigned int, unsigned int));
+void clpf_frame_lbd(yuv_frame_t *frame, yuv_frame_t *org, const deblock_data_t *deblock_data, void *stream,int enable_sb_flag, unsigned int strength, unsigned int fb_size_log2, int bitdepth, plane_t plane, int qp,
+ int(*decision)(int, int, const yuv_frame_t *, const yuv_frame_t *, const deblock_data_t *, int, int, int, void *, unsigned int, unsigned int, unsigned int, unsigned int, int));
+void clpf_frame_hbd(yuv_frame_t *frame, yuv_frame_t *org, const deblock_data_t *deblock_data, void *stream,int enable_sb_flag, unsigned int strength, unsigned int fb_size_log2, int bitdepth, plane_t plane, int qp,
+ int(*decision)(int, int, const yuv_frame_t *, const yuv_frame_t *, const deblock_data_t *, int, int, int, void *, unsigned int, unsigned int, unsigned int, unsigned int, int));
#endif
Oops, something went wrong.

0 comments on commit 461fad8

Please sign in to comment.