Re: [FFmpeg-devel] [PATCH] avfilter: add colortemperature filter

2021-01-27 Thread Michael Niedermayer
On Tue, Jan 26, 2021 at 12:16:31PM +0100, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi  |  22 +++
>  libavfilter/Makefile  |   1 +
>  libavfilter/allfilters.c  |   1 +
>  libavfilter/vf_colortemperature.c | 280 ++
>  4 files changed, 304 insertions(+)
>  create mode 100644 libavfilter/vf_colortemperature.c

This breaks build on arm

In file included from src/libavutil/intmath.h:30:0,
 from src/libavutil/common.h:114,
 from src/libavutil/avutil.h:296,
 from src/libavutil/opt.h:31,
 from src/libavfilter/vf_colortemperature.c:23:
src/libavutil/arm/intmath.h: In function ‘temperature_slice16’:
src/libavutil/arm/intmath.h:77:5: warning: asm operand 2 probably doesn’t match 
constraints
 __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
 ^~~
src/libavutil/arm/intmath.h:77:5: warning: asm operand 2 probably doesn’t match 
constraints
 __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
 ^~~
src/libavutil/arm/intmath.h:77:5: warning: asm operand 2 probably doesn’t match 
constraints
 __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
 ^~~
src/libavutil/arm/intmath.h:77:5: error: impossible constraint in ‘asm’
 __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
 ^~~
src/libavutil/arm/intmath.h:77:5: error: impossible constraint in ‘asm’
 __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
 ^~~
src/libavutil/arm/intmath.h:77:5: error: impossible constraint in ‘asm’
 __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
 ^~~
src/ffbuild/common.mak:67: recipe for target 
'libavfilter/vf_colortemperature.o' failed
make: *** [libavfilter/vf_colortemperature.o] Error 1
make: *** Waiting for unfinished jobs



[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety -- Benjamin Franklin


signature.asc
Description: PGP signature
___
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] avfilter: add colortemperature filter

2021-01-26 Thread Reto Kromer
Paul B Mahol wrote:

>+@item temperature
>+Set the temperature in Kelvins. Allowed range is from 1000 to 4.
>+Default value is 6500 K.

I would use the singular "Kelvin", otherwise LGTM.

___
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] avfilter: add colortemperature filter

2021-01-26 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi  |  22 +++
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_colortemperature.c | 280 ++
 4 files changed, 304 insertions(+)
 create mode 100644 libavfilter/vf_colortemperature.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 991f8d62c0..2a994e110b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8549,6 +8549,28 @@ For example to convert the input to SMPTE-240M, use the 
command:
 colorspace=smpte240m
 @end example
 
+@section colortemperature
+Adjust color temperature in video to simulate variations in ambient color 
temperature.
+
+The filter accepts the following options:
+
+@table @option
+@item temperature
+Set the temperature in Kelvins. Allowed range is from 1000 to 4.
+Default value is 6500 K.
+
+@item mix
+Set mixing with filtered output. Allowed range is from 0 to 1.
+Default value is 1.
+
+@item pl
+Set the amount of preserving lightness. Allowed range is from 0 to 1.
+Default value is 0.
+@end table
+
+@subsection Commands
+This filter supports same @ref{commands} as options.
+
 @section convolution
 
 Apply convolution of 3x3, 5x5, 7x7 or horizontal/vertical up to 49 elements.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index fbb4e29bd0..e1c364fbc6 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -203,6 +203,7 @@ OBJS-$(CONFIG_COLORHOLD_FILTER)  += 
vf_colorkey.o
 OBJS-$(CONFIG_COLORLEVELS_FILTER)+= vf_colorlevels.o
 OBJS-$(CONFIG_COLORMATRIX_FILTER)+= vf_colormatrix.o
 OBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o colorspace.o 
colorspacedsp.o
+OBJS-$(CONFIG_COLORTEMPERATURE_FILTER)   += vf_colortemperature.o
 OBJS-$(CONFIG_CONVOLUTION_FILTER)+= vf_convolution.o
 OBJS-$(CONFIG_CONVOLUTION_OPENCL_FILTER) += vf_convolution_opencl.o 
opencl.o \
 opencl/convolution.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index d9d36554c4..1c1cc5b276 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -192,6 +192,7 @@ extern AVFilter ff_vf_colorhold;
 extern AVFilter ff_vf_colorlevels;
 extern AVFilter ff_vf_colormatrix;
 extern AVFilter ff_vf_colorspace;
+extern AVFilter ff_vf_colortemperature;
 extern AVFilter ff_vf_convolution;
 extern AVFilter ff_vf_convolution_opencl;
 extern AVFilter ff_vf_convolve;
diff --git a/libavfilter/vf_colortemperature.c 
b/libavfilter/vf_colortemperature.c
new file mode 100644
index 00..11ab1d0cce
--- /dev/null
+++ b/libavfilter/vf_colortemperature.c
@@ -0,0 +1,280 @@
+/*
+ * Copyright (c) 2021 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * 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.
+ *
+ * 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct ColorTemperatureContext {
+const AVClass *class;
+
+float temperature;
+float mix;
+float preserve;
+
+float color[3];
+
+int depth;
+
+int (*do_slice)(AVFilterContext *s, void *arg,
+int jobnr, int nb_jobs);
+} ColorTemperatureContext;
+
+static float saturate(float input)
+{
+return av_clipf(input, 0.f, 1.f);
+}
+
+static void kelvin2rgb(float k, float *rgb)
+{
+float kelvin = k / 100.0f;
+
+if (kelvin <= 66.0f) {
+rgb[0] = 1.0f;
+rgb[1] = saturate(0.39008157876901960784f * logf(kelvin) - 
0.63184144378862745098f);
+} else {
+const float t = fmaxf(kelvin - 60.0f, 0.0f);
+rgb[0] = saturate(1.29293618606274509804f * powf(t, -0.1332047592f));
+rgb[1] = saturate(1.12989086089529411765f * powf(t, -0.0755148492f));
+}
+
+if (kelvin >= 66.0f)
+rgb[2] = 1.0f;
+else if (kelvin <= 19.0f)
+rgb[2] = 0.0f;
+else
+rgb[2] = saturate(0.54320678911019607843f * logf(kelvin - 10.0f) - 
1.19625408914f);
+}
+
+static float lerpf(float v0, float v1, float f)
+{
+return v0 + (v1 - v0) * f;
+}
+
+static int temperature_slice8(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+ColorTemperatureContext *s = ctx->priv;
+AVFrame