AcademySoftwareFoundation / openexr

The OpenEXR project provides the specification and reference implementation of the EXR file format, the professional-grade image storage format of the motion picture industry.
http://www.openexr.com/
BSD 3-Clause "New" or "Revised" License
1.64k stars 619 forks source link

Add proper python support for reading/writing header only #1813

Open cary-ilm opened 2 months ago

cary-ilm commented 2 months ago

Currently, constructing a File with header_only=true simply skips the reading of channel data, so a subsequent write doesn't do the right thing. Ideally, the write would do a block copy of the channel data from the old file to the new.

skurmedel commented 1 month ago

Hi Cary, I could take a look at this if you don't mind. Technically it wouldn't be my first contribution to OpenEXR but it would probably a bit more meaningful than fixing a typo :)

cary-ilm commented 1 month ago

Yes, thank you!

Check out what exrstdattr does, in src/bin/stdattr/main.cpp. It calls copyPixels() on the output part. You'll want to do something similar, but it will mean keeping track of the input part in a way the existing code does not.

skurmedel commented 1 month ago

Hi again. I made myself familiar with the code, and I made some progress on this.

However, I have a question about PyFile::parts, the current code indicates to me that one is not supposed to alter the references in PyFile::parts. Is this correct? Perhaps I've just missed some part of the documentation.

If I get a OpenEXR.File from somewhere, I can replace or add parts, as it is a standard Python list. For example, file.parts[0] = OpenEXR.Part(...) or file.parts.append(OpenEXR.Part()). But part indices of a PyFile are set through a private mechanism, at least from the Python users view.

The reason I ask is because if one replaces a part in PyFile::parts as above, we would sort of lose track of the source part. I guess one could check the references and detect that this has happened, but if modifying PyFile::parts this way is unsupported, then I could go for a much simpler mechanism.