OpenImageIO buffers

Run the same conversion as rta::util::ImageConverter::process_image() when the application owns the image buffer. There is no separate command-line form. The command line calls this sequence internally.

The order is the one process_image uses: build the output path, configure, load_image, process_buffer, then save_image. process_buffer applies lens correction, the matrix, scale, and crop. Soft crop is set so the result matches convert a single image. save_image stores half-float samples unless another type is passed. get_WB_multipliers and get_transform_matrix are valid after a successful configure.

Each step returns false and sets status and last_error_message. The examples stop at the first failure. Changing settings that affect the transform requires another configure.

The output is <stem>_aces.exr beside the input. overwrite stays false, so an existing file is refused before the image is read.

C++ provides this sequence in rawtoaces_util. Python provides configure(input_filename) in every build. load_image, process_buffer, save_image, and configure with an OpenImageIO parameter list require OpenImageIO 3.2 or later, as described in OpenImageIO 3.2. Python has no make_output_path; the Python example builds the same file name and applies the same overwrite check.

#include <rawtoaces/image_converter.h>
#include <OpenImageIO/imagebuf.h>
#include <OpenImageIO/paramlist.h>
#include <iostream>
#include <string>

int main(int argc, char **argv)
{
    if (argc != 2)
    {
        std::cerr << "Usage: convert_buffer <INPUT_PATH>\n";
        return 1;
    }
    const std::string input_path = argv[1];
    rta::util::ImageConverter converter;
    converter.settings.crop_mode =
        rta::util::ImageConverter::Settings::CropMode::Soft;
    converter.settings.overwrite = false;

    std::string output_path = input_path;
    if (!converter.make_output_path(output_path))
    {
        std::cerr << converter.last_error_message << '\n';
        return 1;
    }

    OIIO::ParamValueList hints;
    if (!converter.configure(input_path, hints))
    {
        std::cerr << converter.last_error_message << '\n';
        return 1;
    }

    OIIO::ImageBuf buffer;
    if (!converter.load_image(input_path, hints, buffer))
    {
        std::cerr << converter.last_error_message << '\n';
        return 1;
    }
    if (!converter.process_buffer(buffer, buffer))
    {
        std::cerr << converter.last_error_message << '\n';
        return 1;
    }
    if (!converter.save_image(output_path, buffer))
    {
        std::cerr << converter.last_error_message << '\n';
        return 1;
    }
    return 0;
}

See also handle errors and the API overview.