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#pragma once
6#include <string>
7
8#include "tifftools.hpp"
9#include "slideio/imagetools/slideio_imagetools_def.hpp"
10#include "slideio/imagetools/imagetools.hpp"
11
12namespace libtiff
13{
14 struct tiff;
15 typedef tiff TIFF;
16}
17
18namespace slideio
19{
20 class TIFFMessageHandler;
21
22 class SLIDEIO_IMAGETOOLS_EXPORTS TIFFKeeper
23 {
24 public:
25 TIFFKeeper(libtiff::TIFF* hfile = nullptr);
26 TIFFKeeper(const std::string& filePath, bool readOnly = true);
27 ~TIFFKeeper();
28 libtiff::TIFF* getHandle() const {
29 return m_hFile;
30 }
31 bool isValid() const {
32 return getHandle() != nullptr;
33 }
34 operator libtiff::TIFF* () const {
35 return getHandle();
36 }
37 TIFFKeeper& operator = (libtiff::TIFF* hFile) {
38 m_hFile = hFile;
39 return *this;
40 }
41 libtiff::TIFF* release() {
42 libtiff::TIFF* handle = m_hFile;
43 m_hFile = nullptr;
44 return handle;
45 }
46 void openTiffFile(const std::string& filePath, bool readOnly = true);
47 void closeTiffFile();
48 void writeDirectory();
49 void setTags(const TiffDirectory& dir);
50 void writeTile(int x, int y, Compression compression, const EncodeParameters& params, const cv::Mat& mat,
51 uint8_t* buffer, int bufferSize);
52 void readTile(const slideio::TiffDirectory& dir, int tile,
53 const std::vector<int>& channelIndices, cv::OutputArray output);
54 std::string readStringTag(uint16_t tag);
55 void initSubDirs(int numDirs);
56 void writeRawTile(int x, int y, const uint8_t* data, int size);
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>
Definition: exceptions.hpp:15