Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Images/ImageAccessor.cpp @ 4335:82652c5fc04f
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 01 Dec 2020 20:31:04 +0100 |
parents | b30a8de92ad9 |
children | d9473bd5ed43 |
rev | line source |
---|---|
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
983
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
800
diff
changeset
|
23 #include "../PrecompiledHeaders.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "ImageAccessor.h" |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
26 #include "../Logging.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include "../OrthancException.h" |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
28 #include "../ChunkedBuffer.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 #include <stdint.h> |
860 | 31 #include <cassert> |
1397 | 32 #include <boost/lexical_cast.hpp> |
33 | |
34 | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 namespace Orthanc |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
38 template <typename PixelType> |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
39 static void ToMatlabStringInternal(ChunkedBuffer& target, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
40 const ImageAccessor& source) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
41 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
42 target.AddChunk("double([ "); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
43 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
44 const unsigned int width = source.GetWidth(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
45 const unsigned int height = source.GetHeight(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
46 |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
47 for (unsigned int y = 0; y < height; y++) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
48 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
49 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
50 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
51 std::string s; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
52 if (y > 0) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
53 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
54 s = "; "; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
55 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
56 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
57 s.reserve(width * 8); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
58 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
59 for (unsigned int x = 0; x < width; x++, p++) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
60 { |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
61 s += boost::lexical_cast<std::string>(static_cast<double>(*p)) + " "; |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
62 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
63 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
64 target.AddChunk(s); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
65 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
66 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
67 target.AddChunk("])"); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
68 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
69 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
70 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
71 static void RGB24ToMatlabString(ChunkedBuffer& target, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
72 const ImageAccessor& source) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
73 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
74 assert(source.GetFormat() == PixelFormat_RGB24); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
75 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
76 target.AddChunk("double(permute(reshape([ "); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
77 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
78 const unsigned int width = source.GetWidth(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
79 const unsigned int height = source.GetHeight(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
80 |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
81 for (unsigned int y = 0; y < height; y++) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
82 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
83 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
84 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
85 std::string s; |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
86 s.reserve(width * 3 * 8); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
87 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
88 for (unsigned int x = 0; x < 3 * width; x++, p++) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
89 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
90 s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " "; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
91 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
92 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
93 target.AddChunk(s); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
94 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
95 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
96 target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(height) + |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
97 " " + boost::lexical_cast<std::string>(width) + " ]), [ 3 2 1 ]))"); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
98 } |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
99 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
100 |
4300 | 101 ImageAccessor::ImageAccessor() |
102 { | |
103 AssignEmpty(PixelFormat_Grayscale8); | |
104 } | |
105 | |
106 ImageAccessor::~ImageAccessor() | |
107 { | |
108 } | |
109 | |
110 bool ImageAccessor::IsReadOnly() const | |
111 { | |
112 return readOnly_; | |
113 } | |
114 | |
115 PixelFormat ImageAccessor::GetFormat() const | |
116 { | |
117 return format_; | |
118 } | |
119 | |
120 unsigned int ImageAccessor::GetBytesPerPixel() const | |
121 { | |
122 return ::Orthanc::GetBytesPerPixel(format_); | |
123 } | |
124 | |
125 unsigned int ImageAccessor::GetWidth() const | |
126 { | |
127 return width_; | |
128 } | |
129 | |
130 unsigned int ImageAccessor::GetHeight() const | |
131 { | |
132 return height_; | |
133 } | |
134 | |
135 unsigned int ImageAccessor::GetPitch() const | |
136 { | |
137 return pitch_; | |
138 } | |
139 | |
140 unsigned int ImageAccessor::GetSize() const | |
141 { | |
142 return GetHeight() * GetPitch(); | |
143 } | |
144 | |
145 const void *ImageAccessor::GetConstBuffer() const | |
146 { | |
147 return buffer_; | |
148 } | |
149 | |
4201 | 150 void* ImageAccessor::GetBuffer() |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 if (readOnly_) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
154 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
155 "Trying to write to a read-only image"); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 return buffer_; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 const void* ImageAccessor::GetConstRow(unsigned int y) const |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 if (buffer_ != NULL) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 { |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
166 return buffer_ + y * pitch_; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 else |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 return NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 |
4201 | 175 void* ImageAccessor::GetRow(unsigned int y) |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 if (readOnly_) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
179 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
180 "Trying to write to a read-only image"); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 if (buffer_ != NULL) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 { |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
185 return buffer_ + y * pitch_; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 else |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 return NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 void ImageAccessor::AssignEmpty(PixelFormat format) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 readOnly_ = false; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 width_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 height_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 pitch_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 buffer_ = NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 void ImageAccessor::AssignReadOnly(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 const void *buffer) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 readOnly_ = true; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 width_ = width; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 height_ = height; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 pitch_ = pitch; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
216 buffer_ = reinterpret_cast<uint8_t*>(const_cast<void*>(buffer)); |
860 | 217 |
1916 | 218 if (GetBytesPerPixel() * width_ > pitch_) |
219 { | |
220 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
221 } | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 |
4300 | 224 void ImageAccessor::GetReadOnlyAccessor(ImageAccessor &target) const |
225 { | |
226 target.AssignReadOnly(format_, width_, height_, pitch_, buffer_); | |
227 } | |
228 | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 void ImageAccessor::AssignWritable(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 void *buffer) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 readOnly_ = false; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 width_ = width; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 height_ = height; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 pitch_ = pitch; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
241 buffer_ = reinterpret_cast<uint8_t*>(buffer); |
860 | 242 |
1916 | 243 if (GetBytesPerPixel() * width_ > pitch_) |
244 { | |
245 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
246 } | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
248 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
249 |
2865
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
250 void ImageAccessor::GetWriteableAccessor(ImageAccessor& target) const |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
251 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
252 if (readOnly_) |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
253 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
254 throw OrthancException(ErrorCode_ReadOnly); |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
255 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
256 else |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
257 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
258 target.AssignWritable(format_, width_, height_, pitch_, buffer_); |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
259 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
260 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
261 |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
262 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
263 void ImageAccessor::ToMatlabString(std::string& target) const |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
264 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
265 ChunkedBuffer buffer; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
266 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
267 switch (GetFormat()) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
268 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
269 case PixelFormat_Grayscale8: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
270 ToMatlabStringInternal<uint8_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
271 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
272 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
273 case PixelFormat_Grayscale16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
274 ToMatlabStringInternal<uint16_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
275 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
276 |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
277 case PixelFormat_Grayscale32: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
278 ToMatlabStringInternal<uint32_t>(buffer, *this); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
279 break; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
280 |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
281 case PixelFormat_Grayscale64: |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
282 ToMatlabStringInternal<uint64_t>(buffer, *this); |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
283 break; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
284 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
285 case PixelFormat_SignedGrayscale16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
286 ToMatlabStringInternal<int16_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
287 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
288 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
289 case PixelFormat_Float32: |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
290 ToMatlabStringInternal<float>(buffer, *this); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
291 break; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
292 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
293 case PixelFormat_RGB24: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
294 RGB24ToMatlabString(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
295 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
296 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
297 default: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
298 throw OrthancException(ErrorCode_NotImplemented); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
299 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
300 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
301 buffer.Flatten(target); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
302 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
303 |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
304 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
305 |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
306 void ImageAccessor::GetRegion(ImageAccessor& accessor, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
307 unsigned int x, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
308 unsigned int y, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
309 unsigned int width, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
310 unsigned int height) const |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
311 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
312 if (x + width > width_ || |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
313 y + height > height_) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
314 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
315 throw OrthancException(ErrorCode_ParameterOutOfRange); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
316 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
317 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
318 if (width == 0 || |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
319 height == 0) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
320 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
321 accessor.AssignWritable(format_, 0, 0, 0, NULL); |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
322 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
323 else |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
324 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
325 uint8_t* p = (buffer_ + |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
326 y * pitch_ + |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
327 x * GetBytesPerPixel()); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
328 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
329 if (readOnly_) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
330 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
331 accessor.AssignReadOnly(format_, width, height, pitch_, p); |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
332 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
333 else |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
334 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
335 accessor.AssignWritable(format_, width, height, pitch_, p); |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
336 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
337 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
338 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
339 |
2103
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
340 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
341 void ImageAccessor::SetFormat(PixelFormat format) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
342 { |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
343 if (readOnly_) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
344 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
345 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
346 "Trying to modify the format of a read-only image"); |
2103
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
347 } |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
348 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
349 if (::Orthanc::GetBytesPerPixel(format) != ::Orthanc::GetBytesPerPixel(format_)) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
350 { |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
351 throw OrthancException(ErrorCode_IncompatibleImageFormat); |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
352 } |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
353 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
354 format_ = format; |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
355 } |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
356 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
357 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
358 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
359 void* ImageAccessor::GetBuffer() const |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
360 { |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
361 return const_cast<ImageAccessor&>(*this).GetBuffer(); |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
362 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
363 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
364 void* ImageAccessor::GetRow(unsigned int y) const |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
365 { |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
366 return const_cast<ImageAccessor&>(*this).GetRow(y); |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
367 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
368 #endif |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 } |