|
|
@ -41,6 +41,7 @@ typedef struct GEQContext { |
|
|
|
int hsub, vsub; ///< chroma subsampling
|
|
|
|
int hsub, vsub; ///< chroma subsampling
|
|
|
|
int planes; ///< number of planes
|
|
|
|
int planes; ///< number of planes
|
|
|
|
int is_rgb; |
|
|
|
int is_rgb; |
|
|
|
|
|
|
|
int bps; |
|
|
|
} GEQContext; |
|
|
|
} GEQContext; |
|
|
|
|
|
|
|
|
|
|
|
enum { Y = 0, U, V, A, G, B, R }; |
|
|
|
enum { Y = 0, U, V, A, G, B, R }; |
|
|
@ -74,7 +75,7 @@ static inline double getpix(void *priv, double x, double y, int plane) |
|
|
|
GEQContext *geq = priv; |
|
|
|
GEQContext *geq = priv; |
|
|
|
AVFrame *picref = geq->picref; |
|
|
|
AVFrame *picref = geq->picref; |
|
|
|
const uint8_t *src = picref->data[plane]; |
|
|
|
const uint8_t *src = picref->data[plane]; |
|
|
|
const int linesize = picref->linesize[plane]; |
|
|
|
int linesize = picref->linesize[plane]; |
|
|
|
const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width; |
|
|
|
const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width; |
|
|
|
const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height; |
|
|
|
const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height; |
|
|
|
|
|
|
|
|
|
|
@ -87,8 +88,16 @@ static inline double getpix(void *priv, double x, double y, int plane) |
|
|
|
x -= xi; |
|
|
|
x -= xi; |
|
|
|
y -= yi; |
|
|
|
y -= yi; |
|
|
|
|
|
|
|
|
|
|
|
return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize]) |
|
|
|
if (geq->bps > 8) { |
|
|
|
+ y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]); |
|
|
|
const uint16_t *src16 = (const uint16_t*)src; |
|
|
|
|
|
|
|
linesize /= 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (1-y)*((1-x)*src16[xi + yi * linesize] + x*src16[xi + 1 + yi * linesize]) |
|
|
|
|
|
|
|
+ y *((1-x)*src16[xi + (yi+1) * linesize] + x*src16[xi + 1 + (yi+1) * linesize]); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize]) |
|
|
|
|
|
|
|
+ y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO: cubic interpolate
|
|
|
|
//TODO: cubic interpolate
|
|
|
@ -129,8 +138,11 @@ static av_cold int geq_init(AVFilterContext *ctx) |
|
|
|
if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]); |
|
|
|
if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!geq->expr_str[A]) |
|
|
|
if (!geq->expr_str[A]) { |
|
|
|
geq->expr_str[A] = av_strdup("255"); |
|
|
|
char bps_string[8]; |
|
|
|
|
|
|
|
snprintf(bps_string, sizeof(bps_string), "%d", (1<<geq->bps) - 1); |
|
|
|
|
|
|
|
geq->expr_str[A] = av_strdup(bps_string); |
|
|
|
|
|
|
|
} |
|
|
|
if (!geq->expr_str[G]) |
|
|
|
if (!geq->expr_str[G]) |
|
|
|
geq->expr_str[G] = av_strdup("g(X,Y)"); |
|
|
|
geq->expr_str[G] = av_strdup("g(X,Y)"); |
|
|
|
if (!geq->expr_str[B]) |
|
|
|
if (!geq->expr_str[B]) |
|
|
@ -171,10 +183,27 @@ static int geq_query_formats(AVFilterContext *ctx) |
|
|
|
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P, |
|
|
|
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P, |
|
|
|
AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P, |
|
|
|
AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P, |
|
|
|
AV_PIX_FMT_GRAY8, |
|
|
|
AV_PIX_FMT_GRAY8, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUV440P10, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10, |
|
|
|
|
|
|
|
AV_PIX_FMT_GRAY10, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, |
|
|
|
|
|
|
|
AV_PIX_FMT_GRAY12, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV420P14, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUV444P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV420P16, |
|
|
|
|
|
|
|
AV_PIX_FMT_YUVA444P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA420P16, |
|
|
|
|
|
|
|
AV_PIX_FMT_GRAY16, |
|
|
|
AV_PIX_FMT_NONE |
|
|
|
AV_PIX_FMT_NONE |
|
|
|
}; |
|
|
|
}; |
|
|
|
static const enum AVPixelFormat rgb_pix_fmts[] = { |
|
|
|
static const enum AVPixelFormat rgb_pix_fmts[] = { |
|
|
|
AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, |
|
|
|
AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, |
|
|
|
|
|
|
|
AV_PIX_FMT_GBRP9, |
|
|
|
|
|
|
|
AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, |
|
|
|
|
|
|
|
AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, |
|
|
|
|
|
|
|
AV_PIX_FMT_GBRP14, |
|
|
|
|
|
|
|
AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, |
|
|
|
AV_PIX_FMT_NONE |
|
|
|
AV_PIX_FMT_NONE |
|
|
|
}; |
|
|
|
}; |
|
|
|
AVFilterFormats *fmts_list; |
|
|
|
AVFilterFormats *fmts_list; |
|
|
@ -198,6 +227,8 @@ static int geq_config_props(AVFilterLink *inlink) |
|
|
|
geq->hsub = desc->log2_chroma_w; |
|
|
|
geq->hsub = desc->log2_chroma_w; |
|
|
|
geq->vsub = desc->log2_chroma_h; |
|
|
|
geq->vsub = desc->log2_chroma_h; |
|
|
|
geq->planes = desc->nb_components; |
|
|
|
geq->planes = desc->nb_components; |
|
|
|
|
|
|
|
geq->bps = desc->comp[0].depth; |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -223,6 +254,7 @@ static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in) |
|
|
|
for (plane = 0; plane < geq->planes && out->data[plane]; plane++) { |
|
|
|
for (plane = 0; plane < geq->planes && out->data[plane]; plane++) { |
|
|
|
int x, y; |
|
|
|
int x, y; |
|
|
|
uint8_t *dst = out->data[plane]; |
|
|
|
uint8_t *dst = out->data[plane]; |
|
|
|
|
|
|
|
uint16_t *dst16 = (uint16_t*)out->data[plane]; |
|
|
|
const int linesize = out->linesize[plane]; |
|
|
|
const int linesize = out->linesize[plane]; |
|
|
|
const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w; |
|
|
|
const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w; |
|
|
|
const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h; |
|
|
|
const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h; |
|
|
@ -234,11 +266,19 @@ static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in) |
|
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < h; y++) { |
|
|
|
for (y = 0; y < h; y++) { |
|
|
|
values[VAR_Y] = y; |
|
|
|
values[VAR_Y] = y; |
|
|
|
for (x = 0; x < w; x++) { |
|
|
|
if (geq->bps > 8) { |
|
|
|
values[VAR_X] = x; |
|
|
|
for (x = 0; x < w; x++) { |
|
|
|
dst[x] = av_expr_eval(geq->e[plane], values, geq); |
|
|
|
values[VAR_X] = x; |
|
|
|
|
|
|
|
dst16[x] = av_expr_eval(geq->e[plane], values, geq); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dst16 += linesize / 2; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for (x = 0; x < w; x++) { |
|
|
|
|
|
|
|
values[VAR_X] = x; |
|
|
|
|
|
|
|
dst[x] = av_expr_eval(geq->e[plane], values, geq); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dst += linesize; |
|
|
|
} |
|
|
|
} |
|
|
|
dst += linesize; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|