SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
tifftools.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#ifndef OPENCV_slideio_tifftools_HPP
5#define OPENCV_slideio_tifftools_HPP
6
7#include "slideio/imagetools/slideio_imagetools_def.hpp"
8#include "slideio/core/cvstructs.hpp"
9#include "slideio/base/slideio_enums.hpp"
10#include "slideio/base/base.hpp"
11#include <opencv2/core.hpp>
12#include <string>
13#include <vector>
14
15#include "imagetools.hpp"
16
17namespace libtiff
18{
19 struct tiff;
20 typedef tiff TIFF;
21}
22
23namespace slideio
24{
25 struct TiffDirectory
26 {
27 int width;
28 int height;
29 bool tiled;
30 int tileWidth;
31 int tileHeight;
32 int channels;
33 int bitsPerSample;
34 int photometric;
35 int YCbCrSubsampling[2];
36 uint32_t compression;
37 Compression slideioCompression;
38 int dirIndex;
39 int64 offset;
40 std::string description;
41 std::vector<TiffDirectory> subdirectories;
42 Resolution res;
43 cv::Point2d position;
44 bool interleaved;
45 int rowsPerStrip;
46 DataType dataType;
47 int stripSize;
48 int compressionQuality;
49 };
50
51
52 class SLIDEIO_IMAGETOOLS_EXPORTS TiffTools
53 {
54 public:
55 static libtiff::TIFF* openTiffFile(const std::string& path, bool readOnly=true);
56 static void closeTiffFile(libtiff::TIFF* file);
57 static void scanTiffDirTags(libtiff::TIFF* tiff, int dirIndex, int64_t dirOffset, slideio::TiffDirectory& dir);
58 static void scanTiffDir(libtiff::TIFF* tiff, int dirIndex, int64_t dirOffset, slideio::TiffDirectory& dir);
59 static void scanFile(libtiff::TIFF* file, std::vector<TiffDirectory>& directories);
60 static void scanFile(const std::string& filePath, std::vector<TiffDirectory>& directories);
61 static void readNotRGBStripedDir(libtiff::TIFF* tiff, const TiffDirectory& dir, cv::_OutputArray output);
62 static void readRegularStripedDir(libtiff::TIFF* file, const slideio::TiffDirectory& dir, cv::OutputArray output);
63 static void readStripedDir(libtiff::TIFF* file, const slideio::TiffDirectory& dir, cv::OutputArray output);
64 static void readTile(libtiff::TIFF* hFile, const slideio::TiffDirectory& dir, int tile,
65 const std::vector<int>& channelIndices, cv::OutputArray output);
66 static void setCurrentDirectory(libtiff::TIFF* hFile, const slideio::TiffDirectory& dir);
67 static void scaleBlockToDirectory(const TiffDirectory& basisDir, const TiffDirectory& dir,
68 const cv::Rect& basisDirRect, cv::Rect& dirBlockRect);
69 static void readJ2KTile(libtiff::TIFF* hFile, const slideio::TiffDirectory& dir, int tile,
70 const std::vector<int>& channelIndices, cv::OutputArray output);
71 static void readRegularTile(libtiff::TIFF* hFile, const slideio::TiffDirectory& dir, int tile,
72 const std::vector<int>& channelIndices, cv::OutputArray output);
73 static void readNotRGBTile(libtiff::TIFF* hFile, const slideio::TiffDirectory& dir, int tile,
74 const std::vector<int>& channelIndices, cv::OutputArray output);
75 static void writeDirectory(libtiff::TIFF* tiff);
76 static void setTags(libtiff::TIFF* tiff, const TiffDirectory& dir, bool newDirectory);
77 static void writeTile(libtiff::TIFF* tiff, int x, int y, Compression compression,
78 const cv::Mat& tileRaster, const EncodeParameters& parameters,
79 uint8_t* buffer=nullptr, int bufferSize=0);
80 static std::string readStringTag(libtiff::TIFF* tiff, uint16_t tag);
81 static int getNumberOfDirectories(libtiff::TIFF* tiff);
82 };
83}
84
85//boost::log::basic_formatting_ostream& operator << (boost::log::basic_formatting_ostream& os, const slideio::TiffDirectory& dir);
86//boost::log::basic_formatting_ostream& operator << (boost::log::basic_formatting_ostream& os, const std::vector<slideio::TiffDirectory>& dirs);
87
88#endif
Definition: exceptions.hpp:12
Compression
raster data compression enum
Definition: slideio_enums.hpp:12