static NOINLINE void
splat_dc(pixel *dst, const ptrdiff_t stride, const int width, const int height, const int dc HIGHBD_DECL_SUFFIX)
{ #if BITDEPTH == 8
assert(dc <= 0xff);
if (width > 4) { const uint64_t dcN = dc * 0x0101010101010101ULL;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += sizeof(dcN))
*((uint64_t *) &dst[x]) = dcN;
dst += PXSTRIDE(stride);
}
} else { constunsigned dcN = dc * 0x01010101U;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += sizeof(dcN))
*((unsigned *) &dst[x]) = dcN;
dst += PXSTRIDE(stride);
}
} #else
assert(dc <= bitdepth_max); const uint64_t dcN = dc * 0x0001000100010001ULL;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += sizeof(dcN) >> 1)
*((uint64_t *) &dst[x]) = dcN;
dst += PXSTRIDE(stride);
} #endif
}
static NOINLINE void
cfl_pred(pixel *dst, const ptrdiff_t stride, const int width, const int height, const int dc, const int16_t *ac, const int alpha HIGHBD_DECL_SUFFIX)
{
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { const int diff = alpha * ac[x];
dst[x] = iclip_pixel(dc + apply_sign((abs(diff) + 32) >> 6, diff));
}
ac += width;
dst += PXSTRIDE(stride);
}
}
staticunsigned dc_gen_top(const pixel *const topleft, const int width) { unsigned dc = width >> 1;
for (int i = 0; i < width; i++)
dc += topleft[1 + i]; return dc >> ctz(width);
}
staticvoid ipred_dc_top_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{
splat_dc(dst, stride, width, height, dc_gen_top(topleft, width)
HIGHBD_TAIL_SUFFIX);
}
staticunsigned dc_gen_left(const pixel *const topleft, const int height) { unsigned dc = height >> 1;
for (int i = 0; i < height; i++)
dc += topleft[-(1 + i)]; return dc >> ctz(height);
}
staticvoid ipred_dc_left_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{
splat_dc(dst, stride, width, height, dc_gen_left(topleft, height)
HIGHBD_TAIL_SUFFIX);
}
staticvoid ipred_cfl_left_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int16_t *ac, const int alpha
HIGHBD_DECL_SUFFIX)
{ constunsigned dc = dc_gen_left(topleft, height);
cfl_pred(dst, stride, width, height, dc, ac, alpha HIGHBD_TAIL_SUFFIX);
}
staticunsigned dc_gen(const pixel *const topleft, const int width, const int height)
{ unsigned dc = (width + height) >> 1;
for (int i = 0; i < width; i++)
dc += topleft[i + 1];
for (int i = 0; i < height; i++)
dc += topleft[-(i + 1)];
dc >>= ctz(width + height);
if (width != height) {
dc *= (width > height * 2 || height > width * 2) ? MULTIPLIER_1x4 :
MULTIPLIER_1x2;
dc >>= BASE_SHIFT;
} return dc;
}
staticvoid ipred_dc_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{
splat_dc(dst, stride, width, height, dc_gen(topleft, width, height)
HIGHBD_TAIL_SUFFIX);
}
staticvoid ipred_cfl_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int16_t *ac, const int alpha
HIGHBD_DECL_SUFFIX)
{ unsigned dc = dc_gen(topleft, width, height);
cfl_pred(dst, stride, width, height, dc, ac, alpha HIGHBD_TAIL_SUFFIX);
}
staticvoid ipred_dc_128_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{ #if BITDEPTH == 16 const int dc = (bitdepth_max + 1) >> 1; #else const int dc = 128; #endif
splat_dc(dst, stride, width, height, dc HIGHBD_TAIL_SUFFIX);
}
staticvoid ipred_cfl_128_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int16_t *ac, const int alpha
HIGHBD_DECL_SUFFIX)
{ #if BITDEPTH == 16 const int dc = (bitdepth_max + 1) >> 1; #else const int dc = 128; #endif
cfl_pred(dst, stride, width, height, dc, ac, alpha HIGHBD_TAIL_SUFFIX);
}
staticvoid ipred_v_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{
for (int y = 0; y < height; y++) {
pixel_copy(dst, topleft + 1, width);
dst += PXSTRIDE(stride);
}
}
staticvoid ipred_h_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{
for (int y = 0; y < height; y++) {
pixel_set(dst, topleft[-(1 + y)], width);
dst += PXSTRIDE(stride);
}
}
staticvoid ipred_paeth_c(pixel *dst, const ptrdiff_t stride, const pixel *const tl_ptr, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{ const int topleft = tl_ptr[0];
for (int y = 0; y < height; y++) { const int left = tl_ptr[-(y + 1)];
for (int x = 0; x < width; x++) { const int top = tl_ptr[1 + x]; const int base = left + top - topleft; const int ldiff = abs(left - base); const int tdiff = abs(top - base); const int tldiff = abs(topleft - base);
staticvoid ipred_smooth_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{ const uint8_t *const weights_hor = &dav1d_sm_weights[width]; const uint8_t *const weights_ver = &dav1d_sm_weights[height]; const int right = topleft[width], bottom = topleft[-height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { const int pred = weights_ver[y] * topleft[1 + x] +
(256 - weights_ver[y]) * bottom +
weights_hor[x] * topleft[-(1 + y)] +
(256 - weights_hor[x]) * right;
dst[x] = (pred + 256) >> 9;
}
dst += PXSTRIDE(stride);
}
}
staticvoid ipred_smooth_v_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{ const uint8_t *const weights_ver = &dav1d_sm_weights[height]; const int bottom = topleft[-height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { const int pred = weights_ver[y] * topleft[1 + x] +
(256 - weights_ver[y]) * bottom;
dst[x] = (pred + 128) >> 8;
}
dst += PXSTRIDE(stride);
}
}
staticvoid ipred_smooth_h_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft, const int width, const int height, const int a, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{ const uint8_t *const weights_hor = &dav1d_sm_weights[width]; const int right = topleft[width];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { const int pred = weights_hor[x] * topleft[-(y + 1)] +
(256 - weights_hor[x]) * right;
dst[x] = (pred + 128) >> 8;
}
dst += PXSTRIDE(stride);
}
}
static NOINLINE int get_filter_strength(const int wh, const int angle, const int is_sm)
{
if (is_sm) {
if (wh <= 8) {
if (angle >= 64) return2;
if (angle >= 40) return1;
} else if (wh <= 16) {
if (angle >= 48) return2;
if (angle >= 20) return1;
} else if (wh <= 24) {
if (angle >= 4) return3;
} else { return3;
}
} else {
if (wh <= 8) {
if (angle >= 56) return1;
} else if (wh <= 16) {
if (angle >= 40) return1;
} else if (wh <= 24) {
if (angle >= 32) return3;
if (angle >= 16) return2;
if (angle >= 8) return1;
} else if (wh <= 32) {
if (angle >= 32) return3;
if (angle >= 4) return2; return1;
} else { return3;
}
} return0;
}
static NOINLINE void filter_edge(pixel *const out, const int sz, const int lim_from, const int lim_to, const pixel *const in, const int from, const int to, const int strength)
{ staticconst uint8_t kernel[3][5] = {
{ 0, 4, 8, 4, 0 },
{ 0, 5, 6, 5, 0 },
{ 2, 4, 4, 4, 2 }
};
assert(strength > 0);
int i = 0;
for (; i < imin(sz, lim_from); i++)
out[i] = in[iclip(i, from, to - 1)];
for (; i < imin(lim_to, sz); i++) {
int s = 0;
for (int j = 0; j < 5; j++)
s += in[iclip(i - 2 + j, from, to - 1)] * kernel[strength - 1][j];
out[i] = (s + 8) >> 4;
}
for (; i < sz; i++)
out[i] = in[iclip(i, from, to - 1)];
}
static inline int get_upsample(const int wh, const int angle, const int is_sm) { return angle < 40 && wh <= 16 >> is_sm;
}
static NOINLINE void upsample_edge(pixel *const out, const int hsz, const pixel *const in, const int from, const int to HIGHBD_DECL_SUFFIX)
{ staticconst int8_t kernel[4] = { -1, 9, 9, -1 };
int i;
for (i = 0; i < hsz - 1; i++) {
out[i * 2] = in[iclip(i, from, to - 1)];
int s = 0;
for (int j = 0; j < 4; j++)
s += in[iclip(i + j - 1, from, to - 1)] * kernel[j];
out[i * 2 + 1] = iclip_pixel((s + 8) >> 4);
}
out[i * 2] = in[iclip(i, from, to - 1)];
}
staticvoid ipred_z1_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft_in, const int width, const int height, int angle, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{ const int is_sm = (angle >> 9) & 0x1; const int enable_intra_edge_filter = angle >> 10;
angle &= 511;
assert(angle < 90);
int dx = dav1d_dr_intra_derivative[angle >> 1];
pixel top_out[64 + 64]; const pixel *top;
int max_base_x; const int upsample_above = enable_intra_edge_filter ?
get_upsample(width + height, 90 - angle, is_sm) : 0;
if (upsample_above) {
upsample_edge(top_out, width + height, &topleft_in[1], -1,
width + imin(width, height) HIGHBD_TAIL_SUFFIX);
top = top_out;
max_base_x = 2 * (width + height) - 2;
dx <<= 1;
} else { const int filter_strength = enable_intra_edge_filter ?
get_filter_strength(width + height, 90 - angle, is_sm) : 0;
if (filter_strength) {
filter_edge(top_out, width + height, 0, width + height,
&topleft_in[1], -1, width + imin(width, height),
filter_strength);
top = top_out;
max_base_x = width + height - 1;
} else {
top = &topleft_in[1];
max_base_x = width + imin(width, height) - 1;
}
} const int base_inc = 1 + upsample_above;
for (int y = 0, xpos = dx; y < height;
y++, dst += PXSTRIDE(stride), xpos += dx)
{ const int frac = xpos & 0x3E;
for (int x = 0, base = xpos >> 6; x < width; x++, base += base_inc) {
if (base < max_base_x) { const int v = top[base] * (64 - frac) + top[base + 1] * frac;
dst[x] = (v + 32) >> 6;
} else {
pixel_set(&dst[x], top[max_base_x], width - x); break;
}
}
}
}
staticvoid ipred_z2_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft_in, const int width, const int height, int angle, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{ const int is_sm = (angle >> 9) & 0x1; const int enable_intra_edge_filter = angle >> 10;
angle &= 511;
assert(angle > 90 && angle < 180);
int dy = dav1d_dr_intra_derivative[(angle - 90) >> 1];
int dx = dav1d_dr_intra_derivative[(180 - angle) >> 1]; const int upsample_left = enable_intra_edge_filter ?
get_upsample(width + height, 180 - angle, is_sm) : 0; const int upsample_above = enable_intra_edge_filter ?
get_upsample(width + height, angle - 90, is_sm) : 0;
pixel edge[64 + 64 + 1];
pixel *const topleft = &edge[64];
/* Up to 32x32 only */ staticvoid ipred_filter_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft_in, const int width, const int height, int filt_idx, const int max_width, const int max_height
HIGHBD_DECL_SUFFIX)
{
filt_idx &= 511;
assert(filt_idx < 5);
const int8_t *const filter = dav1d_filter_intra_taps[filt_idx]; const pixel *top = &topleft_in[1];
for (int y = 0; y < height; y += 2) { const pixel *topleft = &topleft_in[-y]; const pixel *left = &topleft[-1];
ptrdiff_t left_stride = -1;
for (int x = 0; x < width; x += 4) { const int p0 = *topleft; const int p1 = top[0], p2 = top[1], p3 = top[2], p4 = top[3]; const int p5 = left[0 * left_stride], p6 = left[1 * left_stride];
pixel *ptr = &dst[x]; const int8_t *flt_ptr = filter;
for (int yy = 0; yy < 2; yy++) {
for (int xx = 0; xx < 4; xx++, flt_ptr += FLT_INCR) { const int acc = FILTER(flt_ptr, p0, p1, p2, p3, p4, p5, p6);
ptr[xx] = iclip_pixel((acc + 8) >> 4);
}
ptr += PXSTRIDE(stride);
}
left = &dst[x + 4 - 1];
left_stride = PXSTRIDE(stride);
top += 4;
topleft = &top[-1];
}
top = &dst[PXSTRIDE(stride)];
dst = &dst[PXSTRIDE(stride) * 2];
}
}
static NOINLINE void
cfl_ac_c(int16_t *ac, const pixel *ypx, const ptrdiff_t stride, const int w_pad, const int h_pad, const int width, const int height, const int ss_hor, const int ss_ver)
{
int y, x;
int16_t *const ac_orig = ac;
for (y = 0; y < height - 4 * h_pad; y++) {
for (x = 0; x < width - 4 * w_pad; x++) {
int ac_sum = ypx[x << ss_hor];
if (ss_hor) ac_sum += ypx[x * 2 + 1];
if (ss_ver) {
ac_sum += ypx[(x << ss_hor) + PXSTRIDE(stride)];
if (ss_hor) ac_sum += ypx[x * 2 + 1 + PXSTRIDE(stride)];
}
ac[x] = ac_sum << (1 + !ss_ver + !ss_hor);
}
for (; x < width; x++)
ac[x] = ac[x - 1];
ac += width;
ypx += PXSTRIDE(stride) << ss_ver;
}
for (; y < height; y++) {
memcpy(ac, &ac[-width], width * sizeof(*ac));
ac += width;
}
const int log2sz = ctz(width) + ctz(height);
int sum = (1 << log2sz) >> 1;
for (ac = ac_orig, y = 0; y < height; y++) {
for (x = 0; x < width; x++)
sum += ac[x];
ac += width;
}
sum >>= log2sz;
// subtract DC
for (ac = ac_orig, y = 0; y < height; y++) {
for (x = 0; x < width; x++)
ac[x] -= sum;
ac += width;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.