Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions src/libOpenImageIO/imagespec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const char* imagespec_xml_string = R"EOF(
<attrib name="screenWindowCenter" type="float2">0, 0</attrib>
<attrib name="screenWindowWidth" type="float">1</attrib>
<attrib name="oiio:subimages" type="int">1</attrib>
<attrib name="FramesPerSecond" type="rational">30000/1001</attrib>
</ImageSpec>
)EOF";

Expand Down Expand Up @@ -358,6 +359,20 @@ test_imagespec_from_xml()
OIIO_CHECK_EQUAL(spec.format, TypeFloat);
OIIO_CHECK_EQUAL(spec.get_string_attribute("oiio:ColorSpace"),
"scene_linear");
OIIO_CHECK_EQUAL(spec.getattributetype("FramesPerSecond"), TypeRational);
OIIO_CHECK_EQUAL_THRESH(spec.get_float_attribute("FramesPerSecond", -1.0f),
30000.0f / 1001.0f, 1.0e-5f);

std::string xml = spec.to_xml();
OIIO_CHECK_ASSERT(xml.find("name=\"FramesPerSecond\" type=\"rational\"")
!= std::string::npos);
ImageSpec roundtripped;
roundtripped.from_xml(xml.c_str());
OIIO_CHECK_EQUAL(roundtripped.getattributetype("FramesPerSecond"),
TypeRational);
OIIO_CHECK_EQUAL_THRESH(roundtripped.get_float_attribute("FramesPerSecond",
-1.0f),
30000.0f / 1001.0f, 1.0e-5f);
}


Expand Down
10 changes: 9 additions & 1 deletion src/libutil/paramlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,15 @@ parse_elements(string_view value, ParamValue& p)
ParamValue::ParamValue(string_view name, TypeDesc type, string_view value)
: ParamValue(name, type, 1, cspan<std::byte>())
{
if (type.basetype == TypeDesc::INT) {
if (type == TypeRational || type == TypeURational) {
// Accept either "x,y" or "x/y" here
std::string rational_values(value);
Comment thread
ayushactiveat marked this conversation as resolved.
std::replace(rational_values.begin(), rational_values.end(), '/', ',');
if (type.basetype == TypeDesc::INT)
parse_elements<int>(rational_values, *this);
else if (type.basetype == TypeDesc::UINT)
parse_elements<unsigned int>(rational_values, *this);
} else if (type.basetype == TypeDesc::INT) {
parse_elements<int>(value, *this);
} else if (type.basetype == TypeDesc::UINT) {
parse_elements<unsigned int>(value, *this);
Expand Down
20 changes: 10 additions & 10 deletions src/libutil/typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ TypeDesc::c_str() const
result = Strutil::fmt::format("matrix{}", basetype_code[basetype]);
break;
}
} else if (vecsemantics == RATIONAL && (*this == TypeRational || *this == TypeURational)) {
result = (basetype == TypeDesc::INT) ? "rational" : "urational";
} else if (vecsemantics == BOX) {
result = Strutil::fmt::format("box{}{}", int(aggregate),
basetype == FLOAT
? ""
: basetype_code[basetype]);
alen = arraylen > 2 ? (arraylen / 2) : (arraylen < 0 ? -1 : 0);
} else {
// Special names for vector semantics
const char* vec = "";
Expand All @@ -237,14 +245,6 @@ TypeDesc::c_str() const
if (basetype != FLOAT)
result += basetype_code[basetype];
}
// More unusual cases
if (vecsemantics == BOX) {
result = Strutil::fmt::format("box{}{}", int(aggregate),
basetype == FLOAT
? ""
: basetype_code[basetype]);
alen = arraylen > 2 ? (arraylen / 2) : (arraylen < 0 ? -1 : 0);
}
if (alen > 0)
result += Strutil::fmt::format("[{}]", alen);
else if (alen < 0)
Expand Down Expand Up @@ -323,9 +323,9 @@ TypeDesc::fromstring(string_view typestring)
t = OIIO::TypeFloat4;
else if (type == "timecode")
t = OIIO::TypeTimeCode;
else if (type == "rational")
else if (type == "rational" || type == "rational2i")
t = OIIO::TypeRational;
else if (type == "urational")
else if (type == "urational" || type == "rational2u")
t = OIIO::TypeURational;
else if (type == "box2i")
t = OIIO::TypeBox2i;
Expand Down
2 changes: 2 additions & 0 deletions src/libutil/typedesc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ main(int /*argc*/, char* /*argv*/[])
TypeDesc(TypeDesc::INT, TypeDesc::VEC2,
TypeDesc::RATIONAL),
TypeRational, i2, "1/2");
OIIO_CHECK_EQUAL(TypeDesc("rational"), TypeRational);
OIIO_CHECK_EQUAL(TypeDesc("urational"), TypeURational);
uint32_t ui2[2] = { 1, 2 };
test_type<uint32_t[2]>("urational",
TypeDesc(TypeDesc::UINT32, TypeDesc::VEC2,
Expand Down