summaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_fade.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavfilter/vf_fade.c')
-rw-r--r--libavfilter/vf_fade.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c
index 0c8668c..5032019 100644
--- a/libavfilter/vf_fade.c
+++ b/libavfilter/vf_fade.c
@@ -2,20 +2,20 @@
* Copyright (c) 2010 Brandon Mintern
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,11 +27,13 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
+#include "internal.h"
typedef struct {
int factor, fade_per_frame;
unsigned int frame_index, start_frame, stop_frame;
int hsub, vsub, bpp;
+ unsigned int black_level, black_level_scaled;
} FadeContext;
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
@@ -78,10 +80,17 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
+const static enum PixelFormat studio_level_pix_fmts[] = {
+ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P,
+ PIX_FMT_YUV411P, PIX_FMT_YUV410P,
+ PIX_FMT_YUV440P,
+ PIX_FMT_NONE
+};
+
static int config_props(AVFilterLink *inlink)
{
FadeContext *fade = inlink->dst->priv;
@@ -91,6 +100,11 @@ static int config_props(AVFilterLink *inlink)
fade->vsub = pixdesc->log2_chroma_h;
fade->bpp = av_get_bits_per_pixel(pixdesc) >> 3;
+
+ fade->black_level = ff_fmt_is_in(inlink->format, studio_level_pix_fmts) ? 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;
return 0;
}
@@ -106,10 +120,8 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
for (i = 0; i < h; i++) {
p = outpic->data[0] + (y+i) * outpic->linesize[0];
for (j = 0; j < inlink->w * fade->bpp; j++) {
- /* fade->factor is using 16 lower-order bits for decimal
- * places. 32768 = 1 << 15, it is an integer representation
- * of 0.5 and is for rounding. */
- *p = (*p * fade->factor + 32768) >> 16;
+ /* fade->factor is using 16 lower-order bits for decimal places. */
+ *p = ((*p - fade->black_level) * fade->factor + fade->black_level_scaled) >> 16;
p++;
}
}
OpenPOWER on IntegriCloud