Skip to content

Commit

Permalink
New attrib "oiio:subimages" says number of subimages, if known (#2344)
Browse files Browse the repository at this point in the history
It's the number of frames for movie files, number of subimages for
other files.

Set and positive only if it can be known inexpensively from the file
header. If absent or zero, it means there was no easy way to determine
the number of frames or subimage from just reading the header (in that
case, you'll have to discover the subimages the old fashioned way,
repeatedly seeking to subimages until you fail).
  • Loading branch information
lgritz committed Sep 20, 2019
1 parent 195b3e8 commit 46862d8
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/doc/builtinplugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,12 @@ Some special attributes are used for movie files:
* - ``oiio:Movie``
- int
- Nonzero value for movie files
* - ``oiio:subimages``
- int
- The number of frames in the movie, positive if it can be known
without reading the entire file. Zero or not present if the number
of frames cannot be determinend from reading from just the file
header.
* - ``FramesPerSecond``
- int[2] (rational)
- Frames per second
Expand Down
9 changes: 9 additions & 0 deletions src/doc/stdmetadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ Display hints
If nonzero, a hint that a multi-image file is meant to be interpreted as
an animation (i.e., that the subimages are a time sequence).

.. option:: "oiio:subimages" : int

If nonzero, the number of subimages in the file. Not all image file
formats can know this without reading the entire file, and in such
cases, this attribute will not be set or will be 0. If the value is
present and greater than zero, it can be trusted, but if not, nothing
should be inferred and you will have to repeatedly seek to subimages
to find out how many there are.

.. option:: "FramesPerSecond" : rational

For a multi-image file intended to be played back as an animation, the
Expand Down
1 change: 1 addition & 0 deletions src/ffmpeg.imageio/ffmpeginput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ FFmpegInput::open(const std::string& name, ImageSpec& spec)
int rat[2] = { m_frame_rate.num, m_frame_rate.den };
m_spec.attribute("FramesPerSecond", TypeRational, &rat);
m_spec.attribute("oiio:Movie", true);
m_spec.attribute("oiio:subimages", int(m_frames));
m_spec.attribute("oiio:BitsPerSample",
m_codec_context->bits_per_raw_sample);
m_nsubimages = m_frames;
Expand Down
2 changes: 2 additions & 0 deletions src/openexr.imageio/exrinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ OpenEXRInput::PartInfo::parse_header(OpenEXRInput* in,
if (header->hasName() && header->name() != "")
spec.attribute("oiio:subimagename", header->name());

spec.attribute("oiio:subimages", in->m_nsubimages);

// Squash some problematic texture metadata if we suspect it's wrong
pvt::check_texture_metadata_sanity(spec);

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 @@ -7,6 +7,7 @@ out.exr : 64 x 64, 6 channel, half openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
Reading out2.exr
out2.exr : 64 x 64, 6 channel, half openexr
SHA-1: 6FECD5769C727E137B7580AE3B1823B06EE6F9D9
Expand All @@ -18,4 +19,5 @@ out2.exr : 64 x 64, 6 channel, half openexr
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimagename: "Aimg"
oiio:subimages: 1
openexr:chunkCount: 4
3 changes: 3 additions & 0 deletions testsuite/maketx/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ nan.exr : 64 x 64, 3 channel, half openexr
oiio:AverageColor: "0.5,0.5,0.5"
oiio:ColorSpace: "Linear"
oiio:SHA-1: "44B96A7C3AFBF8D7621E7C6453266E5DD1962D36"
oiio:subimages: 1
openexr:levelmode: 0
Stats Min: 0.000000 0.000000 0.000000 (float)
Stats Max: 1.000000 1.000000 1.000000 (float)
Expand Down Expand Up @@ -305,6 +306,7 @@ checker-exr.pdq : 128 x 128, 4 channel, half openexr
oiio:AverageColor: "0.5,0.5,0.5,1"
oiio:ColorSpace: "Linear"
oiio:SHA-1: "D924CA144A02479D1507F5910F5FC8F51EF78765"
oiio:subimages: 1
openexr:roundingmode: 0
Reading small.tif
small.tif : 64 x 64, 3 channel, uint8 tiff
Expand Down Expand Up @@ -395,4 +397,5 @@ 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:ColorSpace: "Linear"
oiio:SHA-1: "49B533110A914CE89BE0B14753A6A4CC037C964F"
oiio:subimages: 1
openexr:roundingmode: 0
2 changes: 2 additions & 0 deletions testsuite/oiiotool-copy/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ nometamerge.exr : 64 x 64, 6 channel, float openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
Reading metamerge.exr
metamerge.exr : 64 x 64, 6 channel, float openexr
SHA-1: 9F13A523321C66208E90D45F87FA0CD9B370E111
Expand All @@ -41,3 +42,4 @@ metamerge.exr : 64 x 64, 6 channel, float openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
3 changes: 3 additions & 0 deletions testsuite/oiiotool-fixnan/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ src/bad.exr : 64 x 64, 3 channel, half openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
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 All @@ -25,6 +26,7 @@ black.exr : 64 x 64, 3 channel, half openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
Stats Min: 0.000000 0.000000 0.000000 (float)
Stats Max: 1.000000 1.000000 1.000000 (float)
Stats Avg: 0.499756 0.500000 0.500000 (float)
Expand All @@ -43,6 +45,7 @@ box3.exr : 64 x 64, 3 channel, half openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
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
2 changes: 2 additions & 0 deletions testsuite/oiiotool-maketx/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ nan.exr : 64 x 64, 3 channel, half openexr
oiio:AverageColor: "0.5,0.5,0.5"
oiio:ColorSpace: "Linear"
oiio:SHA-1: "44B96A7C3AFBF8D7621E7C6453266E5DD1962D36"
oiio:subimages: 1
openexr:levelmode: 0
Stats Min: 0.000000 0.000000 0.000000 (float)
Stats Max: 1.000000 1.000000 1.000000 (float)
Expand Down Expand Up @@ -305,6 +306,7 @@ checker-exr.pdq : 128 x 128, 4 channel, half openexr
oiio:AverageColor: "0.5,0.5,0.5,1"
oiio:ColorSpace: "Linear"
oiio:SHA-1: "D924CA144A02479D1507F5910F5FC8F51EF78765"
oiio:subimages: 1
openexr:roundingmode: 0
Reading grid.tx
oiio:SHA-1: "9B24D4CC05313A43973AC384718D81D19183B691"
Expand Down
4 changes: 4 additions & 0 deletions testsuite/oiiotool/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ chname.exr : 38 x 38, 5 channel, float openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
Reading allhalf.exr
allhalf.exr : 38 x 38, 5 channel, half openexr
SHA-1: 1C71682E8D8F6DCDC2A7A7B23842DFEEC51438F2
Expand All @@ -30,6 +31,7 @@ allhalf.exr : 38 x 38, 5 channel, half openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
Reading rgbahalf-zfloat.exr
rgbahalf-zfloat.exr : 38 x 38, 5 channel, half/half/half/half/float openexr
SHA-1: 9324AFD44451321A8D87E09F656C7B86E827E5CD
Expand All @@ -43,6 +45,7 @@ rgbahalf-zfloat.exr : 38 x 38, 5 channel, half/half/half/half/float openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
copyA.0001.jpg : 128 x 96, 3 channel, uint8 jpeg
copyA.0002.jpg : 128 x 96, 3 channel, uint8 jpeg
copyA.0003.jpg : 128 x 96, 3 channel, uint8 jpeg
Expand Down Expand Up @@ -89,6 +92,7 @@ add_rgb_rgba.exr : 64 x 64, 4 channel, float openexr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
Comparing "filled.tif" and "ref/filled.tif"
PASS
Comparing "autotrim.tif" and "ref/autotrim.tif"
Expand Down
1 change: 1 addition & 0 deletions testsuite/openexr-chroma/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Reading ../../../../../openexr-images/LuminanceChroma/Garden.exr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
Comparing "../../../../../openexr-images/LuminanceChroma/Garden.exr" and "Garden.exr"
PASS
13 changes: 13 additions & 0 deletions testsuite/openexr-multires/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Reading ../../../../../openexr-images/MultiResolution/Bonita.exr
textureformat: "Plain Texture"
wrapmodes: "clamp,clamp"
oiio:ColorSpace: "Linear"
oiio:subimages: 1
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/Bonita.exr" and "Bonita.exr"
PASS
Expand All @@ -31,6 +32,7 @@ Reading ../../../../../openexr-images/MultiResolution/ColorCodedLevels.exr
textureformat: "Plain Texture"
wrapmodes: "periodic,periodic"
oiio:ColorSpace: "Linear"
oiio:subimages: 1
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/ColorCodedLevels.exr" and "ColorCodedLevels.exr"
PASS
Expand All @@ -50,6 +52,7 @@ Reading ../../../../../openexr-images/MultiResolution/KernerEnvCube.exr
textureformat: "CubeFace Environment"
oiio:ColorSpace: "Linear"
oiio:sampleborder: 1
oiio:subimages: 1
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/KernerEnvCube.exr" and "KernerEnvCube.exr"
PASS
Expand All @@ -67,6 +70,7 @@ Reading ../../../../../openexr-images/MultiResolution/KernerEnvLatLong.exr
textureformat: "LatLong Environment"
oiio:ColorSpace: "Linear"
oiio:sampleborder: 1
oiio:subimages: 1
oiio:updirection: "y"
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/KernerEnvLatLong.exr" and "KernerEnvLatLong.exr"
Expand All @@ -85,6 +89,7 @@ Reading ../../../../../openexr-images/MultiResolution/MirrorPattern.exr
textureformat: "Plain Texture"
wrapmodes: "mirror,mirror"
oiio:ColorSpace: "Linear"
oiio:subimages: 1
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/MirrorPattern.exr" and "MirrorPattern.exr"
PASS
Expand All @@ -104,6 +109,7 @@ Reading ../../../../../openexr-images/MultiResolution/OrientationCube.exr
textureformat: "CubeFace Environment"
oiio:ColorSpace: "Linear"
oiio:sampleborder: 1
oiio:subimages: 1
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/OrientationCube.exr" and "OrientationCube.exr"
PASS
Expand All @@ -121,6 +127,7 @@ Reading ../../../../../openexr-images/MultiResolution/OrientationLatLong.exr
textureformat: "LatLong Environment"
oiio:ColorSpace: "Linear"
oiio:sampleborder: 1
oiio:subimages: 1
oiio:updirection: "y"
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/OrientationLatLong.exr" and "OrientationLatLong.exr"
Expand All @@ -139,6 +146,7 @@ Reading ../../../../../openexr-images/MultiResolution/PeriodicPattern.exr
textureformat: "Plain Texture"
wrapmodes: "periodic,periodic"
oiio:ColorSpace: "Linear"
oiio:subimages: 1
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/PeriodicPattern.exr" and "PeriodicPattern.exr"
PASS
Expand All @@ -158,6 +166,7 @@ Reading ../../../../../openexr-images/MultiResolution/StageEnvCube.exr
textureformat: "CubeFace Environment"
oiio:ColorSpace: "Linear"
oiio:sampleborder: 1
oiio:subimages: 1
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/StageEnvCube.exr" and "StageEnvCube.exr"
PASS
Expand All @@ -175,6 +184,7 @@ Reading ../../../../../openexr-images/MultiResolution/StageEnvLatLong.exr
textureformat: "LatLong Environment"
oiio:ColorSpace: "Linear"
oiio:sampleborder: 1
oiio:subimages: 1
oiio:updirection: "y"
openexr:roundingmode: 1
Comparing "../../../../../openexr-images/MultiResolution/StageEnvLatLong.exr" and "StageEnvLatLong.exr"
Expand All @@ -195,6 +205,7 @@ Reading ../../../../../openexr-images/MultiResolution/WavyLinesCube.exr
textureformat: "CubeFace Environment"
oiio:ColorSpace: "Linear"
oiio:sampleborder: 1
oiio:subimages: 1
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/WavyLinesCube.exr" and "WavyLinesCube.exr"
PASS
Expand All @@ -212,6 +223,7 @@ Reading ../../../../../openexr-images/MultiResolution/WavyLinesLatLong.exr
textureformat: "LatLong Environment"
oiio:ColorSpace: "Linear"
oiio:sampleborder: 1
oiio:subimages: 1
oiio:updirection: "y"
openexr:roundingmode: 0
Comparing "../../../../../openexr-images/MultiResolution/WavyLinesLatLong.exr" and "WavyLinesLatLong.exr"
Expand All @@ -226,5 +238,6 @@ Reading ../../../../../openexr-images/MultiResolution/WavyLinesSphere.exr
screenWindowCenter: 0, 0
screenWindowWidth: 1
oiio:ColorSpace: "Linear"
oiio:subimages: 1
Comparing "../../../../../openexr-images/MultiResolution/WavyLinesSphere.exr" and "WavyLinesSphere.exr"
PASS

0 comments on commit 46862d8

Please sign in to comment.