diff mbox series

[FFmpeg-devel,4/6] avcodec: add common fflcms2 boilerplate

Message ID 20220628134110.87770-5-ffmpeg@haasn.xyz
State New
Headers show
Series [FFmpeg-devel,1/6] fflcms2: move to libavcodec | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 fail Make failed
andriy/make_x86 fail Make failed

Commit Message

Niklas Haas June 28, 2022, 1:41 p.m. UTC
From: Niklas Haas <git@haasn.dev>

Handling this in general code makes more sense than handling it in
individual codec files, because it would be a lot of unnecessary code
duplication for the plenty of formats that support exporting ICC
profiles (jpg, png, tiff, webp, jxl, ...).

encode.c and decode.c will be in charge of initializing this state as
needed, so we merely need to make sure to uninit it afterwards from the
common destructor path.

Signed-off-by: Niklas Haas <git@haasn.dev>
---
 configure             | 2 +-
 libavcodec/Makefile   | 1 +
 libavcodec/avcodec.c  | 4 ++++
 libavcodec/decode.c   | 4 ++++
 libavcodec/internal.h | 8 ++++++++
 5 files changed, 18 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer June 28, 2022, 7:57 p.m. UTC | #1
On Tue, Jun 28, 2022 at 03:41:09PM +0200, Niklas Haas wrote:
> From: Niklas Haas <git@haasn.dev>
> 
> Handling this in general code makes more sense than handling it in
> individual codec files, because it would be a lot of unnecessary code
> duplication for the plenty of formats that support exporting ICC
> profiles (jpg, png, tiff, webp, jxl, ...).
> 
> encode.c and decode.c will be in charge of initializing this state as
> needed, so we merely need to make sure to uninit it afterwards from the
> common destructor path.
> 
> Signed-off-by: Niklas Haas <git@haasn.dev>
> ---
>  configure             | 2 +-
>  libavcodec/Makefile   | 1 +
>  libavcodec/avcodec.c  | 4 ++++
>  libavcodec/decode.c   | 4 ++++
>  libavcodec/internal.h | 8 ++++++++
>  5 files changed, 18 insertions(+), 1 deletion(-)

doesnt build here: (ubuntu x86)
CC	libavformat/4xm.o
In file included from ./libavcodec/internal.h:37:0,
                 from libavformat/4xm.c:32:
./libavcodec/fflcms2.h:32:10: fatal error: lcms2.h: No such file or directory
 #include <lcms2.h>
          ^~~~~~~~~
compilation terminated.
ffbuild/common.mak:81: recipe for target 'libavformat/4xm.o' failed
make: *** [libavformat/4xm.o] Error 1

thx

[...]
Andreas Rheinhardt June 28, 2022, 8:03 p.m. UTC | #2
Michael Niedermayer:
> On Tue, Jun 28, 2022 at 03:41:09PM +0200, Niklas Haas wrote:
>> From: Niklas Haas <git@haasn.dev>
>>
>> Handling this in general code makes more sense than handling it in
>> individual codec files, because it would be a lot of unnecessary code
>> duplication for the plenty of formats that support exporting ICC
>> profiles (jpg, png, tiff, webp, jxl, ...).
>>
>> encode.c and decode.c will be in charge of initializing this state as
>> needed, so we merely need to make sure to uninit it afterwards from the
>> common destructor path.
>>
>> Signed-off-by: Niklas Haas <git@haasn.dev>
>> ---
>>  configure             | 2 +-
>>  libavcodec/Makefile   | 1 +
>>  libavcodec/avcodec.c  | 4 ++++
>>  libavcodec/decode.c   | 4 ++++
>>  libavcodec/internal.h | 8 ++++++++
>>  5 files changed, 18 insertions(+), 1 deletion(-)
> 
> doesnt build here: (ubuntu x86)
> CC	libavformat/4xm.o
> In file included from ./libavcodec/internal.h:37:0,
>                  from libavformat/4xm.c:32:
> ./libavcodec/fflcms2.h:32:10: fatal error: lcms2.h: No such file or directory
>  #include <lcms2.h>
>           ^~~~~~~~~
> compilation terminated.
> ffbuild/common.mak:81: recipe for target 'libavformat/4xm.o' failed
> make: *** [libavformat/4xm.o] Error 1
> 

He uses

+#ifdef CONFIG_LCMS2
+# include "fflcms2.h"
+#endif

where he should use #if as we unconditionally add the CONFIG_* defines
to config.h and config_components.h.
(This has already been mentioned on IRC; the "if (trc =
AVCOL_TRC_UNSPECIFIED)" in 6/6 has also been mentioned there.)

- Andreas
diff mbox series

Patch

diff --git a/configure b/configure
index 0de9b2abcb..d3f151e246 100755
--- a/configure
+++ b/configure
@@ -3807,7 +3807,7 @@  swresample_suggest="libm libsoxr stdatomic"
 swscale_deps="avutil"
 swscale_suggest="libm stdatomic"
 
-avcodec_extralibs="pthreads_extralibs iconv_extralibs dxva2_extralibs"
+avcodec_extralibs="pthreads_extralibs iconv_extralibs dxva2_extralibs lcms2_extralibs"
 avfilter_extralibs="pthreads_extralibs"
 avutil_extralibs="d3d11va_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vaapi_x11_extralibs vdpau_x11_extralibs"
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5c4f62c631..d2f969ba52 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -114,6 +114,7 @@  OBJS-$(CONFIG_INTRAX8)                 += intrax8.o intrax8dsp.o msmpeg4data.o
 OBJS-$(CONFIG_IVIDSP)                  += ivi_dsp.o
 OBJS-$(CONFIG_JNI)                     += ffjni.o jni.o
 OBJS-$(CONFIG_JPEGTABLES)              += jpegtables.o
+OBJS-$(CONFIG_LCMS2)                   += fflcms2.o
 OBJS-$(CONFIG_LLAUDDSP)                += lossless_audiodsp.o
 OBJS-$(CONFIG_LLVIDDSP)                += lossless_videodsp.o
 OBJS-$(CONFIG_LLVIDENCDSP)             += lossless_videoencdsp.o
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 5f6e71a39e..3524214546 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -481,6 +481,10 @@  av_cold int avcodec_close(AVCodecContext *avctx)
 
         av_channel_layout_uninit(&avci->initial_ch_layout);
 
+#if CONFIG_LCMS2
+        ff_icc_context_uninit(&avci->icc);
+#endif
+
         av_freep(&avctx->internal);
     }
 
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 1893caa6a6..d1414c599b 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -49,6 +49,10 @@ 
 #include "internal.h"
 #include "thread.h"
 
+#if CONFIG_LCMS2
+# include "fflcms2.h"
+#endif
+
 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
 {
     int ret;
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 17e1de8127..dce8f7d83a 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -33,6 +33,10 @@ 
 #include "avcodec.h"
 #include "config.h"
 
+#ifdef CONFIG_LCMS2
+# include "fflcms2.h"
+#endif
+
 #define FF_SANE_NB_CHANNELS 512U
 
 #if HAVE_SIMD_ALIGN_64
@@ -148,6 +152,10 @@  typedef struct AVCodecInternal {
     uint64_t initial_channel_layout;
 #endif
     AVChannelLayout initial_ch_layout;
+
+#ifdef CONFIG_LCMS2
+    FFIccContext icc; /* used to read and write embedded ICC profiles */
+#endif
 } AVCodecInternal;
 
 /**