comparison OrthancFramework/Sources/Images/ImageAccessor.h @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Core/Images/ImageAccessor.h@f9863630ec7f
children bf7b9edf6b81
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
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 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #pragma once
35
36 #include "../Enumerations.h"
37
38 #include <string>
39 #include <stdint.h>
40 #include <boost/noncopyable.hpp>
41
42 namespace Orthanc
43 {
44 class ORTHANC_PUBLIC ImageAccessor : public boost::noncopyable
45 {
46 private:
47 template <Orthanc::PixelFormat Format>
48 friend struct ImageTraits;
49
50 bool readOnly_;
51 PixelFormat format_;
52 unsigned int width_;
53 unsigned int height_;
54 unsigned int pitch_;
55 uint8_t *buffer_;
56
57 template <typename T>
58 const T& GetPixelUnchecked(unsigned int x,
59 unsigned int y) const
60 {
61 const uint8_t* row = reinterpret_cast<const uint8_t*>(buffer_) + y * pitch_;
62 return reinterpret_cast<const T*>(row) [x];
63 }
64
65
66 template <typename T>
67 T& GetPixelUnchecked(unsigned int x,
68 unsigned int y)
69 {
70 uint8_t* row = reinterpret_cast<uint8_t*>(buffer_) + y * pitch_;
71 return reinterpret_cast<T*>(row) [x];
72 }
73
74 public:
75 ImageAccessor()
76 {
77 AssignEmpty(PixelFormat_Grayscale8);
78 }
79
80 virtual ~ImageAccessor()
81 {
82 }
83
84 bool IsReadOnly() const
85 {
86 return readOnly_;
87 }
88
89 PixelFormat GetFormat() const
90 {
91 return format_;
92 }
93
94 unsigned int GetBytesPerPixel() const
95 {
96 return ::Orthanc::GetBytesPerPixel(format_);
97 }
98
99 unsigned int GetWidth() const
100 {
101 return width_;
102 }
103
104 unsigned int GetHeight() const
105 {
106 return height_;
107 }
108
109 unsigned int GetPitch() const
110 {
111 return pitch_;
112 }
113
114 unsigned int GetSize() const
115 {
116 return GetHeight() * GetPitch();
117 }
118
119 const void* GetConstBuffer() const
120 {
121 return buffer_;
122 }
123
124 void* GetBuffer() const;
125
126 const void* GetConstRow(unsigned int y) const;
127
128 void* GetRow(unsigned int y) const;
129
130 void AssignEmpty(PixelFormat format);
131
132 void AssignReadOnly(PixelFormat format,
133 unsigned int width,
134 unsigned int height,
135 unsigned int pitch,
136 const void *buffer);
137
138 void GetReadOnlyAccessor(ImageAccessor& target) const
139 {
140 target.AssignReadOnly(format_, width_, height_, pitch_, buffer_);
141 }
142
143 void AssignWritable(PixelFormat format,
144 unsigned int width,
145 unsigned int height,
146 unsigned int pitch,
147 void *buffer);
148
149 void GetWriteableAccessor(ImageAccessor& target) const;
150
151 void ToMatlabString(std::string& target) const;
152
153 void GetRegion(ImageAccessor& accessor,
154 unsigned int x,
155 unsigned int y,
156 unsigned int width,
157 unsigned int height) const;
158
159 void SetFormat(PixelFormat format);
160 };
161 }