more template action
This commit is contained in:
parent
a96b3a1a9c
commit
a202604c32
|
@ -48,8 +48,9 @@ typedef struct ColorizeLSDContext {
|
|||
int planeheight[4];
|
||||
|
||||
// ptr to multithreaded functions
|
||||
// one function for the y plane one for uv
|
||||
int (*do_plane_slice[2])(AVFilterContext *s, void *arg,
|
||||
int jobnr, int nb_jobs);
|
||||
int jobnr, int nb_jobs, int plane);
|
||||
} ColorizeLSDContext;
|
||||
|
||||
} // extern c
|
||||
|
@ -61,56 +62,30 @@ static inline float lerpf(float v0, float v1, float f)
|
|||
|
||||
|
||||
// luminance slices
|
||||
template<typename T>
|
||||
static int colorizey_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
template<typename T, bool color>
|
||||
static int colorize_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int plane)
|
||||
{
|
||||
ColorizeLSDContext *s = (ColorizeLSDContext *) ctx->priv;
|
||||
AVFrame *frame = (AVFrame *) arg;
|
||||
const int width = s->planewidth[0];
|
||||
const int height = s->planeheight[0];
|
||||
const int width = s->planewidth[color]; // plane 1 & 2 are the same size
|
||||
const int height = s->planeheight[color];
|
||||
const int slice_start = (height * jobnr) / nb_jobs;
|
||||
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
|
||||
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;
|
||||
|
||||
for (int y = slice_start; y < slice_end; y++) {
|
||||
for (int x = 0; x < width; x++)
|
||||
yptr[x] = lerpf(yv, yptr[x], mix);
|
||||
const float mix = color ? s->mixcolor : s->mix;
|
||||
|
||||
yptr += ylinesize;
|
||||
}
|
||||
const int linesize = frame->linesize[plane] / sizeof(T);
|
||||
|
||||
return 0;
|
||||
}
|
||||
T *ptr = (T*) frame->data[plane] + slice_start * linesize;
|
||||
|
||||
// color slices
|
||||
template<typename T>
|
||||
static int colorize_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||
{
|
||||
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] / 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;
|
||||
const int c = s->c[plane]; // planes color component of target color
|
||||
|
||||
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);
|
||||
ptr[x] = lerpf(c, ptr[x], mix);
|
||||
}
|
||||
|
||||
uptr += ulinesize;
|
||||
vptr += vlinesize;
|
||||
ptr += linesize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -122,8 +97,9 @@ static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
|||
{
|
||||
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);
|
||||
s->do_plane_slice[0](ctx, arg, jobnr, nb_jobs, 0); // y plane
|
||||
s->do_plane_slice[1](ctx, arg, jobnr, nb_jobs, 1); // u plane
|
||||
s->do_plane_slice[1](ctx, arg, jobnr, nb_jobs, 2); // v plane
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -219,8 +195,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_slice<uint8_t> : colorizey_slice<uint16_t>;
|
||||
s->do_plane_slice[1] = depth <= 8 ? colorize_slice<uint8_t> : colorize_slice<uint16_t>;
|
||||
s->do_plane_slice[0] = depth <= 8 ? colorize_slice<uint8_t, false> : colorize_slice<uint16_t, false>;
|
||||
s->do_plane_slice[1] = depth <= 8 ? colorize_slice<uint8_t, true> : colorize_slice<uint16_t, true>;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue