AcademySoftwareFoundation / AcademySoftwareFoundation/OpenImageIO

[BUG] OpenEXR PixelAspectRatio

Open
#4,083 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.4k
Forks
698
Avg merge
3d 9h
Merged PRs (30d)
48

Description

**Describe the bug**

The PixelAspectRatio metadata is not always propagated in the right way to an exr image whether it is set as a float or as a string.
It must be set as a float to be correctly propagated.
However, when reading back as a float in the image spec, just after the setting as a string, the returned value is correct.

**To Reproduce**
Switch the 2 commented lines of the following code between setting as a float and setting as a string.

```
const std::string filename = "simple.exr";
const int xres = 320, yres = 240, channels = 3;
float pixels[xres * yres * channels] = { 0.5f };
std::unique_ptr out = OIIO::ImageOutput::create(filename);
if (out)
{
std::cout << "save exr file ..." << std::endl;
OIIO::ImageSpec spec_out(xres, yres, channels, OIIO::TypeDesc::FLOAT);

float par = 2.0f;
spec_out.attribute("PixelAspectRatio", par);
//std::string par = "2.0";
//spec_out.attribute("PixelAspectRatio", par);

float par_read = spec_out.get_float_attribute("PixelAspectRatio", 4.0);
std::cout << "PAR read in image spec before saving: " << par_read << std::endl;

out->open(filename, spec_out);
out->write_image(OIIO::TypeDesc::FLOAT, pixels);
out->close();

std::unique_ptr in(OIIO::ImageInput::open(filename));
if (in)
{
std::cout << "read exr file metadata ..." << std::endl;

OIIO::ImageSpec spec_in = in->spec();
in->close();

float parFromNewImage;
spec_in.getattribute("PixelAspectRatio", OIIO::TypeDesc::FLOAT, &parFromNewImage);

std::cout << "PAR read in image spec of saved image: " << parFromNewImage << std::endl;
}
else
{
std::cout << "cannot read the new exr file !!!" << std::endl;
}
}
else
{
std::cout << "cannot create a new exr file !!!" << std::endl;
}

```

**Expected behavior**
What we get when setting as a float (expected behavior):
```
save exr file ...
PAR read in image spec before saving: 2
read exr file metadata ...
PAR read in image spec of saved image: 2
```

**Evidence**
What we get when setting as a string:
```
save exr file ...
PAR read in image spec before saving: 2
read exr file metadata ...
PAR read in image spec of saved image: 1
```

**Platform information:**
- OIIO branch/version: pick up from vcpkg
- OS: Windows
- C++ compiler: Visual Studio 2022
- Any non-default build flags when you build OIIO:

Contributor guide

Open the contributing guide

Research direction

Start with the supplied ImageSpec::attribute and get_float_attribute reproduction, then trace the ImageOutput::create/OpenEXR write path and ImageInput::open metadata readback. Compare string and float PixelAspectRatio values in the saved image; done means both forms preserve the value 2 when read from the reopened image spec.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.