openexr icon indicating copy to clipboard operation
openexr copied to clipboard

Read header without reading file

Open Wagyx opened this issue 5 years ago • 1 comments

Hello, I have a very large EXR file with some additional custom attributes in the header. I want to access these custom attributes without loading the entire file since it is so large. The way I do it for now is:

    Imf::InputFile lFile(pFilename.c_str()); // loads the entire file
    Imf::Header lImfHeader = lFile.header(); // get the header

I have looked through the library for a function that would read the header only but could not find any. I may have missed it though.

Would someone help me, please ?

Wagyx avatar Sep 16 '20 13:09 Wagyx

That code won't read the pixels from the file, but will do a certain amount of memory allocation in preparation for that, which is slow with very large files.

This code reads the same amount of data from the file, but does less allocation, so should be faster.

    #include <OpenEXR/ImfMultiPartInputFile.h>

    Imf::MultiPartInputFile lFile(pFilename.c_str()); // load header(s) and chunk offset table(s)
    const Imf::Header& lImfHeader = lFile.header(0); // get the first header

(your code example also makes a copy of the header, which may be slow if you have a lot of attributes. A "const ref" as above will be much faster if you can do things that way)

peterhillman avatar Sep 16 '20 20:09 peterhillman