13#include "slideio/core/slideio_core_def.hpp"
19#include <opencv2/core.hpp>
20#include <opencv2/imgproc.hpp>
21#include "slideio/core/slideio_enums.hpp"
22#include "slideio/core/slideio_structs.hpp"
26 class SLIDEIO_CORE_EXPORTS Tools
30 void operator()(std::FILE* file)
const {
36 static bool matchPattern(
const std::string& path,
const std::string& pattern);
37 static bool isConsecutiveFromZero(
const std::vector<int>& vec,
int size);
38 static std::vector<int> completeChannelList(
const std::vector<int>& orgChannelList,
int numChannels)
40 std::vector<int> channelList(orgChannelList);
41 if(channelList.empty())
43 channelList.resize(numChannels);
44 for(
int channel=0; channel<numChannels; ++channel)
46 channelList[channel] = channel;
51 template <
typename Functor>
52 static int findZoomLevel(
double zoom,
int numLevels, Functor zoomFunction)
57 const double baseZoom = zoomFunction(0);
62 int goodLevelIndex = -1;
63 double lastZoom = baseZoom;
64 for (
int levelIndex = 1; levelIndex < numLevels; levelIndex++)
66 const double currentZoom = zoomFunction(levelIndex);
67 const double absDif = std::abs(currentZoom - zoom);
68 const double relDif = absDif / currentZoom;
71 goodLevelIndex = levelIndex;
74 if (zoom <= lastZoom && zoom > currentZoom)
76 goodLevelIndex = levelIndex - 1;
79 lastZoom = currentZoom;
81 if (goodLevelIndex < 0)
83 goodLevelIndex = numLevels - 1;
85 return goodLevelIndex;
87 static void convert12BitsTo16Bits(
const uint8_t* source, uint16_t* target,
int targetLen);
88 static void scaleRect(
const cv::Rect& srcRect,
const cv::Size& newSize, cv::Rect& trgRect);
89 static void scaleRect(
const cv::Rect& srcRect,
double scaleX,
double scaleY, cv::Rect& trgRect);
90 static bool isCompleteChannelList(
const std::vector<int>& channelIndices,
const int numChannels)
92 bool allChannels = channelIndices.empty();
94 if (channelIndices.size() == numChannels) {
96 for (
int channel = 0; channel < channelIndices.size(); ++channel) {
97 if (channelIndices[channel] != channel) {
107 static std::wstring toWstring(
const std::string&
string);
110 static std::string fromUnicode16(
const std::u16string& u16string);
111 static void throwIfPathNotExist(
const std::string& path,
const std::string label);
120 static std::optional<double> parseIso8601(
const std::string& text);
130 static std::optional<int64_t> parseTiffDateTime(
const std::string& text);
139 static std::optional<double> parseDicomDateTime(
const std::string& date,
140 const std::string& time,
141 const std::string& zoneOffset = std::string());
142 static std::list<std::string> findFilesWithExtension(
const std::string& directory,
const std::string& extension);
143 static void extractChannels(
const cv::Mat& sourceRaster,
const std::vector<int>& channels, cv::OutputArray output);
144 static FILE* openFile(
const std::string& filePath,
const char* mode);
145 static uint64_t getFilePos(FILE* file);
146 static int setFilePos(FILE* file, uint64_t pos,
int origin);
147 static uint64_t getFileSize(FILE* file);
148 static int dataTypeSize(slideio::DataType dt);
149 static Size cvSizeToSize(
const cv::Size& cvSize) {
150 return {cvSize.width, cvSize.height};
152 static Rect cvRectToRect(
const cv::Rect& cvRect) {
153 return {cvRect.x, cvRect.y, cvRect.width, cvRect.height};
155 static void replaceAll(std::string& str,
const std::string& from,
const std::string& to);
156 static std::vector<std::string> split(
const std::string& value,
char delimiter);
157 static std::string randomUUID();
158 static void resize( cv::InputArray src, cv::OutputArray dst, cv::Size dsize,
159 int interpolation = cv::INTER_LINEAR);
Definition: converter.hpp:18