summaryrefslogtreecommitdiff
path: root/libavcodec/fflcms2.h
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.dev>2022-06-28 13:55:37 +0200
committerNiklas Haas <git@haasn.dev>2022-07-30 11:42:06 +0200
commit1cbd4552fe3bcdc36b76304d11b883d061cc23ee (patch)
treecb6c74f4989ead8805d3722a83572caed3946374 /libavcodec/fflcms2.h
parente0691eab2290952e1b63a8e0ac97940d65f3ca67 (diff)
fflcms2: move to libavcodec
We will need this helper inside libavcodec in the future, so move it there, leaving behind an #include to the raw source file in its old location in libvfilter. This approach is inspired by the handling of vulkan.c, and avoids us needing to expose any of it publicly (or semi-publicly) in e.g. libavutil, thus avoiding any ABI headaches. It's debatable whether the actual code belongs in libavcodec or libavfilter, but I decided to put it into libavcodec because it conceptually deals with encoding and decoding ICC profiles, and will be used to decode embedded ICC profiles in image files. Signed-off-by: Niklas Haas <git@haasn.dev>
Diffstat (limited to 'libavcodec/fflcms2.h')
-rw-r--r--libavcodec/fflcms2.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/libavcodec/fflcms2.h b/libavcodec/fflcms2.h
new file mode 100644
index 0000000000..af63c9a13c
--- /dev/null
+++ b/libavcodec/fflcms2.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2022 Niklas Haas
+ * 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
+ */
+
+/**
+ * @file
+ * Various functions for dealing with ICC profiles
+ */
+
+#ifndef AVCODEC_FFLCMS2_H
+#define AVCODEC_FFLCMS2_H
+
+#include "libavutil/csp.h"
+#include "libavutil/frame.h"
+#include "libavutil/pixfmt.h"
+
+#include <lcms2.h>
+
+typedef struct FFIccContext {
+ void *avctx;
+ cmsContext ctx;
+ cmsToneCurve *curves[AVCOL_TRC_NB]; /* tone curve cache */
+} FFIccContext;
+
+/**
+ * Initializes an FFIccContext. This must be done prior to using it.
+ *
+ * Returns 0 on success, or a negative error code.
+ */
+int ff_icc_context_init(FFIccContext *s, void *avctx);
+void ff_icc_context_uninit(FFIccContext *s);
+
+/**
+ * Generate an ICC profile for a given combination of color primaries and
+ * transfer function. Both values must be set to valid entries (not
+ * "undefined") for this function to work.
+ *
+ * Returns 0 on success, or a negative error code.
+ */
+int ff_icc_profile_generate(FFIccContext *s,
+ enum AVColorPrimaries color_prim,
+ enum AVColorTransferCharacteristic color_trc,
+ cmsHPROFILE *out_profile);
+
+/**
+ * Attach an ICC profile to a frame. Helper wrapper around cmsSaveProfileToMem
+ * and av_frame_new_side_data_from_buf.
+ *
+ * Returns 0 on success, or a negative error code.
+ */
+int ff_icc_profile_attach(FFIccContext *s, cmsHPROFILE profile, AVFrame *frame);
+
+/**
+ * Read the color primaries and white point coefficients encoded by an ICC
+ * profile, and return the raw values in `out_primaries`.
+ *
+ * Returns 0 on success, or a negative error code.
+ */
+int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile,
+ AVColorPrimariesDesc *out_primaries);
+
+/**
+ * Attempt detecting the transfer characteristic that best approximates the
+ * transfer function encoded by an ICC profile. Sets `out_trc` to
+ * AVCOL_TRC_UNSPECIFIED if no clear match can be identified.
+ *
+ * Returns 0 on success (including no match), or a negative error code.
+ */
+int ff_icc_profile_detect_transfer(FFIccContext *s, cmsHPROFILE profile,
+ enum AVColorTransferCharacteristic *out_trc);
+
+#endif /* AVCODEC_FFLCMS2_H */