Skip to content

Commit

Permalink
Merge pull request #6 from abcucberkeley/cpp
Browse files Browse the repository at this point in the history
Cpp
  • Loading branch information
MattHazard authored Oct 26, 2023
2 parents b3974ee + 2017de9 commit 0d46d87
Show file tree
Hide file tree
Showing 1,849 changed files with 531,143 additions and 1,224 deletions.
101 changes: 101 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
cmake_minimum_required(VERSION 3.9)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")

project(
cpp-tiff
VERSION 1.1.0
LANGUAGES CXX)

# OpenMP is Required
find_package(OpenMP REQUIRED)

if(UNIX)
set(ZLIB_STATIC_NAME "libz.a")
else()
set(ZLIB_STATIC_NAME "libzlib.a")
endif()

set(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE)
set(ZLIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zlib-1.2.8")
add_subdirectory(${ZLIB_DIR})
set_property(TARGET zlibstatic PROPERTY POSITION_INDEPENDENT_CODE ON)

set(LIBDEFLATE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libdeflate-1.18")
add_subdirectory(${LIBDEFLATE_DIR})
set_property(TARGET libdeflate_static PROPERTY POSITION_INDEPENDENT_CODE ON)

set(ZSTD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zstd-1.5.5")
add_subdirectory(${ZSTD_DIR}/build/cmake)
set_property(TARGET libzstd_static PROPERTY POSITION_INDEPENDENT_CODE ON)

# Add libtiff
include_directories(${ZSTD_DIR}/lib)
set(ZLIB_INCLUDE_DIR ${ZLIB_DIR} CACHE STRING "" FORCE)
set(ZLIB_LIBRARY ${CMAKE_BINARY_DIR}/dependencies/zlib-1.2.8/${ZLIB_STATIC_NAME} CACHE STRING "" FORCE)
set(Deflate_INCLUDE_DIR ${LIBDEFLATE_DIR} CACHE STRING "" FORCE)
set(Deflate_LIBRARY ${CMAKE_BINARY_DIR}/dependencies/libdeflate-1.18/libdeflate.a CACHE STRING "" FORCE)
set(ZSTD_INCLUDE_DIR ${ZSTD_DIR}/lib CACHE STRING "" FORCE)
set(ZSTD_LIBRARY ${CMAKE_BINARY_DIR}/dependencies/zstd-1.5.5/build/cmake/lib/libzstd.a CACHE STRING "" FORCE)
set(LIBTIFF_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/tiff-4.6.0")
set(tiff-tools OFF CACHE BOOL "" FORCE)
set(tiff-tests OFF CACHE BOOL "" FORCE)
set(tiff-contrib OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
# Disable jpeg and lzma until I can add the dependencies
set(jpeg OFF CACHE BOOL "" FORCE)
set(lzma OFF CACHE BOOL "" FORCE)


add_subdirectory(${LIBTIFF_DIR})
set_property(TARGET tiff PROPERTY POSITION_INDEPENDENT_CODE ON)
add_dependencies(tiff zlibstatic)
add_dependencies(tiff libdeflate_static)
add_dependencies(tiff libzstd_static)


set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")

add_library(cppTiff_shared SHARED ${SRC_DIR}/helperfunctions.cpp ${SRC_DIR}/lzwencode.cpp ${SRC_DIR}/parallelreadtiff.cpp ${SRC_DIR}/parallelwritetiff.cpp)
set_target_properties(cppTiff_shared PROPERTIES OUTPUT_NAME cppTiff)
add_dependencies(cppTiff_shared zlibstatic)
add_dependencies(cppTiff_shared libdeflate_static)
add_dependencies(cppTiff_shared libzstd_static)
add_dependencies(cppTiff_shared tiff)

set_target_properties(cppTiff_shared PROPERTIES PUBLIC_HEADER "${ZSTD_DIR}/lib/zstd.h;${SRC_DIR}/helperfunctions.h;${SRC_DIR}/lzwencode.h;${SRC_DIR}/parallelreadtiff.h;${SRC_DIR}/parallelwritetiff.h")

# Include the header files
target_include_directories(cppTiff_shared PRIVATE
${ZLIB_DIR}
${LIBDEFLATE_DIR}
${ZSTD_DIR}/lib
${LIBTIFF_DIR}/libtiff
)

# Link against the libraries
target_link_libraries(cppTiff_shared PRIVATE
${CMAKE_BINARY_DIR}/dependencies/tiff-4.6.0/libtiff/libtiff.a
${CMAKE_BINARY_DIR}/dependencies/zlib-1.2.8/${ZLIB_STATIC_NAME}
${CMAKE_BINARY_DIR}/dependencies/libdeflate-1.18/libdeflate.a
${CMAKE_BINARY_DIR}/dependencies/zstd-1.5.5/build/cmake/lib/libzstd.a
-static-libgcc
-static-libstdc++
OpenMP::OpenMP_CXX
)

install(TARGETS cppTiff_shared
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
Empty file modified LICENSE
100644 → 100755
Empty file.
10 changes: 5 additions & 5 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# c-tiff
# cpp-tiff
An efficient parallel Tiff reader/writer that utilizes LibTIFF and OpenMP.

## Quick Start Guide (MATLAB)

### Prerequisites
1. None! The parallel reader and writer mex files will work with most recent version of Matlab.
1. None! The parallel reader and writer mex files will work with the most recent version of Matlab.

### Download and Install
1. Download the latest release for your OS from here (windows/linux/mac.zip): https://github.com/abcucberkeley/c-tiff/releases
1. Download the latest release for your OS from here (windows/linux/mac.zip): https://github.com/abcucberkeley/cpp-tiff/releases
2. Unzip the folder
3. You can now put the mex files wherever you'd like and add them to your path if needed

Expand All @@ -17,8 +17,8 @@ Note: For filepath separators, on Mac/Linux you can use / and on Windows you can
#### parallelReadTiff - Read a Tiff image into an array
im = parallelReadTiff('path/to/file.tif');

#### getImageSize_mex - Get the dimensions of a Tiff image
size = getImageSize_mex('path/to/file.tif');
#### getImageSizeMex - Get the dimensions of a Tiff image
size = getImageSizeMex('path/to/file.tif');

#### parallelWriteTiff - Write an array out as a Tiff image
im = rand(100,100,100);
Expand Down
1 change: 1 addition & 0 deletions dependencies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NOTE: If you want to upgrade libtiff (or use your own version) then change tiff-x.x.x/cmake/ZSTDCodec.cmake to match the one in the current repo for the lines that check for the presence of zstd
12 changes: 12 additions & 0 deletions dependencies/libdeflate-1.18/.cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
task:
freebsd_instance:
matrix:
- image_family: freebsd-12-3
- image_family: freebsd-13-0
install_script: pkg install -y cmake
script:
- cmake -B build -DLIBDEFLATE_BUILD_TESTS=1
- cmake --build build
- ctest --test-dir build
# Direct compilation without official build system
- cc -O2 -Wall -Werror lib/*.c lib/*/*.c programs/gzip.c programs/prog_util.c programs/tgetopt.c -o libdeflate-gzip
Loading

0 comments on commit 0d46d87

Please sign in to comment.