Skip to content

Commit 0a11927

Browse files
hio: Add CMake options to handled image file formats by plugins
1 parent 899c19e commit 0a11927

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

cmake/defaults/Options.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,12 @@ if (${PXR_BUILD_PYTHON_DOCUMENTATION})
240240
set(PXR_BUILD_PYTHON_DOCUMENTATION "OFF" CACHE BOOL "" FORCE)
241241
endif()
242242
endif()
243+
244+
set(PXR_IMAGING_HIO_STB_PRECEDENCE "30" CACHE STRING "Hio plugin precedence for Hio_StbImage.")
245+
set(PXR_IMAGING_HIO_STB_FORMATS "bmp;jpg;jpeg;png;tga;hdr" CACHE STRING "Image file formats handled by Hio_StbImage Hio plugin.")
246+
247+
set(PXR_IMAGING_HIO_OPENEXR_PRECEDENCE "30" CACHE STRING "Hio plugin precedence for Hio_OpenEXRImage.")
248+
set(PXR_IMAGING_HIO_OPENEXR_FORMATS "exr" CACHE STRING "Image file formats handled by Hio_OpenEXRImage Hio plugin.")
249+
250+
set(PXR_IMAGING_HIO_OIIO_PRECEDENCE "10" CACHE STRING "Hio plugin precedence for HioOIIO_Image.")
251+
set(PXR_IMAGING_HIO_OIIO_FORMATS "tif;tiff;zfile;tx" CACHE STRING "Image file formats handled by HioOIIO_Image Hio plugin.")

pxr/imaging/hio/CMakeLists.txt

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
set(PXR_PREFIX pxr/imaging)
22
set(PXR_PACKAGE hio)
33

4+
set (optionalCppFiles)
5+
set (optionalPrivateHeaders)
6+
if (PXR_IMAGING_HIO_STB_FORMATS)
7+
list(APPEND optionalCppFiles
8+
stbImage.cpp
9+
)
10+
list(APPEND optionalPrivateHeaders
11+
stb/stb_image.h
12+
stb/stb_image_resize2.h
13+
stb/stb_image_write.h
14+
)
15+
endif()
16+
if (PXR_IMAGING_HIO_OPENEXR_FORMATS)
17+
list(APPEND optionalCppFiles
18+
OpenEXRImage.cpp
19+
OpenEXR/openexr-c.c
20+
)
21+
list(APPEND optionalPrivateHeaders
22+
OpenEXR/openexr-c.h
23+
)
24+
endif()
25+
26+
set(JSON_HIO_STB_FORMATS ${PXR_IMAGING_HIO_STB_FORMATS})
27+
list(TRANSFORM JSON_HIO_STB_FORMATS REPLACE "[a-zA-Z0-9]+" "\"\\0\"")
28+
list(JOIN JSON_HIO_STB_FORMATS ", " JSON_HIO_STB_FORMATS)
29+
30+
set(JSON_HIO_OPENEXR_FORMATS ${PXR_IMAGING_HIO_OPENEXR_FORMATS})
31+
list(TRANSFORM JSON_HIO_OPENEXR_FORMATS REPLACE "[a-zA-Z0-9]+" "\"\\0\"")
32+
list(JOIN JSON_HIO_OPENEXR_FORMATS ", " JSON_HIO_OPENEXR_FORMATS)
33+
34+
file(READ "${CMAKE_CURRENT_LIST_DIR}/plugInfo.json.in" content)
35+
string(REPLACE "<JSON_HIO_OPENEXR_FORMATS>" "${JSON_HIO_OPENEXR_FORMATS}" content "${content}")
36+
string(REPLACE "<PXR_IMAGING_HIO_OPENEXR_PRECEDENCE>" "${PXR_IMAGING_HIO_OPENEXR_PRECEDENCE}" content "${content}")
37+
string(REPLACE "<JSON_HIO_STB_FORMATS>" "${JSON_HIO_STB_FORMATS}" content "${content}")
38+
string(REPLACE "<PXR_IMAGING_HIO_STB_PRECEDENCE>" "${PXR_IMAGING_HIO_STB_PRECEDENCE}" content "${content}")
39+
file(WRITE "${CMAKE_CURRENT_LIST_DIR}/plugInfo.json" "${content}")
40+
441
pxr_library(hio
542
LIBRARIES
643
arch
@@ -29,16 +66,11 @@ pxr_library(hio
2966
api.h
3067

3168
PRIVATE_HEADERS
32-
OpenEXR/openexr-c.h
3369
rankedTypeMap.h
34-
stb/stb_image.h
35-
stb/stb_image_resize2.h
36-
stb/stb_image_write.h
70+
${optionalPrivateHeaders}
3771

3872
CPPFILES
39-
OpenEXRImage.cpp
40-
OpenEXR/openexr-c.c
41-
stbImage.cpp
73+
${optionalCppFiles}
4274

4375
RESOURCE_FILES
4476
plugInfo.json

pxr/imaging/hio/plugInfo.json renamed to pxr/imaging/hio/plugInfo.json.in

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
"Types": {
66
"Hio_OpenEXRImage" : {
77
"bases": ["HioImage"],
8-
"imageTypes": ["exr"],
9-
"precedence": 30
8+
"imageTypes": [<JSON_HIO_OPENEXR_FORMATS>],
9+
"precedence": <PXR_IMAGING_HIO_OPENEXR_PRECEDENCE>
1010
},
1111
"Hio_StbImage" : {
12-
"bases": ["HioImage"],
13-
"imageTypes": ["bmp", "jpg", "jpeg", "png", "tga", "hdr"],
14-
"precedence": 30
12+
"imageTypes": [<JSON_HIO_STB_FORMATS>],
13+
"precedence": <PXR_IMAGING_HIO_STB_PRECEDENCE>
1514
}
1615
}
1716
},

pxr/imaging/plugin/hioOiio/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ if (NOT ${PXR_BUILD_GPU_SUPPORT})
77
return()
88
endif()
99

10+
if (NOT PXR_IMAGING_HIO_OIIO_FORMATS)
11+
message(STATUS
12+
"Skipping ${PXR_PACKAGE} because PXR_IMAGING_HIO_OIIO_FORMATS is empty")
13+
return()
14+
endif()
15+
1016
# Use the import targets set by Imath's package config
1117
if (Imath_FOUND)
1218
set(__OIIO_IMATH_LIBS "Imath::Imath")
@@ -15,6 +21,15 @@ else()
1521
set(__OIIO_IMATH_LIBS ${OPENEXR_LIBRARIES})
1622
endif()
1723

24+
set(JSON_HIO_OIIO_FORMATS ${PXR_IMAGING_HIO_OIIO_FORMATS})
25+
list(TRANSFORM JSON_HIO_OIIO_FORMATS REPLACE "[a-zA-Z0-9]+" "\"\\0\"")
26+
list(JOIN JSON_HIO_OIIO_FORMATS ", " JSON_HIO_OIIO_FORMATS)
27+
28+
file(READ "${CMAKE_CURRENT_LIST_DIR}/plugInfo.json.in" content)
29+
string(REPLACE "<JSON_HIO_OIIO_FORMATS>" "${JSON_HIO_OIIO_FORMATS}" content "${content}")
30+
string(REPLACE "<PXR_IMAGING_HIO_OIIO_PRECEDENCE>" "${PXR_IMAGING_HIO_OIIO_PRECEDENCE}" content "${content}")
31+
file(WRITE "${CMAKE_CURRENT_LIST_DIR}/plugInfo.json" "${content}")
32+
1833
pxr_plugin(hioOiio
1934
LIBRARIES
2035
ar

pxr/imaging/plugin/hioOiio/plugInfo.json renamed to pxr/imaging/plugin/hioOiio/plugInfo.json.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"Types": {
66
"HioOIIO_Image" : {
77
"bases": ["HioImage"],
8-
"imageTypes": ["tif", "tiff", "zfile", "tx"],
9-
"precedence": 10
8+
"imageTypes": [<JSON_HIO_OIIO_FORMATS>],
9+
"precedence": <PXR_IMAGING_HIO_OIIO_PRECEDENCE>
1010
}
1111
}
1212
},

0 commit comments

Comments
 (0)