Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_lut3d: prelut support for 3d cinespace luts

2020-05-22 Thread Paul B Mahol
On 5/22/20, Mark Reid  wrote:
> On Thu, May 21, 2020 at 8:14 AM Paul B Mahol  wrote:
>
>> Probably ok, except code style.
>> Please keep code style consistent across files.
>>
>
> Thanks a lot for the feedback. I see a few inconsistently named variables,
> maybe I used too many spaces in places.  Could you tell me where is it that
> you have the most issue with? Did I name functions incorrectly or put them
> in bad locations?

Not enough spaces:

if()

should be

if ()

>
>
>> On 5/19/20, mindm...@gmail.com  wrote:
>> > From: Mark Reid 
>> >
>> > ---
>> >  libavfilter/vf_lut3d.c | 367 +++--
>> >  1 file changed, 312 insertions(+), 55 deletions(-)
>> >
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_lut3d: prelut support for 3d cinespace luts

2020-05-21 Thread Mark Reid
On Thu, May 21, 2020 at 8:14 AM Paul B Mahol  wrote:

> Probably ok, except code style.
> Please keep code style consistent across files.
>

Thanks a lot for the feedback. I see a few inconsistently named variables,
maybe I used too many spaces in places.  Could you tell me where is it that
you have the most issue with? Did I name functions incorrectly or put them
in bad locations?


> On 5/19/20, mindm...@gmail.com  wrote:
> > From: Mark Reid 
> >
> > ---
> >  libavfilter/vf_lut3d.c | 367 +++--
> >  1 file changed, 312 insertions(+), 55 deletions(-)
> >
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_lut3d: prelut support for 3d cinespace luts

2020-05-21 Thread Paul B Mahol
Probably ok, except code style.
Please keep code style consistent across files.

On 5/19/20, mindm...@gmail.com  wrote:
> From: Mark Reid 
>
> ---
>  libavfilter/vf_lut3d.c | 367 +++--
>  1 file changed, 312 insertions(+), 55 deletions(-)
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/2] avfilter/vf_lut3d: prelut support for 3d cinespace luts

2020-05-18 Thread mindmark
From: Mark Reid 

---
 libavfilter/vf_lut3d.c | 367 +++--
 1 file changed, 312 insertions(+), 55 deletions(-)

diff --git a/libavfilter/vf_lut3d.c b/libavfilter/vf_lut3d.c
index 482e2394a7..4067c4a60a 100644
--- a/libavfilter/vf_lut3d.c
+++ b/libavfilter/vf_lut3d.c
@@ -59,6 +59,15 @@ struct rgbvec {
 /* 3D LUT don't often go up to level 32, but it is common to have a Hald CLUT
  * of 512x512 (64x64x64) */
 #define MAX_LEVEL 256
+#define PRELUT_SIZE 65536
+
+typedef struct Lut3DPreLut {
+int size;
+float min[3];
+float max[3];
+float scale[3];
+float* lut[3];
+} Lut3DPreLut;
 
 typedef struct LUT3DContext {
 const AVClass *class;
@@ -71,6 +80,7 @@ typedef struct LUT3DContext {
 struct rgbvec *lut;
 int lutsize;
 int lutsize2;
+Lut3DPreLut prelut;
 #if CONFIG_HALDCLUT_FILTER
 uint8_t clut_rgba_map[4];
 int clut_step;
@@ -234,6 +244,31 @@ static inline struct rgbvec interp_tetrahedral(const 
LUT3DContext *lut3d,
 return c;
 }
 
+static inline float apply_prelut_channel(const LUT3DContext *lut3d, float x, 
int c)
+{
+
+x = (x - lut3d->prelut.min[c]) * lut3d->prelut.scale[c];
+x = av_clipf(x, 0.0f, lut3d->prelut.size-1);
+
+const float a = lut3d->prelut.lut[c][PREV(x)];
+const float b = lut3d->prelut.lut[c][(FFMIN((int)(x) + 1, 
lut3d->prelut.size - 1))];
+const float mix = x - (float)PREV(x);
+
+return lerpf(a, b, mix);
+}
+
+static inline struct rgbvec apply_prelut(const LUT3DContext *lut3d, const 
struct rgbvec *s)
+{
+if (lut3d->prelut.size <= 0)
+return *s;
+
+struct rgbvec c;
+c.r = apply_prelut_channel(lut3d, s->r, 0);
+c.g = apply_prelut_channel(lut3d, s->g, 1);
+c.b = apply_prelut_channel(lut3d, s->b, 2);
+return c;
+}
+
 #define DEFINE_INTERP_FUNC_PLANAR(name, nbits, depth)  
\
 static int interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs) \
 {  
\
@@ -253,9 +288,11 @@ static int 
interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, i
 const uint8_t *srcbrow = in->data[1] + slice_start * in->linesize[1];  
\
 const uint8_t *srcrrow = in->data[2] + slice_start * in->linesize[2];  
\
 const uint8_t *srcarow = in->data[3] + slice_start * in->linesize[3];  
\
-const float scale_r = (lut3d->scale.r / ((1scale.g / ((1scale.b / ((1lutsize - 1;  
\
+const float scale_f = 1.0f / ((1scale.g * lut_max;
\
+const float scale_b = lut3d->scale.b * lut_max;
\

\
 for (y = slice_start; y < slice_end; y++) {
\
 uint##nbits##_t *dstg = (uint##nbits##_t *)grow;   
\
@@ -267,9 +304,13 @@ static int 
interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, i
 const uint##nbits##_t *srcr = (const uint##nbits##_t *)srcrrow;
\
 const uint##nbits##_t *srca = (const uint##nbits##_t *)srcarow;
\
 for (x = 0; x < in->width; x++) {  
\
-const struct rgbvec scaled_rgb = {srcr[x] * scale_r,   
\
-  srcg[x] * scale_g,   
\
-  srcb[x] * scale_b};  
\
+const struct rgbvec rgb = {srcr[x] * scale_f,  
\
+   srcg[x] * scale_f,  
\
+   srcb[x] * scale_f}; 
\
+const struct rgbvec prelut_rgb = apply_prelut(lut3d, &rgb);
\
+const struct rgbvec scaled_rgb = {av_clipf(prelut_rgb.r * scale_r, 
0, lut_max),\
+  av_clipf(prelut_rgb.g * scale_g, 
0, lut_max),\
+  av_clipf(prelut_rgb.b *