diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-05-26 13:02:14 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-05-26 13:02:30 +0300 |
commit | de68066c1ccfbdd3d9f185164e728677c91874ec (patch) | |
tree | b0108ec1b0fb56150d1eca26734067bfdcb57a46 /source/blender/imbuf/intern/openexr | |
parent | e5fbeba0b3a6e9eea4a8747e97033bbd0d7f017b (diff) |
Fix multilayer OpenEXR not supporting metadata.
This will fix exporting of metadata and importing for imbufs, but image
editor will not display these metadata since multilayer gets converted
to renderresult, which does not support metadata display yet.
This commit is more meant for external image editors/viewers.
Diffstat (limited to 'source/blender/imbuf/intern/openexr')
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 43 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_multi.h | 4 |
2 files changed, 29 insertions, 18 deletions
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index b4f81ebeb57..1950fd81cb6 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -63,6 +63,7 @@ _CRTIMP void __cdecl _invalid_parameter_noinfo(void) #include "BLI_threads.h" #include "BKE_idprop.h" +#include "BKE_image.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -363,6 +364,13 @@ static void openexr_header_metadata(Header *header, struct ImBuf *ibuf) addXDensity(*header, ibuf->ppm[0] / 39.3700787); /* 1 meter = 39.3700787 inches */ } +static void openexr_header_metadata_callback(void *data, const char *propname, const char *prop) +{ + Header *header = (Header *)data; + header->insert(propname, StringAttribute(prop)); +} + + static bool imb_save_openexr_half(ImBuf *ibuf, const char *name, const int flags, const size_t totviews, const char * (*getview)(void *base, size_t view_id), ImBuf * (*getbuffer)(void *base, const size_t view_id)) @@ -821,7 +829,7 @@ void IMB_exr_add_channel(void *handle, const char *layname, const char *passname } /* used for output files (from RenderResult) (single and multilayer, single and multiview) */ -int IMB_exr_begin_write(void *handle, const char *filename, int width, int height, int compress) +int IMB_exr_begin_write(void *handle, const char *filename, int width, int height, int compress, struct StampData *stamp) { ExrHandle *data = (ExrHandle *)handle; Header header(width, height); @@ -836,7 +844,7 @@ int IMB_exr_begin_write(void *handle, const char *filename, int width, int heigh header.channels().insert(echan->name, Channel(Imf::FLOAT)); openexr_header_compression(&header, compress); - // openexr_header_metadata(&header, ibuf); // no imbuf. cant write + BKE_stamp_info_callback(&header, stamp, openexr_header_metadata_callback); /* header.lineOrder() = DECREASING_Y; this crashes in windows for file read! */ imb_exr_type_by_channels(header.channels(), *data->multiView, &is_singlelayer, &is_multilayer, &is_multiview); @@ -1888,6 +1896,22 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, size_t size, int flags, char ibuf->ftype = OPENEXR; if (!(flags & IB_test)) { + + if (flags & IB_metadata) { + const Header & header = file->header(0); + Header::ConstIterator iter; + + for (iter = header.begin(); iter != header.end(); iter++) { + const StringAttribute *attrib = file->header(0).findTypedAttribute <StringAttribute> (iter.name()); + + /* not all attributes are string attributes so we might get some NULLs here */ + if (attrib) { + IMB_metadata_add_field(ibuf, iter.name(), attrib->value().c_str()); + ibuf->flags |= IB_metadata; + } + } + } + if (is_multi && ((flags & IB_thumbnail) == 0)) { /* only enters with IB_multilayer flag set */ /* constructs channels for reading, allocates memory in channels */ ExrHandle *handle = imb_exr_begin_read_mem(*file, width, height); @@ -1973,21 +1997,6 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, size_t size, int flags, char } } - if (flags & IB_metadata) { - const Header & header = file->header(0); - Header::ConstIterator iter; - - for (iter = header.begin(); iter != header.end(); iter++) { - const StringAttribute *attrib = file->header(0).findTypedAttribute <StringAttribute> (iter.name()); - - /* not all attributes are string attributes so we might get some NULLs here */ - if (attrib) { - IMB_metadata_add_field(ibuf, iter.name(), attrib->value().c_str()); - ibuf->flags |= IB_metadata; - } - } - } - /* file is no longer needed */ delete file; } diff --git a/source/blender/imbuf/intern/openexr/openexr_multi.h b/source/blender/imbuf/intern/openexr/openexr_multi.h index 45ab0ed37c7..dbef24cbeb8 100644 --- a/source/blender/imbuf/intern/openexr/openexr_multi.h +++ b/source/blender/imbuf/intern/openexr/openexr_multi.h @@ -48,12 +48,14 @@ extern "C" { #endif +struct StampData; + void *IMB_exr_get_handle(void); void *IMB_exr_get_handle_name(const char *name); void IMB_exr_add_channel(void *handle, const char *layname, const char *passname, const char *view, int xstride, int ystride, float *rect); int IMB_exr_begin_read(void *handle, const char *filename, int *width, int *height); -int IMB_exr_begin_write(void *handle, const char *filename, int width, int height, int compress); +int IMB_exr_begin_write(void *handle, const char *filename, int width, int height, int compress, struct StampData *stamp); void IMB_exrtile_begin_write(void *handle, const char *filename, int mipmap, int width, int height, int tilex, int tiley); void IMB_exr_set_channel(void *handle, const char *layname, const char *passname, int xstride, int ystride, float *rect); |