|
|
@ -124,6 +124,9 @@ static int query_formats(AVFilterContext *ctx) |
|
|
|
AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P, |
|
|
|
AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P, |
|
|
|
AV_PIX_FMT_YUVJ440P, |
|
|
|
AV_PIX_FMT_YUVJ440P, |
|
|
|
AV_PIX_FMT_GBRP, |
|
|
|
AV_PIX_FMT_GBRP, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUVA420P10, |
|
|
|
|
|
|
|
AV_PIX_FMT_GBRP10, |
|
|
|
AV_PIX_FMT_NONE |
|
|
|
AV_PIX_FMT_NONE |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -142,8 +145,8 @@ static int config_input(AVFilterLink *inlink) |
|
|
|
char *expr; |
|
|
|
char *expr; |
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
|
|
if (!(s->temp[0] = av_malloc(FFMAX(w, h))) || |
|
|
|
if (!(s->temp[0] = av_malloc(2*FFMAX(w, h))) || |
|
|
|
!(s->temp[1] = av_malloc(FFMAX(w, h)))) |
|
|
|
!(s->temp[1] = av_malloc(2*FFMAX(w, h)))) |
|
|
|
return AVERROR(ENOMEM); |
|
|
|
return AVERROR(ENOMEM); |
|
|
|
|
|
|
|
|
|
|
|
s->hsub = desc->log2_chroma_w; |
|
|
|
s->hsub = desc->log2_chroma_w; |
|
|
@ -203,7 +206,7 @@ static int config_input(AVFilterLink *inlink) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static inline void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, |
|
|
|
static inline void blur8(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, |
|
|
|
int len, int radius) |
|
|
|
int len, int radius) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Naive boxblur would sum source pixels from x-radius .. x+radius
|
|
|
|
/* Naive boxblur would sum source pixels from x-radius .. x+radius
|
|
|
@ -245,34 +248,77 @@ static inline void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline void blur16(uint16_t *dst, int dst_step, const uint16_t *src, int src_step, |
|
|
|
|
|
|
|
int len, int radius) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const int length = radius*2 + 1; |
|
|
|
|
|
|
|
const int inv = ((1<<16) + length/2)/length; |
|
|
|
|
|
|
|
int x, sum = src[radius*src_step]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < radius; x++) |
|
|
|
|
|
|
|
sum += src[x*src_step]<<1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sum = sum*inv + (1<<15); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (x = 0; x <= radius; x++) { |
|
|
|
|
|
|
|
sum += (src[(radius+x)*src_step] - src[(radius-x)*src_step])*inv; |
|
|
|
|
|
|
|
dst[x*dst_step] = sum>>16; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (; x < len-radius; x++) { |
|
|
|
|
|
|
|
sum += (src[(radius+x)*src_step] - src[(x-radius-1)*src_step])*inv; |
|
|
|
|
|
|
|
dst[x*dst_step] = sum >>16; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (; x < len; x++) { |
|
|
|
|
|
|
|
sum += (src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step])*inv; |
|
|
|
|
|
|
|
dst[x*dst_step] = sum>>16; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, |
|
|
|
|
|
|
|
int len, int radius, int pixsize) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (pixsize == 1) blur8 (dst, dst_step , src, src_step , len, radius); |
|
|
|
|
|
|
|
else blur16((uint16_t*)dst, dst_step>>1, (const uint16_t*)src, src_step>>1, len, radius); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static inline void blur_power(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, |
|
|
|
static inline void blur_power(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, |
|
|
|
int len, int radius, int power, uint8_t *temp[2]) |
|
|
|
int len, int radius, int power, uint8_t *temp[2], int pixsize) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t *a = temp[0], *b = temp[1]; |
|
|
|
uint8_t *a = temp[0], *b = temp[1]; |
|
|
|
|
|
|
|
|
|
|
|
if (radius && power) { |
|
|
|
if (radius && power) { |
|
|
|
blur(a, 1, src, src_step, len, radius); |
|
|
|
blur(a, pixsize, src, src_step, len, radius, pixsize); |
|
|
|
for (; power > 2; power--) { |
|
|
|
for (; power > 2; power--) { |
|
|
|
uint8_t *c; |
|
|
|
uint8_t *c; |
|
|
|
blur(b, 1, a, 1, len, radius); |
|
|
|
blur(b, pixsize, a, pixsize, len, radius, pixsize); |
|
|
|
c = a; a = b; b = c; |
|
|
|
c = a; a = b; b = c; |
|
|
|
} |
|
|
|
} |
|
|
|
if (power > 1) { |
|
|
|
if (power > 1) { |
|
|
|
blur(dst, dst_step, a, 1, len, radius); |
|
|
|
blur(dst, dst_step, a, pixsize, len, radius, pixsize); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
for (i = 0; i < len; i++) |
|
|
|
if (pixsize == 1) { |
|
|
|
dst[i*dst_step] = a[i]; |
|
|
|
for (i = 0; i < len; i++) |
|
|
|
|
|
|
|
dst[i*dst_step] = a[i]; |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
for (i = 0; i < len; i++) |
|
|
|
|
|
|
|
*(uint16_t*)(dst + i*dst_step) = ((uint16_t*)a)[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
for (i = 0; i < len; i++) |
|
|
|
if (pixsize == 1) { |
|
|
|
dst[i*dst_step] = src[i*src_step]; |
|
|
|
for (i = 0; i < len; i++) |
|
|
|
|
|
|
|
dst[i*dst_step] = src[i*src_step]; |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
for (i = 0; i < len; i++) |
|
|
|
|
|
|
|
*(uint16_t*)(dst + i*dst_step) = *(uint16_t*)(src + i*src_step); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, |
|
|
|
static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, |
|
|
|
int w, int h, int radius, int power, uint8_t *temp[2]) |
|
|
|
int w, int h, int radius, int power, uint8_t *temp[2], int pixsize) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int y; |
|
|
|
int y; |
|
|
|
|
|
|
|
|
|
|
@ -280,12 +326,12 @@ static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_li |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < h; y++) |
|
|
|
for (y = 0; y < h; y++) |
|
|
|
blur_power(dst + y*dst_linesize, 1, src + y*src_linesize, 1, |
|
|
|
blur_power(dst + y*dst_linesize, pixsize, src + y*src_linesize, pixsize, |
|
|
|
w, radius, power, temp); |
|
|
|
w, radius, power, temp, pixsize); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, |
|
|
|
static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, |
|
|
|
int w, int h, int radius, int power, uint8_t *temp[2]) |
|
|
|
int w, int h, int radius, int power, uint8_t *temp[2], int pixsize) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int x; |
|
|
|
int x; |
|
|
|
|
|
|
|
|
|
|
@ -293,8 +339,8 @@ static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_li |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < w; x++) |
|
|
|
for (x = 0; x < w; x++) |
|
|
|
blur_power(dst + x, dst_linesize, src + x, src_linesize, |
|
|
|
blur_power(dst + x*pixsize, dst_linesize, src + x*pixsize, src_linesize, |
|
|
|
h, radius, power, temp); |
|
|
|
h, radius, power, temp, pixsize); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
|
|
@ -307,6 +353,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
|
|
|
int cw = FF_CEIL_RSHIFT(inlink->w, s->hsub), ch = FF_CEIL_RSHIFT(in->height, s->vsub); |
|
|
|
int cw = FF_CEIL_RSHIFT(inlink->w, s->hsub), ch = FF_CEIL_RSHIFT(in->height, s->vsub); |
|
|
|
int w[4] = { inlink->w, cw, cw, inlink->w }; |
|
|
|
int w[4] = { inlink->w, cw, cw, inlink->w }; |
|
|
|
int h[4] = { in->height, ch, ch, in->height }; |
|
|
|
int h[4] = { in->height, ch, ch, in->height }; |
|
|
|
|
|
|
|
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
|
|
|
|
|
|
|
const int depth = desc->comp[0].depth_minus1 + 1; |
|
|
|
|
|
|
|
const int pixsize = (depth+7)/8; |
|
|
|
|
|
|
|
|
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
|
|
|
if (!out) { |
|
|
|
if (!out) { |
|
|
@ -319,13 +368,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
|
|
|
hblur(out->data[plane], out->linesize[plane], |
|
|
|
hblur(out->data[plane], out->linesize[plane], |
|
|
|
in ->data[plane], in ->linesize[plane], |
|
|
|
in ->data[plane], in ->linesize[plane], |
|
|
|
w[plane], h[plane], s->radius[plane], s->power[plane], |
|
|
|
w[plane], h[plane], s->radius[plane], s->power[plane], |
|
|
|
s->temp); |
|
|
|
s->temp, pixsize); |
|
|
|
|
|
|
|
|
|
|
|
for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) |
|
|
|
for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) |
|
|
|
vblur(out->data[plane], out->linesize[plane], |
|
|
|
vblur(out->data[plane], out->linesize[plane], |
|
|
|
out->data[plane], out->linesize[plane], |
|
|
|
out->data[plane], out->linesize[plane], |
|
|
|
w[plane], h[plane], s->radius[plane], s->power[plane], |
|
|
|
w[plane], h[plane], s->radius[plane], s->power[plane], |
|
|
|
s->temp); |
|
|
|
s->temp, pixsize); |
|
|
|
|
|
|
|
|
|
|
|
av_frame_free(&in); |
|
|
|
av_frame_free(&in); |
|
|
|
|
|
|
|
|
|
|
|