Skip to content

Commit

Permalink
Add --bitdepth flag to ocioconvert (#2038)
Browse files Browse the repository at this point in the history
Signed-off-by: Rémi Achard <remiachard@gmail.com>
Co-authored-by: Doug Walker <doug.walker@autodesk.com>
  • Loading branch information
remia and doug-walker authored Sep 23, 2024
1 parent a1c4367 commit aa7fac0
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions src/apps/ocioconvert/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ int main(int argc, const char **argv)
std::vector<std::string> intAttrs;
std::vector<std::string> stringAttrs;

std::string outputDepth;

bool usegpu = false;
bool usegpuLegacy = false;
bool outputgpuInfo = false;
Expand Down Expand Up @@ -84,6 +86,7 @@ int main(int argc, const char **argv)
"--help", &help, "Display the help and exit",
"-v" , &verbose, "Display general information",
"<SEPARATOR>", "\nOpenImageIO or OpenEXR options:",
"--bitdepth %s", &outputDepth, "Output image bitdepth",
"--float-attribute %L", &floatAttrs, "\"name=float\" pair defining OIIO float attribute "
"for outputimage",
"--int-attribute %L", &intAttrs, "\"name=int\" pair defining an int attribute "
Expand Down Expand Up @@ -115,6 +118,31 @@ int main(int argc, const char **argv)
}
#endif // OCIO_GPU_ENABLED

OCIO::BitDepth userOutputBitDepth = OCIO::BIT_DEPTH_UNKNOWN;
if (!outputDepth.empty())
{
if (outputDepth == "uint8")
{
userOutputBitDepth = OCIO::BIT_DEPTH_UINT8;
}
else if (outputDepth == "uint16")
{
userOutputBitDepth = OCIO::BIT_DEPTH_UINT16;
}
else if (outputDepth == "half")
{
userOutputBitDepth = OCIO::BIT_DEPTH_F16;
}
else if (outputDepth == "float")
{
userOutputBitDepth = OCIO::BIT_DEPTH_F32;
}
else
{
throw OCIO::Exception("Unsupported output bitdepth, must be uint8, uint16, half or float.");
}
}

const char * inputimage = nullptr;
const char * inputcolorspace = nullptr;
const char * outputimage = nullptr;
Expand Down Expand Up @@ -477,17 +505,24 @@ int main(int argc, const char **argv)
const OCIO::BitDepth inputBitDepth = imgInput.getBitDepth();
OCIO::BitDepth outputBitDepth;

if (inputBitDepth == OCIO::BIT_DEPTH_UINT16 || inputBitDepth == OCIO::BIT_DEPTH_F32)
if (userOutputBitDepth != OCIO::BIT_DEPTH_UNKNOWN)
{
outputBitDepth = OCIO::BIT_DEPTH_F32;
}
else if (inputBitDepth == OCIO::BIT_DEPTH_UINT8 || inputBitDepth == OCIO::BIT_DEPTH_F16)
{
outputBitDepth = OCIO::BIT_DEPTH_F16;
outputBitDepth = userOutputBitDepth;
}
else
{
throw OCIO::Exception("Unsupported input bitdepth, must be uint8, uint16, half or float.");
if (inputBitDepth == OCIO::BIT_DEPTH_UINT16 || inputBitDepth == OCIO::BIT_DEPTH_F32)
{
outputBitDepth = OCIO::BIT_DEPTH_F32;
}
else if (inputBitDepth == OCIO::BIT_DEPTH_UINT8 || inputBitDepth == OCIO::BIT_DEPTH_F16)
{
outputBitDepth = OCIO::BIT_DEPTH_F16;
}
else
{
throw OCIO::Exception("Unsupported input bitdepth, must be uint8, uint16, half or float.");
}
}

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

imgOutput->write(outputimage);
imgOutput->write(outputimage, userOutputBitDepth);
}
catch (...)
{
Expand Down

0 comments on commit aa7fac0

Please sign in to comment.