Blender V4.5
openexr_api.cpp File Reference
#include "IMB_filetype.hh"
#include <algorithm>
#include <cctype>
#include <cerrno>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <OpenEXR/OpenEXRConfig.h>
#include <OpenEXR/half.h>
#include <OpenEXR/Iex.h>
#include <OpenEXR/ImfArray.h>
#include <OpenEXR/ImfAttribute.h>
#include <OpenEXR/ImfChannelList.h>
#include <OpenEXR/ImfChromaticities.h>
#include <OpenEXR/ImfCompression.h>
#include <OpenEXR/ImfCompressionAttribute.h>
#include <OpenEXR/ImfIO.h>
#include <OpenEXR/ImfInputFile.h>
#include <OpenEXR/ImfIntAttribute.h>
#include <OpenEXR/ImfOutputFile.h>
#include <OpenEXR/ImfPixelType.h>
#include <OpenEXR/ImfPreviewImage.h>
#include <OpenEXR/ImfRgbaFile.h>
#include <OpenEXR/ImfStandardAttributes.h>
#include <OpenEXR/ImfStringAttribute.h>
#include <OpenEXR/ImfVersion.h>
#include <OpenEXR/ImfInputPart.h>
#include <OpenEXR/ImfMultiPartInputFile.h>
#include <OpenEXR/ImfMultiPartOutputFile.h>
#include <OpenEXR/ImfMultiView.h>
#include <OpenEXR/ImfOutputPart.h>
#include <OpenEXR/ImfPartHelper.h>
#include <OpenEXR/ImfPartType.h>
#include <OpenEXR/ImfTiledOutputPart.h>
#include "DNA_scene_types.h"
#include <openexr_api.h>
#include <unistd.h>
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_math_base.hh"
#include "BLI_math_color.h"
#include "BLI_mmap.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "BLI_threads.h"
#include "BKE_idprop.hh"
#include "BKE_image.hh"
#include "IMB_allocimbuf.hh"
#include "IMB_colormanagement.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "IMB_metadata.hh"
#include "IMB_openexr.hh"

Go to the source code of this file.

Classes

class  IMemStream
class  IMMapStream
class  IFileStream
class  OMemStream
class  OFileStream
struct  _RGBAZ
struct  ExrHandle
struct  ExrChannel
struct  ExrPass
struct  ExrLayer

Macros

#define COMBINED_OPENEXR_VERSION   ((10000 * OPENEXR_VERSION_MAJOR) + (100 * OPENEXR_VERSION_MINOR) + OPENEXR_VERSION_PATCH)
#define exr_file_offset_t   Int64

Typedefs

using RGBAZ = _RGBAZ

Functions

static struct ExrPassimb_exr_get_pass (ListBase *lb, const char *passname)
static bool exr_has_multiview (MultiPartInputFile &file)
static bool exr_has_multipart_file (MultiPartInputFile &file)
static bool exr_has_alpha (MultiPartInputFile &file)
static void exr_printf (const char *__restrict fmt,...)
static void imb_exr_type_by_channels (ChannelList &channels, StringVector &views, bool *r_singlelayer, bool *r_multilayer, bool *r_multiview)
static half float_to_half_safe (const float value)
bool imb_is_a_openexr (const uchar *mem, const size_t size)
static int openexr_jpg_like_quality_to_dwa_quality (int q)
static void openexr_header_compression (Header *header, int compression, int quality)
static int openexr_header_get_compression (const Header &header)
static void openexr_header_metadata (Header *header, ImBuf *ibuf)
static void openexr_header_metadata_callback (void *data, const char *propname, char *prop, int)
static bool imb_save_openexr_half (ImBuf *ibuf, const char *filepath, const int flags)
static bool imb_save_openexr_float (ImBuf *ibuf, const char *filepath, const int flags)
bool imb_save_openexr (ImBuf *ibuf, const char *filepath, int flags)
static bool imb_exr_multilayer_parse_channels_from_file (ExrHandle *data)
void * IMB_exr_get_handle ()
void * IMB_exr_get_handle_name (const char *name)
void IMB_exr_add_view (void *handle, const char *name)
static int imb_exr_get_multiView_id (StringVector &views, const std::string &name)
static void imb_exr_get_views (MultiPartInputFile &file, StringVector &views)
static void imb_exr_insert_view_name (char name_full[EXR_TOT_MAXNAME+1], const char *passname, const char *viewname)
void IMB_exr_add_channel (void *handle, const char *layname, const char *passname, const char *viewname, int xstride, int ystride, float *rect, bool use_half_float)
bool IMB_exr_begin_write (void *handle, const char *filepath, int width, int height, const double ppm[2], int compress, int quality, const StampData *stamp)
bool IMB_exr_begin_read (void *handle, const char *filepath, int *width, int *height, const bool parse_channels)
bool IMB_exr_set_channel (void *handle, const char *layname, const char *passname, int xstride, int ystride, float *rect)
void IMB_exr_write_channels (void *handle)
void IMB_exr_read_channels (void *handle)
void IMB_exr_multilayer_convert (void *handle, void *base, void *(*addview)(void *base, const char *str), void *(*addlayer)(void *base, const char *str), void(*addpass)(void *base, void *lay, const char *str, float *rect, int totchan, const char *chan_id, const char *view))
void IMB_exr_close (void *handle)
static int imb_exr_split_token (const char *str, const char *end, const char **token)
static void imb_exr_pass_name_from_channel (char *passname, const ExrChannel *echan, const char *channelname, const bool has_xyz_channels)
static void imb_exr_pass_name_from_channel_name (char *passname, const ExrChannel *, const char *channelname, const bool)
static int imb_exr_split_channel_name (ExrChannel *echan, char *layname, char *passname, bool has_xyz_channels)
static ExrLayerimb_exr_get_layer (ListBase *lb, const char *layname)
static bool exr_has_xyz_channels (ExrHandle *exr_handle)
static std::vector< MultiViewChannelName > exr_channels_in_multi_part_file (const MultiPartInputFile &file)
static ExrHandleimb_exr_begin_read_mem (IStream &file_stream, MultiPartInputFile &file, int width, int height)
static void exr_printf (const char *fmt,...)
static void exr_print_filecontents (MultiPartInputFile &file)
static const char * exr_rgba_channelname (MultiPartInputFile &file, const char *chan)
static int exr_has_rgb (MultiPartInputFile &file, const char *rgb_channels[3])
static bool exr_has_luma (MultiPartInputFile &file)
static bool exr_has_chroma (MultiPartInputFile &file)
static bool exr_has_xyz (MultiPartInputFile &file)
static bool exr_is_half_float (MultiPartInputFile &file)
static bool imb_exr_is_multilayer_file (MultiPartInputFile &file)
static bool imb_exr_is_multi (MultiPartInputFile &file)
bool IMB_exr_has_multilayer (void *handle)
static bool imb_check_chromaticity_val (float test_v, float ref_v)
static bool imb_check_chromaticity_matches (const Imf::Chromaticities &a, const Imf::Chromaticities &b)
static void imb_exr_set_known_colorspace (const Header &header, ImFileColorSpace &r_colorspace)
static bool exr_get_ppm (MultiPartInputFile &file, double ppm[2])
bool IMB_exr_get_ppm (void *handle, double ppm[2])
ImBufimb_load_openexr (const uchar *mem, size_t size, int flags, ImFileColorSpace &r_colorspace)
ImBufimb_load_filepath_thumbnail_openexr (const char *filepath, const int, const size_t max_thumb_size, ImFileColorSpace &r_colorspace, size_t *r_width, size_t *r_height)
void imb_initopenexr ()
void imb_exitopenexr ()

Variables

static Imf::Chromaticities CHROMATICITIES_XYZ_E
static Imf::Chromaticities CHROMATICITIES_ACES_2065_1
static ListBase exrhandles = {nullptr, nullptr}

Macro Definition Documentation

◆ COMBINED_OPENEXR_VERSION

#define COMBINED_OPENEXR_VERSION   ((10000 * OPENEXR_VERSION_MAJOR) + (100 * OPENEXR_VERSION_MINOR) + OPENEXR_VERSION_PATCH)

Definition at line 26 of file openexr_api.cpp.

◆ exr_file_offset_t

Typedef Documentation

◆ RGBAZ

using RGBAZ = _RGBAZ

Definition at line 399 of file openexr_api.cpp.

Function Documentation

◆ exr_channels_in_multi_part_file()

std::vector< MultiViewChannelName > exr_channels_in_multi_part_file ( const MultiPartInputFile & file)
static

◆ exr_get_ppm()

bool exr_get_ppm ( MultiPartInputFile & file,
double ppm[2] )
static

Definition at line 2056 of file openexr_api.cpp.

Referenced by IMB_exr_get_ppm(), and imb_load_openexr().

◆ exr_has_alpha()

bool exr_has_alpha ( MultiPartInputFile & file)
static

Definition at line 1869 of file openexr_api.cpp.

Referenced by imb_load_openexr().

◆ exr_has_chroma()

bool exr_has_chroma ( MultiPartInputFile & file)
static

Definition at line 1862 of file openexr_api.cpp.

Referenced by imb_load_openexr().

◆ exr_has_luma()

bool exr_has_luma ( MultiPartInputFile & file)
static

Definition at line 1853 of file openexr_api.cpp.

Referenced by imb_load_openexr().

◆ exr_has_multipart_file()

bool exr_has_multipart_file ( MultiPartInputFile & file)
static

Definition at line 1977 of file openexr_api.cpp.

Referenced by imb_exr_get_views(), and imb_exr_is_multi().

◆ exr_has_multiview()

bool exr_has_multiview ( MultiPartInputFile & file)
static

Definition at line 1966 of file openexr_api.cpp.

Referenced by imb_exr_get_views(), and imb_exr_is_multi().

◆ exr_has_rgb()

int exr_has_rgb ( MultiPartInputFile & file,
const char * rgb_channels[3] )
static

Definition at line 1822 of file openexr_api.cpp.

References i.

Referenced by imb_load_openexr().

◆ exr_has_xyz()

bool exr_has_xyz ( MultiPartInputFile & file)
static

Definition at line 1875 of file openexr_api.cpp.

Referenced by imb_load_openexr().

◆ exr_has_xyz_channels()

bool exr_has_xyz_channels ( ExrHandle * exr_handle)
static

◆ exr_is_half_float()

bool exr_is_half_float ( MultiPartInputFile & file)
static

Definition at line 1886 of file openexr_api.cpp.

References HALF, and i.

Referenced by imb_load_openexr().

◆ exr_print_filecontents()

void exr_print_filecontents ( MultiPartInputFile & file)
static

Definition at line 1775 of file openexr_api.cpp.

References i, printf, and view.

Referenced by imb_load_openexr().

◆ exr_printf() [1/2]

void exr_printf ( const char *__restrict fmt,
... )
static

◆ exr_printf() [2/2]

void exr_printf ( const char * fmt,
... )
static

Definition at line 1763 of file openexr_api.cpp.

◆ exr_rgba_channelname()

const char * exr_rgba_channelname ( MultiPartInputFile & file,
const char * chan )
static

Definition at line 1805 of file openexr_api.cpp.

References BLI_strcasecmp(), i, len, and str.

Referenced by imb_load_openexr().

◆ float_to_half_safe()

half float_to_half_safe ( const float value)
static

Definition at line 401 of file openexr_api.cpp.

References clamp_f().

Referenced by IMB_exr_write_channels(), and imb_save_openexr_half().

◆ imb_check_chromaticity_matches()

bool imb_check_chromaticity_matches ( const Imf::Chromaticities & a,
const Imf::Chromaticities & b )
static

Definition at line 2015 of file openexr_api.cpp.

References b, and imb_check_chromaticity_val().

Referenced by imb_exr_set_known_colorspace().

◆ imb_check_chromaticity_val()

bool imb_check_chromaticity_val ( float test_v,
float ref_v )
static

Definition at line 2008 of file openexr_api.cpp.

Referenced by imb_check_chromaticity_matches().

◆ imb_exitopenexr()

void imb_exitopenexr ( )

Definition at line 2400 of file openexr_api.cpp.

◆ IMB_exr_add_channel()

void IMB_exr_add_channel ( void * handle,
const char * layname,
const char * passname,
const char * viewname,
int xstride,
int ystride,
float * rect,
bool use_half_float )

Adds flattened ExrChannel's xstride, ystride and rect can be done in set_channel too, for tile writing.

Parameters
passnameDoes not include view.

Definition at line 906 of file openexr_api.cpp.

Referenced by IMB_exr_begin_read(), and imb_exr_multilayer_parse_channels_from_file().

◆ IMB_exr_add_view()

void IMB_exr_add_view ( void * handle,
const char * name )

Definition at line 831 of file openexr_api.cpp.

◆ IMB_exr_begin_read()

bool IMB_exr_begin_read ( void * handle,
const char * filepath,
int * width,
int * height,
bool parse_channels )

Read from file.

Definition at line 1032 of file openexr_api.cpp.

◆ imb_exr_begin_read_mem()

ExrHandle * imb_exr_begin_read_mem ( IStream & file_stream,
MultiPartInputFile & file,
int width,
int height )
static

◆ IMB_exr_begin_write()

bool IMB_exr_begin_write ( void * handle,
const char * filepath,
int width,
int height,
const double ppm[2],
int compress,
int quality,
const StampData * stamp )

Used for output files (from RenderResult) (single and multi-layer, single and multi-view).

Definition at line 962 of file openexr_api.cpp.

◆ IMB_exr_close()

void IMB_exr_close ( void * handle)

Definition at line 1307 of file openexr_api.cpp.

Referenced by imb_exr_begin_read_mem().

◆ IMB_exr_get_handle()

void * IMB_exr_get_handle ( )

Definition at line 809 of file openexr_api.cpp.

Referenced by imb_exr_begin_read_mem(), and IMB_exr_get_handle_name().

◆ IMB_exr_get_handle_name()

void * IMB_exr_get_handle_name ( const char * name)

Definition at line 818 of file openexr_api.cpp.

◆ imb_exr_get_layer()

ExrLayer * imb_exr_get_layer ( ListBase * lb,
const char * layname )
static

◆ imb_exr_get_multiView_id()

int imb_exr_get_multiView_id ( StringVector & views,
const std::string & name )
static

Definition at line 837 of file openexr_api.cpp.

References count, and i.

Referenced by IMB_exr_add_channel(), imb_exr_get_views(), and imb_exr_type_by_channels().

◆ imb_exr_get_pass()

ExrPass * imb_exr_get_pass ( ListBase * lb,
const char * passname )
static

◆ IMB_exr_get_ppm()

bool IMB_exr_get_ppm ( void * handle,
double ppm[2] )

Definition at line 2067 of file openexr_api.cpp.

◆ imb_exr_get_views()

void imb_exr_get_views ( MultiPartInputFile & file,
StringVector & views )
static

◆ IMB_exr_has_multilayer()

bool IMB_exr_has_multilayer ( void * handle)

Definition at line 2002 of file openexr_api.cpp.

◆ imb_exr_insert_view_name()

void imb_exr_insert_view_name ( char name_full[EXR_TOT_MAXNAME+1],
const char * passname,
const char * viewname )
static

◆ imb_exr_is_multi()

bool imb_exr_is_multi ( MultiPartInputFile & file)
static

◆ imb_exr_is_multilayer_file()

bool imb_exr_is_multilayer_file ( MultiPartInputFile & file)
static

Definition at line 1898 of file openexr_api.cpp.

Referenced by imb_exr_is_multi().

◆ IMB_exr_multilayer_convert()

void IMB_exr_multilayer_convert ( void * handle,
void * base,
void *(* addview )(void *base, const char *str),
void *(* addlayer )(void *base, const char *str),
void(* addpass )(void *base, void *lay, const char *str, float *rect, int totchan, const char *chan_id, const char *view) )

◆ imb_exr_multilayer_parse_channels_from_file()

◆ imb_exr_pass_name_from_channel()

void imb_exr_pass_name_from_channel ( char * passname,
const ExrChannel * echan,
const char * channelname,
const bool has_xyz_channels )
static

◆ imb_exr_pass_name_from_channel_name()

void imb_exr_pass_name_from_channel_name ( char * passname,
const ExrChannel * ,
const char * channelname,
const bool  )
static

Definition at line 1381 of file openexr_api.cpp.

References BLI_strncpy(), and EXR_TOT_MAXNAME.

Referenced by imb_exr_split_channel_name().

◆ IMB_exr_read_channels()

void IMB_exr_read_channels ( void * handle)

Definition at line 1181 of file openexr_api.cpp.

Referenced by imb_load_openexr().

◆ IMB_exr_set_channel()

bool IMB_exr_set_channel ( void * handle,
const char * layname,
const char * passname,
int xstride,
int ystride,
float * rect )

Still clumsy name handling, layers/channels can be ordered as list in list later.

Parameters
passnameHere is the raw channel name without the layer.

Definition at line 1092 of file openexr_api.cpp.

◆ imb_exr_set_known_colorspace()

◆ imb_exr_split_channel_name()

int imb_exr_split_channel_name ( ExrChannel * echan,
char * layname,
char * passname,
bool has_xyz_channels )
static

◆ imb_exr_split_token()

int imb_exr_split_token ( const char * str,
const char * end,
const char ** token )
static

Get a sub-string from the end of the name, separated by '.'.

Definition at line 1346 of file openexr_api.cpp.

References BLI_str_partition_ex(), and str.

Referenced by imb_exr_split_channel_name().

◆ imb_exr_type_by_channels()

void imb_exr_type_by_channels ( ChannelList & channels,
StringVector & views,
bool * r_singlelayer,
bool * r_multilayer,
bool * r_multiview )
static

Definition at line 1910 of file openexr_api.cpp.

References BLI_assert, i, imb_exr_get_multiView_id(), and pos.

Referenced by IMB_exr_begin_write().

◆ IMB_exr_write_channels()

void IMB_exr_write_channels ( void * handle)

Definition at line 1122 of file openexr_api.cpp.

◆ imb_initopenexr()

void imb_initopenexr ( )

Definition at line 2392 of file openexr_api.cpp.

References BLI_system_thread_count().

◆ imb_is_a_openexr()

bool imb_is_a_openexr ( const unsigned char * mem,
size_t size )

Test presence of OpenEXR file.

Parameters
mempointer to loaded OpenEXR bit-stream.

Definition at line 406 of file openexr_api.cpp.

References size().

Referenced by imb_load_openexr().

◆ imb_load_filepath_thumbnail_openexr()

ImBuf * imb_load_filepath_thumbnail_openexr ( const char * filepath,
const int flags,
const size_t max_thumb_size,
ImFileColorSpace & r_colorspace,
size_t * r_width,
size_t * r_height )

◆ imb_load_openexr()

◆ imb_save_openexr()

◆ imb_save_openexr_float()

◆ imb_save_openexr_half()

◆ openexr_header_compression()

◆ openexr_header_get_compression()

◆ openexr_header_metadata()

◆ openexr_header_metadata_callback()

void openexr_header_metadata_callback ( void * data,
const char * propname,
char * prop,
int  )
static

Definition at line 532 of file openexr_api.cpp.

References data.

Referenced by IMB_exr_begin_write().

◆ openexr_jpg_like_quality_to_dwa_quality()

int openexr_jpg_like_quality_to_dwa_quality ( int q)
static

Definition at line 415 of file openexr_api.cpp.

References blender::math::clamp().

Referenced by openexr_header_compression().

Variable Documentation

◆ CHROMATICITIES_ACES_2065_1

Imf::Chromaticities CHROMATICITIES_ACES_2065_1
static
Initial value:
{
{0.7347f, 0.2653f}, {0.0f, 1.0f}, {0.0001f, -0.077f}, {0.32168f, 0.33767f}}

Definition at line 120 of file openexr_api.cpp.

Referenced by imb_exr_set_known_colorspace(), and openexr_header_metadata().

◆ CHROMATICITIES_XYZ_E

Imf::Chromaticities CHROMATICITIES_XYZ_E
static
Initial value:
{
{1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f / 3.0f, 1.0f / 3.0f}}

Definition at line 117 of file openexr_api.cpp.

Referenced by imb_exr_set_known_colorspace().

◆ exrhandles

ListBase exrhandles = {nullptr, nullptr}
static

Definition at line 742 of file openexr_api.cpp.

Referenced by IMB_exr_close(), IMB_exr_get_handle(), and IMB_exr_get_handle_name().