aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/palette.h
diff options
context:
space:
mode:
authorClément Bœsch <u@pkh.me>2022-11-03 23:28:39 +0100
committerClément Bœsch <u@pkh.me>2023-01-03 17:18:55 +0100
commit31c5f26a46324d5594200a95cb6e44dc2803bf1a (patch)
tree388d83fe1fc1030c86c38cf64dadac34572629d9 /libavfilter/palette.h
parent7bc054e63c86ccb913e89c12d8fd26172b272b52 (diff)
downloadffmpeg-31c5f26a46324d5594200a95cb6e44dc2803bf1a.tar.gz
avfilter/palette{gen,use}: add palette utils
These color management helpers will be shared by palettegen and paletteuse in the following commits. Note that it probably makes sense to share at least the sRGB/linear functions with other filters at some point. More information on OkLab can be found here: https://bottosson.github.io/posts/oklab/ For the arithmetic integer version, see: http://blog.pkh.me/p/38-porting-oklab-colorspace-to-integer-arithmetic.html and https://github.com/ubitux/oklab-int
Diffstat (limited to 'libavfilter/palette.h')
-rw-r--r--libavfilter/palette.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/libavfilter/palette.h b/libavfilter/palette.h
new file mode 100644
index 0000000000..6839bf6fc6
--- /dev/null
+++ b/libavfilter/palette.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2020 Björn Ottosson
+ * Copyright (c) 2022 Clément Bœsch <u pkh me>
+ *
+ * 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
+ */
+
+#ifndef AVFILTER_PALETTE_H
+#define AVFILTER_PALETTE_H
+
+#include <math.h>
+#include <stdint.h>
+
+#include "libavutil/attributes.h"
+
+struct Lab {
+ int32_t L, a, b;
+};
+
+/**
+ * Map sRGB 8-bit color component to a 16-bit linear value (gamma
+ * expand from electrical to optical value).
+ */
+int32_t ff_srgb_u8_to_linear_int(uint8_t x);
+
+/**
+ * Map a 16-bit linear value to a sRGB 8-bit color component (gamma
+ * compressed from optical to electrical value).
+ */
+uint8_t ff_linear_int_to_srgb_u8(int32_t x);
+
+/**
+ * sRGB (non-linear) to OkLab conversion
+ * @see https://bottosson.github.io/posts/oklab/
+ */
+struct Lab ff_srgb_u8_to_oklab_int(uint32_t srgb);
+
+/**
+ * OkLab to sRGB (non-linear) conversion
+ * @see https://bottosson.github.io/posts/oklab/
+ */
+uint32_t ff_oklab_int_to_srgb_u8(struct Lab c);
+
+#endif /* AVFILTER_PALETTE_H */