SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
fiwrapper.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#pragma once
5#include "slideio/imagetools/slideio_imagetools_def.hpp"
6#include "tifftools.hpp"
7#include "slideio/base/size.hpp"
8#include "slideio/base/slideio_enums.hpp"
9#include "slideio/imagetools/smallimage.hpp"
10#include <FreeImage.h>
11#include <map>
12#include <string>
13#include <nlohmann/json.hpp>
14#include <opencv2/core/mat.hpp>
15
16
17struct FIBITMAP;
18struct FIMULTIBITMAP;
19
20namespace slideio
21{
22 class SLIDEIO_IMAGETOOLS_EXPORTS FIWrapper : public SmallImage
23 {
24 public:
25 class SLIDEIO_IMAGETOOLS_EXPORTS Page : public SmallImagePage
26 {
27 public:
28 Page(FIWrapper* parent, int pageIndex);
29 Page(FIWrapper* parent, FIBITMAP* bitmap);
30 Page(const Page&) = delete;
31 Page& operator=(const Page&) = delete;
32 Page(Page&& other) noexcept = delete;
33 Page& operator=(Page&& other) noexcept = delete;
34 virtual ~Page();
35 Size getSize() const override;
36 DataType getDataType() const override{
37 return m_dataType;
38 }
39 int getNumChannels() const override{
40 return m_numChannels;
41 }
42 const std::string& getMetadata() const override{
43 return m_metadata;
44 }
45 Compression getCompression() const override{
46 return m_compression;
47 }
48 void readRaster(cv::OutputArray) override;
49 Resolution getResolution() const override;
50 private:
51 void detectMetadata();
52 void extractCommonMetadata();
53 void extractTiffMetadata();
54 void preparePage();
55 void detectNumChannels();
56 void detectDataType();
57 Compression extractTiffCompression();
58 void detectCompression();
59 private:
60 FIBITMAP* m_pBitmap = nullptr;
61 FIMULTIBITMAP* m_hFile = nullptr;
62 int m_pageIndex = -1;
63 int m_numChannels = 0;
64 DataType m_dataType = DataType::DT_Unknown;
65 std::string m_metadata;
66 Compression m_compression = Compression::Unknown;
67 FREE_IMAGE_FORMAT m_fiFormat = FIF_UNKNOWN;
68 FIWrapper* m_parent = nullptr;
69 };
70 public:
71 FIWrapper(const std::string& filePath);
72 FIWrapper(const FIWrapper&) = delete;
73 FIWrapper& operator=(const FIWrapper&) = delete;
74 FIWrapper(FIWrapper&& other) noexcept = delete;
75 FIWrapper& operator=(FIWrapper&& other) noexcept = delete;
76 virtual ~FIWrapper();
77 bool isValid() const override;
78 int getNumPages() const override;
79 SmallImagePage* readPage(int page) override;
80 FIMULTIBITMAP* getFIHandle() const{
81 return m_hFile;
82 }
83 FREE_IMAGE_FORMAT getFIFormat() const {
84 return m_fiFormat;
85 }
86 const std::string& getFilePath() const {
87 return m_filePath;
88 }
89 int getNumTiffDirectories() const {
90 return (int)m_tiffDirectories.size();
91 }
92 const TiffDirectory& getTiffDirectory(int index) const;
93 static void writeRaster(const std::string& filePath, Compression compression, const cv::Mat& raster);
94 private:
95 FIMULTIBITMAP* m_hFile = nullptr;
96 FIBITMAP* m_pBitmap = nullptr;
97 std::map<int, std::shared_ptr<Page>> m_pages;
98 FREE_IMAGE_FORMAT m_fiFormat = FIF_UNKNOWN;
99 std::string m_filePath;
100 std::vector<TiffDirectory> m_tiffDirectories;
101 };
102};
Definition: exceptions.hpp:15
Compression
raster data compression enum
Definition: slideio_enums.hpp:12