colorizelsd to cpp
This commit is contained in:
parent
7af344b2a4
commit
a96b3a1a9c
|
@ -16,6 +16,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include "libavutil/opt.h"
|
||||
#include "libavutil/imgutils.h"
|
||||
#include "avfilter.h"
|
||||
|
@ -23,8 +25,12 @@
|
|||
#include "internal.h"
|
||||
#include "video.h"
|
||||
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
typedef struct ColorizeLSDContext {
|
||||
const AVClass *class;
|
||||
const AVClass *classs;
|
||||
|
||||
// user input
|
||||
float speed;
|
||||
|
@ -46,6 +52,8 @@ typedef struct ColorizeLSDContext {
|
|||
int jobnr, int nb_jobs);
|
||||
} ColorizeLSDContext;
|
||||
|
||||
} // extern c
|
||||
|
||||
static inline float lerpf(float v0, float v1, float f)
|
||||
{
|
||||
return v0 + (v1 - v0) * f;
|
||||
|
@ -53,39 +61,17 @@ static inline float lerpf(float v0, float v1, float f)
|
|||
|
||||
|
||||
// luminance slices
|
||||
static int colorizey_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
template<typename T>
|
||||
static int colorizey_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
{
|
||||
ColorizeLSDContext *s = ctx->priv;
|
||||
AVFrame *frame = arg;
|
||||
ColorizeLSDContext *s = (ColorizeLSDContext *) ctx->priv;
|
||||
AVFrame *frame = (AVFrame *) arg;
|
||||
const int width = s->planewidth[0];
|
||||
const int height = s->planeheight[0];
|
||||
const int slice_start = (height * jobnr) / nb_jobs;
|
||||
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
|
||||
const int ylinesize = frame->linesize[0];
|
||||
uint8_t *yptr = frame->data[0] + slice_start * ylinesize;
|
||||
const int yv = s->c[0];
|
||||
const float mix = s->mix;
|
||||
|
||||
for (int y = slice_start; y < slice_end; y++) {
|
||||
for (int x = 0; x < width; x++)
|
||||
yptr[x] = lerpf(yv, yptr[x], mix);
|
||||
|
||||
yptr += ylinesize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int colorizey_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
{
|
||||
ColorizeLSDContext *s = ctx->priv;
|
||||
AVFrame *frame = arg;
|
||||
const int width = s->planewidth[0];
|
||||
const int height = s->planeheight[0];
|
||||
const int slice_start = (height * jobnr) / nb_jobs;
|
||||
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
|
||||
const int ylinesize = frame->linesize[0] / 2;
|
||||
uint16_t *yptr = (uint16_t *)frame->data[0] + slice_start * ylinesize;
|
||||
const int ylinesize = frame->linesize[0] / (sizeof(T));
|
||||
T *yptr = (T*) frame->data[0] + slice_start * ylinesize;
|
||||
const int yv = s->c[0];
|
||||
const float mix = s->mix;
|
||||
|
||||
|
@ -100,18 +86,19 @@ static int colorizey_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_
|
|||
}
|
||||
|
||||
// color slices
|
||||
static int colorize_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
template<typename T>
|
||||
static int colorize_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
{
|
||||
ColorizeLSDContext *s = ctx->priv;
|
||||
AVFrame *frame = arg;
|
||||
ColorizeLSDContext *s = (ColorizeLSDContext *) ctx->priv;
|
||||
AVFrame *frame = (AVFrame *) arg;
|
||||
const int width = s->planewidth[1];
|
||||
const int height = s->planeheight[1];
|
||||
const int slice_start = (height * jobnr) / nb_jobs;
|
||||
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
|
||||
const int ulinesize = frame->linesize[1];
|
||||
const int vlinesize = frame->linesize[2];
|
||||
uint8_t *uptr = frame->data[1] + slice_start * ulinesize;
|
||||
uint8_t *vptr = frame->data[2] + slice_start * vlinesize;
|
||||
const int ulinesize = frame->linesize[1] / sizeof(T);
|
||||
const int vlinesize = frame->linesize[2] / sizeof(T);
|
||||
T *uptr = (T*) frame->data[1] + slice_start * ulinesize;
|
||||
T *vptr = (T*) frame->data[2] + slice_start * vlinesize;
|
||||
const int u = s->c[1];
|
||||
const int v = s->c[2];
|
||||
const float mixcolor = s->mixcolor;
|
||||
|
@ -129,38 +116,11 @@ static int colorize_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int colorize_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
{
|
||||
ColorizeLSDContext *s = ctx->priv;
|
||||
AVFrame *frame = arg;
|
||||
const int width = s->planewidth[1];
|
||||
const int height = s->planeheight[1];
|
||||
const int slice_start = (height * jobnr) / nb_jobs;
|
||||
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
|
||||
const int ulinesize = frame->linesize[1] / 2;
|
||||
const int vlinesize = frame->linesize[2] / 2;
|
||||
uint16_t *uptr = (uint16_t *)frame->data[1] + slice_start * ulinesize;
|
||||
uint16_t *vptr = (uint16_t *)frame->data[2] + slice_start * vlinesize;
|
||||
const int u = s->c[1];
|
||||
const int v = s->c[2];
|
||||
const float mixcolor = s->mixcolor;
|
||||
|
||||
for (int y = slice_start; y < slice_end; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
uptr[x] = lerpf(u, uptr[x], mixcolor);
|
||||
vptr[x] = lerpf(v, vptr[x], mixcolor);
|
||||
}
|
||||
|
||||
uptr += ulinesize;
|
||||
vptr += vlinesize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
extern "C" {
|
||||
|
||||
static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
{
|
||||
ColorizeLSDContext *s = ctx->priv;
|
||||
ColorizeLSDContext *s = (ColorizeLSDContext *) ctx->priv;
|
||||
|
||||
s->do_plane_slice[0](ctx, arg, jobnr, nb_jobs);
|
||||
s->do_plane_slice[1](ctx, arg, jobnr, nb_jobs);
|
||||
|
@ -208,8 +168,8 @@ static void rgb2yuv(float r, float g, float b, int *y, int *u, int *v, int depth
|
|||
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
||||
{
|
||||
double timebase = av_q2d(inlink->time_base);
|
||||
AVFilterContext *ctx = inlink->dst;
|
||||
ColorizeLSDContext *s = ctx->priv;
|
||||
AVFilterContext *ctx = (AVFilterContext *) inlink->dst;
|
||||
ColorizeLSDContext *s = (ColorizeLSDContext *) ctx->priv;
|
||||
float c[3]; // temp rgb
|
||||
|
||||
double time = timebase * frame->pts;
|
||||
|
@ -247,9 +207,9 @@ static const enum AVPixelFormat pixel_fmts[] = {
|
|||
|
||||
static av_cold int config_input(AVFilterLink *inlink)
|
||||
{
|
||||
AVFilterContext *ctx = inlink->dst;
|
||||
ColorizeLSDContext *s = ctx->priv;
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
|
||||
AVFilterContext *ctx = (AVFilterContext *) inlink->dst;
|
||||
ColorizeLSDContext *s = (ColorizeLSDContext *) ctx->priv;
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get((AVPixelFormat) inlink->format);
|
||||
int depth;
|
||||
|
||||
s->depth = depth = desc->comp[0].depth;
|
||||
|
@ -259,8 +219,8 @@ static av_cold int config_input(AVFilterLink *inlink)
|
|||
s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
|
||||
s->planeheight[0] = s->planeheight[3] = inlink->h;
|
||||
|
||||
s->do_plane_slice[0] = depth <= 8 ? colorizey_slice8 : colorizey_slice16;
|
||||
s->do_plane_slice[1] = depth <= 8 ? colorize_slice8 : colorize_slice16;
|
||||
s->do_plane_slice[0] = depth <= 8 ? colorizey_slice<uint8_t> : colorizey_slice<uint16_t>;
|
||||
s->do_plane_slice[1] = depth <= 8 ? colorize_slice<uint8_t> : colorize_slice<uint16_t>;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -297,14 +257,30 @@ static const AVOption colorizelsd_options[] = {
|
|||
|
||||
AVFILTER_DEFINE_CLASS(colorizelsd);
|
||||
|
||||
const AVFilter ff_vf_colorizelsd = {
|
||||
extern "C" const AVFilter ff_vf_colorizelsd = {
|
||||
.name = "colorizelsd",
|
||||
.description = NULL_IF_CONFIG_SMALL("Overlay a color change on the video stream."),
|
||||
.priv_size = sizeof(ColorizeLSDContext),
|
||||
.priv_class = &colorizelsd_class,
|
||||
FILTER_INPUTS(colorizelsd_inputs),
|
||||
FILTER_OUTPUTS(colorizelsd_outputs),
|
||||
FILTER_PIXFMTS_ARRAY(pixel_fmts),
|
||||
// FILTER_INPUTS(colorizelsd_inputs),
|
||||
// FILTER_OUTPUTS(colorizelsd_outputs),
|
||||
.inputs = colorizelsd_inputs,
|
||||
.outputs = colorizelsd_outputs,
|
||||
.priv_class = &colorizelsd_class,
|
||||
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
|
||||
.nb_inputs = 1,
|
||||
.nb_outputs = 1,
|
||||
.formats_state = FF_FILTER_FORMATS_PIXFMT_LIST,
|
||||
|
||||
// preinit
|
||||
// init
|
||||
// init_dict
|
||||
// uninit
|
||||
|
||||
.formats = { .pixels_list = pixel_fmts },
|
||||
.priv_size = sizeof(ColorizeLSDContext),
|
||||
|
||||
// FILTER_PIXFMTS_ARRAY(pixel_fmts),
|
||||
.process_command = NULL, // ff_filter_process_command
|
||||
|
||||
// activate
|
||||
};
|
||||
} // extern c
|
Loading…
Reference in New Issue