Skip to content

Commit

Permalink
WIP: New C core (#870)
Browse files Browse the repository at this point in the history
* Initial merge of C core library
* includes exrinfo, similar to exrheader (subject to removal before release)
* introduces the idea of an encoding and decoding pipeline which should enable future gpu or other custom paths

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>

* Comments, testing, and small fixes

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
Co-authored-by: Timothy Grant <tgrant@nvidia.com>
  • Loading branch information
kdt3rd and tgrant-nv committed Jun 23, 2021
1 parent d755ae0 commit a04cbf5
Show file tree
Hide file tree
Showing 86 changed files with 46,726 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ BraceWrapping:
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
Expand Down
5 changes: 5 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ else()
set(OPENEXR_ENABLE_API_VISIBILITY ON)
endif()

if (UNIX AND NOT APPLE AND NOT BEOS)
find_library(OPENEXR_EXTRA_MATH_LIB m)
mark_as_advanced(OPENEXR_EXTRA_MATH_LIB)
endif()

configure_file(OpenEXRConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/OpenEXRConfig.h)
configure_file(OpenEXRConfigInternal.h.in ${CMAKE_CURRENT_BINARY_DIR}/OpenEXRConfigInternal.h)

Expand Down
30 changes: 23 additions & 7 deletions cmake/OpenEXRSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,25 @@ endif()
# Find or install Imath
#######################################

option(OPENEXR_FORCE_INTERNAL_IMATH "Force using an internal imath" OFF)
# Check to see if Imath is installed outside of the current build directory.
set(IMATH_REPO "https://github.com/AcademySoftwareFoundation/Imath.git" CACHE STRING
"Repo for auto-build of Imath")
set(IMATH_TAG "master" CACHE STRING
"Tag for auto-build of Imath (branch, tag, or SHA)")
#TODO: ^^ Release should not clone from master, this is a place holder
set(CMAKE_IGNORE_PATH "${CMAKE_CURRENT_BINARY_DIR}/_deps/imath-src/config;${CMAKE_CURRENT_BINARY_DIR}/_deps/imath-build/config")
find_package(Imath QUIET)
set(CMAKE_IGNORE_PATH)
"Tag for auto-build of Imath (branch, tag, or SHA)")
if(NOT OPENEXR_FORCE_INTERNAL_IMATH)
#TODO: ^^ Release should not clone from master, this is a place holder
set(CMAKE_IGNORE_PATH "${CMAKE_CURRENT_BINARY_DIR}/_deps/imath-src/config;${CMAKE_CURRENT_BINARY_DIR}/_deps/imath-build/config")
find_package(Imath QUIET)
set(CMAKE_IGNORE_PATH)
endif()

if(NOT TARGET Imath::Imath AND NOT Imath_FOUND)
message(STATUS "Imath was not found, installing from ${IMATH_REPO} (${IMATH_TAG})")

if(OPENEXR_FORCE_INTERNAL_IMATH)
message(STATUS "Imath forced internal, installing from ${IMATH_REPO} (${IMATH_TAG})")
else()
message(STATUS "Imath was not found, installing from ${IMATH_REPO} (${IMATH_TAG})")
endif()
include(FetchContent)
FetchContent_Declare(Imath
GIT_REPOSITORY ${IMATH_REPO}
Expand All @@ -275,6 +281,16 @@ if(NOT TARGET Imath::Imath AND NOT Imath_FOUND)
# hrm, cmake makes Imath lowercase for the properties (to imath)
add_subdirectory(${imath_SOURCE_DIR} ${imath_BINARY_DIR})
endif()
# the install creates this but if we're using the library locally we
# haven't installed the header files yet, so need to extract those
# and make a variable for header only usage
if(NOT TARGET Imath::ImathConfig)
get_target_property(imathinc Imath INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(imathconfinc ImathConfig INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND imathinc ${imathconfinc})
set(IMATH_HEADER_ONLY_INCLUDE_DIRS ${imathinc})
message(STATUS "Imath interface dirs ${IMATH_HEADER_ONLY_INCLUDE_DIRS}")
endif()
else()
message(STATUS "Using Imath from ${Imath_DIR}")
endif()
1 change: 1 addition & 0 deletions src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
if(OPENEXR_BUILD_TOOLS)
add_subdirectory( exr2aces )
add_subdirectory( exrheader )
add_subdirectory( exrinfo )
add_subdirectory( exrmaketiled )
add_subdirectory( exrstdattr )
add_subdirectory( exrmakepreview )
Expand Down
12 changes: 12 additions & 0 deletions src/bin/exrinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenEXR Project.

add_executable(exrinfo main.c)
target_link_libraries(exrinfo OpenEXR::OpenEXRCore)
set_target_properties(exrinfo PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exrinfo DESTINATION ${CMAKE_INSTALL_BINDIR})
if(WIN32 AND (BUILD_SHARED_LIBS OR OPENEXR_BUILD_BOTH_STATIC_SHARED))
target_compile_definitions(exrinfo PRIVATE OPENEXR_DLL)
endif()
149 changes: 149 additions & 0 deletions src/bin/exrinfo/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
** SPDX-License-Identifier: BSD-3-Clause
** Copyright Contributors to the OpenEXR Project.
*/

#include <openexr.h>
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
# include <fcntl.h>
# include <io.h>
# include <windows.h>
#else
# include <unistd.h>
#endif

#include <stdlib.h>

static void
usage (const char* argv0)
{
fprintf (
stderr,
"Usage: %s [-v|--verbose] <filename> [<filename> ...]\n\n",
argv0);
}

static void
error_handler_cb (exr_const_context_t f, int code, const char* msg)
{
const char* fn;
if (EXR_ERR_SUCCESS != exr_get_file_name (f, &fn)) fn = "<error>";
fprintf (
stderr,
"ERROR '%s' (%s): %s\n",
fn,
exr_get_error_code_as_string (code),
msg);
}

static int64_t
stdin_reader (
exr_const_context_t file,
void* userdata,
void* buffer,
uint64_t sz,
uint64_t offset,
exr_stream_error_func_ptr_t error_cb)
{
static uint64_t lastoffset = 0;
int64_t nread = 0;

(void) userdata;

if (offset != lastoffset)
{
error_cb (file, EXR_ERR_READ_IO, "Unable to seek in stdin stream");
return -1;
}
#ifdef _WIN32
if (sz >= (size_t) (INT32_MAX))
{
error_cb (
file, EXR_ERR_READ_IO, "Read request too large for win32 API");
return -1;
}
nread = _read (_fileno (stdin), buffer, (unsigned) sz);
#else
nread = read (STDIN_FILENO, buffer, sz);
#endif
if (nread > 0) lastoffset = offset + (uint64_t) nread;
return nread;
}

static int
process_stdin (int verbose)
{
int rv;
exr_context_t e = NULL;
exr_context_initializer_t cinit = EXR_DEFAULT_CONTEXT_INITIALIZER;
cinit.error_handler_fn = &error_handler_cb;
cinit.read_fn = &stdin_reader;

#ifdef _WIN32
_setmode (_fileno (stdin), _O_BINARY);
#endif
rv = exr_start_read (&e, "<stdin>", &cinit);
if (rv == EXR_ERR_SUCCESS)
{
exr_print_context_info (e, verbose);
exr_finish (&e);
}
return rv;
}

static int
process_file (const char* filename, int verbose)
{
int rv;
exr_context_t e = NULL;
exr_context_initializer_t cinit = EXR_DEFAULT_CONTEXT_INITIALIZER;
cinit.error_handler_fn = &error_handler_cb;

rv = exr_start_read (&e, filename, &cinit);
if (rv == 0)
{
exr_print_context_info (e, verbose);
exr_finish (&e);
}
return rv;
}

int
main (int argc, const char* argv[])
{
int rv = 0, nfiles = 0, verbose = 0;

for (int a = 1; a < argc; ++a)
{
if (!strcmp (argv[a], "-h") || !strcmp (argv[a], "-?") ||
!strcmp (argv[a], "--help"))
{
usage (argv[0]);
return 0;
}
else if (!strcmp (argv[a], "-v") || !strcmp (argv[a], "--verbose"))
{
verbose = 1;
}
else if (!strcmp (argv[a], "-"))
{
++nfiles;
rv += process_stdin (verbose);
}
else if (argv[a][0] == '-')
{
usage (argv[0]);
return 1;
}
else
{
++nfiles;
rv += process_file (argv[a], verbose);
}
}

return rv;
}
1 change: 1 addition & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
add_subdirectory( Iex )
add_subdirectory( IlmThread )

add_subdirectory( OpenEXRCore )
add_subdirectory( OpenEXR )
add_subdirectory( OpenEXRUtil )
95 changes: 95 additions & 0 deletions src/lib/OpenEXRCore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenEXR Project.

openexr_define_library(OpenEXRCore
PRIV_EXPORT OPENEXRCORE_EXPORTS
CURDIR ${CMAKE_CURRENT_SOURCE_DIR}
SOURCES
#NB: If you make any of these public, make sure to update the
# locking macros in the relative source files
internal_attr.h
internal_channel_list.h
internal_coding.h
internal_constants.h
internal_compress.h
internal_decompress.h
internal_file.h
internal_float_vector.h
internal_memory.h
internal_opaque.h
internal_posix_file_impl.h
internal_win32_file_impl.h
internal_preview.h
internal_string.h
internal_string_vector.h
internal_structs.h
internal_xdr.h

internal_rle.c
internal_zip.c
internal_pxr24.c
internal_b44.c
internal_b44_table.c
internal_piz.c
internal_dwa.c
internal_huf.c

attributes.c
string.c
string_vector.c
float_vector.c
channel_list.c
opaque.c
preview.c

base.c
context.c
memory.c
internal_structs.c

part.c
part_attr.c
std_attr.c

parse_header.c
write_header.c

chunk.c
coding.c
decoding.c
encoding.c
pack.c
unpack.c
validation.c

debug.c

HEADERS
openexr.h

openexr_attr.h
openexr_base.h
openexr_chunkio.h
openexr_coding.h
openexr_conf.h
openexr_context.h
openexr_decode.h
openexr_debug.h
openexr_encode.h
openexr_errors.h
openexr_part.h
openexr_std_attr.h
DEPENDENCIES
ZLIB::ZLIB
PRIVATE_DEPS
${OPENEXR_EXTRA_MATH_LIB}
)

# when building with an internal imath, this isn't generated until
# install time, so need to use private header only include path (we
# aren't linking to imath or anything c++)
if (TARGET Imath::ImathConfig)
target_link_libraries(OpenEXRCore PRIVATE Imath::ImathConfig)
else()
target_include_directories(OpenEXRCore PRIVATE ${IMATH_HEADER_ONLY_INCLUDE_DIRS})
endif()
Loading

0 comments on commit a04cbf5

Please sign in to comment.