50 #define MIN_MATRIX_SIZE 3
51 #define MAX_MATRIX_SIZE 63
54 #define SHIFTUP(x,shift) (-((-(x))>>(shift)))
76 #define OFFSET(x) offsetof(UnsharpContext, x)
86 {
"chroma_msize_x",
"set chroma matrix x size",
OFFSET(chroma_msize_x),
AV_OPT_TYPE_INT, {.i64=5}, 3, 63 },
88 {
"chroma_msize_y",
"set chroma matrix y size",
OFFSET(chroma_msize_y),
AV_OPT_TYPE_INT, {.i64=5}, 3, 63 },
90 {
"chroma_amount",
"set chroma effect strenght",
OFFSET(chroma_amount),
AV_OPT_TYPE_DOUBLE, {.dbl=0.0}, -DBL_MAX, DBL_MAX },
99 const uint8_t *src,
int src_stride,
102 uint32_t **sc = fp->
sc;
108 const int amount = fp->
amount;
109 const int steps_x = fp->
steps_x;
110 const int steps_y = fp->
steps_y;
115 if (dst_stride == src_stride)
116 memcpy(dst, src, src_stride * height);
118 for (y = 0; y <
height; y++, dst += dst_stride, src += src_stride)
119 memcpy(dst, src, width);
123 for (y = 0; y < 2 * steps_y; y++)
124 memset(sc[y], 0,
sizeof(sc[y][0]) * (width + 2 * steps_x));
126 for (y = -steps_y; y < height + steps_y; y++) {
130 memset(sr, 0,
sizeof(sr[0]) * (2 * steps_x - 1));
131 for (x = -steps_x; x < width + steps_x; x++) {
132 tmp1 = x <= 0 ? src2[0] : x >= width ? src2[width-1] : src2[x];
133 for (z = 0; z < steps_x * 2; z += 2) {
134 tmp2 = sr[z + 0] + tmp1; sr[z + 0] = tmp1;
135 tmp1 = sr[z + 1] + tmp2; sr[z + 1] = tmp2;
137 for (z = 0; z < steps_y * 2; z += 2) {
138 tmp2 = sc[z + 0][x + steps_x] + tmp1; sc[z + 0][x + steps_x] = tmp1;
139 tmp1 = sc[z + 1][x + steps_x] + tmp2; sc[z + 1][x + steps_x] = tmp2;
141 if (x >= steps_x && y >= steps_y) {
142 const uint8_t *srx = src - steps_y * src_stride + x - steps_x;
143 uint8_t *dsx = dst - steps_y * dst_stride + x - steps_x;
145 res = (
int32_t)*srx + ((((
int32_t) * srx - (
int32_t)((tmp1 + halfscale) >> scalebits)) * amount) >> 16);
146 *dsx = av_clip_uint8(res);
160 fp->
amount = amount * 65536.0;
171 static const char *shorthand[] = {
172 "luma_msize_x",
"luma_msize_y",
"luma_amount",
173 "chroma_msize_x",
"chroma_msize_y",
"chroma_amount",
178 unsharp->
class = &unsharp_class;
206 const char *effect = fp->
amount == 0 ?
"none" : fp->
amount < 0 ?
"blur" :
"sharpen";
210 "Invalid even size for %s matrix size %dx%d\n",
218 for (z = 0; z < 2 * fp->
steps_y; z++)
248 for (z = 0; z < 2 * fp->
steps_y; z++)
313 .
inputs = avfilter_vf_unsharp_inputs,
315 .
outputs = avfilter_vf_unsharp_outputs,
317 .priv_class = &unsharp_class,