comparison Framework/Inputs/OpenSlideLibrary.h @ 0:4a7a53257c7d

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 22 Oct 2016 21:48:33 +0200
parents
children 7a3853d51c45
comparison
equal deleted inserted replaced
-1:000000000000 0:4a7a53257c7d
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public License
8 * as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20
21 #pragma once
22
23 #include "../Orthanc/Plugins/Engine/SharedLibrary.h"
24 #include "../Orthanc/Core/Images/ImageAccessor.h"
25
26 #include <vector>
27
28 namespace OrthancWSI
29 {
30 class OpenSlideLibrary : public boost::noncopyable
31 {
32 private:
33 typedef void* (*FunctionClose) (void*);
34 typedef int32_t (*FunctionGetLevelCount) (void*);
35 typedef void (*FunctionGetLevelDimensions) (void*, int32_t, int64_t*, int64_t*);
36 typedef double (*FunctionGetLevelDownsample) (void*, int32_t);
37 typedef void* (*FunctionOpen) (const char*);
38 typedef void (*FunctionReadRegion) (void*, uint32_t*, int64_t, int64_t, int32_t, int64_t, int64_t);
39
40 Orthanc::SharedLibrary library_;
41 FunctionClose close_;
42 FunctionGetLevelCount getLevelCount_;
43 FunctionGetLevelDimensions getLevelDimensions_;
44 FunctionGetLevelDownsample getLevelDownsample_;
45 FunctionOpen open_;
46 FunctionReadRegion readRegion_;
47
48 public:
49 OpenSlideLibrary(const std::string& path);
50
51 static OpenSlideLibrary& GetInstance();
52
53 static void Initialize(const std::string& path);
54
55 static void Finalize();
56
57 class Image : public boost::noncopyable
58 {
59 private:
60 struct Level
61 {
62 unsigned int width_;
63 unsigned int height_;
64 double downsample_;
65
66 Level();
67
68 Level(int64_t width,
69 int64_t height,
70 double downsample);
71 };
72
73 OpenSlideLibrary& that_;
74 void* handle_;
75 std::vector<Level> levels_;
76
77 void Initialize(const std::string& path);
78
79 void Close();
80
81 void CheckLevel(unsigned int level) const;
82
83 public:
84 Image(OpenSlideLibrary& that,
85 const std::string& path);
86
87 Image(const std::string& path);
88
89 ~Image()
90 {
91 Close();
92 }
93
94 unsigned int GetLevelCount() const
95 {
96 return levels_.size();
97 }
98
99 double GetLevelDownsample(unsigned int level) const;
100
101 unsigned int GetLevelWidth(unsigned int level) const;
102
103 unsigned int GetLevelHeight(unsigned int level) const;
104
105 Orthanc::ImageAccessor* ReadRegion(unsigned int level,
106 uint64_t x,
107 uint64_t y,
108 unsigned int width,
109 unsigned int height);
110 };
111 };
112 }