4#ifndef OPENCV_slideio_tools_HPP
5#define OPENCV_slideio_tools_HPP
14#include "slideio/core/slideio_core_def.hpp"
19#include <opencv2/core.hpp>
20#include "slideio/base/slideio_enums.hpp"
24 class SLIDEIO_CORE_EXPORTS Tools
28 void operator()(std::FILE* file)
const {
34 static bool matchPattern(
const std::string& path,
const std::string& pattern);
35 static std::vector<int> completeChannelList(
const std::vector<int>& orgChannelList,
int numChannels)
37 std::vector<int> channelList(orgChannelList);
38 if(channelList.empty())
40 channelList.resize(numChannels);
41 for(
int channel=0; channel<numChannels; ++channel)
43 channelList[channel] = channel;
48 template <
typename Functor>
49 static int findZoomLevel(
double zoom,
int numLevels, Functor zoomFunction)
51 const double baseZoom = zoomFunction(0);
56 int goodLevelIndex = -1;
57 double lastZoom = baseZoom;
58 for (
int levelIndex = 1; levelIndex < numLevels; levelIndex++)
60 const double currentZoom = zoomFunction(levelIndex);
61 const double absDif = std::abs(currentZoom - zoom);
62 const double relDif = absDif / currentZoom;
65 goodLevelIndex = levelIndex;
68 if (zoom <= lastZoom && zoom > currentZoom)
70 goodLevelIndex = levelIndex - 1;
73 lastZoom = currentZoom;
75 if (goodLevelIndex < 0)
77 goodLevelIndex = numLevels - 1;
79 return goodLevelIndex;
81 static void convert12BitsTo16Bits(uint8_t* source, uint16_t* target,
int targetLen);
82 static void scaleRect(
const cv::Rect& srcRect,
const cv::Size& newSize, cv::Rect& trgRect);
83 static void scaleRect(
const cv::Rect& srcRect,
double scaleX,
double scaleY, cv::Rect& trgRect);
84 static bool isCompleteChannelList(
const std::vector<int>& channelIndices,
const int numChannels)
86 bool allChannels = channelIndices.empty();
88 if (channelIndices.size() == numChannels) {
90 for (
int channel = 0; channel < channelIndices.size(); ++channel) {
91 if (channelIndices[channel] != channel) {
100 static std::wstring toWstring(
const std::string&
string);
101 static std::string fromWstring(
const std::wstring& wstring);
102 static std::string fromUnicode16(
const std::u16string& u16string);
103 static void throwIfPathNotExist(
const std::string& path,
const std::string label);
104 static std::list<std::string> findFilesWithExtension(
const std::string& directory,
const std::string& extension);
105 static void extractChannels(
const cv::Mat& sourceRaster,
const std::vector<int>& channels, cv::OutputArray output);
106 static FILE* openFile(
const std::string& filePath,
const char* mode);
108 static bool isLittleEndian() {
109 uint16_t number = 0x1;
110 char* numPtr = (
char*)&number;
111 return (numPtr[0] == 1);
114 static uint16_t bigToLittleEndian16(uint16_t bigEndianValue) {
115 return ((bigEndianValue >> 8) & 0xff) |
116 ((bigEndianValue << 8) & 0xff00);
118 static uint64_t getFilePos(FILE* file);
119 static int setFilePos(FILE* file, uint64_t pos,
int origin);
120 static uint64_t getFileSize(FILE* file);
Definition: exceptions.hpp:12