Commit 04dd5dde authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'c0279956'

* commit 'c0279956':
  vf_fade: use the name 's' for the pointer to the private context
  vf_drawtext: use the name 's' for the pointer to the private context
  vf_drawbox: use the name 's' for the pointer to the private context

Conflicts:
	libavfilter/vf_drawbox.c
	libavfilter/vf_drawtext.c
	libavfilter/vf_fade.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents a134f967 c0279956
......@@ -47,19 +47,19 @@ typedef struct {
static av_cold int init(AVFilterContext *ctx)
{
DrawBoxContext *drawbox = ctx->priv;
DrawBoxContext *s = ctx->priv;
uint8_t rgba_color[4];
if (!strcmp(drawbox->color_str, "invert"))
drawbox->invert_color = 1;
else if (av_parse_color(rgba_color, drawbox->color_str, -1, ctx) < 0)
if (!strcmp(s->color_str, "invert"))
s->invert_color = 1;
else if (av_parse_color(rgba_color, s->color_str, -1, ctx) < 0)
return AVERROR(EINVAL);
if (!drawbox->invert_color) {
drawbox->yuv_color[Y] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
drawbox->yuv_color[U] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
drawbox->yuv_color[V] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
drawbox->yuv_color[A] = rgba_color[3];
if (!s->invert_color) {
s->yuv_color[Y] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
s->yuv_color[U] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
s->yuv_color[V] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
s->yuv_color[A] = rgba_color[3];
}
return 0;
......@@ -81,49 +81,49 @@ static int query_formats(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
{
DrawBoxContext *drawbox = inlink->dst->priv;
DrawBoxContext *s = inlink->dst->priv;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
drawbox->hsub = desc->log2_chroma_w;
drawbox->vsub = desc->log2_chroma_h;
s->hsub = desc->log2_chroma_w;
s->vsub = desc->log2_chroma_h;
if (drawbox->w == 0) drawbox->w = inlink->w;
if (drawbox->h == 0) drawbox->h = inlink->h;
if (s->w == 0) s->w = inlink->w;
if (s->h == 0) s->h = inlink->h;
av_log(inlink->dst, AV_LOG_VERBOSE, "x:%d y:%d w:%d h:%d color:0x%02X%02X%02X%02X\n",
drawbox->x, drawbox->y, drawbox->w, drawbox->h,
drawbox->yuv_color[Y], drawbox->yuv_color[U], drawbox->yuv_color[V], drawbox->yuv_color[A]);
s->x, s->y, s->w, s->h,
s->yuv_color[Y], s->yuv_color[U], s->yuv_color[V], s->yuv_color[A]);
return 0;
}
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
DrawBoxContext *drawbox = inlink->dst->priv;
int plane, x, y, xb = drawbox->x, yb = drawbox->y;
DrawBoxContext *s = inlink->dst->priv;
int plane, x, y, xb = s->x, yb = s->y;
unsigned char *row[4];
for (y = FFMAX(yb, 0); y < frame->height && y < (yb + drawbox->h); y++) {
for (y = FFMAX(yb, 0); y < frame->height && y < (yb + s->h); y++) {
row[0] = frame->data[0] + y * frame->linesize[0];
for (plane = 1; plane < 3; plane++)
row[plane] = frame->data[plane] +
frame->linesize[plane] * (y >> drawbox->vsub);
frame->linesize[plane] * (y >> s->vsub);
if (drawbox->invert_color) {
for (x = FFMAX(xb, 0); x < xb + drawbox->w && x < frame->width; x++)
if ((y - yb < drawbox->thickness-1) || (yb + drawbox->h - y < drawbox->thickness) ||
(x - xb < drawbox->thickness-1) || (xb + drawbox->w - x < drawbox->thickness))
if (s->invert_color) {
for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++)
if ((y - yb < s->thickness-1) || (yb + s->h - y < s->thickness) ||
(x - xb < s->thickness-1) || (xb + s->w - x < s->thickness))
row[0][x] = 0xff - row[0][x];
} else {
for (x = FFMAX(xb, 0); x < xb + drawbox->w && x < frame->width; x++) {
double alpha = (double)drawbox->yuv_color[A] / 255;
if ((y - yb < drawbox->thickness-1) || (yb + drawbox->h - y < drawbox->thickness) ||
(x - xb < drawbox->thickness-1) || (xb + drawbox->w - x < drawbox->thickness)) {
row[0][x ] = (1 - alpha) * row[0][x ] + alpha * drawbox->yuv_color[Y];
row[1][x >> drawbox->hsub] = (1 - alpha) * row[1][x >> drawbox->hsub] + alpha * drawbox->yuv_color[U];
row[2][x >> drawbox->hsub] = (1 - alpha) * row[2][x >> drawbox->hsub] + alpha * drawbox->yuv_color[V];
for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++) {
double alpha = (double)s->yuv_color[A] / 255;
if ((y - yb < s->thickness-1) || (yb + s->h - y < s->thickness) ||
(x - xb < s->thickness-1) || (xb + s->w - x < s->thickness)) {
row[0][x ] = (1 - alpha) * row[0][x ] + alpha * s->yuv_color[Y];
row[1][x >> s->hsub] = (1 - alpha) * row[1][x >> s->hsub] + alpha * s->yuv_color[U];
row[2][x >> s->hsub] = (1 - alpha) * row[2][x >> s->hsub] + alpha * s->yuv_color[V];
}
}
}
......
This diff is collapsed.
......@@ -66,28 +66,28 @@ typedef struct {
static av_cold int init(AVFilterContext *ctx)
{
FadeContext *fade = ctx->priv;
FadeContext *s = ctx->priv;
fade->fade_per_frame = (1 << 16) / fade->nb_frames;
fade->fade_state = VF_FADE_WAITING;
s->fade_per_frame = (1 << 16) / s->nb_frames;
s->fade_state = VF_FADE_WAITING;
if (fade->duration != 0) {
if (s->duration != 0) {
// If duration (seconds) is non-zero, assume that we are not fading based on frames
fade->nb_frames = 0; // Mostly to clean up logging
s->nb_frames = 0; // Mostly to clean up logging
}
// Choose what to log. If both time-based and frame-based options, both lines will be in the log
if (fade->start_frame || fade->nb_frames) {
if (s->start_frame || s->nb_frames) {
av_log(ctx, AV_LOG_VERBOSE,
"type:%s start_frame:%d nb_frames:%d alpha:%d\n",
fade->type == FADE_IN ? "in" : "out", fade->start_frame,
fade->nb_frames,fade->alpha);
s->type == FADE_IN ? "in" : "out", s->start_frame,
s->nb_frames,s->alpha);
}
if (fade->start_time || fade->duration) {
if (s->start_time || s->duration) {
av_log(ctx, AV_LOG_VERBOSE,
"type:%s start_time:%f duration:%f alpha:%d\n",
fade->type == FADE_IN ? "in" : "out", (fade->start_time / (double)AV_TIME_BASE),
(fade->duration / (double)AV_TIME_BASE),fade->alpha);
s->type == FADE_IN ? "in" : "out", (s->start_time / (double)AV_TIME_BASE),
(s->duration / (double)AV_TIME_BASE),s->alpha);
}
return 0;
......@@ -120,22 +120,22 @@ const static enum AVPixelFormat studio_level_pix_fmts[] = {
static int config_props(AVFilterLink *inlink)
{
FadeContext *fade = inlink->dst->priv;
FadeContext *s = inlink->dst->priv;
const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(inlink->format);
fade->hsub = pixdesc->log2_chroma_w;
fade->vsub = pixdesc->log2_chroma_h;
s->hsub = pixdesc->log2_chroma_w;
s->vsub = pixdesc->log2_chroma_h;
fade->bpp = av_get_bits_per_pixel(pixdesc) >> 3;
fade->alpha &= pixdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
fade->is_packed_rgb = ff_fill_rgba_map(fade->rgba_map, inlink->format) >= 0;
s->bpp = av_get_bits_per_pixel(pixdesc) >> 3;
s->alpha &= pixdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
s->is_packed_rgb = ff_fill_rgba_map(s->rgba_map, inlink->format) >= 0;
/* use CCIR601/709 black level for studio-level pixel non-alpha components */
fade->black_level =
ff_fmt_is_in(inlink->format, studio_level_pix_fmts) && !fade->alpha ? 16 : 0;
s->black_level =
ff_fmt_is_in(inlink->format, studio_level_pix_fmts) && !s->alpha ? 16 : 0;
/* 32768 = 1 << 15, it is an integer representation
* of 0.5 and is for rounding. */
fade->black_level_scaled = (fade->black_level << 16) + 32768;
s->black_level_scaled = (s->black_level << 16) + 32768;
return 0;
}
......@@ -151,7 +151,7 @@ static void fade_plane(int y, int h, int w,
for (i = 0; i < h; i++) {
p = data + offset + (y+i) * line_size;
for (j = 0; j < w * bytes_per_plane; j++) {
/* fade->factor is using 16 lower-order bits for decimal places. */
/* s->factor is using 16 lower-order bits for decimal places. */
*p = ((*p - black_level) * fade_factor + black_level_scaled) >> 16;
p+=step;
}
......@@ -160,86 +160,86 @@ static void fade_plane(int y, int h, int w,
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
FadeContext *fade = inlink->dst->priv;
FadeContext *s = inlink->dst->priv;
uint8_t *p;
int i, j, plane;
double frame_timestamp = frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base);
// Calculate Fade assuming this is a Fade In
if (fade->fade_state == VF_FADE_WAITING) {
fade->factor=0;
if ((frame_timestamp >= (fade->start_time/(double)AV_TIME_BASE))
&& (fade->frame_index >= fade->start_frame)) {
if (s->fade_state == VF_FADE_WAITING) {
s->factor=0;
if ((frame_timestamp >= (s->start_time/(double)AV_TIME_BASE))
&& (s->frame_index >= s->start_frame)) {
// Time to start fading
fade->fade_state = VF_FADE_FADING;
s->fade_state = VF_FADE_FADING;
// Save start time in case we are starting based on frames and fading based on time
if ((fade->start_time == 0) && (fade->start_frame != 0)) {
fade->start_time = frame_timestamp*(double)AV_TIME_BASE;
if ((s->start_time == 0) && (s->start_frame != 0)) {
s->start_time = frame_timestamp*(double)AV_TIME_BASE;
}
// Save start frame in case we are starting based on time and fading based on frames
if ((fade->start_time != 0) && (fade->start_frame == 0)) {
fade->start_frame = fade->frame_index;
if ((s->start_time != 0) && (s->start_frame == 0)) {
s->start_frame = s->frame_index;
}
}
}
if (fade->fade_state == VF_FADE_FADING) {
if (fade->duration == 0) {
if (s->fade_state == VF_FADE_FADING) {
if (s->duration == 0) {
// Fading based on frame count
fade->factor = (fade->frame_index - fade->start_frame) * fade->fade_per_frame;
if (fade->frame_index > (fade->start_frame + fade->nb_frames)) {
fade->fade_state = VF_FADE_DONE;
s->factor = (s->frame_index - s->start_frame) * s->fade_per_frame;
if (s->frame_index > (s->start_frame + s->nb_frames)) {
s->fade_state = VF_FADE_DONE;
}
} else {
// Fading based on duration
fade->factor = (frame_timestamp - (fade->start_time/(double)AV_TIME_BASE))
* (float) UINT16_MAX / (fade->duration/(double)AV_TIME_BASE);
if (frame_timestamp > ((fade->start_time/(double)AV_TIME_BASE)
+ (fade->duration/(double)AV_TIME_BASE))) {
fade->fade_state = VF_FADE_DONE;
s->factor = (frame_timestamp - (s->start_time/(double)AV_TIME_BASE))
* (float) UINT16_MAX / (s->duration/(double)AV_TIME_BASE);
if (frame_timestamp > ((s->start_time/(double)AV_TIME_BASE)
+ (s->duration/(double)AV_TIME_BASE))) {
s->fade_state = VF_FADE_DONE;
}
}
}
if (fade->fade_state == VF_FADE_DONE) {
fade->factor=UINT16_MAX;
if (s->fade_state == VF_FADE_DONE) {
s->factor=UINT16_MAX;
}
fade->factor = av_clip_uint16(fade->factor);
s->factor = av_clip_uint16(s->factor);
// Invert fade_factor if Fading Out
if (fade->type == 1) {
fade->factor=UINT16_MAX-fade->factor;
if (s->type == 1) {
s->factor=UINT16_MAX-s->factor;
}
if (fade->factor < UINT16_MAX) {
if (fade->alpha) {
if (s->factor < UINT16_MAX) {
if (s->alpha) {
// alpha only
plane = fade->is_packed_rgb ? 0 : A; // alpha is on plane 0 for packed formats
plane = s->is_packed_rgb ? 0 : A; // alpha is on plane 0 for packed formats
// or plane 3 for planar formats
fade_plane(0, frame->height, inlink->w,
fade->factor, fade->black_level, fade->black_level_scaled,
fade->is_packed_rgb ? fade->rgba_map[A] : 0, // alpha offset for packed formats
fade->is_packed_rgb ? 4 : 1, // pixstep for 8 bit packed formats
s->factor, s->black_level, s->black_level_scaled,
s->is_packed_rgb ? s->rgba_map[A] : 0, // alpha offset for packed formats
s->is_packed_rgb ? 4 : 1, // pixstep for 8 bit packed formats
1, frame->data[plane], frame->linesize[plane]);
} else {
/* luma or rgb plane */
fade_plane(0, frame->height, inlink->w,
fade->factor, fade->black_level, fade->black_level_scaled,
s->factor, s->black_level, s->black_level_scaled,
0, 1, // offset & pixstep for Y plane or RGB packed format
fade->bpp, frame->data[0], frame->linesize[0]);
s->bpp, frame->data[0], frame->linesize[0]);
if (frame->data[1] && frame->data[2]) {
/* chroma planes */
for (plane = 1; plane < 3; plane++) {
for (i = 0; i < frame->height; i++) {
const int width = FF_CEIL_RSHIFT(inlink->w, fade->hsub);
p = frame->data[plane] + (i >> fade->vsub) * frame->linesize[plane];
const int width = FF_CEIL_RSHIFT(inlink->w, s->hsub);
p = frame->data[plane] + (i >> s->vsub) * frame->linesize[plane];
for (j = 0; j < width; j++) {
/* 8421367 = ((128 << 1) + 1) << 15. It is an integer
* representation of 128.5. The .5 is for rounding
* purposes. */
*p = ((*p - 128) * fade->factor + 8421367) >> 16;
*p = ((*p - 128) * s->factor + 8421367) >> 16;
p++;
}
}
......@@ -248,7 +248,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
}
}
fade->frame_index++;
s->frame_index++;
return ff_filter_frame(inlink->dst->outputs[0], frame);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment