Skip to content

Commit

Permalink
fix(exr): fill in OpenEXR lineOrder attribute when reading (#4628)
Browse files Browse the repository at this point in the history
Fill in OpenEXR lineOrder attribute when parsing the header in
OpenEXRCoreInput::PartInfo::parse_header()

---------

Signed-off-by: vernalchen <[email protected]>
  • Loading branch information
vernalchen authored and lgritz committed Feb 8, 2025
1 parent 8191f12 commit cab32b6
Show file tree
Hide file tree
Showing 28 changed files with 183 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/openexr.imageio/exrinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ OIIO_GCC_PRAGMA(GCC diagnostic ignored "-Wunused-parameter")
#include <OpenEXR/ImfInputPart.h>
#include <OpenEXR/ImfIntAttribute.h>
#include <OpenEXR/ImfKeyCodeAttribute.h>
#include <OpenEXR/ImfLineOrderAttribute.h>
#include <OpenEXR/ImfMatrixAttribute.h>
#include <OpenEXR/ImfMultiPartInputFile.h>
#include <OpenEXR/ImfPartType.h>
Expand Down Expand Up @@ -128,7 +129,6 @@ static std::map<std::string, std::string> exr_tag_to_oiio_std {
{ "envmap", "" },
{ "tiledesc", "" },
{ "tiles", "" },
{ "openexr:lineOrder", "" },
{ "type", "" },

// FIXME: Things to consider in the future:
Expand Down Expand Up @@ -467,6 +467,7 @@ OpenEXRInput::PartInfo::parse_header(OpenEXRInput* in,
const Imf::V3dAttribute* v3dattr;
const Imf::M33dAttribute* m33dattr;
const Imf::M44dAttribute* m44dattr;
const Imf::LineOrderAttribute* lattr;
const char* name = hit.name();
auto found = exr_tag_to_oiio_std.find(name);
std::string oname(found != exr_tag_to_oiio_std.end() ? found->second
Expand Down Expand Up @@ -635,6 +636,18 @@ OpenEXRInput::PartInfo::parse_header(OpenEXRInput* in,
oname, n, d);
}
}
} else if (type == "lineOrder"
&& (lattr
= header->findTypedAttribute<Imf::LineOrderAttribute>(
name))) {
const char* lineOrder = "increasingY";
switch (lattr->value()) {
case Imf::INCREASING_Y: lineOrder = "increasingY"; break;
case Imf::DECREASING_Y: lineOrder = "decreasingY"; break;
case Imf::RANDOM_Y: lineOrder = "randomY"; break;
default: break;
}
spec.attribute("openexr:lineOrder", lineOrder);
} else {
#if 0
print(std::cerr, " unknown attribute '{}' name '{}'\n",
Expand Down
14 changes: 12 additions & 2 deletions src/openexr.imageio/exrinput_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ static std::map<std::string, std::string> cexr_tag_to_oiio_std {
{ "envmap", "" },
{ "tiledesc", "" },
{ "tiles", "" },
{ "openexr:lineOrder", "" },
{ "type", "" },

// FIXME: Things to consider in the future:
Expand Down Expand Up @@ -729,12 +728,23 @@ OpenEXRCoreInput::PartInfo::parse_header(OpenEXRCoreInput* in,
break;
}

case EXR_ATTR_LINEORDER: {
std::string lineOrder = "increasingY";
switch (attr->uc) {
case EXR_LINEORDER_INCREASING_Y: lineOrder = "increasingY"; break;
case EXR_LINEORDER_DECREASING_Y: lineOrder = "decreasingY"; break;
case EXR_LINEORDER_RANDOM_Y: lineOrder = "randomY"; break;
default: break;
}
spec.attribute("openexr:lineOrder", lineOrder);
break;
}

case EXR_ATTR_PREVIEW:
case EXR_ATTR_OPAQUE:
case EXR_ATTR_ENVMAP:
case EXR_ATTR_COMPRESSION:
case EXR_ATTR_CHLIST:
case EXR_ATTR_LINEORDER:
case EXR_ATTR_TILEDESC:
default:
#if 0
Expand Down
2 changes: 2 additions & 0 deletions testsuite/dup-channels/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ out.exr : 64 x 64, 6 channel, half openexr
screenWindowWidth: 1
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Reading out2.exr
out2.exr : 64 x 64, 6 channel, half openexr
SHA-1: 6FECD5769C727E137B7580AE3B1823B06EE6F9D9
Expand All @@ -21,3 +22,4 @@ out2.exr : 64 x 64, 6 channel, half openexr
oiio:subimagename: "Aimg"
oiio:subimages: 1
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
4 changes: 4 additions & 0 deletions testsuite/iinfo/ref/out-fmt6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ src/tiny-az.exr : Software: "OpenImageIO 2.5.0.0spi : oiiotool -pattern cons
src/tiny-az.exr : Exif:ImageHistory: "oiiotool -pattern constant:color=0.25,0.5,0.75 4x4 3 --origin +2+2 --fullsize 20x20+1+1 -o tiny-az.exr"
src/tiny-az.exr : oiio:ColorSpace: "lin_rec709"
src/tiny-az.exr : oiio:subimages: 1
src/tiny-az.exr : openexr:lineOrder: "increasingY"
src/tiny-az.exr : Stats Min: 0.250000 0.500000 0.750000 (float)
Stats Max: 0.250000 0.500000 0.750000 (float)
Stats Avg: 0.250000 0.500000 0.750000 (float)
Expand Down Expand Up @@ -176,6 +177,7 @@ src/tiny-az.exr : 4 x 4, 3 channel, float openexr
Exif:ImageHistory: "oiiotool -pattern constant:color=0.25,0.5,0.75 4x4 3 --origin +2+2 --fullsize 20x20+1+1 -o tiny-az.exr"
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Pixel (2, 2): 0.250000000 0.500000000 0.750000000
Pixel (3, 2): 0.250000000 0.500000000 0.750000000
Pixel (4, 2): 0.250000000 0.500000000 0.750000000
Expand Down Expand Up @@ -215,6 +217,7 @@ src/tinydeep.exr : 4 x 4, 2 channel, deep float openexr
Exif:ImageHistory: "oiiotool -pattern constant:color=1e38,0 4x4 2 --chnames Z,A --point:color=10.0,1.0 2,2 --deepen -o tinydeep.exr"
oiio:subimages: 1
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Stats Min: 1.000000 10.000000 (float)
Stats Max: 1.000000 10.000000 (float)
Stats Avg: 1.000000 10.000000 (float)
Expand Down Expand Up @@ -249,6 +252,7 @@ src/tinydeep.exr : 4 x 4, 2 channel, deep float openexr
Exif:ImageHistory: "oiiotool -pattern constant:color=1e38,0 4x4 2 --chnames Z,A --point:color=10.0,1.0 2,2 --deepen -o tinydeep.exr"
oiio:subimages: 1
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Pixel (0, 0): 0 samples
Pixel (1, 0): 0 samples
Pixel (2, 0): 0 samples
Expand Down
4 changes: 4 additions & 0 deletions testsuite/iinfo/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ src/tiny-az.exr : Software: "OpenImageIO 2.5.0.0spi : oiiotool -pattern cons
src/tiny-az.exr : Exif:ImageHistory: "oiiotool -pattern constant:color=0.25,0.5,0.75 4x4 3 --origin +2+2 --fullsize 20x20+1+1 -o tiny-az.exr"
src/tiny-az.exr : oiio:ColorSpace: "lin_rec709"
src/tiny-az.exr : oiio:subimages: 1
src/tiny-az.exr : openexr:lineOrder: "increasingY"
src/tiny-az.exr : Stats Min: 0.250000 0.500000 0.750000 (float)
Stats Max: 0.250000 0.500000 0.750000 (float)
Stats Avg: 0.250000 0.500000 0.750000 (float)
Expand Down Expand Up @@ -176,6 +177,7 @@ src/tiny-az.exr : 4 x 4, 3 channel, float openexr
Exif:ImageHistory: "oiiotool -pattern constant:color=0.25,0.5,0.75 4x4 3 --origin +2+2 --fullsize 20x20+1+1 -o tiny-az.exr"
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Pixel (2, 2): 0.250000000 0.500000000 0.750000000
Pixel (3, 2): 0.250000000 0.500000000 0.750000000
Pixel (4, 2): 0.250000000 0.500000000 0.750000000
Expand Down Expand Up @@ -215,6 +217,7 @@ src/tinydeep.exr : 4 x 4, 2 channel, deep float openexr
Exif:ImageHistory: "oiiotool -pattern constant:color=1e38,0 4x4 2 --chnames Z,A --point:color=10.0,1.0 2,2 --deepen -o tinydeep.exr"
oiio:subimages: 1
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Stats Min: 1.000000 10.000000 (float)
Stats Max: 1.000000 10.000000 (float)
Stats Avg: 1.000000 10.000000 (float)
Expand Down Expand Up @@ -249,6 +252,7 @@ src/tinydeep.exr : 4 x 4, 2 channel, deep float openexr
Exif:ImageHistory: "oiiotool -pattern constant:color=1e38,0 4x4 2 --chnames Z,A --point:color=10.0,1.0 2,2 --deepen -o tinydeep.exr"
oiio:subimages: 1
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Pixel (0, 0): 0 samples
Pixel (1, 0): 0 samples
Pixel (2, 0): 0 samples
Expand Down
5 changes: 5 additions & 0 deletions testsuite/maketx/ref/out-macarm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ nan.exr : 64 x 64, 3 channel, half openexr
oiio:SHA-1: "44B96A7C3AFBF8D7621E7C6453266E5DD1962D36"
oiio:subimages: 1
openexr:levelmode: 0
openexr:lineOrder: "increasingY"
Stats Min: 0.000000 0.000000 0.000000 (float)
Stats Max: 1.000000 1.000000 1.000000 (float)
Stats Avg: 0.500000 0.500000 0.500000 (float)
Expand Down Expand Up @@ -346,6 +347,7 @@ checker-exr.pdq : 128 x 128, 4 channel, half openexr
oiio:ColorSpace: "lin_rec709"
oiio:SHA-1: "D924CA144A02479D1507F5910F5FC8F51EF78765"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
openexr:roundingmode: 0
Reading small.tif
small.tif : 64 x 64, 3 channel, uint8 tiff
Expand Down Expand Up @@ -437,6 +439,7 @@ bumpslope.exr : 64 x 64, 6 channel, half openexr
oiio:AverageColor: "0.499779,-0.000457942,-4.17233e-05,0.00197116,0.00178894,3.45764e-05"
oiio:SHA-1: "49B533110A914CE89BE0B14753A6A4CC037C964F"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
openexr:roundingmode: 0
Reading cdf.exr
cdf.exr : 64 x 64, 1 channel, half openexr
Expand All @@ -457,6 +460,7 @@ cdf.exr : 64 x 64, 1 channel, half openexr
oiio:AverageColor: "0.499779"
oiio:SHA-1: "00DFB31D0260CC466CDCF9FE42446D4896E655FE"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
openexr:roundingmode: 0
Reading bumpslope-cdf.exr
bumpslope-cdf.exr : 64 x 64, 6 channel, half openexr
Expand Down Expand Up @@ -488,6 +492,7 @@ bumpslope-cdf.exr : 64 x 64, 6 channel, half openexr
oiio:AverageColor: "0.499779,-0.000457942,-4.17233e-05,0.00197116,0.00178894,3.45764e-05"
oiio:SHA-1: "49B533110A914CE89BE0B14753A6A4CC037C964F"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
openexr:roundingmode: 0
Reading checker-attribs.tx
checker-attribs.tx : 128 x 128, 4 channel, uint8 tiff
Expand Down
5 changes: 5 additions & 0 deletions testsuite/maketx/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ nan.exr : 64 x 64, 3 channel, half openexr
oiio:SHA-1: "44B96A7C3AFBF8D7621E7C6453266E5DD1962D36"
oiio:subimages: 1
openexr:levelmode: 0
openexr:lineOrder: "increasingY"
Stats Min: 0.000000 0.000000 0.000000 (float)
Stats Max: 1.000000 1.000000 1.000000 (float)
Stats Avg: 0.500000 0.500000 0.500000 (float)
Expand Down Expand Up @@ -346,6 +347,7 @@ checker-exr.pdq : 128 x 128, 4 channel, half openexr
oiio:ColorSpace: "lin_rec709"
oiio:SHA-1: "D924CA144A02479D1507F5910F5FC8F51EF78765"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
openexr:roundingmode: 0
Reading small.tif
small.tif : 64 x 64, 3 channel, uint8 tiff
Expand Down Expand Up @@ -437,6 +439,7 @@ bumpslope.exr : 64 x 64, 6 channel, half openexr
oiio:AverageColor: "0.499779,-0.000457942,-4.17233e-05,0.00197116,0.00178894,3.45764e-05"
oiio:SHA-1: "49B533110A914CE89BE0B14753A6A4CC037C964F"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
openexr:roundingmode: 0
Reading cdf.exr
cdf.exr : 64 x 64, 1 channel, half openexr
Expand All @@ -457,6 +460,7 @@ cdf.exr : 64 x 64, 1 channel, half openexr
oiio:AverageColor: "0.499779"
oiio:SHA-1: "00DFB31D0260CC466CDCF9FE42446D4896E655FE"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
openexr:roundingmode: 0
Reading bumpslope-cdf.exr
bumpslope-cdf.exr : 64 x 64, 6 channel, half openexr
Expand Down Expand Up @@ -488,6 +492,7 @@ bumpslope-cdf.exr : 64 x 64, 6 channel, half openexr
oiio:AverageColor: "0.499779,-0.000457942,-4.17233e-05,0.00197116,0.00178894,3.45764e-05"
oiio:SHA-1: "49B533110A914CE89BE0B14753A6A4CC037C964F"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
openexr:roundingmode: 0
Reading checker-attribs.tx
checker-attribs.tx : 128 x 128, 4 channel, uint8 tiff
Expand Down
4 changes: 4 additions & 0 deletions testsuite/oiiotool-attribs/ref/out-jpeg9d.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ attrib2.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "subimage00"
oiio:subimages: 2
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
subimage 1: 64 x 64, 3 channel, half openexr
SHA-1: EBDD38B69CD5B9F2D00D273C981E16960FBBB4F7
channel list: R, G, B
Expand All @@ -85,6 +86,7 @@ attrib2.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "subimage01"
oiio:subimages: 2
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Reading attrib0.exr
attrib0.exr : 64 x 64, 3 channel, half openexr
2 subimages: 64x64 [h,h,h], 64x64 [h,h,h]
Expand All @@ -100,6 +102,7 @@ attrib0.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "subimage00"
oiio:subimages: 2
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
subimage 1: 64 x 64, 3 channel, half openexr
SHA-1: EBDD38B69CD5B9F2D00D273C981E16960FBBB4F7
channel list: R, G, B
Expand All @@ -112,6 +115,7 @@ attrib0.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "subimage01"
oiio:subimages: 2
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Reading tahoe-icc.jpg
tahoe-icc.jpg : 128 x 96, 3 channel, uint8 jpeg
SHA-1: 9119399610EF6CACDAD0EBAF4D663E4EDEF70B58
Expand Down
4 changes: 4 additions & 0 deletions testsuite/oiiotool-attribs/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ attrib2.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "subimage00"
oiio:subimages: 2
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
subimage 1: 64 x 64, 3 channel, half openexr
SHA-1: EBDD38B69CD5B9F2D00D273C981E16960FBBB4F7
channel list: R, G, B
Expand All @@ -85,6 +86,7 @@ attrib2.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "subimage01"
oiio:subimages: 2
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Reading attrib0.exr
attrib0.exr : 64 x 64, 3 channel, half openexr
2 subimages: 64x64 [h,h,h], 64x64 [h,h,h]
Expand All @@ -100,6 +102,7 @@ attrib0.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "subimage00"
oiio:subimages: 2
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
subimage 1: 64 x 64, 3 channel, half openexr
SHA-1: EBDD38B69CD5B9F2D00D273C981E16960FBBB4F7
channel list: R, G, B
Expand All @@ -112,6 +115,7 @@ attrib0.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "subimage01"
oiio:subimages: 2
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Reading tahoe-icc.jpg
tahoe-icc.jpg : 128 x 96, 3 channel, uint8 jpeg
SHA-1: BC4C6090E793819E1A2869AAA8FBEE3587CC6947
Expand Down
7 changes: 7 additions & 0 deletions testsuite/oiiotool-copy/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ allhalf.exr : 38 x 38, 5 channel, half openexr
screenWindowWidth: 1
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Reading rgbahalf-zfloat.exr
rgbahalf-zfloat.exr : 38 x 38, 5 channel, half/half/half/half/float openexr
SHA-1: 9324AFD44451321A8D87E09F656C7B86E827E5CD
Expand All @@ -28,6 +29,7 @@ rgbahalf-zfloat.exr : 38 x 38, 5 channel, half/half/half/half/float openexr
screenWindowWidth: 1
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
explicit -d uint save result:
uint8.tif : 128 x 128, 3 channel, uint8 tiff
tile size: 16 x 16
Expand Down Expand Up @@ -68,6 +70,7 @@ chname.exr : 38 x 38, 5 channel, float openexr
screenWindowWidth: 1
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Reading green.exr
green.exr : 64 x 64, 3 channel, half openexr
SHA-1: 8B61993247469F3C208CA894D71856727B11606A
Expand All @@ -78,6 +81,7 @@ green.exr : 64 x 64, 3 channel, half openexr
screenWindowWidth: 1
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Reading greenmeta.exr
greenmeta.exr : 64 x 64, 3 channel, half openexr
SHA-1: 8B61993247469F3C208CA894D71856727B11606A
Expand All @@ -91,6 +95,7 @@ greenmeta.exr : 64 x 64, 3 channel, half openexr
weight: 20.5
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Reading nometamerge.exr
nometamerge.exr : 64 x 64, 6 channel, float openexr
SHA-1: 9F13A523321C66208E90D45F87FA0CD9B370E111
Expand All @@ -102,6 +107,7 @@ nometamerge.exr : 64 x 64, 6 channel, float openexr
screenWindowWidth: 1
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Reading metamerge.exr
metamerge.exr : 64 x 64, 6 channel, float openexr
SHA-1: 9F13A523321C66208E90D45F87FA0CD9B370E111
Expand All @@ -114,6 +120,7 @@ metamerge.exr : 64 x 64, 6 channel, float openexr
screenWindowWidth: 1
oiio:ColorSpace: "lin_rec709"
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Testing -o with no image
oiiotool WARNING: -o : out.tif did not have any current image to output.
Comparing "rgonly.exr" and "ref/rgonly.exr"
Expand Down
3 changes: 3 additions & 0 deletions testsuite/oiiotool-deep/ref/out-fmt6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ allhalf.exr : 160 x 120, 2 channel, deep half openexr
worldToNDC: 2.41421, 0, 0, 0, 0, 3.21895, 0, 0, 0, 0, -1.00671, -1, 3.62132, 0, 3.92617, 4
oiio:subimages: 1
openexr:chunkCount: 6
openexr:lineOrder: "randomY"
Stats Min: 0.011902 3.031250 (float)
Stats Max: 0.261963 5.000000 (float)
Stats Avg: 0.082321 4.119433 (float)
Expand Down Expand Up @@ -57,6 +58,7 @@ swaptypes.exr : 160 x 120, 2 channel, deep float/half openexr
worldToNDC: 2.41421, 0, 0, 0, 0, 3.21895, 0, 0, 0, 0, -1.00671, -1, 3.62132, 0, 3.92617, 4
oiio:subimages: 1
openexr:chunkCount: 6
openexr:lineOrder: "randomY"
Stats Min: 0.011902 3.031250 (float)
Stats Max: 0.261963 5.000000 (float)
Stats Avg: 0.082321 4.119433 (float)
Expand Down Expand Up @@ -95,6 +97,7 @@ tinydeep.exr : 4 x 4, 2 channel, deep float openexr
version: 1
oiio:subimages: 1
openexr:chunkCount: 4
openexr:lineOrder: "increasingY"
Pixel (0, 0): 0 samples
Pixel (1, 0): 0 samples
Pixel (2, 0): 0 samples
Expand Down
Loading

0 comments on commit cab32b6

Please sign in to comment.