Skip to content

Commit 0a6baf7

Browse files
committed
add files
1 parent 5f24ad7 commit 0a6baf7

7 files changed

Lines changed: 190 additions & 59 deletions

File tree

CMakeLists.txt

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
############################################################################
2+
# Copyright (c) 2016, Wolf Vollprecht, Johan Mabille, and Sylvain Corlay #
3+
# #
4+
# Distributed under the terms of the BSD 3-Clause License. #
5+
# #
6+
# The full license is in the file LICENSE, distributed with this software. #
7+
############################################################################
8+
9+
cmake_minimum_required(VERSION 3.1)
10+
project(xtensor-io)
11+
12+
set(XTENSOR_IO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
13+
14+
# Versionning
15+
# ===========
16+
17+
file(STRINGS "${XTENSOR_IO_INCLUDE_DIR}/xtensor-io/xtensor_io_config.hpp" xtensor_io_version_defines
18+
REGEX "#define XTENSOR_IO_VERSION_(MAJOR|MINOR|PATCH)")
19+
foreach(ver ${xtensor_io_version_defines})
20+
if(ver MATCHES "#define XTENSOR_IO_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
21+
set(XTENSOR_IO_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
22+
endif()
23+
endforeach()
24+
set(${PROJECT_NAME}_VERSION
25+
${XTENSOR_IO_VERSION_MAJOR}.${XTENSOR_IO_VERSION_MINOR}.${XTENSOR_IO_VERSION_PATCH})
26+
message(STATUS "Building xtensor-io v${${PROJECT_NAME}_VERSION}")
27+
28+
# Dependencies
29+
# ============
30+
31+
find_package(xtensor REQUIRED)
32+
message(STATUS "Found xtensor: ${xtensor_INCLUDE_DIRS}/xtensor")
33+
34+
# Find OpenImageIO
35+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/modules")
36+
message("MODULE PATH: ${CMAKE_MODULE_PATH}")
37+
38+
find_package(OIIO)
39+
message(STATUS "Found OpenImageIO: ${OIIO_INCLUDE_DIRS}")
40+
41+
find_package(ZLIB)
42+
message(STATUS "Found zlib: ${zlib_INCLUDE_DIRS}")
43+
44+
# Build
45+
# =====
46+
47+
set(XTENSOR_IO_HEADERS
48+
${XTENSOR_IO_INCLUDE_DIR}/xtensor-io/ximageio.hpp
49+
${XTENSOR_IO_INCLUDE_DIR}/thirdparty/zstr/strict_fstream.hpp
50+
${XTENSOR_IO_INCLUDE_DIR}/thirdparty/zstr/zstr.hpp
51+
${XTENSOR_IO_INCLUDE_DIR}/xtensor-io/xnpz.hpp
52+
${XTENSOR_IO_INCLUDE_DIR}/xtensor-io/xtensor_io_config.hpp
53+
)
54+
55+
OPTION(BUILD_TESTS "xtensor-io test suite" OFF)
56+
# OPTION(BUILD_BENCHMARK "xtensor-io benchmark" OFF)
57+
OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
58+
OPTION(DOWNLOAD_GBENCHMARK "download google benchmark and build from source" ON)
59+
60+
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
61+
set(BUILD_TESTS ON)
62+
endif()
63+
64+
if(BUILD_TESTS)
65+
add_subdirectory(test)
66+
endif()
67+
68+
if(BUILD_BENCHMARK)
69+
add_subdirectory(benchmark)
70+
endif()
71+
72+
include_directories(${xtensor_INCLUDE_DIRS})
73+
74+
# Installation
75+
# ============
76+
77+
include(GNUInstallDirs)
78+
include(CMakePackageConfigHelpers)
79+
80+
install(FILES ${XTENSOR_IO_HEADERS}
81+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xtensor-io)
82+
83+
set(XTENSOR_IO_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE
84+
STRING "install path for xtensor-ioConfig.cmake")
85+
86+
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
87+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
88+
INSTALL_DESTINATION ${XTENSOR_IO_CMAKECONFIG_INSTALL_DIR})
89+
90+
# xtensor is header-only and does not depend on the architecture.
91+
# Remove CMAKE_SIZEOF_VOID_P from xtensorConfigVersion.cmake so that an xtensorConfig.cmake
92+
# generated for a 64 bit target can be used for 32 bit targets and vice versa.
93+
set(_XTENSOR_IO_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
94+
unset(CMAKE_SIZEOF_VOID_P)
95+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
96+
VERSION ${${PROJECT_NAME}_VERSION}
97+
COMPATIBILITY AnyNewerVersion)
98+
set(CMAKE_SIZEOF_VOID_P ${_XTENSOR_IO_CMAKE_SIZEOF_VOID_P})
99+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
100+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
101+
DESTINATION ${XTENSOR_IO_CMAKECONFIG_INSTALL_DIR})
102+
103+
configure_file(${PROJECT_NAME}.pc.in
104+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
105+
@ONLY)
106+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
107+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# xtensor-io
2+
3+
This library delivers a couple of function to efficiently in- and output
4+
images and NumPy compressed arrays (npz) to xtensor data structures.
5+
In order to read and write images, the ![OpenImageIO](https://github.com/OpenImageIO/oiio)
6+
library is utilized. We only provide a few simple functions, but upon demand
7+
can improve this interface.
8+
9+
```cpp
10+
// loads png image into xarray with shape WIDTH x HEIGHT x CHANNELS
11+
auto arr = xt::load_image("test.png");
12+
13+
// write xarray out to JPEG image
14+
xt::dump_image("dumptest.jpg", arr + 5);
15+
16+
// load npz file containing multiple arrays
17+
auto npy_map = xt::load_npz("test.npz");
18+
19+
auto arr_0 = npy_map["arr_0"].cast<double>();
20+
auto arr_1 = npy_map["arr_1"].cast<unsigned long>();
21+
```
22+
23+
## Installation
24+
25+
In order to install this library on linux systems, please find a copy
26+
of `libopenimageio` (on fedora: `dnf install OpenImageIO-devel`,
27+
ubuntu: `apt-get install libopenimageio-dev`). This should enable you
28+
to build the library like a regular cmake package:
29+
30+
From this directory:
31+
32+
```
33+
mkdir build
34+
cd build
35+
cmake ..
36+
make
37+
sudo make install
38+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/***************************************************************************
2+
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
3+
* *
4+
* Distributed under the terms of the BSD 3-Clause License. *
5+
* *
6+
* The full license is in the file LICENSE, distributed with this software. *
7+
****************************************************************************/
8+
9+
#ifndef XTENSOR_IO_CONFIG_HPP
10+
#define XTENSOR_IO_CONFIG_HPP
11+
12+
#define XTENSOR_IO_VERSION_MAJOR 0
13+
#define XTENSOR_IO_VERSION_MINOR 1
14+
#define XTENSOR_IO_VERSION_PATCH 0
15+
16+
#endif

tutorial/CMakeLists.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

tutorial/test.cpp

Lines changed: 0 additions & 44 deletions
This file was deleted.

xtensor-io.pc.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
3+
includedir=${prefix}/include
4+
5+
Name: xtensor
6+
Description: xtensor-io is a C++ library that enables opening and saving of common file and image formats to and from xtensor arrays.
7+
Version: @xtensor-io_VERSION@
8+
Cflags: -I${includedir}

xtensor-ioConfig.cmake.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
############################################################################
2+
# Copyright (c) 2016, Johan Mabille and Sylvain Corlay #
3+
# #
4+
# Distributed under the terms of the BSD 3-Clause License. #
5+
# #
6+
# The full license is in the file LICENSE, distributed with this software. #
7+
############################################################################
8+
9+
# xtensor cmake module
10+
# This module sets the following variables in your project::
11+
#
12+
# xtensor_io_FOUND - true if xtensor found on the system
13+
# xtensor_io_INCLUDE_DIRS - the directory containing xtensor headers
14+
# xtensor_io_LIBRARY - empty
15+
16+
@PACKAGE_INIT@
17+
18+
set(PN xtensor_io)
19+
set_and_check(${PN}_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
20+
set(${PN}_LIBRARY "")
21+
check_required_components(${PN})

0 commit comments

Comments
 (0)