Files
test/source/blender/imbuf/intern/format_hdr.cc
Brecht Van Lommel ccd7bc2078 Refactor: Modify colorspace handling for image buffer reading
The file formats now fill in ImColorSpaceInfo with the metadata colorspace
and a boolean saying if the pixels have HDR colors. And then the actual
colorspace is decided in imb_handle_colorspace_and_alpha.

This centralizes the logic in one place to make it possible to add
OpenColorIO file rules.

Pull Request: https://projects.blender.org/blender/blender/pulls/136516
2025-03-27 22:07:50 +01:00

54 lines
1.3 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup imbuf
*/
#include "oiio/openimageio_support.hh"
#include "IMB_filetype.hh"
#include "IMB_imbuf_types.hh"
OIIO_NAMESPACE_USING
using namespace blender::imbuf;
bool imb_is_a_hdr(const uchar *mem, size_t size)
{
return imb_oiio_check(mem, size, "hdr");
}
ImBuf *imb_load_hdr(const uchar *mem, size_t size, int flags, ImFileColorSpace &r_colorspace)
{
ImageSpec config, spec;
ReadContext ctx{mem, size, "hdr", IMB_FTYPE_RADHDR, flags};
/* Always create ImBufs with a 4th alpha channel despite the format only supporting 3. */
ctx.use_all_planes = true;
ImBuf *ibuf = imb_oiio_read(ctx, config, r_colorspace, spec);
if (ibuf) {
if (flags & IB_alphamode_detect) {
ibuf->flags |= IB_alphamode_premul;
}
if (flags & IB_byte_data) {
IMB_byte_from_float(ibuf);
}
}
return ibuf;
}
bool imb_save_hdr(ImBuf *ibuf, const char *filepath, int flags)
{
const int file_channels = 3;
const TypeDesc data_format = TypeDesc::FLOAT;
WriteContext ctx = imb_create_write_context("hdr", ibuf, flags);
ImageSpec file_spec = imb_create_write_spec(ctx, file_channels, data_format);
return imb_oiio_write(ctx, filepath, file_spec);
}