SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
tiffkeeper.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4
5#ifndef OPENCV_slideio_tiffkeeper_HPP
6#define OPENCV_slideio_tiffkeeper_HPP
7#include <string>
8
9#include "tifftools.hpp"
10#include "slideio/imagetools/slideio_imagetools_def.hpp"
11#include "slideio/imagetools/imagetools.hpp"
12
13namespace libtiff
14{
15 struct tiff;
16 typedef tiff TIFF;
17}
18
19namespace slideio
20{
21 class TIFFMessageHandler;
22
23 class SLIDEIO_IMAGETOOLS_EXPORTS TIFFKeeper
24 {
25 public:
26 TIFFKeeper(libtiff::TIFF* hfile = nullptr);
27 TIFFKeeper(const std::string& filePath, bool readOnly = true);
28 ~TIFFKeeper();
29 libtiff::TIFF* getHandle() const {
30 return m_hFile;
31 }
32 bool isValid() const {
33 return getHandle() != nullptr;
34 }
35 operator libtiff::TIFF* () const {
36 return getHandle();
37 }
38 TIFFKeeper& operator = (libtiff::TIFF* hFile) {
39 m_hFile = hFile;
40 return *this;
41 }
42 libtiff::TIFF* release() {
43 libtiff::TIFF* handle = m_hFile;
44 m_hFile = nullptr;
45 return handle;
46 }
47 void openTiffFile(const std::string& filePath, bool readOnly = true);
48 void closeTiffFile();
49 void writeDirectory();
50 void setTags(const TiffDirectory& dir);
51 void writeTile(int x, int y, Compression compression, const EncodeParameters& params, const cv::Mat& mat,
52 uint8_t* buffer, int bufferSize);
53 void readTile(const slideio::TiffDirectory& dir, int tile,
54 const std::vector<int>& channelIndices, cv::OutputArray output);
55 std::string readStringTag(uint16_t tag);
56 void initSubDirs(int numDirs);
57
58 private:
59 libtiff::TIFF* m_hFile;
60 std::shared_ptr<TIFFMessageHandler> m_messageHandler;
61
62 };
63}
64
65#define TIFFKeeperPtr std::shared_ptr<slideio::TIFFKeeper>
66
67#endif
Definition: exceptions.hpp:15