45
45
#define MAX_SIZE 13
47
#define CHROMA_WIDTH(link) -((-link->w) >> av_pix_fmt_descriptors[link->format].log2_chroma_w)
48
#define CHROMA_HEIGHT(link) -((-link->h) >> av_pix_fmt_descriptors[link->format].log2_chroma_h)
47
/* right-shift and round-up */
48
#define SHIFTUP(x,shift) (-((-(x))>>(shift)))
50
50
typedef struct FilterParam {
51
51
int msize_x; ///< matrix width
62
62
FilterParam luma; ///< luma parameters (width, height, amount)
63
63
FilterParam chroma; ///< chroma parameters (width, height, amount)
66
static void unsharpen(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, FilterParam *fp)
67
static void apply_unsharp( uint8_t *dst, int dst_stride,
68
const uint8_t *src, int src_stride,
69
int width, int height, FilterParam *fp)
68
71
uint32_t **sc = fp->sc;
69
72
uint32_t sr[(MAX_SIZE * MAX_SIZE) - 1], tmp1, tmp2;
75
79
if (dst_stride == src_stride)
84
88
memset(sc[y], 0, sizeof(sc[y][0]) * (width + 2 * fp->steps_x));
86
90
for (y = -fp->steps_y; y < height + fp->steps_y; y++) {
87
94
memset(sr, 0, sizeof(sr[0]) * (2 * fp->steps_x - 1));
88
95
for (x = -fp->steps_x; x < width + fp->steps_x; x++) {
89
tmp1 = x <= 0 ? src[0] : x >= width ? src[width-1] : src[x];
96
tmp1 = x <= 0 ? src2[0] : x >= width ? src2[width-1] : src2[x];
90
97
for (z = 0; z < fp->steps_x * 2; z += 2) {
91
98
tmp2 = sr[z + 0] + tmp1; sr[z + 0] = tmp1;
92
99
tmp1 = sr[z + 1] + tmp2; sr[z + 1] = tmp2;
125
132
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
127
134
UnsharpContext *unsharp = ctx->priv;
128
int lmsize_x = 5, cmsize_x = 0;
129
int lmsize_y = 5, cmsize_y = 0;
135
int lmsize_x = 5, cmsize_x = 5;
136
int lmsize_y = 5, cmsize_y = 5;
130
137
double lamount = 1.0f, camount = 0.0f;
179
186
UnsharpContext *unsharp = link->dst->priv;
188
unsharp->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
189
unsharp->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
181
191
init_filter_param(link->dst, &unsharp->luma, "luma", link->w);
182
init_filter_param(link->dst, &unsharp->chroma, "chroma", CHROMA_WIDTH(link));
192
init_filter_param(link->dst, &unsharp->chroma, "chroma", SHIFTUP(link->w, unsharp->hsub));
205
215
UnsharpContext *unsharp = link->dst->priv;
206
216
AVFilterBufferRef *in = link->cur_buf;
207
217
AVFilterBufferRef *out = link->dst->outputs[0]->out_buf;
218
int cw = SHIFTUP(link->w, unsharp->hsub);
219
int ch = SHIFTUP(link->h, unsharp->vsub);
209
unsharpen(out->data[0], in->data[0], out->linesize[0], in->linesize[0], link->w, link->h, &unsharp->luma);
210
unsharpen(out->data[1], in->data[1], out->linesize[1], in->linesize[1], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), &unsharp->chroma);
211
unsharpen(out->data[2], in->data[2], out->linesize[2], in->linesize[2], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), &unsharp->chroma);
221
apply_unsharp(out->data[0], out->linesize[0], in->data[0], in->linesize[0], link->w, link->h, &unsharp->luma);
222
apply_unsharp(out->data[1], out->linesize[1], in->data[1], in->linesize[1], cw, ch, &unsharp->chroma);
223
apply_unsharp(out->data[2], out->linesize[2], in->data[2], in->linesize[2], cw, ch, &unsharp->chroma);
213
225
avfilter_unref_buffer(in);
214
226
avfilter_draw_slice(link->dst->outputs[0], 0, link->h, 1);