Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1187 Read EXR files from memory #1448

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions testing/data/DATA_LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- 16bits.*: @bisechen: [CC0](https://creativecommons.org/publicdomain/zero/1.0/)
- (ノಠ益ಠ )ノ.vtp: VTK Data: BSD-3-Clause
- Rec709.exr: [Copyright 2006 Industrial Light & Magic](https://github.com/AcademySoftwareFoundation/openexr/blob/370db2835843ac75f85e1386c05455f26a6ff58c/website/test_images/Chromaticities/Rec709.rst): BSD-3-Clause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add `small.usdz: Copyright USD contributors: CC-BY 4.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the links please

- small.usdz: Copyright USD contributors: CC-BY 4.0

All other datasets are licensed under the BSD-3-Clause F3D license.

Expand Down
33 changes: 7 additions & 26 deletions vtkext/private/module/vtkF3DEXRReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
: Imf::IStream(name)
, buffer(static_cast<const char*>(buff))
, bufflen(static_cast<size_t>(bufferLen))
, pos(0)
{
}

Expand All @@ -37,16 +36,16 @@
pos += n;
return true;
}
return false;

Check warning on line 39 in vtkext/private/module/vtkF3DEXRReader.cxx

View check run for this annotation

Codecov / codecov/patch

vtkext/private/module/vtkF3DEXRReader.cxx#L39

Added line #L39 was not covered by tests
}

/**
* returns the current reading position, in bytes, from the beginning of the file.
* The next read() call will begin reading at the indicated position
*/
uint64_t tellg() override

Check warning on line 46 in vtkext/private/module/vtkF3DEXRReader.cxx

View check run for this annotation

Codecov / codecov/patch

vtkext/private/module/vtkF3DEXRReader.cxx#L46

Added line #L46 was not covered by tests
{
return pos;

Check warning on line 48 in vtkext/private/module/vtkF3DEXRReader.cxx

View check run for this annotation

Codecov / codecov/patch

vtkext/private/module/vtkF3DEXRReader.cxx#L48

Added line #L48 was not covered by tests
Copy link
Contributor

@Meakk Meakk Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this line covered? Do we need to override this function if it's not called?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from this page
https://openexr.com/en/latest/ReadingAndWritingImageFiles.html#low-level-i-o
it seems like that function needs to be overriden to be a proper interface

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure to follow that answer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if that method is not used you can just remove it ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a pure virtual function in the base class so i believe it needs an implementation. I can try removing it and see what happens. In the documentation i posted it says it needs an implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok lets try that. Maybe its needed in some case, but not in our case.

Copy link
Author

@nabielkandiel nabielkandiel Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not build without that function being implemented

error: cannot declare variable ‘memoryStream’ to be of abstract type ‘MemStream’
198 | MemStream memoryStream("EXRmemoryStream", this->MemoryBuffer, this->MemoryBufferLength);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, lets keep it in for now.

}

/**
Expand Down Expand Up @@ -86,13 +85,10 @@

// Setup filename to read the header
this->ComputeInternalFileName(this->DataExtent[4]);
if (this->InternalFileName == nullptr || this->InternalFileName[0] == '\0')
if ((this->InternalFileName == nullptr || this->InternalFileName[0] == '\0') &&
!this->MemoryBuffer)
{
// If we have no file then maybe we have the file in memory
if (!this->MemoryBuffer)
{
return;
}
return;
}

auto execute = [&](Imf::RgbaInputFile& file)
Expand Down Expand Up @@ -201,7 +197,6 @@

try
{
assert(this->InternalFileName);
Imf::setGlobalThreadCount(std::thread::hardware_concurrency());

if (this->MemoryBuffer)
Expand All @@ -212,6 +207,10 @@
}
else
{
if (!(this->InternalFileName))
{
throw std::invalid_argument("Not filename in EXR Reader when no Memory Buffer is set.");

Check warning on line 212 in vtkext/private/module/vtkF3DEXRReader.cxx

View check run for this annotation

Codecov / codecov/patch

vtkext/private/module/vtkF3DEXRReader.cxx#L212

Added line #L212 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this happen ?

Do you really need to throw here ? you could just error out ?

}
Imf::RgbaInputFile file(this->InternalFileName);
execute(file);
}
Expand All @@ -223,24 +222,6 @@
}
}

//------------------------------------------------------------------------------
/**
* Read from memory instead of file
*/
void vtkF3DEXRReader::SetMemoryBuffer(const void* buff)
{
MemoryBuffer = buff;
}

//------------------------------------------------------------------------------
/**
* Specify the in memory image buffer length.
*/
void vtkF3DEXRReader::SetMemoryBufferLength(vtkIdType bufferLen)
{
MemoryBufferLength = bufferLen;
}

//------------------------------------------------------------------------------
int vtkF3DEXRReader::GetWidth() const
{
Expand Down
10 changes: 0 additions & 10 deletions vtkext/private/module/vtkF3DEXRReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ class vtkF3DEXRReader : public vtkImageReader
return "OpenEXR";
}

/**
* Read from memory instead of file
*/
void SetMemoryBuffer(const void* buff) override;

/**
* Specify the in memory image buffer length.
*/
void SetMemoryBufferLength(vtkIdType buflen) override;

protected:
vtkF3DEXRReader();
~vtkF3DEXRReader() override;
Expand Down