Skip to content

Commit

Permalink
hio: Add CMake options to handled image file formats by plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
theblackunknown committed Oct 22, 2024
1 parent 899c19e commit 07cbef4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 15 deletions.
9 changes: 9 additions & 0 deletions cmake/defaults/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,12 @@ if (${PXR_BUILD_PYTHON_DOCUMENTATION})
set(PXR_BUILD_PYTHON_DOCUMENTATION "OFF" CACHE BOOL "" FORCE)
endif()
endif()

set(PXR_IMAGING_HIO_STB_PRECEDENCE "30" CACHE STRING "Hio plugin precedence for Hio_StbImage.")
set(PXR_IMAGING_HIO_STB_FORMATS "bmp;jpg;jpeg;png;tga;hdr" CACHE STRING "Image file formats handled by Hio_StbImage Hio plugin.")

set(PXR_IMAGING_HIO_OPENEXR_PRECEDENCE "30" CACHE STRING "Hio plugin precedence for Hio_OpenEXRImage.")
set(PXR_IMAGING_HIO_OPENEXR_FORMATS "exr" CACHE STRING "Image file formats handled by Hio_OpenEXRImage Hio plugin.")

set(PXR_IMAGING_HIO_OIIO_PRECEDENCE "10" CACHE STRING "Hio plugin precedence for HioOIIO_Image.")
set(PXR_IMAGING_HIO_OIIO_FORMATS "tif;tiff;zfile;tx" CACHE STRING "Image file formats handled by HioOIIO_Image Hio plugin.")
43 changes: 35 additions & 8 deletions pxr/imaging/hio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
set(PXR_PREFIX pxr/imaging)
set(PXR_PACKAGE hio)

set (optionalCppFiles)
set (optionalPrivateHeaders)
if (PXR_IMAGING_HIO_STB_FORMATS)
list(APPEND optionalCppFiles
stbImage.cpp
)
list(APPEND optionalPrivateHeaders
stb/stb_image.h
stb/stb_image_resize2.h
stb/stb_image_write.h
)
endif()
if (PXR_IMAGING_HIO_OPENEXR_FORMATS)
list(APPEND optionalCppFiles
OpenEXRImage.cpp
OpenEXR/openexr-c.c
)
list(APPEND optionalPrivateHeaders
OpenEXR/openexr-c.h
)
endif()

set(JSON_HIO_STB_FORMATS ${PXR_IMAGING_HIO_STB_FORMATS})
list(TRANSFORM JSON_HIO_STB_FORMATS REPLACE "[a-zA-Z0-9]+" "\"\\0\"")
list(JOIN JSON_HIO_STB_FORMATS ", " JSON_HIO_STB_FORMATS)

set(JSON_HIO_OPENEXR_FORMATS ${PXR_IMAGING_HIO_OPENEXR_FORMATS})
list(TRANSFORM JSON_HIO_OPENEXR_FORMATS REPLACE "[a-zA-Z0-9]+" "\"\\0\"")
list(JOIN JSON_HIO_OPENEXR_FORMATS ", " JSON_HIO_OPENEXR_FORMATS)

configure_file("${CMAKE_CURRENT_LIST_DIR}/plugInfo.json.in" "${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json" @ONLY)

pxr_library(hio
LIBRARIES
arch
Expand Down Expand Up @@ -29,19 +61,14 @@ pxr_library(hio
api.h

PRIVATE_HEADERS
OpenEXR/openexr-c.h
rankedTypeMap.h
stb/stb_image.h
stb/stb_image_resize2.h
stb/stb_image_write.h
${optionalPrivateHeaders}

CPPFILES
OpenEXRImage.cpp
OpenEXR/openexr-c.c
stbImage.cpp
${optionalCppFiles}

RESOURCE_FILES
plugInfo.json
"${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json"

DOXYGEN_FILES
overview.dox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"Types": {
"Hio_OpenEXRImage" : {
"bases": ["HioImage"],
"imageTypes": ["exr"],
"precedence": 30
"imageTypes": [@JSON_HIO_OPENEXR_FORMATS@],
"precedence": @PXR_IMAGING_HIO_OPENEXR_PRECEDENCE@
},
"Hio_StbImage" : {
"bases": ["HioImage"],
"imageTypes": ["bmp", "jpg", "jpeg", "png", "tga", "hdr"],
"precedence": 30
"imageTypes": [@JSON_HIO_STB_FORMATS@],
"precedence": @PXR_IMAGING_HIO_STB_PRECEDENCE@
}
}
},
Expand Down
14 changes: 13 additions & 1 deletion pxr/imaging/plugin/hioOiio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ if (NOT ${PXR_BUILD_GPU_SUPPORT})
return()
endif()

if (NOT PXR_IMAGING_HIO_OIIO_FORMATS)
message(STATUS
"Skipping ${PXR_PACKAGE} because PXR_IMAGING_HIO_OIIO_FORMATS is empty")
return()
endif()

# Use the import targets set by Imath's package config
if (Imath_FOUND)
set(__OIIO_IMATH_LIBS "Imath::Imath")
Expand All @@ -15,6 +21,12 @@ else()
set(__OIIO_IMATH_LIBS ${OPENEXR_LIBRARIES})
endif()

set(JSON_HIO_OIIO_FORMATS ${PXR_IMAGING_HIO_OIIO_FORMATS})
list(TRANSFORM JSON_HIO_OIIO_FORMATS REPLACE "[a-zA-Z0-9]+" "\"\\0\"")
list(JOIN JSON_HIO_OIIO_FORMATS ", " JSON_HIO_OIIO_FORMATS)

configure_file("${CMAKE_CURRENT_LIST_DIR}/plugInfo.json.in" "${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json" @ONLY)

pxr_plugin(hioOiio
LIBRARIES
ar
Expand All @@ -34,5 +46,5 @@ pxr_plugin(hioOiio
metadata.cpp

RESOURCE_FILES
plugInfo.json
"${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json"
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"Types": {
"HioOIIO_Image" : {
"bases": ["HioImage"],
"imageTypes": ["tif", "tiff", "zfile", "tx"],
"precedence": 10
"imageTypes": [@JSON_HIO_OIIO_FORMATS@],
"precedence": @PXR_IMAGING_HIO_OIIO_PRECEDENCE@
}
}
},
Expand Down

0 comments on commit 07cbef4

Please sign in to comment.