Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/openexr/openexr_api.cpp
| Show All 26 Lines | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include <cstdlib> | #include <cstdlib> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <iostream> | #include <iostream> | ||||
| #include <set> | #include <set> | ||||
| #include <stdexcept> | #include <stdexcept> | ||||
| #include <string> | #include <string> | ||||
| #include <Iex.h> | /* The OpenEXR version can reliably be found in this header file from OpenEXR, | ||||
| #include <ImathBox.h> | * for both 2.x and 3.x: | ||||
| #include <ImfArray.h> | */ | ||||
| #include <ImfChannelList.h> | #include <OpenEXR/OpenEXRConfig.h> | ||||
| #include <ImfCompression.h> | #define COMBINED_OPENEXR_VERSION \ | ||||
| #include <ImfCompressionAttribute.h> | ((10000 * OPENEXR_VERSION_MAJOR) + (100 * OPENEXR_VERSION_MINOR) + OPENEXR_VERSION_PATCH) | ||||
| #include <ImfIO.h> | |||||
| #include <ImfInputFile.h> | #if COMBINED_OPENEXR_VERSION >= 20599 | ||||
| #include <ImfOutputFile.h> | /* >=2.5.99 -> OpenEXR >=3.0 */ | ||||
| #include <ImfPixelType.h> | # include <Imath/half.h> | ||||
| #include <ImfStandardAttributes.h> | # include <OpenEXR/ImfFrameBuffer.h> | ||||
| #include <ImfStringAttribute.h> | # define exr_file_offset_t uint64_t | ||||
| #include <ImfVersion.h> | #else | ||||
| #include <half.h> | /* OpenEXR 2.x, use the old locations. */ | ||||
| # include <OpenEXR/half.h> | |||||
| # define exr_file_offset_t Int64 | |||||
| #endif | |||||
| #include <OpenEXR/Iex.h> | |||||
| #include <OpenEXR/ImfArray.h> | |||||
| #include <OpenEXR/ImfChannelList.h> | |||||
| #include <OpenEXR/ImfCompression.h> | |||||
| #include <OpenEXR/ImfCompressionAttribute.h> | |||||
| #include <OpenEXR/ImfIO.h> | |||||
| #include <OpenEXR/ImfInputFile.h> | |||||
| #include <OpenEXR/ImfOutputFile.h> | |||||
| #include <OpenEXR/ImfPixelType.h> | |||||
| #include <OpenEXR/ImfStandardAttributes.h> | |||||
| #include <OpenEXR/ImfStringAttribute.h> | |||||
| #include <OpenEXR/ImfVersion.h> | |||||
| /* multiview/multipart */ | /* multiview/multipart */ | ||||
| #include <ImfInputPart.h> | #include <OpenEXR/ImfInputPart.h> | ||||
| #include <ImfMultiPartInputFile.h> | #include <OpenEXR/ImfMultiPartInputFile.h> | ||||
| #include <ImfMultiPartOutputFile.h> | #include <OpenEXR/ImfMultiPartOutputFile.h> | ||||
| #include <ImfMultiView.h> | #include <OpenEXR/ImfMultiView.h> | ||||
| #include <ImfOutputPart.h> | #include <OpenEXR/ImfOutputPart.h> | ||||
| #include <ImfPartHelper.h> | #include <OpenEXR/ImfPartHelper.h> | ||||
| #include <ImfPartType.h> | #include <OpenEXR/ImfPartType.h> | ||||
| #include <ImfTiledOutputPart.h> | #include <OpenEXR/ImfTiledOutputPart.h> | ||||
| #include "DNA_scene_types.h" /* For OpenEXR compression constants */ | #include "DNA_scene_types.h" /* For OpenEXR compression constants */ | ||||
| #include <openexr_api.h> | #include <openexr_api.h> | ||||
| #if defined(WIN32) | #if defined(WIN32) | ||||
| # include "utfconv.h" | # include "utfconv.h" | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (n + _exrpos <= _exrsize) { | ||||
| memcpy(c, (void *)(&_exrbuf[_exrpos]), n); | memcpy(c, (void *)(&_exrbuf[_exrpos]), n); | ||||
| _exrpos += n; | _exrpos += n; | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| Int64 tellg() override | exr_file_offset_t tellg() override | ||||
brecht: Note that the old `Int64` defined by OpenEXR 2 was in fact unsigned, so this works for both. | |||||
| { | { | ||||
| return _exrpos; | return _exrpos; | ||||
| } | } | ||||
| void seekg(Int64 pos) override | void seekg(exr_file_offset_t pos) override | ||||
| { | { | ||||
| _exrpos = pos; | _exrpos = pos; | ||||
| } | } | ||||
| void clear() override | void clear() override | ||||
| { | { | ||||
| } | } | ||||
| private: | private: | ||||
| Int64 _exrpos; | exr_file_offset_t _exrpos; | ||||
| Int64 _exrsize; | exr_file_offset_t _exrsize; | ||||
| unsigned char *_exrbuf; | unsigned char *_exrbuf; | ||||
| }; | }; | ||||
| /* File Input Stream */ | /* File Input Stream */ | ||||
| class IFileStream : public Imf::IStream { | class IFileStream : public Imf::IStream { | ||||
| public: | public: | ||||
| IFileStream(const char *filename) : IStream(filename) | IFileStream(const char *filename) : IStream(filename) | ||||
| Show All 18 Lines | if (!ifs) { | ||||
| throw Iex::InputExc("Unexpected end of file."); | throw Iex::InputExc("Unexpected end of file."); | ||||
| } | } | ||||
| errno = 0; | errno = 0; | ||||
| ifs.read(c, n); | ifs.read(c, n); | ||||
| return check_error(); | return check_error(); | ||||
| } | } | ||||
| Int64 tellg() override | exr_file_offset_t tellg() override | ||||
| { | { | ||||
| return std::streamoff(ifs.tellg()); | return std::streamoff(ifs.tellg()); | ||||
| } | } | ||||
| void seekg(Int64 pos) override | void seekg(exr_file_offset_t pos) override | ||||
| { | { | ||||
| ifs.seekg(pos); | ifs.seekg(pos); | ||||
| check_error(); | check_error(); | ||||
| } | } | ||||
| void clear() override | void clear() override | ||||
| { | { | ||||
| ifs.clear(); | ifs.clear(); | ||||
| Show All 27 Lines | public: | ||||
| void write(const char c[], int n) override | void write(const char c[], int n) override | ||||
| { | { | ||||
| ensure_size(offset + n); | ensure_size(offset + n); | ||||
| memcpy(ibuf->encodedbuffer + offset, c, n); | memcpy(ibuf->encodedbuffer + offset, c, n); | ||||
| offset += n; | offset += n; | ||||
| ibuf->encodedsize += n; | ibuf->encodedsize += n; | ||||
| } | } | ||||
| Int64 tellp() override | exr_file_offset_t tellp() override | ||||
| { | { | ||||
| return offset; | return offset; | ||||
| } | } | ||||
| void seekp(Int64 pos) override | void seekp(exr_file_offset_t pos) override | ||||
| { | { | ||||
| offset = pos; | offset = pos; | ||||
| ensure_size(offset); | ensure_size(offset); | ||||
| } | } | ||||
| private: | private: | ||||
| void ensure_size(Int64 size) | void ensure_size(exr_file_offset_t size) | ||||
| { | { | ||||
| /* if buffer is too small increase it. */ | /* if buffer is too small increase it. */ | ||||
| while (size > ibuf->encodedbuffersize) { | while (size > ibuf->encodedbuffersize) { | ||||
| if (!imb_enlargeencodedbufferImBuf(ibuf)) { | if (!imb_enlargeencodedbufferImBuf(ibuf)) { | ||||
| throw Iex::ErrnoExc("Out of memory."); | throw Iex::ErrnoExc("Out of memory."); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| Int64 offset; | exr_file_offset_t offset; | ||||
| }; | }; | ||||
| /* File Output Stream */ | /* File Output Stream */ | ||||
| class OFileStream : public OStream { | class OFileStream : public OStream { | ||||
| public: | public: | ||||
| OFileStream(const char *filename) : OStream(filename) | OFileStream(const char *filename) : OStream(filename) | ||||
| { | { | ||||
| Show All 13 Lines | #endif | ||||
| void write(const char c[], int n) override | void write(const char c[], int n) override | ||||
| { | { | ||||
| errno = 0; | errno = 0; | ||||
| ofs.write(c, n); | ofs.write(c, n); | ||||
| check_error(); | check_error(); | ||||
| } | } | ||||
| Int64 tellp() override | exr_file_offset_t tellp() override | ||||
| { | { | ||||
| return std::streamoff(ofs.tellp()); | return std::streamoff(ofs.tellp()); | ||||
| } | } | ||||
| void seekp(Int64 pos) override | void seekp(exr_file_offset_t pos) override | ||||
| { | { | ||||
| ofs.seekp(pos); | ofs.seekp(pos); | ||||
| check_error(); | check_error(); | ||||
| } | } | ||||
| private: | private: | ||||
| void check_error() | void check_error() | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 1,816 Lines • Show Last 20 Lines | |||||
Note that the old Int64 defined by OpenEXR 2 was in fact unsigned, so this works for both.