Skip to content

Commit 62d0171

Browse files
Merge branch 'master' into develop
2 parents 460215f + 16cce98 commit 62d0171

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ option(APR_INSTALL "Install APR library" OFF)
1212
option(APR_BUILD_SHARED_LIB "Builds shared library" ON)
1313
option(APR_BUILD_STATIC_LIB "Builds static library" OFF)
1414
option(APR_BUILD_EXAMPLES "Build APR examples" OFF)
15+
option(APR_USE_LIBTIFF "Use LibTIFF" ON)
1516
option(APR_TESTS "Build APR tests" OFF)
1617
option(APR_PREFER_EXTERNAL_GTEST "When found, use the installed GTEST libs instead of included sources" OFF)
1718
option(APR_PREFER_EXTERNAL_BLOSC "When found, use the installed BLOSC libs instead of included sources" OFF)
@@ -52,7 +53,13 @@ message("Configuring for APR version: " ${APR_VERSION_STRING})
5253
###############################################################################
5354
find_package(HDF5 REQUIRED)
5455
find_package(ZLIB REQUIRED)
55-
find_package(TIFF REQUIRED)
56+
if(APR_USE_LIBTIFF)
57+
find_package(TIFF)
58+
set(CMAKE_C_FLAGS "${CMAKE_CFLAGS} -DHAVE_LIBTIFF")
59+
set(CMAKE_CXX_FLAGS "${CMAKE_CXXFLAGS} -DHAVE_LIBTIFF")
60+
else()
61+
message(WARNING "LibTIFF support disable, this disables TIFF writing functionality.")
62+
endif()
5663

5764
# Handle OpenMP
5865
find_package(OpenMP)

src/io/TiffUtils.hpp

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99

1010
#include <string>
11-
#include <tiffio.h>
11+
#ifdef HAVE_LIBTIFF
12+
#include <tiffio.h>
13+
#endif
1214
#include <sstream>
1315
#include "data_structures/Mesh/PixelData.hpp"
1416

@@ -56,7 +58,9 @@ namespace TiffUtils {
5658
outputStr << "NOT SUPPORTED";
5759
}
5860
outputStr << ", Photometric: " << iPhotometric;
61+
#ifdef HAVE_LIBTIFF
5962
outputStr << ", StripSize: " << TIFFStripSize(iFile);
63+
#endif /* HAVE_LIBTIFF */
6064

6165
return outputStr.str();
6266
}
@@ -67,7 +71,12 @@ namespace TiffUtils {
6771
bool isFileOpened() const { return iFile != nullptr; }
6872

6973
TiffType iType = TiffType::TIFF_INVALID;
74+
#ifdef HAVE_LIBTIFF
7075
TIFF *iFile = nullptr;
76+
#else
77+
void* iFile = nullptr;
78+
typedef unsigned int uint32;
79+
#endif /* HAVE_LIBTIFF */
7180
std::string iFileName = "";
7281
uint32 iImgWidth = 0;
7382
uint32 iImgHeight = 0;
@@ -81,6 +90,12 @@ namespace TiffUtils {
8190
TiffInfo(const TiffInfo&) = delete; // make it noncopyable
8291
TiffInfo& operator=(const TiffInfo&) = delete; // make it not assignable
8392

93+
friend std::ostream& operator<<(std::ostream &os, const TiffInfo &obj) {
94+
os << obj.toString();
95+
return os;
96+
}
97+
98+
#ifdef HAVE_LIBTIFF
8499
/**
85100
* opens TIFF
86101
**/
@@ -142,12 +157,21 @@ namespace TiffUtils {
142157
}
143158
}
144159

145-
friend std::ostream& operator<<(std::ostream &os, const TiffInfo &obj) {
146-
os << obj.toString();
147-
return os;
160+
#else
161+
bool open(const std::string &aFileName) {
162+
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
163+
std::cerr << "Trying to open file " << aFileName << ", returning false." << std::endl;
164+
return false;
148165
}
166+
167+
void close() {
168+
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
169+
std::cerr << "Shim-closing TIFF file" << std::endl;
170+
}
171+
#endif /* HAVE_LIBTIFF */
149172
};
150173

174+
#ifdef HAVE_LIBTIFF
151175

152176
/**
153177
* Reads TIFF file to mesh
@@ -287,6 +311,46 @@ namespace TiffUtils {
287311
PixelData<uint16_t> mesh16{aData, true /*copy data*/};
288312
saveMeshAsTiff(filename, mesh16);
289313
}
314+
#else
315+
template<typename T>
316+
PixelData<T> getMesh(const std::string &aFileName) {
317+
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
318+
std::cerr << "getMesh() called for " << &aFileName << ", returning empty mesh." << std::endl;
319+
320+
PixelData<T> mesh(1, 1, 1);
321+
return mesh;
322+
}
323+
324+
template<typename T>
325+
PixelData<T> getMesh(const TiffInfo &aTiff) {
326+
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
327+
std::cerr << "getMesh() called for TiffInfo, returning empty mesh." << std::endl;
328+
329+
PixelData<T> mesh(1, 1, 1);
330+
return mesh;
331+
}
332+
333+
template<typename T>
334+
void getMesh(const TiffInfo &aTiff, PixelData<T> &aInputMesh) {
335+
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
336+
std::cerr << "getMesh() called for inputMesh, returning empty inputMesh." << std::endl;
337+
338+
PixelData<T> mesh(1, 1, 1);
339+
aInputMesh.swap(mesh);
340+
}
341+
342+
template<typename T>
343+
void saveMeshAsTiff(const std::string &aFileName, const PixelData<T> &aData) {
344+
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
345+
std::cerr << "saveMeshAsTiff() called for " << aFileName << ", not doing anything." << std::endl;
346+
}
347+
348+
template<typename T>
349+
void saveMeshAsTiffUint16(const std::string &filename, const PixelData<T> &aData) {
350+
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
351+
std::cerr << "saveMeshAsTiff() called for " << filename << ", not doing anything." << std::endl;
352+
}
353+
#endif
290354
}
291355

292356
#endif

0 commit comments

Comments
 (0)