10#include <OpenImageIO/imagebufalgo.h>
11#include <spdlog/spdlog.h>
17 const auto cs { buf.spec().get_string_attribute(
"oiio:ColorSpace") };
18 return cs.empty() ? std::string{} : std::string(cs);
23 if (colorspace.empty()) {
29 if (colorspace.starts_with(
"lin_")) {
34 if (colorspace.starts_with(
"scene_linear")) {
39 if (colorspace ==
"Linear") {
48 const auto cs { spec.get_string_attribute(
"oiio:ColorSpace") };
57std::expected<void, ErrorHandling::CoreError>
60 if (!image.initialized()) {
61 spdlog::warn(
"[transformToColorSpace]: Buffer is not initialized");
67 if (source_cs.empty()) {
68 spdlog::warn(
"[transformToColorSpace]: No color space metadata found");
72 if (!OIIO::ImageBufAlgo::colorconvert(image, image,
74 std::string(target_cs))) {
75 spdlog::error(
"[transformToColorSpace]: Conversion from {} to {} failed: {}",
76 source_cs, target_cs, image.geterror());
Utilities for analyzing and converting image color spaces.
@ DecodingError
Failed to decode the image data.
@ InvalidWorkingImage
The working image state is invalid or corrupted.
bool isLinearToken(std::string_view colorspace) noexcept
Checks whether an OIIO-detected color space token represents linear data.
ColorSpaceInfo analyzeColorSpace(const OIIO::ImageSpec &spec) noexcept
Analyzes whether an image's pixel data is stored in a linear color space.
std::expected< void, ErrorHandling::CoreError > transformToColorSpace(OIIO::ImageBuf &image, std::string_view target_cs)
Converts an image buffer to a target color space (in-place).
std::pair< bool, std::string > ColorSpaceInfo
Result of a color space analysis.
std::string getColorSpace(const OIIO::ImageBuf &buf) noexcept
Extracts the color space name from an OIIO image buffer metadata.