Skip to content

Commit aa7fac0

Browse files
remiadoug-walker
andauthored
Add --bitdepth flag to ocioconvert (#2038)
Signed-off-by: Rémi Achard <[email protected]> Co-authored-by: Doug Walker <[email protected]>
1 parent a1c4367 commit aa7fac0

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

src/apps/ocioconvert/main.cpp

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ int main(int argc, const char **argv)
4949
std::vector<std::string> intAttrs;
5050
std::vector<std::string> stringAttrs;
5151

52+
std::string outputDepth;
53+
5254
bool usegpu = false;
5355
bool usegpuLegacy = false;
5456
bool outputgpuInfo = false;
@@ -84,6 +86,7 @@ int main(int argc, const char **argv)
8486
"--help", &help, "Display the help and exit",
8587
"-v" , &verbose, "Display general information",
8688
"<SEPARATOR>", "\nOpenImageIO or OpenEXR options:",
89+
"--bitdepth %s", &outputDepth, "Output image bitdepth",
8790
"--float-attribute %L", &floatAttrs, "\"name=float\" pair defining OIIO float attribute "
8891
"for outputimage",
8992
"--int-attribute %L", &intAttrs, "\"name=int\" pair defining an int attribute "
@@ -115,6 +118,31 @@ int main(int argc, const char **argv)
115118
}
116119
#endif // OCIO_GPU_ENABLED
117120

121+
OCIO::BitDepth userOutputBitDepth = OCIO::BIT_DEPTH_UNKNOWN;
122+
if (!outputDepth.empty())
123+
{
124+
if (outputDepth == "uint8")
125+
{
126+
userOutputBitDepth = OCIO::BIT_DEPTH_UINT8;
127+
}
128+
else if (outputDepth == "uint16")
129+
{
130+
userOutputBitDepth = OCIO::BIT_DEPTH_UINT16;
131+
}
132+
else if (outputDepth == "half")
133+
{
134+
userOutputBitDepth = OCIO::BIT_DEPTH_F16;
135+
}
136+
else if (outputDepth == "float")
137+
{
138+
userOutputBitDepth = OCIO::BIT_DEPTH_F32;
139+
}
140+
else
141+
{
142+
throw OCIO::Exception("Unsupported output bitdepth, must be uint8, uint16, half or float.");
143+
}
144+
}
145+
118146
const char * inputimage = nullptr;
119147
const char * inputcolorspace = nullptr;
120148
const char * outputimage = nullptr;
@@ -477,17 +505,24 @@ int main(int argc, const char **argv)
477505
const OCIO::BitDepth inputBitDepth = imgInput.getBitDepth();
478506
OCIO::BitDepth outputBitDepth;
479507

480-
if (inputBitDepth == OCIO::BIT_DEPTH_UINT16 || inputBitDepth == OCIO::BIT_DEPTH_F32)
508+
if (userOutputBitDepth != OCIO::BIT_DEPTH_UNKNOWN)
481509
{
482-
outputBitDepth = OCIO::BIT_DEPTH_F32;
483-
}
484-
else if (inputBitDepth == OCIO::BIT_DEPTH_UINT8 || inputBitDepth == OCIO::BIT_DEPTH_F16)
485-
{
486-
outputBitDepth = OCIO::BIT_DEPTH_F16;
510+
outputBitDepth = userOutputBitDepth;
487511
}
488512
else
489513
{
490-
throw OCIO::Exception("Unsupported input bitdepth, must be uint8, uint16, half or float.");
514+
if (inputBitDepth == OCIO::BIT_DEPTH_UINT16 || inputBitDepth == OCIO::BIT_DEPTH_F32)
515+
{
516+
outputBitDepth = OCIO::BIT_DEPTH_F32;
517+
}
518+
else if (inputBitDepth == OCIO::BIT_DEPTH_UINT8 || inputBitDepth == OCIO::BIT_DEPTH_F16)
519+
{
520+
outputBitDepth = OCIO::BIT_DEPTH_F16;
521+
}
522+
else
523+
{
524+
throw OCIO::Exception("Unsupported input bitdepth, must be uint8, uint16, half or float.");
525+
}
491526
}
492527

493528
OCIO::ConstCPUProcessorRcPtr cpuProcessor
@@ -611,7 +646,7 @@ int main(int argc, const char **argv)
611646
imgOutput->attribute("oiio:ColorSpace", outputcolorspace);
612647
}
613648

614-
imgOutput->write(outputimage);
649+
imgOutput->write(outputimage, userOutputBitDepth);
615650
}
616651
catch (...)
617652
{

0 commit comments

Comments
 (0)